@@ -3234,43 +3234,6 @@ SpirvVariable *DeclResultIdMapper::getBuiltinVar(spv::BuiltIn builtIn,
32343234 return var;
32353235}
32363236
3237- SpirvVariable *DeclResultIdMapper::createSpirvIntermediateOutputStageVar (
3238- const NamedDecl *decl, const llvm::StringRef name, QualType type) {
3239- const auto *semantic = hlsl::Semantic::GetByName (name);
3240- SemanticInfo thisSemantic{name, semantic, name, 0 , decl->getLocation ()};
3241-
3242- const auto *sigPoint =
3243- deduceSigPoint (cast<DeclaratorDecl>(decl), /* asInput=*/ false ,
3244- spvContext.getCurrentShaderModelKind (), /* forPCF=*/ false );
3245-
3246- StageVar stageVar (sigPoint, thisSemantic, decl->getAttr <VKBuiltInAttr>(),
3247- type, /* locCount=*/ 1 );
3248- SpirvVariable *varInstr =
3249- createSpirvStageVar (&stageVar, decl, name, thisSemantic.loc );
3250-
3251- if (!varInstr)
3252- return nullptr ;
3253-
3254- stageVar.setSpirvInstr (varInstr);
3255- stageVar.setLocationAttr (decl->getAttr <VKLocationAttr>());
3256- stageVar.setIndexAttr (decl->getAttr <VKIndexAttr>());
3257- if (stageVar.getStorageClass () == spv::StorageClass::Input ||
3258- stageVar.getStorageClass () == spv::StorageClass::Output) {
3259- stageVar.setEntryPoint (entryFunction);
3260- }
3261- stageVars.push_back (stageVar);
3262-
3263- // Emit OpDecorate* instructions to link this stage variable with the HLSL
3264- // semantic it is created for.
3265- spvBuilder.decorateHlslSemantic (varInstr, stageVar.getSemanticStr ());
3266-
3267- // We have semantics attached to this decl, which means it must be a
3268- // function/parameter/variable. All are DeclaratorDecls.
3269- stageVarInstructions[cast<DeclaratorDecl>(decl)] = varInstr;
3270-
3271- return varInstr;
3272- }
3273-
32743237SpirvVariable *DeclResultIdMapper::createSpirvStageVar (
32753238 StageVar *stageVar, const NamedDecl *decl, const llvm::StringRef name,
32763239 SourceLocation srcLoc) {
@@ -4008,21 +3971,6 @@ void DeclResultIdMapper::tryToCreateImplicitConstVar(const ValueDecl *decl) {
40083971 astDecls[varDecl].instr = constVal;
40093972}
40103973
4011- SpirvInstruction *
4012- DeclResultIdMapper::createHullMainOutputPatch (const ParmVarDecl *param,
4013- const QualType retType,
4014- uint32_t numOutputControlPoints) {
4015- const QualType hullMainRetType = astContext.getConstantArrayType (
4016- retType, llvm::APInt (32 , numOutputControlPoints),
4017- clang::ArrayType::Normal, 0 );
4018- SpirvInstruction *hullMainOutputPatch = createSpirvIntermediateOutputStageVar (
4019- param, " temp.var.hullMainRetVal" , hullMainRetType);
4020- assert (astDecls[param].instr == nullptr );
4021- astDecls[param].instr = hullMainOutputPatch;
4022- return hullMainOutputPatch;
4023- }
4024-
4025-
40263974template <typename Functor>
40273975void DeclResultIdMapper::decorateWithIntrinsicAttrs (const NamedDecl *decl,
40283976 SpirvVariable *varInst,
@@ -4048,5 +3996,53 @@ void DeclResultIdMapper::decorateVariableWithIntrinsicAttrs(
40483996 decorateWithIntrinsicAttrs (decl, varInst, [](VKDecorateExtAttr *) {});
40493997}
40503998
3999+ void DeclResultIdMapper::copyHullOutStageVarsToOutputPatch (
4000+ SpirvInstruction *hullMainOutputPatch, const ParmVarDecl *outputPatchDecl,
4001+ QualType outputControlPointType, uint32_t numOutputControlPoints) {
4002+ for (uint32_t outputCtrlPoint = 0 ; outputCtrlPoint < numOutputControlPoints;
4003+ ++outputCtrlPoint) {
4004+ SpirvConstant *index = spvBuilder.getConstantInt (
4005+ astContext.UnsignedIntTy , llvm::APInt (32 , outputCtrlPoint));
4006+ auto *tempLocation = spvBuilder.createAccessChain (
4007+ outputControlPointType, hullMainOutputPatch, {index}, /* loc=*/ {});
4008+ storeOutStageVarsToStorage (cast<DeclaratorDecl>(outputPatchDecl), index,
4009+ outputControlPointType, tempLocation);
4010+ }
4011+ }
4012+
4013+ void DeclResultIdMapper::storeOutStageVarsToStorage (
4014+ const DeclaratorDecl *outputPatchDecl, SpirvConstant *ctrlPointID,
4015+ QualType outputControlPointType, SpirvInstruction *ptr) {
4016+ if (!outputControlPointType->isStructureType ()) {
4017+ const auto found = stageVarInstructions.find (outputPatchDecl);
4018+ if (found == stageVarInstructions.end ()) {
4019+ emitError (" Shader output variable '%0' was not created" , {})
4020+ << outputPatchDecl->getName ();
4021+ }
4022+ auto *ptrToOutputStageVar = spvBuilder.createAccessChain (
4023+ outputControlPointType, found->second , {ctrlPointID}, /* loc=*/ {});
4024+ auto *load = spvBuilder.createLoad (outputControlPointType,
4025+ ptrToOutputStageVar, /* loc=*/ {});
4026+ spvBuilder.createStore (ptr, load, /* loc=*/ {});
4027+ return ;
4028+ }
4029+
4030+ const auto *recordType = outputControlPointType->getAs <RecordType>();
4031+ assert (recordType != nullptr );
4032+ const auto *structDecl = recordType->getDecl ();
4033+ assert (structDecl != nullptr );
4034+
4035+ uint32_t index = 0 ;
4036+ for (const auto *field : structDecl->fields ()) {
4037+ SpirvConstant *indexInst = spvBuilder.getConstantInt (
4038+ astContext.UnsignedIntTy , llvm::APInt (32 , index));
4039+ auto *tempLocation = spvBuilder.createAccessChain (field->getType (), ptr,
4040+ {indexInst}, /* loc=*/ {});
4041+ storeOutStageVarsToStorage (cast<DeclaratorDecl>(field), ctrlPointID,
4042+ field->getType (), tempLocation);
4043+ ++index;
4044+ }
4045+ }
4046+
40514047} // end namespace spirv
40524048} // end namespace clang
0 commit comments