Skip to content

Commit 55c9d69

Browse files
teoxoyjimblandy
authored andcommitted
[naga] fix the way we adjust constant initializers when processing overrides
This fixes 2 issues: - we used to index `adjusted_global_expressions` with the handle index of the constant instead of its initializer - we used to adjust the initializer multiple times if the arena contained multiple `Expression::Constant`s pointing to the same constant
1 parent 5735f85 commit 55c9d69

6 files changed

+169
-2
lines changed

naga/src/back/pipeline_constants.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,10 @@ pub fn process_overrides<'a>(
129129
Expression::Constant(c_h)
130130
}
131131
Expression::Constant(c_h) => {
132-
adjusted_constant_initializers.insert(c_h);
133-
module.constants[c_h].init = adjusted_global_expressions[c_h.index()];
132+
if adjusted_constant_initializers.insert(c_h) {
133+
let init = &mut module.constants[c_h].init;
134+
*init = adjusted_global_expressions[init.index()];
135+
}
134136
expr
135137
}
136138
expr => expr,
1.4 KB
Binary file not shown.
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
; SPIR-V
2+
; Version: 1.5
3+
; Generator: Google rspirv; 0
4+
; Bound: 68
5+
; Schema: 0
6+
OpCapability Shader
7+
OpCapability VulkanMemoryModel
8+
OpMemoryModel Logical Vulkan
9+
OpEntryPoint Fragment %1 "fragment" %gl_FragCoord %3
10+
OpEntryPoint Vertex %4 "vertex" %gl_VertexIndex %gl_Position
11+
OpExecutionMode %1 OriginUpperLeft
12+
OpDecorate %gl_FragCoord BuiltIn FragCoord
13+
OpDecorate %10 SpecId 100
14+
OpDecorate %3 Location 0
15+
OpDecorate %_arr_v4float_uint_6 ArrayStride 16
16+
OpDecorate %gl_VertexIndex BuiltIn VertexIndex
17+
OpDecorate %gl_Position BuiltIn Position
18+
OpDecorate %gl_Position Invariant
19+
%float = OpTypeFloat 32
20+
%v4float = OpTypeVector %float 4
21+
%_ptr_Input_v4float = OpTypePointer Input %v4float
22+
%_ptr_Output_v4float = OpTypePointer Output %v4float
23+
%void = OpTypeVoid
24+
%17 = OpTypeFunction %void
25+
%gl_FragCoord = OpVariable %_ptr_Input_v4float Input
26+
%bool = OpTypeBool
27+
%uint = OpTypeInt 32 0
28+
%10 = OpSpecConstant %uint 2
29+
%uint_1 = OpConstant %uint 1
30+
%v2float = OpTypeVector %float 2
31+
%_ptr_Output_float = OpTypePointer Output %float
32+
%3 = OpVariable %_ptr_Output_v4float Output
33+
%uint_0 = OpConstant %uint 0
34+
%_ptr_Input_uint = OpTypePointer Input %uint
35+
%uint_6 = OpConstant %uint 6
36+
%_arr_v4float_uint_6 = OpTypeArray %v4float %uint_6
37+
%_ptr_Function__arr_v4float_uint_6 = OpTypePointer Function %_arr_v4float_uint_6
38+
%gl_VertexIndex = OpVariable %_ptr_Input_uint Input
39+
%float_n1 = OpConstant %float -1
40+
%float_0 = OpConstant %float 0
41+
%float_1 = OpConstant %float 1
42+
%32 = OpConstantComposite %v4float %float_n1 %float_n1 %float_0 %float_1
43+
%33 = OpConstantComposite %v4float %float_1 %float_n1 %float_0 %float_1
44+
%34 = OpConstantComposite %v4float %float_1 %float_1 %float_0 %float_1
45+
%35 = OpConstantComposite %v4float %float_n1 %float_1 %float_0 %float_1
46+
%36 = OpConstantComposite %_arr_v4float_uint_6 %32 %33 %34 %34 %35 %32
47+
%_ptr_Function_v4float = OpTypePointer Function %v4float
48+
%gl_Position = OpVariable %_ptr_Output_v4float Output
49+
%float_0_25 = OpConstant %float 0.25
50+
%float_0_5 = OpConstant %float 0.5
51+
%1 = OpFunction %void None %17
52+
%38 = OpLabel
53+
%39 = OpLoad %v4float %gl_FragCoord
54+
%40 = OpCompositeExtract %float %39 0
55+
%41 = OpCompositeExtract %float %39 1
56+
%42 = OpIEqual %bool %10 %uint_1
57+
OpSelectionMerge %43 None
58+
OpBranchConditional %42 %44 %45
59+
%44 = OpLabel
60+
%46 = OpFMul %float %40 %float_0_5
61+
%47 = OpFMul %float %41 %float_0_5
62+
%48 = OpCompositeConstruct %v2float %46 %47
63+
OpBranch %43
64+
%45 = OpLabel
65+
%49 = OpFMul %float %40 %float_0_25
66+
%50 = OpFMul %float %41 %float_0_25
67+
%51 = OpCompositeConstruct %v2float %49 %50
68+
OpBranch %43
69+
%43 = OpLabel
70+
%52 = OpPhi %v2float %48 %44 %51 %45
71+
%53 = OpCompositeExtract %float %52 0
72+
%54 = OpAccessChain %_ptr_Output_float %3 %uint_0
73+
OpStore %54 %53
74+
%55 = OpCompositeExtract %float %52 1
75+
%56 = OpAccessChain %_ptr_Output_float %3 %uint_1
76+
OpStore %56 %55
77+
OpReturn
78+
OpFunctionEnd
79+
%4 = OpFunction %void None %17
80+
%57 = OpLabel
81+
%58 = OpVariable %_ptr_Function__arr_v4float_uint_6 Function
82+
%59 = OpLoad %uint %gl_VertexIndex
83+
OpStore %58 %36
84+
%60 = OpULessThan %bool %59 %uint_6
85+
OpSelectionMerge %61 None
86+
OpBranchConditional %60 %62 %63
87+
%62 = OpLabel
88+
%64 = OpInBoundsAccessChain %_ptr_Function_v4float %58 %59
89+
%65 = OpLoad %v4float %64
90+
OpStore %gl_Position %65
91+
OpBranch %61
92+
%63 = OpLabel
93+
OpBranch %61
94+
%61 = OpLabel
95+
OpReturn
96+
OpFunctionEnd
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#version 310 es
2+
3+
precision highp float;
4+
precision highp int;
5+
6+
vec4 global = vec4(0.0);
7+
8+
vec4 global_1 = vec4(0.0);
9+
10+
layout(location = 0) out vec4 _fs2p_location0;
11+
12+
void function() {
13+
vec2 phi_52_ = vec2(0.0);
14+
vec4 _e7 = global;
15+
if (false) {
16+
phi_52_ = vec2((_e7.x * 0.5), (_e7.y * 0.5));
17+
} else {
18+
phi_52_ = vec2((_e7.x * 0.25), (_e7.y * 0.25));
19+
}
20+
vec2 _e20 = phi_52_;
21+
global_1[0u] = _e20.x;
22+
global_1[1u] = _e20.y;
23+
return;
24+
}
25+
26+
void main() {
27+
vec4 param = gl_FragCoord;
28+
global = param;
29+
function();
30+
vec4 _e3 = global_1;
31+
_fs2p_location0 = _e3;
32+
return;
33+
}
34+
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#version 310 es
2+
3+
precision highp float;
4+
precision highp int;
5+
6+
uint global_2 = 0u;
7+
8+
vec4 global_3 = vec4(0.0, 0.0, 0.0, 1.0);
9+
10+
invariant gl_Position;
11+
12+
void function_1() {
13+
vec4 local[6] = vec4[6](vec4(0.0), vec4(0.0), vec4(0.0), vec4(0.0), vec4(0.0), vec4(0.0));
14+
uint _e5 = global_2;
15+
local = vec4[6](vec4(-1.0, -1.0, 0.0, 1.0), vec4(1.0, -1.0, 0.0, 1.0), vec4(1.0, 1.0, 0.0, 1.0), vec4(1.0, 1.0, 0.0, 1.0), vec4(-1.0, 1.0, 0.0, 1.0), vec4(-1.0, -1.0, 0.0, 1.0));
16+
if ((_e5 < 6u)) {
17+
vec4 _e8 = local[_e5];
18+
global_3 = _e8;
19+
}
20+
return;
21+
}
22+
23+
void main() {
24+
uint param_1 = uint(gl_VertexID);
25+
global_2 = param_1;
26+
function_1();
27+
float _e4 = global_3.y;
28+
global_3.y = -(_e4);
29+
vec4 _e6 = global_3;
30+
gl_Position = _e6;
31+
gl_Position.yz = vec2(-gl_Position.y, gl_Position.z * 2.0 - gl_Position.w);
32+
return;
33+
}
34+

naga/tests/snapshots.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -973,6 +973,7 @@ fn convert_spv_all() {
973973
);
974974
convert_spv("builtin-accessed-outside-entrypoint", true, Targets::WGSL);
975975
convert_spv("spec-constants", true, Targets::IR);
976+
convert_spv("spec-constants-issue-5598", true, Targets::GLSL);
976977
convert_spv(
977978
"subgroup-operations-s",
978979
false,

0 commit comments

Comments
 (0)