Avoid generating 8/16-bit constants when 8/16-bit arithmetic extensions aren't enabled
This commit is contained in:
parent
f970253a5d
commit
c1ad396258
10 changed files with 136 additions and 80 deletions
|
|
@ -574,24 +574,6 @@ TIntermTyped* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
|
|||
|
||||
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 ||
|
||||
convertTo == EbtInt16 || convertTo == EbtUint16 ||
|
||||
convertTo == EbtInt || convertTo == EbtUint ||
|
||||
|
|
@ -608,19 +590,19 @@ TIntermTyped* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
|
|||
node->getBasicType() == EbtFloat ||
|
||||
node->getBasicType() == EbtDouble);
|
||||
|
||||
if (! arithemeticInt8Enabled) {
|
||||
if (! getArithemeticInt8Enabled()) {
|
||||
if (((convertTo == EbtInt8 || convertTo == EbtUint8) && ! convertFromIntTypes) ||
|
||||
((node->getBasicType() == EbtInt8 || node->getBasicType() == EbtUint8) && ! convertToIntTypes))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (! arithemeticInt16Enabled) {
|
||||
if (! getArithemeticInt16Enabled()) {
|
||||
if (((convertTo == EbtInt16 || convertTo == EbtUint16) && ! convertFromIntTypes) ||
|
||||
((node->getBasicType() == EbtInt16 || node->getBasicType() == EbtUint16) && ! convertToIntTypes))
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (! arithemeticFloat16Enabled) {
|
||||
if (! getArithemeticFloat16Enabled()) {
|
||||
if ((convertTo == EbtFloat16 && ! convertFromFloatTypes) ||
|
||||
(node->getBasicType() == EbtFloat16 && ! convertToFloatTypes))
|
||||
return nullptr;
|
||||
|
|
@ -841,9 +823,15 @@ TIntermTyped* TIntermediate::createConversion(TBasicType convertTo, TIntermTyped
|
|||
newNode = addUnaryNode(newOp, node, node->getLoc(), newType);
|
||||
|
||||
if (node->getAsConstantUnion()) {
|
||||
TIntermTyped* folded = node->getAsConstantUnion()->fold(newOp, newType);
|
||||
if (folded)
|
||||
return folded;
|
||||
// 8/16-bit storage extensions don't support 8/16-bit constants, so don't fold conversions
|
||||
// to those types
|
||||
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
|
||||
|
|
|
|||
|
|
@ -6948,6 +6948,16 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
|
|||
case EOpConstructF16Mat4x4:
|
||||
case 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;
|
||||
|
||||
case EOpConstructI8Vec2:
|
||||
|
|
@ -6955,6 +6965,16 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
|
|||
case EOpConstructI8Vec4:
|
||||
case 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;
|
||||
|
||||
case EOpConstructU8Vec2:
|
||||
|
|
@ -6962,6 +6982,16 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
|
|||
case EOpConstructU8Vec4:
|
||||
case 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;
|
||||
|
||||
case EOpConstructI16Vec2:
|
||||
|
|
@ -6969,6 +6999,16 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
|
|||
case EOpConstructI16Vec4:
|
||||
case 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;
|
||||
|
||||
case EOpConstructU16Vec2:
|
||||
|
|
@ -6976,6 +7016,16 @@ TIntermTyped* TParseContext::constructBuiltIn(const TType& type, TOperator op, T
|
|||
case EOpConstructU16Vec4:
|
||||
case 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;
|
||||
|
||||
case EOpConstructIVec2:
|
||||
|
|
|
|||
|
|
@ -780,6 +780,27 @@ public:
|
|||
const char* const implicitThisName;
|
||||
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:
|
||||
TIntermSymbol* addSymbol(int Id, const TString&, const TType&, const TConstUnionArray&, TIntermTyped* subtree, const TSourceLoc&);
|
||||
void error(TInfoSink& infoSink, const char*);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue