summaryrefslogtreecommitdiffstats
path: root/thirdparty/glslang/SPIRV/SpvBuilder.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'thirdparty/glslang/SPIRV/SpvBuilder.cpp')
-rw-r--r--thirdparty/glslang/SPIRV/SpvBuilder.cpp136
1 files changed, 88 insertions, 48 deletions
diff --git a/thirdparty/glslang/SPIRV/SpvBuilder.cpp b/thirdparty/glslang/SPIRV/SpvBuilder.cpp
index d42f728816..9216817a2a 100644
--- a/thirdparty/glslang/SPIRV/SpvBuilder.cpp
+++ b/thirdparty/glslang/SPIRV/SpvBuilder.cpp
@@ -182,7 +182,7 @@ Id Builder::makeVoidType()
return type->getResultId();
}
-Id Builder::makeBoolType(bool const compilerGenerated)
+Id Builder::makeBoolType()
{
Instruction* type;
if (groupedTypes[OpTypeBool].size() == 0) {
@@ -190,14 +190,15 @@ Id Builder::makeBoolType(bool const compilerGenerated)
groupedTypes[OpTypeBool].push_back(type);
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
+
+ if (emitNonSemanticShaderDebugInfo) {
+ auto const debugResultId = makeBoolDebugType(32);
+ debugId[type->getResultId()] = debugResultId;
+ }
+
} else
type = groupedTypes[OpTypeBool].back();
- if (emitNonSemanticShaderDebugInfo && !compilerGenerated)
- {
- auto const debugResultId = makeBoolDebugType(32);
- debugId[type->getResultId()] = debugResultId;
- }
return type->getResultId();
}
@@ -1182,13 +1183,26 @@ Id Builder::makeDebugExpression()
return debugExpression;
}
-Id Builder::makeDebugDeclare(Id const debugLocalVariable, Id const localVariable)
+Id Builder::makeDebugDeclare(Id const debugLocalVariable, Id const pointer)
{
Instruction* inst = new Instruction(getUniqueId(), makeVoidType(), OpExtInst);
inst->addIdOperand(nonSemanticShaderDebugInfo);
inst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugDeclare);
inst->addIdOperand(debugLocalVariable); // debug local variable id
- inst->addIdOperand(localVariable); // local variable id
+ inst->addIdOperand(pointer); // pointer to local variable id
+ inst->addIdOperand(makeDebugExpression()); // expression id
+ buildPoint->addInstruction(std::unique_ptr<Instruction>(inst));
+
+ return inst->getResultId();
+}
+
+Id Builder::makeDebugValue(Id const debugLocalVariable, Id const value)
+{
+ Instruction* inst = new Instruction(getUniqueId(), makeVoidType(), OpExtInst);
+ inst->addIdOperand(nonSemanticShaderDebugInfo);
+ inst->addImmediateOperand(NonSemanticShaderDebugInfo100DebugValue);
+ inst->addIdOperand(debugLocalVariable); // debug local variable id
+ inst->addIdOperand(value); // value of local variable id
inst->addIdOperand(makeDebugExpression()); // expression id
buildPoint->addInstruction(std::unique_ptr<Instruction>(inst));
@@ -2061,11 +2075,6 @@ Function* Builder::makeEntryPoint(const char* entryPoint)
{
assert(! entryPointFunction);
- Block* entry;
- std::vector<Id> paramsTypes;
- std::vector<char const*> paramNames;
- std::vector<std::vector<Decoration>> decorations;
-
auto const returnType = makeVoidType();
restoreNonSemanticShaderDebugInfo = emitNonSemanticShaderDebugInfo;
@@ -2073,7 +2082,8 @@ Function* Builder::makeEntryPoint(const char* entryPoint)
emitNonSemanticShaderDebugInfo = false;
}
- entryPointFunction = makeFunctionEntry(NoPrecision, returnType, entryPoint, LinkageTypeMax, paramsTypes, paramNames, decorations, &entry);
+ Block* entry = nullptr;
+ entryPointFunction = makeFunctionEntry(NoPrecision, returnType, entryPoint, LinkageTypeMax, {}, {}, &entry);
emitNonSemanticShaderDebugInfo = restoreNonSemanticShaderDebugInfo;
@@ -2082,8 +2092,8 @@ Function* Builder::makeEntryPoint(const char* entryPoint)
// Comments in header
Function* Builder::makeFunctionEntry(Decoration precision, Id returnType, const char* name, LinkageType linkType,
- const std::vector<Id>& paramTypes, const std::vector<char const*>& paramNames,
- const std::vector<std::vector<Decoration>>& decorations, Block **entry)
+ const std::vector<Id>& paramTypes,
+ const std::vector<std::vector<Decoration>>& decorations, Block** entry)
{
// Make the function and initial instructions in it
Id typeId = makeFunctionType(returnType, paramTypes);
@@ -2101,12 +2111,8 @@ Function* Builder::makeFunctionEntry(Decoration precision, Id returnType, const
}
}
- // Make the debug function instruction
+ // reset last debug scope
if (emitNonSemanticShaderDebugInfo) {
- Id nameId = getStringId(unmangleFunctionName(name));
- Id debugFuncId = makeDebugFunction(function, nameId, typeId);
- debugId[funcId] = debugFuncId;
- currentDebugScopeId.push(debugFuncId);
lastDebugScopeId = NoResult;
}
@@ -2116,41 +2122,67 @@ Function* Builder::makeFunctionEntry(Decoration precision, Id returnType, const
function->addBlock(*entry);
setBuildPoint(*entry);
+ if (name)
+ addName(function->getId(), name);
+
+ functions.push_back(std::unique_ptr<Function>(function));
+
+ return function;
+}
+
+void Builder::setupDebugFunctionEntry(Function* function, const char* name, int line, const std::vector<Id>& paramTypes,
+ const std::vector<char const*>& paramNames)
+{
+
+ if (!emitNonSemanticShaderDebugInfo)
+ return;
+
+ currentLine = line;
+ Id nameId = getStringId(unmangleFunctionName(name));
+ Id funcTypeId = function->getFuncTypeId();
+ assert(debugId[funcTypeId] != 0);
+ Id funcId = function->getId();
+
+ assert(funcId != 0);
+
+ // Make the debug function instruction
+ Id debugFuncId = makeDebugFunction(function, nameId, funcTypeId);
+ debugId[funcId] = debugFuncId;
+ currentDebugScopeId.push(debugFuncId);
+
// DebugScope and DebugLine for parameter DebugDeclares
- if (emitNonSemanticShaderDebugInfo && (int)paramTypes.size() > 0) {
+ assert(paramTypes.size() == paramNames.size());
+ if ((int)paramTypes.size() > 0) {
addDebugScopeAndLine(currentFileId, currentLine, 0);
- }
- if (emitNonSemanticShaderDebugInfo) {
- assert(paramTypes.size() == paramNames.size());
- for(size_t p = 0; p < paramTypes.size(); ++p)
- {
- auto getParamTypeId = [this](Id const& typeId) {
- if (isPointerType(typeId) || isArrayType(typeId)) {
- return getContainedTypeId(typeId);
- }
- else {
- return typeId;
- }
- };
+ Id firstParamId = function->getParamId(0);
+
+ for (size_t p = 0; p < paramTypes.size(); ++p) {
+ bool passByRef = false;
+ Id paramTypeId = paramTypes[p];
+
+ // For pointer-typed parameters, they are actually passed by reference and we need unwrap the pointer to get the actual parameter type.
+ if (isPointerType(paramTypeId) || isArrayType(paramTypeId)) {
+ passByRef = true;
+ paramTypeId = getContainedTypeId(paramTypeId);
+ }
+
auto const& paramName = paramNames[p];
- auto const debugLocalVariableId = createDebugLocalVariable(debugId[getParamTypeId(paramTypes[p])], paramName, p+1);
- debugId[firstParamId + p] = debugLocalVariableId;
+ auto const debugLocalVariableId = createDebugLocalVariable(debugId[paramTypeId], paramName, p + 1);
+ auto const paramId = static_cast<Id>(firstParamId + p);
+ debugId[paramId] = debugLocalVariableId;
- makeDebugDeclare(debugLocalVariableId, firstParamId + p);
+ if (passByRef) {
+ makeDebugDeclare(debugLocalVariableId, paramId);
+ } else {
+ makeDebugValue(debugLocalVariableId, paramId);
+ }
}
}
- if (name)
- addName(function->getId(), name);
-
- functions.push_back(std::unique_ptr<Function>(function));
-
// Clear debug scope stack
if (emitNonSemanticShaderDebugInfo)
currentDebugScopeId.pop();
-
- return function;
}
Id Builder::makeDebugFunction([[maybe_unused]] Function* function, Id nameId, Id funcTypeId)
@@ -2166,13 +2198,13 @@ Id Builder::makeDebugFunction([[maybe_unused]] Function* function, Id nameId, Id
type->addImmediateOperand(NonSemanticShaderDebugInfo100DebugFunction);
type->addIdOperand(nameId);
type->addIdOperand(debugId[funcTypeId]);
- type->addIdOperand(makeDebugSource(currentFileId)); // Will be fixed later when true filename available
- type->addIdOperand(makeUintConstant(currentLine)); // Will be fixed later when true line available
+ type->addIdOperand(makeDebugSource(currentFileId)); // TODO: This points to file of definition instead of declaration
+ type->addIdOperand(makeUintConstant(currentLine)); // TODO: This points to line of definition instead of declaration
type->addIdOperand(makeUintConstant(0)); // column
type->addIdOperand(makeDebugCompilationUnit()); // scope
type->addIdOperand(nameId); // linkage name
type->addIdOperand(makeUintConstant(NonSemanticShaderDebugInfo100FlagIsPublic));
- type->addIdOperand(makeUintConstant(currentLine)); // TODO(greg-lunarg): correct scope line
+ type->addIdOperand(makeUintConstant(currentLine));
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(type));
module.mapInstruction(type);
return funcId;
@@ -2709,6 +2741,14 @@ Id Builder::createSpecConstantOp(Op opCode, Id typeId, const std::vector<Id>& op
module.mapInstruction(op);
constantsTypesGlobals.push_back(std::unique_ptr<Instruction>(op));
+ // OpSpecConstantOp's using 8 or 16 bit types require the associated capability
+ if (containsType(typeId, OpTypeInt, 8))
+ addCapability(CapabilityInt8);
+ if (containsType(typeId, OpTypeInt, 16))
+ addCapability(CapabilityInt16);
+ if (containsType(typeId, OpTypeFloat, 16))
+ addCapability(CapabilityFloat16);
+
return op->getResultId();
}