Skip to content

[HLSL] Adding support for root descriptors in root signature metadata representation #139781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 38 commits into from
Jun 4, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
0abacfc
adding support for Root Descriptors
Apr 24, 2025
8b8c02a
clean up
Apr 24, 2025
7ac9641
addressing comments
Apr 25, 2025
c105458
formating
Apr 26, 2025
efe76aa
try fix test
Apr 26, 2025
a928e9d
addressing comments
Apr 26, 2025
a38f10b
refactoring mcdxbc struct to store root parameters out of order
Apr 25, 2025
9a7c359
changing name
Apr 28, 2025
d6c2b55
changing variant to host pointers
Apr 28, 2025
93e4cf2
clean up
Apr 28, 2025
b45b1b6
fix
Apr 28, 2025
f804a23
fix
Apr 28, 2025
15eb6f5
fix naming
May 5, 2025
b9d7f07
fix naming
May 5, 2025
46cc8c1
addressing comments
May 8, 2025
1b3e10a
addressing comments
May 8, 2025
1f31957
addressing comments
May 8, 2025
e8fbfce
clean up
May 8, 2025
a31e5a5
removing v parameter
May 9, 2025
a394ad0
Merge branch 'obj2yaml/root-descriptors' into refactoring/remove-union
May 9, 2025
ad415a7
clean up
May 9, 2025
8ff4845
Merge branch 'main' into refactoring/remove-union
May 9, 2025
f875555
adding support for root descriptors
May 13, 2025
4f7f998
removing none as a flag option
May 13, 2025
3eb5e10
adding tests
May 13, 2025
58e1789
clean up and add more tests
May 13, 2025
81915ad
addressing comments
May 30, 2025
a515e28
Merge branch 'main' into metadata/root-descriptors
Jun 2, 2025
0d54162
clean
Jun 2, 2025
7f70dc5
cleanup
Jun 2, 2025
0c570c8
adding requested comment
Jun 2, 2025
d1ca37d
addressing PR comments
Jun 3, 2025
cb0780b
formating
Jun 3, 2025
eeffded
addressing PR comments
Jun 3, 2025
3cbe0cf
formating
Jun 3, 2025
92b766b
formating
Jun 3, 2025
8732594
adding test
Jun 3, 2025
fdb8b98
clean up
Jun 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
adding tests
  • Loading branch information
joaosaffran committed May 13, 2025
commit 3eb5e101b0087fcb29f7ecb6655c82fddf34428a
1 change: 1 addition & 0 deletions llvm/include/llvm/BinaryFormat/DXContainerConstants.def
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed)
// ROOT_DESCRIPTOR_FLAG(bit offset for the flag, name).
#ifdef ROOT_DESCRIPTOR_FLAG

ROOT_DESCRIPTOR_FLAG(0, NONE)
ROOT_DESCRIPTOR_FLAG(1, DATA_VOLATILE)
ROOT_DESCRIPTOR_FLAG(2, DATA_STATIC_WHILE_SET_AT_EXECUTE)
ROOT_DESCRIPTOR_FLAG(3, DATA_STATIC)
Expand Down
61 changes: 61 additions & 0 deletions llvm/lib/Target/DirectX/DXILRootSignature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "DXILRootSignature.h"
#include "DirectX.h"
#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/DXILMetadataAnalysis.h"
Expand All @@ -30,6 +31,7 @@
#include <cstdint>
#include <optional>
#include <utility>
#include <variant>

using namespace llvm;
using namespace llvm::dxil;
Expand Down Expand Up @@ -217,6 +219,19 @@ static bool verifyVersion(uint32_t Version) {
return (Version == 1 || Version == 2);
}

static bool verifyRegisterValue(uint32_t RegisterValue) {
return !(RegisterValue == 0xFFFFFFFF);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clearer to use std::numeric_limits or ~0U here. Also !(x == y) is harder to understand than x != y

}

static bool verifyRegisterSpace(uint32_t RegisterSpace) {
return !(RegisterSpace >= 0xFFFFFFF0 && RegisterSpace <= 0xFFFFFFFF);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a comment about what the condition we're checking here is? Why are specifically the largest 16 values of a uint32 invalid?

}

static bool verifyDescriptorFlag(uint32_t Flags) {
return (Flags & ~0xE) == 0;
}


static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {

if (!verifyVersion(RSD.Version)) {
Expand All @@ -234,6 +249,38 @@ static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {

assert(dxbc::isValidParameterType(Info.Header.ParameterType) &&
"Invalid value for ParameterType");


auto P = RSD.ParametersContainer.getParameter(&Info);
if(!P)
return reportError(Ctx, "Cannot locate parameter from Header Info");

if( std::holds_alternative<const dxbc::RTS0::v1::RootDescriptor *>(*P)){
auto *Descriptor = std::get<const dxbc::RTS0::v1::RootDescriptor *>(P.value());

if(!verifyRegisterValue(Descriptor->ShaderRegister))
return reportValueError(Ctx, "ShaderRegister",
Descriptor->ShaderRegister);

if(!verifyRegisterSpace(Descriptor->RegisterSpace))
return reportValueError(Ctx, "RegisterSpace",
Descriptor->RegisterSpace);

} else if( std::holds_alternative<const dxbc::RTS0::v2::RootDescriptor *>(*P)){
auto *Descriptor = std::get<const dxbc::RTS0::v2::RootDescriptor *>(P.value());

if(!verifyRegisterValue(Descriptor->ShaderRegister))
return reportValueError(Ctx, "ShaderRegister",
Descriptor->ShaderRegister);

if(!verifyRegisterSpace(Descriptor->RegisterSpace))
return reportValueError(Ctx, "RegisterSpace",
Descriptor->RegisterSpace);

if(!verifyDescriptorFlag(Descriptor->Flags))
return reportValueError(Ctx, "DescriptorFlag",
Descriptor->Flags);
}
}

return false;
Expand Down Expand Up @@ -370,6 +417,20 @@ PreservedAnalyses RootSignatureAnalysisPrinter::run(Module &M,
<< "Shader Register: " << Constants->ShaderRegister << "\n";
OS << indent(Space + 2)
<< "Num 32 Bit Values: " << Constants->Num32BitValues << "\n";
} else if (std::holds_alternative<const dxbc::RTS0::v1::RootDescriptor *>(*P)) {
auto *Constants = std::get<const dxbc::RTS0::v1::RootDescriptor *>(*P);
OS << indent(Space + 2)
<< "Register Space: " << Constants->RegisterSpace << "\n";
OS << indent(Space + 2)
<< "Shader Register: " << Constants->ShaderRegister << "\n";
} else if (std::holds_alternative<const dxbc::RTS0::v2::RootDescriptor *>(*P)) {
auto *Constants = std::get<const dxbc::RTS0::v2::RootDescriptor *>(*P);
OS << indent(Space + 2)
<< "Register Space: " << Constants->RegisterSpace << "\n";
OS << indent(Space + 2)
<< "Shader Register: " << Constants->ShaderRegister << "\n";
OS << indent(Space + 2)
<< "Flags: " << Constants->Flags << "\n";
}
}
Space--;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s

target triple = "dxil-unknown-shadermodel6.0-compute"


; CHECK: error: Invalid value for DescriptorFlag: 3
; CHECK-NOT: Root Signature Definitions
define void @main() #0 {
entry:
ret void
}
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }


!dx.rootsignatures = !{!2} ; list of function/root signature pairs
!2 = !{ ptr @main, !3 } ; function, root signature
!3 = !{ !5 } ; list of root signature elements
!5 = !{ !"RootCBV", i32 0, i32 1, i32 2, i32 3 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s

target triple = "dxil-unknown-shadermodel6.0-compute"


; CHECK: error: Invalid value for RegisterSpace: 4294967280
; CHECK-NOT: Root Signature Definitions
define void @main() #0 {
entry:
ret void
}
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }


!dx.rootsignatures = !{!2} ; list of function/root signature pairs
!2 = !{ ptr @main, !3 } ; function, root signature
!3 = !{ !5 } ; list of root signature elements
!5 = !{ !"RootCBV", i32 0, i32 1, i32 4294967280, i32 0 }
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s

target triple = "dxil-unknown-shadermodel6.0-compute"


; CHECK: error: Invalid value for ShaderRegister: 4294967295
; CHECK-NOT: Root Signature Definitions
define void @main() #0 {
entry:
ret void
}
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }


!dx.rootsignatures = !{!2} ; list of function/root signature pairs
!2 = !{ ptr @main, !3 } ; function, root signature
!3 = !{ !5 } ; list of root signature elements
!5 = !{ !"RootCBV", i32 0, i32 4294967295, i32 2, i32 3 }
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
!2 = !{ ptr @main, !3 } ; function, root signature
!3 = !{ !5 } ; list of root signature elements
!5 = !{ !"RootCBV", i32 0, i32 1, i32 2, i32 3 }
!5 = !{ !"RootCBV", i32 0, i32 1, i32 2, i32 8 }

; DXC: - Name: RTS0
; DXC-NEXT: Size: 48
Expand All @@ -31,4 +31,4 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
; DXC-NEXT: Descriptor:
; DXC-NEXT: RegisterSpace: 2
; DXC-NEXT: ShaderRegister: 1
; DXC-NEXT: DATA_VOLATILE: true
; DXC-NEXT: DATA_STATIC: true