[llvm] [DXIL] Add support for root signature flag element in DXContainer (PR #123147)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 7 14:30:02 PST 2025
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/123147
>From 8adb678cbb5effc1a578a41a9490fdbc9e22cd0a Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Mon, 13 Jan 2025 21:57:03 +0000
Subject: [PATCH 01/50] adding rootsignature to obj2yaml
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 9 +++++++
.../BinaryFormat/DXContainerConstants.def | 1 +
llvm/include/llvm/Object/DXContainer.h | 7 +++++
.../include/llvm/ObjectYAML/DXContainerYAML.h | 16 +++++++++++
llvm/lib/Object/DXContainer.cpp | 14 ++++++++++
llvm/lib/ObjectYAML/DXContainerEmitter.cpp | 8 ++++++
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 11 ++++++++
.../RootSignatures/FlagsElement.ll | 27 +++++++++++++++++++
llvm/tools/obj2yaml/dxcontainer2yaml.cpp | 8 ++++++
9 files changed, 101 insertions(+)
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignatures/FlagsElement.ll
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 21e28d546286eea..3907d88df43b072 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -63,6 +63,15 @@ struct ShaderHash {
void swapBytes() { sys::swapByteOrder(Flags); }
};
+struct RootSignatureDesc {
+ uint32_t Version;
+ uint32_t Flags;
+ void swapBytes() {
+ sys::swapByteOrder(Version);
+ sys::swapByteOrder(Flags);
+ }
+};
+
struct ContainerVersion {
uint16_t Major;
uint16_t Minor;
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index 1aacbb2f65b27f6..38b69228cd39754 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -4,6 +4,7 @@ CONTAINER_PART(DXIL)
CONTAINER_PART(SFI0)
CONTAINER_PART(HASH)
CONTAINER_PART(PSV0)
+CONTAINER_PART(RTS0)
CONTAINER_PART(ISG1)
CONTAINER_PART(OSG1)
CONTAINER_PART(PSG1)
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index 19c83ba6c6e85df..9159b9083b6185c 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -287,6 +287,7 @@ class DXContainer {
std::optional<uint64_t> ShaderFeatureFlags;
std::optional<dxbc::ShaderHash> Hash;
std::optional<DirectX::PSVRuntimeInfo> PSVInfo;
+ std::optional<dxbc::RootSignatureDesc> RootSignature;
DirectX::Signature InputSignature;
DirectX::Signature OutputSignature;
DirectX::Signature PatchConstantSignature;
@@ -296,6 +297,7 @@ class DXContainer {
Error parseDXILHeader(StringRef Part);
Error parseShaderFeatureFlags(StringRef Part);
Error parseHash(StringRef Part);
+ Error parseRootSignature(StringRef Part);
Error parsePSVInfo(StringRef Part);
Error parseSignature(StringRef Part, DirectX::Signature &Array);
friend class PartIterator;
@@ -382,6 +384,11 @@ class DXContainer {
std::optional<dxbc::ShaderHash> getShaderHash() const { return Hash; }
+ std::optional<dxbc::RootSignatureDesc>
+ getRootSignature() const {
+ return RootSignature;
+ }
+
const std::optional<DirectX::PSVRuntimeInfo> &getPSVInfo() const {
return PSVInfo;
};
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index 66ad057ab0e30f3..c4bf6bc4920cf7b 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -72,6 +72,16 @@ struct ShaderHash {
std::vector<llvm::yaml::Hex8> Digest;
};
+
+
+struct RootSignatureDesc {
+ RootSignatureDesc() = default;
+ RootSignatureDesc(const dxbc::RootSignatureDesc &Data);
+
+ uint32_t Version;
+ uint32_t Flags;
+};
+
using ResourceFlags = dxbc::PSV::ResourceFlags;
using ResourceBindInfo = dxbc::PSV::v2::ResourceBindInfo;
@@ -159,6 +169,7 @@ struct Part {
std::optional<ShaderHash> Hash;
std::optional<PSVInfo> Info;
std::optional<DXContainerYAML::Signature> Signature;
+ std::optional<DXContainerYAML::RootSignatureDesc> RootSignature;
};
struct Object {
@@ -241,6 +252,11 @@ template <> struct MappingTraits<DXContainerYAML::Signature> {
static void mapping(IO &IO, llvm::DXContainerYAML::Signature &El);
};
+template <> struct MappingTraits<DXContainerYAML::RootSignatureDesc> {
+ static void mapping(IO &IO,
+ DXContainerYAML::RootSignatureDesc &RootSignature);
+};
+
} // namespace yaml
} // namespace llvm
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index 3b1a6203a1f8fcb..e6577192a92c74b 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -10,6 +10,7 @@
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/Error.h"
#include "llvm/Support/Alignment.h"
+#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormatVariadic.h"
using namespace llvm;
@@ -92,6 +93,14 @@ Error DXContainer::parseHash(StringRef Part) {
return Error::success();
}
+Error DXContainer::parseRootSignature(StringRef Part) {
+ dxbc::RootSignatureDesc Desc;
+ if (Error Err = readStruct(Part, Part.begin(), Desc))
+ return Err;
+ RootSignature = Desc;
+ return Error::success();
+}
+
Error DXContainer::parsePSVInfo(StringRef Part) {
if (PSVInfo)
return parseFailed("More than one PSV0 part is present in the file");
@@ -192,6 +201,11 @@ Error DXContainer::parsePartOffsets() {
return Err;
break;
case dxbc::PartType::Unknown:
+ break;
+ case dxbc::PartType::RTS0:
+ if (Error Err = parseRootSignature(PartData))
+ return Err;
+
break;
}
}
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index 175f1a12f93145f..22ac2b223ea53cc 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -261,6 +261,14 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
}
case dxbc::PartType::Unknown:
break; // Skip any handling for unrecognized parts.
+ case dxbc::PartType::RTS0:
+ if (!P.RootSignature.has_value())
+ continue;
+ dxbc::RootSignatureDesc RS = {P.RootSignature->Version, P.RootSignature->Flags};
+ if (sys::IsBigEndianHost)
+ RS.swapBytes();
+ OS.write(reinterpret_cast<char *>(&RS), sizeof(dxbc::RootSignatureDesc));
+ break;
}
uint64_t BytesWritten = OS.tell() - DataStart;
RollingOffset += BytesWritten;
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 5dee1221b27c015..7bfd77acaecfbe5 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -45,6 +45,10 @@ DXContainerYAML::ShaderHash::ShaderHash(const dxbc::ShaderHash &Data)
memcpy(Digest.data(), &Data.Digest[0], 16);
}
+DXContainerYAML::RootSignatureDesc::RootSignatureDesc(const dxbc::RootSignatureDesc &Data)
+ : Version(Data.Version), Flags(Data.Flags) {
+}
+
DXContainerYAML::PSVInfo::PSVInfo() : Version(0) {
memset(&Info, 0, sizeof(Info));
}
@@ -188,6 +192,12 @@ void MappingTraits<DXContainerYAML::Signature>::mapping(
IO.mapRequired("Parameters", S.Parameters);
}
+void MappingTraits<DXContainerYAML::RootSignatureDesc>::mapping(
+ IO &IO, DXContainerYAML::RootSignatureDesc &S) {
+ IO.mapRequired("Version", S.Version);
+ IO.mapRequired("Flags", S.Flags);
+}
+
void MappingTraits<DXContainerYAML::Part>::mapping(IO &IO,
DXContainerYAML::Part &P) {
IO.mapRequired("Name", P.Name);
@@ -197,6 +207,7 @@ void MappingTraits<DXContainerYAML::Part>::mapping(IO &IO,
IO.mapOptional("Hash", P.Hash);
IO.mapOptional("PSVInfo", P.Info);
IO.mapOptional("Signature", P.Signature);
+ IO.mapOptional("RootSignature", P.RootSignature);
}
void MappingTraits<DXContainerYAML::Object>::mapping(
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignatures/FlagsElement.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignatures/FlagsElement.ll
new file mode 100644
index 000000000000000..402f03a4dd589b0
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignatures/FlagsElement.ll
@@ -0,0 +1,27 @@
+; RUN: opt %s -dxil-embed -dxil-globals -S -o - | FileCheck %s
+; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: @dx.rts0 = private constant [8 x i8] c"{{.*}}", section "RTS0", align 4
+
+
+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 = !{ !4 } ; list of root signature elements
+!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
+
+
+; DXC: - Name: RTS0
+; DXC-NEXT: Size: 8
+; DXC-NEXT: RootSignature:
+; DXC-NEXT: Version: 1.0
+; DXC-NEXT: Flags: AllowInputAssemblerInputLayout
diff --git a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
index 06966b1883586c5..90ee47cd469949c 100644
--- a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
+++ b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
@@ -7,9 +7,11 @@
//===----------------------------------------------------------------------===//
#include "obj2yaml.h"
+#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/DXContainer.h"
#include "llvm/ObjectYAML/DXContainerYAML.h"
#include "llvm/Support/Error.h"
+#include "llvm/Support/ErrorHandling.h"
#include <algorithm>
@@ -153,6 +155,12 @@ dumpDXContainer(MemoryBufferRef Source) {
break;
case dxbc::PartType::Unknown:
break;
+ case dxbc::PartType::RTS0:
+ std::optional<dxbc::RootSignatureDesc> RS = Container.getRootSignature();
+ if (RS && RS.has_value())
+ NewPart.RootSignature = DXContainerYAML::RootSignatureDesc(*RS);
+ break;
+ break;
}
}
>From ba78f21112999d704bef4e0605a51de8f2add813 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Mon, 13 Jan 2025 22:31:14 +0000
Subject: [PATCH 02/50] adding test
---
.../RootSignature-FlagsRootElement.yaml | 242 ++++++++++++++++++
1 file changed, 242 insertions(+)
create mode 100644 llvm/test/ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml
new file mode 100644
index 000000000000000..5435c432a073ec2
--- /dev/null
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml
@@ -0,0 +1,242 @@
+# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+--- !dxcontainer
+Header:
+ Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+ Version:
+ Major: 1
+ Minor: 0
+ FileSize: 1672
+ PartCount: 7
+ PartOffsets: [ 60, 1496, 1512, 1540, 1556, 1572, 1588 ]
+Parts:
+ - Name: DXIL
+ Size: 1428
+ Program:
+ MajorVersion: 6
+ MinorVers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,
+ 0x19, 0xC5, 0x96, 0x78, 0x49, 0x89, 0x5C, 0x6B ]
+ - Name: ISG1
+ Size: 8
+ Signature:
+ Parameters: []
+ - Name: OSG1
+ Size: 8
+ Signature:
+ Parameters: []
+ - Name: RTS0
+ Size: 8
+ RootSignature:
+ Version: 1
+ Flags: 8
+ - Name: PSV0
+ Size: 76
+ PSVInfo:
+ Version: 3
+ ShaderStage: 5
+ MinimumWaveLaneCount: 0
+ MaximumWaveLaneCount: 4294967295
+ UsesViewID: 0
+ SigInputVectors: 0
+ SigOutputVectors: [ 0, 0, 0, 0 ]
+ NumThreadsX: 1
+ NumThreadsY: 1
+ NumThreadsZ: 1
+ EntryName: main
+ ResourceStride: 24
+ Resources: []
+ SigInputElements: []
+ SigOutputElements: []
+ SigPatchOrPrimElements: []
+ InputOutputMap:
+ - [ ]
+ - [ ]
+ - [ ]
+ - [ ]
+
+# CHECK: - Name: RTS0
+# CHECK-NEXT: Size: 8
+# CHECK-NEXT: RootSignature:
+# CHECK-NEXT: Version: 1
+# CHECK-NEXT: Flags: 8
>From 0a54559969f272f574ca1be557157c8c9f5f1c06 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Mon, 13 Jan 2025 22:35:01 +0000
Subject: [PATCH 03/50] removing old test
---
.../RootSignatures/FlagsElement.ll | 27 -------------------
1 file changed, 27 deletions(-)
delete mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignatures/FlagsElement.ll
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignatures/FlagsElement.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignatures/FlagsElement.ll
deleted file mode 100644
index 402f03a4dd589b0..000000000000000
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignatures/FlagsElement.ll
+++ /dev/null
@@ -1,27 +0,0 @@
-; RUN: opt %s -dxil-embed -dxil-globals -S -o - | FileCheck %s
-; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC
-
-target triple = "dxil-unknown-shadermodel6.0-compute"
-
-; CHECK: @dx.rts0 = private constant [8 x i8] c"{{.*}}", section "RTS0", align 4
-
-
-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 = !{ !4 } ; list of root signature elements
-!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
-
-
-; DXC: - Name: RTS0
-; DXC-NEXT: Size: 8
-; DXC-NEXT: RootSignature:
-; DXC-NEXT: Version: 1.0
-; DXC-NEXT: Flags: AllowInputAssemblerInputLayout
>From 557075fd17edfd8bfb40266bd70299cb27ee9632 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Mon, 13 Jan 2025 22:43:27 +0000
Subject: [PATCH 04/50] remove useless includes
---
llvm/lib/Object/DXContainer.cpp | 1 -
llvm/tools/obj2yaml/dxcontainer2yaml.cpp | 2 --
2 files changed, 3 deletions(-)
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index e6577192a92c74b..4ffa00f70bdb753 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -10,7 +10,6 @@
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/Error.h"
#include "llvm/Support/Alignment.h"
-#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/FormatVariadic.h"
using namespace llvm;
diff --git a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
index 90ee47cd469949c..6ae0a0859b48e1b 100644
--- a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
+++ b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
@@ -7,11 +7,9 @@
//===----------------------------------------------------------------------===//
#include "obj2yaml.h"
-#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/DXContainer.h"
#include "llvm/ObjectYAML/DXContainerYAML.h"
#include "llvm/Support/Error.h"
-#include "llvm/Support/ErrorHandling.h"
#include <algorithm>
>From e0d3dcd9d60a9955bb1cb0fd23dbd78bf0deddd3 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Tue, 14 Jan 2025 23:42:24 +0000
Subject: [PATCH 05/50] addressing comments
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 5 +
.../BinaryFormat/DXContainerConstants.def | 19 ++
.../include/llvm/ObjectYAML/DXContainerYAML.h | 5 +-
llvm/lib/Object/DXContainer.cpp | 3 +
llvm/lib/ObjectYAML/DXContainerEmitter.cpp | 5 +-
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 26 +-
.../RootSignature-FlagsRootElement.yaml | 259 ++----------------
7 files changed, 85 insertions(+), 237 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 3907d88df43b072..0ada21251193784 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -161,6 +161,11 @@ enum class FeatureFlags : uint64_t {
static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63,
"Shader flag bits exceed enum size.");
+#define ROOT_ELEMENT_FLAG(Num, Val) Val = 1ull << Num,
+enum class RootElementFlag : uint32_t {
+#include "DXContainerConstants.def"
+};
+
PartType parsePartType(StringRef S);
struct VertexPSVInfo {
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index 38b69228cd39754..b351b9a01773c8b 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -53,6 +53,25 @@ SHADER_FEATURE_FLAG(31, 36, NextUnusedBit, "Next reserved shader flag bit (not a
#undef SHADER_FEATURE_FLAG
#endif // SHADER_FEATURE_FLAG
+#ifdef ROOT_ELEMENT_FLAG
+
+
+ROOT_ELEMENT_FLAG(0, AllowInputAssemblerInputLayout)
+ROOT_ELEMENT_FLAG(1, DenyVertexShaderRootAccess)
+ROOT_ELEMENT_FLAG(2, DenyHullShaderRootAccess)
+ROOT_ELEMENT_FLAG(3, DenyDomainShaderRootAccess)
+ROOT_ELEMENT_FLAG(4, DenyGeometryShaderRootAccess)
+ROOT_ELEMENT_FLAG(5, DenyPixelShaderRootAccess)
+ROOT_ELEMENT_FLAG(6, AllowStreamOutput)
+ROOT_ELEMENT_FLAG(7, LocalRootSignature)
+ROOT_ELEMENT_FLAG(8, DenyAmplificationShaderRootAccess)
+ROOT_ELEMENT_FLAG(9, DenyMeshShaderRootAccess)
+ROOT_ELEMENT_FLAG(10, CBVSRVUAVHeapDirectlyIndexed)
+ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed)
+#undef ROOT_ELEMENT_FLAG
+#endif // ROOT_ELEMENT_FLAG
+
+
#ifdef DXIL_MODULE_FLAG
// Only save DXIL module flags which not map to feature flags here.
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index c4bf6bc4920cf7b..9b25c5c33e7ef8a 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -73,13 +73,14 @@ struct ShaderHash {
};
-
+#define ROOT_ELEMENT_FLAG(Num, Val) bool Val = false;
struct RootSignatureDesc {
RootSignatureDesc() = default;
RootSignatureDesc(const dxbc::RootSignatureDesc &Data);
+ uint32_t getEncodedFlags();
uint32_t Version;
- uint32_t Flags;
+#include "llvm/BinaryFormat/DXContainerConstants.def"
};
using ResourceFlags = dxbc::PSV::ResourceFlags;
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index 4ffa00f70bdb753..92956c580f9b237 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -8,6 +8,7 @@
#include "llvm/Object/DXContainer.h"
#include "llvm/BinaryFormat/DXContainer.h"
+#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/Object/Error.h"
#include "llvm/Support/Alignment.h"
#include "llvm/Support/FormatVariadic.h"
@@ -93,6 +94,8 @@ Error DXContainer::parseHash(StringRef Part) {
}
Error DXContainer::parseRootSignature(StringRef Part) {
+ if (RootSignature)
+ return parseFailed("More than one RTS0 part is present in the file");
dxbc::RootSignatureDesc Desc;
if (Error Err = readStruct(Part, Part.begin(), Desc))
return Err;
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index 22ac2b223ea53cc..e5561fe44375d74 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -264,7 +264,10 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
case dxbc::PartType::RTS0:
if (!P.RootSignature.has_value())
continue;
- dxbc::RootSignatureDesc RS = {P.RootSignature->Version, P.RootSignature->Flags};
+ uint32_t Flags = P.RootSignature->getEncodedFlags();
+ if (sys::IsBigEndianHost)
+ sys::swapByteOrder(Flags);
+ dxbc::RootSignatureDesc RS = {P.RootSignature->Version, Flags};
if (sys::IsBigEndianHost)
RS.swapBytes();
OS.write(reinterpret_cast<char *>(&RS), sizeof(dxbc::RootSignatureDesc));
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 7bfd77acaecfbe5..d226a5b2e5942bd 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -15,6 +15,7 @@
#include "llvm/ADT/ScopeExit.h"
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Support/ScopedPrinter.h"
+#include <cstdint>
namespace llvm {
@@ -29,6 +30,23 @@ DXContainerYAML::ShaderFeatureFlags::ShaderFeatureFlags(uint64_t FlagData) {
#include "llvm/BinaryFormat/DXContainerConstants.def"
}
+
+DXContainerYAML::RootSignatureDesc::RootSignatureDesc(const dxbc::RootSignatureDesc &Data): Version(Data.Version) {
+#define ROOT_ELEMENT_FLAG(Num, Val) \
+ Val = (Data.Flags & (uint32_t)dxbc::RootElementFlag::Val) > 0;
+#include "llvm/BinaryFormat/DXContainerConstants.def"
+}
+
+
+uint32_t DXContainerYAML::RootSignatureDesc::getEncodedFlags() {
+ uint64_t Flag = 0;
+#define ROOT_ELEMENT_FLAG(Num, Val) \
+ if (Val) \
+ Flag |= (uint32_t)dxbc::RootElementFlag::Val;
+#include "llvm/BinaryFormat/DXContainerConstants.def"
+ return Flag;
+}
+
uint64_t DXContainerYAML::ShaderFeatureFlags::getEncodedFlags() {
uint64_t Flag = 0;
#define SHADER_FEATURE_FLAG(Num, DxilModuleNum, Val, Str) \
@@ -45,10 +63,6 @@ DXContainerYAML::ShaderHash::ShaderHash(const dxbc::ShaderHash &Data)
memcpy(Digest.data(), &Data.Digest[0], 16);
}
-DXContainerYAML::RootSignatureDesc::RootSignatureDesc(const dxbc::RootSignatureDesc &Data)
- : Version(Data.Version), Flags(Data.Flags) {
-}
-
DXContainerYAML::PSVInfo::PSVInfo() : Version(0) {
memset(&Info, 0, sizeof(Info));
}
@@ -195,7 +209,9 @@ void MappingTraits<DXContainerYAML::Signature>::mapping(
void MappingTraits<DXContainerYAML::RootSignatureDesc>::mapping(
IO &IO, DXContainerYAML::RootSignatureDesc &S) {
IO.mapRequired("Version", S.Version);
- IO.mapRequired("Flags", S.Flags);
+ #define ROOT_ELEMENT_FLAG(Num, Val) \
+ IO.mapRequired(#Val, S.Val);
+ #include "llvm/BinaryFormat/DXContainerConstants.def"
}
void MappingTraits<DXContainerYAML::Part>::mapping(IO &IO,
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml
index 5435c432a073ec2..2ed71091cacd45d 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml
@@ -6,237 +6,38 @@ Header:
Version:
Major: 1
Minor: 0
- FileSize: 1672
- PartCount: 7
- PartOffsets: [ 60, 1496, 1512, 1540, 1556, 1572, 1588 ]
+ PartCount: 1
+ PartOffsets: [ 60 ]
Parts:
- - Name: DXIL
- Size: 1428
- Program:
- MajorVersion: 6
- MinorVersion: 0
- ShaderKind: 5
- Size: 357
- DXILMajorVersion: 1
- DXILMinorVersion: 0
- DXILSize: 1404
- DXIL: [ 0x42, 0x43, 0xC0, 0xDE, 0x21, 0xC, 0x0, 0x0, 0x5C,
- 0x1, 0x0, 0x0, 0xB, 0x82, 0x20, 0x0, 0x2, 0x0,
- 0x0, 0x0, 0x13, 0x0, 0x0, 0x0, 0x7, 0x81, 0x23,
- 0x91, 0x41, 0xC8, 0x4, 0x49, 0x6, 0x10, 0x32,
- 0x39, 0x92, 0x1, 0x84, 0xC, 0x25, 0x5, 0x8, 0x19,
- 0x1E, 0x4, 0x8B, 0x62, 0x80, 0x10, 0x45, 0x2,
- 0x42, 0x92, 0xB, 0x42, 0x84, 0x10, 0x32, 0x14,
- 0x38, 0x8, 0x18, 0x4B, 0xA, 0x32, 0x42, 0x88,
- 0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xA5,
- 0x0, 0x19, 0x32, 0x42, 0xE4, 0x48, 0xE, 0x90,
- 0x11, 0x22, 0xC4, 0x50, 0x41, 0x51, 0x81, 0x8C,
- 0xE1, 0x83, 0xE5, 0x8A, 0x4, 0x21, 0x46, 0x6,
- 0x89, 0x20, 0x0, 0x0, 0x11, 0x0, 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 0x0,
- 0x0, 0x0, 0x7, 0x50, 0x10, 0xCD, 0x14, 0x61, 0x0,
- 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
- - Name: SFI0
- Size: 8
- - Name: HASH
- Size: 20
- Hash:
- IncludesSource: false
- Digest: [ 0xCE, 0xA, 0x5B, 0x9C, 0xBF, 0x9A, 0xBB, 0x5,
- 0x19, 0xC5, 0x96, 0x78, 0x49, 0x89, 0x5C, 0x6B ]
- - Name: ISG1
- Size: 8
- Signature:
- Parameters: []
- - Name: OSG1
- Size: 8
- Signature:
- Parameters: []
- Name: RTS0
Size: 8
RootSignature:
Version: 1
- Flags: 8
- - Name: PSV0
- Size: 76
- PSVInfo:
- Version: 3
- ShaderStage: 5
- MinimumWaveLaneCount: 0
- MaximumWaveLaneCount: 4294967295
- UsesViewID: 0
- SigInputVectors: 0
- SigOutputVectors: [ 0, 0, 0, 0 ]
- NumThreadsX: 1
- NumThreadsY: 1
- NumThreadsZ: 1
- EntryName: main
- ResourceStride: 24
- Resources: []
- SigInputElements: []
- SigOutputElements: []
- SigPatchOrPrimElements: []
- InputOutputMap:
- - [ ]
- - [ ]
- - [ ]
- - [ ]
-
-# CHECK: - Name: RTS0
-# CHECK-NEXT: Size: 8
-# CHECK-NEXT: RootSignature:
-# CHECK-NEXT: Version: 1
-# CHECK-NEXT: Flags: 8
+ AllowInputAssemblerInputLayout: true
+ DenyVertexShaderRootAccess: false
+ DenyHullShaderRootAccess: false
+ DenyDomainShaderRootAccess: false
+ DenyGeometryShaderRootAccess: false
+ DenyPixelShaderRootAccess: false
+ AllowStreamOutput: false
+ LocalRootSignature: false
+ DenyAmplificationShaderRootAccess: false
+ DenyMeshShaderRootAccess: false
+ CBVSRVUAVHeapDirectlyIndexed: false
+ SamplerHeapDirectlyIndexed: false
+#CHECK: - Name: RTS0
+#CHECK-NEXT: Size: 8
+#CHECK-NEXT: RootSignature:
+#CHECK-NEXT: Version: 1
+#CHECK-NEXT: AllowInputAssemblerInputLayout: true
+#CHECK-NEXT: DenyVertexShaderRootAccess: false
+#CHECK-NEXT: DenyHullShaderRootAccess: false
+#CHECK-NEXT: DenyDomainShaderRootAccess: false
+#CHECK-NEXT: DenyGeometryShaderRootAccess: false
+#CHECK-NEXT: DenyPixelShaderRootAccess: false
+#CHECK-NEXT: AllowStreamOutput: false
+#CHECK-NEXT: LocalRootSignature: false
+#CHECK-NEXT: DenyAmplificationShaderRootAccess: false
+#CHECK-NEXT: DenyMeshShaderRootAccess: false
+#CHECK-NEXT: CBVSRVUAVHeapDirectlyIndexed: false
+#CHECK-NEXT: SamplerHeapDirectlyIndexed: false
>From 80587ddd3736472bfd3e089db35880762a2035b7 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Tue, 14 Jan 2025 23:47:46 +0000
Subject: [PATCH 06/50] updating test
---
.../ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml
index 2ed71091cacd45d..8ce18d8e1aa4cb4 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml
@@ -25,6 +25,7 @@ Parts:
DenyMeshShaderRootAccess: false
CBVSRVUAVHeapDirectlyIndexed: false
SamplerHeapDirectlyIndexed: false
+
#CHECK: - Name: RTS0
#CHECK-NEXT: Size: 8
#CHECK-NEXT: RootSignature:
>From be3764d8748cf55c781cd3b98a5f616c9a09e5f0 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Wed, 15 Jan 2025 00:42:39 +0000
Subject: [PATCH 07/50] removing useless header
---
llvm/lib/Object/DXContainer.cpp | 1 -
1 file changed, 1 deletion(-)
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index 92956c580f9b237..b7eff25ed7b33b0 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -8,7 +8,6 @@
#include "llvm/Object/DXContainer.h"
#include "llvm/BinaryFormat/DXContainer.h"
-#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/Object/Error.h"
#include "llvm/Support/Alignment.h"
#include "llvm/Support/FormatVariadic.h"
>From 7582ca61409969ae247c116374bacbbdb4909fca Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Wed, 15 Jan 2025 17:30:00 +0000
Subject: [PATCH 08/50] fix formating
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 4 ++--
llvm/include/llvm/Object/DXContainer.h | 3 +--
llvm/include/llvm/ObjectYAML/DXContainerYAML.h | 1 -
llvm/lib/ObjectYAML/DXContainerEmitter.cpp | 2 +-
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 15 +++++++--------
5 files changed, 11 insertions(+), 14 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 0ada21251193784..74003387a249ef7 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -66,9 +66,9 @@ struct ShaderHash {
struct RootSignatureDesc {
uint32_t Version;
uint32_t Flags;
- void swapBytes() {
+ void swapBytes() {
sys::swapByteOrder(Version);
- sys::swapByteOrder(Flags);
+ sys::swapByteOrder(Flags);
}
};
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index 9159b9083b6185c..8574a04027ce463 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -384,8 +384,7 @@ class DXContainer {
std::optional<dxbc::ShaderHash> getShaderHash() const { return Hash; }
- std::optional<dxbc::RootSignatureDesc>
- getRootSignature() const {
+ std::optional<dxbc::RootSignatureDesc> getRootSignature() const {
return RootSignature;
}
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index 9b25c5c33e7ef8a..bb232543cd3b075 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -72,7 +72,6 @@ struct ShaderHash {
std::vector<llvm::yaml::Hex8> Digest;
};
-
#define ROOT_ELEMENT_FLAG(Num, Val) bool Val = false;
struct RootSignatureDesc {
RootSignatureDesc() = default;
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index e5561fe44375d74..3ac539c8e0853c3 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -267,7 +267,7 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
uint32_t Flags = P.RootSignature->getEncodedFlags();
if (sys::IsBigEndianHost)
sys::swapByteOrder(Flags);
- dxbc::RootSignatureDesc RS = {P.RootSignature->Version, Flags};
+ dxbc::RootSignatureDesc RS = {P.RootSignature->Version, Flags};
if (sys::IsBigEndianHost)
RS.swapBytes();
OS.write(reinterpret_cast<char *>(&RS), sizeof(dxbc::RootSignatureDesc));
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index d226a5b2e5942bd..80f4587a06ff5e8 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -30,17 +30,17 @@ DXContainerYAML::ShaderFeatureFlags::ShaderFeatureFlags(uint64_t FlagData) {
#include "llvm/BinaryFormat/DXContainerConstants.def"
}
-
-DXContainerYAML::RootSignatureDesc::RootSignatureDesc(const dxbc::RootSignatureDesc &Data): Version(Data.Version) {
-#define ROOT_ELEMENT_FLAG(Num, Val) \
+DXContainerYAML::RootSignatureDesc::RootSignatureDesc(
+ const dxbc::RootSignatureDesc &Data)
+ : Version(Data.Version) {
+#define ROOT_ELEMENT_FLAG(Num, Val) \
Val = (Data.Flags & (uint32_t)dxbc::RootElementFlag::Val) > 0;
#include "llvm/BinaryFormat/DXContainerConstants.def"
}
-
uint32_t DXContainerYAML::RootSignatureDesc::getEncodedFlags() {
uint64_t Flag = 0;
-#define ROOT_ELEMENT_FLAG(Num, Val) \
+#define ROOT_ELEMENT_FLAG(Num, Val) \
if (Val) \
Flag |= (uint32_t)dxbc::RootElementFlag::Val;
#include "llvm/BinaryFormat/DXContainerConstants.def"
@@ -209,9 +209,8 @@ void MappingTraits<DXContainerYAML::Signature>::mapping(
void MappingTraits<DXContainerYAML::RootSignatureDesc>::mapping(
IO &IO, DXContainerYAML::RootSignatureDesc &S) {
IO.mapRequired("Version", S.Version);
- #define ROOT_ELEMENT_FLAG(Num, Val) \
- IO.mapRequired(#Val, S.Val);
- #include "llvm/BinaryFormat/DXContainerConstants.def"
+#define ROOT_ELEMENT_FLAG(Num, Val) IO.mapRequired(#Val, S.Val);
+#include "llvm/BinaryFormat/DXContainerConstants.def"
}
void MappingTraits<DXContainerYAML::Part>::mapping(IO &IO,
>From 6aaa0a5a0d8a9bf7bf6514ed4960ec9ef8bae9a4 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Wed, 15 Jan 2025 18:21:06 +0000
Subject: [PATCH 09/50] renaming test
---
...otSignature-FlagsRootElement.yaml => RootSignature-Flags.yaml} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename llvm/test/ObjectYAML/DXContainer/{RootSignature-FlagsRootElement.yaml => RootSignature-Flags.yaml} (100%)
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
similarity index 100%
rename from llvm/test/ObjectYAML/DXContainer/RootSignature-FlagsRootElement.yaml
rename to llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
>From 916b2f17afef4e7b79818596551df44c75a55016 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 16 Jan 2025 22:16:45 +0000
Subject: [PATCH 10/50] addressing pr comments
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 2 +-
.../BinaryFormat/DXContainerConstants.def | 24 +++++++++----------
.../include/llvm/ObjectYAML/DXContainerYAML.h | 2 +-
llvm/lib/Object/DXContainer.cpp | 1 -
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 6 ++---
llvm/tools/obj2yaml/dxcontainer2yaml.cpp | 3 +--
6 files changed, 18 insertions(+), 20 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 74003387a249ef7..605281df31ed466 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -161,7 +161,7 @@ enum class FeatureFlags : uint64_t {
static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63,
"Shader flag bits exceed enum size.");
-#define ROOT_ELEMENT_FLAG(Num, Val) Val = 1ull << Num,
+#define ROOT_ELEMENT_FLAG(Num, Val, Str) Val = 1ull << Num,
enum class RootElementFlag : uint32_t {
#include "DXContainerConstants.def"
};
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index b351b9a01773c8b..a382cd714ce7f39 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -56,18 +56,18 @@ SHADER_FEATURE_FLAG(31, 36, NextUnusedBit, "Next reserved shader flag bit (not a
#ifdef ROOT_ELEMENT_FLAG
-ROOT_ELEMENT_FLAG(0, AllowInputAssemblerInputLayout)
-ROOT_ELEMENT_FLAG(1, DenyVertexShaderRootAccess)
-ROOT_ELEMENT_FLAG(2, DenyHullShaderRootAccess)
-ROOT_ELEMENT_FLAG(3, DenyDomainShaderRootAccess)
-ROOT_ELEMENT_FLAG(4, DenyGeometryShaderRootAccess)
-ROOT_ELEMENT_FLAG(5, DenyPixelShaderRootAccess)
-ROOT_ELEMENT_FLAG(6, AllowStreamOutput)
-ROOT_ELEMENT_FLAG(7, LocalRootSignature)
-ROOT_ELEMENT_FLAG(8, DenyAmplificationShaderRootAccess)
-ROOT_ELEMENT_FLAG(9, DenyMeshShaderRootAccess)
-ROOT_ELEMENT_FLAG(10, CBVSRVUAVHeapDirectlyIndexed)
-ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed)
+ROOT_ELEMENT_FLAG(0, AllowInputAssemblerInputLayout, "")
+ROOT_ELEMENT_FLAG(1, DenyVertexShaderRootAccess, "")
+ROOT_ELEMENT_FLAG(2, DenyHullShaderRootAccess, "")
+ROOT_ELEMENT_FLAG(3, DenyDomainShaderRootAccess, "")
+ROOT_ELEMENT_FLAG(4, DenyGeometryShaderRootAccess, "")
+ROOT_ELEMENT_FLAG(5, DenyPixelShaderRootAccess, "")
+ROOT_ELEMENT_FLAG(6, AllowStreamOutput, "")
+ROOT_ELEMENT_FLAG(7, LocalRootSignature, "")
+ROOT_ELEMENT_FLAG(8, DenyAmplificationShaderRootAccess, "")
+ROOT_ELEMENT_FLAG(9, DenyMeshShaderRootAccess, "")
+ROOT_ELEMENT_FLAG(10, CBVSRVUAVHeapDirectlyIndexed, "")
+ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed, "")
#undef ROOT_ELEMENT_FLAG
#endif // ROOT_ELEMENT_FLAG
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index bb232543cd3b075..755c81541e5db03 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -72,7 +72,7 @@ struct ShaderHash {
std::vector<llvm::yaml::Hex8> Digest;
};
-#define ROOT_ELEMENT_FLAG(Num, Val) bool Val = false;
+#define ROOT_ELEMENT_FLAG(Num, Val, Str) bool Val = false;
struct RootSignatureDesc {
RootSignatureDesc() = default;
RootSignatureDesc(const dxbc::RootSignatureDesc &Data);
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index b7eff25ed7b33b0..160844f73669ac7 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -206,7 +206,6 @@ Error DXContainer::parsePartOffsets() {
case dxbc::PartType::RTS0:
if (Error Err = parseRootSignature(PartData))
return Err;
-
break;
}
}
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 80f4587a06ff5e8..682216e5febec0d 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -33,14 +33,14 @@ DXContainerYAML::ShaderFeatureFlags::ShaderFeatureFlags(uint64_t FlagData) {
DXContainerYAML::RootSignatureDesc::RootSignatureDesc(
const dxbc::RootSignatureDesc &Data)
: Version(Data.Version) {
-#define ROOT_ELEMENT_FLAG(Num, Val) \
+#define ROOT_ELEMENT_FLAG(Num, Val, Str) \
Val = (Data.Flags & (uint32_t)dxbc::RootElementFlag::Val) > 0;
#include "llvm/BinaryFormat/DXContainerConstants.def"
}
uint32_t DXContainerYAML::RootSignatureDesc::getEncodedFlags() {
uint64_t Flag = 0;
-#define ROOT_ELEMENT_FLAG(Num, Val) \
+#define ROOT_ELEMENT_FLAG(Num, Val, Str) \
if (Val) \
Flag |= (uint32_t)dxbc::RootElementFlag::Val;
#include "llvm/BinaryFormat/DXContainerConstants.def"
@@ -209,7 +209,7 @@ void MappingTraits<DXContainerYAML::Signature>::mapping(
void MappingTraits<DXContainerYAML::RootSignatureDesc>::mapping(
IO &IO, DXContainerYAML::RootSignatureDesc &S) {
IO.mapRequired("Version", S.Version);
-#define ROOT_ELEMENT_FLAG(Num, Val) IO.mapRequired(#Val, S.Val);
+#define ROOT_ELEMENT_FLAG(Num, Val, Str) IO.mapRequired(#Val, S.Val);
#include "llvm/BinaryFormat/DXContainerConstants.def"
}
diff --git a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
index 6ae0a0859b48e1b..9588a8277dad7b1 100644
--- a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
+++ b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
@@ -155,10 +155,9 @@ dumpDXContainer(MemoryBufferRef Source) {
break;
case dxbc::PartType::RTS0:
std::optional<dxbc::RootSignatureDesc> RS = Container.getRootSignature();
- if (RS && RS.has_value())
+ if (RS.has_value())
NewPart.RootSignature = DXContainerYAML::RootSignatureDesc(*RS);
break;
- break;
}
}
>From d9bce0a1d80155b342726189e929dabb4ec3fb90 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 16 Jan 2025 22:20:18 +0000
Subject: [PATCH 11/50] adding str to ROOT_ELEMENT_FLAG
---
.../BinaryFormat/DXContainerConstants.def | 24 +++++++++----------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index a382cd714ce7f39..300d0dd2797c9ab 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -56,18 +56,18 @@ SHADER_FEATURE_FLAG(31, 36, NextUnusedBit, "Next reserved shader flag bit (not a
#ifdef ROOT_ELEMENT_FLAG
-ROOT_ELEMENT_FLAG(0, AllowInputAssemblerInputLayout, "")
-ROOT_ELEMENT_FLAG(1, DenyVertexShaderRootAccess, "")
-ROOT_ELEMENT_FLAG(2, DenyHullShaderRootAccess, "")
-ROOT_ELEMENT_FLAG(3, DenyDomainShaderRootAccess, "")
-ROOT_ELEMENT_FLAG(4, DenyGeometryShaderRootAccess, "")
-ROOT_ELEMENT_FLAG(5, DenyPixelShaderRootAccess, "")
-ROOT_ELEMENT_FLAG(6, AllowStreamOutput, "")
-ROOT_ELEMENT_FLAG(7, LocalRootSignature, "")
-ROOT_ELEMENT_FLAG(8, DenyAmplificationShaderRootAccess, "")
-ROOT_ELEMENT_FLAG(9, DenyMeshShaderRootAccess, "")
-ROOT_ELEMENT_FLAG(10, CBVSRVUAVHeapDirectlyIndexed, "")
-ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed, "")
+ROOT_ELEMENT_FLAG(0, AllowInputAssemblerInputLayout, "The app is opting in to using the Input Assembler")
+ROOT_ELEMENT_FLAG(1, DenyVertexShaderRootAccess, "Denies the vertex shader access to the root signature.")
+ROOT_ELEMENT_FLAG(2, DenyHullShaderRootAccess, "Denies the hull shader access to the root signature.")
+ROOT_ELEMENT_FLAG(3, DenyDomainShaderRootAccess, "Denies the domain shader access to the root signature.")
+ROOT_ELEMENT_FLAG(4, DenyGeometryShaderRootAccess, "Denies the geometry shader access to the root signature.")
+ROOT_ELEMENT_FLAG(5, DenyPixelShaderRootAccess, "Denies the pixel shader access to the root signature.")
+ROOT_ELEMENT_FLAG(6, AllowStreamOutput, "The app is opting in to using Stream Output.")
+ROOT_ELEMENT_FLAG(7, LocalRootSignature, "The root signature is to be used with raytracing shaders to define resource bindings sourced from shader records in shader tables.")
+ROOT_ELEMENT_FLAG(8, DenyAmplificationShaderRootAccess, "Denies the amplification shader access to the root signature.")
+ROOT_ELEMENT_FLAG(9, DenyMeshShaderRootAccess, "Denies the mesh shader access to the root signature.")
+ROOT_ELEMENT_FLAG(10, CBVSRVUAVHeapDirectlyIndexed, "The shaders are allowed to index the CBV/SRV/UAV descriptor heap directly, using the ResourceDescriptorHeap built-in variable.")
+ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed, "The shaders are allowed to index the sampler descriptor heap directly, using the SamplerDescriptorHeap built-in variable.")
#undef ROOT_ELEMENT_FLAG
#endif // ROOT_ELEMENT_FLAG
>From e7676ed42376dea921f74a0f9c5f3d422235a08f Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Fri, 17 Jan 2025 07:28:09 +0000
Subject: [PATCH 12/50] formating
---
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 682216e5febec0d..0351239cac2c120 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -33,14 +33,14 @@ DXContainerYAML::ShaderFeatureFlags::ShaderFeatureFlags(uint64_t FlagData) {
DXContainerYAML::RootSignatureDesc::RootSignatureDesc(
const dxbc::RootSignatureDesc &Data)
: Version(Data.Version) {
-#define ROOT_ELEMENT_FLAG(Num, Val, Str) \
+#define ROOT_ELEMENT_FLAG(Num, Val, Str) \
Val = (Data.Flags & (uint32_t)dxbc::RootElementFlag::Val) > 0;
#include "llvm/BinaryFormat/DXContainerConstants.def"
}
uint32_t DXContainerYAML::RootSignatureDesc::getEncodedFlags() {
uint64_t Flag = 0;
-#define ROOT_ELEMENT_FLAG(Num, Val, Str) \
+#define ROOT_ELEMENT_FLAG(Num, Val, Str) \
if (Val) \
Flag |= (uint32_t)dxbc::RootElementFlag::Val;
#include "llvm/BinaryFormat/DXContainerConstants.def"
>From a0cee57b8ea574a67704b3aa1a0b820c99820b57 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Sat, 18 Jan 2025 00:03:15 +0000
Subject: [PATCH 13/50] refactoring to follow llvm standards
---
.../llvm/MC/DXContainerRootSignature.h | 27 +++++++++++++++++
llvm/include/llvm/Object/DXContainer.h | 23 +++++++++++++--
.../include/llvm/ObjectYAML/DXContainerYAML.h | 3 +-
llvm/lib/MC/CMakeLists.txt | 1 +
llvm/lib/MC/DXContainerRootSignature.cpp | 29 +++++++++++++++++++
llvm/lib/Object/DXContainer.cpp | 18 ++++++++++--
llvm/lib/ObjectYAML/DXContainerEmitter.cpp | 14 ++++-----
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 8 +++--
llvm/tools/obj2yaml/dxcontainer2yaml.cpp | 2 +-
9 files changed, 109 insertions(+), 16 deletions(-)
create mode 100644 llvm/include/llvm/MC/DXContainerRootSignature.h
create mode 100644 llvm/lib/MC/DXContainerRootSignature.cpp
diff --git a/llvm/include/llvm/MC/DXContainerRootSignature.h b/llvm/include/llvm/MC/DXContainerRootSignature.h
new file mode 100644
index 000000000000000..3926193697a49c1
--- /dev/null
+++ b/llvm/include/llvm/MC/DXContainerRootSignature.h
@@ -0,0 +1,27 @@
+//===- llvm/MC/DXContainerRootSignature.h - DXContainer RootSignature -*- C++
+//-------*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include <cstdint>
+#include <limits>
+
+namespace llvm {
+
+class raw_ostream;
+
+namespace mcdxbc {
+struct RootSignatureHeader {
+ uint32_t Version;
+ uint32_t Flags;
+
+ void swapBytes();
+ void write(raw_ostream &OS,
+ uint32_t Version = std::numeric_limits<uint32_t>::max());
+};
+} // namespace mcdxbc
+} // namespace llvm
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index 8574a04027ce463..0e93a0f1d9615df 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -22,6 +22,8 @@
#include "llvm/Support/MemoryBufferRef.h"
#include "llvm/TargetParser/Triple.h"
#include <array>
+#include <cstdint>
+#include <sys/types.h>
#include <variant>
namespace llvm {
@@ -116,6 +118,23 @@ template <typename T> struct ViewArray {
};
namespace DirectX {
+
+class RootSignature {
+private:
+ StringRef Data;
+ uint32_t Version;
+ uint32_t Flags;
+
+public:
+ RootSignature(StringRef Data) : Data(Data) {}
+
+ Error parse();
+
+ uint32_t getVersion() const { return Version; }
+
+ uint32_t getFlags() const { return Flags; }
+};
+
class PSVRuntimeInfo {
using ResourceArray = ViewArray<dxbc::PSV::v2::ResourceBindInfo>;
@@ -287,7 +306,7 @@ class DXContainer {
std::optional<uint64_t> ShaderFeatureFlags;
std::optional<dxbc::ShaderHash> Hash;
std::optional<DirectX::PSVRuntimeInfo> PSVInfo;
- std::optional<dxbc::RootSignatureDesc> RootSignature;
+ std::optional<DirectX::RootSignature> RootSignature;
DirectX::Signature InputSignature;
DirectX::Signature OutputSignature;
DirectX::Signature PatchConstantSignature;
@@ -384,7 +403,7 @@ class DXContainer {
std::optional<dxbc::ShaderHash> getShaderHash() const { return Hash; }
- std::optional<dxbc::RootSignatureDesc> getRootSignature() const {
+ std::optional<DirectX::RootSignature> getRootSignature() const {
return RootSignature;
}
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index 755c81541e5db03..eb514c197675923 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -17,6 +17,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/DXContainer.h"
+#include "llvm/Object/DXContainer.h"
#include "llvm/ObjectYAML/YAML.h"
#include "llvm/Support/YAMLTraits.h"
#include <array>
@@ -75,7 +76,7 @@ struct ShaderHash {
#define ROOT_ELEMENT_FLAG(Num, Val, Str) bool Val = false;
struct RootSignatureDesc {
RootSignatureDesc() = default;
- RootSignatureDesc(const dxbc::RootSignatureDesc &Data);
+ RootSignatureDesc(const object::DirectX::RootSignature &Data);
uint32_t getEncodedFlags();
uint32_t Version;
diff --git a/llvm/lib/MC/CMakeLists.txt b/llvm/lib/MC/CMakeLists.txt
index e1d19196c8766a7..f49f14c848b9023 100644
--- a/llvm/lib/MC/CMakeLists.txt
+++ b/llvm/lib/MC/CMakeLists.txt
@@ -1,6 +1,7 @@
add_llvm_component_library(LLVMMC
ConstantPools.cpp
DXContainerPSVInfo.cpp
+ DXContainerRootSignature.cpp
ELFObjectWriter.cpp
GOFFObjectWriter.cpp
MCAsmBackend.cpp
diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp
new file mode 100644
index 000000000000000..331d5131fce7bc6
--- /dev/null
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -0,0 +1,29 @@
+//===- llvm/MC/DXContainerRootSignature.cpp - DXContainer RootSignature -*- C++
+//-------*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+
+#include "llvm/MC/DXContainerRootSignature.h"
+#include "llvm/Support/EndianStream.h"
+#include "llvm/Support/SwapByteOrder.h"
+#include <iterator>
+
+using namespace llvm;
+using namespace llvm::mcdxbc;
+
+void RootSignatureHeader::write(raw_ostream &OS, uint32_t Version) {
+
+ uint32_t SizeInfo = sizeof(this);
+ // support::endian::write(OS, SizeInfo, llvm::endianness::little);
+
+ if (sys::IsBigEndianHost) {
+ sys::swapByteOrder(Version);
+ sys::swapByteOrder(Flags);
+ }
+
+ OS.write(reinterpret_cast<const char *>(this), SizeInfo);
+}
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index 160844f73669ac7..3d67a7bc0a566bc 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -95,8 +95,8 @@ Error DXContainer::parseHash(StringRef Part) {
Error DXContainer::parseRootSignature(StringRef Part) {
if (RootSignature)
return parseFailed("More than one RTS0 part is present in the file");
- dxbc::RootSignatureDesc Desc;
- if (Error Err = readStruct(Part, Part.begin(), Desc))
+ DirectX::RootSignature Desc(Part);
+ if (Error Err = Desc.parse())
return Err;
RootSignature = Desc;
return Error::success();
@@ -242,6 +242,20 @@ void DXContainer::PartIterator::updateIteratorImpl(const uint32_t Offset) {
IteratorState.Offset = Offset;
}
+Error DirectX::RootSignature::parse() {
+ const char *Current = Data.begin();
+ dxbc::RootSignatureDesc Desc;
+ if (Error Err = readStruct(Data, Current, Desc))
+ return Err;
+
+ if (sys::IsBigEndianHost)
+ Desc.swapBytes();
+
+ Version = Desc.Version;
+ Flags = Desc.Flags;
+ return Error::success();
+}
+
Error DirectX::PSVRuntimeInfo::parse(uint16_t ShaderKind) {
Triple::EnvironmentType ShaderStage = dxbc::getShaderStage(ShaderKind);
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index 3ac539c8e0853c3..0504f6b88a7db5a 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -13,6 +13,7 @@
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/MC/DXContainerPSVInfo.h"
+#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/ObjectYAML/ObjectYAML.h"
#include "llvm/ObjectYAML/yaml2obj.h"
#include "llvm/Support/Errc.h"
@@ -264,13 +265,12 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
case dxbc::PartType::RTS0:
if (!P.RootSignature.has_value())
continue;
- uint32_t Flags = P.RootSignature->getEncodedFlags();
- if (sys::IsBigEndianHost)
- sys::swapByteOrder(Flags);
- dxbc::RootSignatureDesc RS = {P.RootSignature->Version, Flags};
- if (sys::IsBigEndianHost)
- RS.swapBytes();
- OS.write(reinterpret_cast<char *>(&RS), sizeof(dxbc::RootSignatureDesc));
+
+ mcdxbc::RootSignatureHeader Header;
+ Header.Version = P.RootSignature->Version;
+ Header.Flags = P.RootSignature->getEncodedFlags();
+
+ Header.write(OS);
break;
}
uint64_t BytesWritten = OS.tell() - DataStart;
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 0351239cac2c120..aeae3d9f3958a55 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -14,6 +14,7 @@
#include "llvm/ObjectYAML/DXContainerYAML.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/BinaryFormat/DXContainer.h"
+#include "llvm/Object/DXContainer.h"
#include "llvm/Support/ScopedPrinter.h"
#include <cstdint>
@@ -31,10 +32,11 @@ DXContainerYAML::ShaderFeatureFlags::ShaderFeatureFlags(uint64_t FlagData) {
}
DXContainerYAML::RootSignatureDesc::RootSignatureDesc(
- const dxbc::RootSignatureDesc &Data)
- : Version(Data.Version) {
+ const object::DirectX::RootSignature &Data)
+ : Version(Data.getVersion()) {
+ uint32_t Flags = Data.getFlags();
#define ROOT_ELEMENT_FLAG(Num, Val, Str) \
- Val = (Data.Flags & (uint32_t)dxbc::RootElementFlag::Val) > 0;
+ Val = (Flags & (uint32_t)dxbc::RootElementFlag::Val) > 0;
#include "llvm/BinaryFormat/DXContainerConstants.def"
}
diff --git a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
index 9588a8277dad7b1..54a912d9438afdb 100644
--- a/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
+++ b/llvm/tools/obj2yaml/dxcontainer2yaml.cpp
@@ -154,7 +154,7 @@ dumpDXContainer(MemoryBufferRef Source) {
case dxbc::PartType::Unknown:
break;
case dxbc::PartType::RTS0:
- std::optional<dxbc::RootSignatureDesc> RS = Container.getRootSignature();
+ std::optional<DirectX::RootSignature> RS = Container.getRootSignature();
if (RS.has_value())
NewPart.RootSignature = DXContainerYAML::RootSignatureDesc(*RS);
break;
>From 1e7a1fe405d911d478b8ecdb886a4db33b201500 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Mon, 27 Jan 2025 21:13:51 +0000
Subject: [PATCH 14/50] addressing comments
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 31 +++++++++++++++++++
.../BinaryFormat/DXContainerConstants.def | 25 ++++++++++++++-
.../llvm/MC/DXContainerRootSignature.h | 3 +-
llvm/include/llvm/Object/DXContainer.h | 3 ++
.../include/llvm/ObjectYAML/DXContainerYAML.h | 5 +++
llvm/lib/MC/DXContainerRootSignature.cpp | 16 +++-------
llvm/lib/Object/DXContainer.cpp | 21 +++++++------
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 5 +--
.../DXContainer/RootSignature-Flags.yaml | 26 ++--------------
9 files changed, 86 insertions(+), 49 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 605281df31ed466..dbe1aee97b1742d 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -13,10 +13,12 @@
#ifndef LLVM_BINARYFORMAT_DXCONTAINER_H
#define LLVM_BINARYFORMAT_DXCONTAINER_H
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/SwapByteOrder.h"
#include "llvm/TargetParser/Triple.h"
+#include <cstdint>
#include <stdint.h>
namespace llvm {
@@ -63,10 +65,39 @@ struct ShaderHash {
void swapBytes() { sys::swapByteOrder(Flags); }
};
+#define ROOT_PARAMETER(RootParameter) RootParameter,
+enum class RootParameterType {
+#include "DXContainerConstants.def"
+};
+
+#define SHADER_VISIBILITY(ShaderVisibility) ShaderVisibility,
+enum class ShaderVisibilityFlag {
+#include "DXContainerConstants.def"
+};
+
+struct RootConstants {
+ uint32_t ShaderRegister;
+ uint32_t RegisterSpace;
+ uint32_t Num32BitValues;
+};
+
+struct RootParameter {
+ RootParameterType ParameterType;
+ union {
+ RootConstants Constants;
+ };
+ ShaderVisibilityFlag ShaderVisibility;
+};
+
struct RootSignatureDesc {
+ uint32_t Size;
uint32_t Version;
uint32_t Flags;
+ uint32_t NumParameters;
+ RootParameter *Parameters;
+
void swapBytes() {
+ sys::swapByteOrder(Size);
sys::swapByteOrder(Version);
sys::swapByteOrder(Flags);
}
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index 300d0dd2797c9ab..2134c2375f6d35e 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -53,8 +53,31 @@ SHADER_FEATURE_FLAG(31, 36, NextUnusedBit, "Next reserved shader flag bit (not a
#undef SHADER_FEATURE_FLAG
#endif // SHADER_FEATURE_FLAG
-#ifdef ROOT_ELEMENT_FLAG
+#ifdef ROOT_PARAMETER
+
+ROOT_PARAMETER(DescriptorTable)
+ROOT_PARAMETER(Constants32Bit)
+ROOT_PARAMETER(CBV)
+ROOT_PARAMETER(SRV)
+ROOT_PARAMETER(UAV)
+#undef ROOT_PARAMETER
+#endif // ROOT_PARAMETER
+
+
+#ifdef SHADER_VISIBILITY
+
+SHADER_VISIBILITY(All)
+SHADER_VISIBILITY(Vertex)
+SHADER_VISIBILITY(Hull)
+SHADER_VISIBILITY(Domain)
+SHADER_VISIBILITY(Geometry)
+SHADER_VISIBILITY(Pixel)
+SHADER_VISIBILITY(Amplification)
+SHADER_VISIBILITY(Mesh)
+#undef SHADER_VISIBILITY
+#endif // SHADER_VISIBILITY
+#ifdef ROOT_ELEMENT_FLAG
ROOT_ELEMENT_FLAG(0, AllowInputAssemblerInputLayout, "The app is opting in to using the Input Assembler")
ROOT_ELEMENT_FLAG(1, DenyVertexShaderRootAccess, "Denies the vertex shader access to the root signature.")
diff --git a/llvm/include/llvm/MC/DXContainerRootSignature.h b/llvm/include/llvm/MC/DXContainerRootSignature.h
index 3926193697a49c1..d83ae28ffd692d6 100644
--- a/llvm/include/llvm/MC/DXContainerRootSignature.h
+++ b/llvm/include/llvm/MC/DXContainerRootSignature.h
@@ -20,8 +20,7 @@ struct RootSignatureHeader {
uint32_t Flags;
void swapBytes();
- void write(raw_ostream &OS,
- uint32_t Version = std::numeric_limits<uint32_t>::max());
+ void write(raw_ostream &OS);
};
} // namespace mcdxbc
} // namespace llvm
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index 0e93a0f1d9615df..07a3c872ac83d4d 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -122,6 +122,7 @@ namespace DirectX {
class RootSignature {
private:
StringRef Data;
+ uint32_t Size;
uint32_t Version;
uint32_t Flags;
@@ -130,6 +131,8 @@ class RootSignature {
Error parse();
+ uint32_t getSize() const { return Size; }
+
uint32_t getVersion() const { return Version; }
uint32_t getFlags() const { return Flags; }
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index eb514c197675923..e9b318faee2957e 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -15,6 +15,7 @@
#ifndef LLVM_OBJECTYAML_DXCONTAINERYAML_H
#define LLVM_OBJECTYAML_DXCONTAINERYAML_H
+#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/DXContainer.h"
@@ -79,7 +80,11 @@ struct RootSignatureDesc {
RootSignatureDesc(const object::DirectX::RootSignature &Data);
uint32_t getEncodedFlags();
+ uint32_t Size;
uint32_t Version;
+ uint32_t NumParameters;
+ SmallVector<dxbc::RootParameter> Parameters;
+
#include "llvm/BinaryFormat/DXContainerConstants.def"
};
diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp
index 331d5131fce7bc6..0bb87c2cc38324f 100644
--- a/llvm/lib/MC/DXContainerRootSignature.cpp
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -1,5 +1,4 @@
-//===- llvm/MC/DXContainerRootSignature.cpp - DXContainer RootSignature -*- C++
-//-------*-===//
+//===- llvm/MC/DXContainerRootSignature.cpp - RootSignature -*- C++ -*-=======//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -15,15 +14,10 @@
using namespace llvm;
using namespace llvm::mcdxbc;
-void RootSignatureHeader::write(raw_ostream &OS, uint32_t Version) {
+void RootSignatureHeader::write(raw_ostream &OS) {
uint32_t SizeInfo = sizeof(this);
- // support::endian::write(OS, SizeInfo, llvm::endianness::little);
-
- if (sys::IsBigEndianHost) {
- sys::swapByteOrder(Version);
- sys::swapByteOrder(Flags);
- }
-
- OS.write(reinterpret_cast<const char *>(this), SizeInfo);
+ support::endian::write(OS, SizeInfo, llvm::endianness::little);
+ support::endian::write(OS, Version, llvm::endianness::little);
+ support::endian::write(OS, Flags, llvm::endianness::little);
}
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index 3d67a7bc0a566bc..ffb0b6884831ba0 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -10,6 +10,7 @@
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/Error.h"
#include "llvm/Support/Alignment.h"
+#include "llvm/Support/Endian.h"
#include "llvm/Support/FormatVariadic.h"
using namespace llvm;
@@ -95,10 +96,9 @@ Error DXContainer::parseHash(StringRef Part) {
Error DXContainer::parseRootSignature(StringRef Part) {
if (RootSignature)
return parseFailed("More than one RTS0 part is present in the file");
- DirectX::RootSignature Desc(Part);
- if (Error Err = Desc.parse())
+ RootSignature = DirectX::RootSignature(Part);
+ if (Error Err = RootSignature->parse())
return Err;
- RootSignature = Desc;
return Error::success();
}
@@ -244,15 +244,16 @@ void DXContainer::PartIterator::updateIteratorImpl(const uint32_t Offset) {
Error DirectX::RootSignature::parse() {
const char *Current = Data.begin();
- dxbc::RootSignatureDesc Desc;
- if (Error Err = readStruct(Data, Current, Desc))
- return Err;
- if (sys::IsBigEndianHost)
- Desc.swapBytes();
+ Size = support::endian::read<uint32_t, llvm::endianness::little>(Current);
+ Current += sizeof(uint32_t);
+
+ Version = support::endian::read<uint32_t, llvm::endianness::little>(Current);
+ Current += sizeof(uint32_t);
+
+ Flags = support::endian::read<uint32_t, llvm::endianness::little>(Current);
+ Current += sizeof(uint32_t);
- Version = Desc.Version;
- Flags = Desc.Flags;
return Error::success();
}
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index aeae3d9f3958a55..f3febcb09400ffd 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -33,7 +33,7 @@ DXContainerYAML::ShaderFeatureFlags::ShaderFeatureFlags(uint64_t FlagData) {
DXContainerYAML::RootSignatureDesc::RootSignatureDesc(
const object::DirectX::RootSignature &Data)
- : Version(Data.getVersion()) {
+ : Size(Data.getSize()), Version(Data.getVersion()) {
uint32_t Flags = Data.getFlags();
#define ROOT_ELEMENT_FLAG(Num, Val, Str) \
Val = (Flags & (uint32_t)dxbc::RootElementFlag::Val) > 0;
@@ -210,8 +210,9 @@ void MappingTraits<DXContainerYAML::Signature>::mapping(
void MappingTraits<DXContainerYAML::RootSignatureDesc>::mapping(
IO &IO, DXContainerYAML::RootSignatureDesc &S) {
+ IO.mapRequired("Size", S.Size);
IO.mapRequired("Version", S.Version);
-#define ROOT_ELEMENT_FLAG(Num, Val, Str) IO.mapRequired(#Val, S.Val);
+#define ROOT_ELEMENT_FLAG(Num, Val, Str) IO.mapOptional(#Val, S.Val, false);
#include "llvm/BinaryFormat/DXContainerConstants.def"
}
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
index 8ce18d8e1aa4cb4..6c0ccda2e4ca5f5 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
@@ -12,33 +12,13 @@ Parts:
- Name: RTS0
Size: 8
RootSignature:
+ Size: 8
Version: 1
AllowInputAssemblerInputLayout: true
- DenyVertexShaderRootAccess: false
- DenyHullShaderRootAccess: false
- DenyDomainShaderRootAccess: false
- DenyGeometryShaderRootAccess: false
- DenyPixelShaderRootAccess: false
- AllowStreamOutput: false
- LocalRootSignature: false
- DenyAmplificationShaderRootAccess: false
- DenyMeshShaderRootAccess: false
- CBVSRVUAVHeapDirectlyIndexed: false
- SamplerHeapDirectlyIndexed: false
-
+
#CHECK: - Name: RTS0
#CHECK-NEXT: Size: 8
#CHECK-NEXT: RootSignature:
+#CHECK-NEXT: Size: 8
#CHECK-NEXT: Version: 1
#CHECK-NEXT: AllowInputAssemblerInputLayout: true
-#CHECK-NEXT: DenyVertexShaderRootAccess: false
-#CHECK-NEXT: DenyHullShaderRootAccess: false
-#CHECK-NEXT: DenyDomainShaderRootAccess: false
-#CHECK-NEXT: DenyGeometryShaderRootAccess: false
-#CHECK-NEXT: DenyPixelShaderRootAccess: false
-#CHECK-NEXT: AllowStreamOutput: false
-#CHECK-NEXT: LocalRootSignature: false
-#CHECK-NEXT: DenyAmplificationShaderRootAccess: false
-#CHECK-NEXT: DenyMeshShaderRootAccess: false
-#CHECK-NEXT: CBVSRVUAVHeapDirectlyIndexed: false
-#CHECK-NEXT: SamplerHeapDirectlyIndexed: false
>From 0ed658a364305f1e315fa9b0c4caf9bbf40f45d9 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Mon, 27 Jan 2025 22:04:58 +0000
Subject: [PATCH 15/50] clean up
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 2 --
llvm/include/llvm/MC/DXContainerRootSignature.h | 3 +--
llvm/include/llvm/Object/DXContainer.h | 2 --
llvm/include/llvm/ObjectYAML/DXContainerYAML.h | 1 -
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 1 -
5 files changed, 1 insertion(+), 8 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index dbe1aee97b1742d..9268c28dbc69d23 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -13,12 +13,10 @@
#ifndef LLVM_BINARYFORMAT_DXCONTAINER_H
#define LLVM_BINARYFORMAT_DXCONTAINER_H
-#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/SwapByteOrder.h"
#include "llvm/TargetParser/Triple.h"
-#include <cstdint>
#include <stdint.h>
namespace llvm {
diff --git a/llvm/include/llvm/MC/DXContainerRootSignature.h b/llvm/include/llvm/MC/DXContainerRootSignature.h
index d83ae28ffd692d6..23de2709088c667 100644
--- a/llvm/include/llvm/MC/DXContainerRootSignature.h
+++ b/llvm/include/llvm/MC/DXContainerRootSignature.h
@@ -1,5 +1,4 @@
-//===- llvm/MC/DXContainerRootSignature.h - DXContainer RootSignature -*- C++
-//-------*-===//
+//===- llvm/MC/DXContainerRootSignature.h - RootSignature -*- C++ -*- ========//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index 07a3c872ac83d4d..290fbd69991864e 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -22,8 +22,6 @@
#include "llvm/Support/MemoryBufferRef.h"
#include "llvm/TargetParser/Triple.h"
#include <array>
-#include <cstdint>
-#include <sys/types.h>
#include <variant>
namespace llvm {
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index e9b318faee2957e..6b01f105a544bf7 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -15,7 +15,6 @@
#ifndef LLVM_OBJECTYAML_DXCONTAINERYAML_H
#define LLVM_OBJECTYAML_DXCONTAINERYAML_H
-#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/DXContainer.h"
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index f3febcb09400ffd..985546872a8b358 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -16,7 +16,6 @@
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/DXContainer.h"
#include "llvm/Support/ScopedPrinter.h"
-#include <cstdint>
namespace llvm {
>From 932062e69fd910b8432d49e11f614f2634f64e2f Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 30 Jan 2025 22:43:23 +0000
Subject: [PATCH 16/50] remove version
---
llvm/include/llvm/MC/DXContainerRootSignature.h | 1 -
llvm/include/llvm/Object/DXContainer.h | 3 ---
llvm/include/llvm/ObjectYAML/DXContainerYAML.h | 1 -
llvm/lib/MC/DXContainerRootSignature.cpp | 1 -
llvm/lib/Object/DXContainer.cpp | 3 ---
llvm/lib/ObjectYAML/DXContainerEmitter.cpp | 1 -
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 3 +--
llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml | 2 --
8 files changed, 1 insertion(+), 14 deletions(-)
diff --git a/llvm/include/llvm/MC/DXContainerRootSignature.h b/llvm/include/llvm/MC/DXContainerRootSignature.h
index 23de2709088c667..20b4f5a4285f69b 100644
--- a/llvm/include/llvm/MC/DXContainerRootSignature.h
+++ b/llvm/include/llvm/MC/DXContainerRootSignature.h
@@ -15,7 +15,6 @@ class raw_ostream;
namespace mcdxbc {
struct RootSignatureHeader {
- uint32_t Version;
uint32_t Flags;
void swapBytes();
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index 290fbd69991864e..5f7737d2fa41d26 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -121,7 +121,6 @@ class RootSignature {
private:
StringRef Data;
uint32_t Size;
- uint32_t Version;
uint32_t Flags;
public:
@@ -131,8 +130,6 @@ class RootSignature {
uint32_t getSize() const { return Size; }
- uint32_t getVersion() const { return Version; }
-
uint32_t getFlags() const { return Flags; }
};
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index 6b01f105a544bf7..9b3259f3bf6c603 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -80,7 +80,6 @@ struct RootSignatureDesc {
uint32_t getEncodedFlags();
uint32_t Size;
- uint32_t Version;
uint32_t NumParameters;
SmallVector<dxbc::RootParameter> Parameters;
diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp
index 0bb87c2cc38324f..4e085654a1e5e1b 100644
--- a/llvm/lib/MC/DXContainerRootSignature.cpp
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -18,6 +18,5 @@ void RootSignatureHeader::write(raw_ostream &OS) {
uint32_t SizeInfo = sizeof(this);
support::endian::write(OS, SizeInfo, llvm::endianness::little);
- support::endian::write(OS, Version, llvm::endianness::little);
support::endian::write(OS, Flags, llvm::endianness::little);
}
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index ffb0b6884831ba0..6743911059cfd43 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -248,9 +248,6 @@ Error DirectX::RootSignature::parse() {
Size = support::endian::read<uint32_t, llvm::endianness::little>(Current);
Current += sizeof(uint32_t);
- Version = support::endian::read<uint32_t, llvm::endianness::little>(Current);
- Current += sizeof(uint32_t);
-
Flags = support::endian::read<uint32_t, llvm::endianness::little>(Current);
Current += sizeof(uint32_t);
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index 0504f6b88a7db5a..ada7383ea3c6b8f 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -267,7 +267,6 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
continue;
mcdxbc::RootSignatureHeader Header;
- Header.Version = P.RootSignature->Version;
Header.Flags = P.RootSignature->getEncodedFlags();
Header.write(OS);
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 985546872a8b358..fd85d75dc32eb35 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -32,7 +32,7 @@ DXContainerYAML::ShaderFeatureFlags::ShaderFeatureFlags(uint64_t FlagData) {
DXContainerYAML::RootSignatureDesc::RootSignatureDesc(
const object::DirectX::RootSignature &Data)
- : Size(Data.getSize()), Version(Data.getVersion()) {
+ : Size(Data.getSize()) {
uint32_t Flags = Data.getFlags();
#define ROOT_ELEMENT_FLAG(Num, Val, Str) \
Val = (Flags & (uint32_t)dxbc::RootElementFlag::Val) > 0;
@@ -210,7 +210,6 @@ void MappingTraits<DXContainerYAML::Signature>::mapping(
void MappingTraits<DXContainerYAML::RootSignatureDesc>::mapping(
IO &IO, DXContainerYAML::RootSignatureDesc &S) {
IO.mapRequired("Size", S.Size);
- IO.mapRequired("Version", S.Version);
#define ROOT_ELEMENT_FLAG(Num, Val, Str) IO.mapOptional(#Val, S.Val, false);
#include "llvm/BinaryFormat/DXContainerConstants.def"
}
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
index 6c0ccda2e4ca5f5..6f10bd2f74b46fa 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
@@ -13,12 +13,10 @@ Parts:
Size: 8
RootSignature:
Size: 8
- Version: 1
AllowInputAssemblerInputLayout: true
#CHECK: - Name: RTS0
#CHECK-NEXT: Size: 8
#CHECK-NEXT: RootSignature:
#CHECK-NEXT: Size: 8
-#CHECK-NEXT: Version: 1
#CHECK-NEXT: AllowInputAssemblerInputLayout: true
>From 628937c1d268008ea8f7414e35f29171d207c5c9 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 30 Jan 2025 22:53:12 +0000
Subject: [PATCH 17/50] fix pr
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 28 -------------------
.../include/llvm/ObjectYAML/DXContainerYAML.h | 2 --
2 files changed, 30 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 9268c28dbc69d23..71a6d15e46a81db 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -63,40 +63,12 @@ struct ShaderHash {
void swapBytes() { sys::swapByteOrder(Flags); }
};
-#define ROOT_PARAMETER(RootParameter) RootParameter,
-enum class RootParameterType {
-#include "DXContainerConstants.def"
-};
-
-#define SHADER_VISIBILITY(ShaderVisibility) ShaderVisibility,
-enum class ShaderVisibilityFlag {
-#include "DXContainerConstants.def"
-};
-
-struct RootConstants {
- uint32_t ShaderRegister;
- uint32_t RegisterSpace;
- uint32_t Num32BitValues;
-};
-
-struct RootParameter {
- RootParameterType ParameterType;
- union {
- RootConstants Constants;
- };
- ShaderVisibilityFlag ShaderVisibility;
-};
-
struct RootSignatureDesc {
uint32_t Size;
- uint32_t Version;
uint32_t Flags;
- uint32_t NumParameters;
- RootParameter *Parameters;
void swapBytes() {
sys::swapByteOrder(Size);
- sys::swapByteOrder(Version);
sys::swapByteOrder(Flags);
}
};
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index 9b3259f3bf6c603..a82083fa18de6b1 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -80,8 +80,6 @@ struct RootSignatureDesc {
uint32_t getEncodedFlags();
uint32_t Size;
- uint32_t NumParameters;
- SmallVector<dxbc::RootParameter> Parameters;
#include "llvm/BinaryFormat/DXContainerConstants.def"
};
>From 1378c9fda2cbbd66267496b9ce8394cc29f9945c Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Fri, 31 Jan 2025 07:04:08 +0000
Subject: [PATCH 18/50] adding dxil-dis test
---
.../DXContainer/RootSignature-Flags.yaml | 194 +++++++++++++++++-
1 file changed, 191 insertions(+), 3 deletions(-)
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
index 6f10bd2f74b46fa..bcb04c2c9edd923 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
@@ -1,4 +1,6 @@
# RUN: yaml2obj %s | obj2yaml | FileCheck %s
+# RUN: yaml2obj %s | dxil-dis | FileCheck %s --check-prefix=DXC
+
--- !dxcontainer
Header:
Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
@@ -6,17 +8,203 @@ Header:
Version:
Major: 1
Minor: 0
- PartCount: 1
- PartOffsets: [ 60 ]
+ PartCount: 2
+ PartOffsets: [ 60, 1496 ]
Parts:
+ - Name: DXIL
+ Size: 1428
+ Program:
+ MajorVersion: 6
+ MinorVersion: 0
+ ShaderKind: 5
+ Size: 357
+ DXILMajorVersion: 1
+ DXILMinorVersion: 0
+ DXILSize: 1404
+ DXIL: [ 0x42, 0x43, 0xC0, 0xDE, 0x21, 0xC, 0x0, 0x0, 0x5C,
+ 0x1, 0x0, 0x0, 0xB, 0x82, 0x20, 0x0, 0x2, 0x0,
+ 0x0, 0x0, 0x13, 0x0, 0x0, 0x0, 0x7, 0x81, 0x23,
+ 0x91, 0x41, 0xC8, 0x4, 0x49, 0x6, 0x10, 0x32,
+ 0x39, 0x92, 0x1, 0x84, 0xC, 0x25, 0x5, 0x8, 0x19,
+ 0x1E, 0x4, 0x8B, 0x62, 0x80, 0x10, 0x45, 0x2,
+ 0x42, 0x92, 0xB, 0x42, 0x84, 0x10, 0x32, 0x14,
+ 0x38, 0x8, 0x18, 0x4B, 0xA, 0x32, 0x42, 0x88,
+ 0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xA5,
+ 0x0, 0x19, 0x32, 0x42, 0xE4, 0x48, 0xE, 0x90,
+ 0x11, 0x22, 0xC4, 0x50, 0x41, 0x51, 0x81, 0x8C,
+ 0xE1, 0x83, 0xE5, 0x8A, 0x4, 0x21, 0x46, 0x6,
+ 0x89, 0x20, 0x0, 0x0, 0x11, 0x0, 0x0, 0x0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, 0x0,
+ 0x0, 0x6, 0x40, 0x30, 0x0, 0xD2, 0x0, 0x0, 0x0,
+ 0x61, 0x20, 0x0, 0x0, 0x6, 0x0, 0x0, 0x0, 0x13,
+ 0x4, 0x1, 0x86, 0x3, 0x1, 0x0, 0x0, 0x2, 0x0,
+ 0x0, 0x0, 0x7, 0x50, 0x10, 0xCD, 0x14, 0x61, 0x0,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
- Name: RTS0
Size: 8
RootSignature:
Size: 8
AllowInputAssemblerInputLayout: true
-
+
+
+
#CHECK: - Name: RTS0
#CHECK-NEXT: Size: 8
#CHECK-NEXT: RootSignature:
#CHECK-NEXT: Size: 8
#CHECK-NEXT: AllowInputAssemblerInputLayout: true
+
+# DXC: !dx.rootsignatures = !{[[RS:![0-9]+]]}
+# DXC: [[RS]] = !{void ()* @main, [[REL:![0-9]+]]}
+# DXC: [[REL]] = !{[[RF:![0-9]+]]}
+# DXC: [[RF]] = !{!"RootFlags", i32 1}
>From e3206c9daf0bb601cf03c490c23c483dd7a56e14 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Fri, 31 Jan 2025 22:53:06 +0000
Subject: [PATCH 19/50] adding compatibility test
---
.../DXContainer/RootSignature-Flags.yaml | 191 +----------------
llvm/test/tools/dxil-dis/lit.local.cfg | 2 +-
llvm/test/tools/dxil-dis/root-signature.yaml | 201 ++++++++++++++++++
3 files changed, 204 insertions(+), 190 deletions(-)
create mode 100644 llvm/test/tools/dxil-dis/root-signature.yaml
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
index bcb04c2c9edd923..e3ca7347d52c7cb 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
@@ -1,5 +1,4 @@
# RUN: yaml2obj %s | obj2yaml | FileCheck %s
-# RUN: yaml2obj %s | dxil-dis | FileCheck %s --check-prefix=DXC
--- !dxcontainer
Header:
@@ -8,203 +7,17 @@ Header:
Version:
Major: 1
Minor: 0
- PartCount: 2
- PartOffsets: [ 60, 1496 ]
+ PartCount: 1
+ PartOffsets: [ 60 ]
Parts:
- - Name: DXIL
- Size: 1428
- Program:
- MajorVersion: 6
- MinorVersion: 0
- ShaderKind: 5
- Size: 357
- DXILMajorVersion: 1
- DXILMinorVersion: 0
- DXILSize: 1404
- DXIL: [ 0x42, 0x43, 0xC0, 0xDE, 0x21, 0xC, 0x0, 0x0, 0x5C,
- 0x1, 0x0, 0x0, 0xB, 0x82, 0x20, 0x0, 0x2, 0x0,
- 0x0, 0x0, 0x13, 0x0, 0x0, 0x0, 0x7, 0x81, 0x23,
- 0x91, 0x41, 0xC8, 0x4, 0x49, 0x6, 0x10, 0x32,
- 0x39, 0x92, 0x1, 0x84, 0xC, 0x25, 0x5, 0x8, 0x19,
- 0x1E, 0x4, 0x8B, 0x62, 0x80, 0x10, 0x45, 0x2,
- 0x42, 0x92, 0xB, 0x42, 0x84, 0x10, 0x32, 0x14,
- 0x38, 0x8, 0x18, 0x4B, 0xA, 0x32, 0x42, 0x88,
- 0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xA5,
- 0x0, 0x19, 0x32, 0x42, 0xE4, 0x48, 0xE, 0x90,
- 0x11, 0x22, 0xC4, 0x50, 0x41, 0x51, 0x81, 0x8C,
- 0xE1, 0x83, 0xE5, 0x8A, 0x4, 0x21, 0x46, 0x6,
- 0x89, 0x20, 0x0, 0x0, 0x11, 0x0, 0x0, 0x0, 0x32,
- 0x22, 0x8, 0x9, 0x20, 0x64, 0x85, 0x4, 0x13, 0x22,
- 0xA4, 0x84, 0x4, 0x13, 0x22, 0xE3, 0x84, 0xA1,
- 0x90, 0x14, 0x12, 0x4C, 0x88, 0x8C, 0xB, 0x84,
- 0x84, 0x4C, 0x10, 0x20, 0x73,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0x82, 0x21, 0x8, 0x87,
- 0x30, 0x4, 0xE1, 0x18, 0x86, 0x20, 0x1C, 0xC4,
- 0x18, 0x84, 0xA0, 0x18, 0x43, 0x90, 0x8C, 0x41,
- 0x20, 0x94, 0x31, 0xC, 0x82, 0x71, 0x8C, 0x41,
- 0x28, 0x8E, 0x31, 0xC, 0x45, 0x51, 0x8C, 0x41,
- 0x40, 0x9C, 0x31, 0x14, 0xC4, 0x0, 0x0, 0x8F,
- 0x89, 0xC8, 0xF0, 0x5C, 0xE4, 0xDE, 0xDE, 0xE8,
- 0xE6, 0xD2, 0xCE, 0xDC, 0xC2, 0xE8, 0xEA, 0xE4,
- 0xCA, 0xE6, 0x86, 0x12, 0x28, 0xC6, 0x21, 0xC3,
- 0x73, 0x99, 0x43, 0xB, 0x23, 0x2B, 0x93, 0x6B,
- 0x7A, 0x23, 0x2B, 0x63, 0x1B, 0x4A, 0xB0, 0x18,
- 0x85, 0xC, 0xCF, 0xC5, 0xAE, 0x4C, 0x6E, 0x2E,
- 0xED, 0xCD, 0x6D, 0x28, 0x1, 0x63, 0x1C, 0x32,
- 0x3C, 0x97, 0x32, 0x37, 0x3A, 0xB9, 0x3C, 0xA8,
- 0xB7, 0x34, 0x37, 0xBA, 0xB9, 0xA1, 0x4, 0xF,
- 0x0, 0x0, 0x71, 0x20, 0x0, 0x0, 0x2, 0x0, 0x0,
- 0x0, 0x6, 0x40, 0x30, 0x0, 0xD2, 0x0, 0x0, 0x0,
- 0x61, 0x20, 0x0, 0x0, 0x6, 0x0, 0x0, 0x0, 0x13,
- 0x4, 0x1, 0x86, 0x3, 0x1, 0x0, 0x0, 0x2, 0x0,
- 0x0, 0x0, 0x7, 0x50, 0x10, 0xCD, 0x14, 0x61, 0x0,
- 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
- Name: RTS0
Size: 8
RootSignature:
Size: 8
AllowInputAssemblerInputLayout: true
-
-
#CHECK: - Name: RTS0
#CHECK-NEXT: Size: 8
#CHECK-NEXT: RootSignature:
#CHECK-NEXT: Size: 8
#CHECK-NEXT: AllowInputAssemblerInputLayout: true
-
-# DXC: !dx.rootsignatures = !{[[RS:![0-9]+]]}
-# DXC: [[RS]] = !{void ()* @main, [[REL:![0-9]+]]}
-# DXC: [[REL]] = !{[[RF:![0-9]+]]}
-# DXC: [[RF]] = !{!"RootFlags", i32 1}
diff --git a/llvm/test/tools/dxil-dis/lit.local.cfg b/llvm/test/tools/dxil-dis/lit.local.cfg
index 7b6819e0b406ae3..8fe45f696bff99d 100644
--- a/llvm/test/tools/dxil-dis/lit.local.cfg
+++ b/llvm/test/tools/dxil-dis/lit.local.cfg
@@ -1,3 +1,3 @@
if not config.dxil_tests:
config.unsupported = True
-config.suffixes = [".ll"]
+config.suffixes = [".ll", ".yaml"]
diff --git a/llvm/test/tools/dxil-dis/root-signature.yaml b/llvm/test/tools/dxil-dis/root-signature.yaml
new file mode 100644
index 000000000000000..2a11dd9b3fcee22
--- /dev/null
+++ b/llvm/test/tools/dxil-dis/root-signature.yaml
@@ -0,0 +1,201 @@
+# RUN: yaml2obj %s | dxil-dis | FileCheck %s
+
+--- !dxcontainer
+Header:
+ Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+ Version:
+ Major: 1
+ Minor: 0
+ PartCount: 2
+ PartOffsets: [ 60, 1496 ]
+Parts:
+ - Name: DXIL
+ Size: 1428
+ Program:
+ MajorVersion: 6
+ MinorVersion: 0
+ ShaderKind: 5
+ Size: 357
+ DXILMajorVersion: 1
+ DXILMinorVersion: 0
+ DXILSize: 1404
+ DXIL: [ 0x42, 0x43, 0xC0, 0xDE, 0x21, 0xC, 0x0, 0x0, 0x5C,
+ 0x1, 0x0, 0x0, 0xB, 0x82, 0x20, 0x0, 0x2, 0x0,
+ 0x0, 0x0, 0x13, 0x0, 0x0, 0x0, 0x7, 0x81, 0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, 0xE4, 0xDE, 0xDE, 0xE8,
+ 0xE6, 0xD2, 0xCE, 0xDC, 0xC2, 0xE8, 0xEA, 0xE4,
+ 0xCA, 0xE6, 0x86, 0x12, 0x28, 0xC6, 0x21, 0xC3,
+ 0x73, 0x99, 0x43, 0xB, 0x23, 0x2B, 0x93, 0x6B,
+ 0x7A, 0x23, 0x2B, 0x63, 0x1B, 0x4A, 0xB0, 0x18,
+ 0x85, 0xC, 0xCF, 0xC5, 0xAE, 0x4C, 0x6E, 0x2E,
+ 0xED, 0xCD, 0x6D, 0x28, 0x1, 0x63, 0x1C, 0x32,
+ 0x3C, 0x97, 0x32, 0x37, 0x3A, 0xB9, 0x3C, 0xA8,
+ 0xB7, 0x34, 0x37, 0xBA, 0xB9, 0xA1, 0x4, 0xF,
+ 0x0, 0x0, 0x71, 0x20, 0x0, 0x0, 0x2, 0x0, 0x0,
+ 0x0, 0x6, 0x40, 0x30, 0x0, 0xD2, 0x0, 0x0, 0x0,
+ 0x61, 0x20, 0x0, 0x0, 0x6, 0x0, 0x0, 0x0, 0x13,
+ 0x4, 0x1, 0x86, 0x3, 0x1, 0x0, 0x0, 0x2, 0x0,
+ 0x0, 0x0, 0x7, 0x50, 0x10, 0xCD, 0x14, 0x61, 0x0,
+ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
+ - Name: RTS0
+ Size: 8
+ RootSignature:
+ Size: 8
+ AllowInputAssemblerInputLayout: true
+
+# CHECK: !dx.rootsignatures = !{[[RS:![0-9]+]]}
+# CHECK: [[RS]] = !{void ()* @main, [[REL:![0-9]+]]}
+# CHECK: [[REL]] = !{[[RF:![0-9]+]]}
+# CHECK: [[RF]] = !{!"RootFlags", i32 1}
>From f93d42d1a38f86300b4ee3d2f33ed9ffeb470acc Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Mon, 3 Feb 2025 21:05:40 +0000
Subject: [PATCH 20/50] addressing test concerns
---
.../llvm/MC/DXContainerRootSignature.h | 8 +-
llvm/include/llvm/Object/DXContainer.h | 14 +-
.../include/llvm/ObjectYAML/DXContainerYAML.h | 6 +-
llvm/lib/MC/DXContainerRootSignature.cpp | 9 +-
llvm/lib/Object/DXContainer.cpp | 18 +-
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 11 +-
.../DXContainer/RootSignature-Flags.yaml | 22 +-
llvm/test/tools/dxil-dis/root-signature.yaml | 201 ------------------
llvm/unittests/Object/DXContainerTest.cpp | 22 ++
.../ObjectYAML/DXContainerYAMLTest.cpp | 40 ++++
10 files changed, 129 insertions(+), 222 deletions(-)
delete mode 100644 llvm/test/tools/dxil-dis/root-signature.yaml
diff --git a/llvm/include/llvm/MC/DXContainerRootSignature.h b/llvm/include/llvm/MC/DXContainerRootSignature.h
index 20b4f5a4285f69b..e1a9be5fc52d8b7 100644
--- a/llvm/include/llvm/MC/DXContainerRootSignature.h
+++ b/llvm/include/llvm/MC/DXContainerRootSignature.h
@@ -15,9 +15,13 @@ class raw_ostream;
namespace mcdxbc {
struct RootSignatureHeader {
- uint32_t Flags;
+ uint32_t Version = 2;
+ uint32_t NumParameters = 0;
+ uint32_t RootParametersOffset = 0;
+ uint32_t NumStaticSamplers = 0;
+ uint32_t StaticSamplersOffset = 0;
+ uint32_t Flags = 0;
- void swapBytes();
void write(raw_ostream &OS);
};
} // namespace mcdxbc
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index 5f7737d2fa41d26..47128f94e0968e1 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -120,16 +120,22 @@ namespace DirectX {
class RootSignature {
private:
StringRef Data;
- uint32_t Size;
+ uint32_t Version;
+ uint32_t NumParameters;
+ uint32_t RootParametersOffset;
+ uint32_t NumStaticSamplers;
+ uint32_t StaticSamplersOffset;
uint32_t Flags;
public:
RootSignature(StringRef Data) : Data(Data) {}
Error parse();
-
- uint32_t getSize() const { return Size; }
-
+ uint32_t getVersion() const { return Version; }
+ uint32_t getNumParameters() const { return NumParameters; }
+ uint32_t getRootParametersOffset() const { return RootParametersOffset; }
+ uint32_t getNumStaticSamplers() const { return NumStaticSamplers; }
+ uint32_t getStaticSamplersOffset() const { return StaticSamplersOffset; }
uint32_t getFlags() const { return Flags; }
};
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index a82083fa18de6b1..1f967114ea1eb84 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -79,7 +79,11 @@ struct RootSignatureDesc {
RootSignatureDesc(const object::DirectX::RootSignature &Data);
uint32_t getEncodedFlags();
- uint32_t Size;
+ uint32_t Version;
+ uint32_t NumParameters;
+ uint32_t RootParametersOffset;
+ uint32_t NumStaticSamplers;
+ uint32_t StaticSamplersOffset;
#include "llvm/BinaryFormat/DXContainerConstants.def"
};
diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp
index 4e085654a1e5e1b..000d23f24d2413e 100644
--- a/llvm/lib/MC/DXContainerRootSignature.cpp
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -8,15 +8,16 @@
#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/Support/EndianStream.h"
-#include "llvm/Support/SwapByteOrder.h"
-#include <iterator>
using namespace llvm;
using namespace llvm::mcdxbc;
void RootSignatureHeader::write(raw_ostream &OS) {
- uint32_t SizeInfo = sizeof(this);
- support::endian::write(OS, SizeInfo, llvm::endianness::little);
+ support::endian::write(OS, Version, llvm::endianness::little);
+ support::endian::write(OS, NumParameters, llvm::endianness::little);
+ support::endian::write(OS, RootParametersOffset, llvm::endianness::little);
+ support::endian::write(OS, NumStaticSamplers, llvm::endianness::little);
+ support::endian::write(OS, StaticSamplersOffset, llvm::endianness::little);
support::endian::write(OS, Flags, llvm::endianness::little);
}
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index 6743911059cfd43..14179283f98078d 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -245,7 +245,23 @@ void DXContainer::PartIterator::updateIteratorImpl(const uint32_t Offset) {
Error DirectX::RootSignature::parse() {
const char *Current = Data.begin();
- Size = support::endian::read<uint32_t, llvm::endianness::little>(Current);
+ Version = support::endian::read<uint32_t, llvm::endianness::little>(Current);
+ Current += sizeof(uint32_t);
+
+ NumParameters =
+ support::endian::read<uint32_t, llvm::endianness::little>(Current);
+ Current += sizeof(uint32_t);
+
+ RootParametersOffset =
+ support::endian::read<uint32_t, llvm::endianness::little>(Current);
+ Current += sizeof(uint32_t);
+
+ NumStaticSamplers =
+ support::endian::read<uint32_t, llvm::endianness::little>(Current);
+ Current += sizeof(uint32_t);
+
+ StaticSamplersOffset =
+ support::endian::read<uint32_t, llvm::endianness::little>(Current);
Current += sizeof(uint32_t);
Flags = support::endian::read<uint32_t, llvm::endianness::little>(Current);
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index fd85d75dc32eb35..522781c0d36ef8b 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -32,7 +32,10 @@ DXContainerYAML::ShaderFeatureFlags::ShaderFeatureFlags(uint64_t FlagData) {
DXContainerYAML::RootSignatureDesc::RootSignatureDesc(
const object::DirectX::RootSignature &Data)
- : Size(Data.getSize()) {
+ : Version(Data.getVersion()), NumParameters(Data.getNumParameters()),
+ RootParametersOffset(Data.getRootParametersOffset()),
+ NumStaticSamplers(Data.getNumStaticSamplers()),
+ StaticSamplersOffset(Data.getStaticSamplersOffset()) {
uint32_t Flags = Data.getFlags();
#define ROOT_ELEMENT_FLAG(Num, Val, Str) \
Val = (Flags & (uint32_t)dxbc::RootElementFlag::Val) > 0;
@@ -209,7 +212,11 @@ void MappingTraits<DXContainerYAML::Signature>::mapping(
void MappingTraits<DXContainerYAML::RootSignatureDesc>::mapping(
IO &IO, DXContainerYAML::RootSignatureDesc &S) {
- IO.mapRequired("Size", S.Size);
+ IO.mapRequired("Version", S.Version);
+ IO.mapRequired("NumParameters", S.NumParameters);
+ IO.mapRequired("RootParametersOffset", S.RootParametersOffset);
+ IO.mapRequired("NumStaticSamplers", S.NumStaticSamplers);
+ IO.mapRequired("StaticSamplersOffset", S.StaticSamplersOffset);
#define ROOT_ELEMENT_FLAG(Num, Val, Str) IO.mapOptional(#Val, S.Val, false);
#include "llvm/BinaryFormat/DXContainerConstants.def"
}
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
index e3ca7347d52c7cb..06814f660f28345 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
@@ -11,13 +11,21 @@ Header:
PartOffsets: [ 60 ]
Parts:
- Name: RTS0
- Size: 8
+ Size: 24
RootSignature:
- Size: 8
+ Version: 2
+ NumParameters: 0
+ RootParametersOffset: 0
+ NumStaticSamplers: 0
+ StaticSamplersOffset: 0
AllowInputAssemblerInputLayout: true
-#CHECK: - Name: RTS0
-#CHECK-NEXT: Size: 8
-#CHECK-NEXT: RootSignature:
-#CHECK-NEXT: Size: 8
-#CHECK-NEXT: AllowInputAssemblerInputLayout: true
+# CHECK: - Name: RTS0
+# CHECK-NEXT: Size: 24
+# CHECK-NEXT: RootSignature:
+# CHECK-NEXT: Version: 2
+# CHECK-NEXT: NumParameters: 0
+# CHECK-NEXT: RootParametersOffset: 0
+# CHECK-NEXT: NumStaticSamplers: 0
+# CHECK-NEXT: StaticSamplersOffset: 0
+# CHECK-NEXT: AllowInputAssemblerInputLayout: true
diff --git a/llvm/test/tools/dxil-dis/root-signature.yaml b/llvm/test/tools/dxil-dis/root-signature.yaml
deleted file mode 100644
index 2a11dd9b3fcee22..000000000000000
--- a/llvm/test/tools/dxil-dis/root-signature.yaml
+++ /dev/null
@@ -1,201 +0,0 @@
-# RUN: yaml2obj %s | dxil-dis | FileCheck %s
-
---- !dxcontainer
-Header:
- Hash: [ 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
- 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
- Version:
- Major: 1
- Minor: 0
- PartCount: 2
- PartOffsets: [ 60, 1496 ]
-Parts:
- - Name: DXIL
- Size: 1428
- Program:
- MajorVersion: 6
- MinorVersion: 0
- ShaderKind: 5
- Size: 357
- DXILMajorVersion: 1
- DXILMinorVersion: 0
- DXILSize: 1404
- DXIL: [ 0x42, 0x43, 0xC0, 0xDE, 0x21, 0xC, 0x0, 0x0, 0x5C,
- 0x1, 0x0, 0x0, 0xB, 0x82, 0x20, 0x0, 0x2, 0x0,
- 0x0, 0x0, 0x13, 0x0, 0x0, 0x0, 0x7, 0x81, 0x23,
- 0x91, 0x41, 0xC8, 0x4, 0x49, 0x6, 0x10, 0x32,
- 0x39, 0x92, 0x1, 0x84, 0xC, 0x25, 0x5, 0x8, 0x19,
- 0x1E, 0x4, 0x8B, 0x62, 0x80, 0x10, 0x45, 0x2,
- 0x42, 0x92, 0xB, 0x42, 0x84, 0x10, 0x32, 0x14,
- 0x38, 0x8, 0x18, 0x4B, 0xA, 0x32, 0x42, 0x88,
- 0x48, 0x90, 0x14, 0x20, 0x43, 0x46, 0x88, 0xA5,
- 0x0, 0x19, 0x32, 0x42, 0xE4, 0x48, 0xE, 0x90,
- 0x11, 0x22, 0xC4, 0x50, 0x41, 0x51, 0x81, 0x8C,
- 0xE1, 0x83, 0xE5, 0x8A, 0x4, 0x21, 0x46, 0x6,
- 0x89, 0x20, 0x0, 0x0, 0x11, 0x0, 0x0, 0x0, 0x32,
- 0x22, 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 0x50, 0x10, 0xCD, 0x14, 0x61, 0x0,
- 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 ]
- - Name: RTS0
- Size: 8
- RootSignature:
- Size: 8
- AllowInputAssemblerInputLayout: true
-
-# CHECK: !dx.rootsignatures = !{[[RS:![0-9]+]]}
-# CHECK: [[RS]] = !{void ()* @main, [[REL:![0-9]+]]}
-# CHECK: [[REL]] = !{[[RF:![0-9]+]]}
-# CHECK: [[RF]] = !{!"RootFlags", i32 1}
diff --git a/llvm/unittests/Object/DXContainerTest.cpp b/llvm/unittests/Object/DXContainerTest.cpp
index 5a2c852d6aef976..f80828f06bdd255 100644
--- a/llvm/unittests/Object/DXContainerTest.cpp
+++ b/llvm/unittests/Object/DXContainerTest.cpp
@@ -821,3 +821,25 @@ TEST(DXCFile, MalformedSignature) {
"the end of the part data"));
}
}
+
+TEST(RootSignature, ParseRootFlags) {
+ uint8_t Buffer[] = {
+ 0x44, 0x58, 0x42, 0x43, 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35, 0x6F,
+ 0x05, 0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1, 0x01, 0x00, 0x00, 0x00,
+ 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
+ 0x52, 0x54, 0x53, 0x30, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+ };
+ DXContainer C =
+ llvm::cantFail(DXContainer::create(getMemoryBuffer<180>(Buffer)));
+
+ const auto &RS = C.getRootSignature();
+ ASSERT_TRUE(RS.has_value());
+ ASSERT_EQ(RS->getVersion(), 2);
+ ASSERT_EQ(RS->getNumParameters(), 0);
+ ASSERT_EQ(RS->getRootParametersOffset(), 0);
+ ASSERT_EQ(RS->getNumStaticSamplers(), 0);
+ ASSERT_EQ(RS->getStaticSamplersOffset(), 0);
+ ASSERT_EQ(RS->getFlags(), 0x01);
+}
diff --git a/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp b/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
index d4232295c8584ad..b18075bac96c79c 100644
--- a/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
+++ b/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
@@ -15,6 +15,7 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
+#include <cstdint>
using namespace llvm;
using namespace llvm::object;
@@ -107,3 +108,42 @@ TEST(DXCFile, ParseEmptyParts) {
EXPECT_EQ(Storage.size(), 116u);
EXPECT_TRUE(memcmp(Buffer, Storage.data(), 116) == 0);
}
+
+TEST(RootSignature, ParseRootFlags) {
+ SmallString<128> Storage;
+
+ // First read a fully explicit yaml with all sizes and offsets provided
+ ASSERT_TRUE(convert(Storage, R"(--- !dxcontainer
+ Header:
+ Hash: [ 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35, 0x6F, 0x5,
+ 0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1 ]
+ Version:
+ Major: 1
+ Minor: 0
+ FileSize: 68
+ PartCount: 1
+ PartOffsets: [ 36 ]
+ Parts:
+ - Name: RTS0
+ Size: 24
+ RootSignature:
+ Version: 2
+ NumParameters: 0
+ RootParametersOffset: 24
+ NumStaticSamplers: 0
+ StaticSamplersOffset: 24
+ AllowInputAssemblerInputLayout: true
+ )"));
+
+ uint8_t Buffer[] = {
+ 0x44, 0x58, 0x42, 0x43, 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35, 0x6F,
+ 0x05, 0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1, 0x01, 0x00, 0x00, 0x00,
+ 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
+ 0x52, 0x54, 0x53, 0x30, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+ };
+
+ EXPECT_EQ(Storage.size(), 68u);
+ EXPECT_TRUE(memcmp(Buffer, Storage.data(), 68u) == 0);
+}
>From 25e3f374698f06f2966aa433728e45c73c790034 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Mon, 3 Feb 2025 21:11:48 +0000
Subject: [PATCH 21/50] clean up
---
llvm/test/tools/dxil-dis/lit.local.cfg | 2 +-
llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/test/tools/dxil-dis/lit.local.cfg b/llvm/test/tools/dxil-dis/lit.local.cfg
index 8fe45f696bff99d..7b6819e0b406ae3 100644
--- a/llvm/test/tools/dxil-dis/lit.local.cfg
+++ b/llvm/test/tools/dxil-dis/lit.local.cfg
@@ -1,3 +1,3 @@
if not config.dxil_tests:
config.unsupported = True
-config.suffixes = [".ll", ".yaml"]
+config.suffixes = [".ll"]
diff --git a/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp b/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
index b18075bac96c79c..eaa8049e8e7d908 100644
--- a/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
+++ b/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
@@ -15,7 +15,6 @@
#include "llvm/Support/raw_ostream.h"
#include "llvm/Testing/Support/Error.h"
#include "gtest/gtest.h"
-#include <cstdint>
using namespace llvm;
using namespace llvm::object;
>From 751cbdcc76b5f6874f76765ef5ccdaaf7c58c449 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Tue, 4 Feb 2025 07:20:03 +0000
Subject: [PATCH 22/50] addressing comments
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 2 +-
.../BinaryFormat/DXContainerConstants.def | 48 +++++--------------
.../include/llvm/ObjectYAML/DXContainerYAML.h | 5 +-
llvm/lib/ObjectYAML/DXContainerEmitter.cpp | 5 ++
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 6 +--
.../DXContainer/RootSignature-Flags.yaml | 18 +++----
.../ObjectYAML/DXContainerYAMLTest.cpp | 4 +-
7 files changed, 36 insertions(+), 52 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 71a6d15e46a81db..b47cd2b5facd0b7 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -162,7 +162,7 @@ enum class FeatureFlags : uint64_t {
static_assert((uint64_t)FeatureFlags::NextUnusedBit <= 1ull << 63,
"Shader flag bits exceed enum size.");
-#define ROOT_ELEMENT_FLAG(Num, Val, Str) Val = 1ull << Num,
+#define ROOT_ELEMENT_FLAG(Num, Val) Val = 1ull << Num,
enum class RootElementFlag : uint32_t {
#include "DXContainerConstants.def"
};
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index 2134c2375f6d35e..e82c68bc0bda8a0 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -53,44 +53,20 @@ SHADER_FEATURE_FLAG(31, 36, NextUnusedBit, "Next reserved shader flag bit (not a
#undef SHADER_FEATURE_FLAG
#endif // SHADER_FEATURE_FLAG
-#ifdef ROOT_PARAMETER
-
-ROOT_PARAMETER(DescriptorTable)
-ROOT_PARAMETER(Constants32Bit)
-ROOT_PARAMETER(CBV)
-ROOT_PARAMETER(SRV)
-ROOT_PARAMETER(UAV)
-#undef ROOT_PARAMETER
-#endif // ROOT_PARAMETER
-
-
-#ifdef SHADER_VISIBILITY
-
-SHADER_VISIBILITY(All)
-SHADER_VISIBILITY(Vertex)
-SHADER_VISIBILITY(Hull)
-SHADER_VISIBILITY(Domain)
-SHADER_VISIBILITY(Geometry)
-SHADER_VISIBILITY(Pixel)
-SHADER_VISIBILITY(Amplification)
-SHADER_VISIBILITY(Mesh)
-#undef SHADER_VISIBILITY
-#endif // SHADER_VISIBILITY
-
#ifdef ROOT_ELEMENT_FLAG
-ROOT_ELEMENT_FLAG(0, AllowInputAssemblerInputLayout, "The app is opting in to using the Input Assembler")
-ROOT_ELEMENT_FLAG(1, DenyVertexShaderRootAccess, "Denies the vertex shader access to the root signature.")
-ROOT_ELEMENT_FLAG(2, DenyHullShaderRootAccess, "Denies the hull shader access to the root signature.")
-ROOT_ELEMENT_FLAG(3, DenyDomainShaderRootAccess, "Denies the domain shader access to the root signature.")
-ROOT_ELEMENT_FLAG(4, DenyGeometryShaderRootAccess, "Denies the geometry shader access to the root signature.")
-ROOT_ELEMENT_FLAG(5, DenyPixelShaderRootAccess, "Denies the pixel shader access to the root signature.")
-ROOT_ELEMENT_FLAG(6, AllowStreamOutput, "The app is opting in to using Stream Output.")
-ROOT_ELEMENT_FLAG(7, LocalRootSignature, "The root signature is to be used with raytracing shaders to define resource bindings sourced from shader records in shader tables.")
-ROOT_ELEMENT_FLAG(8, DenyAmplificationShaderRootAccess, "Denies the amplification shader access to the root signature.")
-ROOT_ELEMENT_FLAG(9, DenyMeshShaderRootAccess, "Denies the mesh shader access to the root signature.")
-ROOT_ELEMENT_FLAG(10, CBVSRVUAVHeapDirectlyIndexed, "The shaders are allowed to index the CBV/SRV/UAV descriptor heap directly, using the ResourceDescriptorHeap built-in variable.")
-ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed, "The shaders are allowed to index the sampler descriptor heap directly, using the SamplerDescriptorHeap built-in variable.")
+ROOT_ELEMENT_FLAG(0, AllowInputAssemblerInputLayout)
+ROOT_ELEMENT_FLAG(1, DenyVertexShaderRootAccess)
+ROOT_ELEMENT_FLAG(2, DenyHullShaderRootAccess)
+ROOT_ELEMENT_FLAG(3, DenyDomainShaderRootAccess)
+ROOT_ELEMENT_FLAG(4, DenyGeometryShaderRootAccess)
+ROOT_ELEMENT_FLAG(5, DenyPixelShaderRootAccess)
+ROOT_ELEMENT_FLAG(6, AllowStreamOutput)
+ROOT_ELEMENT_FLAG(7, LocalRootSignature)
+ROOT_ELEMENT_FLAG(8, DenyAmplificationShaderRootAccess)
+ROOT_ELEMENT_FLAG(9, DenyMeshShaderRootAccess)
+ROOT_ELEMENT_FLAG(10, CBVSRVUAVHeapDirectlyIndexed)
+ROOT_ELEMENT_FLAG(11, SamplerHeapDirectlyIndexed)
#undef ROOT_ELEMENT_FLAG
#endif // ROOT_ELEMENT_FLAG
diff --git a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
index 1f967114ea1eb84..0200f5cb196ff08 100644
--- a/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
+++ b/llvm/include/llvm/ObjectYAML/DXContainerYAML.h
@@ -73,18 +73,19 @@ struct ShaderHash {
std::vector<llvm::yaml::Hex8> Digest;
};
-#define ROOT_ELEMENT_FLAG(Num, Val, Str) bool Val = false;
+#define ROOT_ELEMENT_FLAG(Num, Val) bool Val = false;
struct RootSignatureDesc {
RootSignatureDesc() = default;
RootSignatureDesc(const object::DirectX::RootSignature &Data);
- uint32_t getEncodedFlags();
uint32_t Version;
uint32_t NumParameters;
uint32_t RootParametersOffset;
uint32_t NumStaticSamplers;
uint32_t StaticSamplersOffset;
+ uint32_t getEncodedFlags();
+
#include "llvm/BinaryFormat/DXContainerConstants.def"
};
diff --git a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
index ada7383ea3c6b8f..b7d1c6558fa1fd7 100644
--- a/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerEmitter.cpp
@@ -268,6 +268,11 @@ void DXContainerWriter::writeParts(raw_ostream &OS) {
mcdxbc::RootSignatureHeader Header;
Header.Flags = P.RootSignature->getEncodedFlags();
+ Header.Version = P.RootSignature->Version;
+ Header.NumParameters = P.RootSignature->NumParameters;
+ Header.RootParametersOffset = P.RootSignature->RootParametersOffset;
+ Header.NumStaticSamplers = P.RootSignature->NumStaticSamplers;
+ Header.StaticSamplersOffset = P.RootSignature->StaticSamplersOffset;
Header.write(OS);
break;
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 522781c0d36ef8b..fdf87b05d1f43df 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -37,14 +37,14 @@ DXContainerYAML::RootSignatureDesc::RootSignatureDesc(
NumStaticSamplers(Data.getNumStaticSamplers()),
StaticSamplersOffset(Data.getStaticSamplersOffset()) {
uint32_t Flags = Data.getFlags();
-#define ROOT_ELEMENT_FLAG(Num, Val, Str) \
+#define ROOT_ELEMENT_FLAG(Num, Val) \
Val = (Flags & (uint32_t)dxbc::RootElementFlag::Val) > 0;
#include "llvm/BinaryFormat/DXContainerConstants.def"
}
uint32_t DXContainerYAML::RootSignatureDesc::getEncodedFlags() {
uint64_t Flag = 0;
-#define ROOT_ELEMENT_FLAG(Num, Val, Str) \
+#define ROOT_ELEMENT_FLAG(Num, Val) \
if (Val) \
Flag |= (uint32_t)dxbc::RootElementFlag::Val;
#include "llvm/BinaryFormat/DXContainerConstants.def"
@@ -217,7 +217,7 @@ void MappingTraits<DXContainerYAML::RootSignatureDesc>::mapping(
IO.mapRequired("RootParametersOffset", S.RootParametersOffset);
IO.mapRequired("NumStaticSamplers", S.NumStaticSamplers);
IO.mapRequired("StaticSamplersOffset", S.StaticSamplersOffset);
-#define ROOT_ELEMENT_FLAG(Num, Val, Str) IO.mapOptional(#Val, S.Val, false);
+#define ROOT_ELEMENT_FLAG(Num, Val) IO.mapOptional(#Val, S.Val, false);
#include "llvm/BinaryFormat/DXContainerConstants.def"
}
diff --git a/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
index 06814f660f28345..b0a3e6945f454bc 100644
--- a/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
+++ b/llvm/test/ObjectYAML/DXContainer/RootSignature-Flags.yaml
@@ -14,18 +14,20 @@ Parts:
Size: 24
RootSignature:
Version: 2
- NumParameters: 0
- RootParametersOffset: 0
- NumStaticSamplers: 0
- StaticSamplersOffset: 0
+ NumParameters: 1
+ RootParametersOffset: 3
+ NumStaticSamplers: 4
+ StaticSamplersOffset: 5
AllowInputAssemblerInputLayout: true
+ DenyGeometryShaderRootAccess: true
# CHECK: - Name: RTS0
# CHECK-NEXT: Size: 24
# CHECK-NEXT: RootSignature:
# CHECK-NEXT: Version: 2
-# CHECK-NEXT: NumParameters: 0
-# CHECK-NEXT: RootParametersOffset: 0
-# CHECK-NEXT: NumStaticSamplers: 0
-# CHECK-NEXT: StaticSamplersOffset: 0
+# CHECK-NEXT: NumParameters: 1
+# CHECK-NEXT: RootParametersOffset: 3
+# CHECK-NEXT: NumStaticSamplers: 4
+# CHECK-NEXT: StaticSamplersOffset: 5
# CHECK-NEXT: AllowInputAssemblerInputLayout: true
+# CHECK-NEXT: DenyGeometryShaderRootAccess: true
diff --git a/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp b/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
index eaa8049e8e7d908..b48cd9ce5398731 100644
--- a/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
+++ b/llvm/unittests/ObjectYAML/DXContainerYAMLTest.cpp
@@ -128,9 +128,9 @@ TEST(RootSignature, ParseRootFlags) {
RootSignature:
Version: 2
NumParameters: 0
- RootParametersOffset: 24
+ RootParametersOffset: 0
NumStaticSamplers: 0
- StaticSamplersOffset: 24
+ StaticSamplersOffset: 0
AllowInputAssemblerInputLayout: true
)"));
>From 44532d6517e2664221104653482101f167aafd62 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Tue, 4 Feb 2025 19:19:36 +0000
Subject: [PATCH 23/50] adding fail test
---
llvm/include/llvm/Object/DXContainer.h | 5 +--
llvm/lib/Object/DXContainer.cpp | 12 ++++--
llvm/unittests/Object/DXContainerTest.cpp | 51 +++++++++++++++--------
3 files changed, 44 insertions(+), 24 deletions(-)
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index 47128f94e0968e1..c3a2f756bd683fd 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -119,7 +119,6 @@ namespace DirectX {
class RootSignature {
private:
- StringRef Data;
uint32_t Version;
uint32_t NumParameters;
uint32_t RootParametersOffset;
@@ -128,9 +127,9 @@ class RootSignature {
uint32_t Flags;
public:
- RootSignature(StringRef Data) : Data(Data) {}
+ RootSignature() {}
- Error parse();
+ Error parse(StringRef Data);
uint32_t getVersion() const { return Version; }
uint32_t getNumParameters() const { return NumParameters; }
uint32_t getRootParametersOffset() const { return RootParametersOffset; }
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index 14179283f98078d..91391b5144290f8 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -7,6 +7,7 @@
//===----------------------------------------------------------------------===//
#include "llvm/Object/DXContainer.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/Error.h"
#include "llvm/Support/Alignment.h"
@@ -96,8 +97,8 @@ Error DXContainer::parseHash(StringRef Part) {
Error DXContainer::parseRootSignature(StringRef Part) {
if (RootSignature)
return parseFailed("More than one RTS0 part is present in the file");
- RootSignature = DirectX::RootSignature(Part);
- if (Error Err = RootSignature->parse())
+ RootSignature = DirectX::RootSignature();
+ if (Error Err = RootSignature->parse(Part))
return Err;
return Error::success();
}
@@ -242,9 +243,14 @@ void DXContainer::PartIterator::updateIteratorImpl(const uint32_t Offset) {
IteratorState.Offset = Offset;
}
-Error DirectX::RootSignature::parse() {
+Error DirectX::RootSignature::parse(StringRef Data) {
const char *Current = Data.begin();
+ // Root Signature headers expects 6 integers to be present.
+ if (Data.size() < 6 * sizeof(uint32_t)) {
+ return parseFailed("Invalid data. Too small.");
+ }
+
Version = support::endian::read<uint32_t, llvm::endianness::little>(Current);
Current += sizeof(uint32_t);
diff --git a/llvm/unittests/Object/DXContainerTest.cpp b/llvm/unittests/Object/DXContainerTest.cpp
index f80828f06bdd255..bff58c036489f05 100644
--- a/llvm/unittests/Object/DXContainerTest.cpp
+++ b/llvm/unittests/Object/DXContainerTest.cpp
@@ -823,23 +823,38 @@ TEST(DXCFile, MalformedSignature) {
}
TEST(RootSignature, ParseRootFlags) {
- uint8_t Buffer[] = {
- 0x44, 0x58, 0x42, 0x43, 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35, 0x6F,
- 0x05, 0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1, 0x01, 0x00, 0x00, 0x00,
- 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
- 0x52, 0x54, 0x53, 0x30, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
- };
- DXContainer C =
- llvm::cantFail(DXContainer::create(getMemoryBuffer<180>(Buffer)));
+ {
+ uint8_t Buffer[] = {
+ 0x44, 0x58, 0x42, 0x43, 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35, 0x6F,
+ 0x05, 0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1, 0x01, 0x00, 0x00, 0x00,
+ 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
+ 0x52, 0x54, 0x53, 0x30, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+ };
+ DXContainer C =
+ llvm::cantFail(DXContainer::create(getMemoryBuffer<180>(Buffer)));
+
+ const auto &RS = C.getRootSignature();
+ ASSERT_TRUE(RS.has_value());
+ ASSERT_EQ(RS->getVersion(), 2);
+ ASSERT_EQ(RS->getNumParameters(), 0);
+ ASSERT_EQ(RS->getRootParametersOffset(), 0);
+ ASSERT_EQ(RS->getNumStaticSamplers(), 0);
+ ASSERT_EQ(RS->getStaticSamplersOffset(), 0);
+ ASSERT_EQ(RS->getFlags(), 0x01);
+ }
- const auto &RS = C.getRootSignature();
- ASSERT_TRUE(RS.has_value());
- ASSERT_EQ(RS->getVersion(), 2);
- ASSERT_EQ(RS->getNumParameters(), 0);
- ASSERT_EQ(RS->getRootParametersOffset(), 0);
- ASSERT_EQ(RS->getNumStaticSamplers(), 0);
- ASSERT_EQ(RS->getStaticSamplersOffset(), 0);
- ASSERT_EQ(RS->getFlags(), 0x01);
+ {
+ uint8_t Buffer[] = {
+ 0x44, 0x58, 0x42, 0x43, 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35,
+ 0x6F, 0x05, 0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1, 0x01, 0x00,
+ 0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24,
+ 0x00, 0x00, 0x00, 0x52, 0x54, 0x53, 0x30, 0x18, 0x00, 0x00, 0x00,
+ 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ };
+ EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<44>(Buffer)),
+ FailedWithMessage("Invalid data. Too small."));
+ }
}
>From ca21878831fe70976e4eeeec60e7a5300c2e1235 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Tue, 4 Feb 2025 19:26:29 +0000
Subject: [PATCH 24/50] adding comment
---
llvm/include/llvm/BinaryFormat/DXContainerConstants.def | 2 ++
llvm/unittests/Object/DXContainerTest.cpp | 1 +
2 files changed, 3 insertions(+)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index e82c68bc0bda8a0..39a0e7a5c849322 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -53,6 +53,8 @@ SHADER_FEATURE_FLAG(31, 36, NextUnusedBit, "Next reserved shader flag bit (not a
#undef SHADER_FEATURE_FLAG
#endif // SHADER_FEATURE_FLAG
+
+// ROOT_ELEMENT_FLAG(bit offset for the flag, name).
#ifdef ROOT_ELEMENT_FLAG
ROOT_ELEMENT_FLAG(0, AllowInputAssemblerInputLayout)
diff --git a/llvm/unittests/Object/DXContainerTest.cpp b/llvm/unittests/Object/DXContainerTest.cpp
index bff58c036489f05..8e20ae552c06215 100644
--- a/llvm/unittests/Object/DXContainerTest.cpp
+++ b/llvm/unittests/Object/DXContainerTest.cpp
@@ -846,6 +846,7 @@ TEST(RootSignature, ParseRootFlags) {
}
{
+ // this parameter has the root signature definition missing some values.
uint8_t Buffer[] = {
0x44, 0x58, 0x42, 0x43, 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35,
0x6F, 0x05, 0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1, 0x01, 0x00,
>From 987901c6a74757e09345eeae172a1f4d23a39e0a Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Tue, 4 Feb 2025 23:24:59 +0000
Subject: [PATCH 25/50] adding few more tests
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 27 ++++++++++++------
llvm/include/llvm/Object/DXContainer.h | 1 +
llvm/lib/Object/DXContainer.cpp | 17 +++++++++--
llvm/unittests/Object/DXContainerTest.cpp | 30 ++++++++++++++++++--
4 files changed, 62 insertions(+), 13 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index b47cd2b5facd0b7..4f48d0c41cf76bb 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -14,9 +14,12 @@
#define LLVM_BINARYFORMAT_DXCONTAINER_H
#include "llvm/ADT/StringRef.h"
+#include "llvm/Object/Error.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/SwapByteOrder.h"
#include "llvm/TargetParser/Triple.h"
+#include <cstdint>
#include <stdint.h>
namespace llvm {
@@ -63,15 +66,6 @@ struct ShaderHash {
void swapBytes() { sys::swapByteOrder(Flags); }
};
-struct RootSignatureDesc {
- uint32_t Size;
- uint32_t Flags;
-
- void swapBytes() {
- sys::swapByteOrder(Size);
- sys::swapByteOrder(Flags);
- }
-};
struct ContainerVersion {
uint16_t Major;
@@ -556,6 +550,21 @@ struct ProgramSignatureElement {
static_assert(sizeof(ProgramSignatureElement) == 32,
"ProgramSignatureElement is misaligned");
+struct RootSignatureValidations {
+
+ static Expected<uint32_t> validateRootFlag(uint32_t Flags) {
+ if ((Flags & ~0x80000fff) != 0)
+ return llvm::make_error<object::GenericBinaryError>("Invalid flag");
+ return Flags;
+ }
+
+ static Expected<uint32_t> validateVersion(uint32_t Version) {
+ if (Version < 1 || Version > 2)
+ return llvm::make_error<object::GenericBinaryError>("Invalid Version");
+ return Version;
+ }
+};
+
} // namespace dxbc
} // namespace llvm
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index c3a2f756bd683fd..e90c6866400e028 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -18,6 +18,7 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/DXContainer.h"
+#include "llvm/Object/Error.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBufferRef.h"
#include "llvm/TargetParser/Triple.h"
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index 91391b5144290f8..a9fbae89820244e 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -12,7 +12,9 @@
#include "llvm/Object/Error.h"
#include "llvm/Support/Alignment.h"
#include "llvm/Support/Endian.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
+#include <cstdint>
using namespace llvm;
using namespace llvm::object;
@@ -246,14 +248,20 @@ void DXContainer::PartIterator::updateIteratorImpl(const uint32_t Offset) {
Error DirectX::RootSignature::parse(StringRef Data) {
const char *Current = Data.begin();
+
// Root Signature headers expects 6 integers to be present.
if (Data.size() < 6 * sizeof(uint32_t)) {
return parseFailed("Invalid data. Too small.");
}
- Version = support::endian::read<uint32_t, llvm::endianness::little>(Current);
+ uint32_t VValue = support::endian::read<uint32_t, llvm::endianness::little>(Current);
Current += sizeof(uint32_t);
+ Expected<uint32_t> MaybeVersion = dxbc::RootSignatureValidations::validateVersion(VValue);
+ if(Error E = MaybeVersion.takeError())
+ return E;
+ Version = MaybeVersion.get();
+
NumParameters =
support::endian::read<uint32_t, llvm::endianness::little>(Current);
Current += sizeof(uint32_t);
@@ -270,9 +278,14 @@ Error DirectX::RootSignature::parse(StringRef Data) {
support::endian::read<uint32_t, llvm::endianness::little>(Current);
Current += sizeof(uint32_t);
- Flags = support::endian::read<uint32_t, llvm::endianness::little>(Current);
+ uint32_t FValue = support::endian::read<uint32_t, llvm::endianness::little>(Current);
Current += sizeof(uint32_t);
+ Expected<uint32_t> MaybeFlag = dxbc::RootSignatureValidations::validateRootFlag(FValue);
+ if(Error E = MaybeFlag.takeError())
+ return E;
+ Flags = MaybeFlag.get();
+
return Error::success();
}
diff --git a/llvm/unittests/Object/DXContainerTest.cpp b/llvm/unittests/Object/DXContainerTest.cpp
index 8e20ae552c06215..1433d5e7f2f081d 100644
--- a/llvm/unittests/Object/DXContainerTest.cpp
+++ b/llvm/unittests/Object/DXContainerTest.cpp
@@ -833,7 +833,7 @@ TEST(RootSignature, ParseRootFlags) {
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
};
DXContainer C =
- llvm::cantFail(DXContainer::create(getMemoryBuffer<180>(Buffer)));
+ llvm::cantFail(DXContainer::create(getMemoryBuffer<68>(Buffer)));
const auto &RS = C.getRootSignature();
ASSERT_TRUE(RS.has_value());
@@ -855,7 +855,33 @@ TEST(RootSignature, ParseRootFlags) {
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
- EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<44>(Buffer)),
+ EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<64>(Buffer)),
FailedWithMessage("Invalid data. Too small."));
}
+ {
+ // Version has been changed to an invalid number.
+ uint8_t Buffer[] = {
+ 0x44, 0x58, 0x42, 0x43, 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35, 0x6F,
+ 0x05, 0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1, 0x01, 0x00, 0x00, 0x00,
+ 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
+ 0x52, 0x54, 0x53, 0x30, 0x18, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
+ };
+ EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<68>(Buffer)),
+ FailedWithMessage("Invalid Version"));
+ }
+ {
+ // Flag has been set to an invalid value
+ uint8_t Buffer[] = {
+ 0x44, 0x58, 0x42, 0x43, 0x32, 0x9A, 0x53, 0xD8, 0xEC, 0xBE, 0x35, 0x6F,
+ 0x05, 0x39, 0xE1, 0xFE, 0x31, 0x20, 0xF0, 0xC1, 0x01, 0x00, 0x00, 0x00,
+ 0x44, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00,
+ 0x52, 0x54, 0x53, 0x30, 0x18, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xFF,
+ };
+ EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<68>(Buffer)),
+ FailedWithMessage("Invalid flag"));
+ }
}
>From 0fbe900a6d0d431c9267513901c90cd778ac61ed Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Tue, 4 Feb 2025 23:29:02 +0000
Subject: [PATCH 26/50] format
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 21 ++++++++++----------
llvm/lib/Object/DXContainer.cpp | 17 +++++++++-------
llvm/unittests/Object/DXContainerTest.cpp | 4 ++--
3 files changed, 22 insertions(+), 20 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 4f48d0c41cf76bb..0d5caabd3471e9d 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -66,7 +66,6 @@ struct ShaderHash {
void swapBytes() { sys::swapByteOrder(Flags); }
};
-
struct ContainerVersion {
uint16_t Major;
uint16_t Minor;
@@ -552,17 +551,17 @@ static_assert(sizeof(ProgramSignatureElement) == 32,
struct RootSignatureValidations {
- static Expected<uint32_t> validateRootFlag(uint32_t Flags) {
- if ((Flags & ~0x80000fff) != 0)
- return llvm::make_error<object::GenericBinaryError>("Invalid flag");
- return Flags;
- }
+ static Expected<uint32_t> validateRootFlag(uint32_t Flags) {
+ if ((Flags & ~0x80000fff) != 0)
+ return llvm::make_error<object::GenericBinaryError>("Invalid flag");
+ return Flags;
+ }
- static Expected<uint32_t> validateVersion(uint32_t Version) {
- if (Version < 1 || Version > 2)
- return llvm::make_error<object::GenericBinaryError>("Invalid Version");
- return Version;
- }
+ static Expected<uint32_t> validateVersion(uint32_t Version) {
+ if (Version < 1 || Version > 2)
+ return llvm::make_error<object::GenericBinaryError>("Invalid Version");
+ return Version;
+ }
};
} // namespace dxbc
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index a9fbae89820244e..e4faed38c3e0af8 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -248,17 +248,18 @@ void DXContainer::PartIterator::updateIteratorImpl(const uint32_t Offset) {
Error DirectX::RootSignature::parse(StringRef Data) {
const char *Current = Data.begin();
-
// Root Signature headers expects 6 integers to be present.
if (Data.size() < 6 * sizeof(uint32_t)) {
return parseFailed("Invalid data. Too small.");
}
- uint32_t VValue = support::endian::read<uint32_t, llvm::endianness::little>(Current);
+ uint32_t VValue =
+ support::endian::read<uint32_t, llvm::endianness::little>(Current);
Current += sizeof(uint32_t);
- Expected<uint32_t> MaybeVersion = dxbc::RootSignatureValidations::validateVersion(VValue);
- if(Error E = MaybeVersion.takeError())
+ Expected<uint32_t> MaybeVersion =
+ dxbc::RootSignatureValidations::validateVersion(VValue);
+ if (Error E = MaybeVersion.takeError())
return E;
Version = MaybeVersion.get();
@@ -278,11 +279,13 @@ Error DirectX::RootSignature::parse(StringRef Data) {
support::endian::read<uint32_t, llvm::endianness::little>(Current);
Current += sizeof(uint32_t);
- uint32_t FValue = support::endian::read<uint32_t, llvm::endianness::little>(Current);
+ uint32_t FValue =
+ support::endian::read<uint32_t, llvm::endianness::little>(Current);
Current += sizeof(uint32_t);
- Expected<uint32_t> MaybeFlag = dxbc::RootSignatureValidations::validateRootFlag(FValue);
- if(Error E = MaybeFlag.takeError())
+ Expected<uint32_t> MaybeFlag =
+ dxbc::RootSignatureValidations::validateRootFlag(FValue);
+ if (Error E = MaybeFlag.takeError())
return E;
Flags = MaybeFlag.get();
diff --git a/llvm/unittests/Object/DXContainerTest.cpp b/llvm/unittests/Object/DXContainerTest.cpp
index 1433d5e7f2f081d..8489b05f8b33132 100644
--- a/llvm/unittests/Object/DXContainerTest.cpp
+++ b/llvm/unittests/Object/DXContainerTest.cpp
@@ -868,7 +868,7 @@ TEST(RootSignature, ParseRootFlags) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
};
- EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<68>(Buffer)),
+ EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<68>(Buffer)),
FailedWithMessage("Invalid Version"));
}
{
@@ -881,7 +881,7 @@ TEST(RootSignature, ParseRootFlags) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xFF,
};
- EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<68>(Buffer)),
+ EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<68>(Buffer)),
FailedWithMessage("Invalid flag"));
}
}
>From b771aeac329152334ec10a0435b4f3e448ef934e Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Wed, 5 Feb 2025 20:21:43 +0000
Subject: [PATCH 27/50] cleanup
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 7 +++----
llvm/include/llvm/Object/DXContainer.h | 1 -
llvm/lib/Object/DXContainer.cpp | 3 ---
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 1 -
4 files changed, 3 insertions(+), 9 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index 0d5caabd3471e9d..c219aa819795e83 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -14,12 +14,11 @@
#define LLVM_BINARYFORMAT_DXCONTAINER_H
#include "llvm/ADT/StringRef.h"
-#include "llvm/Object/Error.h"
+#include "llvm/Support/BinaryStreamError.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/SwapByteOrder.h"
#include "llvm/TargetParser/Triple.h"
-#include <cstdint>
#include <stdint.h>
namespace llvm {
@@ -553,13 +552,13 @@ struct RootSignatureValidations {
static Expected<uint32_t> validateRootFlag(uint32_t Flags) {
if ((Flags & ~0x80000fff) != 0)
- return llvm::make_error<object::GenericBinaryError>("Invalid flag");
+ return llvm::make_error<BinaryStreamError>("Invalid flag");
return Flags;
}
static Expected<uint32_t> validateVersion(uint32_t Version) {
if (Version < 1 || Version > 2)
- return llvm::make_error<object::GenericBinaryError>("Invalid Version");
+ return llvm::make_error<BinaryStreamError>("Invalid Version");
return Version;
}
};
diff --git a/llvm/include/llvm/Object/DXContainer.h b/llvm/include/llvm/Object/DXContainer.h
index e90c6866400e028..c3a2f756bd683fd 100644
--- a/llvm/include/llvm/Object/DXContainer.h
+++ b/llvm/include/llvm/Object/DXContainer.h
@@ -18,7 +18,6 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/DXContainer.h"
-#include "llvm/Object/Error.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBufferRef.h"
#include "llvm/TargetParser/Triple.h"
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index e4faed38c3e0af8..4a5f58180804512 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -7,14 +7,11 @@
//===----------------------------------------------------------------------===//
#include "llvm/Object/DXContainer.h"
-#include "llvm/ADT/StringRef.h"
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Object/Error.h"
#include "llvm/Support/Alignment.h"
#include "llvm/Support/Endian.h"
-#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
-#include <cstdint>
using namespace llvm;
using namespace llvm::object;
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index fdf87b05d1f43df..0869fd4fa978587 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -14,7 +14,6 @@
#include "llvm/ObjectYAML/DXContainerYAML.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/BinaryFormat/DXContainer.h"
-#include "llvm/Object/DXContainer.h"
#include "llvm/Support/ScopedPrinter.h"
namespace llvm {
>From aabdfe7d6c6b6e27e9c2150c10199baa6638b6df Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Wed, 15 Jan 2025 17:30:00 +0000
Subject: [PATCH 28/50] adding metadata extraction
---
.../llvm/Analysis/DXILMetadataAnalysis.h | 3 +
llvm/lib/Analysis/DXILMetadataAnalysis.cpp | 89 +++++++++++++++++++
.../lib/Target/DirectX/DXContainerGlobals.cpp | 24 +++++
3 files changed, 116 insertions(+)
diff --git a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
index cb535ac14f1c613..f420244ba111a45 100644
--- a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
+++ b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
@@ -11,9 +11,11 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/PassManager.h"
+#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/Pass.h"
#include "llvm/Support/VersionTuple.h"
#include "llvm/TargetParser/Triple.h"
+#include <optional>
namespace llvm {
@@ -37,6 +39,7 @@ struct ModuleMetadataInfo {
Triple::EnvironmentType ShaderProfile{Triple::UnknownEnvironment};
VersionTuple ValidatorVersion{};
SmallVector<EntryProperties> EntryPropertyVec{};
+ std::optional<mcdxbc::RootSignatureDesc> RootSignatureDesc;
void print(raw_ostream &OS) const;
};
diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
index a7f666a3f8b48f2..388e3853008eaec 100644
--- a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -15,12 +15,91 @@
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/InitializePasses.h"
+#include "llvm/MC/DXContainerRootSignature.h"
+#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
+#include <memory>
#define DEBUG_TYPE "dxil-metadata-analysis"
using namespace llvm;
using namespace dxil;
+using namespace llvm::mcdxbc;
+
+static bool parseRootFlags(MDNode *RootFlagNode, RootSignatureDesc *Desc) {
+
+ assert(RootFlagNode->getNumOperands() == 2 &&
+ "Invalid format for RootFlag Element");
+ auto *Flag = mdconst::extract<ConstantInt>(RootFlagNode->getOperand(1));
+ auto Value = (RootSignatureFlags)Flag->getZExtValue();
+
+ if ((Value & ~RootSignatureFlags::ValidFlags) != RootSignatureFlags::None)
+ return true;
+
+ Desc->Flags = Value;
+ return false;
+}
+
+static bool parseRootSignatureElement(MDNode *Element,
+ RootSignatureDesc *Desc) {
+ MDString *ElementText = cast<MDString>(Element->getOperand(0));
+
+ assert(ElementText != nullptr && "First preoperty of element is not ");
+
+ RootSignatureElementKind ElementKind =
+ StringSwitch<RootSignatureElementKind>(ElementText->getString())
+ .Case("RootFlags", RootSignatureElementKind::RootFlags)
+ .Case("RootConstants", RootSignatureElementKind::RootConstants)
+ .Case("RootCBV", RootSignatureElementKind::RootDescriptor)
+ .Case("RootSRV", RootSignatureElementKind::RootDescriptor)
+ .Case("RootUAV", RootSignatureElementKind::RootDescriptor)
+ .Case("Sampler", RootSignatureElementKind::RootDescriptor)
+ .Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
+ .Case("StaticSampler", RootSignatureElementKind::StaticSampler)
+ .Default(RootSignatureElementKind::None);
+
+ switch (ElementKind) {
+
+ case RootSignatureElementKind::RootFlags: {
+ return parseRootFlags(Element, Desc);
+ break;
+ }
+
+ case RootSignatureElementKind::RootConstants:
+ case RootSignatureElementKind::RootDescriptor:
+ case RootSignatureElementKind::DescriptorTable:
+ case RootSignatureElementKind::StaticSampler:
+ case RootSignatureElementKind::None:
+ llvm_unreachable("Not Implemented yet");
+ break;
+ }
+
+ return true;
+}
+
+bool parseRootSignature(RootSignatureDesc *Desc, int32_t Version,
+ NamedMDNode *Root) {
+ Desc->Version = Version;
+ bool HasError = false;
+
+ for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
+ // This should be an if, for error handling
+ MDNode *Node = cast<MDNode>(Root->getOperand(Sid));
+
+ // Not sure what use this for...
+ Metadata *Func = Node->getOperand(0).get();
+
+ // This should be an if, for error handling
+ MDNode *Elements = cast<MDNode>(Node->getOperand(1).get());
+
+ for (unsigned int Eid = 0; Eid < Elements->getNumOperands(); Eid++) {
+ MDNode *Element = cast<MDNode>(Elements->getOperand(Eid));
+
+ HasError = HasError || parseRootSignatureElement(Element, Desc);
+ }
+ }
+ return HasError;
+}
static ModuleMetadataInfo collectMetadataInfo(Module &M) {
ModuleMetadataInfo MMDAI;
@@ -28,6 +107,7 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
MMDAI.DXILVersion = TT.getDXILVersion();
MMDAI.ShaderModelVersion = TT.getOSVersion();
MMDAI.ShaderProfile = TT.getEnvironment();
+
NamedMDNode *ValidatorVerNode = M.getNamedMetadata("dx.valver");
if (ValidatorVerNode) {
auto *ValVerMD = cast<MDNode>(ValidatorVerNode->getOperand(0));
@@ -37,6 +117,15 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
VersionTuple(MajorMD->getZExtValue(), MinorMD->getZExtValue());
}
+ NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
+ if (RootSignatureNode) {
+ mcdxbc::RootSignatureDesc Desc;
+
+ parseRootSignature(&Desc, 1, RootSignatureNode);
+
+ MMDAI.RootSignatureDesc = Desc;
+ }
+
// For all HLSL Shader functions
for (auto &F : M.functions()) {
if (!F.hasFnAttribute("hlsl.shader"))
diff --git a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
index 7a0bd6a7c886923..7ab11ce757e436c 100644
--- a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
+++ b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
@@ -23,9 +23,11 @@
#include "llvm/IR/Module.h"
#include "llvm/InitializePasses.h"
#include "llvm/MC/DXContainerPSVInfo.h"
+#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/Pass.h"
#include "llvm/Support/MD5.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
+#include <optional>
using namespace llvm;
using namespace llvm::dxil;
@@ -41,6 +43,7 @@ class DXContainerGlobals : public llvm::ModulePass {
GlobalVariable *buildSignature(Module &M, Signature &Sig, StringRef Name,
StringRef SectionName);
void addSignature(Module &M, SmallVector<GlobalValue *> &Globals);
+ void addRootSignature(Module &M, SmallVector<GlobalValue *> &Globals);
void addResourcesForPSV(Module &M, PSVRuntimeInfo &PSV);
void addPipelineStateValidationInfo(Module &M,
SmallVector<GlobalValue *> &Globals);
@@ -73,6 +76,7 @@ bool DXContainerGlobals::runOnModule(Module &M) {
Globals.push_back(getFeatureFlags(M));
Globals.push_back(computeShaderHash(M));
addSignature(M, Globals);
+ addRootSignature(M, Globals);
addPipelineStateValidationInfo(M, Globals);
appendToCompilerUsed(M, Globals);
return true;
@@ -144,6 +148,26 @@ void DXContainerGlobals::addSignature(Module &M,
Globals.emplace_back(buildSignature(M, OutputSig, "dx.osg1", "OSG1"));
}
+void DXContainerGlobals::addRootSignature(Module &M,
+ SmallVector<GlobalValue *> &Globals) {
+
+ std::optional<RootSignatureDesc> Desc =
+ getAnalysis<DXILMetadataAnalysisWrapperPass>()
+ .getModuleMetadata()
+ .RootSignatureDesc;
+ if (!Desc.has_value())
+ return;
+
+ SmallString<256> Data;
+ raw_svector_ostream OS(Data);
+ RootSignatureDescWriter writer(&Desc.value());
+ writer.write(OS);
+
+ Constant *Constant =
+ ConstantDataArray::getString(M.getContext(), Data, /*AddNull*/ false);
+ Globals.emplace_back(buildContainerGlobal(M, Constant, "dx.rts0", "RTS0"));
+}
+
void DXContainerGlobals::addResourcesForPSV(Module &M, PSVRuntimeInfo &PSV) {
const DXILBindingMap &DBM =
getAnalysis<DXILResourceBindingWrapperPass>().getBindingMap();
>From 4f6f941e3410e6aab982a73572d5ab2fa2cc1520 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 16 Jan 2025 00:36:11 +0000
Subject: [PATCH 29/50] moving root signature to it's own pass
---
.../llvm/Analysis/DXILMetadataAnalysis.h | 2 -
llvm/lib/Analysis/DXILMetadataAnalysis.cpp | 84 ----------
llvm/lib/MC/CMakeLists.txt | 1 -
llvm/lib/Target/DirectX/CMakeLists.txt | 2 +-
.../lib/Target/DirectX/DXContainerGlobals.cpp | 15 +-
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 146 ++++++++++++++++++
llvm/lib/Target/DirectX/DXILRootSignature.h | 75 +++++++++
llvm/lib/Target/DirectX/DirectX.h | 3 +
.../Target/DirectX/DirectXTargetMachine.cpp | 1 +
.../ContainerData/RootSignature-Flags.ll | 38 +++++
10 files changed, 271 insertions(+), 96 deletions(-)
create mode 100644 llvm/lib/Target/DirectX/DXILRootSignature.cpp
create mode 100644 llvm/lib/Target/DirectX/DXILRootSignature.h
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
diff --git a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
index f420244ba111a45..dcc3237f57802f9 100644
--- a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
+++ b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
@@ -11,7 +11,6 @@
#include "llvm/ADT/SmallVector.h"
#include "llvm/IR/PassManager.h"
-#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/Pass.h"
#include "llvm/Support/VersionTuple.h"
#include "llvm/TargetParser/Triple.h"
@@ -39,7 +38,6 @@ struct ModuleMetadataInfo {
Triple::EnvironmentType ShaderProfile{Triple::UnknownEnvironment};
VersionTuple ValidatorVersion{};
SmallVector<EntryProperties> EntryPropertyVec{};
- std::optional<mcdxbc::RootSignatureDesc> RootSignatureDesc;
void print(raw_ostream &OS) const;
};
diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
index 388e3853008eaec..15e72bf17515b15 100644
--- a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -15,7 +15,6 @@
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/InitializePasses.h"
-#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
#include <memory>
@@ -24,82 +23,8 @@
using namespace llvm;
using namespace dxil;
-using namespace llvm::mcdxbc;
-static bool parseRootFlags(MDNode *RootFlagNode, RootSignatureDesc *Desc) {
- assert(RootFlagNode->getNumOperands() == 2 &&
- "Invalid format for RootFlag Element");
- auto *Flag = mdconst::extract<ConstantInt>(RootFlagNode->getOperand(1));
- auto Value = (RootSignatureFlags)Flag->getZExtValue();
-
- if ((Value & ~RootSignatureFlags::ValidFlags) != RootSignatureFlags::None)
- return true;
-
- Desc->Flags = Value;
- return false;
-}
-
-static bool parseRootSignatureElement(MDNode *Element,
- RootSignatureDesc *Desc) {
- MDString *ElementText = cast<MDString>(Element->getOperand(0));
-
- assert(ElementText != nullptr && "First preoperty of element is not ");
-
- RootSignatureElementKind ElementKind =
- StringSwitch<RootSignatureElementKind>(ElementText->getString())
- .Case("RootFlags", RootSignatureElementKind::RootFlags)
- .Case("RootConstants", RootSignatureElementKind::RootConstants)
- .Case("RootCBV", RootSignatureElementKind::RootDescriptor)
- .Case("RootSRV", RootSignatureElementKind::RootDescriptor)
- .Case("RootUAV", RootSignatureElementKind::RootDescriptor)
- .Case("Sampler", RootSignatureElementKind::RootDescriptor)
- .Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
- .Case("StaticSampler", RootSignatureElementKind::StaticSampler)
- .Default(RootSignatureElementKind::None);
-
- switch (ElementKind) {
-
- case RootSignatureElementKind::RootFlags: {
- return parseRootFlags(Element, Desc);
- break;
- }
-
- case RootSignatureElementKind::RootConstants:
- case RootSignatureElementKind::RootDescriptor:
- case RootSignatureElementKind::DescriptorTable:
- case RootSignatureElementKind::StaticSampler:
- case RootSignatureElementKind::None:
- llvm_unreachable("Not Implemented yet");
- break;
- }
-
- return true;
-}
-
-bool parseRootSignature(RootSignatureDesc *Desc, int32_t Version,
- NamedMDNode *Root) {
- Desc->Version = Version;
- bool HasError = false;
-
- for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
- // This should be an if, for error handling
- MDNode *Node = cast<MDNode>(Root->getOperand(Sid));
-
- // Not sure what use this for...
- Metadata *Func = Node->getOperand(0).get();
-
- // This should be an if, for error handling
- MDNode *Elements = cast<MDNode>(Node->getOperand(1).get());
-
- for (unsigned int Eid = 0; Eid < Elements->getNumOperands(); Eid++) {
- MDNode *Element = cast<MDNode>(Elements->getOperand(Eid));
-
- HasError = HasError || parseRootSignatureElement(Element, Desc);
- }
- }
- return HasError;
-}
static ModuleMetadataInfo collectMetadataInfo(Module &M) {
ModuleMetadataInfo MMDAI;
@@ -117,15 +42,6 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
VersionTuple(MajorMD->getZExtValue(), MinorMD->getZExtValue());
}
- NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
- if (RootSignatureNode) {
- mcdxbc::RootSignatureDesc Desc;
-
- parseRootSignature(&Desc, 1, RootSignatureNode);
-
- MMDAI.RootSignatureDesc = Desc;
- }
-
// For all HLSL Shader functions
for (auto &F : M.functions()) {
if (!F.hasFnAttribute("hlsl.shader"))
diff --git a/llvm/lib/MC/CMakeLists.txt b/llvm/lib/MC/CMakeLists.txt
index f49f14c848b9023..e1d19196c8766a7 100644
--- a/llvm/lib/MC/CMakeLists.txt
+++ b/llvm/lib/MC/CMakeLists.txt
@@ -1,7 +1,6 @@
add_llvm_component_library(LLVMMC
ConstantPools.cpp
DXContainerPSVInfo.cpp
- DXContainerRootSignature.cpp
ELFObjectWriter.cpp
GOFFObjectWriter.cpp
MCAsmBackend.cpp
diff --git a/llvm/lib/Target/DirectX/CMakeLists.txt b/llvm/lib/Target/DirectX/CMakeLists.txt
index 26315db891b577a..89fe494dea71ccd 100644
--- a/llvm/lib/Target/DirectX/CMakeLists.txt
+++ b/llvm/lib/Target/DirectX/CMakeLists.txt
@@ -33,7 +33,7 @@ add_llvm_target(DirectXCodeGen
DXILResourceAccess.cpp
DXILShaderFlags.cpp
DXILTranslateMetadata.cpp
-
+ DXILRootSignature.cpp
LINK_COMPONENTS
Analysis
AsmPrinter
diff --git a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
index 7ab11ce757e436c..833a22a9b3e81ee 100644
--- a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
+++ b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "DXILShaderFlags.h"
+#include "DXILRootSignature.h"
#include "DirectX.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
@@ -23,7 +24,6 @@
#include "llvm/IR/Module.h"
#include "llvm/InitializePasses.h"
#include "llvm/MC/DXContainerPSVInfo.h"
-#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/Pass.h"
#include "llvm/Support/MD5.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -63,6 +63,7 @@ class DXContainerGlobals : public llvm::ModulePass {
void getAnalysisUsage(AnalysisUsage &AU) const override {
AU.setPreservesAll();
AU.addRequired<ShaderFlagsAnalysisWrapper>();
+ AU.addRequired<RootSignatureAnalysisWrapper>();
AU.addRequired<DXILMetadataAnalysisWrapperPass>();
AU.addRequired<DXILResourceTypeWrapperPass>();
AU.addRequired<DXILResourceBindingWrapperPass>();
@@ -151,17 +152,15 @@ void DXContainerGlobals::addSignature(Module &M,
void DXContainerGlobals::addRootSignature(Module &M,
SmallVector<GlobalValue *> &Globals) {
- std::optional<RootSignatureDesc> Desc =
- getAnalysis<DXILMetadataAnalysisWrapperPass>()
- .getModuleMetadata()
- .RootSignatureDesc;
- if (!Desc.has_value())
+ std::optional<ModuleRootSignature> MRS =
+ getAnalysis<RootSignatureAnalysisWrapper>()
+ .getRootSignature();
+ if (!MRS.has_value())
return;
SmallString<256> Data;
raw_svector_ostream OS(Data);
- RootSignatureDescWriter writer(&Desc.value());
- writer.write(OS);
+ MRS->write(OS);
Constant *Constant =
ConstantDataArray::getString(M.getContext(), Data, /*AddNull*/ false);
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
new file mode 100644
index 000000000000000..4a51198d97ac347
--- /dev/null
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -0,0 +1,146 @@
+//===- DXILRootSignature.cpp - DXIL Root Signature helper objects ---------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file This file contains helper objects and APIs for working with DXIL
+/// Root Signatures.
+///
+//===----------------------------------------------------------------------===//
+#include "DXILRootSignature.h"
+#include "DirectX.h"
+#include "llvm/ADT/StringSwitch.h"
+#include "llvm/BinaryFormat/DXContainer.h"
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
+
+using namespace llvm;
+using namespace llvm::dxil;
+
+static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
+
+ assert(RootFlagNode->getNumOperands() == 2 &&
+ "Invalid format for RootFlag Element");
+ auto *Flag = mdconst::extract<ConstantInt>(RootFlagNode->getOperand(1));
+ auto Value = Flag->getZExtValue();
+
+ // Root Element validation, as specified: https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
+ if ((Value & ~0x80000fff) != 0)
+ return true;
+
+ MRS->Flags = Value;
+ return false;
+}
+
+static bool parseRootSignatureElement(ModuleRootSignature *MRS, MDNode *Element) {
+ MDString *ElementText = cast<MDString>(Element->getOperand(0));
+
+ assert(ElementText != nullptr && "First preoperty of element is not ");
+
+ RootSignatureElementKind ElementKind =
+ StringSwitch<RootSignatureElementKind>(ElementText->getString())
+ .Case("RootFlags", RootSignatureElementKind::RootFlags)
+ .Case("RootConstants", RootSignatureElementKind::RootConstants)
+ .Case("RootCBV", RootSignatureElementKind::RootDescriptor)
+ .Case("RootSRV", RootSignatureElementKind::RootDescriptor)
+ .Case("RootUAV", RootSignatureElementKind::RootDescriptor)
+ .Case("Sampler", RootSignatureElementKind::RootDescriptor)
+ .Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
+ .Case("StaticSampler", RootSignatureElementKind::StaticSampler)
+ .Default(RootSignatureElementKind::None);
+
+ switch (ElementKind) {
+
+ case RootSignatureElementKind::RootFlags: {
+ return parseRootFlags(MRS, Element);
+ break;
+ }
+
+ case RootSignatureElementKind::RootConstants:
+ case RootSignatureElementKind::RootDescriptor:
+ case RootSignatureElementKind::DescriptorTable:
+ case RootSignatureElementKind::StaticSampler:
+ case RootSignatureElementKind::None:
+ llvm_unreachable("Not Implemented yet");
+ break;
+ }
+
+ return true;
+}
+
+bool ModuleRootSignature::parse( int32_t Version,
+ NamedMDNode *Root) {
+ this->Version = Version;
+ bool HasError = false;
+
+ for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
+ // This should be an if, for error handling
+ MDNode *Node = cast<MDNode>(Root->getOperand(Sid));
+
+ // Not sure what use this for...
+ Metadata *Func = Node->getOperand(0).get();
+
+ // This should be an if, for error handling
+ MDNode *Elements = cast<MDNode>(Node->getOperand(1).get());
+
+ for (unsigned int Eid = 0; Eid < Elements->getNumOperands(); Eid++) {
+ MDNode *Element = cast<MDNode>(Elements->getOperand(Eid));
+
+ HasError = HasError || parseRootSignatureElement(this, Element);
+ }
+ }
+ return HasError;
+}
+
+void ModuleRootSignature::write(raw_ostream &OS) {
+ dxbc::RootSignatureDesc Out{this->Version, this->Flags};
+
+ if (sys::IsBigEndianHost) {
+ Out.swapBytes();
+ }
+
+ OS.write(reinterpret_cast<const char *>(&Out), sizeof(dxbc::RootSignatureDesc));
+}
+
+AnalysisKey RootSignatureAnalysis::Key;
+
+ModuleRootSignature RootSignatureAnalysis::run(Module &M,
+ ModuleAnalysisManager &AM) {
+ ModuleRootSignature MRSI;
+
+ NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
+ if (RootSignatureNode) {
+ MRSI.parse(1, RootSignatureNode);
+ }
+
+ return MRSI;
+
+}
+
+
+//===----------------------------------------------------------------------===//
+bool RootSignatureAnalysisWrapper::runOnModule(Module &M) {
+ ModuleRootSignature MRS;
+
+ NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
+ if (RootSignatureNode) {
+ MRS.parse(1, RootSignatureNode);
+ this->MRS = MRS;
+ }
+
+
+ return false;
+}
+
+void RootSignatureAnalysisWrapper::getAnalysisUsage(AnalysisUsage &AU) const {
+ AU.setPreservesAll();
+}
+
+char RootSignatureAnalysisWrapper::ID = 0;
+
+INITIALIZE_PASS(RootSignatureAnalysisWrapper, "dx-root-signature-analysis",
+ "DXIL Root Signature Analysis", true, true)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.h b/llvm/lib/Target/DirectX/DXILRootSignature.h
new file mode 100644
index 000000000000000..fdfd6c41c0af371
--- /dev/null
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.h
@@ -0,0 +1,75 @@
+//===- DXILRootSignature.h - DXIL Root Signature helper objects ---------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file This file contains helper objects and APIs for working with DXIL
+/// Root Signatures.
+///
+//===----------------------------------------------------------------------===//
+
+
+#include "llvm/IR/Metadata.h"
+#include "llvm/IR/PassManager.h"
+#include "llvm/Pass.h"
+#include <optional>
+
+namespace llvm {
+namespace dxil {
+
+
+ enum class RootSignatureElementKind {
+ None = 0,
+ RootFlags = 1,
+ RootConstants = 2,
+ RootDescriptor = 3,
+ DescriptorTable = 4,
+ StaticSampler = 5
+ };
+
+ struct ModuleRootSignature {
+ uint32_t Version;
+ uint32_t Flags;
+
+ ModuleRootSignature() = default;
+
+ bool parse( int32_t Version, NamedMDNode *Root);
+ void write(raw_ostream &OS);
+ };
+
+ class RootSignatureAnalysis : public AnalysisInfoMixin<RootSignatureAnalysis> {
+ friend AnalysisInfoMixin<RootSignatureAnalysis>;
+ static AnalysisKey Key;
+
+ public:
+ RootSignatureAnalysis() = default;
+
+ using Result = ModuleRootSignature;
+
+ ModuleRootSignature run(Module &M, ModuleAnalysisManager &AM);
+ };
+
+ /// Wrapper pass for the legacy pass manager.
+ ///
+ /// This is required because the passes that will depend on this are codegen
+ /// passes which run through the legacy pass manager.
+ class RootSignatureAnalysisWrapper : public ModulePass {
+ std::optional<ModuleRootSignature> MRS;
+
+ public:
+ static char ID;
+
+ RootSignatureAnalysisWrapper() : ModulePass(ID) {}
+
+ const std::optional<ModuleRootSignature> &getRootSignature() { return MRS; }
+
+ bool runOnModule(Module &M) override;
+
+ void getAnalysisUsage(AnalysisUsage &AU) const override;
+ };
+
+} // namespace dxil
+} // namespace llvm
diff --git a/llvm/lib/Target/DirectX/DirectX.h b/llvm/lib/Target/DirectX/DirectX.h
index add23587de7d583..953ac3eb8209878 100644
--- a/llvm/lib/Target/DirectX/DirectX.h
+++ b/llvm/lib/Target/DirectX/DirectX.h
@@ -77,6 +77,9 @@ void initializeDXILPrettyPrinterLegacyPass(PassRegistry &);
/// Initializer for dxil::ShaderFlagsAnalysisWrapper pass.
void initializeShaderFlagsAnalysisWrapperPass(PassRegistry &);
+/// Initializer for dxil::RootSignatureAnalysisWrapper pass.
+void initializeRootSignatureAnalysisWrapperPass(PassRegistry &);
+
/// Initializer for DXContainerGlobals pass.
void initializeDXContainerGlobalsPass(PassRegistry &);
diff --git a/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp b/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
index ecb1bf775f85786..93745d7a5cb0d2b 100644
--- a/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
+++ b/llvm/lib/Target/DirectX/DirectXTargetMachine.cpp
@@ -61,6 +61,7 @@ extern "C" LLVM_EXTERNAL_VISIBILITY void LLVMInitializeDirectXTarget() {
initializeDXILTranslateMetadataLegacyPass(*PR);
initializeDXILResourceMDWrapperPass(*PR);
initializeShaderFlagsAnalysisWrapperPass(*PR);
+ initializeRootSignatureAnalysisWrapperPass(*PR);
initializeDXILFinalizeLinkageLegacyPass(*PR);
}
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
new file mode 100644
index 000000000000000..ffbf5e9ffd1d325
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
@@ -0,0 +1,38 @@
+; RUN: opt %s -dxil-embed -dxil-globals -S -o - | FileCheck %s
+; RUN: llc %s --filetype=obj -o - | obj2yaml | FileCheck %s --check-prefix=DXC
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: @dx.rts0 = private constant [8 x i8] c"{{.*}}", section "RTS0", align 4
+
+
+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 = !{ !4 } ; list of root signature elements
+!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
+
+
+; DXC: - Name: RTS0
+; DXC-NEXT: Size: 8
+; DXC-NEXT: RootSignature:
+; DXC-NEXT: Version: 1
+; DXC-NEXT: AllowInputAssemblerInputLayout: true
+; DXC-NEXT: DenyVertexShaderRootAccess: false
+; DXC-NEXT: DenyHullShaderRootAccess: false
+; DXC-NEXT: DenyDomainShaderRootAccess: false
+; DXC-NEXT: DenyGeometryShaderRootAccess: false
+; DXC-NEXT: DenyPixelShaderRootAccess: false
+; DXC-NEXT: AllowStreamOutput: false
+; DXC-NEXT: LocalRootSignature: false
+; DXC-NEXT: DenyAmplificationShaderRootAccess: false
+; DXC-NEXT: DenyMeshShaderRootAccess: false
+; DXC-NEXT: CBVSRVUAVHeapDirectlyIndexed: false
+; DXC-NEXT: SamplerHeapDirectlyIndexed: false
>From a7f778412de28258703b51aed85699e413491e29 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 16 Jan 2025 00:37:14 +0000
Subject: [PATCH 30/50] formating
---
llvm/lib/Analysis/DXILMetadataAnalysis.cpp | 2 -
.../lib/Target/DirectX/DXContainerGlobals.cpp | 5 +-
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 48 ++++++------
llvm/lib/Target/DirectX/DXILRootSignature.h | 77 +++++++++----------
4 files changed, 64 insertions(+), 68 deletions(-)
diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
index 15e72bf17515b15..197b7e422092c6b 100644
--- a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -24,8 +24,6 @@
using namespace llvm;
using namespace dxil;
-
-
static ModuleMetadataInfo collectMetadataInfo(Module &M) {
ModuleMetadataInfo MMDAI;
Triple TT(Triple(M.getTargetTriple()));
diff --git a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
index 833a22a9b3e81ee..ac70bd3771dadf2 100644
--- a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
+++ b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
@@ -10,8 +10,8 @@
//
//===----------------------------------------------------------------------===//
-#include "DXILShaderFlags.h"
#include "DXILRootSignature.h"
+#include "DXILShaderFlags.h"
#include "DirectX.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
@@ -153,8 +153,7 @@ void DXContainerGlobals::addRootSignature(Module &M,
SmallVector<GlobalValue *> &Globals) {
std::optional<ModuleRootSignature> MRS =
- getAnalysis<RootSignatureAnalysisWrapper>()
- .getRootSignature();
+ getAnalysis<RootSignatureAnalysisWrapper>().getRootSignature();
if (!MRS.has_value())
return;
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 4a51198d97ac347..89621868a93368f 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -1,4 +1,5 @@
-//===- DXILRootSignature.cpp - DXIL Root Signature helper objects ---------------===//
+//===- DXILRootSignature.cpp - DXIL Root Signature helper objects
+//---------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -28,7 +29,8 @@ static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
auto *Flag = mdconst::extract<ConstantInt>(RootFlagNode->getOperand(1));
auto Value = Flag->getZExtValue();
- // Root Element validation, as specified: https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
+ // Root Element validation, as specified:
+ // https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
if ((Value & ~0x80000fff) != 0)
return true;
@@ -36,7 +38,8 @@ static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
return false;
}
-static bool parseRootSignatureElement(ModuleRootSignature *MRS, MDNode *Element) {
+static bool parseRootSignatureElement(ModuleRootSignature *MRS,
+ MDNode *Element) {
MDString *ElementText = cast<MDString>(Element->getOperand(0));
assert(ElementText != nullptr && "First preoperty of element is not ");
@@ -72,8 +75,7 @@ static bool parseRootSignatureElement(ModuleRootSignature *MRS, MDNode *Element)
return true;
}
-bool ModuleRootSignature::parse( int32_t Version,
- NamedMDNode *Root) {
+bool ModuleRootSignature::parse(int32_t Version, NamedMDNode *Root) {
this->Version = Version;
bool HasError = false;
@@ -103,37 +105,35 @@ void ModuleRootSignature::write(raw_ostream &OS) {
Out.swapBytes();
}
- OS.write(reinterpret_cast<const char *>(&Out), sizeof(dxbc::RootSignatureDesc));
+ OS.write(reinterpret_cast<const char *>(&Out),
+ sizeof(dxbc::RootSignatureDesc));
}
AnalysisKey RootSignatureAnalysis::Key;
ModuleRootSignature RootSignatureAnalysis::run(Module &M,
- ModuleAnalysisManager &AM) {
- ModuleRootSignature MRSI;
+ ModuleAnalysisManager &AM) {
+ ModuleRootSignature MRSI;
- NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
- if (RootSignatureNode) {
- MRSI.parse(1, RootSignatureNode);
- }
-
- return MRSI;
+ NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
+ if (RootSignatureNode) {
+ MRSI.parse(1, RootSignatureNode);
+ }
+ return MRSI;
}
-
//===----------------------------------------------------------------------===//
bool RootSignatureAnalysisWrapper::runOnModule(Module &M) {
ModuleRootSignature MRS;
- NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
- if (RootSignatureNode) {
- MRS.parse(1, RootSignatureNode);
- this->MRS = MRS;
- }
-
+ NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
+ if (RootSignatureNode) {
+ MRS.parse(1, RootSignatureNode);
+ this->MRS = MRS;
+ }
- return false;
+ return false;
}
void RootSignatureAnalysisWrapper::getAnalysisUsage(AnalysisUsage &AU) const {
@@ -142,5 +142,5 @@ void RootSignatureAnalysisWrapper::getAnalysisUsage(AnalysisUsage &AU) const {
char RootSignatureAnalysisWrapper::ID = 0;
-INITIALIZE_PASS(RootSignatureAnalysisWrapper, "dx-root-signature-analysis",
- "DXIL Root Signature Analysis", true, true)
+INITIALIZE_PASS(RootSignatureAnalysisWrapper, "dx-root-signature-analysis",
+ "DXIL Root Signature Analysis", true, true)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.h b/llvm/lib/Target/DirectX/DXILRootSignature.h
index fdfd6c41c0af371..de82afcdc8c4677 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.h
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.h
@@ -1,4 +1,5 @@
-//===- DXILRootSignature.h - DXIL Root Signature helper objects ---------------===//
+//===- DXILRootSignature.h - DXIL Root Signature helper objects
+//---------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -11,7 +12,6 @@
///
//===----------------------------------------------------------------------===//
-
#include "llvm/IR/Metadata.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
@@ -20,56 +20,55 @@
namespace llvm {
namespace dxil {
+enum class RootSignatureElementKind {
+ None = 0,
+ RootFlags = 1,
+ RootConstants = 2,
+ RootDescriptor = 3,
+ DescriptorTable = 4,
+ StaticSampler = 5
+};
- enum class RootSignatureElementKind {
- None = 0,
- RootFlags = 1,
- RootConstants = 2,
- RootDescriptor = 3,
- DescriptorTable = 4,
- StaticSampler = 5
- };
-
- struct ModuleRootSignature {
- uint32_t Version;
- uint32_t Flags;
+struct ModuleRootSignature {
+ uint32_t Version;
+ uint32_t Flags;
- ModuleRootSignature() = default;
+ ModuleRootSignature() = default;
- bool parse( int32_t Version, NamedMDNode *Root);
- void write(raw_ostream &OS);
- };
+ bool parse(int32_t Version, NamedMDNode *Root);
+ void write(raw_ostream &OS);
+};
- class RootSignatureAnalysis : public AnalysisInfoMixin<RootSignatureAnalysis> {
- friend AnalysisInfoMixin<RootSignatureAnalysis>;
- static AnalysisKey Key;
+class RootSignatureAnalysis : public AnalysisInfoMixin<RootSignatureAnalysis> {
+ friend AnalysisInfoMixin<RootSignatureAnalysis>;
+ static AnalysisKey Key;
- public:
- RootSignatureAnalysis() = default;
+public:
+ RootSignatureAnalysis() = default;
- using Result = ModuleRootSignature;
+ using Result = ModuleRootSignature;
- ModuleRootSignature run(Module &M, ModuleAnalysisManager &AM);
- };
+ ModuleRootSignature run(Module &M, ModuleAnalysisManager &AM);
+};
- /// Wrapper pass for the legacy pass manager.
- ///
- /// This is required because the passes that will depend on this are codegen
- /// passes which run through the legacy pass manager.
- class RootSignatureAnalysisWrapper : public ModulePass {
- std::optional<ModuleRootSignature> MRS;
+/// Wrapper pass for the legacy pass manager.
+///
+/// This is required because the passes that will depend on this are codegen
+/// passes which run through the legacy pass manager.
+class RootSignatureAnalysisWrapper : public ModulePass {
+ std::optional<ModuleRootSignature> MRS;
- public:
- static char ID;
+public:
+ static char ID;
- RootSignatureAnalysisWrapper() : ModulePass(ID) {}
+ RootSignatureAnalysisWrapper() : ModulePass(ID) {}
- const std::optional<ModuleRootSignature> &getRootSignature() { return MRS; }
+ const std::optional<ModuleRootSignature> &getRootSignature() { return MRS; }
- bool runOnModule(Module &M) override;
+ bool runOnModule(Module &M) override;
- void getAnalysisUsage(AnalysisUsage &AU) const override;
- };
+ void getAnalysisUsage(AnalysisUsage &AU) const override;
+};
} // namespace dxil
} // namespace llvm
>From bf3b2e0ed560e5776391db1511997b7278b9a122 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 16 Jan 2025 00:42:54 +0000
Subject: [PATCH 31/50] removing useless imports
---
llvm/include/llvm/Analysis/DXILMetadataAnalysis.h | 1 -
llvm/lib/Analysis/DXILMetadataAnalysis.cpp | 3 ---
2 files changed, 4 deletions(-)
diff --git a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
index dcc3237f57802f9..cb535ac14f1c613 100644
--- a/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
+++ b/llvm/include/llvm/Analysis/DXILMetadataAnalysis.h
@@ -14,7 +14,6 @@
#include "llvm/Pass.h"
#include "llvm/Support/VersionTuple.h"
#include "llvm/TargetParser/Triple.h"
-#include <optional>
namespace llvm {
diff --git a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
index 197b7e422092c6b..a7f666a3f8b48f2 100644
--- a/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
+++ b/llvm/lib/Analysis/DXILMetadataAnalysis.cpp
@@ -15,9 +15,7 @@
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
#include "llvm/InitializePasses.h"
-#include "llvm/Support/Casting.h"
#include "llvm/Support/ErrorHandling.h"
-#include <memory>
#define DEBUG_TYPE "dxil-metadata-analysis"
@@ -30,7 +28,6 @@ static ModuleMetadataInfo collectMetadataInfo(Module &M) {
MMDAI.DXILVersion = TT.getDXILVersion();
MMDAI.ShaderModelVersion = TT.getOSVersion();
MMDAI.ShaderProfile = TT.getEnvironment();
-
NamedMDNode *ValidatorVerNode = M.getNamedMetadata("dx.valver");
if (ValidatorVerNode) {
auto *ValVerMD = cast<MDNode>(ValidatorVerNode->getOperand(0));
>From 16b4d03d316c40f1f97cb766d9ae979185132807 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 16 Jan 2025 19:22:31 +0000
Subject: [PATCH 32/50] fixing pr changes
---
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index 0869fd4fa978587..afcc093cf045687 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -15,6 +15,7 @@
#include "llvm/ADT/ScopeExit.h"
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Support/ScopedPrinter.h"
+#include <cstdint>
namespace llvm {
>From e0433700ff8ddc13d88876075deea7116715e8c8 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 16 Jan 2025 20:06:13 +0000
Subject: [PATCH 33/50] adding some asserts
---
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 89621868a93368f..024743b9f81a6cc 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -18,6 +18,7 @@
#include "llvm/IR/Constants.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
+#include <cassert>
using namespace llvm;
using namespace llvm::dxil;
@@ -31,8 +32,7 @@ static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
// Root Element validation, as specified:
// https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
- if ((Value & ~0x80000fff) != 0)
- return true;
+ assert((Value & ~0x80000fff) != 0 && "Invalid flag for RootFlag Element");
MRS->Flags = Value;
return false;
@@ -41,8 +41,7 @@ static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
static bool parseRootSignatureElement(ModuleRootSignature *MRS,
MDNode *Element) {
MDString *ElementText = cast<MDString>(Element->getOperand(0));
-
- assert(ElementText != nullptr && "First preoperty of element is not ");
+ assert(ElementText != nullptr && "First preoperty of element is not a string");
RootSignatureElementKind ElementKind =
StringSwitch<RootSignatureElementKind>(ElementText->getString())
@@ -84,13 +83,14 @@ bool ModuleRootSignature::parse(int32_t Version, NamedMDNode *Root) {
MDNode *Node = cast<MDNode>(Root->getOperand(Sid));
// Not sure what use this for...
- Metadata *Func = Node->getOperand(0).get();
+ // Metadata *Func = Node->getOperand(0).get();
- // This should be an if, for error handling
MDNode *Elements = cast<MDNode>(Node->getOperand(1).get());
+ assert(Elements && "Invalid Metadata type on root signature");
for (unsigned int Eid = 0; Eid < Elements->getNumOperands(); Eid++) {
MDNode *Element = cast<MDNode>(Elements->getOperand(Eid));
+ assert(Element && "Invalid Metadata type on root element");
HasError = HasError || parseRootSignatureElement(this, Element);
}
>From 57bf935dccd2f4aaaa211984a77b94a28ef267bc Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 16 Jan 2025 20:11:36 +0000
Subject: [PATCH 34/50] format
---
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 024743b9f81a6cc..cabaec3671078e4 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -41,7 +41,8 @@ static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
static bool parseRootSignatureElement(ModuleRootSignature *MRS,
MDNode *Element) {
MDString *ElementText = cast<MDString>(Element->getOperand(0));
- assert(ElementText != nullptr && "First preoperty of element is not a string");
+ assert(ElementText != nullptr &&
+ "First preoperty of element is not a string");
RootSignatureElementKind ElementKind =
StringSwitch<RootSignatureElementKind>(ElementText->getString())
>From 1f8c0a5c34d1f3f5350c8282c7d65ea9753d5de9 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Sat, 18 Jan 2025 00:24:53 +0000
Subject: [PATCH 35/50] fixing assert
---
llvm/lib/MC/CMakeLists.txt | 1 +
llvm/lib/Target/DirectX/DXContainerGlobals.cpp | 7 ++++++-
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 13 +------------
llvm/lib/Target/DirectX/DXILRootSignature.h | 1 -
.../DirectX/ContainerData/RootSignature-Flags.ll | 16 +++-------------
5 files changed, 11 insertions(+), 27 deletions(-)
diff --git a/llvm/lib/MC/CMakeLists.txt b/llvm/lib/MC/CMakeLists.txt
index e1d19196c8766a7..f49f14c848b9023 100644
--- a/llvm/lib/MC/CMakeLists.txt
+++ b/llvm/lib/MC/CMakeLists.txt
@@ -1,6 +1,7 @@
add_llvm_component_library(LLVMMC
ConstantPools.cpp
DXContainerPSVInfo.cpp
+ DXContainerRootSignature.cpp
ELFObjectWriter.cpp
GOFFObjectWriter.cpp
MCAsmBackend.cpp
diff --git a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
index ac70bd3771dadf2..c090d1074250a03 100644
--- a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
+++ b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
@@ -24,6 +24,7 @@
#include "llvm/IR/Module.h"
#include "llvm/InitializePasses.h"
#include "llvm/MC/DXContainerPSVInfo.h"
+#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/Pass.h"
#include "llvm/Support/MD5.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
@@ -159,7 +160,11 @@ void DXContainerGlobals::addRootSignature(Module &M,
SmallString<256> Data;
raw_svector_ostream OS(Data);
- MRS->write(OS);
+
+ RootSignatureHeader RSH;
+ RSH.Flags = MRS->Flags;
+ RSH.Version = MRS->Version;
+ RSH.write(OS);
Constant *Constant =
ConstantDataArray::getString(M.getContext(), Data, /*AddNull*/ false);
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index cabaec3671078e4..5ee9eea68b9e600 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -32,7 +32,7 @@ static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
// Root Element validation, as specified:
// https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
- assert((Value & ~0x80000fff) != 0 && "Invalid flag for RootFlag Element");
+ assert((Value & ~0x80000fff) == 0 && "Invalid flag for RootFlag Element");
MRS->Flags = Value;
return false;
@@ -99,17 +99,6 @@ bool ModuleRootSignature::parse(int32_t Version, NamedMDNode *Root) {
return HasError;
}
-void ModuleRootSignature::write(raw_ostream &OS) {
- dxbc::RootSignatureDesc Out{this->Version, this->Flags};
-
- if (sys::IsBigEndianHost) {
- Out.swapBytes();
- }
-
- OS.write(reinterpret_cast<const char *>(&Out),
- sizeof(dxbc::RootSignatureDesc));
-}
-
AnalysisKey RootSignatureAnalysis::Key;
ModuleRootSignature RootSignatureAnalysis::run(Module &M,
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.h b/llvm/lib/Target/DirectX/DXILRootSignature.h
index de82afcdc8c4677..3bbbaa12b079842 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.h
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.h
@@ -36,7 +36,6 @@ struct ModuleRootSignature {
ModuleRootSignature() = default;
bool parse(int32_t Version, NamedMDNode *Root);
- void write(raw_ostream &OS);
};
class RootSignatureAnalysis : public AnalysisInfoMixin<RootSignatureAnalysis> {
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
index ffbf5e9ffd1d325..20253efbb8e5c51 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
@@ -3,7 +3,7 @@
target triple = "dxil-unknown-shadermodel6.0-compute"
-; CHECK: @dx.rts0 = private constant [8 x i8] c"{{.*}}", section "RTS0", align 4
+; CHECK: @dx.rts0 = private constant [12 x i8] c"{{.*}}", section "RTS0", align 4
define void @main() #0 {
@@ -21,18 +21,8 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
; DXC: - Name: RTS0
-; DXC-NEXT: Size: 8
+; DXC-NEXT: Size: 12
; DXC-NEXT: RootSignature:
+; DXC-NEXT: Size: 8
; DXC-NEXT: Version: 1
; DXC-NEXT: AllowInputAssemblerInputLayout: true
-; DXC-NEXT: DenyVertexShaderRootAccess: false
-; DXC-NEXT: DenyHullShaderRootAccess: false
-; DXC-NEXT: DenyDomainShaderRootAccess: false
-; DXC-NEXT: DenyGeometryShaderRootAccess: false
-; DXC-NEXT: DenyPixelShaderRootAccess: false
-; DXC-NEXT: AllowStreamOutput: false
-; DXC-NEXT: LocalRootSignature: false
-; DXC-NEXT: DenyAmplificationShaderRootAccess: false
-; DXC-NEXT: DenyMeshShaderRootAccess: false
-; DXC-NEXT: CBVSRVUAVHeapDirectlyIndexed: false
-; DXC-NEXT: SamplerHeapDirectlyIndexed: false
>From 0905b8341c5baa6225b5f8fcd51455c80c160593 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Mon, 27 Jan 2025 23:45:45 +0000
Subject: [PATCH 36/50] cleaning
---
llvm/lib/ObjectYAML/DXContainerYAML.cpp | 1 -
llvm/lib/Target/DirectX/DXContainerGlobals.cpp | 1 -
2 files changed, 2 deletions(-)
diff --git a/llvm/lib/ObjectYAML/DXContainerYAML.cpp b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
index afcc093cf045687..0869fd4fa978587 100644
--- a/llvm/lib/ObjectYAML/DXContainerYAML.cpp
+++ b/llvm/lib/ObjectYAML/DXContainerYAML.cpp
@@ -15,7 +15,6 @@
#include "llvm/ADT/ScopeExit.h"
#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/Support/ScopedPrinter.h"
-#include <cstdint>
namespace llvm {
diff --git a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
index c090d1074250a03..36e7cedbdaee0cb 100644
--- a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
+++ b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
@@ -28,7 +28,6 @@
#include "llvm/Pass.h"
#include "llvm/Support/MD5.h"
#include "llvm/Transforms/Utils/ModuleUtils.h"
-#include <optional>
using namespace llvm;
using namespace llvm::dxil;
>From 77e85444c8ebd747046267d10d5ac221eb912b40 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Wed, 29 Jan 2025 18:36:55 +0000
Subject: [PATCH 37/50] clean up
---
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 2 --
llvm/test/CodeGen/DirectX/llc-pipeline.ll | 1 +
2 files changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 5ee9eea68b9e600..71ca8a91bc3fe09 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -14,11 +14,9 @@
#include "DXILRootSignature.h"
#include "DirectX.h"
#include "llvm/ADT/StringSwitch.h"
-#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/IR/Constants.h"
#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
-#include <cassert>
using namespace llvm;
using namespace llvm::dxil;
diff --git a/llvm/test/CodeGen/DirectX/llc-pipeline.ll b/llvm/test/CodeGen/DirectX/llc-pipeline.ll
index b07155724941467..fc0a7833ea2f073 100644
--- a/llvm/test/CodeGen/DirectX/llc-pipeline.ll
+++ b/llvm/test/CodeGen/DirectX/llc-pipeline.ll
@@ -33,6 +33,7 @@
; CHECK-ASM-NEXT: Print Module IR
; CHECK-OBJ-NEXT: DXIL Embedder
+; CHECK-OBJ-NEXT: DXIL Root Signature Analysis
; CHECK-OBJ-NEXT: DXContainer Global Emitter
; CHECK-OBJ-NEXT: FunctionPass Manager
; CHECK-OBJ-NEXT: Lazy Machine Block Frequency Analysis
>From 1351fb06360ace76419d9d5991695d4b80c5eca2 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 30 Jan 2025 00:22:01 +0000
Subject: [PATCH 38/50] addressing comments
---
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 89 ++++++++++++-------
llvm/lib/Target/DirectX/DXILRootSignature.h | 2 +
.../ContainerData/RootSignature-Error.ll | 17 ++++
.../RootSignature-Flags-Error.ll | 19 ++++
.../RootSignature-Flags-Validation-Error.ll | 19 ++++
.../RootSignature-RootElement-Error.ll | 18 ++++
6 files changed, 132 insertions(+), 32 deletions(-)
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Error.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Validation-Error.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootElement-Error.ll
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 71ca8a91bc3fe09..52c7ad8e249379e 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -1,5 +1,4 @@
-//===- DXILRootSignature.cpp - DXIL Root Signature helper objects
-//---------------===//
+//===- DXILRootSignature.cpp - DXIL Root Signature helper objects ----===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
@@ -14,23 +13,31 @@
#include "DXILRootSignature.h"
#include "DirectX.h"
#include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/Twine.h"
#include "llvm/IR/Constants.h"
-#include "llvm/IR/Metadata.h"
#include "llvm/IR/Module.h"
+#include <cstdint>
using namespace llvm;
using namespace llvm::dxil;
+static bool reportError(Twine Message) {
+ report_fatal_error(Message, false);
+ return true;
+}
+
static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
- assert(RootFlagNode->getNumOperands() == 2 &&
- "Invalid format for RootFlag Element");
+ if (RootFlagNode->getNumOperands() != 2)
+ return reportError("Invalid format for RootFlag Element");
+
auto *Flag = mdconst::extract<ConstantInt>(RootFlagNode->getOperand(1));
- auto Value = Flag->getZExtValue();
+ uint32_t Value = Flag->getZExtValue();
// Root Element validation, as specified:
// https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
- assert((Value & ~0x80000fff) == 0 && "Invalid flag for RootFlag Element");
+ if ((Value & ~0x80000fff) != 0)
+ return reportError("Invalid flag value for RootFlag");
MRS->Flags = Value;
return false;
@@ -39,8 +46,8 @@ static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
static bool parseRootSignatureElement(ModuleRootSignature *MRS,
MDNode *Element) {
MDString *ElementText = cast<MDString>(Element->getOperand(0));
- assert(ElementText != nullptr &&
- "First preoperty of element is not a string");
+ if (ElementText == nullptr)
+ return reportError("Invalid format for Root Element");
RootSignatureElementKind ElementKind =
StringSwitch<RootSignatureElementKind>(ElementText->getString())
@@ -66,7 +73,7 @@ static bool parseRootSignatureElement(ModuleRootSignature *MRS,
case RootSignatureElementKind::DescriptorTable:
case RootSignatureElementKind::StaticSampler:
case RootSignatureElementKind::None:
- llvm_unreachable("Not Implemented yet");
+ return reportError("Invalid Root Element: " + ElementText->getString());
break;
}
@@ -77,19 +84,37 @@ bool ModuleRootSignature::parse(int32_t Version, NamedMDNode *Root) {
this->Version = Version;
bool HasError = false;
+ /** Root Signature are specified as following in the metadata:
+
+ !dx.rootsignatures = !{!2} ; list of function/root signature pairs
+ !2 = !{ ptr @main, !3 } ; function, root signature
+ !3 = !{ !4, !5, !6, !7 } ; list of root signature elements
+
+ So for each MDNode inside dx.rootsignatures NamedMDNode
+ (the Root parameter of this function), the parsing process needs
+ to loop through each of it's operand and process the pairs function
+ signature pair.
+ */
+
for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
- // This should be an if, for error handling
- MDNode *Node = cast<MDNode>(Root->getOperand(Sid));
+ MDNode *Node = dyn_cast<MDNode>(Root->getOperand(Sid));
+
+ if (Node == nullptr || Node->getNumOperands() != 2)
+ return reportError("Invalid format for Root Signature Definition. Pairs "
+ "of function, root signature expected.");
+
+ // Get the Root Signature Description from the function signature pair.
+ MDNode *RS = dyn_cast<MDNode>(Node->getOperand(1).get());
- // Not sure what use this for...
- // Metadata *Func = Node->getOperand(0).get();
+ if (RS == nullptr)
+ return reportError("Missing Root Signature Metadata node.");
- MDNode *Elements = cast<MDNode>(Node->getOperand(1).get());
- assert(Elements && "Invalid Metadata type on root signature");
+ // Loop through the Root Elements of the root signature.
+ for (unsigned int Eid = 0; Eid < RS->getNumOperands(); Eid++) {
- for (unsigned int Eid = 0; Eid < Elements->getNumOperands(); Eid++) {
- MDNode *Element = cast<MDNode>(Elements->getOperand(Eid));
- assert(Element && "Invalid Metadata type on root element");
+ MDNode *Element = dyn_cast<MDNode>(RS->getOperand(Eid));
+ if (Element == nullptr)
+ return reportError("Missing Root Element Metadata Node.");
HasError = HasError || parseRootSignatureElement(this, Element);
}
@@ -97,29 +122,29 @@ bool ModuleRootSignature::parse(int32_t Version, NamedMDNode *Root) {
return HasError;
}
-AnalysisKey RootSignatureAnalysis::Key;
-
-ModuleRootSignature RootSignatureAnalysis::run(Module &M,
- ModuleAnalysisManager &AM) {
- ModuleRootSignature MRSI;
+ModuleRootSignature ModuleRootSignature::analyzeModule(Module &M) {
+ ModuleRootSignature MRS;
NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
if (RootSignatureNode) {
- MRSI.parse(1, RootSignatureNode);
+ if (MRS.parse(1, RootSignatureNode))
+ llvm_unreachable("Invalid Root Signature Metadata.");
}
- return MRSI;
+ return MRS;
+}
+
+AnalysisKey RootSignatureAnalysis::Key;
+
+ModuleRootSignature RootSignatureAnalysis::run(Module &M,
+ ModuleAnalysisManager &AM) {
+ return ModuleRootSignature::analyzeModule(M);
}
//===----------------------------------------------------------------------===//
bool RootSignatureAnalysisWrapper::runOnModule(Module &M) {
- ModuleRootSignature MRS;
- NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
- if (RootSignatureNode) {
- MRS.parse(1, RootSignatureNode);
- this->MRS = MRS;
- }
+ this->MRS = MRS = ModuleRootSignature::analyzeModule(M);
return false;
}
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.h b/llvm/lib/Target/DirectX/DXILRootSignature.h
index 3bbbaa12b079842..0439deea6451a67 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.h
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.h
@@ -36,6 +36,8 @@ struct ModuleRootSignature {
ModuleRootSignature() = default;
bool parse(int32_t Version, NamedMDNode *Root);
+
+ static ModuleRootSignature analyzeModule(Module &M);
};
class RootSignatureAnalysis : public AnalysisInfoMixin<RootSignatureAnalysis> {
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error.ll
new file mode 100644
index 000000000000000..cbcd8e56c1c0463
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error.ll
@@ -0,0 +1,17 @@
+; RUN: not llc %s --filetype=obj -o - 2>&1 | FileCheck %s
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: LLVM ERROR: Invalid format for Root Signature Definition. Pairs of function, root signature expected.
+
+
+define void @main() #0 {
+entry:
+ ret void
+}
+
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!1} ; list of function/root signature pairs
+!1= !{ !"RootFlags" } ; function, root signature
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Error.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Error.ll
new file mode 100644
index 000000000000000..9b4208011bba508
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Error.ll
@@ -0,0 +1,19 @@
+; RUN: not llc %s --filetype=obj -o - 2>&1 | FileCheck %s
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: LLVM ERROR: Invalid Root Element: NOTRootFlags
+
+
+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 = !{ !4 } ; list of root signature elements
+!4 = !{ !"NOTRootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Validation-Error.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Validation-Error.ll
new file mode 100644
index 000000000000000..85e6f4d6748d5c4
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Validation-Error.ll
@@ -0,0 +1,19 @@
+; RUN: not llc %s --filetype=obj -o - 2>&1 | FileCheck %s
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: LLVM ERROR: Invalid flag value for RootFlag
+
+
+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 = !{ !4 } ; list of root signature elements
+!4 = !{ !"RootFlags", i32 2147487744 } ; 1 = allow_input_assembler_input_layout
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootElement-Error.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootElement-Error.ll
new file mode 100644
index 000000000000000..501e3438943a3c9
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootElement-Error.ll
@@ -0,0 +1,18 @@
+; RUN: not llc %s --filetype=obj -o - 2>&1 | FileCheck %s
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: LLVM ERROR: Missing Root Element Metadata Node.
+
+
+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 = !{ !"NOTRootElements" } ; list of root signature elements
>From 09e645aec09371cd145cf42f54809d8ae0832ce5 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 30 Jan 2025 18:33:23 +0000
Subject: [PATCH 39/50] removing version
---
llvm/lib/Target/DirectX/DXContainerGlobals.cpp | 2 +-
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 5 ++---
llvm/lib/Target/DirectX/DXILRootSignature.h | 3 +--
3 files changed, 4 insertions(+), 6 deletions(-)
diff --git a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
index 36e7cedbdaee0cb..37108f92718df81 100644
--- a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
+++ b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
@@ -162,7 +162,7 @@ void DXContainerGlobals::addRootSignature(Module &M,
RootSignatureHeader RSH;
RSH.Flags = MRS->Flags;
- RSH.Version = MRS->Version;
+
RSH.write(OS);
Constant *Constant =
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 52c7ad8e249379e..c86be5bd9eb676c 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -80,8 +80,7 @@ static bool parseRootSignatureElement(ModuleRootSignature *MRS,
return true;
}
-bool ModuleRootSignature::parse(int32_t Version, NamedMDNode *Root) {
- this->Version = Version;
+bool ModuleRootSignature::parse(NamedMDNode *Root) {
bool HasError = false;
/** Root Signature are specified as following in the metadata:
@@ -127,7 +126,7 @@ ModuleRootSignature ModuleRootSignature::analyzeModule(Module &M) {
NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
if (RootSignatureNode) {
- if (MRS.parse(1, RootSignatureNode))
+ if (MRS.parse(RootSignatureNode))
llvm_unreachable("Invalid Root Signature Metadata.");
}
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.h b/llvm/lib/Target/DirectX/DXILRootSignature.h
index 0439deea6451a67..f89fb0f00b5a4d5 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.h
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.h
@@ -30,12 +30,11 @@ enum class RootSignatureElementKind {
};
struct ModuleRootSignature {
- uint32_t Version;
uint32_t Flags;
ModuleRootSignature() = default;
- bool parse(int32_t Version, NamedMDNode *Root);
+ bool parse(NamedMDNode *Root);
static ModuleRootSignature analyzeModule(Module &M);
};
>From 5a44b6286fd8da48d46927d031f442a41eca2840 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 30 Jan 2025 22:29:30 +0000
Subject: [PATCH 40/50] fix test
---
.../CodeGen/DirectX/ContainerData/RootSignature-Flags.ll | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
index 20253efbb8e5c51..b44d31c5b385746 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
@@ -3,7 +3,7 @@
target triple = "dxil-unknown-shadermodel6.0-compute"
-; CHECK: @dx.rts0 = private constant [12 x i8] c"{{.*}}", section "RTS0", align 4
+; CHECK: @dx.rts0 = private constant [8 x i8] c"{{.*}}", section "RTS0", align 4
define void @main() #0 {
@@ -11,6 +11,9 @@ entry:
ret void
}
+
+
+
attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
@@ -21,8 +24,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
; DXC: - Name: RTS0
-; DXC-NEXT: Size: 12
+; DXC-NEXT: Size: 8
; DXC-NEXT: RootSignature:
; DXC-NEXT: Size: 8
-; DXC-NEXT: Version: 1
; DXC-NEXT: AllowInputAssemblerInputLayout: true
>From d1a79b3678375e587460844419a65a74b2ba7412 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Fri, 31 Jan 2025 00:42:33 +0000
Subject: [PATCH 41/50] addressing PR Comments
---
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 5 ++---
llvm/lib/Target/DirectX/DXILRootSignature.h | 2 +-
2 files changed, 3 insertions(+), 4 deletions(-)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index c86be5bd9eb676c..109069eb66dea52 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -95,10 +95,9 @@ bool ModuleRootSignature::parse(NamedMDNode *Root) {
signature pair.
*/
- for (unsigned int Sid = 0; Sid < Root->getNumOperands(); Sid++) {
- MDNode *Node = dyn_cast<MDNode>(Root->getOperand(Sid));
+ for (const MDNode *Node : Root->operands()) {
- if (Node == nullptr || Node->getNumOperands() != 2)
+ if (Node->getNumOperands() != 2)
return reportError("Invalid format for Root Signature Definition. Pairs "
"of function, root signature expected.");
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.h b/llvm/lib/Target/DirectX/DXILRootSignature.h
index f89fb0f00b5a4d5..5bbea29d22ae50a 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.h
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.h
@@ -30,7 +30,7 @@ enum class RootSignatureElementKind {
};
struct ModuleRootSignature {
- uint32_t Flags;
+ uint32_t Flags = 0;
ModuleRootSignature() = default;
>From 9f8e51255b6c2f23761bab88478094da282311db Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Mon, 3 Feb 2025 21:32:59 +0000
Subject: [PATCH 42/50] fix test
---
.../DirectX/ContainerData/RootSignature-Flags.ll | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
index b44d31c5b385746..c3e38c44c619445 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
@@ -3,7 +3,7 @@
target triple = "dxil-unknown-shadermodel6.0-compute"
-; CHECK: @dx.rts0 = private constant [8 x i8] c"{{.*}}", section "RTS0", align 4
+; CHECK: @dx.rts0 = private constant [24 x i8] c"{{.*}}", section "RTS0", align 4
define void @main() #0 {
@@ -23,8 +23,12 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
!4 = !{ !"RootFlags", i32 1 } ; 1 = allow_input_assembler_input_layout
-; DXC: - Name: RTS0
-; DXC-NEXT: Size: 8
-; DXC-NEXT: RootSignature:
-; DXC-NEXT: Size: 8
-; DXC-NEXT: AllowInputAssemblerInputLayout: true
+; DXC: - Name: RTS0
+; DXC-NEXT: Size: 24
+; DXC-NEXT: RootSignature:
+; DXC-NEXT: Version: 2
+; DXC-NEXT: NumParameters: 0
+; DXC-NEXT: RootParametersOffset: 0
+; DXC-NEXT: NumStaticSamplers: 0
+; DXC-NEXT: StaticSamplersOffset: 0
+; DXC-NEXT: AllowInputAssemblerInputLayout: true
>From 5c7ed7e42803423cb9771fbf895ef1878b4ed803 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Tue, 4 Feb 2025 00:07:43 +0000
Subject: [PATCH 43/50] filtering root signatures not associated with entry
function
---
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 57 ++++++++++++++++---
llvm/lib/Target/DirectX/DXILRootSignature.h | 4 +-
.../ContainerData/RootSignature-Flags.ll | 1 -
3 files changed, 50 insertions(+), 12 deletions(-)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 109069eb66dea52..984505b3fb85b81 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -14,9 +14,12 @@
#include "DirectX.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
+#include "llvm/Analysis/DXILMetadataAnalysis.h"
#include "llvm/IR/Constants.h"
+#include "llvm/IR/Function.h"
#include "llvm/IR/Module.h"
-#include <cstdint>
+#include "llvm/InitializePasses.h"
+#include "llvm/Pass.h"
using namespace llvm;
using namespace llvm::dxil;
@@ -80,7 +83,7 @@ static bool parseRootSignatureElement(ModuleRootSignature *MRS,
return true;
}
-bool ModuleRootSignature::parse(NamedMDNode *Root) {
+bool ModuleRootSignature::parse(NamedMDNode *Root, const Function *EF) {
bool HasError = false;
/** Root Signature are specified as following in the metadata:
@@ -96,11 +99,25 @@ bool ModuleRootSignature::parse(NamedMDNode *Root) {
*/
for (const MDNode *Node : Root->operands()) {
-
if (Node->getNumOperands() != 2)
return reportError("Invalid format for Root Signature Definition. Pairs "
"of function, root signature expected.");
+ Metadata *MD = Node->getOperand(0).get();
+ if (auto *VAM = llvm::dyn_cast<llvm::ValueAsMetadata>(MD)) {
+ llvm::Value *V = VAM->getValue();
+ if (Function *F = dyn_cast<Function>(V)) {
+ if (F != EF)
+ continue;
+ } else {
+ return reportError(
+ "Root Signature MD node, first element is not a function.");
+ }
+ } else {
+ return reportError(
+ "Root Signature MD node, first element is not a function.");
+ }
+
// Get the Root Signature Description from the function signature pair.
MDNode *RS = dyn_cast<MDNode>(Node->getOperand(1).get());
@@ -120,12 +137,13 @@ bool ModuleRootSignature::parse(NamedMDNode *Root) {
return HasError;
}
-ModuleRootSignature ModuleRootSignature::analyzeModule(Module &M) {
+ModuleRootSignature ModuleRootSignature::analyzeModule(Module &M,
+ const Function *F) {
ModuleRootSignature MRS;
NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
if (RootSignatureNode) {
- if (MRS.parse(RootSignatureNode))
+ if (MRS.parse(RootSignatureNode, F))
llvm_unreachable("Invalid Root Signature Metadata.");
}
@@ -136,22 +154,43 @@ AnalysisKey RootSignatureAnalysis::Key;
ModuleRootSignature RootSignatureAnalysis::run(Module &M,
ModuleAnalysisManager &AM) {
- return ModuleRootSignature::analyzeModule(M);
+ auto MMI = AM.getResult<DXILMetadataAnalysis>(M);
+
+ if (MMI.ShaderProfile == Triple::Library)
+ return ModuleRootSignature();
+
+ assert(MMI.EntryPropertyVec.size() == 1);
+
+ const Function *EntryFunction = MMI.EntryPropertyVec[0].Entry;
+ return ModuleRootSignature::analyzeModule(M, EntryFunction);
}
//===----------------------------------------------------------------------===//
bool RootSignatureAnalysisWrapper::runOnModule(Module &M) {
- this->MRS = MRS = ModuleRootSignature::analyzeModule(M);
+ dxil::ModuleMetadataInfo &MMI =
+ getAnalysis<DXILMetadataAnalysisWrapperPass>().getModuleMetadata();
+
+ if (MMI.ShaderProfile == Triple::Library)
+ return false;
+ assert(MMI.EntryPropertyVec.size() == 1);
+
+ const Function *EntryFunction = MMI.EntryPropertyVec[0].Entry;
+ this->MRS = MRS = ModuleRootSignature::analyzeModule(M, EntryFunction);
return false;
}
void RootSignatureAnalysisWrapper::getAnalysisUsage(AnalysisUsage &AU) const {
AU.setPreservesAll();
+ AU.addRequired<DXILMetadataAnalysisWrapperPass>();
}
char RootSignatureAnalysisWrapper::ID = 0;
-INITIALIZE_PASS(RootSignatureAnalysisWrapper, "dx-root-signature-analysis",
- "DXIL Root Signature Analysis", true, true)
+INITIALIZE_PASS_BEGIN(RootSignatureAnalysisWrapper,
+ "dx-root-signature-analysis",
+ "DXIL Root Signature Analysis", true, true)
+INITIALIZE_PASS_DEPENDENCY(DXILMetadataAnalysisWrapperPass)
+INITIALIZE_PASS_END(RootSignatureAnalysisWrapper, "dx-root-signature-analysis",
+ "DXIL Root Signature Analysis", true, true)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.h b/llvm/lib/Target/DirectX/DXILRootSignature.h
index 5bbea29d22ae50a..0650ffa7edf415d 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.h
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.h
@@ -34,9 +34,9 @@ struct ModuleRootSignature {
ModuleRootSignature() = default;
- bool parse(NamedMDNode *Root);
+ bool parse(NamedMDNode *Root, const Function *F);
- static ModuleRootSignature analyzeModule(Module &M);
+ static ModuleRootSignature analyzeModule(Module &M, const Function *F);
};
class RootSignatureAnalysis : public AnalysisInfoMixin<RootSignatureAnalysis> {
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
index c3e38c44c619445..cf00609a7307eb3 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags.ll
@@ -5,7 +5,6 @@ target triple = "dxil-unknown-shadermodel6.0-compute"
; CHECK: @dx.rts0 = private constant [24 x i8] c"{{.*}}", section "RTS0", align 4
-
define void @main() #0 {
entry:
ret void
>From 93f7c4c87d2f60358371eabf07bc3512ac336587 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Tue, 4 Feb 2025 01:17:18 +0000
Subject: [PATCH 44/50] separating parsing and validation
---
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 37 ++++++++++++-------
llvm/lib/Target/DirectX/DXILRootSignature.h | 7 +++-
2 files changed, 29 insertions(+), 15 deletions(-)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 984505b3fb85b81..c85291186f61807 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -29,25 +29,18 @@ static bool reportError(Twine Message) {
return true;
}
-static bool parseRootFlags(ModuleRootSignature *MRS, MDNode *RootFlagNode) {
+bool ModuleRootSignature::parseRootFlags(MDNode *RootFlagNode) {
if (RootFlagNode->getNumOperands() != 2)
return reportError("Invalid format for RootFlag Element");
auto *Flag = mdconst::extract<ConstantInt>(RootFlagNode->getOperand(1));
- uint32_t Value = Flag->getZExtValue();
+ this->Flags = Flag->getZExtValue();
- // Root Element validation, as specified:
- // https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
- if ((Value & ~0x80000fff) != 0)
- return reportError("Invalid flag value for RootFlag");
-
- MRS->Flags = Value;
return false;
}
-static bool parseRootSignatureElement(ModuleRootSignature *MRS,
- MDNode *Element) {
+bool ModuleRootSignature::parseRootSignatureElement(MDNode *Element) {
MDString *ElementText = cast<MDString>(Element->getOperand(0));
if (ElementText == nullptr)
return reportError("Invalid format for Root Element");
@@ -67,7 +60,7 @@ static bool parseRootSignatureElement(ModuleRootSignature *MRS,
switch (ElementKind) {
case RootSignatureElementKind::RootFlags: {
- return parseRootFlags(MRS, Element);
+ return parseRootFlags(Element);
break;
}
@@ -131,19 +124,35 @@ bool ModuleRootSignature::parse(NamedMDNode *Root, const Function *EF) {
if (Element == nullptr)
return reportError("Missing Root Element Metadata Node.");
- HasError = HasError || parseRootSignatureElement(this, Element);
+ HasError = HasError || parseRootSignatureElement(Element);
}
}
return HasError;
}
+bool ModuleRootSignature::validateRootFlag() {
+ // Root Element validation, as specified:
+ // https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
+ if ((Flags & ~0x80000fff) != 0)
+ return reportError("Invalid flag value for RootFlag");
+
+ return false;
+}
+
+bool ModuleRootSignature::validate() {
+ if (validateRootFlag())
+ return reportError("Invalid flag value for RootFlag");
+
+ return false;
+}
+
ModuleRootSignature ModuleRootSignature::analyzeModule(Module &M,
const Function *F) {
ModuleRootSignature MRS;
NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
if (RootSignatureNode) {
- if (MRS.parse(RootSignatureNode, F))
+ if (MRS.parse(RootSignatureNode, F) || MRS.validate())
llvm_unreachable("Invalid Root Signature Metadata.");
}
@@ -176,7 +185,7 @@ bool RootSignatureAnalysisWrapper::runOnModule(Module &M) {
assert(MMI.EntryPropertyVec.size() == 1);
const Function *EntryFunction = MMI.EntryPropertyVec[0].Entry;
- this->MRS = MRS = ModuleRootSignature::analyzeModule(M, EntryFunction);
+ MRS = ModuleRootSignature::analyzeModule(M, EntryFunction);
return false;
}
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.h b/llvm/lib/Target/DirectX/DXILRootSignature.h
index 0650ffa7edf415d..f79597721c3501f 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.h
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.h
@@ -33,10 +33,15 @@ struct ModuleRootSignature {
uint32_t Flags = 0;
ModuleRootSignature() = default;
+ static ModuleRootSignature analyzeModule(Module &M, const Function *F);
+private:
bool parse(NamedMDNode *Root, const Function *F);
+ bool parseRootSignatureElement(MDNode *Element);
+ bool parseRootFlags(MDNode *RootFlagNode);
- static ModuleRootSignature analyzeModule(Module &M, const Function *F);
+ bool validate();
+ bool validateRootFlag();
};
class RootSignatureAnalysis : public AnalysisInfoMixin<RootSignatureAnalysis> {
>From 5aac761b8a254dfa7a02c4e182091ce795cf8579 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 6 Feb 2025 01:32:09 +0000
Subject: [PATCH 45/50] improve error handling
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 12 ++----
llvm/lib/Object/DXContainer.cpp | 17 +++-----
.../lib/Target/DirectX/DXContainerGlobals.cpp | 10 +++--
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 43 ++++++++-----------
llvm/lib/Target/DirectX/DXILRootSignature.h | 27 ++++++++----
.../ContainerData/RootSignature-Error.ll | 2 +-
.../RootSignature-Flags-Error.ll | 4 +-
.../RootSignature-Flags-Validation-Error.ll | 6 +--
.../RootSignature-RootElement-Error.ll | 2 +-
9 files changed, 61 insertions(+), 62 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index c219aa819795e83..7bcf6f2bc7db58f 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -550,16 +550,12 @@ static_assert(sizeof(ProgramSignatureElement) == 32,
struct RootSignatureValidations {
- static Expected<uint32_t> validateRootFlag(uint32_t Flags) {
- if ((Flags & ~0x80000fff) != 0)
- return llvm::make_error<BinaryStreamError>("Invalid flag");
- return Flags;
+ static bool validateRootFlag(uint32_t Flags) {
+ return (Flags & ~0x80000fff) != 0;
}
- static Expected<uint32_t> validateVersion(uint32_t Version) {
- if (Version < 1 || Version > 2)
- return llvm::make_error<BinaryStreamError>("Invalid Version");
- return Version;
+ static bool validateVersion(uint32_t Version) {
+ return (Version < 1 || Version > 2);
}
};
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index 4a5f58180804512..460d4a10207b6b9 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -11,6 +11,7 @@
#include "llvm/Object/Error.h"
#include "llvm/Support/Alignment.h"
#include "llvm/Support/Endian.h"
+#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
using namespace llvm;
@@ -254,11 +255,9 @@ Error DirectX::RootSignature::parse(StringRef Data) {
support::endian::read<uint32_t, llvm::endianness::little>(Current);
Current += sizeof(uint32_t);
- Expected<uint32_t> MaybeVersion =
- dxbc::RootSignatureValidations::validateVersion(VValue);
- if (Error E = MaybeVersion.takeError())
- return E;
- Version = MaybeVersion.get();
+ if (dxbc::RootSignatureValidations::validateVersion(VValue))
+ return make_error<GenericBinaryError>("Invalid Version");
+ Version = VValue;
NumParameters =
support::endian::read<uint32_t, llvm::endianness::little>(Current);
@@ -280,11 +279,9 @@ Error DirectX::RootSignature::parse(StringRef Data) {
support::endian::read<uint32_t, llvm::endianness::little>(Current);
Current += sizeof(uint32_t);
- Expected<uint32_t> MaybeFlag =
- dxbc::RootSignatureValidations::validateRootFlag(FValue);
- if (Error E = MaybeFlag.takeError())
- return E;
- Flags = MaybeFlag.get();
+ if (dxbc::RootSignatureValidations::validateRootFlag(FValue))
+ return make_error<GenericBinaryError>("Invalid flag");
+ Flags = FValue;
return Error::success();
}
diff --git a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
index 37108f92718df81..b0f00c2735080a5 100644
--- a/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
+++ b/llvm/lib/Target/DirectX/DXContainerGlobals.cpp
@@ -152,16 +152,18 @@ void DXContainerGlobals::addSignature(Module &M,
void DXContainerGlobals::addRootSignature(Module &M,
SmallVector<GlobalValue *> &Globals) {
- std::optional<ModuleRootSignature> MRS =
- getAnalysis<RootSignatureAnalysisWrapper>().getRootSignature();
- if (!MRS.has_value())
+ auto &RSA = getAnalysis<RootSignatureAnalysisWrapper>();
+
+ if (!RSA.hasRootSignature())
return;
+ ModuleRootSignature MRS = RSA.getRootSignature();
+
SmallString<256> Data;
raw_svector_ostream OS(Data);
RootSignatureHeader RSH;
- RSH.Flags = MRS->Flags;
+ RSH.Flags = MRS.Flags;
RSH.write(OS);
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index c85291186f61807..f051de8f8c896e2 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -15,17 +15,23 @@
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/DXILMetadataAnalysis.h"
+#include "llvm/BinaryFormat/DXContainer.h"
#include "llvm/IR/Constants.h"
+#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Function.h"
+#include "llvm/IR/LLVMContext.h"
#include "llvm/IR/Module.h"
#include "llvm/InitializePasses.h"
#include "llvm/Pass.h"
+#include "llvm/Support/Error.h"
+#include <optional>
using namespace llvm;
using namespace llvm::dxil;
-static bool reportError(Twine Message) {
- report_fatal_error(Message, false);
+bool ModuleRootSignature::reportError(Twine Message,
+ DiagnosticSeverity Severity) {
+ Ctx->diagnose(DiagnosticInfoGeneric(Message, Severity));
return true;
}
@@ -130,43 +136,33 @@ bool ModuleRootSignature::parse(NamedMDNode *Root, const Function *EF) {
return HasError;
}
-bool ModuleRootSignature::validateRootFlag() {
- // Root Element validation, as specified:
- // https://github.com/llvm/wg-hlsl/blob/main/proposals/0002-root-signature-in-clang.md#validations-during-dxil-generation
- if ((Flags & ~0x80000fff) != 0)
- return reportError("Invalid flag value for RootFlag");
-
- return false;
-}
-
bool ModuleRootSignature::validate() {
- if (validateRootFlag())
+ if (dxbc::RootSignatureValidations::validateRootFlag(Flags)) {
return reportError("Invalid flag value for RootFlag");
-
+ }
return false;
}
-ModuleRootSignature ModuleRootSignature::analyzeModule(Module &M,
- const Function *F) {
- ModuleRootSignature MRS;
+OptionalRootSignature ModuleRootSignature::analyzeModule(Module &M,
+ const Function *F) {
+ ModuleRootSignature MRS(&M.getContext());
NamedMDNode *RootSignatureNode = M.getNamedMetadata("dx.rootsignatures");
- if (RootSignatureNode) {
- if (MRS.parse(RootSignatureNode, F) || MRS.validate())
- llvm_unreachable("Invalid Root Signature Metadata.");
- }
+ if (RootSignatureNode == nullptr || MRS.parse(RootSignatureNode, F) ||
+ MRS.validate())
+ return std::nullopt;
return MRS;
}
AnalysisKey RootSignatureAnalysis::Key;
-ModuleRootSignature RootSignatureAnalysis::run(Module &M,
- ModuleAnalysisManager &AM) {
+OptionalRootSignature RootSignatureAnalysis::run(Module &M,
+ ModuleAnalysisManager &AM) {
auto MMI = AM.getResult<DXILMetadataAnalysis>(M);
if (MMI.ShaderProfile == Triple::Library)
- return ModuleRootSignature();
+ return std::nullopt;
assert(MMI.EntryPropertyVec.size() == 1);
@@ -186,7 +182,6 @@ bool RootSignatureAnalysisWrapper::runOnModule(Module &M) {
const Function *EntryFunction = MMI.EntryPropertyVec[0].Entry;
MRS = ModuleRootSignature::analyzeModule(M, EntryFunction);
-
return false;
}
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.h b/llvm/lib/Target/DirectX/DXILRootSignature.h
index f79597721c3501f..da38078ad42f85d 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.h
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.h
@@ -12,10 +12,13 @@
///
//===----------------------------------------------------------------------===//
+#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/Metadata.h"
+#include "llvm/IR/Module.h"
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
#include <optional>
+#include <utility>
namespace llvm {
namespace dxil {
@@ -31,19 +34,25 @@ enum class RootSignatureElementKind {
struct ModuleRootSignature {
uint32_t Flags = 0;
-
- ModuleRootSignature() = default;
- static ModuleRootSignature analyzeModule(Module &M, const Function *F);
+ ModuleRootSignature() { Ctx = nullptr; };
+ ModuleRootSignature(LLVMContext *Ctx) : Ctx(Ctx) {}
+ static std::optional<ModuleRootSignature> analyzeModule(Module &M,
+ const Function *F);
private:
+ LLVMContext *Ctx;
+
bool parse(NamedMDNode *Root, const Function *F);
bool parseRootSignatureElement(MDNode *Element);
bool parseRootFlags(MDNode *RootFlagNode);
bool validate();
- bool validateRootFlag();
+
+ bool reportError(Twine Message, DiagnosticSeverity Severity = DS_Error);
};
+using OptionalRootSignature = std::optional<ModuleRootSignature>;
+
class RootSignatureAnalysis : public AnalysisInfoMixin<RootSignatureAnalysis> {
friend AnalysisInfoMixin<RootSignatureAnalysis>;
static AnalysisKey Key;
@@ -51,9 +60,9 @@ class RootSignatureAnalysis : public AnalysisInfoMixin<RootSignatureAnalysis> {
public:
RootSignatureAnalysis() = default;
- using Result = ModuleRootSignature;
+ using Result = OptionalRootSignature;
- ModuleRootSignature run(Module &M, ModuleAnalysisManager &AM);
+ OptionalRootSignature run(Module &M, ModuleAnalysisManager &AM);
};
/// Wrapper pass for the legacy pass manager.
@@ -61,14 +70,16 @@ class RootSignatureAnalysis : public AnalysisInfoMixin<RootSignatureAnalysis> {
/// This is required because the passes that will depend on this are codegen
/// passes which run through the legacy pass manager.
class RootSignatureAnalysisWrapper : public ModulePass {
- std::optional<ModuleRootSignature> MRS;
+private:
+ OptionalRootSignature MRS;
public:
static char ID;
RootSignatureAnalysisWrapper() : ModulePass(ID) {}
- const std::optional<ModuleRootSignature> &getRootSignature() { return MRS; }
+ const ModuleRootSignature &getRootSignature() { return MRS.value(); }
+ bool hasRootSignature() { return MRS.has_value(); }
bool runOnModule(Module &M) override;
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error.ll
index cbcd8e56c1c0463..0f0c7cc39d73b53 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: LLVM ERROR: Invalid format for Root Signature Definition. Pairs of function, root signature expected.
+; CHECK: error: Invalid format for Root Signature Definition. Pairs of function, root signature expected.
define void @main() #0 {
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Error.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Error.ll
index 9b4208011bba508..630bd5c1e3836e2 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Error.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Error.ll
@@ -1,8 +1,8 @@
-; RUN: not llc %s --filetype=obj -o - 2>&1 | FileCheck %s
+; RUN: not llc %s --filetype=obj -o -
target triple = "dxil-unknown-shadermodel6.0-compute"
-; CHECK: LLVM ERROR: Invalid Root Element: NOTRootFlags
+; expected-error at -1: Invalid Root Element: NOTRootFlags
define void @main() #0 {
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Validation-Error.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Validation-Error.ll
index 85e6f4d6748d5c4..dae3c75e70cb80b 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Validation-Error.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Flags-Validation-Error.ll
@@ -1,8 +1,6 @@
-; RUN: not llc %s --filetype=obj -o - 2>&1 | FileCheck %s
-
+; RUN: not llc %s --filetype=obj -o -
target triple = "dxil-unknown-shadermodel6.0-compute"
-
-; CHECK: LLVM ERROR: Invalid flag value for RootFlag
+; expected-error at -1: Invalid flag value for RootFlag
define void @main() #0 {
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootElement-Error.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootElement-Error.ll
index 501e3438943a3c9..80f969e849d25b1 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootElement-Error.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-RootElement-Error.ll
@@ -2,7 +2,7 @@
target triple = "dxil-unknown-shadermodel6.0-compute"
-; CHECK: LLVM ERROR: Missing Root Element Metadata Node.
+; CHECK: error: Missing Root Element Metadata Node.
define void @main() #0 {
>From 47b01f7aa435c266a05e81657a1605de62ba4a6f Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 6 Feb 2025 18:31:30 +0000
Subject: [PATCH 46/50] clean up
---
llvm/lib/Object/DXContainer.cpp | 1 -
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 28 ++++++++-----------
llvm/lib/Target/DirectX/DXILRootSignature.h | 3 +-
3 files changed, 14 insertions(+), 18 deletions(-)
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index 460d4a10207b6b9..5c37d0ae6f9a4ba 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -11,7 +11,6 @@
#include "llvm/Object/Error.h"
#include "llvm/Support/Alignment.h"
#include "llvm/Support/Endian.h"
-#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
using namespace llvm;
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index f051de8f8c896e2..dd0c7618c728d34 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -102,30 +102,26 @@ bool ModuleRootSignature::parse(NamedMDNode *Root, const Function *EF) {
return reportError("Invalid format for Root Signature Definition. Pairs "
"of function, root signature expected.");
- Metadata *MD = Node->getOperand(0).get();
- if (auto *VAM = llvm::dyn_cast<llvm::ValueAsMetadata>(MD)) {
- llvm::Value *V = VAM->getValue();
- if (Function *F = dyn_cast<Function>(V)) {
- if (F != EF)
- continue;
- } else {
- return reportError(
- "Root Signature MD node, first element is not a function.");
- }
- } else {
- return reportError(
- "Root Signature MD node, first element is not a function.");
- }
+ ValueAsMetadata *VAM =
+ llvm::dyn_cast<ValueAsMetadata>(Node->getOperand(0).get());
+ if (VAM == nullptr)
+ return reportError("First element of root signature is not a value");
+
+ Function *F = dyn_cast<Function>(VAM->getValue());
+ if (F == nullptr)
+ return reportError("First element of root signature is not a function");
+
+ if (F != EF)
+ continue;
// Get the Root Signature Description from the function signature pair.
MDNode *RS = dyn_cast<MDNode>(Node->getOperand(1).get());
if (RS == nullptr)
- return reportError("Missing Root Signature Metadata node.");
+ return reportError("Missing Root Element List Metadata node.");
// Loop through the Root Elements of the root signature.
for (unsigned int Eid = 0; Eid < RS->getNumOperands(); Eid++) {
-
MDNode *Element = dyn_cast<MDNode>(RS->getOperand(Eid));
if (Element == nullptr)
return reportError("Missing Root Element Metadata Node.");
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.h b/llvm/lib/Target/DirectX/DXILRootSignature.h
index da38078ad42f85d..9bb95102952b3dd 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.h
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.h
@@ -35,13 +35,14 @@ enum class RootSignatureElementKind {
struct ModuleRootSignature {
uint32_t Flags = 0;
ModuleRootSignature() { Ctx = nullptr; };
- ModuleRootSignature(LLVMContext *Ctx) : Ctx(Ctx) {}
static std::optional<ModuleRootSignature> analyzeModule(Module &M,
const Function *F);
private:
LLVMContext *Ctx;
+ ModuleRootSignature(LLVMContext *Ctx) : Ctx(Ctx) {}
+
bool parse(NamedMDNode *Root, const Function *F);
bool parseRootSignatureElement(MDNode *Element);
bool parseRootFlags(MDNode *RootFlagNode);
>From 486ab883257d99206cf66e33c89ebf5acc586f47 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 6 Feb 2025 22:04:48 +0000
Subject: [PATCH 47/50] clean up
---
llvm/lib/Target/DirectX/DXILRootSignature.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.h b/llvm/lib/Target/DirectX/DXILRootSignature.h
index 9bb95102952b3dd..dd19fd97165ee21 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.h
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.h
@@ -18,7 +18,6 @@
#include "llvm/IR/PassManager.h"
#include "llvm/Pass.h"
#include <optional>
-#include <utility>
namespace llvm {
namespace dxil {
@@ -80,6 +79,7 @@ class RootSignatureAnalysisWrapper : public ModulePass {
RootSignatureAnalysisWrapper() : ModulePass(ID) {}
const ModuleRootSignature &getRootSignature() { return MRS.value(); }
+
bool hasRootSignature() { return MRS.has_value(); }
bool runOnModule(Module &M) override;
>From 852ac25e3989ecc3d36d93ebd776afdf8a850de0 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 6 Feb 2025 22:12:25 +0000
Subject: [PATCH 48/50] formating
---
llvm/lib/Target/DirectX/DXILRootSignature.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.h b/llvm/lib/Target/DirectX/DXILRootSignature.h
index dd19fd97165ee21..eb3fcbcbc5701f1 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.h
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.h
@@ -79,7 +79,7 @@ class RootSignatureAnalysisWrapper : public ModulePass {
RootSignatureAnalysisWrapper() : ModulePass(ID) {}
const ModuleRootSignature &getRootSignature() { return MRS.value(); }
-
+
bool hasRootSignature() { return MRS.has_value(); }
bool runOnModule(Module &M) override;
>From 74f722698fa3058dc2e6ad1bde6f4b22869a4a86 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Fri, 7 Feb 2025 18:26:44 +0000
Subject: [PATCH 49/50] addressing comments and fix tests
---
llvm/include/llvm/BinaryFormat/DXContainer.h | 5 +++--
llvm/lib/Object/DXContainer.cpp | 6 +++---
llvm/unittests/Object/DXContainerTest.cpp | 18 ++++++++++++------
3 files changed, 18 insertions(+), 11 deletions(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainer.h b/llvm/include/llvm/BinaryFormat/DXContainer.h
index c219aa819795e83..548760afc08e8b7 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainer.h
+++ b/llvm/include/llvm/BinaryFormat/DXContainer.h
@@ -552,13 +552,14 @@ struct RootSignatureValidations {
static Expected<uint32_t> validateRootFlag(uint32_t Flags) {
if ((Flags & ~0x80000fff) != 0)
- return llvm::make_error<BinaryStreamError>("Invalid flag");
+ return llvm::make_error<BinaryStreamError>("Invalid Root Signature flag");
return Flags;
}
static Expected<uint32_t> validateVersion(uint32_t Version) {
if (Version < 1 || Version > 2)
- return llvm::make_error<BinaryStreamError>("Invalid Version");
+ return llvm::make_error<BinaryStreamError>(
+ "Invalid Root Signature Version");
return Version;
}
};
diff --git a/llvm/lib/Object/DXContainer.cpp b/llvm/lib/Object/DXContainer.cpp
index 4a5f58180804512..f28b096008b2fd6 100644
--- a/llvm/lib/Object/DXContainer.cpp
+++ b/llvm/lib/Object/DXContainer.cpp
@@ -246,9 +246,9 @@ Error DirectX::RootSignature::parse(StringRef Data) {
const char *Current = Data.begin();
// Root Signature headers expects 6 integers to be present.
- if (Data.size() < 6 * sizeof(uint32_t)) {
- return parseFailed("Invalid data. Too small.");
- }
+ if (Data.size() < 6 * sizeof(uint32_t))
+ return parseFailed(
+ "Invalid root signature, insufficient space for header.");
uint32_t VValue =
support::endian::read<uint32_t, llvm::endianness::little>(Current);
diff --git a/llvm/unittests/Object/DXContainerTest.cpp b/llvm/unittests/Object/DXContainerTest.cpp
index 8489b05f8b33132..88a915f560e05f4 100644
--- a/llvm/unittests/Object/DXContainerTest.cpp
+++ b/llvm/unittests/Object/DXContainerTest.cpp
@@ -855,8 +855,10 @@ TEST(RootSignature, ParseRootFlags) {
0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
};
- EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<64>(Buffer)),
- FailedWithMessage("Invalid data. Too small."));
+ EXPECT_THAT_EXPECTED(
+ DXContainer::create(getMemoryBuffer<64>(Buffer)),
+ FailedWithMessage(
+ "Invalid root signature, insufficient space for header."));
}
{
// Version has been changed to an invalid number.
@@ -868,8 +870,10 @@ TEST(RootSignature, ParseRootFlags) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
};
- EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<68>(Buffer)),
- FailedWithMessage("Invalid Version"));
+ EXPECT_THAT_EXPECTED(
+ DXContainer::create(getMemoryBuffer<68>(Buffer)),
+ FailedWithMessage("Stream Error: An unspecified error has occurred. "
+ "Invalid Root Signature Version"));
}
{
// Flag has been set to an invalid value
@@ -881,7 +885,9 @@ TEST(RootSignature, ParseRootFlags) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xFF,
};
- EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<68>(Buffer)),
- FailedWithMessage("Invalid flag"));
+ EXPECT_THAT_EXPECTED(
+ DXContainer::create(getMemoryBuffer<68>(Buffer)),
+ FailedWithMessage("Stream Error: An unspecified error has occurred. "
+ "Invalid Root Signature flag"));
}
}
>From c67d039ac978adc8abb6e0f2195f92be95cbbefa Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Fri, 7 Feb 2025 19:56:57 +0000
Subject: [PATCH 50/50] formating
---
llvm/unittests/Object/DXContainerTest.cpp | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
diff --git a/llvm/unittests/Object/DXContainerTest.cpp b/llvm/unittests/Object/DXContainerTest.cpp
index 1fd0e973ddfd38d..bafde7334fbbc4f 100644
--- a/llvm/unittests/Object/DXContainerTest.cpp
+++ b/llvm/unittests/Object/DXContainerTest.cpp
@@ -870,9 +870,8 @@ TEST(RootSignature, ParseRootFlags) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
};
- EXPECT_THAT_EXPECTED(
- DXContainer::create(getMemoryBuffer<68>(Buffer)),
- FailedWithMessage("Invalid Root Signature Version"));
+ EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<68>(Buffer)),
+ FailedWithMessage("Invalid Root Signature Version"));
}
{
// Flag has been set to an invalid value
@@ -884,8 +883,7 @@ TEST(RootSignature, ParseRootFlags) {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0xFF,
};
- EXPECT_THAT_EXPECTED(
- DXContainer::create(getMemoryBuffer<68>(Buffer)),
- FailedWithMessage("Invalid Root Signature flag"));
+ EXPECT_THAT_EXPECTED(DXContainer::create(getMemoryBuffer<68>(Buffer)),
+ FailedWithMessage("Invalid Root Signature flag"));
}
}
More information about the llvm-commits
mailing list