Skip to content

Commit e3429c5

Browse files
committed
[SPIR-V] Fix LinkageAttribute emission for Vulkan
Linkage capability is required for LinkageAttribute. This capability could be allowed in Shaders, but the Vulkan environment do not support it so we should not emit this decoration under Vulkan.
1 parent 2ecbfc0 commit e3429c5

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

llvm/lib/Target/SPIRV/SPIRVGlobalRegistry.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,9 @@ Register SPIRVGlobalRegistry::buildGlobalVariable(
780780
buildOpDecorate(Reg, MIRBuilder, SPIRV::Decoration::Alignment, {Alignment});
781781
}
782782

783-
if (HasLinkageTy)
783+
// LinkageAttributes required Linkage capability. This capability is not
784+
// supported by Vulkan.
785+
if (HasLinkageTy && !ST.isVulkan())
784786
buildOpDecorate(Reg, MIRBuilder, SPIRV::Decoration::LinkageAttributes,
785787
{static_cast<uint32_t>(LinkageType)}, Name);
786788

llvm/lib/Target/SPIRV/SPIRVSubtarget.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ class SPIRVSubtarget : public SPIRVGenSubtargetInfo {
101101
return TargetTriple.getArch() == Triple::spirv32 ||
102102
TargetTriple.getArch() == Triple::spirv64;
103103
}
104+
bool isVulkan() const { return TargetTriple.getOS() == Triple::Vulkan; }
104105
const std::string &getTargetTripleAsStr() const { return TargetTriple.str(); }
105106
VersionTuple getSPIRVVersion() const { return SPIRVVersion; };
106107
bool isAtLeastSPIRVVer(VersionTuple VerToCompareTo) const;
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 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)