diff options
| author | skal <pascal.massimino@gmail.com> | 2026-01-28 01:27:02 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-01-28 01:27:02 +0100 |
| commit | 7ed0286e8cd40367ab6ba7f100e3b30d9d1ae383 (patch) | |
| tree | d7935ffe9ee407c782985789c194b384a36f69f9 /src/gpu/gpu.cc | |
| parent | 6cd6fb41ed44bd37bd05e5a4abf23661605c00df (diff) | |
opt: Implement build stripping and platform-specific size optimizations
Adds a 'STRIP_ALL' mode to minimize binary size for the final build, and refines size optimization flags for macOS.
- **STRIP_ALL Mode**: Added a 'DEMO_STRIP_ALL' CMake option that defines 'STRIP_ALL'. In this mode, command-line parsing is bypassed (forcing fullscreen), debug labels/error callbacks are removed from WebGPU, and non-essential code (like iostream) is stripped.
- **macOS Optimizations**: Updated CMake to use '-dead_strip' instead of GNU '--gc-sections' on Apple platforms to resolve linker errors and improve dead code elimination.
- **Documentation**: Updated HOWTO.md to document the new 'Final / Strip Build' process and FETCH_DEPS.md for optimized wgpu-native build guidance.
- **Task 7 & 8**: Marks these tasks as completed in PROJECT_CONTEXT.md.
Diffstat (limited to 'src/gpu/gpu.cc')
| -rw-r--r-- | src/gpu/gpu.cc | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc index a1da2db..9eb2437 100644 --- a/src/gpu/gpu.cc +++ b/src/gpu/gpu.cc @@ -8,9 +8,12 @@ #include <algorithm> #include <cassert> #include <cstring> -#include <iostream> #include <vector> +#ifndef STRIP_ALL +#include <iostream> +#endif + static WGPUInstance g_instance = nullptr; static WGPUAdapter g_adapter = nullptr; static WGPUDevice g_device = nullptr; @@ -23,10 +26,16 @@ static WGPUBuffer g_uniform_buffer = nullptr; static WGPUBindGroup g_bind_group = nullptr; static WGPUStringView str_view(const char *str) { +#ifndef STRIP_ALL if (!str) return {nullptr, 0}; return {str, strlen(str)}; +#else + (void)str; + return {nullptr, 0}; +#endif } +#ifndef STRIP_ALL static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, void *userdata1, void *userdata2) { @@ -36,7 +45,17 @@ static void handle_request_adapter(WGPURequestAdapterStatus status, printf("Request adapter failed: %.*s\n", (int)message.length, message.data); } } +#else +static void handle_request_adapter(WGPURequestAdapterStatus status, + WGPUAdapter adapter, WGPUStringView message, + void *userdata1, void *userdata2) { + if (status == WGPURequestAdapterStatus_Success) { + *((WGPUAdapter *)userdata1) = adapter; + } +} +#endif +#ifndef STRIP_ALL static void handle_request_device(WGPURequestDeviceStatus status, WGPUDevice device, WGPUStringView message, void *userdata1, void *userdata2) { @@ -46,12 +65,23 @@ static void handle_request_device(WGPURequestDeviceStatus status, printf("Request device failed: %.*s\n", (int)message.length, message.data); } } +#else +static void handle_request_device(WGPURequestDeviceStatus status, + WGPUDevice device, WGPUStringView message, + void *userdata1, void *userdata2) { + if (status == WGPURequestDeviceStatus_Success) { + *((WGPUDevice *)userdata1) = device; + } +} +#endif +#ifndef STRIP_ALL static void handle_device_error(WGPUDevice const *device, WGPUErrorType type, WGPUStringView message, void *userdata1, void *userdata2) { printf("WebGPU Error: %.*s\n", (int)message.length, message.data); } +#endif const char *shader_wgsl_code = R"( struct Uniforms { @@ -116,7 +146,9 @@ void gpu_init(GLFWwindow *window) { WGPUDeviceDescriptor device_desc = {}; device_desc.label = str_view("Demo Device"); +#ifndef STRIP_ALL device_desc.uncapturedErrorCallbackInfo.callback = handle_device_error; +#endif wgpuAdapterRequestDevice( g_adapter, &device_desc, |
