Skip to content

Commit 5b5d1fe

Browse files
committed
fix(dx12): Fix textureNum{Levels,Layers,Samples} functions
1 parent 928ddb4 commit 5b5d1fe

4 files changed

Lines changed: 24 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ By @beholdnec in [#8505](https://github.com/gfx-rs/wgpu/pull/8505).
216216
- 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).
217217
- Fixed a `debug_assert` during stride validation for indirect multi draw. By @kristoff3r in [#9332](https://github.com/gfx-rs/wgpu/pull/9332)
218218
- Fixed stencil values read with `textureLoad` appearing in G instead of R. By @andyleiserson in [#9520](https://github.com/gfx-rs/wgpu/pull/9520).
219+
- Fixed some cases where the `textureNum{Layers,Levels,Samples}` functions returned incorrect results. By @andyleiserson in TBD.
219220

220221
#### Metal
221222

cts_runner/fail.lst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ webgpu:api,validation,state,device_lost,destroy:* // crash
6565
webgpu:api,validation,texture,destroy:submit_a_destroyed_texture_as_attachment:* // 44%, https://github.com/gfx-rs/wgpu/issues/8714
6666

6767
webgpu:shader,execution,expression,call,builtin,atan2:f16:* // dx12, fails with dxc, passes with fxc, https://github.com/gfx-rs/wgpu/issues/9179
68+
webgpu:shader,execution,expression,call,builtin,textureDimensions:* // dx12, https://github.com/gfx-rs/wgpu/issues/9541
6869

6970
webgpu:shader,validation,decl,let:* // texture/sampler let
7071
webgpu:shader,validation,decl,override:* // 93%, unrestricted_pointer_parameters not implemented, https://github.com/gfx-rs/wgpu/issues/5158

cts_runner/test.lst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,10 @@ webgpu:shader,execution,expression,call,builtin,firstLeadingBit:*
359359
//FAIL: webgpu:shader,execution,expression,call,builtin,select:*
360360
// - Fails with `const`/abstract int cases on all platforms because of <https://github.com/gfx-rs/wgpu/issues/4507>.
361361
// - Fails with `vec3` & `f16` cases on macOS because of <https://github.com/gfx-rs/wgpu/issues/5262>.
362+
fails-if(dx12) webgpu:shader,execution,expression,call,builtin,textureDimensions:*
363+
webgpu:shader,execution,expression,call,builtin,textureNumLayers:*
364+
webgpu:shader,execution,expression,call,builtin,textureNumLevels:*
365+
webgpu:shader,execution,expression,call,builtin,textureNumSamples:*
362366
webgpu:shader,execution,expression,call,builtin,textureSample:sampled_1d_coords:*
363367
webgpu:shader,execution,expression,call,builtin,textureSampleBaseClampToEdge:2d_coords:stage="c";textureType="texture_2d<f32>";*
364368
// NOTE: This is supposed to be an exhaustive listing underneath

naga/src/back/hlsl/help.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,8 @@ impl<W: Write> super::Writer<'_, W> {
667667

668668
// GetDimensions Overloaded Methods
669669
// https://docs.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl-to-getdimensions#overloaded-methods
670-
let (ret_swizzle, number_of_params) = match wiq.query {
670+
// We rely on the validator to reject invalid queries.
671+
let (ret_swizzle, number_of_out_params) = match wiq.query {
671672
ImageQuery::Size | ImageQuery::SizeLevel => {
672673
let ret = match wiq.dim {
673674
IDim::D1 => "x",
@@ -677,13 +678,22 @@ impl<W: Write> super::Writer<'_, W> {
677678
};
678679
(ret, ret.len() + array_coords + extra_coords)
679680
}
680-
ImageQuery::NumLevels | ImageQuery::NumSamples | ImageQuery::NumLayers => {
681-
if wiq.arrayed || wiq.dim == IDim::D3 {
682-
("w", 4)
683-
} else {
684-
("z", 3)
681+
ImageQuery::NumLevels | ImageQuery::NumSamples => {
682+
// We want `NumberOfLevels` or `Samples`
683+
match wiq.dim {
684+
IDim::D1 => ("y", 2),
685+
IDim::D3 => ("w", 4),
686+
IDim::D2 | IDim::Cube => {
687+
if wiq.arrayed {
688+
("w", 4)
689+
} else {
690+
("z", 3)
691+
}
692+
}
685693
}
686694
}
695+
// We want `Elements`
696+
ImageQuery::NumLayers => ("z", 3 + extra_coords),
687697
};
688698

689699
// Write `GetDimensions` function.
@@ -704,7 +714,7 @@ impl<W: Write> super::Writer<'_, W> {
704714
},
705715
}
706716

707-
for component in COMPONENTS[..number_of_params - 1].iter() {
717+
for component in COMPONENTS[..number_of_out_params - 1].iter() {
708718
write!(self.out, "{RETURN_VARIABLE_NAME}.{component}, ")?;
709719
}
710720

@@ -713,7 +723,7 @@ impl<W: Write> super::Writer<'_, W> {
713723
self.out,
714724
"{}.{}",
715725
RETURN_VARIABLE_NAME,
716-
COMPONENTS[number_of_params - 1]
726+
COMPONENTS[number_of_out_params - 1]
717727
)?;
718728

719729
writeln!(self.out, ");")?;

0 commit comments

Comments
 (0)