summaryrefslogtreecommitdiff
path: root/src/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/gpu.cc34
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,