Front-end: Get the right set of nodes marked as spec-const.

This is according to the expected KHR_vulkan_glsl without floating point.
So, floating-point spec-const operations no longer work, and that's
reflected in the tests.
This commit is contained in:
John Kessenich 2016-04-06 13:32:44 -06:00
parent a8d9faba1f
commit 78a6b78810
6 changed files with 180 additions and 101 deletions

View File

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

View File

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

View File

@ -7,10 +7,9 @@ Linked vertex stage:
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80001 // Generated by (magic number): 80001
// Id's are bound by 107 // Id's are bound by 101
Capability Shader Capability Shader
Capability Float64
1: ExtInstImport "GLSL.std.450" 1: ExtInstImport "GLSL.std.450"
MemoryModel Logical GLSL450 MemoryModel Logical GLSL450
EntryPoint Vertex 4 "main" EntryPoint Vertex 4 "main"
@ -39,85 +38,79 @@ Linked vertex stage:
25: TypeInt 32 0 25: TypeInt 32 0
26: 25(int) SpecConstant 100 26: 25(int) SpecConstant 100
27: 6(int) SpecConstant 4294967286 27: 6(int) SpecConstant 4294967286
28: TypeFloat 64 28: 6(int) SpecConstantOp 126 10
29: 28(float) SpecConstantOp 115 24 29: 6(int) SpecConstantOp 200 10
30: 23(float) SpecConstantOp 115 29 30: 6(int) SpecConstantOp 128 10 11
31: 6(int) SpecConstantOp 126 10 31: 6(int) SpecConstantOp 128 10 11
32: 6(int) SpecConstantOp 200 10 32: 6(int) Constant 3
33: 6(int) SpecConstantOp 128 10 11 33: 6(int) SpecConstantOp 130 31 32
34: 6(int) SpecConstantOp 128 10 11 34: 6(int) Constant 4
35: 6(int) Constant 3 35: 6(int) SpecConstantOp 130 30 34
36: 6(int) SpecConstantOp 130 34 35 36: 6(int) SpecConstantOp 132 27 11
37: 6(int) Constant 4 37: 25(int) Constant 2
38: 6(int) SpecConstantOp 130 33 37 38: 25(int) SpecConstantOp 132 26 37
39: 6(int) SpecConstantOp 132 27 11 39: 6(int) Constant 5
40: 25(int) Constant 2 40: 6(int) SpecConstantOp 135 36 39
41: 25(int) SpecConstantOp 132 26 40 41: 25(int) Constant 5
42: 6(int) Constant 5 42: 25(int) SpecConstantOp 134 38 41
43: 6(int) SpecConstantOp 135 39 42 43: 6(int) SpecConstantOp 139 27 34
44: 25(int) Constant 5 44: 25(int) Constant 4
45: 25(int) SpecConstantOp 134 41 44 45: 25(int) SpecConstantOp 137 26 44
46: 6(int) SpecConstantOp 139 27 37 46: 6(int) SpecConstantOp 132 27 32
47: 25(int) Constant 4 47: 6(int) SpecConstantOp 135 46 39
48: 25(int) SpecConstantOp 137 26 47 48: 6(int) Constant 10
49: 6(int) SpecConstantOp 132 27 35 49: 6(int) SpecConstantOp 195 27 48
50: 6(int) SpecConstantOp 135 49 42 50: 6(int) Constant 20
51: 6(int) Constant 10 51: 25(int) SpecConstantOp 194 26 50
52: 6(int) SpecConstantOp 195 27 51 52: 6(int) SpecConstantOp 196 27 16
53: 6(int) Constant 20 53: 25(int) SpecConstantOp 196 26 11
54: 25(int) SpecConstantOp 194 26 53 54: 6(int) Constant 256
55: 6(int) SpecConstantOp 196 27 16 55: 6(int) SpecConstantOp 197 27 54
56: 25(int) SpecConstantOp 196 26 11 56: 25(int) Constant 512
57: 6(int) Constant 256 57: 25(int) SpecConstantOp 198 26 56
58: 6(int) SpecConstantOp 197 27 57 58: TypeBool
59: 25(int) Constant 512 59: 58(bool) SpecConstantOp 177 10 27
60: 25(int) SpecConstantOp 198 26 59 60: 58(bool) SpecConstantOp 170 26 26
61: TypeBool 61: 58(bool) SpecConstantOp 173 10 27
62: 61(bool) SpecConstantOp 177 10 27 62: TypeVector 6(int) 4
63: 61(bool) SpecConstantOp 170 26 26 63: 6(int) Constant 30
64: 61(bool) SpecConstantOp 173 10 27 64: 62(ivec4) SpecConstantComposite 50 63 10 10
65: TypeVector 6(int) 4 65: TypeVector 25(int) 4
66: 6(int) Constant 30 66: 25(int) Constant 4294967295
67: 65(ivec4) SpecConstantComposite 53 66 10 10 67: 25(int) Constant 4294967294
68: TypeVector 25(int) 4 68: 65(ivec4) SpecConstantComposite 26 26 66 67
69: 25(int) Constant 4294967295 69: TypeVector 23(float) 4
70: 25(int) Constant 4294967294 70: 23(float) Constant 1067450368
71: 68(ivec4) SpecConstantComposite 26 26 69 70 71: 69(fvec4) SpecConstantComposite 24 70 24 70
72: TypeVector 23(float) 4 72: 62(ivec4) SpecConstantOp 200 64
73: 23(float) Constant 1067450368 73: 62(ivec4) SpecConstantOp 126 64
74: 72(fvec4) SpecConstantComposite 24 73 24 73 74: 62(ivec4) ConstantComposite 11 11 11 11
75: TypeVector 28(float) 4 75: 62(ivec4) SpecConstantOp 128 64 74
76: 75(fvec4) SpecConstantOp 115 74 76: 62(ivec4) SpecConstantOp 128 64 74
77: 72(fvec4) SpecConstantOp 115 76 77: 62(ivec4) ConstantComposite 32 32 32 32
78: 65(ivec4) SpecConstantOp 200 67 78: 62(ivec4) SpecConstantOp 130 76 77
79: 65(ivec4) SpecConstantOp 126 67 79: 62(ivec4) ConstantComposite 34 34 34 34
80: 65(ivec4) ConstantComposite 11 11 11 11 80: 62(ivec4) SpecConstantOp 130 78 79
81: 65(ivec4) SpecConstantOp 128 67 80 81: 62(ivec4) SpecConstantOp 132 64 74
82: 65(ivec4) SpecConstantOp 128 67 80 82: 62(ivec4) ConstantComposite 39 39 39 39
83: 65(ivec4) ConstantComposite 35 35 35 35 83: 62(ivec4) SpecConstantOp 135 81 82
84: 65(ivec4) SpecConstantOp 130 82 83 84: 62(ivec4) SpecConstantOp 139 64 79
85: 65(ivec4) ConstantComposite 37 37 37 37 85: 62(ivec4) ConstantComposite 48 48 48 48
86: 65(ivec4) SpecConstantOp 130 84 85 86: 62(ivec4) SpecConstantOp 195 64 85
87: 65(ivec4) SpecConstantOp 132 67 80 87: 62(ivec4) SpecConstantOp 196 64 74
88: 65(ivec4) ConstantComposite 42 42 42 42 88: 6(int) Constant 1024
89: 65(ivec4) SpecConstantOp 135 87 88 89: 62(ivec4) ConstantComposite 88 88 88 88
90: 65(ivec4) SpecConstantOp 139 67 85 90: 62(ivec4) SpecConstantOp 197 64 89
91: 65(ivec4) ConstantComposite 51 51 51 51 91: 25(int) Constant 2048
92: 65(ivec4) SpecConstantOp 195 67 91 92: 65(ivec4) ConstantComposite 91 91 91 91
93: 65(ivec4) SpecConstantOp 196 67 80 93: 65(ivec4) SpecConstantOp 198 68 92
94: 6(int) Constant 1024 94: 25(int) Constant 0
95: 65(ivec4) ConstantComposite 94 94 94 94 95: 6(int) SpecConstantOp 81 64 0
96: 65(ivec4) SpecConstantOp 197 67 95 96: TypeVector 6(int) 2
97: 25(int) Constant 2048 97: 96(ivec2) SpecConstantOp 79 64 64 1(GLSL.std.450) 0
98: 68(ivec4) ConstantComposite 97 97 97 97 98: TypeVector 6(int) 3
99: 68(ivec4) SpecConstantOp 198 71 98 99: 98(ivec3) SpecConstantOp 79 64 64 2 1(GLSL.std.450) 0
100: 25(int) Constant 0 100: 62(ivec4) SpecConstantOp 79 64 64 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

View File

@ -11,8 +11,8 @@ layout(constant_id = 203) const int sp_sint = -10;
// //
// Size convert // Size convert
const double float_to_double = double(sp_float); //const double float_to_double = double(sp_float);
const float double_to_float = float(float_to_double); //const float double_to_float = float(float_to_double);
// Negate and Not // Negate and Not
const int negate_int = -sp_int; const int negate_int = -sp_int;
@ -55,8 +55,8 @@ const uvec4 uv = uvec4(sp_uint, sp_uint, -1, -2);
const vec4 fv = vec4(sp_float, 1.25, sp_float, 1.25); const vec4 fv = vec4(sp_float, 1.25, sp_float, 1.25);
// Size convert // Size convert
const dvec4 fv_to_dv = dvec4(fv); //const dvec4 fv_to_dv = dvec4(fv);
const vec4 dv_to_fv = vec4(fv_to_dv); //const vec4 dv_to_fv = vec4(fv_to_dv);
// Negate and Not // Negate and Not
const ivec4 not_iv = ~iv; const ivec4 not_iv = ~iv;

View File

@ -145,9 +145,11 @@ TIntermTyped* TIntermediate::addBinaryMath(TOperator op, TIntermTyped* left, TIn
// If either is a specialization constant, while the other is // If either is a specialization constant, while the other is
// a constant (or specialization constant), the result is still // a constant (or specialization constant), the result is still
// a specialization constant. // a specialization constant, if the operation is an allowed
// specialization-constant operation.
if (( left->getType().getQualifier().isSpecConstant() && right->getType().getQualifier().isConstant()) || if (( left->getType().getQualifier().isSpecConstant() && right->getType().getQualifier().isConstant()) ||
(right->getType().getQualifier().isSpecConstant() && left->getType().getQualifier().isConstant())) (right->getType().getQualifier().isSpecConstant() && left->getType().getQualifier().isConstant()))
if (isSpecializationOperation(*node))
node->getWritableType().getQualifier().makeSpecConstant(); node->getWritableType().getQualifier().makeSpecConstant();
return node; return node;
@ -292,8 +294,9 @@ TIntermTyped* TIntermediate::addUnaryMath(TOperator op, TIntermTyped* child, TSo
if (child->getAsConstantUnion()) if (child->getAsConstantUnion())
return child->getAsConstantUnion()->fold(op, node->getType()); return child->getAsConstantUnion()->fold(op, node->getType());
// If it's a specialization constant, the result is too. // If it's a specialization constant, the result is too,
if (child->getType().getQualifier().isSpecConstant()) // if the operation is allowed for specialization constants.
if (child->getType().getQualifier().isSpecConstant() && isSpecializationOperation(*node))
node->getWritableType().getQualifier().makeSpecConstant(); node->getWritableType().getQualifier().makeSpecConstant();
return node; return node;
@ -619,8 +622,8 @@ TIntermTyped* TIntermediate::addConversion(TOperator op, const TType& type, TInt
// TODO: it seems that some unary folding operations should occur here, but are not // TODO: it seems that some unary folding operations should occur here, but are not
// Propagate specialization-constant-ness. // Propagate specialization-constant-ness, if allowed
if (node->getType().getQualifier().isSpecConstant()) if (node->getType().getQualifier().isSpecConstant() && isSpecializationOperation(*newNode))
newNode->getWritableType().getQualifier().makeSpecConstant(); newNode->getWritableType().getQualifier().makeSpecConstant();
return newNode; return newNode;
@ -1065,6 +1068,87 @@ void TIntermediate::removeTree()
RemoveAllTreeNodes(treeRoot); RemoveAllTreeNodes(treeRoot);
} }
//
// Implement the part of KHR_vulkan_glsl that lists the set of operations
// that can result in a specialization constant operation.
//
// "5.x Specialization Constant Operations"
//
// ...
//
// It also needs to allow basic construction, swizzling, and indexing
// operations.
//
bool TIntermediate::isSpecializationOperation(const TIntermOperator& node) const
{
// allow construction
if (node.isConstructor())
return true;
// The set for floating point is quite limited
if (node.getBasicType() == EbtFloat ||
node.getBasicType() == EbtDouble) {
switch (node.getOp()) {
case EOpIndexDirect:
case EOpIndexIndirect:
case EOpIndexDirectStruct:
case EOpVectorSwizzle:
return true;
default:
return false;
}
}
// Floating-point is out of the way.
// Now check for integer/bool-based operations
switch (node.getOp()) {
// dereference/swizzle
case EOpIndexDirect:
case EOpIndexIndirect:
case EOpIndexDirectStruct:
case EOpVectorSwizzle:
// conversion constructors
case EOpConvIntToBool:
case EOpConvUintToBool:
case EOpConvUintToInt:
case EOpConvBoolToInt:
case EOpConvIntToUint:
case EOpConvBoolToUint:
// unary operations
case EOpNegative:
case EOpLogicalNot:
case EOpBitwiseNot:
// binary operations
case EOpAdd:
case EOpSub:
case EOpMul:
case EOpVectorTimesScalar:
case EOpDiv:
case EOpMod:
case EOpRightShift:
case EOpLeftShift:
case EOpAnd:
case EOpInclusiveOr:
case EOpExclusiveOr:
case EOpLogicalOr:
case EOpLogicalXor:
case EOpLogicalAnd:
case EOpEqual:
case EOpNotEqual:
case EOpLessThan:
case EOpGreaterThan:
case EOpLessThanEqual:
case EOpGreaterThanEqual:
return true;
default:
return false;
}
}
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
// //
// Member functions of the nodes used for building the tree. // Member functions of the nodes used for building the tree.

View File

@ -342,6 +342,8 @@ protected:
TIntermSequence& findLinkerObjects() const; TIntermSequence& findLinkerObjects() const;
bool userOutputUsed() const; bool userOutputUsed() const;
static int getBaseAlignmentScalar(const TType&, int& size); static int getBaseAlignmentScalar(const TType&, int& size);
bool isSpecializationOperation(const TIntermOperator&) const;
const EShLanguage language; // stage, known at construction time const EShLanguage language; // stage, known at construction time
EShSource source; // source language, known a bit later EShSource source; // source language, known a bit later