@@ -771,9 +771,12 @@ void SemaHLSL::ActOnTopLevelFunction(FunctionDecl *FD) {
771771 }
772772}
773773
774- bool SemaHLSL::determineActiveSemanticOnScalar (
775- FunctionDecl *FD, DeclaratorDecl *OutputDecl, DeclaratorDecl *D,
776- SemanticInfo &ActiveSemantic, llvm::StringSet<> &UsedSemantics) {
774+ bool SemaHLSL::determineActiveSemanticOnScalar (FunctionDecl *FD,
775+ DeclaratorDecl *OutputDecl,
776+ DeclaratorDecl *D,
777+ SemanticInfo &ActiveSemantic,
778+ llvm::StringSet<> &UsedSemantics,
779+ bool IsInput) {
777780 if (ActiveSemantic.Semantic == nullptr ) {
778781 ActiveSemantic.Semantic = D->getAttr <HLSLParsedSemanticAttr>();
779782 if (ActiveSemantic.Semantic )
@@ -792,7 +795,7 @@ bool SemaHLSL::determineActiveSemanticOnScalar(
792795 if (!A)
793796 return false ;
794797
795- checkSemanticAnnotation (FD, D, A);
798+ checkSemanticAnnotation (FD, D, A, IsInput );
796799 OutputDecl->addAttr (A);
797800
798801 unsigned Location = ActiveSemantic.Index .value_or (0 );
@@ -820,7 +823,8 @@ bool SemaHLSL::determineActiveSemantic(FunctionDecl *FD,
820823 DeclaratorDecl *OutputDecl,
821824 DeclaratorDecl *D,
822825 SemanticInfo &ActiveSemantic,
823- llvm::StringSet<> &UsedSemantics) {
826+ llvm::StringSet<> &UsedSemantics,
827+ bool IsInput) {
824828 if (ActiveSemantic.Semantic == nullptr ) {
825829 ActiveSemantic.Semantic = D->getAttr <HLSLParsedSemanticAttr>();
826830 if (ActiveSemantic.Semantic )
@@ -833,12 +837,13 @@ bool SemaHLSL::determineActiveSemantic(FunctionDecl *FD,
833837 const RecordType *RT = dyn_cast<RecordType>(T);
834838 if (!RT)
835839 return determineActiveSemanticOnScalar (FD, OutputDecl, D, ActiveSemantic,
836- UsedSemantics);
840+ UsedSemantics, IsInput );
837841
838842 const RecordDecl *RD = RT->getDecl ();
839843 for (FieldDecl *Field : RD->fields ()) {
840844 SemanticInfo Info = ActiveSemantic;
841- if (!determineActiveSemantic (FD, OutputDecl, Field, Info, UsedSemantics)) {
845+ if (!determineActiveSemantic (FD, OutputDecl, Field, Info, UsedSemantics,
846+ IsInput)) {
842847 Diag (Field->getLocation (), diag::note_hlsl_semantic_used_here) << Field;
843848 return false ;
844849 }
@@ -920,7 +925,7 @@ void SemaHLSL::CheckEntryPoint(FunctionDecl *FD) {
920925
921926 // FIXME: Verify output semantics in parameters.
922927 if (!determineActiveSemantic (FD, Param, Param, ActiveSemantic,
923- ActiveInputSemantics)) {
928+ ActiveInputSemantics, /* IsInput= */ true )) {
924929 Diag (Param->getLocation (), diag::note_previous_decl) << Param;
925930 FD->setInvalidDecl ();
926931 }
@@ -932,12 +937,13 @@ void SemaHLSL::CheckEntryPoint(FunctionDecl *FD) {
932937 if (ActiveSemantic.Semantic )
933938 ActiveSemantic.Index = ActiveSemantic.Semantic ->getSemanticIndex ();
934939 if (!FD->getReturnType ()->isVoidType ())
935- determineActiveSemantic (FD, FD, FD, ActiveSemantic, ActiveOutputSemantics);
940+ determineActiveSemantic (FD, FD, FD, ActiveSemantic, ActiveOutputSemantics,
941+ /* IsInput= */ false );
936942}
937943
938944void SemaHLSL::checkSemanticAnnotation (
939945 FunctionDecl *EntryPoint, const Decl *Param,
940- const HLSLAppliedSemanticAttr *SemanticAttr) {
946+ const HLSLAppliedSemanticAttr *SemanticAttr, bool IsInput ) {
941947 auto *ShaderAttr = EntryPoint->getAttr <HLSLShaderAttr>();
942948 assert (ShaderAttr && " Entry point has no shader attribute" );
943949 llvm::Triple::EnvironmentType ST = ShaderAttr->getType ();
@@ -961,11 +967,12 @@ void SemaHLSL::checkSemanticAnnotation(
961967 }
962968
963969 if (SemanticName == " SV_POSITION" ) {
964- // TODO(#143523): allow use on other shader types & output once the overall
965- // semantic logic is implemented .
966- if (ST == llvm::Triple::Pixel)
970+ // SV_Position can be an input or output in vertex shaders,
971+ // but only an input in pixel shaders .
972+ if (ST == llvm::Triple::Vertex || (ST == llvm::Triple:: Pixel && IsInput) )
967973 return ;
968- DiagnoseAttrStageMismatch (SemanticAttr, ST, {llvm::Triple::Pixel});
974+ DiagnoseAttrStageMismatch (SemanticAttr, ST,
975+ {llvm::Triple::Pixel, llvm::Triple::Vertex});
969976 return ;
970977 }
971978
0 commit comments