From cd5c2ee728fcfc5c0bf81ba51899fa7369d0d1e2 Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 17 Feb 2026 09:08:25 +0100 Subject: feat: Rename GPU stub and headless files and update references --- cmake/DemoCommon.cmake | 4 +- cmake/DemoSourceLists.cmake | 4 +- doc/COMPLETED.md | 2 +- doc/SIZE_MEASUREMENT.md | 8 +-- src/gpu/gpu_headless.cc | 147 ++++++++++++++++++++++++++++++++++++++++++++ src/gpu/gpu_stub.cc | 66 ++++++++++++++++++++ src/gpu/headless_gpu.cc | 147 -------------------------------------------- src/gpu/stub_gpu.cc | 66 -------------------- 8 files changed, 222 insertions(+), 222 deletions(-) create mode 100644 src/gpu/gpu_headless.cc create mode 100644 src/gpu/gpu_stub.cc delete mode 100644 src/gpu/headless_gpu.cc delete mode 100644 src/gpu/stub_gpu.cc diff --git a/cmake/DemoCommon.cmake b/cmake/DemoCommon.cmake index 401ea05..5f41786 100644 --- a/cmake/DemoCommon.cmake +++ b/cmake/DemoCommon.cmake @@ -14,8 +14,8 @@ # # Usage: # demo_set_conditional_sources(GPU_SOURCES -# "src/gpu/headless_gpu.cc;src/gpu/effect.cc" -# "src/gpu/stub_gpu.cc" +# "src/gpu/gpu_headless.cc;src/gpu/effect.cc" +# "src/gpu/gpu_stub.cc" # "src/gpu/gpu.cc;src/gpu/effect.cc" # ) function(demo_set_conditional_sources VAR HEADLESS_LIST STRIP_LIST NORMAL_LIST) diff --git a/cmake/DemoSourceLists.cmake b/cmake/DemoSourceLists.cmake index 0f5ac8c..b7bc843 100644 --- a/cmake/DemoSourceLists.cmake +++ b/cmake/DemoSourceLists.cmake @@ -52,9 +52,9 @@ set(COMMON_GPU_EFFECTS # GPU sources (conditional: HEADLESS / STRIP_EXTERNAL / NORMAL) demo_set_conditional_sources(GPU_SOURCES # Headless mode: Functional stubs (timeline/audio work) - "src/gpu/headless_gpu.cc;src/gpu/demo_effects.cc;${COMMON_GPU_EFFECTS}" + "src/gpu/gpu_headless.cc;src/gpu/demo_effects.cc;${COMMON_GPU_EFFECTS}" # Strip mode: Minimal GPU stubs only - "src/gpu/stub_gpu.cc" + "src/gpu/gpu_stub.cc" # Normal mode: Full GPU implementation "src/gpu/gpu.cc;${COMMON_GPU_EFFECTS}" ) diff --git a/doc/COMPLETED.md b/doc/COMPLETED.md index 4f0a889..427ac4f 100644 --- a/doc/COMPLETED.md +++ b/doc/COMPLETED.md @@ -142,7 +142,7 @@ Use `read @doc/archive/FILENAME.md` to access archived documents. - Audio: Use miniaudio's `ma_backend_null` (excludes platform drivers, saves 100-200KB) - GPU/Platform: Stub our abstractions (~30 functions) instead of external APIs (~300 functions) - Created `src/platform/stub_types.h` with minimal WebGPU opaque types - - Created `src/platform/stub_platform.cc` and `src/gpu/stub_gpu.cc` + - Created `src/platform/stub_platform.cc` and `src/gpu/gpu_stub.cc` - Added `DEMO_STRIP_EXTERNAL_LIBS` build mode - Created `scripts/measure_size.sh` for automated measurement - **Result**: Demo=4.4MB (69%), External=2.0MB (31%). Binary compiles but doesn't run. diff --git a/doc/SIZE_MEASUREMENT.md b/doc/SIZE_MEASUREMENT.md index 96c8e6c..f4d93b2 100644 --- a/doc/SIZE_MEASUREMENT.md +++ b/doc/SIZE_MEASUREMENT.md @@ -60,7 +60,7 @@ double platform_get_time() { return 0.0; } #endif ``` -**`src/gpu/stub_gpu.cc`:** +**`src/gpu/gpu_stub.cc`:** ```cpp #if defined(STRIP_EXTERNAL_LIBS) WGPUDevice gpu_create_device() { return nullptr; } @@ -90,7 +90,7 @@ if(DEMO_STRIP_EXTERNAL_LIBS) target_compile_definitions(demo64k PRIVATE STRIP_EXTERNAL_LIBS) target_sources(demo64k PRIVATE src/platform/stub_platform.cc - src/gpu/stub_gpu.cc + src/gpu/gpu_stub.cc ) # Don't link external libs @@ -144,7 +144,7 @@ Create `src/platform/stub_platform.cc`: ### Phase 3: GPU Stubs (1 hour) -Create `src/gpu/stub_gpu.cc`: +Create `src/gpu/gpu_stub.cc`: - Implement ~20 gpu wrapper functions as no-ops - All pointer returns = nullptr - All void functions = empty body @@ -199,7 +199,7 @@ size build_size/demo64k **New:** - `src/platform/stub_types.h` - WebGPU opaque types - `src/platform/stub_platform.cc` - Platform stubs (~10 functions) -- `src/gpu/stub_gpu.cc` - GPU stubs (~20 functions) +- `src/gpu/gpu_stub.cc` - GPU stubs (~20 functions) - `scripts/measure_size.sh` - Size measurement script **Modified:** diff --git a/src/gpu/gpu_headless.cc b/src/gpu/gpu_headless.cc new file mode 100644 index 0000000..e6995b2 --- /dev/null +++ b/src/gpu/gpu_headless.cc @@ -0,0 +1,147 @@ +// Headless GPU implementation - functional stubs for testing +// Workspace: demo (shared across all workspaces) + +#if defined(DEMO_HEADLESS) + +#include "gpu.h" +#include "gpu/effect.h" +#include "platform/stub_types.h" +#include + +static bool g_initialized = false; + +GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage, + const void* data) { + (void)device; + (void)size; + (void)usage; + (void)data; + return {nullptr, 0}; +} + +RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format, + const char* shader_code, + ResourceBinding* bindings, int num_bindings) { + (void)device; + (void)format; + (void)shader_code; + (void)bindings; + (void)num_bindings; + return {nullptr, nullptr, 0, 0}; +} + +ComputePass gpu_create_compute_pass(WGPUDevice device, const char* shader_code, + ResourceBinding* bindings, + int num_bindings) { + (void)device; + (void)shader_code; + (void)bindings; + (void)num_bindings; + return {nullptr, nullptr, 0, 0, 0}; +} + +void gpu_init(PlatformState* platform_state) { + (void)platform_state; + if (!g_initialized) { + printf("[headless] GPU initialized\n"); + g_initialized = true; + } +} + +void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat_time, + float beat_phase) { + (void)audio_peak; + (void)aspect_ratio; + (void)time; + (void)beat_time; + (void)beat_phase; +} + +void gpu_resize(int width, int height) { + (void)width; + (void)height; +} + +void gpu_shutdown() { + if (g_initialized) { + printf("[headless] GPU shutdown\n"); + g_initialized = false; + } +} + +const GpuContext* gpu_get_context() { + static GpuContext ctx = {nullptr, nullptr, WGPUTextureFormat_BGRA8Unorm}; + return &ctx; +} + +WGPUSurface gpu_get_surface() { + return nullptr; +} + +TextureWithView gpu_create_texture_2d(WGPUDevice device, uint32_t width, + uint32_t height, WGPUTextureFormat format, + WGPUTextureUsage usage, + uint32_t mip_levels) { + (void)device; + (void)width; + (void)height; + (void)format; + (void)usage; + (void)mip_levels; + return {nullptr, nullptr}; +} + +TextureWithView gpu_create_storage_texture_2d(WGPUDevice device, uint32_t width, + uint32_t height, + WGPUTextureFormat format) { + (void)device; + (void)width; + (void)height; + (void)format; + return {nullptr, nullptr}; +} + +TextureWithView gpu_create_post_process_texture(WGPUDevice device, + uint32_t width, uint32_t height, + WGPUTextureFormat format) { + (void)device; + (void)width; + (void)height; + (void)format; + return {nullptr, nullptr}; +} + +WGPUTextureView gpu_create_mip_view(WGPUTexture texture, + WGPUTextureFormat format, + uint32_t mip_level) { + (void)texture; + (void)format; + (void)mip_level; + return nullptr; +} + +WGPUTextureView gpu_create_texture_view_2d(WGPUTexture texture, + WGPUTextureFormat format, + uint32_t mip_levels) { + (void)texture; + (void)format; + (void)mip_levels; + return nullptr; +} + +#if !defined(STRIP_ALL) +void gpu_simulate_until(float time, float bpm) { + (void)time; + (void)bpm; +} + +void gpu_add_custom_effect(Effect* effect, float start_time, float end_time, + int priority) { + (void)effect; + (void)start_time; + (void)end_time; + (void)priority; +} +#endif + +#endif // DEMO_HEADLESS diff --git a/src/gpu/gpu_stub.cc b/src/gpu/gpu_stub.cc new file mode 100644 index 0000000..d889666 --- /dev/null +++ b/src/gpu/gpu_stub.cc @@ -0,0 +1,66 @@ +// Stub GPU implementation for size measurement builds. +// All functions are no-ops. Binary compiles but does NOT run. +// This file is only compiled when STRIP_EXTERNAL_LIBS is defined. + +#if defined(STRIP_EXTERNAL_LIBS) + +#include "gpu.h" +#include "platform/stub_types.h" + +GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage, + const void* data) { + (void)device; + (void)size; + (void)usage; + (void)data; + return {nullptr, 0}; +} + +RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format, + const char* shader_code, + ResourceBinding* bindings, int num_bindings) { + (void)device; + (void)format; + (void)shader_code; + (void)bindings; + (void)num_bindings; + return {nullptr, nullptr, 0, 0}; +} + +ComputePass gpu_create_compute_pass(WGPUDevice device, const char* shader_code, + ResourceBinding* bindings, + int num_bindings) { + (void)device; + (void)shader_code; + (void)bindings; + (void)num_bindings; + return {nullptr, nullptr, 0, 0, 0}; +} + +void gpu_init(PlatformState* platform_state) { + (void)platform_state; +} + +void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat_time, + float beat_phase) { + (void)audio_peak; + (void)aspect_ratio; + (void)time; + (void)beat_time; + (void)beat_phase; +} + +void gpu_resize(int width, int height) { + (void)width; + (void)height; +} + +void gpu_shutdown() { +} + +const GpuContext* gpu_get_context() { + static GpuContext ctx = {nullptr, nullptr, WGPUTextureFormat_BGRA8Unorm}; + return &ctx; +} + +#endif // STRIP_EXTERNAL_LIBS diff --git a/src/gpu/headless_gpu.cc b/src/gpu/headless_gpu.cc deleted file mode 100644 index e6995b2..0000000 --- a/src/gpu/headless_gpu.cc +++ /dev/null @@ -1,147 +0,0 @@ -// Headless GPU implementation - functional stubs for testing -// Workspace: demo (shared across all workspaces) - -#if defined(DEMO_HEADLESS) - -#include "gpu.h" -#include "gpu/effect.h" -#include "platform/stub_types.h" -#include - -static bool g_initialized = false; - -GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage, - const void* data) { - (void)device; - (void)size; - (void)usage; - (void)data; - return {nullptr, 0}; -} - -RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format, - const char* shader_code, - ResourceBinding* bindings, int num_bindings) { - (void)device; - (void)format; - (void)shader_code; - (void)bindings; - (void)num_bindings; - return {nullptr, nullptr, 0, 0}; -} - -ComputePass gpu_create_compute_pass(WGPUDevice device, const char* shader_code, - ResourceBinding* bindings, - int num_bindings) { - (void)device; - (void)shader_code; - (void)bindings; - (void)num_bindings; - return {nullptr, nullptr, 0, 0, 0}; -} - -void gpu_init(PlatformState* platform_state) { - (void)platform_state; - if (!g_initialized) { - printf("[headless] GPU initialized\n"); - g_initialized = true; - } -} - -void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat_time, - float beat_phase) { - (void)audio_peak; - (void)aspect_ratio; - (void)time; - (void)beat_time; - (void)beat_phase; -} - -void gpu_resize(int width, int height) { - (void)width; - (void)height; -} - -void gpu_shutdown() { - if (g_initialized) { - printf("[headless] GPU shutdown\n"); - g_initialized = false; - } -} - -const GpuContext* gpu_get_context() { - static GpuContext ctx = {nullptr, nullptr, WGPUTextureFormat_BGRA8Unorm}; - return &ctx; -} - -WGPUSurface gpu_get_surface() { - return nullptr; -} - -TextureWithView gpu_create_texture_2d(WGPUDevice device, uint32_t width, - uint32_t height, WGPUTextureFormat format, - WGPUTextureUsage usage, - uint32_t mip_levels) { - (void)device; - (void)width; - (void)height; - (void)format; - (void)usage; - (void)mip_levels; - return {nullptr, nullptr}; -} - -TextureWithView gpu_create_storage_texture_2d(WGPUDevice device, uint32_t width, - uint32_t height, - WGPUTextureFormat format) { - (void)device; - (void)width; - (void)height; - (void)format; - return {nullptr, nullptr}; -} - -TextureWithView gpu_create_post_process_texture(WGPUDevice device, - uint32_t width, uint32_t height, - WGPUTextureFormat format) { - (void)device; - (void)width; - (void)height; - (void)format; - return {nullptr, nullptr}; -} - -WGPUTextureView gpu_create_mip_view(WGPUTexture texture, - WGPUTextureFormat format, - uint32_t mip_level) { - (void)texture; - (void)format; - (void)mip_level; - return nullptr; -} - -WGPUTextureView gpu_create_texture_view_2d(WGPUTexture texture, - WGPUTextureFormat format, - uint32_t mip_levels) { - (void)texture; - (void)format; - (void)mip_levels; - return nullptr; -} - -#if !defined(STRIP_ALL) -void gpu_simulate_until(float time, float bpm) { - (void)time; - (void)bpm; -} - -void gpu_add_custom_effect(Effect* effect, float start_time, float end_time, - int priority) { - (void)effect; - (void)start_time; - (void)end_time; - (void)priority; -} -#endif - -#endif // DEMO_HEADLESS diff --git a/src/gpu/stub_gpu.cc b/src/gpu/stub_gpu.cc deleted file mode 100644 index d889666..0000000 --- a/src/gpu/stub_gpu.cc +++ /dev/null @@ -1,66 +0,0 @@ -// Stub GPU implementation for size measurement builds. -// All functions are no-ops. Binary compiles but does NOT run. -// This file is only compiled when STRIP_EXTERNAL_LIBS is defined. - -#if defined(STRIP_EXTERNAL_LIBS) - -#include "gpu.h" -#include "platform/stub_types.h" - -GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage, - const void* data) { - (void)device; - (void)size; - (void)usage; - (void)data; - return {nullptr, 0}; -} - -RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format, - const char* shader_code, - ResourceBinding* bindings, int num_bindings) { - (void)device; - (void)format; - (void)shader_code; - (void)bindings; - (void)num_bindings; - return {nullptr, nullptr, 0, 0}; -} - -ComputePass gpu_create_compute_pass(WGPUDevice device, const char* shader_code, - ResourceBinding* bindings, - int num_bindings) { - (void)device; - (void)shader_code; - (void)bindings; - (void)num_bindings; - return {nullptr, nullptr, 0, 0, 0}; -} - -void gpu_init(PlatformState* platform_state) { - (void)platform_state; -} - -void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat_time, - float beat_phase) { - (void)audio_peak; - (void)aspect_ratio; - (void)time; - (void)beat_time; - (void)beat_phase; -} - -void gpu_resize(int width, int height) { - (void)width; - (void)height; -} - -void gpu_shutdown() { -} - -const GpuContext* gpu_get_context() { - static GpuContext ctx = {nullptr, nullptr, WGPUTextureFormat_BGRA8Unorm}; - return &ctx; -} - -#endif // STRIP_EXTERNAL_LIBS -- cgit v1.2.3