summaryrefslogtreecommitdiff
path: root/src/gpu
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/effect.h6
-rw-r--r--src/gpu/effects/post_process_helper.h1
-rw-r--r--src/gpu/effects/shaders.cc36
-rw-r--r--src/gpu/gpu.cc37
-rw-r--r--src/gpu/gpu.h77
-rw-r--r--src/gpu/texture_manager.h6
6 files changed, 20 insertions, 143 deletions
diff --git a/src/gpu/effect.h b/src/gpu/effect.h
index 7e5e2ce..77504bd 100644
--- a/src/gpu/effect.h
+++ b/src/gpu/effect.h
@@ -4,12 +4,6 @@
#include <memory>
#include <vector>
-#if defined(DEMO_CROSS_COMPILE_WIN32)
-#include <webgpu/webgpu.h>
-#else
-#include <webgpu.h>
-#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */
-
class MainSequence;
class PostProcessEffect;
diff --git a/src/gpu/effects/post_process_helper.h b/src/gpu/effects/post_process_helper.h
index d3a37bd..1986ff3 100644
--- a/src/gpu/effects/post_process_helper.h
+++ b/src/gpu/effects/post_process_helper.h
@@ -4,7 +4,6 @@
#pragma once
#include "gpu/gpu.h"
-#include <webgpu.h>
// Helper to create a standard post-processing pipeline
WGPURenderPipeline create_post_process_pipeline(WGPUDevice device,
diff --git a/src/gpu/effects/shaders.cc b/src/gpu/effects/shaders.cc
index cd516cd..b2d184d 100644
--- a/src/gpu/effects/shaders.cc
+++ b/src/gpu/effects/shaders.cc
@@ -3,8 +3,6 @@
#include "../demo_effects.h"
-
-
#if defined(USE_TEST_ASSETS)
#include "test_assets.h"
@@ -15,36 +13,23 @@
#endif
-
-
#include "gpu/effects/shader_composer.h"
#include "util/asset_manager.h"
-
-
void InitShaderComposer() {
-
auto& sc = ShaderComposer::Get();
-
-
auto register_if_exists = [&](const char* name, AssetId id) {
+ size_t size;
- size_t size;
-
- const char* data = (const char*)GetAsset(id, &size);
-
- if (data) {
-
- sc.RegisterSnippet(name, std::string(data, size));
-
- }
+ const char* data = (const char*)GetAsset(id, &size);
+ if (data) {
+ sc.RegisterSnippet(name, std::string(data, size));
+ }
};
-
-
register_if_exists("common_uniforms", AssetId::ASSET_SHADER_COMMON_UNIFORMS);
register_if_exists("sdf_primitives", AssetId::ASSET_SHADER_SDF_PRIMITIVES);
@@ -52,23 +37,16 @@ void InitShaderComposer() {
register_if_exists("lighting", AssetId::ASSET_SHADER_LIGHTING);
register_if_exists("ray_box", AssetId::ASSET_SHADER_RAY_BOX);
-
}
-
-
// Helper to get asset string or empty string
static const char* SafeGetAsset(AssetId id) {
+ const uint8_t* data = GetAsset(id);
- const uint8_t* data = GetAsset(id);
-
- return data ? (const char*)data : "";
-
+ return data ? (const char*)data : "";
}
-
-
const char* main_shader_wgsl = SafeGetAsset(AssetId::ASSET_SHADER_MAIN);
const char* particle_compute_wgsl =
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 <GLFW/glfw3.h>
-#include <math.h>
-
-#include <algorithm>
#include <cassert>
+#include <cmath>
#include <cstdint>
+#include <cstdio>
#include <cstring>
#include <vector>
@@ -21,29 +19,6 @@
#include <iostream>
#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);
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
diff --git a/src/gpu/texture_manager.h b/src/gpu/texture_manager.h
index b97e6a8..f49e827 100644
--- a/src/gpu/texture_manager.h
+++ b/src/gpu/texture_manager.h
@@ -9,12 +9,6 @@
#include <string>
#include <vector>
-#if defined(DEMO_CROSS_COMPILE_WIN32)
-#include <webgpu/webgpu.h>
-#else
-#include <webgpu.h>
-#endif
-
struct ProceduralTextureDef {
int width;
int height;