Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ By @beholdnec in [#8505](https://github.com/gfx-rs/wgpu/pull/8505).
- Fix incorrect checks for dynamic binding bounds when calling an encoder's `set_bind_group` in passes and bundles. By @ErichDonGubler in [#9308](https://github.com/gfx-rs/wgpu/pull/9308).
- Writes from `Queue::write_buffer` are now flushed by calls to `Buffer::map_async` for that same buffer, to prevent reading stale data. `on_submitted_work_done` also now flushes pending writes. By @andyleiserson in [#9307](https://github.com/gfx-rs/wgpu/pull/9307).
- Fix missing dependency feature activations when building wgpu-hal with gles/dx12 in isolation. By @wumpf in [#9325](https://github.com/gfx-rs/wgpu/pull/9325)
- Stencil clear and reference values are now truncated to 8 bits. By @beicause in [#9607](https://github.com/gfx-rs/wgpu/pull/9607).

#### naga

Expand Down
2 changes: 1 addition & 1 deletion cts_runner/test.lst
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_t
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth32float-stencil8";depthReadOnly=true;stencilReadOnly=true
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="stencil8";*

webgpu:api,operation,render_pass,storeOp:*
webgpu:api,operation,render_pass,*
webgpu:api,operation,render_pipeline,overrides:*
webgpu:api,operation,render_pipeline,pipeline_output_targets:color,component_count,blend:*
webgpu:api,operation,rendering,basic:clear:*
Expand Down
27 changes: 24 additions & 3 deletions wgpu-core/src/command/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ fn store_hal_ops(store: StoreOp) -> hal::AttachmentOps {
}
}

// Stencil clear and reference value should take the LSBs.
fn convert_stencil_value(value: u32, format: Option<wgt::TextureFormat>) -> u32 {
let Some(format) = format else {
return value;
};
let Some(stencil_format) = format.aspect_specific_format(wgt::TextureAspect::StencilOnly)
else {
return value;
};
// Currently only 8-bit stencil formats are supported
assert_eq!(stencil_format, wgt::TextureFormat::Stencil8);
value & 255
}

/// Describes an individual channel within a render pass, such as color, depth, or stencil.
///
/// A channel must either be read-only, or it must specify both load and store
Expand Down Expand Up @@ -1833,7 +1847,7 @@ impl Global {
}

arc_desc.depth_stencil_attachment =
// https://gpuweb.github.io/gpuweb/#abstract-opdef-gpurenderpassdepthstencilattachment-gpurenderpassdepthstencilattachment-valid-usage
// https://gpuweb.github.io/gpuweb/#abstract-opdef-gpurenderpassdepthstencilattachment-gpurenderpassdepthstencilattachment-valid-usage
if let Some(depth_stencil_attachment) = desc.depth_stencil_attachment {
let view = texture_views.get(depth_stencil_attachment.view).get()?;
view.same_device(device)?;
Expand Down Expand Up @@ -1868,7 +1882,9 @@ impl Global {
ResolvedPassChannel::ReadOnly
},
stencil: if format.has_stencil_aspect() {
depth_stencil_attachment.stencil.resolve(|clear| Ok(clear.unwrap_or_default()))?
depth_stencil_attachment.stencil.resolve(|clear| {
Ok(convert_stencil_value(clear.unwrap_or_default(), Some(format)))
})?
} else {
if depth_stencil_attachment.stencil.load_op.is_some() || depth_stencil_attachment.stencil.store_op.is_some() {
return Err(RenderPassErrorInner::InvalidAttachment(AttachmentError::StencilOpsWithoutAspect {
Expand Down Expand Up @@ -3502,7 +3518,12 @@ impl Global {
) -> Result<(), PassStateError> {
let scope = PassErrorScope::SetStencilReference;
let base = pass_base!(pass, scope);

let value = convert_stencil_value(
value,
pass.depth_stencil_attachment
.as_ref()
.map(|at| at.view.desc.format),
);
base.commands
.push(ArcRenderCommand::SetStencilReference(value));

Expand Down
Loading