fix the wrong generated code when a non-constant array is declared with its size derived from spec constant operations
This commit is contained in:
parent
aa0298bfde
commit
4c9126153d
@ -66,6 +66,25 @@ namespace {
|
|||||||
// or a different instruction sequence to do something gets used).
|
// or a different instruction sequence to do something gets used).
|
||||||
const int GeneratorVersion = 1;
|
const int GeneratorVersion = 1;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
class SpecConstantOpModeGuard {
|
||||||
|
public:
|
||||||
|
SpecConstantOpModeGuard(spv::Builder* builder)
|
||||||
|
: builder_(builder) {
|
||||||
|
previous_flag_ = builder->isInSpecConstCodeGenMode();
|
||||||
|
builder->setToSpecConstCodeGenMode();
|
||||||
|
}
|
||||||
|
~SpecConstantOpModeGuard() {
|
||||||
|
previous_flag_ ? builder_->setToSpecConstCodeGenMode()
|
||||||
|
: builder_->setToNormalCodeGenMode();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
spv::Builder* builder_;
|
||||||
|
bool previous_flag_;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// The main holder of information for translating glslang to SPIR-V.
|
// The main holder of information for translating glslang to SPIR-V.
|
||||||
//
|
//
|
||||||
@ -1927,6 +1946,7 @@ spv::Id TGlslangToSpvTraverser::makeArraySizeId(const glslang::TArraySizes& arra
|
|||||||
glslang::TIntermTyped* specNode = arraySizes.getDimNode(dim);
|
glslang::TIntermTyped* specNode = arraySizes.getDimNode(dim);
|
||||||
if (specNode != nullptr) {
|
if (specNode != nullptr) {
|
||||||
builder.clearAccessChain();
|
builder.clearAccessChain();
|
||||||
|
SpecConstantOpModeGuard set_to_spec_const_mode(&builder);
|
||||||
specNode->traverse(this);
|
specNode->traverse(this);
|
||||||
return accessChainLoad(specNode->getAsTyped()->getType());
|
return accessChainLoad(specNode->getAsTyped()->getType());
|
||||||
}
|
}
|
||||||
@ -3868,25 +3888,6 @@ spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstUnionArray(const glsla
|
|||||||
return builder.makeCompositeConstant(typeId, spvConsts);
|
return builder.makeCompositeConstant(typeId, spvConsts);
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace {
|
|
||||||
class SpecConstantOpModeGuard {
|
|
||||||
public:
|
|
||||||
SpecConstantOpModeGuard(spv::Builder* builder)
|
|
||||||
: builder_(builder) {
|
|
||||||
previous_flag_ = builder->isInSpecConstCodeGenMode();
|
|
||||||
builder->setToSpecConstCodeGenMode();
|
|
||||||
}
|
|
||||||
~SpecConstantOpModeGuard() {
|
|
||||||
previous_flag_ ? builder_->setToSpecConstCodeGenMode()
|
|
||||||
: builder_->setToNormalCodeGenMode();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
spv::Builder* builder_;
|
|
||||||
bool previous_flag_;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create constant ID from const initializer sub tree.
|
// Create constant ID from const initializer sub tree.
|
||||||
spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstSubTree(
|
spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstSubTree(
|
||||||
glslang::TIntermTyped* subTree)
|
glslang::TIntermTyped* subTree)
|
||||||
|
|||||||
@ -7,7 +7,7 @@ Linked vertex stage:
|
|||||||
|
|
||||||
// Module Version 10000
|
// Module Version 10000
|
||||||
// Generated by (magic number): 80001
|
// Generated by (magic number): 80001
|
||||||
// Id's are bound by 94
|
// Id's are bound by 107
|
||||||
|
|
||||||
Capability Shader
|
Capability Shader
|
||||||
Capability Float64
|
Capability Float64
|
||||||
@ -16,101 +16,116 @@ Linked vertex stage:
|
|||||||
EntryPoint Vertex 4 "main"
|
EntryPoint Vertex 4 "main"
|
||||||
Source GLSL 450
|
Source GLSL 450
|
||||||
Name 4 "main"
|
Name 4 "main"
|
||||||
Decorate 7 SpecId 200
|
Name 8 "non_const_array_size_from_spec_const("
|
||||||
Decorate 9 SpecId 201
|
Name 15 "array"
|
||||||
Decorate 11 SpecId 202
|
Decorate 10 SpecId 201
|
||||||
Decorate 12 SpecId 203
|
Decorate 24 SpecId 200
|
||||||
|
Decorate 26 SpecId 202
|
||||||
|
Decorate 27 SpecId 203
|
||||||
2: TypeVoid
|
2: TypeVoid
|
||||||
3: TypeFunction 2
|
3: TypeFunction 2
|
||||||
6: TypeFloat 32
|
6: TypeInt 32 1
|
||||||
7: 6(float) SpecConstant 1078530010
|
7: TypeFunction 6(int)
|
||||||
8: TypeInt 32 1
|
10: 6(int) SpecConstant 10
|
||||||
9: 8(int) SpecConstant 10
|
11: 6(int) Constant 2
|
||||||
10: TypeInt 32 0
|
12: 6(int) SpecConstantOp 128 10 11
|
||||||
11: 10(int) SpecConstant 100
|
13: TypeArray 6(int) 12
|
||||||
12: 8(int) SpecConstant 4294967286
|
14: TypePointer Function 13
|
||||||
13: TypeFloat 64
|
16: 6(int) Constant 1
|
||||||
14: 13(float) SpecConstantOp 115 7
|
18: TypePointer Function 6(int)
|
||||||
15: 6(float) SpecConstantOp 115 14
|
23: TypeFloat 32
|
||||||
16: 8(int) SpecConstantOp 126 9
|
24: 23(float) SpecConstant 1078530010
|
||||||
17: 8(int) SpecConstantOp 200 9
|
25: TypeInt 32 0
|
||||||
18: 8(int) Constant 2
|
26: 25(int) SpecConstant 100
|
||||||
19: 8(int) SpecConstantOp 128 9 18
|
27: 6(int) SpecConstant 4294967286
|
||||||
20: 8(int) SpecConstantOp 128 9 18
|
28: TypeFloat 64
|
||||||
21: 8(int) Constant 3
|
29: 28(float) SpecConstantOp 115 24
|
||||||
22: 8(int) SpecConstantOp 130 20 21
|
30: 23(float) SpecConstantOp 115 29
|
||||||
23: 8(int) Constant 4
|
31: 6(int) SpecConstantOp 126 10
|
||||||
24: 8(int) SpecConstantOp 130 19 23
|
32: 6(int) SpecConstantOp 200 10
|
||||||
25: 8(int) SpecConstantOp 132 12 18
|
33: 6(int) SpecConstantOp 128 10 11
|
||||||
26: 10(int) Constant 2
|
34: 6(int) SpecConstantOp 128 10 11
|
||||||
27: 10(int) SpecConstantOp 132 11 26
|
35: 6(int) Constant 3
|
||||||
28: 8(int) Constant 5
|
36: 6(int) SpecConstantOp 130 34 35
|
||||||
29: 8(int) SpecConstantOp 135 25 28
|
37: 6(int) Constant 4
|
||||||
30: 10(int) Constant 5
|
38: 6(int) SpecConstantOp 130 33 37
|
||||||
31: 10(int) SpecConstantOp 134 27 30
|
39: 6(int) SpecConstantOp 132 27 11
|
||||||
32: 8(int) SpecConstantOp 139 12 23
|
40: 25(int) Constant 2
|
||||||
33: 10(int) Constant 4
|
41: 25(int) SpecConstantOp 132 26 40
|
||||||
34: 10(int) SpecConstantOp 137 11 33
|
42: 6(int) Constant 5
|
||||||
35: 8(int) SpecConstantOp 132 12 21
|
43: 6(int) SpecConstantOp 135 39 42
|
||||||
36: 8(int) SpecConstantOp 135 35 28
|
44: 25(int) Constant 5
|
||||||
37: 8(int) Constant 10
|
45: 25(int) SpecConstantOp 134 41 44
|
||||||
38: 8(int) SpecConstantOp 195 12 37
|
46: 6(int) SpecConstantOp 139 27 37
|
||||||
39: 8(int) Constant 20
|
47: 25(int) Constant 4
|
||||||
40: 10(int) SpecConstantOp 194 11 39
|
48: 25(int) SpecConstantOp 137 26 47
|
||||||
41: 8(int) Constant 1
|
49: 6(int) SpecConstantOp 132 27 35
|
||||||
42: 8(int) SpecConstantOp 196 12 41
|
50: 6(int) SpecConstantOp 135 49 42
|
||||||
43: 10(int) SpecConstantOp 196 11 18
|
51: 6(int) Constant 10
|
||||||
44: 8(int) Constant 256
|
52: 6(int) SpecConstantOp 195 27 51
|
||||||
45: 8(int) SpecConstantOp 197 12 44
|
53: 6(int) Constant 20
|
||||||
46: 10(int) Constant 512
|
54: 25(int) SpecConstantOp 194 26 53
|
||||||
47: 10(int) SpecConstantOp 198 11 46
|
55: 6(int) SpecConstantOp 196 27 16
|
||||||
48: TypeBool
|
56: 25(int) SpecConstantOp 196 26 11
|
||||||
49: 48(bool) SpecConstantOp 177 9 12
|
57: 6(int) Constant 256
|
||||||
50: 48(bool) SpecConstantOp 170 11 11
|
58: 6(int) SpecConstantOp 197 27 57
|
||||||
51: 48(bool) SpecConstantOp 173 9 12
|
59: 25(int) Constant 512
|
||||||
52: TypeVector 8(int) 4
|
60: 25(int) SpecConstantOp 198 26 59
|
||||||
53: 8(int) Constant 30
|
61: TypeBool
|
||||||
54: 52(ivec4) SpecConstantComposite 39 53 9 9
|
62: 61(bool) SpecConstantOp 177 10 27
|
||||||
55: TypeVector 10(int) 4
|
63: 61(bool) SpecConstantOp 170 26 26
|
||||||
56: 10(int) Constant 4294967295
|
64: 61(bool) SpecConstantOp 173 10 27
|
||||||
57: 10(int) Constant 4294967294
|
65: TypeVector 6(int) 4
|
||||||
58: 55(ivec4) SpecConstantComposite 11 11 56 57
|
66: 6(int) Constant 30
|
||||||
59: TypeVector 6(float) 4
|
67: 65(ivec4) SpecConstantComposite 53 66 10 10
|
||||||
60: 6(float) Constant 1067450368
|
68: TypeVector 25(int) 4
|
||||||
61: 59(fvec4) SpecConstantComposite 7 60 7 60
|
69: 25(int) Constant 4294967295
|
||||||
62: TypeVector 13(float) 4
|
70: 25(int) Constant 4294967294
|
||||||
63: 62(fvec4) SpecConstantOp 115 61
|
71: 68(ivec4) SpecConstantComposite 26 26 69 70
|
||||||
64: 59(fvec4) SpecConstantOp 115 63
|
72: TypeVector 23(float) 4
|
||||||
65: 52(ivec4) SpecConstantOp 200 54
|
73: 23(float) Constant 1067450368
|
||||||
66: 52(ivec4) SpecConstantOp 126 54
|
74: 72(fvec4) SpecConstantComposite 24 73 24 73
|
||||||
67: 52(ivec4) ConstantComposite 18 18 18 18
|
75: TypeVector 28(float) 4
|
||||||
68: 52(ivec4) SpecConstantOp 128 54 67
|
76: 75(fvec4) SpecConstantOp 115 74
|
||||||
69: 52(ivec4) SpecConstantOp 128 54 67
|
77: 72(fvec4) SpecConstantOp 115 76
|
||||||
70: 52(ivec4) ConstantComposite 21 21 21 21
|
78: 65(ivec4) SpecConstantOp 200 67
|
||||||
71: 52(ivec4) SpecConstantOp 130 69 70
|
79: 65(ivec4) SpecConstantOp 126 67
|
||||||
72: 52(ivec4) ConstantComposite 23 23 23 23
|
80: 65(ivec4) ConstantComposite 11 11 11 11
|
||||||
73: 52(ivec4) SpecConstantOp 130 71 72
|
81: 65(ivec4) SpecConstantOp 128 67 80
|
||||||
74: 52(ivec4) SpecConstantOp 132 54 67
|
82: 65(ivec4) SpecConstantOp 128 67 80
|
||||||
75: 52(ivec4) ConstantComposite 28 28 28 28
|
83: 65(ivec4) ConstantComposite 35 35 35 35
|
||||||
76: 52(ivec4) SpecConstantOp 135 74 75
|
84: 65(ivec4) SpecConstantOp 130 82 83
|
||||||
77: 52(ivec4) SpecConstantOp 139 54 72
|
85: 65(ivec4) ConstantComposite 37 37 37 37
|
||||||
78: 52(ivec4) ConstantComposite 37 37 37 37
|
86: 65(ivec4) SpecConstantOp 130 84 85
|
||||||
79: 52(ivec4) SpecConstantOp 195 54 78
|
87: 65(ivec4) SpecConstantOp 132 67 80
|
||||||
80: 52(ivec4) SpecConstantOp 196 54 67
|
88: 65(ivec4) ConstantComposite 42 42 42 42
|
||||||
81: 8(int) Constant 1024
|
89: 65(ivec4) SpecConstantOp 135 87 88
|
||||||
82: 52(ivec4) ConstantComposite 81 81 81 81
|
90: 65(ivec4) SpecConstantOp 139 67 85
|
||||||
83: 52(ivec4) SpecConstantOp 197 54 82
|
91: 65(ivec4) ConstantComposite 51 51 51 51
|
||||||
84: 10(int) Constant 2048
|
92: 65(ivec4) SpecConstantOp 195 67 91
|
||||||
85: 55(ivec4) ConstantComposite 84 84 84 84
|
93: 65(ivec4) SpecConstantOp 196 67 80
|
||||||
86: 55(ivec4) SpecConstantOp 198 58 85
|
94: 6(int) Constant 1024
|
||||||
87: 10(int) Constant 0
|
95: 65(ivec4) ConstantComposite 94 94 94 94
|
||||||
88: 8(int) SpecConstantOp 81 54 0
|
96: 65(ivec4) SpecConstantOp 197 67 95
|
||||||
89: TypeVector 8(int) 2
|
97: 25(int) Constant 2048
|
||||||
90: 89(ivec2) SpecConstantOp 79 54 54 1(GLSL.std.450) 0
|
98: 68(ivec4) ConstantComposite 97 97 97 97
|
||||||
91: TypeVector 8(int) 3
|
99: 68(ivec4) SpecConstantOp 198 71 98
|
||||||
92: 91(ivec3) SpecConstantOp 79 54 54 2 1(GLSL.std.450) 0
|
100: 25(int) Constant 0
|
||||||
93: 52(ivec4) SpecConstantOp 79 54 54 1(GLSL.std.450) 2 0 3
|
101: 6(int) SpecConstantOp 81 67 0
|
||||||
|
102: TypeVector 6(int) 2
|
||||||
|
103: 102(ivec2) SpecConstantOp 79 67 67 1(GLSL.std.450) 0
|
||||||
|
104: TypeVector 6(int) 3
|
||||||
|
105: 104(ivec3) SpecConstantOp 79 67 67 2 1(GLSL.std.450) 0
|
||||||
|
106: 65(ivec4) SpecConstantOp 79 67 67 1(GLSL.std.450) 2 0 3
|
||||||
4(main): 2 Function None 3
|
4(main): 2 Function None 3
|
||||||
5: Label
|
5: Label
|
||||||
Return
|
Return
|
||||||
FunctionEnd
|
FunctionEnd
|
||||||
|
8(non_const_array_size_from_spec_const(): 6(int) Function None 7
|
||||||
|
9: Label
|
||||||
|
15(array): 14(ptr) Variable Function
|
||||||
|
17: 6(int) IAdd 10 16
|
||||||
|
19: 18(ptr) AccessChain 15(array) 17
|
||||||
|
20: 6(int) Load 19
|
||||||
|
ReturnValue 20
|
||||||
|
FunctionEnd
|
||||||
|
|||||||
@ -86,5 +86,10 @@ const ivec2 iv_yx = iv.yx;
|
|||||||
const ivec3 iv_zyx = iv.zyx;
|
const ivec3 iv_zyx = iv.zyx;
|
||||||
const ivec4 iv_yzxw = iv.yzxw;
|
const ivec4 iv_yzxw = iv.yzxw;
|
||||||
|
|
||||||
|
int non_const_array_size_from_spec_const() {
|
||||||
|
int array[sp_int + 2];
|
||||||
|
return array[sp_int + 1];
|
||||||
|
}
|
||||||
|
|
||||||
void main() {}
|
void main() {}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user