Mask stencil clear value and reference value with 255 (#9607)

This commit is contained in:
Luo Zhihao authored and GitHub committed 2026-06-02 17:09:58 +00:00
1 parent e4e2c451d2
commit 8b7e9edcdb
3 files changed
+26 -4

No files matched your search

+24 -3
View File
@@ -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
@@ -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)?;
@@ -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 {
@@ -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));