Skip to content

Commit d0cfafe

Browse files
committed
pr-feedback
1 parent 24b9a4e commit d0cfafe

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -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;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %clang_cc1 -triple spirv-linux-vulkan-vertex -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s
2+
3+
// This is almost the same as semantic.explicit-mix-builtin.hlsl, except this
4+
// time we build a vertex shader. This means the SV_Position semantic output
5+
// is also a BuiltIn, This means we can mix implicit and explicit location
6+
// assignment.
7+
struct S1 {
8+
float4 position : SV_Position;
9+
[[vk::location(3)]] float4 color : A;
10+
};
11+
12+
// CHECK: @SV_Position0 = external hidden thread_local addrspace(7) externally_initialized constant <4 x float>, !spirv.Decorations ![[#MD_0:]]
13+
// CHECK: @SV_Position = external hidden thread_local addrspace(8) global <4 x float>, !spirv.Decorations ![[#MD_2:]]
14+
// CHECK: @A0 = external hidden thread_local addrspace(8) global <4 x float>, !spirv.Decorations ![[#MD_0]]
15+
16+
[shader("vertex")]
17+
S1 main1(float4 position : SV_Position) {
18+
S1 output;
19+
output.position = position;
20+
output.color = position;
21+
return output;
22+
}
23+
24+
// CHECK: ![[#MD_0]] = !{![[#MD_1:]]}
25+
// CHECK: ![[#MD_1]] = !{i32 30, i32 0}
26+
// | `-> Location index
27+
// `-> SPIR-V decoration 'Location'
28+
// CHECK: ![[#MD_2]] = !{![[#MD_3:]]}
29+
// CHECK: ![[#MD_3]] = !{i32 11, i32 0}
30+
// | `-> BuiltIn 'Position'
31+
// `-> SPIR-V decoration 'BuiltIn'

0 commit comments

Comments
 (0)