|
@@ -2946,6 +2946,39 @@ SpirvVariable *DeclResultIdMapper::getBuiltinVar(spv::BuiltIn builtIn,
|
|
|
return var;
|
|
|
}
|
|
|
|
|
|
+SpirvVariable *DeclResultIdMapper::createSpirvIntermediateOutputStageVar(
|
|
|
+ const NamedDecl *decl, const llvm::StringRef name, QualType type) {
|
|
|
+ const auto *semantic = hlsl::Semantic::GetByName(name);
|
|
|
+ SemanticInfo thisSemantic{name, semantic, name, 0, decl->getLocation()};
|
|
|
+
|
|
|
+ const auto *sigPoint =
|
|
|
+ deduceSigPoint(cast<DeclaratorDecl>(decl), /*asInput=*/false,
|
|
|
+ spvContext.getCurrentShaderModelKind(), /*forPCF=*/false);
|
|
|
+
|
|
|
+ StageVar stageVar(sigPoint, thisSemantic, decl->getAttr<VKBuiltInAttr>(),
|
|
|
+ type, /*locCount=*/1);
|
|
|
+ SpirvVariable *varInstr =
|
|
|
+ createSpirvStageVar(&stageVar, decl, name, thisSemantic.loc);
|
|
|
+
|
|
|
+ if (!varInstr)
|
|
|
+ return nullptr;
|
|
|
+
|
|
|
+ stageVar.setSpirvInstr(varInstr);
|
|
|
+ stageVar.setLocationAttr(decl->getAttr<VKLocationAttr>());
|
|
|
+ stageVar.setIndexAttr(decl->getAttr<VKIndexAttr>());
|
|
|
+ stageVars.push_back(stageVar);
|
|
|
+
|
|
|
+ // Emit OpDecorate* instructions to link this stage variable with the HLSL
|
|
|
+ // semantic it is created for.
|
|
|
+ spvBuilder.decorateHlslSemantic(varInstr, stageVar.getSemanticStr());
|
|
|
+
|
|
|
+ // We have semantics attached to this decl, which means it must be a
|
|
|
+ // function/parameter/variable. All are DeclaratorDecls.
|
|
|
+ stageVarInstructions[cast<DeclaratorDecl>(decl)] = varInstr;
|
|
|
+
|
|
|
+ return varInstr;
|
|
|
+}
|
|
|
+
|
|
|
SpirvVariable *DeclResultIdMapper::createSpirvStageVar(
|
|
|
StageVar *stageVar, const NamedDecl *decl, const llvm::StringRef name,
|
|
|
SourceLocation srcLoc) {
|
|
@@ -3662,15 +3695,15 @@ void DeclResultIdMapper::tryToCreateImplicitConstVar(const ValueDecl *decl) {
|
|
|
astDecls[varDecl].instr = constVal;
|
|
|
}
|
|
|
|
|
|
-SpirvInstruction *DeclResultIdMapper::createHullMainOutputPatch(
|
|
|
- const ParmVarDecl *param, const QualType retType,
|
|
|
- uint32_t numOutputControlPoints, SourceLocation loc) {
|
|
|
+SpirvInstruction *
|
|
|
+DeclResultIdMapper::createHullMainOutputPatch(const ParmVarDecl *param,
|
|
|
+ const QualType retType,
|
|
|
+ uint32_t numOutputControlPoints) {
|
|
|
const QualType hullMainRetType = astContext.getConstantArrayType(
|
|
|
retType, llvm::APInt(32, numOutputControlPoints),
|
|
|
clang::ArrayType::Normal, 0);
|
|
|
- SpirvInstruction *hullMainOutputPatch = spvBuilder.addModuleVar(
|
|
|
- hullMainRetType, spv::StorageClass::Workgroup, false,
|
|
|
- "temp.var.hullMainRetVal", llvm::None, loc);
|
|
|
+ SpirvInstruction *hullMainOutputPatch = createSpirvIntermediateOutputStageVar(
|
|
|
+ param, "temp.var.hullMainRetVal", hullMainRetType);
|
|
|
assert(astDecls[param].instr == nullptr);
|
|
|
astDecls[param].instr = hullMainOutputPatch;
|
|
|
return hullMainOutputPatch;
|