Generate SPV_EXT_replicated_composites when requested by pragma.

Implement GL_EXT_spec_constant_composites.
This commit is contained in:
Jeff Bolz 2024-05-31 12:00:03 -05:00 committed by arcady-lunarg
parent 6a8b2b2439
commit 4da479aa6a
19 changed files with 656 additions and 14 deletions

View file

@ -399,6 +399,10 @@ void TParseContext::handlePragma(const TSourceLoc& loc, const TVector<TString>&
if (spvVersion.spv < glslang::EShTargetSpv_1_3)
error(loc, "requires SPIR-V 1.3", "#pragma use_variable_pointers", "");
intermediate.setUseVariablePointers();
} else if (spvVersion.spv > 0 && tokens[0].compare("use_replicated_composites") == 0) {
if (tokens.size() != 1)
error(loc, "extra tokens", "#pragma", "");
intermediate.setReplicatedComposites();
} else if (tokens[0].compare("once") == 0) {
warn(loc, "not implemented", "#pragma once", "");
} else if (tokens[0].compare("glslang_binary_double_output") == 0) {
@ -3613,6 +3617,19 @@ bool TParseContext::constructorError(const TSourceLoc& loc, TIntermNode* node, T
makeSpecConst = ! intArgument && !type.isArray();
break;
case EOpConstructCooperativeMatrixNV:
case EOpConstructCooperativeMatrixKHR:
case EOpConstructStruct:
{
const char *specConstantCompositeExt[] = { E_GL_EXT_spec_constant_composites };
if (checkExtensionsRequested(loc, 1, specConstantCompositeExt, "spec constant aggregate constructor")) {
makeSpecConst = true;
} else {
makeSpecConst = false;
}
}
break;
default:
// anything else wasn't white-listed in the spec as a conversion
makeSpecConst = false;
@ -8355,6 +8372,11 @@ TIntermTyped* TParseContext::addConstructor(const TSourceLoc& loc, TIntermNode*
int paramCount = 0; // keeps track of the constructor parameter number being checked
// We don't know "top down" whether type is a specialization constant,
// but a const becomes a specialization constant if any of its children are.
bool hasSpecConst = false;
bool isConstConstructor = true;
// for each parameter to the constructor call, check to see if the right type is passed or convert them
// to the right type if possible (and allowed).
// for structure constructors, just check if the right type is passed, no conversion is allowed.
@ -8367,13 +8389,24 @@ TIntermTyped* TParseContext::addConstructor(const TSourceLoc& loc, TIntermNode*
else
newNode = constructBuiltIn(type, op, (*p)->getAsTyped(), node->getLoc(), true);
if (newNode)
if (newNode) {
*p = newNode;
else
if (!newNode->getType().getQualifier().isConstant())
isConstConstructor = false;
if (newNode->getType().getQualifier().isSpecConstant())
hasSpecConst = true;
} else
return nullptr;
}
TIntermTyped *ret_node = intermediate.setAggregateOperator(aggrNode, op, type, loc);
TIntermTyped* ret_node = intermediate.setAggregateOperator(aggrNode, op, type, loc);
const char *specConstantCompositeExt[] = { E_GL_EXT_spec_constant_composites };
if (checkExtensionsRequested(loc, 1, specConstantCompositeExt, "spec constant aggregate constructor")) {
if (isConstConstructor && hasSpecConst) {
ret_node->getWritableType().getQualifier().makeSpecConstant();
}
}
TIntermAggregate *agg_node = ret_node->getAsAggregate();
if (agg_node && (agg_node->isVector() || agg_node->isArray() || agg_node->isMatrix()))