fix(dx12): Map components properly for textureLoad from stencil (#9520)

This commit is contained in:
Andy Leiserson authored and GitHub committed 2026-05-12 12:00:21 +02:00
1 parent b2adc9cfce
commit 928ddb40f5
5 files changed
+55 -1

No files matched your search

+1
View File
@@ -215,6 +215,7 @@ By @beholdnec in [#8505](https://github.com/gfx-rs/wgpu/pull/8505).
- Fixed use of a texture view without `TextureUsage::TEXTURE_BINDING` as a read-only depth attachment. By @andyleiserson in [#9346](https://github.com/gfx-rs/wgpu/pull/9346).
- Fixed a `debug_assert` during stride validation for indirect multi draw. By @kristoff3r in [#9332](https://github.com/gfx-rs/wgpu/pull/9332)
- Fixed stencil values read with `textureLoad` appearing in G instead of R. By @andyleiserson in [#9520](https://github.com/gfx-rs/wgpu/pull/9520).
#### Metal
+5
View File
@@ -11,6 +11,11 @@
//
// The `cts_runner` integration test `lst_files_are_sorted` verifies that test selectors
// appear in this file in order -- including ones in comments.
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth24plus-stencil8";depthReadOnly=false;stencilReadOnly=true // https://github.com/gfx-rs/wgpu/issues/8705
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth24plus-stencil8";depthReadOnly=true;stencilReadOnly=false // https://github.com/gfx-rs/wgpu/issues/8705
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth32float-stencil8";depthReadOnly=false;stencilReadOnly=true // https://github.com/gfx-rs/wgpu/issues/8705
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth32float-stencil8";depthReadOnly=true;stencilReadOnly=false // https://github.com/gfx-rs/wgpu/issues/8705
webgpu:api,operation,rendering,3d_texture_slices:* // https://github.com/gfx-rs/wgpu/issues/9455
webgpu:api,validation,buffer,mapping:* // crash
+9
View File
@@ -36,6 +36,15 @@ webgpu:api,operation,compute_pipeline,overrides:*
//FAIL: webgpu:api,operation,compute,basic:large_dispatch:*
webgpu:api,operation,compute,basic:memcpy:*
webgpu:api,operation,device,lost:*
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth16unorm";*
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth24plus";*
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth24plus-stencil8";depthReadOnly=false;stencilReadOnly=false
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth24plus-stencil8";depthReadOnly=true;stencilReadOnly=true
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth32float";*
webgpu:api,operation,memory_sync,texture,readonly_depth_stencil:sampling_while_testing:format="depth32float-stencil8";depthReadOnly=false;stencilReadOnly=false
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_pipeline,overrides:*
webgpu:api,operation,render_pipeline,pipeline_output_targets:color,component_count,blend:*
+18
View File
@@ -447,3 +447,21 @@ pub(crate) fn map_acceleration_structure_copy_mode(
}
}
}
pub(crate) const fn make_shader_component_mapping(
src0: Direct3D12::D3D12_SHADER_COMPONENT_MAPPING,
src1: Direct3D12::D3D12_SHADER_COMPONENT_MAPPING,
src2: Direct3D12::D3D12_SHADER_COMPONENT_MAPPING,
src3: Direct3D12::D3D12_SHADER_COMPONENT_MAPPING,
) -> Direct3D12::D3D12_SHADER_COMPONENT_MAPPING {
const M: i32 = Direct3D12::D3D12_SHADER_COMPONENT_MAPPING_MASK as i32;
const S: i32 = Direct3D12::D3D12_SHADER_COMPONENT_MAPPING_SHIFT as i32;
Direct3D12::D3D12_SHADER_COMPONENT_MAPPING(
(src0.0 & M)
| (src1.0 & M) << S
| (src2.0 & M) << (S * 2)
| (src3.0 & M) << (S * 3)
| Direct3D12::D3D12_SHADER_COMPONENT_MAPPING_ALWAYS_SET_BIT_AVOIDING_ZEROMEM_MISTAKES
as i32,
)
}
+22 -1
View File
@@ -41,12 +41,33 @@ fn aspects_to_plane(aspects: crate::FormatAspects) -> u32 {
}
}
/// Shader component mapping for stencil views
///
/// Stencil views use `DXGI_FORMAT_X24_TYPELESS_G8_UINT` or
/// `DXGI_FORMAT_X32_TYPELESS_G8X24_UINT`, which have the stencil value in
/// the green component. WebGPU specifies that the stencil value be in the
/// red component. It also specifies that the remaining components _should_
/// be (0, 0, 1), but may have an unspecified value.
const STENCIL_COMPONENT_MAPPING: Direct3D12::D3D12_SHADER_COMPONENT_MAPPING =
super::conv::make_shader_component_mapping(
Direct3D12::D3D12_SHADER_COMPONENT_MAPPING_FROM_MEMORY_COMPONENT_1,
Direct3D12::D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0,
Direct3D12::D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_0,
Direct3D12::D3D12_SHADER_COMPONENT_MAPPING_FORCE_VALUE_1,
);
impl ViewDescriptor {
pub(crate) unsafe fn to_srv(&self) -> Option<Direct3D12::D3D12_SHADER_RESOURCE_VIEW_DESC> {
let swizzle = if self.aspects == crate::FormatAspects::STENCIL {
STENCIL_COMPONENT_MAPPING.0 as u32
} else {
Direct3D12::D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING
};
let mut desc = Direct3D12::D3D12_SHADER_RESOURCE_VIEW_DESC {
Format: self.srv_uav_format?,
ViewDimension: Direct3D12::D3D12_SRV_DIMENSION_UNKNOWN,
Shader4ComponentMapping: Direct3D12::D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING,
Shader4ComponentMapping: swizzle,
Anonymous: Default::default(),
};