summaryrefslogtreecommitdiff
path: root/src/gpu
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-08 09:12:48 +0100
committerskal <pascal.massimino@gmail.com>2026-02-08 09:12:48 +0100
commitec98466b62797fe7e71f35f009a891e72f4ae85a (patch)
tree0f86391c020a6d223ccd4a46ccc9c45aa87fe866 /src/gpu
parent16c2cdce6ad1d89d3c537f2c2cff743449925125 (diff)
Revert "feat(platform): Centralize platform-specific WebGPU code and improve shader composition"
This reverts commit 16c2cdce6ad1d89d3c537f2c2cff743449925125.
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/effect.cc6
-rw-r--r--src/gpu/effects/shader_composer.cc10
-rw-r--r--src/gpu/effects/shader_composer.h5
-rw-r--r--src/gpu/gpu.cc111
-rw-r--r--src/gpu/texture_manager.cc17
5 files changed, 125 insertions, 24 deletions
diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc
index 9e769eb..a1b45f1 100644
--- a/src/gpu/effect.cc
+++ b/src/gpu/effect.cc
@@ -260,7 +260,9 @@ void MainSequence::render_frame(float global_time, float beat, float peak,
scene_attachment.loadOp = WGPULoadOp_Clear;
scene_attachment.storeOp = WGPUStoreOp_Store;
scene_attachment.clearValue = {0, 0, 0, 1};
+#if !defined(DEMO_CROSS_COMPILE_WIN32)
scene_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
+#endif /* !defined(DEMO_CROSS_COMPILE_WIN32) */
WGPURenderPassDepthStencilAttachment depth_attachment = {};
depth_attachment.view = depth_view_;
@@ -300,7 +302,9 @@ void MainSequence::render_frame(float global_time, float beat, float peak,
final_attachment.resolveTarget = nullptr;
final_attachment.loadOp = WGPULoadOp_Load;
final_attachment.storeOp = WGPUStoreOp_Store;
+#if !defined(DEMO_CROSS_COMPILE_WIN32)
final_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
+#endif /* !defined(DEMO_CROSS_COMPILE_WIN32) */
WGPURenderPassDescriptor final_desc = {
.colorAttachmentCount = 1, .colorAttachments = &final_attachment};
WGPURenderPassEncoder final_pass =
@@ -334,7 +338,9 @@ void MainSequence::render_frame(float global_time, float beat, float peak,
pp_attachment.resolveTarget = nullptr;
pp_attachment.loadOp = WGPULoadOp_Load;
pp_attachment.storeOp = WGPUStoreOp_Store;
+#if !defined(DEMO_CROSS_COMPILE_WIN32)
pp_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
+#endif /* !defined(DEMO_CROSS_COMPILE_WIN32) */
WGPURenderPassDescriptor pp_desc = {.colorAttachmentCount = 1,
.colorAttachments = &pp_attachment};
WGPURenderPassEncoder pp_pass =
diff --git a/src/gpu/effects/shader_composer.cc b/src/gpu/effects/shader_composer.cc
index 5cd8699..b746f8b 100644
--- a/src/gpu/effects/shader_composer.cc
+++ b/src/gpu/effects/shader_composer.cc
@@ -2,7 +2,6 @@
// It implements the ShaderComposer class.
#include "gpu/effects/shader_composer.h"
-#include "util/asset_manager.h"
#include <set>
#include <sstream>
@@ -87,12 +86,3 @@ ShaderComposer::Compose(const std::vector<std::string>& dependencies,
return ss.str();
}
-
-std::string
-ShaderComposer::Compose(const std::vector<std::string>& dependencies,
- AssetId main_code_asset_id,
- const CompositionMap& substitutions) {
- size_t size;
- const char* main_code = reinterpret_cast<const char*>(GetAsset(main_code_asset_id, &size));
- return Compose(dependencies, std::string(main_code, size), substitutions);
-}
diff --git a/src/gpu/effects/shader_composer.h b/src/gpu/effects/shader_composer.h
index 961ffcb..9eb43f4 100644
--- a/src/gpu/effects/shader_composer.h
+++ b/src/gpu/effects/shader_composer.h
@@ -3,7 +3,6 @@
#pragma once
-#include "generated/assets.h" // For AssetId
#include <map>
#include <set>
#include <string>
@@ -24,10 +23,6 @@ class ShaderComposer {
std::string Compose(const std::vector<std::string>& dependencies,
const std::string& main_code,
const CompositionMap& substitutions = {});
-
- std::string Compose(const std::vector<std::string>& dependencies,
- AssetId main_code_asset_id,
- const CompositionMap& substitutions = {});
private:
ShaderComposer() = default;
diff --git a/src/gpu/gpu.cc b/src/gpu/gpu.cc
index c61c605..9776eac 100644
--- a/src/gpu/gpu.cc
+++ b/src/gpu/gpu.cc
@@ -57,7 +57,11 @@ RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format,
RenderPass pass = {};
// Create Shader Module
- WGPUShaderModuleDescriptor shader_desc = platform_create_shader_module_descriptor(shader_code);
+ WGPUShaderSourceWGSL wgsl_src = {};
+ wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL;
+ wgsl_src.code = str_view(shader_code);
+ WGPUShaderModuleDescriptor shader_desc = {};
+ shader_desc.nextInChain = &wgsl_src.chain;
WGPUShaderModule shader_module =
wgpuDeviceCreateShaderModule(device, &shader_desc);
@@ -141,7 +145,7 @@ RenderPass gpu_create_render_pass(WGPUDevice device, WGPUTextureFormat format,
depth_stencil.format = WGPUTextureFormat_Depth24Plus;
depth_stencil.depthWriteEnabled = WGPUOptionalBool_False;
depth_stencil.depthCompare = WGPUCompareFunction_Always;
- PLATFORM_SET_PIPELINE_DEPTH_STENCIL(pipeline_desc, &depth_stencil);
+ pipeline_desc.depthStencil = &depth_stencil;
pass.pipeline = wgpuDeviceCreateRenderPipeline(device, &pipeline_desc);
@@ -153,7 +157,11 @@ ComputePass gpu_create_compute_pass(WGPUDevice device, const char* shader_code,
int num_bindings) {
ComputePass pass = {};
- WGPUShaderModuleDescriptor shader_desc = platform_create_shader_module_descriptor(shader_code);
+ WGPUShaderSourceWGSL wgsl_src = {};
+ wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL;
+ wgsl_src.code = str_view(shader_code);
+ WGPUShaderModuleDescriptor shader_desc = {};
+ shader_desc.nextInChain = &wgsl_src.chain;
WGPUShaderModule shader_module =
wgpuDeviceCreateShaderModule(device, &shader_desc);
@@ -206,11 +214,49 @@ ComputePass gpu_create_compute_pass(WGPUDevice device, const char* shader_code,
#if !defined(STRIP_ALL)
#if defined(DEMO_CROSS_COMPILE_WIN32)
+static void handle_request_adapter(WGPURequestAdapterStatus status,
+ WGPUAdapter adapter, const char* message,
+ void* userdata) {
+ if (status == WGPURequestAdapterStatus_Success) {
+ *((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) {
+ if (status == WGPURequestDeviceStatus_Success) {
+ *((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) {
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)userdata2;
+ if (status == WGPURequestAdapterStatus_Success) {
+ *((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)userdata2;
+ if (status == WGPURequestDeviceStatus_Success) {
+ *((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) {
@@ -220,6 +266,41 @@ static void handle_device_error(const WGPUDevice* device, WGPUErrorType type,
printf("WebGPU Error: %.*s\n", (int)message.length, message.data);
}
#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) {
+ if (status == WGPURequestAdapterStatus_Success) {
+ *((WGPUAdapter*)userdata) = adapter;
+ }
+}
+static void handle_request_device(WGPURequestDeviceStatus status,
+ WGPUDevice device, const char* message,
+ void* userdata) {
+ if (status == WGPURequestDeviceStatus_Success) {
+ *((WGPUDevice*)userdata) = device;
+ }
+}
+#else
+static void handle_request_adapter(WGPURequestAdapterStatus status,
+ WGPUAdapter adapter, WGPUStringView message,
+ void* userdata, void* userdata2) {
+ (void)userdata2;
+ if (status == WGPURequestAdapterStatus_Success) {
+ *((WGPUAdapter*)userdata) = adapter;
+ }
+}
+static void handle_request_device(WGPURequestDeviceStatus status,
+ WGPUDevice device, WGPUStringView message,
+ void* userdata, void* userdata2) {
+ (void)userdata2;
+ if (status == WGPURequestDeviceStatus_Success) {
+ *((WGPUDevice*)userdata) = device;
+ }
+}
+#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */
#endif /* !defined(STRIP_ALL) */
void gpu_init(PlatformState* platform_state) {
@@ -230,8 +311,16 @@ void gpu_init(PlatformState* platform_state) {
adapter_opts.compatibleSurface = g_surface;
adapter_opts.powerPreference = WGPUPowerPreference_HighPerformance;
- platform_wgpu_request_adapter(g_instance, &adapter_opts, &g_adapter);
-
+#if defined(DEMO_CROSS_COMPILE_WIN32)
+ wgpuInstanceRequestAdapter(g_instance, &adapter_opts, handle_request_adapter,
+ &g_adapter);
+#else
+ WGPURequestAdapterCallbackInfo adapter_cb = {};
+ adapter_cb.mode = WGPUCallbackMode_WaitAnyOnly;
+ adapter_cb.callback = handle_request_adapter;
+ adapter_cb.userdata1 = &g_adapter;
+ wgpuInstanceRequestAdapter(g_instance, &adapter_opts, adapter_cb);
+#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */
while (!g_adapter)
platform_wgpu_wait_any(g_instance);
@@ -242,8 +331,16 @@ void gpu_init(PlatformState* platform_state) {
#endif /* !defined(DEMO_CROSS_COMPILE_WIN32) */
#endif /* !defined(STRIP_ALL) */
- platform_wgpu_request_device(g_adapter, &device_desc, &g_device);
-
+#if defined(DEMO_CROSS_COMPILE_WIN32)
+ wgpuAdapterRequestDevice(g_adapter, &device_desc, handle_request_device,
+ &g_device);
+#else
+ WGPURequestDeviceCallbackInfo device_cb = {};
+ device_cb.mode = WGPUCallbackMode_WaitAnyOnly;
+ device_cb.callback = handle_request_device;
+ device_cb.userdata1 = &g_device;
+ wgpuAdapterRequestDevice(g_adapter, &device_desc, device_cb);
+#endif /* defined(DEMO_CROSS_COMPILE_WIN32) */
while (!g_device)
platform_wgpu_wait_any(g_instance);
diff --git a/src/gpu/texture_manager.cc b/src/gpu/texture_manager.cc
index e69425f..0c30c94 100644
--- a/src/gpu/texture_manager.cc
+++ b/src/gpu/texture_manager.cc
@@ -2,10 +2,19 @@
// It implements the TextureManager.
#include "gpu/texture_manager.h"
-#include "platform/platform.h" // Include for WGPU_TEX_COPY_INFO and WGPU_TEX_DATA_LAYOUT
#include <cstdio>
#include <vector>
+#if defined(DEMO_CROSS_COMPILE_WIN32)
+// Old API
+#define WGPU_TEX_COPY_INFO WGPUImageCopyTexture
+#define WGPU_TEX_DATA_LAYOUT WGPUTextureDataLayout
+#else
+// New API
+#define WGPU_TEX_COPY_INFO WGPUTexelCopyTextureInfo
+#define WGPU_TEX_DATA_LAYOUT WGPUTexelCopyBufferLayout
+#endif
+
void TextureManager::init(WGPUDevice device, WGPUQueue queue) {
device_ = device;
queue_ = queue;
@@ -51,7 +60,11 @@ void TextureManager::create_texture(const std::string& name, int width,
tex_desc.format = WGPUTextureFormat_RGBA8Unorm;
tex_desc.mipLevelCount = 1;
tex_desc.sampleCount = 1;
- tex_desc.label = label_view(name.c_str());
+#if defined(DEMO_CROSS_COMPILE_WIN32)
+ tex_desc.label = nullptr;
+#else
+ tex_desc.label = {nullptr, 0};
+#endif
WGPUTexture texture = wgpuDeviceCreateTexture(device_, &tex_desc);