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.h | 77 ++++++----------------------------------------------------- 1 file changed, 7 insertions(+), 70 deletions(-) (limited to 'src/gpu/gpu.h') diff --git a/src/gpu/gpu.h b/src/gpu/gpu.h index 45c6413..40274b9 100644 --- a/src/gpu/gpu.h +++ b/src/gpu/gpu.h @@ -4,74 +4,7 @@ #pragma once -#include - -#include // For strlen - -#if defined(DEMO_CROSS_COMPILE_WIN32) - -// Windows (MinGW) using wgpu-native v0.19.4.1 -#define WGPUOptionalBool_True true -#define WGPUOptionalBool_False false - -#include - -#include - -static inline const char* str_view(const char* str) { - return str; -} - -static inline const char* label_view(const char* str) { - return str; -} - -#define WGPUSType_ShaderSourceWGSL WGPUSType_ShaderModuleWGSLDescriptor - -using WGPUShaderSourceWGSL = WGPUShaderModuleWGSLDescriptor; - -#define WGPUSurfaceGetCurrentTextureStatus_SuccessOptimal \ - WGPUSurfaceGetCurrentTextureStatus_Success - -#define WGPUSurfaceGetCurrentTextureStatus_SuccessSuboptimal \ - WGPUSurfaceGetCurrentTextureStatus_Success - -#define WGPUCallbackMode_WaitAnyOnly 0 - -#else - -// Native (macOS/Linux) using newer wgpu-native - -#include - -#include - -static inline WGPUStringView str_view(const char* str) { - if (!str) - return {nullptr, 0}; - - return {str, strlen(str)}; -} - -static inline WGPUStringView label_view(const char* str) { - -#if !defined(STRIP_ALL) - - if (!str) - return {nullptr, 0}; - - return {str, strlen(str)}; - -#else - - (void)str; - - return {nullptr, 0}; - -#endif /* !defined(STRIP_ALL) */ -} - -#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */ +#include "platform.h" struct PlatformState; // Forward declaration @@ -123,7 +56,11 @@ inline void gpu_init_color_attachment(WGPURenderPassColorAttachment& attachment, attachment.view = view; attachment.loadOp = WGPULoadOp_Clear; attachment.storeOp = WGPUStoreOp_Store; -#if !defined(DEMO_CROSS_COMPILE_WIN32) + attachment.clearValue = {0.0f, 0.0f, 0.0f, 1.0f}; +#if defined(DEMO_CROSS_COMPILE_WIN32) + // depthSlice is handled via macro in platform.h if needed, + // but usually it's better to just avoid setting it on older wgpu-native +#else attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED; #endif } @@ -137,4 +74,4 @@ RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format, // Needed for render pipeline const char* shader_code, ResourceBinding* bindings, - int num_bindings); + int num_bindings); \ No newline at end of file -- cgit v1.2.3