From bf46e44e1cb6027a072819a2a3aa3be32651f6e1 Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 3 Feb 2026 18:44:41 +0100 Subject: refactor: Task #20 - Platform & Code Hygiene - Consolidated all WebGPU shims and platform-specific logic into src/platform.h. - Refactored platform_init to return PlatformState by value and platform_poll to automatically refresh time and aspect_ratio. - Removed STL dependencies (std::map, std::vector, std::string) from AssetManager and Procedural subsystems. - Fixed Windows cross-compilation by adjusting include paths and linker flags in CMakeLists.txt and updating build_win.sh. - Removed redundant direct inclusions of GLFW/glfw3.h and WebGPU headers across the project. - Applied clang-format and updated documentation. handoff(Gemini): Completed Task #20 and 20.1. Platform abstraction is now unified, and core paths are STL-free. Windows build is stable. --- src/gpu/gpu.cc | 37 ++++++------------------------------- 1 file changed, 6 insertions(+), 31 deletions(-) (limited to 'src/gpu/gpu.cc') diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc index 8342c94..1f71711 100644 --- a/src/gpu/gpu.cc +++ b/src/gpu/gpu.cc @@ -5,15 +5,13 @@ #include "gpu.h" #include "demo_effects.h" #include "effect.h" -#include "platform.h" #include "gpu/effects/shaders.h" +#include "platform.h" -#include -#include - -#include #include +#include #include +#include #include #include @@ -21,29 +19,6 @@ #include #endif /* !defined(STRIP_ALL) */ -// --- WebGPU Headers & Compatibility --- -#if defined(DEMO_CROSS_COMPILE_WIN32) -// Renamed Types/Enums -#define WGPUOptionalBool_False false -#define WGPUSurfaceGetCurrentTextureStatus_SuccessOptimal \ - WGPUSurfaceGetCurrentTextureStatus_Success -#define WGPUSurfaceGetCurrentTextureStatus_SuccessSuboptimal \ - WGPUSurfaceGetCurrentTextureStatus_Success -#define WGPUCallbackMode_WaitAnyOnly 0 -static void wgpuInstanceWaitAny(WGPUInstance instance, size_t, void*, - uint64_t) { - wgpuInstanceProcessEvents(instance); -} -static void set_error_callback(WGPUDevice device, WGPUErrorCallback callback) { - wgpuDeviceSetUncapturedErrorCallback(device, callback, nullptr); -} -#else -static void set_error_callback(WGPUDevice device, - WGPUUncapturedErrorCallback callback) { - // Handled in descriptor for new API. -} -#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ - static WGPUInstance g_instance = nullptr; static WGPUAdapter g_adapter = nullptr; static WGPUDevice g_device = nullptr; @@ -331,7 +306,7 @@ void gpu_init(PlatformState* platform_state) { wgpuInstanceRequestAdapter(g_instance, &adapter_opts, adapter_cb); #endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ while (!g_adapter) - wgpuInstanceWaitAny(g_instance, 0, nullptr, 0); + platform_wgpu_wait_any(g_instance); WGPUDeviceDescriptor device_desc = {}; #if !defined(STRIP_ALL) @@ -351,10 +326,10 @@ void gpu_init(PlatformState* platform_state) { wgpuAdapterRequestDevice(g_adapter, &device_desc, device_cb); #endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ while (!g_device) - wgpuInstanceWaitAny(g_instance, 0, nullptr, 0); + platform_wgpu_wait_any(g_instance); #if defined(DEMO_CROSS_COMPILE_WIN32) && !defined(STRIP_ALL) - set_error_callback(g_device, handle_device_error); + platform_wgpu_set_error_callback(g_device, handle_device_error); #endif /* defined(DEMO_CROSS_COMPILE_WIN32) && !defined(STRIP_ALL) */ g_queue = wgpuDeviceGetQueue(g_device); -- cgit v1.2.3