summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-09 18:34:20 +0100
committerskal <pascal.massimino@gmail.com>2026-02-09 18:34:20 +0100
commit26915d8c47260f90d67df8c6af1f16ba7607a3d5 (patch)
treec01f1e6bfe0cb85a27f5fc94ed01dea7aa9b969e /src
parent82fcfd2656a9f7085c54407d9c390a7d413c4b5a (diff)
feat: Implement Task #76 external library size measurement
- Use ma_backend_null for audio (100-200KB savings) - Stub platform/gpu abstractions instead of external APIs - Add DEMO_STRIP_EXTERNAL_LIBS build mode - Create stub_types.h with minimal WebGPU opaque types - Add scripts/measure_size.sh for automated measurement Results: Demo=4.4MB, External=2.0MB (69% vs 31%) handoff(Claude): Task #76 complete. Binary compiles but doesn't run (size measurement only).
Diffstat (limited to 'src')
-rw-r--r--src/gpu/stub_gpu.cc83
-rw-r--r--src/platform/platform.h5
-rw-r--r--src/platform/stub_platform.cc53
-rw-r--r--src/platform/stub_types.h159
-rw-r--r--src/stub_main.cc13
5 files changed, 312 insertions, 1 deletions
diff --git a/src/gpu/stub_gpu.cc b/src/gpu/stub_gpu.cc
new file mode 100644
index 0000000..0b4185c
--- /dev/null
+++ b/src/gpu/stub_gpu.cc
@@ -0,0 +1,83 @@
+// 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) {
+ (void)audio_peak;
+ (void)aspect_ratio;
+ (void)time;
+ (void)beat;
+}
+
+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;
+}
+
+MainSequence* gpu_get_main_sequence() {
+ 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 // STRIP_EXTERNAL_LIBS
diff --git a/src/platform/platform.h b/src/platform/platform.h
index 0a98850..7bcee9d 100644
--- a/src/platform/platform.h
+++ b/src/platform/platform.h
@@ -7,7 +7,10 @@
#include <cstring>
// WebGPU specific headers and shims
-#if defined(DEMO_CROSS_COMPILE_WIN32)
+#if defined(STRIP_EXTERNAL_LIBS)
+#include "stub_types.h"
+
+#elif defined(DEMO_CROSS_COMPILE_WIN32)
#include <webgpu/webgpu.h>
#include <webgpu/wgpu.h>
diff --git a/src/platform/stub_platform.cc b/src/platform/stub_platform.cc
new file mode 100644
index 0000000..61473a0
--- /dev/null
+++ b/src/platform/stub_platform.cc
@@ -0,0 +1,53 @@
+// Stub platform 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 "platform.h"
+#include "stub_types.h"
+
+// Forward declare GLFWwindow stub
+struct GLFWwindow {};
+
+PlatformState platform_init(bool fullscreen, int width, int height) {
+ (void)fullscreen;
+ PlatformState state = {};
+ state.width = width;
+ state.height = height;
+ state.aspect_ratio = (float)width / (float)height;
+ state.window = nullptr;
+ state.time = 0.0;
+ state.is_fullscreen = false;
+ return state;
+}
+
+void platform_shutdown(PlatformState* state) {
+ (void)state;
+}
+
+void platform_poll(PlatformState* state) {
+ (void)state;
+}
+
+bool platform_should_close(PlatformState* state) {
+ (void)state;
+ return false;
+}
+
+void platform_toggle_fullscreen(PlatformState* state) {
+ (void)state;
+}
+
+WGPUSurface platform_create_wgpu_surface(WGPUInstance instance,
+ PlatformState* state) {
+ (void)instance;
+ (void)state;
+ return nullptr;
+}
+
+double platform_get_time() {
+ return 0.0;
+}
+
+#endif // STRIP_EXTERNAL_LIBS
diff --git a/src/platform/stub_types.h b/src/platform/stub_types.h
new file mode 100644
index 0000000..f532e04
--- /dev/null
+++ b/src/platform/stub_types.h
@@ -0,0 +1,159 @@
+// Minimal WebGPU type definitions for size measurement builds.
+// All types are opaque pointers, all descriptor structs are empty.
+// This file is only used when STRIP_EXTERNAL_LIBS is defined.
+
+#pragma once
+
+#if defined(STRIP_EXTERNAL_LIBS)
+
+#include <cstdint>
+#include <cstring>
+
+// Opaque handle types
+typedef void* WGPUInstance;
+typedef void* WGPUAdapter;
+typedef void* WGPUSurface;
+typedef void* WGPUDevice;
+typedef void* WGPUQueue;
+typedef void* WGPUBuffer;
+typedef void* WGPUTexture;
+typedef void* WGPUTextureView;
+typedef void* WGPUSampler;
+typedef void* WGPUShaderModule;
+typedef void* WGPUBindGroupLayout;
+typedef void* WGPUPipelineLayout;
+typedef void* WGPUBindGroup;
+typedef void* WGPURenderPipeline;
+typedef void* WGPUComputePipeline;
+typedef void* WGPUCommandEncoder;
+typedef void* WGPURenderPassEncoder;
+typedef void* WGPUComputePassEncoder;
+typedef void* WGPUCommandBuffer;
+typedef void* WGPUQuerySet;
+typedef void* WGPURenderBundle;
+typedef void* WGPURenderBundleEncoder;
+
+// Enums (minimal values)
+typedef enum {
+ WGPUTextureFormat_Undefined = 0,
+ WGPUTextureFormat_BGRA8Unorm = 1,
+ WGPUTextureFormat_RGBA8Unorm = 2,
+} WGPUTextureFormat;
+
+typedef enum {
+ WGPUBufferBindingType_Uniform = 0,
+ WGPUBufferBindingType_Storage = 1,
+ WGPUBufferBindingType_ReadOnlyStorage = 2,
+} WGPUBufferBindingType;
+
+typedef enum {
+ WGPULoadOp_Clear = 0,
+ WGPULoadOp_Load = 1,
+} WGPULoadOp;
+
+typedef enum {
+ WGPUStoreOp_Store = 0,
+ WGPUStoreOp_Discard = 1,
+} WGPUStoreOp;
+
+typedef enum {
+ WGPUSurfaceGetCurrentTextureStatus_Success = 0,
+ WGPUSurfaceGetCurrentTextureStatus_Timeout = 1,
+ WGPUSurfaceGetCurrentTextureStatus_Outdated = 2,
+ WGPUSurfaceGetCurrentTextureStatus_Lost = 3,
+} WGPUSurfaceGetCurrentTextureStatus;
+
+// Buffer usage flags
+#define WGPUBufferUsage_MapRead 0x00000001
+#define WGPUBufferUsage_MapWrite 0x00000002
+#define WGPUBufferUsage_CopySrc 0x00000004
+#define WGPUBufferUsage_CopyDst 0x00000008
+#define WGPUBufferUsage_Index 0x00000010
+#define WGPUBufferUsage_Vertex 0x00000020
+#define WGPUBufferUsage_Uniform 0x00000040
+#define WGPUBufferUsage_Storage 0x00000080
+#define WGPUBufferUsage_Indirect 0x00000100
+#define WGPUBufferUsage_QueryResolve 0x00000200
+
+// Descriptor structs (all empty)
+struct WGPUInstanceDescriptor {};
+struct WGPUAdapterInfo {};
+struct WGPUSurfaceConfiguration {};
+struct WGPUDeviceDescriptor {};
+struct WGPUBufferDescriptor {};
+struct WGPUTextureDescriptor {};
+struct WGPUTextureViewDescriptor {};
+struct WGPUSamplerDescriptor {};
+struct WGPUShaderModuleDescriptor {};
+struct WGPUShaderSourceWGSL {};
+struct WGPUShaderModuleWGSLDescriptor {};
+struct WGPUBindGroupLayoutDescriptor {};
+struct WGPUBindGroupLayoutEntry {};
+struct WGPUPipelineLayoutDescriptor {};
+struct WGPUBindGroupDescriptor {};
+struct WGPUBindGroupEntry {};
+struct WGPURenderPipelineDescriptor {};
+struct WGPUComputePipelineDescriptor {};
+struct WGPUVertexState {};
+struct WGPUFragmentState {};
+struct WGPUColorTargetState {};
+struct WGPUBlendState {};
+struct WGPUPrimitiveState {};
+struct WGPUMultisampleState {};
+struct WGPUDepthStencilState {};
+struct WGPURenderPassDescriptor {};
+struct WGPURenderPassColorAttachment {
+ WGPUTextureView view;
+ WGPULoadOp loadOp;
+ WGPUStoreOp storeOp;
+ struct { float r, g, b, a; } clearValue;
+ uint32_t depthSlice;
+};
+struct WGPUComputePassDescriptor {};
+struct WGPUCommandEncoderDescriptor {};
+struct WGPUCommandBufferDescriptor {};
+struct WGPUSurfaceTexture {
+ WGPUTexture texture;
+ WGPUSurfaceGetCurrentTextureStatus status;
+};
+struct WGPUColor { float r, g, b, a; };
+struct WGPUExtent3D { uint32_t width, height, depthOrArrayLayers; };
+struct WGPUOrigin3D { uint32_t x, y, z; };
+struct WGPUImageCopyTexture {};
+struct WGPUImageCopyBuffer {};
+struct WGPUTextureDataLayout {};
+struct WGPUBufferBindingLayout {};
+struct WGPUSamplerBindingLayout {};
+struct WGPUTextureBindingLayout {};
+struct WGPUStorageTextureBindingLayout {};
+
+// String view helper (for compatibility)
+struct WGPUStringView {
+ const char* data;
+ size_t length;
+};
+
+static inline WGPUStringView str_view(const char* str) {
+ if (!str) return {nullptr, 0};
+ return {str, strlen(str)};
+}
+
+static inline WGPUStringView label_view(const char* str) {
+ (void)str;
+ return {nullptr, 0};
+}
+
+// Platform shims (no-ops)
+static inline void platform_wgpu_wait_any(WGPUInstance) {}
+static inline void platform_wgpu_set_error_callback(WGPUDevice, void*) {}
+
+// Constants
+#define WGPU_DEPTH_SLICE_UNDEFINED 0xffffffff
+#define WGPUOptionalBool_True true
+#define WGPUOptionalBool_False false
+
+// Callback types (empty)
+typedef void (*WGPUErrorCallback)(void*, void*, const char*);
+typedef void (*WGPUUncapturedErrorCallback)(void*, void*, const char*);
+
+#endif // STRIP_EXTERNAL_LIBS
diff --git a/src/stub_main.cc b/src/stub_main.cc
new file mode 100644
index 0000000..8540fcd
--- /dev/null
+++ b/src/stub_main.cc
@@ -0,0 +1,13 @@
+// Stub main for size measurement builds.
+// Binary compiles but does NOT run.
+// This file is only compiled when STRIP_EXTERNAL_LIBS is defined.
+
+#if defined(STRIP_EXTERNAL_LIBS)
+
+int main(int argc, char** argv) {
+ (void)argc;
+ (void)argv;
+ return 0;
+}
+
+#endif // STRIP_EXTERNAL_LIBS