@@ -699,8 +699,9 @@ void CGHLSLRuntime::emitUserSemanticStore(IRBuilder<> &B, llvm::Value *Source,
699699}
700700
701701llvm::Value *CGHLSLRuntime::emitSystemSemanticLoad (
702- IRBuilder<> &B, llvm::Type *Type, const clang::DeclaratorDecl *Decl,
703- HLSLAppliedSemanticAttr *Semantic, std::optional<unsigned > Index) {
702+ IRBuilder<> &B, const FunctionDecl *FD, llvm::Type *Type,
703+ const clang::DeclaratorDecl *Decl, HLSLAppliedSemanticAttr *Semantic,
704+ std::optional<unsigned > Index) {
704705
705706 std::string SemanticName = Semantic->getAttrName ()->getName ().upper ();
706707 if (SemanticName == " SV_GROUPINDEX" ) {
@@ -736,8 +737,12 @@ llvm::Value *CGHLSLRuntime::emitSystemSemanticLoad(
736737 return buildVectorInput (B, GroupIDIntrinsic, Type);
737738 }
738739
740+ const auto *ShaderAttr = FD->getAttr <HLSLShaderAttr>();
741+ assert (ShaderAttr && " Entry point has no shader attribute" );
742+ llvm::Triple::EnvironmentType ST = ShaderAttr->getType ();
743+
739744 if (SemanticName == " SV_POSITION" ) {
740- if (CGM. getTriple (). getEnvironment () == Triple::EnvironmentType::Pixel) {
745+ if (ST == Triple::EnvironmentType::Pixel) {
741746 if (CGM.getTarget ().getTriple ().isSPIRV ())
742747 return createSPIRVBuiltinLoad (B, CGM.getModule (), Type,
743748 Semantic->getAttrName ()->getName (),
@@ -746,7 +751,7 @@ llvm::Value *CGHLSLRuntime::emitSystemSemanticLoad(
746751 return emitDXILUserSemanticLoad (B, Type, Semantic, Index);
747752 }
748753
749- if (CGM. getTriple (). getEnvironment () == Triple::EnvironmentType::Vertex) {
754+ if (ST == Triple::EnvironmentType::Vertex) {
750755 return emitUserSemanticLoad (B, Type, Decl, Semantic, Index);
751756 }
752757 }
@@ -804,7 +809,7 @@ llvm::Value *CGHLSLRuntime::handleScalarSemanticLoad(
804809
805810 std::optional<unsigned > Index = Semantic->getSemanticIndex ();
806811 if (Semantic->getAttrName ()->getName ().starts_with_insensitive (" SV_" ))
807- return emitSystemSemanticLoad (B, Type, Decl, Semantic, Index);
812+ return emitSystemSemanticLoad (B, FD, Type, Decl, Semantic, Index);
808813 return emitUserSemanticLoad (B, Type, Decl, Semantic, Index);
809814}
810815
0 commit comments