From 2c37608ad39072a231cf231e67dae3325493bece Mon Sep 17 00:00:00 2001 From: Niklas Korz Date: Mon, 10 Apr 2023 11:21:17 +0200 Subject: [PATCH] Web: handle None for depth_ops and stencil_ops (#3660) --- CHANGELOG.md | 4 +++ wgpu/src/backend/web.rs | 56 ++++++++++++++++------------------------- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31d54440a..28cc0e4cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -148,6 +148,10 @@ By @cwfitzgerald in [#3610](https://github.com/gfx-rs/wgpu/pull/3610). ### Bug Fixes +#### WebGPU + +- Fix handling of `None` values for `depth_ops` and `stencil_ops` in `RenderPassDescriptor::depth_stencil_attachment`. By @niklaskorz in [#3660](https://github.com/gfx-rs/wgpu/pull/3660) + #### Metal - Fix incorrect mipmap being sampled when using `MinLod <= 0.0` and `MaxLod >= 32.0` or when the fragment shader samples different Lods in the same quad. By @cwfitzgerald in [#3610](https://github.com/gfx-rs/wgpu/pull/3610). diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index f6f465c46..c373e1573 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -2079,44 +2079,32 @@ impl crate::context::Context for Context { } if let Some(dsa) = &desc.depth_stencil_attachment { - let mut depth_clear_value = 0.0; - let mut stencil_clear_value = 0; - let (depth_load_op, depth_store_op) = match dsa.depth_ops { - Some(ref ops) => { - let load_op = match ops.load { - crate::LoadOp::Clear(v) => { - depth_clear_value = v; - web_sys::GpuLoadOp::Clear - } - crate::LoadOp::Load => web_sys::GpuLoadOp::Load, - }; - (load_op, map_store_op(ops.store)) - } - None => (web_sys::GpuLoadOp::Load, web_sys::GpuStoreOp::Store), - }; - let (stencil_load_op, stencil_store_op) = match dsa.stencil_ops { - Some(ref ops) => { - let load_op = match ops.load { - crate::LoadOp::Clear(v) => { - stencil_clear_value = v; - web_sys::GpuLoadOp::Clear - } - crate::LoadOp::Load => web_sys::GpuLoadOp::Load, - }; - (load_op, map_store_op(ops.store)) - } - None => (web_sys::GpuLoadOp::Load, web_sys::GpuStoreOp::Store), - }; let mut mapped_depth_stencil_attachment = web_sys::GpuRenderPassDepthStencilAttachment::new( &<::TextureViewId>::from(dsa.view.id).0, ); - mapped_depth_stencil_attachment.depth_clear_value(depth_clear_value); - mapped_depth_stencil_attachment.depth_load_op(depth_load_op); - mapped_depth_stencil_attachment.depth_store_op(depth_store_op); - mapped_depth_stencil_attachment.stencil_clear_value(stencil_clear_value); - mapped_depth_stencil_attachment.stencil_load_op(stencil_load_op); - mapped_depth_stencil_attachment.stencil_store_op(stencil_store_op); + if let Some(ref ops) = dsa.depth_ops { + let load_op = match ops.load { + crate::LoadOp::Clear(v) => { + mapped_depth_stencil_attachment.depth_clear_value(v); + web_sys::GpuLoadOp::Clear + } + crate::LoadOp::Load => web_sys::GpuLoadOp::Load, + }; + mapped_depth_stencil_attachment.depth_load_op(load_op); + mapped_depth_stencil_attachment.depth_store_op(map_store_op(ops.store)); + } + if let Some(ref ops) = dsa.stencil_ops { + let load_op = match ops.load { + crate::LoadOp::Clear(v) => { + mapped_depth_stencil_attachment.stencil_clear_value(v); + web_sys::GpuLoadOp::Clear + } + crate::LoadOp::Load => web_sys::GpuLoadOp::Load, + }; + mapped_depth_stencil_attachment.stencil_load_op(load_op); + mapped_depth_stencil_attachment.stencil_store_op(map_store_op(ops.store)); + } mapped_desc.depth_stencil_attachment(&mapped_depth_stencil_attachment); }