diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-03 18:44:41 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-03 18:44:41 +0100 |
| commit | bf46e44e1cb6027a072819a2a3aa3be32651f6e1 (patch) | |
| tree | 21267e7ef52fd91e7b99271ed87e275e91b3de3c /src/gpu/gpu.h | |
| parent | 815c428dea14a6a1ea5c421c400985d0c14d473d (diff) | |
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.
Diffstat (limited to 'src/gpu/gpu.h')
| -rw-r--r-- | src/gpu/gpu.h | 77 |
1 files changed, 7 insertions, 70 deletions
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 <webgpu.h> - -#include <cstring> // 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 <webgpu/webgpu.h> - -#include <webgpu/wgpu.h> - -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 <webgpu.h> - -#include <wgpu.h> - -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 |
