fix: emit dimension-correct HLSL texture sample offsets (#9951)

Co-authored-by: Matt Van Horn <455140+mvanhorn@users.noreply.github.com>
Co-authored-by: Erich Gubler <erichdongubler@gmail.com>
This commit is contained in:
authored and GitHub committed 2026-07-30 12:58:50 +00:00
1 parent 5205d3d1e5
commit c079e55f53
6 files changed
+75 -1

No files matched your search

+1
View File
@@ -95,6 +95,7 @@ Bottom level categories:
#### Naga
- Replace embedded NUL characters with `?` when writing debug strings to SPIR-V. By @andyleiserson in [#9904](https://github.com/gfx-rs/wgpu/pull/9904).
- Fix invalid HLSL generated for `textureSampleLevel` with non-2D textures. By @mvanhorn in [#9717](https://github.com/gfx-rs/wgpu/issues/9717).
#### Vulkan
+11 -1
View File
@@ -4239,7 +4239,17 @@ impl<'a, W: fmt::Write> super::Writer<'a, W> {
if let Some(offset) = offset {
write!(self.out, ", ")?;
write!(self.out, "int2(")?; // work around https://github.com/microsoft/DirectXShaderCompiler/issues/5082#issuecomment-1540147807
// Work around https://github.com/microsoft/DirectXShaderCompiler/issues/5082#issuecomment-1540147807
let (size, scalar) = func_ctx
.resolve_type(offset, &module.types)
.vector_size_and_scalar()
.unwrap();
assert_eq!(scalar.kind, ScalarKind::Sint);
write!(self.out, "{}", scalar.to_hlsl_str()?)?;
if let Some(size) = size {
write!(self.out, "{}", common::vector_size_str(size))?;
}
write!(self.out, "(")?;
self.write_const_expression(module, offset, func_ctx.expressions)?;
write!(self.out, ")")?;
}
@@ -0,0 +1 @@
targets = "HLSL"
@@ -0,0 +1,31 @@
@group(0) @binding(0)
var sampled_texture_1d: texture_1d<f32>;
@group(0) @binding(1)
var sampled_texture_2d: texture_2d<f32>;
@group(0) @binding(2)
var sampled_texture_3d: texture_3d<f32>;
@group(0) @binding(3)
var texture_sampler: sampler;
@fragment
fn main() -> @location(0) vec4<f32> {
let sample_1d = textureSampleLevel(sampled_texture_1d, texture_sampler, 0.5, 0.0, -1);
let sample_2d = textureSampleLevel(
sampled_texture_2d,
texture_sampler,
vec2<f32>(0.5),
0.0,
vec2<i32>(-1, 2),
);
let sample_3d = textureSampleLevel(
sampled_texture_3d,
texture_sampler,
vec3<f32>(0.5),
0.0,
vec3<i32>(-1, 2, -3),
);
return sample_1d + sample_2d + sample_3d;
}
@@ -0,0 +1,15 @@
Texture1D<float4> sampled_texture_1d : register(t0);
Texture2D<float4> sampled_texture_2d : register(t1);
Texture3D<float4> sampled_texture_3d : register(t2);
SamplerState nagaSamplerHeap[2048]: register(s0, space0);
SamplerComparisonState nagaComparisonSamplerHeap[2048]: register(s0, space1);
StructuredBuffer<uint> nagaGroup0SamplerIndexArray : register(t0, space255);
static const SamplerState texture_sampler = nagaSamplerHeap[nagaGroup0SamplerIndexArray[3]];
float4 main() : SV_Target0
{
float4 sample_1d = sampled_texture_1d.SampleLevel(texture_sampler, 0.5, 0.0, int(int(-1)));
float4 sample_2d = sampled_texture_2d.SampleLevel(texture_sampler, (0.5).xx, 0.0, int2(int2(int(-1), int(2))));
float4 sample_3d = sampled_texture_3d.SampleLevel(texture_sampler, (0.5).xxx, 0.0, int3(int3(int(-1), int(2), int(-3))));
return ((sample_1d + sample_2d) + sample_3d);
}
@@ -0,0 +1,16 @@
(
vertex:[
],
fragment:[
(
entry_point:"main",
target_profile:"ps_5_1",
),
],
compute:[
],
task:[
],
mesh:[
],
)