Skip to content

Commit 8f07d0b

Browse files
committed
reuse spirv.Decorations metadata
1 parent 9f2b07d commit 8f07d0b

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

clang/lib/CodeGen/CGHLSLRuntime.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -559,9 +559,11 @@ void CGHLSLRuntime::handleGlobalVarDefinition(const VarDecl *VD,
559559
if (auto Attr = VD->getAttr<HLSLVkExtBuiltinInputAttr>()) {
560560
LLVMContext &Ctx = GV->getContext();
561561
IRBuilder<> B(GV->getContext());
562-
MDNode *Val = MDNode::get(
563-
Ctx, {ConstantAsMetadata::get(B.getInt32(Attr->getBuiltIn()))});
564-
GV->addMetadata("spv.builtin", *Val);
562+
MDNode *Operands = MDNode::get(
563+
Ctx, {ConstantAsMetadata::get(B.getInt32(11)),
564+
ConstantAsMetadata::get(B.getInt32(Attr->getBuiltIn()))});
565+
MDNode *Decoration = MDNode::get(Ctx, {Operands});
566+
GV->addMetadata("spirv.Decorations", *Decoration);
565567
}
566568
}
567569

clang/test/CodeGenHLSL/vk-input-builtin.hlsl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33

44
[[vk::ext_builtin_input(/* WorkgroupId */ 26)]]
55
static const uint3 groupid;
6-
// CHECK: @_ZL7groupid = local_unnamed_addr addrspace(7) externally_initialized constant <3 x i32> undef, align 16, !spv.builtin [[META0:![0-9]+]]
6+
// CHECK: @_ZL7groupid = local_unnamed_addr addrspace(7) externally_initialized constant <3 x i32> undef, align 16, !spirv.Decorations [[META0:![0-9]+]]
77

88
RWStructuredBuffer<int> output : register(u1, space0);
99

1010
[numthreads(1, 1, 1)]
1111
void main() {
1212
output[0] = groupid;
1313
}
14-
// CHECK: [[META0]] = !{i32 26}
14+
// CHECK: [[META0]] = !{[[META1:![0-9]+]]}
15+
// CHECK: [[META1]] = !{i32 11, i32 26}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
; RUN: llc -O0 -verify-machineinstrs -mtriple=spirv-vulkan-unknown %s -o - | FileCheck %s
2+
3+
; FIXME(138268): Alignment decoration is emitted.
4+
; NO-RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-vulkan-unknown %s -o - -filetype=obj | spirv-val %}
5+
6+
; CHECK-DAG: OpDecorate %[[#WorkgroupId:]] BuiltIn WorkgroupId
7+
8+
; CHECK-DAG: %[[#uint:]] = OpTypeInt 32 0
9+
; CHECK-DAG: %[[#uint_0:]] = OpConstant %[[#uint]] 0
10+
; CHECK-DAG: %[[#v3uint:]] = OpTypeVector %[[#uint]] 3
11+
; CHECK-DAG: %[[#ptr_Input_uint:]] = OpTypePointer Input %[[#uint]]
12+
; CHECK-DAG: %[[#ptr_Input_v3uint:]] = OpTypePointer Input %[[#v3uint]]
13+
; CHECK-DAG: %[[#WorkgroupId:]] = OpVariable %[[#ptr_Input_v3uint]] Input
14+
@var = local_unnamed_addr addrspace(7) externally_initialized constant <3 x i32> undef, align 16, !spirv.Decorations !0
15+
16+
define i32 @foo() {
17+
entry:
18+
; CHECK: %[[#ptr:]] = OpAccessChain %[[#ptr_Input_uint]] %[[#WorkgroupId]] %[[#uint_0]]
19+
; CHECK: %[[#res:]] = OpLoad %[[#uint]] %[[#ptr]] Aligned 16
20+
; CHECK: OpReturnValue %[[#res]]
21+
%0 = load i32, ptr addrspace(7) @var, align 16
22+
ret i32 %0
23+
}
24+
25+
!0 = !{!1}
26+
!1 = !{i32 11, i32 26}

0 commit comments

Comments
 (0)