Skip to content

Commit 3af4d4e

Browse files
authored
[HLSL][SPIR-V] Fix LinkageAttribute emission for BuiltIn (#144701)
BuiltIn variables were missing the visibility attribute, which caused the Linkage capability to be emitted by the backend.
1 parent b53c1e4 commit 3af4d4e

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,7 @@ static llvm::Value *createSPIRVBuiltinLoad(IRBuilder<> &B, llvm::Module &M,
375375
llvm::GlobalVariable::GeneralDynamicTLSModel,
376376
/* AddressSpace */ 7, /* isExternallyInitialized= */ true);
377377
addSPIRVBuiltinDecoration(GV, BuiltInID);
378+
GV->setVisibility(llvm::GlobalValue::HiddenVisibility);
378379
return B.CreateLoad(Ty, GV);
379380
}
380381

clang/test/CodeGenHLSL/semantics/SV_Position.ps.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %clang_cc1 -triple spirv-unknown-vulkan1.3-pixel -x hlsl -emit-llvm -finclude-default-header -disable-llvm-passes -o - %s | FileCheck %s
22

3-
// CHECK: @sv_position = external thread_local addrspace(7) externally_initialized constant <4 x float>, !spirv.Decorations !0
3+
// CHECK: @sv_position = external hidden thread_local addrspace(7) externally_initialized constant <4 x float>, !spirv.Decorations !0
44

55
// CHECK: define void @main() {{.*}} {
66
float4 main(float4 p : SV_Position) {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
; RUN: llc -verify-machineinstrs -O0 -mtriple=spirv-unknown-vulkan1.3-pixel %s -o - | FileCheck %s
2+
; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-vulkan1.3-pixel %s -o - -filetype=obj | spirv-val --target-env vulkan1.3 %}
3+
4+
@sv_position = external hidden thread_local local_unnamed_addr addrspace(7) externally_initialized constant <4 x float>, !spirv.Decorations !0
5+
6+
; CHECK-NOT: OpDecorate %[[#var]] LinkageAttributes "sv_position" Import
7+
8+
; CHECK-DAG: %[[#float:]] = OpTypeFloat 32
9+
; CHECK-DAG: %[[#float4:]] = OpTypeVector %[[#float]]
10+
; CHECK-DAG: %[[#type:]] = OpTypePointer Input %[[#float4]]
11+
; CHECK-DAG: %[[#var:]] = OpVariable %[[#type]] Input
12+
13+
; CHECK-NOT: OpDecorate %[[#var]] LinkageAttributes "sv_position" Import
14+
15+
define void @main() #1 {
16+
entry:
17+
ret void
18+
}
19+
20+
attributes #1 = { "hlsl.shader"="pixel" }
21+
22+
!0 = !{!1}
23+
!1 = !{i32 11, i32 0}

0 commit comments

Comments
 (0)