summaryrefslogtreecommitdiff
path: root/src/gpu/effect.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-01-31 20:44:23 +0100
committerskal <pascal.massimino@gmail.com>2026-01-31 20:44:23 +0100
commitc6b33c5e9b2325ca472dab8c4b64d1dab7b2885a (patch)
treebdd7ad7a253562a5860fb9db20a9179931401672 /src/gpu/effect.cc
parent4a55151d1a30f03ce1aa67e4c952ff6759c480c9 (diff)
fix(gpu): resolve multiple WebGPU validation and runtime errors
- Fixed 'Invalid sample count 0' and 'Invalid anisotropic clamp: 0' by ensuring explicit pipeline and sampler states. - Resolved WGSL parsing errors by replacing swizzle assignments in compute shaders. - Fixed 'Texture destroyed' error in render_frame by reordering command submission and resource presentation/release. - Added WGPU_DEPTH_SLICE_UNDEFINED for Windows compatibility and ensured consistent resolveTarget initialization. - Cleaned up PassthroughEffect bind group layout mismatch and redundant string helper definitions. - Verified all tests pass and applied consistent formatting.
Diffstat (limited to 'src/gpu/effect.cc')
-rw-r--r--src/gpu/effect.cc63
1 files changed, 33 insertions, 30 deletions
diff --git a/src/gpu/effect.cc b/src/gpu/effect.cc
index 0ac9063..f9ebf0c 100644
--- a/src/gpu/effect.cc
+++ b/src/gpu/effect.cc
@@ -175,12 +175,11 @@ void MainSequence::render_frame(float global_time, float beat, float peak,
// 2. Scene Pass (to A)
WGPURenderPassColorAttachment scene_attachment = {};
scene_attachment.view = framebuffer_view_a_;
+ scene_attachment.resolveTarget = nullptr;
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
WGPURenderPassDescriptor scene_desc = {.colorAttachmentCount = 1,
.colorAttachments = &scene_attachment};
WGPURenderPassEncoder scene_pass =
@@ -192,48 +191,52 @@ void MainSequence::render_frame(float global_time, float beat, float peak,
wgpuRenderPassEncoderEnd(scene_pass);
// 3. Post Chain
+ WGPUSurfaceTexture st = {};
+ WGPUTextureView final_view = nullptr;
+
if (post_effects.empty()) {
- WGPUSurfaceTexture st;
wgpuSurfaceGetCurrentTexture(surface, &st);
- WGPUTextureView final_view = wgpuTextureCreateView(st.texture, nullptr);
+ final_view = wgpuTextureCreateView(st.texture, nullptr);
passthrough_effect_->update_bind_group(framebuffer_view_a_);
- WGPURenderPassColorAttachment final_attachment = {.view = final_view,
- .loadOp = WGPULoadOp_Load,
- .storeOp =
- WGPUStoreOp_Store};
+ WGPURenderPassColorAttachment final_attachment = {};
+ final_attachment.view = final_view;
+ final_attachment.resolveTarget = nullptr;
+ final_attachment.loadOp = WGPULoadOp_Load;
+ final_attachment.storeOp = WGPUStoreOp_Store;
+ final_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
WGPURenderPassDescriptor final_desc = {
.colorAttachmentCount = 1, .colorAttachments = &final_attachment};
WGPURenderPassEncoder final_pass =
wgpuCommandEncoderBeginRenderPass(encoder, &final_desc);
passthrough_effect_->render(final_pass, 0, 0, 0, aspect_ratio);
wgpuRenderPassEncoderEnd(final_pass);
-
- wgpuTextureViewRelease(final_view);
- wgpuSurfacePresent(surface);
- wgpuTextureRelease(st.texture);
} else {
WGPUTextureView current_input = framebuffer_view_a_;
for (size_t i = 0; i < post_effects.size(); ++i) {
bool is_last = (i == post_effects.size() - 1);
- WGPUSurfaceTexture st;
- if (is_last)
- wgpuSurfaceGetCurrentTexture(surface, &st);
+ WGPUTextureView current_output = nullptr;
- WGPUTextureView current_output =
- is_last
- ? wgpuTextureCreateView(st.texture, nullptr)
- : (current_input == framebuffer_view_a_ ? framebuffer_view_b_
- : framebuffer_view_a_);
+ if (is_last) {
+ wgpuSurfaceGetCurrentTexture(surface, &st);
+ final_view = wgpuTextureCreateView(st.texture, nullptr);
+ current_output = final_view;
+ } else {
+ current_output =
+ (current_input == framebuffer_view_a_ ? framebuffer_view_b_
+ : framebuffer_view_a_);
+ }
PostProcessEffect *pp =
static_cast<PostProcessEffect *>(post_effects[i]->effect.get());
pp->update_bind_group(current_input);
- WGPURenderPassColorAttachment pp_attachment = {.view = current_output,
- .loadOp = WGPULoadOp_Load,
- .storeOp =
- WGPUStoreOp_Store};
+ WGPURenderPassColorAttachment pp_attachment = {};
+ pp_attachment.view = current_output;
+ pp_attachment.resolveTarget = nullptr;
+ pp_attachment.loadOp = WGPULoadOp_Load;
+ pp_attachment.storeOp = WGPUStoreOp_Store;
+ pp_attachment.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED;
WGPURenderPassDescriptor pp_desc = {.colorAttachmentCount = 1,
.colorAttachments = &pp_attachment};
WGPURenderPassEncoder pp_pass =
@@ -241,18 +244,18 @@ void MainSequence::render_frame(float global_time, float beat, float peak,
pp->render(pp_pass, global_time - post_effects[i]->start_time, beat, peak,
aspect_ratio);
wgpuRenderPassEncoderEnd(pp_pass);
-
- if (is_last) {
- wgpuTextureViewRelease(current_output);
- wgpuSurfacePresent(surface);
- wgpuTextureRelease(st.texture);
- }
current_input = current_output;
}
}
WGPUCommandBuffer commands = wgpuCommandEncoderFinish(encoder, nullptr);
wgpuQueueSubmit(queue, 1, &commands);
+
+ if (st.texture) {
+ wgpuTextureViewRelease(final_view);
+ wgpuSurfacePresent(surface);
+ wgpuTextureRelease(st.texture);
+ }
}
void MainSequence::shutdown() {