diff options
Diffstat (limited to 'src/gpu/gpu.cc')
| -rw-r--r-- | src/gpu/gpu.cc | 106 |
1 files changed, 55 insertions, 51 deletions
diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc index 8618280..a097efa 100644 --- a/src/gpu/gpu.cc +++ b/src/gpu/gpu.cc @@ -16,9 +16,9 @@ #include <cstring> #include <vector> -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) #include <iostream> -#endif +#endif /* !defined(STRIP_ALL) */ // --- WebGPU Headers & Compatibility --- #if defined(DEMO_CROSS_COMPILE_WIN32) @@ -28,7 +28,7 @@ #define WGPUSurfaceGetCurrentTextureStatus_SuccessSuboptimal \ WGPUSurfaceGetCurrentTextureStatus_Success #define WGPUCallbackMode_WaitAnyOnly 0 -static void wgpuInstanceWaitAny(WGPUInstance instance, size_t, void *, +static void wgpuInstanceWaitAny(WGPUInstance instance, size_t, void*, uint64_t) { wgpuInstanceProcessEvents(instance); } @@ -40,7 +40,7 @@ static void set_error_callback(WGPUDevice device, WGPUUncapturedErrorCallback callback) { // Handled in descriptor for new API. } -#endif +#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ static WGPUInstance g_instance = nullptr; static WGPUAdapter g_adapter = nullptr; @@ -54,7 +54,7 @@ static MainSequence g_main_sequence; // --- Helper Functions --- GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage, - const void *data) { + const void* data) { WGPUBufferDescriptor desc = {}; desc.label = label_view("GpuBuffer"); desc.usage = (WGPUBufferUsage)usage; // Cast for C++ strictness with enums @@ -64,7 +64,7 @@ GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage, WGPUBuffer buffer = wgpuDeviceCreateBuffer(device, &desc); if (data) { - void *ptr = wgpuBufferGetMappedRange(buffer, 0, size); + void* ptr = wgpuBufferGetMappedRange(buffer, 0, size); memcpy(ptr, data, size); wgpuBufferUnmap(buffer); } @@ -73,8 +73,8 @@ GpuBuffer gpu_create_buffer(WGPUDevice device, size_t size, uint32_t usage, } RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format, - const char *shader_code, - ResourceBinding *bindings, int num_bindings) { + const char* shader_code, + ResourceBinding* bindings, int num_bindings) { RenderPass pass = {}; // Create Shader Module @@ -160,8 +160,8 @@ RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format, return pass; } -ComputePass gpu_create_compute_pass(WGPUDevice device, const char *shader_code, - ResourceBinding *bindings, +ComputePass gpu_create_compute_pass(WGPUDevice device, const char* shader_code, + ResourceBinding* bindings, int num_bindings) { ComputePass pass = {}; @@ -220,98 +220,98 @@ ComputePass gpu_create_compute_pass(WGPUDevice device, const char *shader_code, // --- Main Init/Draw --- -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) #if defined(DEMO_CROSS_COMPILE_WIN32) static void handle_request_adapter(WGPURequestAdapterStatus status, - WGPUAdapter adapter, const char *message, - void *userdata) { + WGPUAdapter adapter, const char* message, + void* userdata) { if (status == WGPURequestAdapterStatus_Success) { - *((WGPUAdapter *)userdata) = adapter; + *((WGPUAdapter*)userdata) = adapter; } else { printf("Request adapter failed: %s\n", message ? message : "Unknown"); } } static void handle_request_device(WGPURequestDeviceStatus status, - WGPUDevice device, const char *message, - void *userdata) { + WGPUDevice device, const char* message, + void* userdata) { if (status == WGPURequestDeviceStatus_Success) { - *((WGPUDevice *)userdata) = device; + *((WGPUDevice*)userdata) = device; } else { printf("Request device failed: %s\n", message ? message : "Unknown"); } } -static void handle_device_error(WGPUErrorType type, const char *message, - void *userdata) { +static void handle_device_error(WGPUErrorType type, const char* message, + void* userdata) { printf("WebGPU Error: %s\n", message ? message : "Unknown"); } #else static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, - void *userdata, void *userdata2) { + void* userdata, void* userdata2) { (void)userdata2; if (status == WGPURequestAdapterStatus_Success) { - *((WGPUAdapter *)userdata) = adapter; + *((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* userdata, void* userdata2) { (void)userdata2; if (status == WGPURequestDeviceStatus_Success) { - *((WGPUDevice *)userdata) = device; + *((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 *userdata2) { +static void handle_device_error(const WGPUDevice* device, WGPUErrorType type, + WGPUStringView message, void* userdata, + void* userdata2) { (void)device; (void)userdata; (void)userdata2; printf("WebGPU Error: %.*s\n", (int)message.length, message.data); } -#endif +#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ #else // STRIP_ALL versions #if defined(DEMO_CROSS_COMPILE_WIN32) static void handle_request_adapter(WGPURequestAdapterStatus status, - WGPUAdapter adapter, const char *message, - void *userdata) { + WGPUAdapter adapter, const char* message, + void* userdata) { if (status == WGPURequestAdapterStatus_Success) { - *((WGPUAdapter *)userdata) = adapter; + *((WGPUAdapter*)userdata) = adapter; } } static void handle_request_device(WGPURequestDeviceStatus status, - WGPUDevice device, const char *message, - void *userdata) { + WGPUDevice device, const char* message, + void* userdata) { if (status == WGPURequestDeviceStatus_Success) { - *((WGPUDevice *)userdata) = device; + *((WGPUDevice*)userdata) = device; } } #else static void handle_request_adapter(WGPURequestAdapterStatus status, WGPUAdapter adapter, WGPUStringView message, - void *userdata, void *userdata2) { + void* userdata, void* userdata2) { (void)userdata2; if (status == WGPURequestAdapterStatus_Success) { - *((WGPUAdapter *)userdata) = adapter; + *((WGPUAdapter*)userdata) = adapter; } } static void handle_request_device(WGPURequestDeviceStatus status, WGPUDevice device, WGPUStringView message, - void *userdata, void *userdata2) { + void* userdata, void* userdata2) { (void)userdata2; if (status == WGPURequestDeviceStatus_Success) { - *((WGPUDevice *)userdata) = device; + *((WGPUDevice*)userdata) = device; } } -#endif -#endif +#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ +#endif /* !defined(STRIP_ALL) */ -void gpu_init(GLFWwindow *window, int width, int height) { +void gpu_init(GLFWwindow* window, int width, int height) { g_instance = wgpuCreateInstance(nullptr); g_surface = platform_create_wgpu_surface(g_instance); @@ -328,15 +328,16 @@ void gpu_init(GLFWwindow *window, int width, int height) { 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); +#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ + while (!g_adapter) + wgpuInstanceWaitAny(g_instance, 0, nullptr, 0); WGPUDeviceDescriptor device_desc = {}; -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) #if !defined(DEMO_CROSS_COMPILE_WIN32) device_desc.uncapturedErrorCallbackInfo.callback = handle_device_error; -#endif -#endif +#endif /* !defined(DEMO_CROSS_COMPILE_WIN32) */ +#endif /* !defined(STRIP_ALL) */ #if defined(DEMO_CROSS_COMPILE_WIN32) wgpuAdapterRequestDevice(g_adapter, &device_desc, handle_request_device, @@ -347,12 +348,13 @@ void gpu_init(GLFWwindow *window, int width, int height) { 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); +#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ + while (!g_device) + wgpuInstanceWaitAny(g_instance, 0, nullptr, 0); #if defined(DEMO_CROSS_COMPILE_WIN32) && !defined(STRIP_ALL) set_error_callback(g_device, handle_device_error); -#endif +#endif /* defined(DEMO_CROSS_COMPILE_WIN32) && !defined(STRIP_ALL) */ g_queue = wgpuDeviceGetQueue(g_device); @@ -378,10 +380,12 @@ void gpu_draw(float audio_peak, float aspect_ratio, float time, float beat) { g_main_sequence.render_frame(time, beat, audio_peak, aspect_ratio, g_surface); } -#ifndef STRIP_ALL +#if !defined(STRIP_ALL) void gpu_simulate_until(float time) { g_main_sequence.simulate_until(time, 1.0f / 60.0f); } -#endif +#endif /* !defined(STRIP_ALL) */ -void gpu_shutdown() { g_main_sequence.shutdown(); }
\ No newline at end of file +void gpu_shutdown() { + g_main_sequence.shutdown(); +} |
