Updated glslang.

This commit is contained in:
Бранимир Караџић 2024-06-15 10:33:05 -07:00
parent ee481af66c
commit ad28ab88ab
12 changed files with 204 additions and 13 deletions

View File

@ -41,5 +41,6 @@ static const char* const E_SPV_EXT_shader_atomic_float_min_max = "SPV_EXT_shader
static const char* const E_SPV_EXT_shader_image_int64 = "SPV_EXT_shader_image_int64"; static const char* const E_SPV_EXT_shader_image_int64 = "SPV_EXT_shader_image_int64";
static const char* const E_SPV_EXT_shader_tile_image = "SPV_EXT_shader_tile_image"; static const char* const E_SPV_EXT_shader_tile_image = "SPV_EXT_shader_tile_image";
static const char* const E_SPV_EXT_mesh_shader = "SPV_EXT_mesh_shader"; static const char* const E_SPV_EXT_mesh_shader = "SPV_EXT_mesh_shader";
static const char* const E_SPV_ARM_cooperative_matrix_layouts = "SPV_ARM_cooperative_matrix_layouts";
#endif // #ifndef GLSLextEXT_H #endif // #ifndef GLSLextEXT_H

View File

@ -61,5 +61,7 @@ static const char* const E_SPV_KHR_cooperative_matrix = "SPV_KHR_coope
static const char* const E_SPV_KHR_maximal_reconvergence = "SPV_KHR_maximal_reconvergence"; static const char* const E_SPV_KHR_maximal_reconvergence = "SPV_KHR_maximal_reconvergence";
static const char* const E_SPV_KHR_subgroup_rotate = "SPV_KHR_subgroup_rotate"; static const char* const E_SPV_KHR_subgroup_rotate = "SPV_KHR_subgroup_rotate";
static const char* const E_SPV_KHR_expect_assume = "SPV_KHR_expect_assume"; static const char* const E_SPV_KHR_expect_assume = "SPV_KHR_expect_assume";
static const char* const E_SPV_EXT_replicated_composites = "SPV_EXT_replicated_composites";
static const char* const E_SPV_KHR_relaxed_extended_instruction = "SPV_KHR_relaxed_extended_instruction";
#endif // #ifndef GLSLextKHR_H #endif // #ifndef GLSLextKHR_H

View File

@ -1583,6 +1583,8 @@ TGlslangToSpvTraverser::TGlslangToSpvTraverser(unsigned int spvVersion,
builder.addInclude(iItr->first, iItr->second); builder.addInclude(iItr->first, iItr->second);
} }
builder.setUseReplicatedComposites(glslangIntermediate->usingReplicatedComposites());
stdBuiltins = builder.import("GLSL.std.450"); stdBuiltins = builder.import("GLSL.std.450");
spv::AddressingModel addressingModel = spv::AddressingModelLogical; spv::AddressingModel addressingModel = spv::AddressingModelLogical;
@ -3703,6 +3705,12 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
idImmOps.push_back(spv::IdImmediate(true, operands[1])); // buf idImmOps.push_back(spv::IdImmediate(true, operands[1])); // buf
if (node->getOp() == glslang::EOpCooperativeMatrixLoad) { if (node->getOp() == glslang::EOpCooperativeMatrixLoad) {
idImmOps.push_back(spv::IdImmediate(true, operands[3])); // matrixLayout idImmOps.push_back(spv::IdImmediate(true, operands[3])); // matrixLayout
auto layout = builder.getConstantScalar(operands[3]);
if (layout == spv::CooperativeMatrixLayoutRowBlockedInterleavedARM ||
layout == spv::CooperativeMatrixLayoutColumnBlockedInterleavedARM) {
builder.addExtension(spv::E_SPV_ARM_cooperative_matrix_layouts);
builder.addCapability(spv::CapabilityCooperativeMatrixLayoutsARM);
}
idImmOps.push_back(spv::IdImmediate(true, operands[2])); // stride idImmOps.push_back(spv::IdImmediate(true, operands[2])); // stride
} else { } else {
idImmOps.push_back(spv::IdImmediate(true, operands[2])); // stride idImmOps.push_back(spv::IdImmediate(true, operands[2])); // stride
@ -3727,6 +3735,12 @@ bool TGlslangToSpvTraverser::visitAggregate(glslang::TVisit visit, glslang::TInt
idImmOps.push_back(spv::IdImmediate(true, operands[0])); // object idImmOps.push_back(spv::IdImmediate(true, operands[0])); // object
if (node->getOp() == glslang::EOpCooperativeMatrixStore) { if (node->getOp() == glslang::EOpCooperativeMatrixStore) {
idImmOps.push_back(spv::IdImmediate(true, operands[3])); // matrixLayout idImmOps.push_back(spv::IdImmediate(true, operands[3])); // matrixLayout
auto layout = builder.getConstantScalar(operands[3]);
if (layout == spv::CooperativeMatrixLayoutRowBlockedInterleavedARM ||
layout == spv::CooperativeMatrixLayoutColumnBlockedInterleavedARM) {
builder.addExtension(spv::E_SPV_ARM_cooperative_matrix_layouts);
builder.addCapability(spv::CapabilityCooperativeMatrixLayoutsARM);
}
idImmOps.push_back(spv::IdImmediate(true, operands[2])); // stride idImmOps.push_back(spv::IdImmediate(true, operands[2])); // stride
} else { } else {
idImmOps.push_back(spv::IdImmediate(true, operands[2])); // stride idImmOps.push_back(spv::IdImmediate(true, operands[2])); // stride
@ -5787,8 +5801,16 @@ void TGlslangToSpvTraverser::translateArguments(const glslang::TIntermAggregate&
lvalueCoherentFlags = builder.getAccessChain().coherentFlags; lvalueCoherentFlags = builder.getAccessChain().coherentFlags;
builder.addDecoration(lvalue_id, TranslateNonUniformDecoration(lvalueCoherentFlags)); builder.addDecoration(lvalue_id, TranslateNonUniformDecoration(lvalueCoherentFlags));
lvalueCoherentFlags |= TranslateCoherent(glslangArguments[i]->getAsTyped()->getType()); lvalueCoherentFlags |= TranslateCoherent(glslangArguments[i]->getAsTyped()->getType());
} else } else {
arguments.push_back(accessChainLoad(glslangArguments[i]->getAsTyped()->getType())); if (i > 0 &&
glslangArguments[i]->getAsSymbolNode() && glslangArguments[i-1]->getAsSymbolNode() &&
glslangArguments[i]->getAsSymbolNode()->getId() == glslangArguments[i-1]->getAsSymbolNode()->getId()) {
// Reuse the id if possible
arguments.push_back(arguments[i-1]);
} else {
arguments.push_back(accessChainLoad(glslangArguments[i]->getAsTyped()->getType()));
}
}
} }
} }

View File

@ -182,6 +182,10 @@ Id Builder::makeForwardPointer(StorageClass storageClass)
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type)); constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type); module.mapInstruction(type);
if (emitNonSemanticShaderDebugInfo) {
const Id debugResultId = makeForwardPointerDebugType(storageClass);
debugId[type->getResultId()] = debugResultId;
}
return type->getResultId(); return type->getResultId();
} }
@ -204,6 +208,15 @@ Id Builder::makePointerFromForwardPointer(StorageClass storageClass, Id forwardP
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type)); constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type); module.mapInstruction(type);
// If we are emitting nonsemantic debuginfo, we need to patch the debug pointer type
// that was emitted alongside the forward pointer, now that we have a pointee debug
// type for it to point to.
if (emitNonSemanticShaderDebugInfo) {
Instruction *debugForwardPointer = module.getInstruction(debugId[forwardPointerType]);
assert(debugId[pointee]);
debugForwardPointer->setIdOperand(2, debugId[pointee]);
}
return type->getResultId(); return type->getResultId();
} }
@ -1045,6 +1058,29 @@ Id Builder::makePointerDebugType(StorageClass storageClass, Id const baseType)
return type->getResultId(); return type->getResultId();
} }
// Emit a OpExtInstWithForwardRefsKHR nonsemantic instruction for a pointer debug type
// where we don't have the pointee yet. Since we don't have the pointee yet, it just
// points to itself and we rely on patching it later.
Id Builder::makeForwardPointerDebugType(StorageClass storageClass)
{
const Id scID = makeUintConstant(storageClass);
this->addExtension(spv::E_SPV_KHR_relaxed_extended_instruction);
Instruction *type = new Instruction(getUniqueId(), makeVoidType(), OpExtInstWithForwardRefsKHR);
type->addIdOperand(nonSemanticShaderDebugInfo);
type->addImmediateOperand(NonSemanticShaderDebugInfo100DebugTypePointer);
type->addIdOperand(type->getResultId());
type->addIdOperand(scID);
type->addIdOperand(makeUintConstant(0));
groupedDebugTypes[NonSemanticShaderDebugInfo100DebugTypePointer].push_back(type);
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
return type->getResultId();
}
Id Builder::makeDebugSource(const Id fileName) { Id Builder::makeDebugSource(const Id fileName) {
if (debugSourceId.find(fileName) != debugSourceId.end()) if (debugSourceId.find(fileName) != debugSourceId.end())
return debugSourceId[fileName]; return debugSourceId[fileName];
@ -1484,12 +1520,14 @@ bool Builder::isConstantOpCode(Op opcode) const
case OpConstantFalse: case OpConstantFalse:
case OpConstant: case OpConstant:
case OpConstantComposite: case OpConstantComposite:
case OpConstantCompositeReplicateEXT:
case OpConstantSampler: case OpConstantSampler:
case OpConstantNull: case OpConstantNull:
case OpSpecConstantTrue: case OpSpecConstantTrue:
case OpSpecConstantFalse: case OpSpecConstantFalse:
case OpSpecConstant: case OpSpecConstant:
case OpSpecConstantComposite: case OpSpecConstantComposite:
case OpSpecConstantCompositeReplicateEXT:
case OpSpecConstantOp: case OpSpecConstantOp:
return true; return true;
default: default:
@ -1506,6 +1544,7 @@ bool Builder::isSpecConstantOpCode(Op opcode) const
case OpSpecConstant: case OpSpecConstant:
case OpSpecConstantComposite: case OpSpecConstantComposite:
case OpSpecConstantOp: case OpSpecConstantOp:
case OpSpecConstantCompositeReplicateEXT:
return true; return true;
default: default:
return false; return false;
@ -1782,10 +1821,27 @@ Id Builder::findStructConstant(Id typeId, const std::vector<Id>& comps)
// Comments in header // Comments in header
Id Builder::makeCompositeConstant(Id typeId, const std::vector<Id>& members, bool specConstant) Id Builder::makeCompositeConstant(Id typeId, const std::vector<Id>& members, bool specConstant)
{ {
Op opcode = specConstant ? OpSpecConstantComposite : OpConstantComposite;
assert(typeId); assert(typeId);
Op typeClass = getTypeClass(typeId); Op typeClass = getTypeClass(typeId);
bool replicate = false;
size_t numMembers = members.size();
if (useReplicatedComposites) {
// use replicate if all members are the same
replicate = numMembers > 0 &&
std::equal(members.begin() + 1, members.end(), members.begin());
if (replicate) {
numMembers = 1;
addCapability(spv::CapabilityReplicatedCompositesEXT);
addExtension(spv::E_SPV_EXT_replicated_composites);
}
}
Op opcode = replicate ?
(specConstant ? OpSpecConstantCompositeReplicateEXT : OpConstantCompositeReplicateEXT) :
(specConstant ? OpSpecConstantComposite : OpConstantComposite);
switch (typeClass) { switch (typeClass) {
case OpTypeVector: case OpTypeVector:
case OpTypeArray: case OpTypeArray:
@ -1812,7 +1868,7 @@ Id Builder::makeCompositeConstant(Id typeId, const std::vector<Id>& members, boo
Instruction* c = new Instruction(getUniqueId(), typeId, opcode); Instruction* c = new Instruction(getUniqueId(), typeId, opcode);
c->reserveOperands(members.size()); c->reserveOperands(members.size());
for (int op = 0; op < (int)members.size(); ++op) for (size_t op = 0; op < numMembers; ++op)
c->addIdOperand(members[op]); c->addIdOperand(members[op]);
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(c)); constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(c));
if (typeClass == OpTypeStruct) if (typeClass == OpTypeStruct)
@ -2928,7 +2984,17 @@ Id Builder::smearScalar(Decoration precision, Id scalar, Id vectorType)
auto result_id = makeCompositeConstant(vectorType, members, isSpecConstant(scalar)); auto result_id = makeCompositeConstant(vectorType, members, isSpecConstant(scalar));
smear = module.getInstruction(result_id); smear = module.getInstruction(result_id);
} else { } else {
smear = new Instruction(getUniqueId(), vectorType, OpCompositeConstruct); bool replicate = useReplicatedComposites && (numComponents > 0);
if (replicate) {
numComponents = 1;
addCapability(spv::CapabilityReplicatedCompositesEXT);
addExtension(spv::E_SPV_EXT_replicated_composites);
}
Op opcode = replicate ? OpCompositeConstructReplicateEXT : OpCompositeConstruct;
smear = new Instruction(getUniqueId(), vectorType, opcode);
smear->reserveOperands(numComponents); smear->reserveOperands(numComponents);
for (int c = 0; c < numComponents; ++c) for (int c = 0; c < numComponents; ++c)
smear->addIdOperand(scalar); smear->addIdOperand(scalar);
@ -3321,9 +3387,25 @@ Id Builder::createCompositeConstruct(Id typeId, const std::vector<Id>& constitue
[&](spv::Id id) { return isSpecConstant(id); })); [&](spv::Id id) { return isSpecConstant(id); }));
} }
Instruction* op = new Instruction(getUniqueId(), typeId, OpCompositeConstruct); bool replicate = false;
size_t numConstituents = constituents.size();
if (useReplicatedComposites) {
replicate = numConstituents > 0 &&
std::equal(constituents.begin() + 1, constituents.end(), constituents.begin());
}
if (replicate) {
numConstituents = 1;
addCapability(spv::CapabilityReplicatedCompositesEXT);
addExtension(spv::E_SPV_EXT_replicated_composites);
}
Op opcode = replicate ? OpCompositeConstructReplicateEXT : OpCompositeConstruct;
Instruction* op = new Instruction(getUniqueId(), typeId, opcode);
op->reserveOperands(constituents.size()); op->reserveOperands(constituents.size());
for (int c = 0; c < (int)constituents.size(); ++c) for (size_t c = 0; c < numConstituents; ++c)
op->addIdOperand(constituents[c]); op->addIdOperand(constituents[c]);
addInstruction(std::unique_ptr<Instruction>(op)); addInstruction(std::unique_ptr<Instruction>(op));
@ -3458,6 +3540,13 @@ Id Builder::createMatrixConstructor(Decoration precision, const std::vector<Id>&
return setPrecision(createCompositeConstruct(resultTypeId, matrixColumns), precision); return setPrecision(createCompositeConstruct(resultTypeId, matrixColumns), precision);
} }
// Detect a matrix being constructed from a repeated vector of the correct size.
// Create the composite directly from it.
if ((int)sources.size() == numCols && isVector(sources[0]) && getNumComponents(sources[0]) == numRows &&
std::equal(sources.begin() + 1, sources.end(), sources.begin())) {
return setPrecision(createCompositeConstruct(resultTypeId, sources), precision);
}
// Otherwise, will use a two step process // Otherwise, will use a two step process
// 1. make a compile-time 2D array of values // 1. make a compile-time 2D array of values
// 2. construct a matrix from that array // 2. construct a matrix from that array

View File

@ -235,6 +235,7 @@ public:
Id makeCompositeDebugType(std::vector<Id> const& memberTypes, char const*const name, Id makeCompositeDebugType(std::vector<Id> const& memberTypes, char const*const name,
NonSemanticShaderDebugInfo100DebugCompositeType const tag, bool const isOpaqueType = false); NonSemanticShaderDebugInfo100DebugCompositeType const tag, bool const isOpaqueType = false);
Id makePointerDebugType(StorageClass storageClass, Id const baseType); Id makePointerDebugType(StorageClass storageClass, Id const baseType);
Id makeForwardPointerDebugType(StorageClass storageClass);
Id makeDebugSource(const Id fileName); Id makeDebugSource(const Id fileName);
Id makeDebugCompilationUnit(); Id makeDebugCompilationUnit();
Id createDebugGlobalVariable(Id const type, char const*const name, Id const variable); Id createDebugGlobalVariable(Id const type, char const*const name, Id const variable);
@ -872,6 +873,8 @@ public:
// Check if the builder is generating code for spec constants. // Check if the builder is generating code for spec constants.
bool isInSpecConstCodeGenMode() { return generatingOpCodeForSpecConst; } bool isInSpecConstCodeGenMode() { return generatingOpCodeForSpecConst; }
void setUseReplicatedComposites(bool use) { useReplicatedComposites = use; }
protected: protected:
Id makeIntConstant(Id typeId, unsigned value, bool specConstant); Id makeIntConstant(Id typeId, unsigned value, bool specConstant);
Id makeInt64Constant(Id typeId, unsigned long long value, bool specConstant); Id makeInt64Constant(Id typeId, unsigned long long value, bool specConstant);
@ -938,6 +941,7 @@ public:
Id uniqueId; Id uniqueId;
Function* entryPointFunction; Function* entryPointFunction;
bool generatingOpCodeForSpecConst; bool generatingOpCodeForSpecConst;
bool useReplicatedComposites { false };
AccessChain accessChain; AccessChain accessChain;
// special blocks of instructions for output // special blocks of instructions for output

View File

@ -1035,6 +1035,8 @@ const char* CapabilityString(int info)
case CapabilityTileImageDepthReadAccessEXT: return "TileImageDepthReadAccessEXT"; case CapabilityTileImageDepthReadAccessEXT: return "TileImageDepthReadAccessEXT";
case CapabilityTileImageStencilReadAccessEXT: return "TileImageStencilReadAccessEXT"; case CapabilityTileImageStencilReadAccessEXT: return "TileImageStencilReadAccessEXT";
case CapabilityCooperativeMatrixLayoutsARM: return "CooperativeMatrixLayoutsARM";
case CapabilityFragmentShadingRateKHR: return "FragmentShadingRateKHR"; case CapabilityFragmentShadingRateKHR: return "FragmentShadingRateKHR";
case CapabilityDemoteToHelperInvocationEXT: return "DemoteToHelperInvocationEXT"; case CapabilityDemoteToHelperInvocationEXT: return "DemoteToHelperInvocationEXT";
@ -1066,6 +1068,8 @@ const char* CapabilityString(int info)
case CapabilityTextureBlockMatchQCOM: return "TextureBlockMatchQCOM"; case CapabilityTextureBlockMatchQCOM: return "TextureBlockMatchQCOM";
case CapabilityTextureBlockMatch2QCOM: return "TextureBlockMatch2QCOM"; case CapabilityTextureBlockMatch2QCOM: return "TextureBlockMatch2QCOM";
case CapabilityReplicatedCompositesEXT: return "CapabilityReplicatedCompositesEXT";
default: return "Bad"; default: return "Bad";
} }
} }
@ -1443,6 +1447,7 @@ const char* OpcodeString(int op)
case 4429: return "OpSubgroupAnyKHR"; case 4429: return "OpSubgroupAnyKHR";
case 4430: return "OpSubgroupAllEqualKHR"; case 4430: return "OpSubgroupAllEqualKHR";
case 4432: return "OpSubgroupReadInvocationKHR"; case 4432: return "OpSubgroupReadInvocationKHR";
case 4433: return "OpExtInstWithForwardRefsKHR";
case OpGroupNonUniformQuadAllKHR: return "OpGroupNonUniformQuadAllKHR"; case OpGroupNonUniformQuadAllKHR: return "OpGroupNonUniformQuadAllKHR";
case OpGroupNonUniformQuadAnyKHR: return "OpGroupNonUniformQuadAnyKHR"; case OpGroupNonUniformQuadAnyKHR: return "OpGroupNonUniformQuadAnyKHR";
@ -1584,6 +1589,10 @@ const char* OpcodeString(int op)
case OpImageBlockMatchGatherSSDQCOM: return "OpImageBlockMatchGatherSSDQCOM"; case OpImageBlockMatchGatherSSDQCOM: return "OpImageBlockMatchGatherSSDQCOM";
case OpImageBlockMatchGatherSADQCOM: return "OpImageBlockMatchGatherSADQCOM"; case OpImageBlockMatchGatherSADQCOM: return "OpImageBlockMatchGatherSADQCOM";
case OpConstantCompositeReplicateEXT: return "OpConstantCompositeReplicateEXT";
case OpSpecConstantCompositeReplicateEXT: return "OpSpecConstantCompositeReplicateEXT";
case OpCompositeConstructReplicateEXT: return "OpCompositeConstructReplicateEXT";
default: default:
return "Bad"; return "Bad";
} }
@ -1890,6 +1899,10 @@ void Parameterize()
InstructionDesc[OpExtInst].operands.push(OperandLiteralNumber, "'Instruction'"); InstructionDesc[OpExtInst].operands.push(OperandLiteralNumber, "'Instruction'");
InstructionDesc[OpExtInst].operands.push(OperandVariableIds, "'Operand 1', +\n'Operand 2', +\n..."); InstructionDesc[OpExtInst].operands.push(OperandVariableIds, "'Operand 1', +\n'Operand 2', +\n...");
InstructionDesc[OpExtInstWithForwardRefsKHR].operands.push(OperandId, "'Set'");
InstructionDesc[OpExtInstWithForwardRefsKHR].operands.push(OperandLiteralNumber, "'Instruction'");
InstructionDesc[OpExtInstWithForwardRefsKHR].operands.push(OperandVariableIds, "'Operand 1', +\n'Operand 2', +\n...");
InstructionDesc[OpLoad].operands.push(OperandId, "'Pointer'"); InstructionDesc[OpLoad].operands.push(OperandId, "'Pointer'");
InstructionDesc[OpLoad].operands.push(OperandMemoryAccess, "", true); InstructionDesc[OpLoad].operands.push(OperandMemoryAccess, "", true);
InstructionDesc[OpLoad].operands.push(OperandLiteralNumber, "", true); InstructionDesc[OpLoad].operands.push(OperandLiteralNumber, "", true);
@ -3471,6 +3484,10 @@ void Parameterize()
InstructionDesc[OpImageBlockMatchGatherSADQCOM].operands.push(OperandId, "'block size'"); InstructionDesc[OpImageBlockMatchGatherSADQCOM].operands.push(OperandId, "'block size'");
InstructionDesc[OpImageBlockMatchGatherSADQCOM].operands.push(OperandImageOperands, "", true); InstructionDesc[OpImageBlockMatchGatherSADQCOM].operands.push(OperandImageOperands, "", true);
InstructionDesc[OpImageBlockMatchGatherSADQCOM].setResultAndType(true, true); InstructionDesc[OpImageBlockMatchGatherSADQCOM].setResultAndType(true, true);
InstructionDesc[OpConstantCompositeReplicateEXT].operands.push(OperandId, "'Value'");
InstructionDesc[OpSpecConstantCompositeReplicateEXT].operands.push(OperandId, "'Value'");
InstructionDesc[OpCompositeConstructReplicateEXT].operands.push(OperandId, "'Value'");
}); });
} }

View File

@ -1002,6 +1002,7 @@ enum Capability {
CapabilityTileImageColorReadAccessEXT = 4166, CapabilityTileImageColorReadAccessEXT = 4166,
CapabilityTileImageDepthReadAccessEXT = 4167, CapabilityTileImageDepthReadAccessEXT = 4167,
CapabilityTileImageStencilReadAccessEXT = 4168, CapabilityTileImageStencilReadAccessEXT = 4168,
CapabilityCooperativeMatrixLayoutsARM = 4201,
CapabilityFragmentShadingRateKHR = 4422, CapabilityFragmentShadingRateKHR = 4422,
CapabilitySubgroupBallotKHR = 4423, CapabilitySubgroupBallotKHR = 4423,
CapabilityDrawParameters = 4427, CapabilityDrawParameters = 4427,
@ -1162,7 +1163,8 @@ enum Capability {
CapabilityDotProduct = 6019, CapabilityDotProduct = 6019,
CapabilityDotProductKHR = 6019, CapabilityDotProductKHR = 6019,
CapabilityRayCullMaskKHR = 6020, CapabilityRayCullMaskKHR = 6020,
CapabilityCooperativeMatrixKHR = 6022, CapabilityCooperativeMatrixKHR = 6022,
CapabilityReplicatedCompositesEXT = 6024,
CapabilityBitInstructions = 6025, CapabilityBitInstructions = 6025,
CapabilityGroupNonUniformRotateKHR = 6026, CapabilityGroupNonUniformRotateKHR = 6026,
CapabilityAtomicFloat32AddEXT = 6033, CapabilityAtomicFloat32AddEXT = 6033,
@ -1301,6 +1303,8 @@ enum CooperativeMatrixOperandsMask {
enum CooperativeMatrixLayout { enum CooperativeMatrixLayout {
CooperativeMatrixLayoutRowMajorKHR = 0, CooperativeMatrixLayoutRowMajorKHR = 0,
CooperativeMatrixLayoutColumnMajorKHR = 1, CooperativeMatrixLayoutColumnMajorKHR = 1,
CooperativeMatrixLayoutRowBlockedInterleavedARM = 4202,
CooperativeMatrixLayoutColumnBlockedInterleavedARM = 4203,
CooperativeMatrixLayoutMax = 0x7fffffff, CooperativeMatrixLayoutMax = 0x7fffffff,
}; };
@ -1667,6 +1671,7 @@ enum Op {
OpSubgroupAllEqualKHR = 4430, OpSubgroupAllEqualKHR = 4430,
OpGroupNonUniformRotateKHR = 4431, OpGroupNonUniformRotateKHR = 4431,
OpSubgroupReadInvocationKHR = 4432, OpSubgroupReadInvocationKHR = 4432,
OpExtInstWithForwardRefsKHR = 4433,
OpTraceRayKHR = 4445, OpTraceRayKHR = 4445,
OpExecuteCallableKHR = 4446, OpExecuteCallableKHR = 4446,
OpConvertUToAccelerationStructureKHR = 4447, OpConvertUToAccelerationStructureKHR = 4447,
@ -1688,7 +1693,10 @@ enum Op {
OpCooperativeMatrixLoadKHR = 4457, OpCooperativeMatrixLoadKHR = 4457,
OpCooperativeMatrixStoreKHR = 4458, OpCooperativeMatrixStoreKHR = 4458,
OpCooperativeMatrixMulAddKHR = 4459, OpCooperativeMatrixMulAddKHR = 4459,
OpCooperativeMatrixLengthKHR = 4460, OpCooperativeMatrixLengthKHR = 4460,
OpConstantCompositeReplicateEXT = 4461,
OpSpecConstantCompositeReplicateEXT = 4462,
OpCompositeConstructReplicateEXT = 4463,
OpTypeRayQueryKHR = 4472, OpTypeRayQueryKHR = 4472,
OpRayQueryInitializeKHR = 4473, OpRayQueryInitializeKHR = 4473,
OpRayQueryTerminateKHR = 4474, OpRayQueryTerminateKHR = 4474,
@ -2391,6 +2399,7 @@ inline void HasResultAndType(Op opcode, bool *hasResult, bool *hasResultType) {
case OpPtrEqual: *hasResult = true; *hasResultType = true; break; case OpPtrEqual: *hasResult = true; *hasResultType = true; break;
case OpPtrNotEqual: *hasResult = true; *hasResultType = true; break; case OpPtrNotEqual: *hasResult = true; *hasResultType = true; break;
case OpPtrDiff: *hasResult = true; *hasResultType = true; break; case OpPtrDiff: *hasResult = true; *hasResultType = true; break;
case OpExtInstWithForwardRefsKHR: *hasResult = true; *hasResultType = true; break;
case OpColorAttachmentReadEXT: *hasResult = true; *hasResultType = true; break; case OpColorAttachmentReadEXT: *hasResult = true; *hasResultType = true; break;
case OpDepthAttachmentReadEXT: *hasResult = true; *hasResultType = true; break; case OpDepthAttachmentReadEXT: *hasResult = true; *hasResultType = true; break;
case OpStencilAttachmentReadEXT: *hasResult = true; *hasResultType = true; break; case OpStencilAttachmentReadEXT: *hasResult = true; *hasResultType = true; break;
@ -2417,7 +2426,10 @@ inline void HasResultAndType(Op opcode, bool *hasResult, bool *hasResultType) {
case OpCooperativeMatrixLoadKHR: *hasResult = true; *hasResultType = true; break; case OpCooperativeMatrixLoadKHR: *hasResult = true; *hasResultType = true; break;
case OpCooperativeMatrixStoreKHR: *hasResult = false; *hasResultType = false; break; case OpCooperativeMatrixStoreKHR: *hasResult = false; *hasResultType = false; break;
case OpCooperativeMatrixMulAddKHR: *hasResult = true; *hasResultType = true; break; case OpCooperativeMatrixMulAddKHR: *hasResult = true; *hasResultType = true; break;
case OpCooperativeMatrixLengthKHR: *hasResult = true; *hasResultType = true; break; case OpCooperativeMatrixLengthKHR: *hasResult = true; *hasResultType = true; break;
case OpConstantCompositeReplicateEXT: *hasResult = true; *hasResultType = true; break;
case OpSpecConstantCompositeReplicateEXT: *hasResult = true; *hasResultType = true; break;
case OpCompositeConstructReplicateEXT: *hasResult = true; *hasResultType = true; break;
case OpTypeRayQueryKHR: *hasResult = true; *hasResultType = false; break; case OpTypeRayQueryKHR: *hasResult = true; *hasResultType = false; break;
case OpRayQueryInitializeKHR: *hasResult = false; *hasResultType = false; break; case OpRayQueryInitializeKHR: *hasResult = false; *hasResultType = false; break;
case OpRayQueryTerminateKHR: *hasResult = false; *hasResultType = false; break; case OpRayQueryTerminateKHR: *hasResult = false; *hasResultType = false; break;

View File

@ -4558,6 +4558,8 @@ void TBuiltIns::initialize(int version, EProfile profile, const SpvVersion& spvV
"const int gl_MatrixOperandsSaturatingAccumulation = 0x10;\n" "const int gl_MatrixOperandsSaturatingAccumulation = 0x10;\n"
"const int gl_CooperativeMatrixLayoutRowMajor = 0;\n" "const int gl_CooperativeMatrixLayoutRowMajor = 0;\n"
"const int gl_CooperativeMatrixLayoutColumnMajor = 1;\n" "const int gl_CooperativeMatrixLayoutColumnMajor = 1;\n"
"const int gl_CooperativeMatrixLayoutRowBlockedInterleavedARM = 4202;\n"
"const int gl_CooperativeMatrixLayoutColumnBlockedInterleavedARM = 4203;\n"
"\n" "\n"
); );
} }

View File

@ -399,6 +399,10 @@ void TParseContext::handlePragma(const TSourceLoc& loc, const TVector<TString>&
if (spvVersion.spv < glslang::EShTargetSpv_1_3) if (spvVersion.spv < glslang::EShTargetSpv_1_3)
error(loc, "requires SPIR-V 1.3", "#pragma use_variable_pointers", ""); error(loc, "requires SPIR-V 1.3", "#pragma use_variable_pointers", "");
intermediate.setUseVariablePointers(); 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) { } else if (tokens[0].compare("once") == 0) {
warn(loc, "not implemented", "#pragma once", ""); warn(loc, "not implemented", "#pragma once", "");
} else if (tokens[0].compare("glslang_binary_double_output") == 0) { } 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(); makeSpecConst = ! intArgument && !type.isArray();
break; 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: default:
// anything else wasn't white-listed in the spec as a conversion // anything else wasn't white-listed in the spec as a conversion
makeSpecConst = false; 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 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 // 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). // to the right type if possible (and allowed).
// for structure constructors, just check if the right type is passed, no conversion is 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 else
newNode = constructBuiltIn(type, op, (*p)->getAsTyped(), node->getLoc(), true); newNode = constructBuiltIn(type, op, (*p)->getAsTyped(), node->getLoc(), true);
if (newNode) if (newNode) {
*p = newNode; *p = newNode;
else if (!newNode->getType().getQualifier().isConstant())
isConstConstructor = false;
if (newNode->getType().getQualifier().isSpecConstant())
hasSpecConst = true;
} else
return nullptr; 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(); TIntermAggregate *agg_node = ret_node->getAsAggregate();
if (agg_node && (agg_node->isVector() || agg_node->isArray() || agg_node->isMatrix())) if (agg_node && (agg_node->isVector() || agg_node->isArray() || agg_node->isMatrix()))

View File

@ -265,6 +265,7 @@ void TParseVersions::initializeExtensionBehavior()
extensionBehavior[E_GL_EXT_expect_assume] = EBhDisable; extensionBehavior[E_GL_EXT_expect_assume] = EBhDisable;
extensionBehavior[E_GL_EXT_control_flow_attributes2] = EBhDisable; extensionBehavior[E_GL_EXT_control_flow_attributes2] = EBhDisable;
extensionBehavior[E_GL_EXT_spec_constant_composites] = EBhDisable;
extensionBehavior[E_GL_KHR_cooperative_matrix] = EBhDisable; extensionBehavior[E_GL_KHR_cooperative_matrix] = EBhDisable;
@ -519,6 +520,7 @@ void TParseVersions::getPreamble(std::string& preamble)
"#define GL_EXT_fragment_shading_rate 1\n" "#define GL_EXT_fragment_shading_rate 1\n"
"#define GL_EXT_shared_memory_block 1\n" "#define GL_EXT_shared_memory_block 1\n"
"#define GL_EXT_shader_integer_mix 1\n" "#define GL_EXT_shader_integer_mix 1\n"
"#define GL_EXT_spec_constant_composites 1\n"
// GL_KHR_shader_subgroup // GL_KHR_shader_subgroup
"#define GL_KHR_shader_subgroup_basic 1\n" "#define GL_KHR_shader_subgroup_basic 1\n"

View File

@ -222,6 +222,7 @@ const char* const E_GL_EXT_texture_array = "GL_EXT_texture_ar
const char* const E_GL_EXT_maximal_reconvergence = "GL_EXT_maximal_reconvergence"; const char* const E_GL_EXT_maximal_reconvergence = "GL_EXT_maximal_reconvergence";
const char* const E_GL_EXT_expect_assume = "GL_EXT_expect_assume"; const char* const E_GL_EXT_expect_assume = "GL_EXT_expect_assume";
const char* const E_GL_EXT_control_flow_attributes2 = "GL_EXT_control_flow_attributes2"; const char* const E_GL_EXT_control_flow_attributes2 = "GL_EXT_control_flow_attributes2";
const char* const E_GL_EXT_spec_constant_composites = "GL_EXT_spec_constant_composites";
// Arrays of extensions for the above viewportEXTs duplications // Arrays of extensions for the above viewportEXTs duplications

View File

@ -729,6 +729,11 @@ public:
usePhysicalStorageBuffer = true; usePhysicalStorageBuffer = true;
} }
bool usingPhysicalStorageBuffer() const { return usePhysicalStorageBuffer; } bool usingPhysicalStorageBuffer() const { return usePhysicalStorageBuffer; }
void setReplicatedComposites()
{
useReplicatedComposites = true;
}
bool usingReplicatedComposites() const { return useReplicatedComposites; }
void setUseVariablePointers() void setUseVariablePointers()
{ {
useVariablePointers = true; useVariablePointers = true;
@ -1242,6 +1247,7 @@ protected:
bool subgroupUniformControlFlow; bool subgroupUniformControlFlow;
bool maximallyReconverges; bool maximallyReconverges;
bool usePhysicalStorageBuffer; bool usePhysicalStorageBuffer;
bool useReplicatedComposites { false };
TSpirvRequirement* spirvRequirement; TSpirvRequirement* spirvRequirement;
TSpirvExecutionMode* spirvExecutionMode; TSpirvExecutionMode* spirvExecutionMode;