@@ -771,8 +771,9 @@ void SemaHLSL::ActOnTopLevelFunction(FunctionDecl *FD) {
771771 }
772772}
773773
774- static bool isPipelineBuiltin (const ASTContext &AstContext, FunctionDecl *FD,
775- HLSLAppliedSemanticAttr *Semantic) {
774+ static bool isVkPipelineBuiltin (const ASTContext &AstContext, FunctionDecl *FD,
775+ HLSLAppliedSemanticAttr *Semantic,
776+ bool IsInput) {
776777 if (AstContext.getTargetInfo ().getTriple ().getOS () != llvm::Triple::Vulkan)
777778 return false ;
778779
@@ -781,8 +782,13 @@ static bool isPipelineBuiltin(const ASTContext &AstContext, FunctionDecl *FD,
781782 llvm::Triple::EnvironmentType ST = ShaderAttr->getType ();
782783 auto SemanticName = Semantic->getSemanticName ().upper ();
783784
784- if (ST == llvm::Triple::Pixel && SemanticName == " SV_POSITION" )
785- return true ;
785+ // The SV_Position semantic is lowered to:
786+ // - Position built-in for vertex output.
787+ // - FragCoord built-in for fragment input.
788+ if (SemanticName == " SV_POSITION" ) {
789+ return (ST == llvm::Triple::Vertex && !IsInput) ||
790+ (ST == llvm::Triple::Pixel && IsInput);
791+ }
786792
787793 return false ;
788794}
@@ -816,7 +822,7 @@ bool SemaHLSL::determineActiveSemanticOnScalar(FunctionDecl *FD,
816822
817823 unsigned Location = ActiveSemantic.Index .value_or (0 );
818824
819- if (!isPipelineBuiltin (getASTContext (), FD, A)) {
825+ if (!isVkPipelineBuiltin (getASTContext (), FD, A, IsInput )) {
820826 bool HasVkLocation = false ;
821827 if (auto *A = D->getAttr <HLSLVkLocationAttr>()) {
822828 HasVkLocation = true ;
0 commit comments