Implement GL_EXT_null_initializer
Adds null initializer syntax (empty braces) Allows null initialization of shared variables
This commit is contained in:
committed by
Alan Baker
parent
6abdde3ce5
commit
c739e03748
@@ -3652,13 +3652,14 @@ spv::Id TGlslangToSpvTraverser::createSpvVariable(const glslang::TIntermSymbol*
|
||||
|
||||
spv::Id initializer = spv::NoResult;
|
||||
|
||||
if (node->getType().getQualifier().storage == glslang::EvqUniform &&
|
||||
!node->getConstArray().empty()) {
|
||||
int nextConst = 0;
|
||||
initializer = createSpvConstantFromConstUnionArray(node->getType(),
|
||||
node->getConstArray(),
|
||||
nextConst,
|
||||
false /* specConst */);
|
||||
if (node->getType().getQualifier().storage == glslang::EvqUniform && !node->getConstArray().empty()) {
|
||||
int nextConst = 0;
|
||||
initializer = createSpvConstantFromConstUnionArray(node->getType(),
|
||||
node->getConstArray(),
|
||||
nextConst,
|
||||
false /* specConst */);
|
||||
} else if (node->getType().getQualifier().isNullInit()) {
|
||||
initializer = builder.makeNullConstant(spvType);
|
||||
}
|
||||
|
||||
return builder.createVariable(spv::NoPrecision, storageClass, spvType, name, initializer);
|
||||
|
||||
@@ -869,6 +869,30 @@ bool Builder::isSpecConstantOpCode(Op opcode) const
|
||||
}
|
||||
}
|
||||
|
||||
Id Builder::makeNullConstant(Id typeId)
|
||||
{
|
||||
Instruction* constant;
|
||||
|
||||
// See if we already made it.
|
||||
Id existing = NoResult;
|
||||
for (int i = 0; i < (int)nullConstants.size(); ++i) {
|
||||
constant = nullConstants[i];
|
||||
if (constant->getTypeId() == typeId)
|
||||
existing = constant->getResultId();
|
||||
}
|
||||
|
||||
if (existing != NoResult)
|
||||
return existing;
|
||||
|
||||
// Make it
|
||||
Instruction* c = new Instruction(getUniqueId(), typeId, OpConstantNull);
|
||||
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(c));
|
||||
nullConstants.push_back(c);
|
||||
module.mapInstruction(c);
|
||||
|
||||
return c->getResultId();
|
||||
}
|
||||
|
||||
Id Builder::makeBoolConstant(bool b, bool specConstant)
|
||||
{
|
||||
Id typeId = makeBoolType();
|
||||
|
||||
@@ -293,6 +293,7 @@ public:
|
||||
}
|
||||
|
||||
// For making new constants (will return old constant if the requested one was already made).
|
||||
Id makeNullConstant(Id typeId);
|
||||
Id makeBoolConstant(bool b, bool specConstant = false);
|
||||
Id makeInt8Constant(int i, bool specConstant = false)
|
||||
{ return makeIntConstant(makeIntType(8), (unsigned)i, specConstant); }
|
||||
@@ -838,6 +839,8 @@ public:
|
||||
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedStructConstants;
|
||||
// map type opcodes to type instructions
|
||||
std::unordered_map<unsigned int, std::vector<Instruction*>> groupedTypes;
|
||||
// list of OpConstantNull instructions
|
||||
std::vector<Instruction*> nullConstants;
|
||||
|
||||
// stack of switches
|
||||
std::stack<Block*> switchMerges;
|
||||
|
||||
Reference in New Issue
Block a user