Merge pull request #1832 from jeffbolznv/issue1828

Avoid generating 8/16-bit constants when 8/16-bit arithmetic extensions aren't enabled
This commit is contained in:
John Kessenich 2019-07-10 15:10:30 -06:00 committed by GitHub
commit c538b5d796
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 136 additions and 80 deletions

View File

@ -1,8 +1,7 @@
spv.16bitstorage-int.frag spv.16bitstorage-int.frag
Validation failed
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80007 // Generated by (magic number): 80007
// Id's are bound by 172 // Id's are bound by 171
Capability Shader Capability Shader
Capability StorageUniformBufferBlock16 Capability StorageUniformBufferBlock16
@ -210,10 +209,7 @@ Validation failed
114: 20(int) Constant 7 114: 20(int) Constant 7
115: 20(int) Constant 6 115: 20(int) Constant 6
116: TypePointer Uniform 20(int) 116: TypePointer Uniform 20(int)
166: 6(int16_t) Constant 1 166: 39(ivec2) ConstantComposite 32 33
167: 6(int16_t) Constant 2
168: 7(i16vec2) ConstantComposite 166 167
170: 6(int16_t) Constant 3
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
69(x0): 68(ptr) Variable Function 69(x0): 68(ptr) Variable Function
@ -333,9 +329,11 @@ Validation failed
164: 6(int16_t) Load 163 164: 6(int16_t) Load 163
165: 28(ptr) AccessChain 19(b2) 21 165: 28(ptr) AccessChain 19(b2) 21
Store 165 164 Store 165 164
169: 42(ptr) AccessChain 19(b2) 32 167: 7(i16vec2) SConvert 166
Store 169 168 168: 42(ptr) AccessChain 19(b2) 32
171: 28(ptr) AccessChain 19(b2) 21 Store 168 167
Store 171 170 169: 6(int16_t) SConvert 58
170: 28(ptr) AccessChain 19(b2) 21
Store 170 169
Return Return
FunctionEnd FunctionEnd

View File

@ -1,5 +1,4 @@
spv.16bitstorage-uint.frag spv.16bitstorage-uint.frag
Validation failed
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80007 // Generated by (magic number): 80007
// Id's are bound by 173 // Id's are bound by 173
@ -211,10 +210,8 @@ Validation failed
115: 20(int) Constant 7 115: 20(int) Constant 7
116: 20(int) Constant 6 116: 20(int) Constant 6
117: TypePointer Uniform 9(int) 117: TypePointer Uniform 9(int)
167: 6(int16_t) Constant 1 167: 39(ivec2) ConstantComposite 82 10
168: 6(int16_t) Constant 2 170: 9(int) Constant 3
169: 7(i16vec2) ConstantComposite 167 168
171: 6(int16_t) Constant 3
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
69(x0): 68(ptr) Variable Function 69(x0): 68(ptr) Variable Function
@ -334,8 +331,10 @@ Validation failed
165: 6(int16_t) Load 164 165: 6(int16_t) Load 164
166: 28(ptr) AccessChain 19(b2) 21 166: 28(ptr) AccessChain 19(b2) 21
Store 166 165 Store 166 165
170: 42(ptr) AccessChain 19(b2) 32 168: 7(i16vec2) UConvert 167
Store 170 169 169: 42(ptr) AccessChain 19(b2) 32
Store 169 168
171: 6(int16_t) UConvert 170
172: 28(ptr) AccessChain 19(b2) 21 172: 28(ptr) AccessChain 19(b2) 21
Store 172 171 Store 172 171
Return Return

View File

@ -1,8 +1,7 @@
spv.16bitstorage.frag spv.16bitstorage.frag
Validation failed
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80007 // Generated by (magic number): 80007
// Id's are bound by 172 // Id's are bound by 173
Capability Shader Capability Shader
Capability StorageUniformBufferBlock16 Capability StorageUniformBufferBlock16
@ -210,10 +209,9 @@ Validation failed
114: 20(int) Constant 7 114: 20(int) Constant 7
115: 20(int) Constant 6 115: 20(int) Constant 6
116: TypePointer Uniform 20(int) 116: TypePointer Uniform 20(int)
166:6(float16_t) Constant 15360 166: 37(float) Constant 1073741824
167:6(float16_t) Constant 16384 167: 40(fvec2) ConstantComposite 83 166
168: 7(f16vec2) ConstantComposite 166 167 170: 37(float) Constant 1077936128
170:6(float16_t) Constant 16896
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
70(x0): 69(ptr) Variable Function 70(x0): 69(ptr) Variable Function
@ -333,9 +331,11 @@ Validation failed
164:6(float16_t) Load 163 164:6(float16_t) Load 163
165: 28(ptr) AccessChain 19(b2) 21 165: 28(ptr) AccessChain 19(b2) 21
Store 165 164 Store 165 164
168: 7(f16vec2) FConvert 167
169: 43(ptr) AccessChain 19(b2) 32 169: 43(ptr) AccessChain 19(b2) 32
Store 169 168 Store 169 168
171: 28(ptr) AccessChain 19(b2) 21 171:6(float16_t) FConvert 170
Store 171 170 172: 28(ptr) AccessChain 19(b2) 21
Store 172 171
Return Return
FunctionEnd FunctionEnd

View File

@ -1,8 +1,7 @@
spv.8bitstorage-int.frag spv.8bitstorage-int.frag
Validation failed
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80007 // Generated by (magic number): 80007
// Id's are bound by 172 // Id's are bound by 171
Capability Shader Capability Shader
Capability UniformAndStorageBuffer8BitAccess Capability UniformAndStorageBuffer8BitAccess
@ -209,10 +208,7 @@ Validation failed
114: 20(int) Constant 7 114: 20(int) Constant 7
115: 20(int) Constant 6 115: 20(int) Constant 6
116: TypePointer Uniform 20(int) 116: TypePointer Uniform 20(int)
166: 6(int8_t) Constant 1 166: 39(ivec2) ConstantComposite 32 33
167: 6(int8_t) Constant 2
168: 7(i8vec2) ConstantComposite 166 167
170: 6(int8_t) Constant 3
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
69(x0): 68(ptr) Variable Function 69(x0): 68(ptr) Variable Function
@ -332,9 +328,11 @@ Validation failed
164: 6(int8_t) Load 163 164: 6(int8_t) Load 163
165: 28(ptr) AccessChain 19(b2) 21 165: 28(ptr) AccessChain 19(b2) 21
Store 165 164 Store 165 164
169: 42(ptr) AccessChain 19(b2) 32 167: 7(i8vec2) SConvert 166
Store 169 168 168: 42(ptr) AccessChain 19(b2) 32
171: 28(ptr) AccessChain 19(b2) 21 Store 168 167
Store 171 170 169: 6(int8_t) SConvert 58
170: 28(ptr) AccessChain 19(b2) 21
Store 170 169
Return Return
FunctionEnd FunctionEnd

View File

@ -1,5 +1,4 @@
spv.8bitstorage-uint.frag spv.8bitstorage-uint.frag
Validation failed
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80007 // Generated by (magic number): 80007
// Id's are bound by 173 // Id's are bound by 173
@ -210,10 +209,8 @@ Validation failed
115: 20(int) Constant 7 115: 20(int) Constant 7
116: 20(int) Constant 6 116: 20(int) Constant 6
117: TypePointer Uniform 9(int) 117: TypePointer Uniform 9(int)
167: 6(int8_t) Constant 1 167: 39(ivec2) ConstantComposite 82 10
168: 6(int8_t) Constant 2 170: 9(int) Constant 3
169: 7(i8vec2) ConstantComposite 167 168
171: 6(int8_t) Constant 3
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
69(x0): 68(ptr) Variable Function 69(x0): 68(ptr) Variable Function
@ -333,8 +330,10 @@ Validation failed
165: 6(int8_t) Load 164 165: 6(int8_t) Load 164
166: 28(ptr) AccessChain 19(b2) 21 166: 28(ptr) AccessChain 19(b2) 21
Store 166 165 Store 166 165
170: 42(ptr) AccessChain 19(b2) 32 168: 7(i8vec2) UConvert 167
Store 170 169 169: 42(ptr) AccessChain 19(b2) 32
Store 169 168
171: 6(int8_t) UConvert 170
172: 28(ptr) AccessChain 19(b2) 21 172: 28(ptr) AccessChain 19(b2) 21
Store 172 171 Store 172 171
Return Return

View File

@ -2,10 +2,9 @@ spv.bufferhandle11.frag
WARNING: 0:6: '' : all default precisions are highp; use precision statements to quiet warning, e.g.: WARNING: 0:6: '' : all default precisions are highp; use precision statements to quiet warning, e.g.:
"precision mediump int; precision highp float;" "precision mediump int; precision highp float;"
Validation failed
// Module Version 10000 // Module Version 10000
// Generated by (magic number): 80007 // Generated by (magic number): 80007
// Id's are bound by 60 // Id's are bound by 61
Capability Shader Capability Shader
Capability StorageBuffer8BitAccess Capability StorageBuffer8BitAccess
@ -69,7 +68,7 @@ Validation failed
50: 49(ptr) Variable StorageBuffer 50: 49(ptr) Variable StorageBuffer
51: TypePointer StorageBuffer 6(int) 51: TypePointer StorageBuffer 6(int)
54: 31(int) Constant 1 54: 31(int) Constant 1
58: 27(int8_t) Constant 9 58: 6(int) Constant 9
4(main): 2 Function None 3 4(main): 2 Function None 3
5: Label 5: Label
20(allOk): 19(ptr) Variable Function 20(allOk): 19(ptr) Variable Function
@ -104,8 +103,9 @@ Validation failed
47: Label 47: Label
56: 33(ptr) AccessChain 30 32 56: 33(ptr) AccessChain 30 32
57: 25(ptr) Load 56 57: 25(ptr) Load 56
59: 36(ptr) AccessChain 57 32 59: 27(int8_t) UConvert 58
Store 59 58 Aligned 16 60: 36(ptr) AccessChain 57 32
Store 60 59 Aligned 16
Return Return
FunctionEnd FunctionEnd
12(compare_uint8_t(u1;u1;): 8(bool) Function None 9 12(compare_uint8_t(u1;u1;): 8(bool) Function None 9

View File

@ -654,9 +654,21 @@ enum TOperator {
EOpConstructBool, EOpConstructBool,
EOpConstructFloat, EOpConstructFloat,
EOpConstructDouble, EOpConstructDouble,
// Keep vector and matrix constructors in a consistent relative order for
// TParseContext::constructBuiltIn, which converts between 8/16/32 bit
// vector constructors
EOpConstructVec2, EOpConstructVec2,
EOpConstructVec3, EOpConstructVec3,
EOpConstructVec4, EOpConstructVec4,
EOpConstructMat2x2,
EOpConstructMat2x3,
EOpConstructMat2x4,
EOpConstructMat3x2,
EOpConstructMat3x3,
EOpConstructMat3x4,
EOpConstructMat4x2,
EOpConstructMat4x3,
EOpConstructMat4x4,
EOpConstructDVec2, EOpConstructDVec2,
EOpConstructDVec3, EOpConstructDVec3,
EOpConstructDVec4, EOpConstructDVec4,
@ -687,15 +699,6 @@ enum TOperator {
EOpConstructU64Vec2, EOpConstructU64Vec2,
EOpConstructU64Vec3, EOpConstructU64Vec3,
EOpConstructU64Vec4, EOpConstructU64Vec4,
EOpConstructMat2x2,
EOpConstructMat2x3,
EOpConstructMat2x4,
EOpConstructMat3x2,
EOpConstructMat3x3,
EOpConstructMat3x4,
EOpConstructMat4x2,
EOpConstructMat4x3,
EOpConstructMat4x4,
EOpConstructDMat2x2, EOpConstructDMat2x2,
EOpConstructDMat2x3, EOpConstructDMat2x3,
EOpConstructDMat2x4, EOpConstructDMat2x4,

View File

@ -574,24 +574,6 @@ TIntermTyped* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
TOperator newOp = EOpNull; TOperator newOp = EOpNull;
// Certain explicit conversions are allowed conditionally
bool arithemeticInt8Enabled = extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_int8);
#ifdef AMD_EXTENSIONS
bool arithemeticInt16Enabled = extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_int16) ||
extensionRequested(E_GL_AMD_gpu_shader_int16);
bool arithemeticFloat16Enabled = extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_float16) ||
extensionRequested(E_GL_AMD_gpu_shader_half_float);
#else
bool arithemeticInt16Enabled = extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_int16);
bool arithemeticFloat16Enabled = extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_float16);
#endif
bool convertToIntTypes = (convertTo == EbtInt8 || convertTo == EbtUint8 || bool convertToIntTypes = (convertTo == EbtInt8 || convertTo == EbtUint8 ||
convertTo == EbtInt16 || convertTo == EbtUint16 || convertTo == EbtInt16 || convertTo == EbtUint16 ||
convertTo == EbtInt || convertTo == EbtUint || convertTo == EbtInt || convertTo == EbtUint ||
@ -608,19 +590,19 @@ TIntermTyped* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
node->getBasicType() == EbtFloat || node->getBasicType() == EbtFloat ||
node->getBasicType() == EbtDouble); node->getBasicType() == EbtDouble);
if (! arithemeticInt8Enabled) { if (! getArithemeticInt8Enabled()) {
if (((convertTo == EbtInt8 || convertTo == EbtUint8) && ! convertFromIntTypes) || if (((convertTo == EbtInt8 || convertTo == EbtUint8) && ! convertFromIntTypes) ||
((node->getBasicType() == EbtInt8 || node->getBasicType() == EbtUint8) && ! convertToIntTypes)) ((node->getBasicType() == EbtInt8 || node->getBasicType() == EbtUint8) && ! convertToIntTypes))
return nullptr; return nullptr;
} }
if (! arithemeticInt16Enabled) { if (! getArithemeticInt16Enabled()) {
if (((convertTo == EbtInt16 || convertTo == EbtUint16) && ! convertFromIntTypes) || if (((convertTo == EbtInt16 || convertTo == EbtUint16) && ! convertFromIntTypes) ||
((node->getBasicType() == EbtInt16 || node->getBasicType() == EbtUint16) && ! convertToIntTypes)) ((node->getBasicType() == EbtInt16 || node->getBasicType() == EbtUint16) && ! convertToIntTypes))
return nullptr; return nullptr;
} }
if (! arithemeticFloat16Enabled) { if (! getArithemeticFloat16Enabled()) {
if ((convertTo == EbtFloat16 && ! convertFromFloatTypes) || if ((convertTo == EbtFloat16 && ! convertFromFloatTypes) ||
(node->getBasicType() == EbtFloat16 && ! convertToFloatTypes)) (node->getBasicType() == EbtFloat16 && ! convertToFloatTypes))
return nullptr; return nullptr;
@ -841,9 +823,15 @@ TIntermTyped* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
newNode = addUnaryNode(newOp, node, node->getLoc(), newType); newNode = addUnaryNode(newOp, node, node->getLoc(), newType);
if (node->getAsConstantUnion()) { if (node->getAsConstantUnion()) {
TIntermTyped* folded = node->getAsConstantUnion()->fold(newOp, newType); // 8/16-bit storage extensions don't support 8/16-bit constants, so don't fold conversions
if (folded) // to those types
return folded; if ((getArithemeticInt8Enabled() || !(convertTo == EbtInt8 || convertTo == EbtUint8)) &&
(getArithemeticInt16Enabled() || !(convertTo == EbtInt16 || convertTo == EbtUint16)) &&
(getArithemeticFloat16Enabled() || !(convertTo == EbtFloat16))) {
TIntermTyped* folded = node->getAsConstantUnion()->fold(newOp, newType);
if (folded)
return folded;
}
} }
// Propagate specialization-constant-ness, if allowed // Propagate specialization-constant-ness, if allowed

View File

@ -6948,6 +6948,16 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
case EOpConstructF16Mat4x4: case EOpConstructF16Mat4x4:
case EOpConstructFloat16: case EOpConstructFloat16:
basicOp = EOpConstructFloat16; basicOp = EOpConstructFloat16;
// 8/16-bit storage extensions don't support constructing composites of 8/16-bit types,
// so construct a 32-bit type and convert
if (!intermediate.getArithemeticFloat16Enabled()) {
TType tempType(EbtFloat, EvqTemporary, type.getVectorSize());
newNode = node;
if (tempType != newNode->getType())
newNode = intermediate.setAggregateOperator(newNode, (TOperator)(EOpConstructVec2 + op - EOpConstructF16Vec2), tempType, node->getLoc());
newNode = intermediate.addConversion(EbtFloat16, newNode);
return newNode;
}
break; break;
case EOpConstructI8Vec2: case EOpConstructI8Vec2:
@ -6955,6 +6965,16 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
case EOpConstructI8Vec4: case EOpConstructI8Vec4:
case EOpConstructInt8: case EOpConstructInt8:
basicOp = EOpConstructInt8; basicOp = EOpConstructInt8;
// 8/16-bit storage extensions don't support constructing composites of 8/16-bit types,
// so construct a 32-bit type and convert
if (!intermediate.getArithemeticInt8Enabled()) {
TType tempType(EbtInt, EvqTemporary, type.getVectorSize());
newNode = node;
if (tempType != newNode->getType())
newNode = intermediate.setAggregateOperator(newNode, (TOperator)(EOpConstructIVec2 + op - EOpConstructI8Vec2), tempType, node->getLoc());
newNode = intermediate.addConversion(EbtInt8, newNode);
return newNode;
}
break; break;
case EOpConstructU8Vec2: case EOpConstructU8Vec2:
@ -6962,6 +6982,16 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
case EOpConstructU8Vec4: case EOpConstructU8Vec4:
case EOpConstructUint8: case EOpConstructUint8:
basicOp = EOpConstructUint8; basicOp = EOpConstructUint8;
// 8/16-bit storage extensions don't support constructing composites of 8/16-bit types,
// so construct a 32-bit type and convert
if (!intermediate.getArithemeticInt8Enabled()) {
TType tempType(EbtUint, EvqTemporary, type.getVectorSize());
newNode = node;
if (tempType != newNode->getType())
newNode = intermediate.setAggregateOperator(newNode, (TOperator)(EOpConstructUVec2 + op - EOpConstructU8Vec2), tempType, node->getLoc());
newNode = intermediate.addConversion(EbtUint8, newNode);
return newNode;
}
break; break;
case EOpConstructI16Vec2: case EOpConstructI16Vec2:
@ -6969,6 +6999,16 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
case EOpConstructI16Vec4: case EOpConstructI16Vec4:
case EOpConstructInt16: case EOpConstructInt16:
basicOp = EOpConstructInt16; basicOp = EOpConstructInt16;
// 8/16-bit storage extensions don't support constructing composites of 8/16-bit types,
// so construct a 32-bit type and convert
if (!intermediate.getArithemeticInt16Enabled()) {
TType tempType(EbtInt, EvqTemporary, type.getVectorSize());
newNode = node;
if (tempType != newNode->getType())
newNode = intermediate.setAggregateOperator(newNode, (TOperator)(EOpConstructIVec2 + op - EOpConstructI16Vec2), tempType, node->getLoc());
newNode = intermediate.addConversion(EbtInt16, newNode);
return newNode;
}
break; break;
case EOpConstructU16Vec2: case EOpConstructU16Vec2:
@ -6976,6 +7016,16 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
case EOpConstructU16Vec4: case EOpConstructU16Vec4:
case EOpConstructUint16: case EOpConstructUint16:
basicOp = EOpConstructUint16; basicOp = EOpConstructUint16;
// 8/16-bit storage extensions don't support constructing composites of 8/16-bit types,
// so construct a 32-bit type and convert
if (!intermediate.getArithemeticInt16Enabled()) {
TType tempType(EbtUint, EvqTemporary, type.getVectorSize());
newNode = node;
if (tempType != newNode->getType())
newNode = intermediate.setAggregateOperator(newNode, (TOperator)(EOpConstructUVec2 + op - EOpConstructU16Vec2), tempType, node->getLoc());
newNode = intermediate.addConversion(EbtUint16, newNode);
return newNode;
}
break; break;
case EOpConstructIVec2: case EOpConstructIVec2:

View File

@ -780,6 +780,27 @@ public:
const char* const implicitThisName; const char* const implicitThisName;
const char* const implicitCounterName; const char* const implicitCounterName;
// Certain explicit conversions are allowed conditionally
bool getArithemeticInt8Enabled() const {
return extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_int8);
}
bool getArithemeticInt16Enabled() const {
return extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
#ifdef AMD_EXTENSIONS
extensionRequested(E_GL_AMD_gpu_shader_int16) ||
#endif
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_int16);
}
bool getArithemeticFloat16Enabled() const {
return extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types) ||
#ifdef AMD_EXTENSIONS
extensionRequested(E_GL_AMD_gpu_shader_half_float) ||
#endif
extensionRequested(E_GL_EXT_shader_explicit_arithmetic_types_float16);
}
protected: protected:
TIntermSymbol* addSymbol(int Id, const TString&, const TType&, const TConstUnionArray&, TIntermTyped* subtree, const TSourceLoc&); TIntermSymbol* addSymbol(int Id, const TString&, const TType&, const TConstUnionArray&, TIntermTyped* subtree, const TSourceLoc&);
void error(TInfoSink& infoSink, const char*); void error(TInfoSink& infoSink, const char*);