Author: Justin Bogner Date: 2025-06-20T16:21:47-07:00 New Revision: 6b9fe9e0bc7421d89f38ade857c91f0ae153ad9c
URL: https://github.com/llvm/llvm-project/commit/6b9fe9e0bc7421d89f38ade857c91f0ae153ad9c DIFF: https://github.com/llvm/llvm-project/commit/6b9fe9e0bc7421d89f38ade857c91f0ae153ad9c.diff LOG: [HLSL] Emit a version in the dx.rootsignatures metadata (#145113) In #144957 the backend was updated to expect a version in the metadata, but since the frontend wasn't updated this breaks compilation. This is a somewhat temporary fix to that until #144813 lands. Added: Modified: clang/lib/CodeGen/CGHLSLRuntime.cpp clang/test/CodeGenHLSL/RootSignature.hlsl llvm/lib/Target/DirectX/DXILRootSignature.cpp llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error.ll Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp index 34960c34e109f..3103f1798e14e 100644 --- a/clang/lib/CodeGen/CGHLSLRuntime.cpp +++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp @@ -72,12 +72,17 @@ void addRootSignature(ArrayRef<llvm::hlsl::rootsig::RootElement> Elements, llvm::hlsl::rootsig::MetadataBuilder Builder(Ctx, Elements); MDNode *RootSignature = Builder.BuildRootSignature(); - MDNode *FnPairing = - MDNode::get(Ctx, {ValueAsMetadata::get(Fn), RootSignature}); + + // TODO: We need to wire the root signature version up through the frontend + // rather than hardcoding it. + ConstantAsMetadata *Version = + ConstantAsMetadata::get(ConstantInt::get(llvm::Type::getInt32Ty(Ctx), 2)); + MDNode *MDVals = + MDNode::get(Ctx, {ValueAsMetadata::get(Fn), RootSignature, Version}); StringRef RootSignatureValKey = "dx.rootsignatures"; auto *RootSignatureValMD = M.getOrInsertNamedMetadata(RootSignatureValKey); - RootSignatureValMD->addOperand(FnPairing); + RootSignatureValMD->addOperand(MDVals); } } // namespace diff --git a/clang/test/CodeGenHLSL/RootSignature.hlsl b/clang/test/CodeGenHLSL/RootSignature.hlsl index ca843ffbb1ced..6618ca741aa9d 100644 --- a/clang/test/CodeGenHLSL/RootSignature.hlsl +++ b/clang/test/CodeGenHLSL/RootSignature.hlsl @@ -3,14 +3,14 @@ // CHECK: !dx.rootsignatures = !{![[#EMPTY_ENTRY:]], ![[#DT_ENTRY:]], // CHECK-SAME: ![[#RF_ENTRY:]], ![[#RC_ENTRY:]], ![[#RD_ENTRY:]], ![[#SS_ENTRY:]]} -// CHECK: ![[#EMPTY_ENTRY]] = !{ptr @EmptyEntry, ![[#EMPTY:]]} +// CHECK: ![[#EMPTY_ENTRY]] = !{ptr @EmptyEntry, ![[#EMPTY:]], i32 2} // CHECK: ![[#EMPTY]] = !{} [shader("compute"), RootSignature("")] [numthreads(1,1,1)] void EmptyEntry() {} -// CHECK: ![[#DT_ENTRY]] = !{ptr @DescriptorTableEntry, ![[#DT_RS:]]} +// CHECK: ![[#DT_ENTRY]] = !{ptr @DescriptorTableEntry, ![[#DT_RS:]], i32 2} // CHECK: ![[#DT_RS]] = !{![[#TABLE:]]} // CHECK: ![[#TABLE]] = !{!"DescriptorTable", i32 0, ![[#CBV:]], ![[#SRV:]]} // CHECK: ![[#CBV]] = !{!"CBV", i32 1, i32 0, i32 0, i32 -1, i32 4} @@ -25,7 +25,7 @@ void EmptyEntry() {} [numthreads(1,1,1)] void DescriptorTableEntry() {} -// CHECK: ![[#RF_ENTRY]] = !{ptr @RootFlagsEntry, ![[#RF_RS:]]} +// CHECK: ![[#RF_ENTRY]] = !{ptr @RootFlagsEntry, ![[#RF_RS:]], i32 2} // CHECK: ![[#RF_RS]] = !{![[#ROOT_FLAGS:]]} // CHECK: ![[#ROOT_FLAGS]] = !{!"RootFlags", i32 2114} @@ -38,7 +38,7 @@ void DescriptorTableEntry() {} [numthreads(1,1,1)] void RootFlagsEntry() {} -// CHECK: ![[#RC_ENTRY]] = !{ptr @RootConstantsEntry, ![[#RC_RS:]]} +// CHECK: ![[#RC_ENTRY]] = !{ptr @RootConstantsEntry, ![[#RC_RS:]], i32 2} // CHECK: ![[#RC_RS]] = !{![[#ROOT_CONSTANTS:]]} // CHECK: ![[#ROOT_CONSTANTS]] = !{!"RootConstants", i32 5, i32 1, i32 2, i32 1} @@ -52,7 +52,7 @@ void RootFlagsEntry() {} [numthreads(1,1,1)] void RootConstantsEntry() {} -// CHECK: ![[#RD_ENTRY]] = !{ptr @RootDescriptorsEntry, ![[#RD_RS:]]} +// CHECK: ![[#RD_ENTRY]] = !{ptr @RootDescriptorsEntry, ![[#RD_RS:]], i32 2} // CHECK: ![[#RD_RS]] = !{![[#ROOT_CBV:]], ![[#ROOT_UAV:]], ![[#ROOT_SRV:]]} // CHECK: ![[#ROOT_CBV]] = !{!"RootCBV", i32 0, i32 0, i32 0, i32 4} // CHECK: ![[#ROOT_UAV]] = !{!"RootUAV", i32 0, i32 42, i32 3, i32 2} @@ -66,7 +66,7 @@ void RootConstantsEntry() {} [numthreads(1,1,1)] void RootDescriptorsEntry() {} -// CHECK: ![[#SS_ENTRY]] = !{ptr @StaticSamplerEntry, ![[#SS_RS:]]} +// CHECK: ![[#SS_ENTRY]] = !{ptr @StaticSamplerEntry, ![[#SS_RS:]], i32 2} // CHECK: ![[#SS_RS]] = !{![[#STATIC_SAMPLER:]]} // checking filter = 0x4 diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp index 1f175fd4ecd99..29e78fcce5262 100644 --- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp +++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp @@ -491,8 +491,8 @@ analyzeModule(Module &M) { for (const auto &RSDefNode : RootSignatureNode->operands()) { if (RSDefNode->getNumOperands() != 3) { - reportError(Ctx, "Invalid format for Root Signature Definition. Pairs " - "of function, root signature expected."); + reportError(Ctx, "Invalid Root Signature metadata - expected function, " + "signature, and version."); continue; } diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error.ll index 2a2188b1a13bb..0392065842116 100644 --- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error.ll +++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error.ll @@ -2,7 +2,7 @@ target triple = "dxil-unknown-shadermodel6.0-compute" -; CHECK: error: Invalid format for Root Signature Definition. Pairs of function, root signature expected. +; CHECK: error: Invalid Root Signature metadata - expected function, signature, and version. ; CHECK-NOT: Root Signature Definitions _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits