Skip to content

Commit 9b2a9c9

Browse files
committed
(Naga) Add support for Storage Image Multisample when ingesting SPIR-V
Naga seems to support StorageImageMultisample just fine. The snapshot test I added shows that the correct WGSL is created. Fixes #8269
1 parent 61e5124 commit 9b2a9c9

File tree

6 files changed

+158
-1
lines changed

6 files changed

+158
-1
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,8 @@ By @cwfitzgerald in [#8162](https://github.com/gfx-rs/wgpu/pull/8162).
200200
- **BREAKING**: Previously the WGSL storage-texture format `rg11b10float` was incorrectly accepted and generated by naga, but now only accepts the the correct name `rg11b10ufloat` instead. By @ErikWDev in [#8219](https://github.com/gfx-rs/wgpu/pull/8219).
201201
- The [`source()`](https://doc.rust-lang.org/std/error/trait.Error.html#method.source) method of `ShaderError` no longer reports the error as its own source. By @andyleiserson in [#8258](https://github.com/gfx-rs/wgpu/pull/8258).
202202
- naga correctly ingests SPIR-V that use descriptor runtime indexing, which in turn is correctly converted into WGSLs binding array. By @hasenbanck in [8256](https://github.com/gfx-rs/wgpu/pull/8256).
203-
203+
- naga correctly ingests SPIR-V that loads from multi-sampled textures, which in turn is correctly converted into WGSLs texture_multisampled_2d and load operations. By @hasenbanck in [8270](https://github.com/gfx-rs/wgpu/pull/8270).
204+
-
204205
#### DX12
205206

206207
- Allow disabling waiting for latency waitable object. By @marcpabst in [#7400](https://github.com/gfx-rs/wgpu/pull/7400)

naga/src/front/spv/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ pub const SUPPORTED_CAPABILITIES: &[spirv::Capability] = &[
8383
spirv::Capability::GroupNonUniformShuffle,
8484
spirv::Capability::GroupNonUniformShuffleRelative,
8585
spirv::Capability::RuntimeDescriptorArray,
86+
spirv::Capability::StorageImageMultisample,
8687
// tricky ones
8788
spirv::Capability::UniformBufferArrayDynamicIndexing,
8889
spirv::Capability::StorageBufferArrayDynamicIndexing,
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Compiled with:
2+
// slangc -target spirv -profile spirv_1_5 -o naga/tests/in/spv/load-ms-texture.spv naga/tests/in/spv/load-ms-texture.slang
3+
// Disassembled with:
4+
// spirv-dis naga/tests/in/spv/load-ms-texture.spv -o naga/tests/in/spv/load-ms-texture.spvasm
5+
#language slang 2026
6+
7+
[[vk::binding(0, 0)]] var texture: Texture2DMS;
8+
9+
[[shader("pixel")]]
10+
func fs_main(float4 position : SV_Position) -> float4 {
11+
let pixel_coord = int2(position.xy);
12+
var color: float4;
13+
14+
for (var index: int = 0; index < 8; index++) {
15+
color += texture.Load(pixel_coord, index);
16+
}
17+
18+
color = color / 8.0;
19+
20+
return color;
21+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
; SPIR-V
2+
; Version: 1.5
3+
; Generator: Khronos Slang Compiler; 0
4+
; Bound: 65
5+
; Schema: 0
6+
OpCapability StorageImageMultisample
7+
OpCapability Shader
8+
OpMemoryModel Logical GLSL450
9+
OpEntryPoint Fragment %fs_main "main" %texture %entryPointParam_fs_main %gl_FragCoord
10+
OpExecutionMode %fs_main OriginUpperLeft
11+
OpSource Slang 1
12+
OpName %index "index"
13+
OpName %index "index"
14+
OpName %color "color"
15+
OpName %color "color"
16+
OpName %color_0 "color"
17+
OpName %entryPointParam_fs_main "entryPointParam_fs_main"
18+
OpName %texture "texture"
19+
OpName %sampled "sampled"
20+
OpName %color_1 "color"
21+
OpName %fs_main "fs_main"
22+
OpDecorate %gl_FragCoord BuiltIn FragCoord
23+
OpDecorate %entryPointParam_fs_main Location 0
24+
OpDecorate %texture Binding 0
25+
OpDecorate %texture DescriptorSet 0
26+
%void = OpTypeVoid
27+
%3 = OpTypeFunction %void
28+
%int = OpTypeInt 32 1
29+
%_ptr_Function_int = OpTypePointer Function %int
30+
%float = OpTypeFloat 32
31+
%v4float = OpTypeVector %float 4
32+
%_ptr_Function_v4float = OpTypePointer Function %v4float
33+
%_ptr_Input_v4float = OpTypePointer Input %v4float
34+
%v2float = OpTypeVector %float 2
35+
%v2int = OpTypeVector %int 2
36+
%int_0 = OpConstant %int 0
37+
%bool = OpTypeBool
38+
%int_8 = OpConstant %int 8
39+
%_ptr_Output_v4float = OpTypePointer Output %v4float
40+
%45 = OpTypeImage %float 2D 2 0 1 1 Unknown
41+
%_ptr_UniformConstant_45 = OpTypePointer UniformConstant %45
42+
%int_1 = OpConstant %int 1
43+
%gl_FragCoord = OpVariable %_ptr_Input_v4float Input
44+
%entryPointParam_fs_main = OpVariable %_ptr_Output_v4float Output
45+
%texture = OpVariable %_ptr_UniformConstant_45 UniformConstant
46+
%float_0_125 = OpConstant %float 0.125
47+
%64 = OpConstantComposite %v4float %float_0_125 %float_0_125 %float_0_125 %float_0_125
48+
%fs_main = OpFunction %void None %3
49+
%4 = OpLabel
50+
%index = OpVariable %_ptr_Function_int Function
51+
%color = OpVariable %_ptr_Function_v4float Function
52+
%22 = OpLoad %v4float %gl_FragCoord
53+
%26 = OpVectorShuffle %v2float %22 %22 0 1
54+
%28 = OpConvertFToS %v2int %26
55+
OpStore %index %int_0
56+
OpBranch %12
57+
%12 = OpLabel
58+
OpLoopMerge %17 %21 None
59+
OpBranch %13
60+
%13 = OpLabel
61+
OpBranch %14
62+
%14 = OpLabel
63+
OpBranch %15
64+
%15 = OpLabel
65+
%31 = OpLoad %int %index
66+
%33 = OpSLessThan %bool %31 %int_8
67+
OpSelectionMerge %18 None
68+
OpBranchConditional %33 %18 %16
69+
%16 = OpLabel
70+
OpBranch %17
71+
%18 = OpLabel
72+
%46 = OpLoad %45 %texture
73+
%49 = OpLoad %int %index
74+
%sampled = OpImageFetch %v4float %46 %28 Sample %49
75+
%52 = OpLoad %v4float %color
76+
%color_1 = OpFAdd %v4float %52 %sampled
77+
OpBranch %19
78+
%19 = OpLabel
79+
OpBranch %20
80+
%20 = OpLabel
81+
%56 = OpLoad %int %index
82+
%57 = OpIAdd %int %56 %int_1
83+
OpStore %index %57
84+
OpStore %color %color_1
85+
OpBranch %21
86+
%21 = OpLabel
87+
OpBranch %12
88+
%17 = OpLabel
89+
%37 = OpLoad %v4float %color
90+
%color_0 = OpFMul %v4float %37 %64
91+
OpStore %entryPointParam_fs_main %color_0
92+
OpReturn
93+
OpFunctionEnd
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
god_mode = true
2+
3+
[spv-in]
4+
adjust_coordinate_space = true
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
var<private> global: vec4<f32>;
2+
var<private> entryPointParam_fs_main: vec4<f32>;
3+
@group(0) @binding(0)
4+
var texture: texture_multisampled_2d<f32>;
5+
6+
fn fs_main() {
7+
var index: i32;
8+
var color: vec4<f32>;
9+
10+
let _e9 = global;
11+
index = 0i;
12+
loop {
13+
let _e12 = index;
14+
if (_e12 < 8i) {
15+
} else {
16+
break;
17+
}
18+
let _e14 = index;
19+
let _e15 = textureLoad(texture, vec2<i32>(_e9.xy), _e14);
20+
let _e16 = color;
21+
let _e18 = index;
22+
index = (_e18 + 1i);
23+
color = (_e16 + _e15);
24+
continue;
25+
}
26+
let _e20 = color;
27+
entryPointParam_fs_main = (_e20 * vec4<f32>(0.125f, 0.125f, 0.125f, 0.125f));
28+
return;
29+
}
30+
31+
@fragment
32+
fn main(@builtin(position) param: vec4<f32>) -> @location(0) vec4<f32> {
33+
global = param;
34+
fs_main();
35+
let _e3 = entryPointParam_fs_main;
36+
return _e3;
37+
}

0 commit comments

Comments
 (0)