Skip to content

Commit c6f79ae

Browse files
chirsz-everbartlomieju
authored andcommitted
fix(ext/webgpu): Allow depthClearValue to be undefined when depthLoadOp is not "clear" (#23850)
1 parent a454585 commit c6f79ae

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

ext/webgpu/command_encoder.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub struct GpuRenderPassColorAttachment {
7979
#[serde(rename_all = "camelCase")]
8080
pub struct GpuRenderPassDepthStencilAttachment {
8181
view: ResourceId,
82-
depth_clear_value: f32,
82+
depth_clear_value: Option<f32>,
8383
depth_load_op: Option<wgpu_core::command::LoadOp>,
8484
depth_store_op: Option<wgpu_core::command::StoreOp>,
8585
depth_read_only: bool,
@@ -168,7 +168,9 @@ pub fn op_webgpu_command_encoder_begin_render_pass(
168168
store_op: attachment
169169
.depth_store_op
170170
.unwrap_or(wgpu_core::command::StoreOp::Store),
171-
clear_value: attachment.depth_clear_value,
171+
// In "01_webgpu.js", `depthLoadOp` is cheked to ensure its value is not "clear"
172+
// when `depthClearValue` is undefined, so the default 0.0 doesn't matter.
173+
clear_value: attachment.depth_clear_value.unwrap_or(0.0),
172174
read_only: attachment.depth_read_only,
173175
},
174176
stencil: wgpu_core::command::PassChannel {

tests/unit/webgpu_test.ts

+30
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,36 @@ Deno.test({
496496
device.destroy();
497497
});
498498

499+
Deno.test({
500+
ignore: isWsl || isLinuxOrMacCI,
501+
}, async function beginRenderPassWithoutDepthClearValue() {
502+
const adapter = await navigator.gpu.requestAdapter();
503+
assert(adapter);
504+
const device = await adapter.requestDevice();
505+
assert(device);
506+
507+
const encoder = device.createCommandEncoder();
508+
509+
const depthTexture = device.createTexture({
510+
size: [256, 256],
511+
format: "depth32float",
512+
usage: GPUTextureUsage.RENDER_ATTACHMENT,
513+
});
514+
const depthView = depthTexture.createView();
515+
516+
const renderPass = encoder.beginRenderPass({
517+
colorAttachments: [],
518+
depthStencilAttachment: {
519+
view: depthView,
520+
depthLoadOp: "load",
521+
},
522+
});
523+
524+
assert(renderPass);
525+
526+
device.destroy();
527+
});
528+
499529
async function checkIsWsl() {
500530
return Deno.build.os === "linux" && await hasMicrosoftProcVersion();
501531

0 commit comments

Comments
 (0)