Turn on SpecConstantOpMode based on node qualifier

Move SpecConstantOpModeGuard from makeSpvConstantFromConstSubTree() to
visitbinary() and visitunary(). Checking if the visiting node is a spec
constants, if so, turn on the SpecConstantOpMode, otherwise, stay in the
normal mode.
This commit is contained in:
qining 2016-04-03 22:20:42 -04:00
parent 4c9126153d
commit 408876600f
5 changed files with 32 additions and 32 deletions

View File

@ -72,12 +72,14 @@ public:
SpecConstantOpModeGuard(spv::Builder* builder)
: builder_(builder) {
previous_flag_ = builder->isInSpecConstCodeGenMode();
builder->setToSpecConstCodeGenMode();
}
~SpecConstantOpModeGuard() {
previous_flag_ ? builder_->setToSpecConstCodeGenMode()
: builder_->setToNormalCodeGenMode();
}
void turnOnSpecConstantOpMode() {
builder_->setToSpecConstCodeGenMode();
}
private:
spv::Builder* builder_;
@ -813,6 +815,10 @@ void TGlslangToSpvTraverser::visitSymbol(glslang::TIntermSymbol* symbol)
bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::TIntermBinary* node)
{
SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder);
if (node->getType().getQualifier().isSpecConstant())
spec_constant_op_mode_setter.turnOnSpecConstantOpMode();
// First, handle special cases
switch (node->getOp()) {
case glslang::EOpAssign:
@ -985,6 +991,10 @@ bool TGlslangToSpvTraverser::visitBinary(glslang::TVisit /* visit */, glslang::T
bool TGlslangToSpvTraverser::visitUnary(glslang::TVisit /* visit */, glslang::TIntermUnary* node)
{
SpecConstantOpModeGuard spec_constant_op_mode_setter(&builder);
if (node->getType().getQualifier().isSpecConstant())
spec_constant_op_mode_setter.turnOnSpecConstantOpMode();
spv::Id result = spv::NoResult;
// try texturing first
@ -1946,7 +1956,7 @@ spv::Id TGlslangToSpvTraverser::makeArraySizeId(const glslang::TArraySizes& arra
glslang::TIntermTyped* specNode = arraySizes.getDimNode(dim);
if (specNode != nullptr) {
builder.clearAccessChain();
SpecConstantOpModeGuard set_to_spec_const_mode(&builder);
// SpecConstantOpModeGuard set_to_spec_const_mode(&builder);
specNode->traverse(this);
return accessChainLoad(specNode->getAsTyped()->getType());
}
@ -3920,22 +3930,12 @@ spv::Id TGlslangToSpvTraverser::createSpvConstantFromConstSubTree(
} else if (glslang::TIntermBinary* bn = subTree->getAsBinaryNode()) {
// Binary operation node, we should generate OpSpecConstantOp <binary op>
// This case should only happen when Specialization Constants are involved.
// Spec constants defined with binary operations and other constants requires
// OpSpecConstantOp instruction.
SpecConstantOpModeGuard set_to_spec_const_mode(&builder);
bn->traverse(this);
return accessChainLoad(bn->getType());
} else if (glslang::TIntermUnary* un = subTree->getAsUnaryNode()) {
// Unary operation node, similar to binary operation node, should only
// happen when specialization constants are involved.
// Spec constants defined with unary operations and other constants requires
// OpSpecConstantOp instruction.
SpecConstantOpModeGuard set_to_spec_const_mode(&builder);
un->traverse(this);
return accessChainLoad(un->getType());

View File

@ -39,16 +39,16 @@ Linked compute stage:
15: TypeVector 6(int) 3
16: 15(ivec3) SpecConstantComposite 12 13 14
17: 6(int) Constant 0
18: 6(int) SpecConstantOp 81 16 0
19: 6(int) Constant 1
20: 6(int) SpecConstantOp 81 16 1(GLSL.std.450)
21: 6(int) SpecConstantOp 132 18 20
22: 6(int) Constant 2
23: 6(int) SpecConstantOp 81 16 2
24: 6(int) SpecConstantOp 132 21 23
25: TypePointer Uniform 6(int)
4(main): 2 Function None 3
5: Label
18: 6(int) CompositeExtract 16 0
20: 6(int) CompositeExtract 16 1
21: 6(int) IMul 18 20
23: 6(int) CompositeExtract 16 2
24: 6(int) IMul 21 23
26: 25(ptr) AccessChain 9(bi) 11
Store 26 24
Return

View File

@ -58,17 +58,25 @@ Linked vertex stage:
30: 29(bool) SpecConstantTrue
33: TypeInt 32 0
34: 33(int) SpecConstant 2
35: 6(float) SpecConstantOp 112 34
38: TypeFloat 64
39: 38(float) SpecConstant 1413754136 1074340347
40: 6(float) SpecConstant 1078523331
41: 38(float) SpecConstantOp 115 40
42: 38(float) SpecConstantOp 136 39 41
43: 6(float) SpecConstantOp 115 42
50: 8(int) SpecConstant 12
51: TypeArray 7(fvec4) 50
52: TypePointer Input 51
53(dupUcol): 52(ptr) Variable Input
60: 29(bool) SpecConstantTrue
63: 33(int) SpecConstant 2
64: 6(float) SpecConstantOp 112 63
67: 38(float) SpecConstant 1413754136 1074340347
68: 6(float) SpecConstant 1078523331
69: 38(float) SpecConstantOp 115 68
70: 38(float) SpecConstantOp 136 67 69
71: 6(float) SpecConstantOp 115 70
75: TypePointer Function 8(int)
77: 8(int) SpecConstant 8
4(main): 2 Function None 3
@ -81,15 +89,11 @@ Linked vertex stage:
SelectionMerge 32 None
BranchConditional 30 31 32
31: Label
35: 6(float) ConvertUToF 34
36: 7(fvec4) Load 20(color)
37: 7(fvec4) VectorTimesScalar 36 35
Store 20(color) 37
Branch 32
32: Label
41: 38(float) FConvert 40
42: 38(float) FDiv 39 41
43: 6(float) FConvert 42
44: 7(fvec4) Load 20(color)
45: 7(fvec4) CompositeConstruct 43 43 43 43
46: 7(fvec4) FAdd 44 45
@ -113,15 +117,11 @@ Linked vertex stage:
SelectionMerge 62 None
BranchConditional 60 61 62
61: Label
64: 6(float) ConvertUToF 63
65: 7(fvec4) Load 20(color)
66: 7(fvec4) VectorTimesScalar 65 64
Store 20(color) 66
Branch 62
62: Label
69: 38(float) FConvert 68
70: 38(float) FDiv 67 69
71: 6(float) FConvert 70
72: 7(fvec4) Load 20(color)
73: 7(fvec4) CompositeConstruct 71 71 71 71
74: 7(fvec4) FAdd 72 73

View File

@ -51,6 +51,7 @@ Linked vertex stage:
26: TypePointer Output 25(fvec4)
27(color): 26(ptr) Variable Output
28: 14(int) SpecConstant 3
29: 24(float) SpecConstantOp 111 28
32: 24(float) SpecConstant 1078523331
33: 25(fvec4) SpecConstantComposite 32 32 32 32
36: 24(float) Constant 1133908460
@ -76,6 +77,7 @@ Linked vertex stage:
70: 68 SpecConstantComposite 28 28 63 46 69
71: TypePointer Function 68
73: TypePointer Function 14(int)
79: 24(float) SpecConstantOp 111 78
87: 24(float) Constant 1106321080
88:41(flat_struct) SpecConstantComposite 69 87 43 21
89: 14(int) Constant 10
@ -99,7 +101,6 @@ Linked vertex stage:
SelectionMerge 23 None
BranchConditional 21 22 23
22: Label
29: 24(float) ConvertSToF 28
30: 25(fvec4) Load 27(color)
31: 25(fvec4) VectorTimesScalar 30 29
Store 27(color) 31
@ -146,7 +147,6 @@ Linked vertex stage:
Store 76(indexable) 70
77: 73(ptr) AccessChain 76(indexable) 75
78: 14(int) Load 77
79: 24(float) ConvertSToF 78
80: 25(fvec4) Load 27(color)
81: 25(fvec4) CompositeConstruct 79 79 79 79
82: 25(fvec4) FDiv 80 81

View File

@ -32,6 +32,7 @@ Linked vertex stage:
13: TypeArray 6(int) 12
14: TypePointer Function 13
16: 6(int) Constant 1
17: 6(int) SpecConstantOp 128 10 16
18: TypePointer Function 6(int)
23: TypeFloat 32
24: 23(float) SpecConstant 1078530010
@ -111,20 +112,19 @@ Linked vertex stage:
98: 68(ivec4) ConstantComposite 97 97 97 97
99: 68(ivec4) SpecConstantOp 198 71 98
100: 25(int) Constant 0
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
5: Label
Return
101: 6(int) CompositeExtract 67 0
103: 102(ivec2) VectorShuffle 67 67 1 0
105: 104(ivec3) VectorShuffle 67 67 2 1 0
106: 65(ivec4) VectorShuffle 67 67 1 2 0 3
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