summaryrefslogtreecommitdiff
path: root/src/gpu
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-01-31 14:26:36 +0100
committerskal <pascal.massimino@gmail.com>2026-01-31 14:26:36 +0100
commit213c99a2bb5a0061a2fae0533616f9547bfe0832 (patch)
tree37bc76dc4cb7b99ab55e3d2be46131e37709f2d5 /src/gpu
parent757c8e3f8f66cb7bbd354df61477bac1a5bf4eac (diff)
fix: Resolve macOS build breakage and restore tools audio support
Updates gpu.cc to handle modern wgpu-native callback signatures (5 args) for macOS while maintaining Windows compatibility. Modifies audio.cc and CMakeLists.txt to ensure miniaudio encoding features are only stripped from the demo binary, not the tools (spectool/tests).
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/gpu.cc73
1 files changed, 62 insertions, 11 deletions
diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc
index b1f3f14..1d3c24f 100644
--- a/src/gpu/gpu.cc
+++ b/src/gpu/gpu.cc
@@ -78,11 +78,9 @@ static WGPUStringView str_view(const char *str) {
return {str, strlen(str)};
}
-static void set_error_callback(WGPUDevice device, WGPUErrorCallback callback) {
- // Handled in descriptor for new API, mostly.
- // But we can also set it here if needed, or define a no-op if descriptor
- // handles it. For new API, we set it in
- // WGPUDeviceDescriptor.uncapturedErrorCallbackInfo.
+static void set_error_callback(WGPUDevice device,
+ WGPUUncapturedErrorCallback callback) {
+ // Handled in descriptor for new API.
}
#endif
@@ -278,6 +276,7 @@ ComputePass gpu_create_compute_pass(const char *shader_code,
// --- Main Init/Draw ---
#ifndef STRIP_ALL
+#if defined(DEMO_CROSS_COMPILE_WIN32)
static void handle_request_adapter(WGPURequestAdapterStatus status,
WGPUAdapter adapter, const char *message,
void *userdata) {
@@ -302,6 +301,36 @@ static void handle_device_error(WGPUErrorType type, const char *message,
}
#else
static void handle_request_adapter(WGPURequestAdapterStatus status,
+ WGPUAdapter adapter, WGPUStringView message,
+ void *userdata, void *userdata2) {
+ (void)userdata2;
+ if (status == WGPURequestAdapterStatus_Success) {
+ *((WGPUAdapter *)userdata) = adapter;
+ } else {
+ printf("Request adapter failed: %.*s\n", (int)message.length, message.data);
+ }
+}
+static void handle_request_device(WGPURequestDeviceStatus status,
+ WGPUDevice device, WGPUStringView message,
+ void *userdata, void *userdata2) {
+ (void)userdata2;
+ if (status == WGPURequestDeviceStatus_Success) {
+ *((WGPUDevice *)userdata) = device;
+ } else {
+ printf("Request device failed: %.*s\n", (int)message.length, message.data);
+ }
+}
+static void handle_device_error(const WGPUDevice *device, WGPUErrorType type,
+ WGPUStringView message, void *userdata) {
+ (void)device;
+ (void)userdata;
+ printf("WebGPU Error: %.*s\n", (int)message.length, message.data);
+}
+#endif
+#else
+// STRIP_ALL versions
+#if defined(DEMO_CROSS_COMPILE_WIN32)
+static void handle_request_adapter(WGPURequestAdapterStatus status,
WGPUAdapter adapter, const char *message,
void *userdata) {
if (status == WGPURequestAdapterStatus_Success) {
@@ -315,6 +344,24 @@ static void handle_request_device(WGPURequestDeviceStatus status,
*((WGPUDevice *)userdata) = device;
}
}
+#else
+static void handle_request_adapter(WGPURequestAdapterStatus status,
+ WGPUAdapter adapter, WGPUStringView message,
+ void *userdata, void *userdata2) {
+ (void)userdata2;
+ if (status == WGPURequestAdapterStatus_Success) {
+ *((WGPUAdapter *)userdata) = adapter;
+ }
+}
+static void handle_request_device(WGPURequestDeviceStatus status,
+ WGPUDevice device, WGPUStringView message,
+ void *userdata, void *userdata2) {
+ (void)userdata2;
+ if (status == WGPURequestDeviceStatus_Success) {
+ *((WGPUDevice *)userdata) = device;
+ }
+}
+#endif
#endif
// ... (Shaders omitted for brevity, they are unchanged) ...
@@ -492,9 +539,11 @@ void gpu_init(GLFWwindow *window) {
wgpuInstanceRequestAdapter(g_instance, &adapter_opts, handle_request_adapter,
&g_adapter);
#else
- wgpuInstanceRequestAdapter(g_instance, &adapter_opts,
- {nullptr, WGPUCallbackMode_WaitAnyOnly,
- handle_request_adapter, &g_adapter, nullptr});
+ WGPURequestAdapterCallbackInfo adapter_cb = {};
+ adapter_cb.mode = WGPUCallbackMode_WaitAnyOnly;
+ adapter_cb.callback = handle_request_adapter;
+ adapter_cb.userdata1 = &g_adapter;
+ wgpuInstanceRequestAdapter(g_instance, &adapter_opts, adapter_cb);
#endif
while (!g_adapter)
wgpuInstanceWaitAny(g_instance, 0, nullptr, 0);
@@ -510,9 +559,11 @@ void gpu_init(GLFWwindow *window) {
wgpuAdapterRequestDevice(g_adapter, &device_desc, handle_request_device,
&g_device);
#else
- wgpuAdapterRequestDevice(g_adapter, &device_desc,
- {nullptr, WGPUCallbackMode_WaitAnyOnly,
- handle_request_device, &g_device, nullptr});
+ WGPURequestDeviceCallbackInfo device_cb = {};
+ device_cb.mode = WGPUCallbackMode_WaitAnyOnly;
+ device_cb.callback = handle_request_device;
+ device_cb.userdata1 = &g_device;
+ wgpuAdapterRequestDevice(g_adapter, &device_desc, device_cb);
#endif
while (!g_device)
wgpuInstanceWaitAny(g_instance, 0, nullptr, 0);