[llvm-branch-commits] [llvm] [HLSL] Add descriptor table metadata parsing (PR #142492)
https://github.com/joaosaffran edited https://github.com/llvm/llvm-project/pull/142492 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [HLSL] Add descriptor table metadata parsing (PR #142492)
https://github.com/joaosaffran edited https://github.com/llvm/llvm-project/pull/142492 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [HLSL] Add descriptor table metadata parsing (PR #142492)
https://github.com/joaosaffran edited https://github.com/llvm/llvm-project/pull/142492 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [HLSL] Add descriptor table metadata parsing (PR #142492)
https://github.com/joaosaffran updated
https://github.com/llvm/llvm-project/pull/142492
>From 3e6b07e119988058defd305199ad3e08d424eebd Mon Sep 17 00:00:00 2001
From: joaosaffran
Date: Mon, 2 Jun 2025 19:36:32 +
Subject: [PATCH 1/6] add parsing
---
.../BinaryFormat/DXContainerConstants.def | 11 ++
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 176 ++
llvm/lib/Target/DirectX/DXILRootSignature.h | 3 +-
3 files changed, 189 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index 501ef0c31cdd0..fa66450c563c4 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -98,6 +98,17 @@ DESCRIPTOR_RANGE_FLAG(16,
DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS)
#undef DESCRIPTOR_RANGE_FLAG
#endif // DESCRIPTOR_RANGE_FLAG
+// DESCRIPTOR_RANGE(value, name).
+#ifdef DESCRIPTOR_RANGE
+ DESCRIPTOR_RANGE(4, ERROR)
+ DESCRIPTOR_RANGE(0, SRV)
+ DESCRIPTOR_RANGE(1, UAV)
+ DESCRIPTOR_RANGE(2, CBV)
+ DESCRIPTOR_RANGE(3, Sampler)
+DESCRIPTOR_RANGE(0, NONE)
+#undef DESCRIPTOR_RANGE
+#endif // DESCRIPTOR_RANGE
+
#ifdef ROOT_PARAMETER
ROOT_PARAMETER(0, DescriptorTable)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 878272537d366..a14a9fdce5cbd 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -12,6 +12,7 @@
//===--===//
#include "DXILRootSignature.h"
#include "DirectX.h"
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/DXILMetadataAnalysis.h"
@@ -27,6 +28,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
+#include
#include
#include
#include
@@ -166,6 +168,88 @@ static bool parseRootDescriptors(LLVMContext *Ctx,
return false;
}
+static bool parseDescriptorRange(LLVMContext *Ctx,
+ mcdxbc::RootSignatureDesc &RSD,
+ mcdxbc::DescriptorTable &Table,
+ MDNode *RangeDescriptorNode) {
+
+ if (RangeDescriptorNode->getNumOperands() != 6)
+return reportError(Ctx, "Invalid format for Descriptor Range");
+
+ dxbc::RTS0::v2::DescriptorRange Range;
+
+ std::optional ElementText =
+ extractMdStringValue(RangeDescriptorNode, 0);
+
+ if (!ElementText.has_value())
+return reportError(Ctx, "Descriptor Range, first element is not a
string.");
+
+ Range.RangeType =
+ StringSwitch(*ElementText)
+ .Case("CBV", llvm::to_underlying(dxbc::DescriptorRangeType::CBV))
+ .Case("SRV", llvm::to_underlying(dxbc::DescriptorRangeType::SRV))
+ .Case("UAV", llvm::to_underlying(dxbc::DescriptorRangeType::UAV))
+ .Case("Sampler",
+llvm::to_underlying(dxbc::DescriptorRangeType::Sampler))
+ .Default(llvm::to_underlying(dxbc::DescriptorRangeType::ERROR));
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 1))
+Range.NumDescriptors = *Val;
+ else
+return reportError(Ctx, "Invalid value for Number of Descriptor in Range");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 2))
+Range.BaseShaderRegister = *Val;
+ else
+return reportError(Ctx, "Invalid value for BaseShaderRegister");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 3))
+Range.RegisterSpace = *Val;
+ else
+return reportError(Ctx, "Invalid value for RegisterSpace");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 4))
+Range.OffsetInDescriptorsFromTableStart = *Val;
+ else
+return reportError(Ctx,
+ "Invalid value for OffsetInDescriptorsFromTableStart");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 5))
+Range.Flags = *Val;
+ else
+return reportError(Ctx, "Invalid value for Descriptor Range Flags");
+
+ Table.Ranges.push_back(Range);
+ return false;
+}
+
+static bool parseDescriptorTable(LLVMContext *Ctx,
+ mcdxbc::RootSignatureDesc &RSD,
+ MDNode *DescriptorTableNode) {
+ if (DescriptorTableNode->getNumOperands() < 2)
+return reportError(Ctx, "Invalid format for Descriptor Table");
+
+ dxbc::RTS0::v1::RootParameterHeader Header;
+ if (std::optional Val = extractMdIntValue(DescriptorTableNode, 1))
+Header.ShaderVisibility = *Val;
+ else
+return reportError(Ctx, "Invalid value for ShaderVisibility");
+
+ mcdxbc::DescriptorTable Table;
+
+ for (unsigned int I = 2; I < DescriptorTableNode->getNumOperands(); I++) {
+MDNode *Element = dyn_cast(DescriptorTableNode->getOperand(I));
+if (Element == nullptr
[llvm-branch-commits] [llvm] [HLSL] Add descriptor table metadata parsing (PR #142492)
github-actions[bot] wrote:
:warning: C/C++ code formatter, clang-format found issues in your code.
:warning:
You can test this locally with the following command:
``bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp,h --
llvm/lib/Target/DirectX/DXILRootSignature.cpp
llvm/lib/Target/DirectX/DXILRootSignature.h
``
View the diff from clang-format here.
``diff
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index cd25cca0e..5dbd5887f 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -451,7 +451,7 @@ static bool validate(LLVMContext *Ctx, const
mcdxbc::RootSignatureDesc &RSD) {
return reportValueError(Ctx, "RegisterSpace", Range.RegisterSpace);
if (!verifyDescriptorRangeFlag(RSD.Version, Range.RangeType,
-Range.Flags))
+ Range.Flags))
return reportValueError(Ctx, "DescriptorFlag", Range.Flags);
}
break;
``
https://github.com/llvm/llvm-project/pull/142492
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [HLSL] Add descriptor table metadata parsing (PR #142492)
https://github.com/joaosaffran updated
https://github.com/llvm/llvm-project/pull/142492
>From 3e6b07e119988058defd305199ad3e08d424eebd Mon Sep 17 00:00:00 2001
From: joaosaffran
Date: Mon, 2 Jun 2025 19:36:32 +
Subject: [PATCH 1/5] add parsing
---
.../BinaryFormat/DXContainerConstants.def | 11 ++
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 176 ++
llvm/lib/Target/DirectX/DXILRootSignature.h | 3 +-
3 files changed, 189 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index 501ef0c31cdd0..fa66450c563c4 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -98,6 +98,17 @@ DESCRIPTOR_RANGE_FLAG(16,
DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS)
#undef DESCRIPTOR_RANGE_FLAG
#endif // DESCRIPTOR_RANGE_FLAG
+// DESCRIPTOR_RANGE(value, name).
+#ifdef DESCRIPTOR_RANGE
+ DESCRIPTOR_RANGE(4, ERROR)
+ DESCRIPTOR_RANGE(0, SRV)
+ DESCRIPTOR_RANGE(1, UAV)
+ DESCRIPTOR_RANGE(2, CBV)
+ DESCRIPTOR_RANGE(3, Sampler)
+DESCRIPTOR_RANGE(0, NONE)
+#undef DESCRIPTOR_RANGE
+#endif // DESCRIPTOR_RANGE
+
#ifdef ROOT_PARAMETER
ROOT_PARAMETER(0, DescriptorTable)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 878272537d366..a14a9fdce5cbd 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -12,6 +12,7 @@
//===--===//
#include "DXILRootSignature.h"
#include "DirectX.h"
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/DXILMetadataAnalysis.h"
@@ -27,6 +28,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
+#include
#include
#include
#include
@@ -166,6 +168,88 @@ static bool parseRootDescriptors(LLVMContext *Ctx,
return false;
}
+static bool parseDescriptorRange(LLVMContext *Ctx,
+ mcdxbc::RootSignatureDesc &RSD,
+ mcdxbc::DescriptorTable &Table,
+ MDNode *RangeDescriptorNode) {
+
+ if (RangeDescriptorNode->getNumOperands() != 6)
+return reportError(Ctx, "Invalid format for Descriptor Range");
+
+ dxbc::RTS0::v2::DescriptorRange Range;
+
+ std::optional ElementText =
+ extractMdStringValue(RangeDescriptorNode, 0);
+
+ if (!ElementText.has_value())
+return reportError(Ctx, "Descriptor Range, first element is not a
string.");
+
+ Range.RangeType =
+ StringSwitch(*ElementText)
+ .Case("CBV", llvm::to_underlying(dxbc::DescriptorRangeType::CBV))
+ .Case("SRV", llvm::to_underlying(dxbc::DescriptorRangeType::SRV))
+ .Case("UAV", llvm::to_underlying(dxbc::DescriptorRangeType::UAV))
+ .Case("Sampler",
+llvm::to_underlying(dxbc::DescriptorRangeType::Sampler))
+ .Default(llvm::to_underlying(dxbc::DescriptorRangeType::ERROR));
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 1))
+Range.NumDescriptors = *Val;
+ else
+return reportError(Ctx, "Invalid value for Number of Descriptor in Range");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 2))
+Range.BaseShaderRegister = *Val;
+ else
+return reportError(Ctx, "Invalid value for BaseShaderRegister");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 3))
+Range.RegisterSpace = *Val;
+ else
+return reportError(Ctx, "Invalid value for RegisterSpace");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 4))
+Range.OffsetInDescriptorsFromTableStart = *Val;
+ else
+return reportError(Ctx,
+ "Invalid value for OffsetInDescriptorsFromTableStart");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 5))
+Range.Flags = *Val;
+ else
+return reportError(Ctx, "Invalid value for Descriptor Range Flags");
+
+ Table.Ranges.push_back(Range);
+ return false;
+}
+
+static bool parseDescriptorTable(LLVMContext *Ctx,
+ mcdxbc::RootSignatureDesc &RSD,
+ MDNode *DescriptorTableNode) {
+ if (DescriptorTableNode->getNumOperands() < 2)
+return reportError(Ctx, "Invalid format for Descriptor Table");
+
+ dxbc::RTS0::v1::RootParameterHeader Header;
+ if (std::optional Val = extractMdIntValue(DescriptorTableNode, 1))
+Header.ShaderVisibility = *Val;
+ else
+return reportError(Ctx, "Invalid value for ShaderVisibility");
+
+ mcdxbc::DescriptorTable Table;
+
+ for (unsigned int I = 2; I < DescriptorTableNode->getNumOperands(); I++) {
+MDNode *Element = dyn_cast(DescriptorTableNode->getOperand(I));
+if (Element == nullptr
[llvm-branch-commits] [llvm] [HLSL] Add descriptor table metadata parsing (PR #142492)
https://github.com/joaosaffran updated
https://github.com/llvm/llvm-project/pull/142492
>From 3e6b07e119988058defd305199ad3e08d424eebd Mon Sep 17 00:00:00 2001
From: joaosaffran
Date: Mon, 2 Jun 2025 19:36:32 +
Subject: [PATCH 1/5] add parsing
---
.../BinaryFormat/DXContainerConstants.def | 11 ++
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 176 ++
llvm/lib/Target/DirectX/DXILRootSignature.h | 3 +-
3 files changed, 189 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index 501ef0c31cdd0..fa66450c563c4 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -98,6 +98,17 @@ DESCRIPTOR_RANGE_FLAG(16,
DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS)
#undef DESCRIPTOR_RANGE_FLAG
#endif // DESCRIPTOR_RANGE_FLAG
+// DESCRIPTOR_RANGE(value, name).
+#ifdef DESCRIPTOR_RANGE
+ DESCRIPTOR_RANGE(4, ERROR)
+ DESCRIPTOR_RANGE(0, SRV)
+ DESCRIPTOR_RANGE(1, UAV)
+ DESCRIPTOR_RANGE(2, CBV)
+ DESCRIPTOR_RANGE(3, Sampler)
+DESCRIPTOR_RANGE(0, NONE)
+#undef DESCRIPTOR_RANGE
+#endif // DESCRIPTOR_RANGE
+
#ifdef ROOT_PARAMETER
ROOT_PARAMETER(0, DescriptorTable)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 878272537d366..a14a9fdce5cbd 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -12,6 +12,7 @@
//===--===//
#include "DXILRootSignature.h"
#include "DirectX.h"
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/DXILMetadataAnalysis.h"
@@ -27,6 +28,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
+#include
#include
#include
#include
@@ -166,6 +168,88 @@ static bool parseRootDescriptors(LLVMContext *Ctx,
return false;
}
+static bool parseDescriptorRange(LLVMContext *Ctx,
+ mcdxbc::RootSignatureDesc &RSD,
+ mcdxbc::DescriptorTable &Table,
+ MDNode *RangeDescriptorNode) {
+
+ if (RangeDescriptorNode->getNumOperands() != 6)
+return reportError(Ctx, "Invalid format for Descriptor Range");
+
+ dxbc::RTS0::v2::DescriptorRange Range;
+
+ std::optional ElementText =
+ extractMdStringValue(RangeDescriptorNode, 0);
+
+ if (!ElementText.has_value())
+return reportError(Ctx, "Descriptor Range, first element is not a
string.");
+
+ Range.RangeType =
+ StringSwitch(*ElementText)
+ .Case("CBV", llvm::to_underlying(dxbc::DescriptorRangeType::CBV))
+ .Case("SRV", llvm::to_underlying(dxbc::DescriptorRangeType::SRV))
+ .Case("UAV", llvm::to_underlying(dxbc::DescriptorRangeType::UAV))
+ .Case("Sampler",
+llvm::to_underlying(dxbc::DescriptorRangeType::Sampler))
+ .Default(llvm::to_underlying(dxbc::DescriptorRangeType::ERROR));
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 1))
+Range.NumDescriptors = *Val;
+ else
+return reportError(Ctx, "Invalid value for Number of Descriptor in Range");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 2))
+Range.BaseShaderRegister = *Val;
+ else
+return reportError(Ctx, "Invalid value for BaseShaderRegister");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 3))
+Range.RegisterSpace = *Val;
+ else
+return reportError(Ctx, "Invalid value for RegisterSpace");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 4))
+Range.OffsetInDescriptorsFromTableStart = *Val;
+ else
+return reportError(Ctx,
+ "Invalid value for OffsetInDescriptorsFromTableStart");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 5))
+Range.Flags = *Val;
+ else
+return reportError(Ctx, "Invalid value for Descriptor Range Flags");
+
+ Table.Ranges.push_back(Range);
+ return false;
+}
+
+static bool parseDescriptorTable(LLVMContext *Ctx,
+ mcdxbc::RootSignatureDesc &RSD,
+ MDNode *DescriptorTableNode) {
+ if (DescriptorTableNode->getNumOperands() < 2)
+return reportError(Ctx, "Invalid format for Descriptor Table");
+
+ dxbc::RTS0::v1::RootParameterHeader Header;
+ if (std::optional Val = extractMdIntValue(DescriptorTableNode, 1))
+Header.ShaderVisibility = *Val;
+ else
+return reportError(Ctx, "Invalid value for ShaderVisibility");
+
+ mcdxbc::DescriptorTable Table;
+
+ for (unsigned int I = 2; I < DescriptorTableNode->getNumOperands(); I++) {
+MDNode *Element = dyn_cast(DescriptorTableNode->getOperand(I));
+if (Element == nullptr
[llvm-branch-commits] [llvm] [HLSL] Add descriptor table metadata parsing (PR #142492)
https://github.com/joaosaffran created
https://github.com/llvm/llvm-project/pull/142492
- adds parsing from metadata into dxcontainer binary
- adds validations as described in the spec
- adds testing scenarios
Closes: #[126640](https://github.com/llvm/llvm-project/issues/126640)
>From 3e6b07e119988058defd305199ad3e08d424eebd Mon Sep 17 00:00:00 2001
From: joaosaffran
Date: Mon, 2 Jun 2025 19:36:32 +
Subject: [PATCH 1/4] add parsing
---
.../BinaryFormat/DXContainerConstants.def | 11 ++
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 176 ++
llvm/lib/Target/DirectX/DXILRootSignature.h | 3 +-
3 files changed, 189 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index 501ef0c31cdd0..fa66450c563c4 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -98,6 +98,17 @@ DESCRIPTOR_RANGE_FLAG(16,
DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS)
#undef DESCRIPTOR_RANGE_FLAG
#endif // DESCRIPTOR_RANGE_FLAG
+// DESCRIPTOR_RANGE(value, name).
+#ifdef DESCRIPTOR_RANGE
+ DESCRIPTOR_RANGE(4, ERROR)
+ DESCRIPTOR_RANGE(0, SRV)
+ DESCRIPTOR_RANGE(1, UAV)
+ DESCRIPTOR_RANGE(2, CBV)
+ DESCRIPTOR_RANGE(3, Sampler)
+DESCRIPTOR_RANGE(0, NONE)
+#undef DESCRIPTOR_RANGE
+#endif // DESCRIPTOR_RANGE
+
#ifdef ROOT_PARAMETER
ROOT_PARAMETER(0, DescriptorTable)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 878272537d366..a14a9fdce5cbd 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -12,6 +12,7 @@
//===--===//
#include "DXILRootSignature.h"
#include "DirectX.h"
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/DXILMetadataAnalysis.h"
@@ -27,6 +28,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
+#include
#include
#include
#include
@@ -166,6 +168,88 @@ static bool parseRootDescriptors(LLVMContext *Ctx,
return false;
}
+static bool parseDescriptorRange(LLVMContext *Ctx,
+ mcdxbc::RootSignatureDesc &RSD,
+ mcdxbc::DescriptorTable &Table,
+ MDNode *RangeDescriptorNode) {
+
+ if (RangeDescriptorNode->getNumOperands() != 6)
+return reportError(Ctx, "Invalid format for Descriptor Range");
+
+ dxbc::RTS0::v2::DescriptorRange Range;
+
+ std::optional ElementText =
+ extractMdStringValue(RangeDescriptorNode, 0);
+
+ if (!ElementText.has_value())
+return reportError(Ctx, "Descriptor Range, first element is not a
string.");
+
+ Range.RangeType =
+ StringSwitch(*ElementText)
+ .Case("CBV", llvm::to_underlying(dxbc::DescriptorRangeType::CBV))
+ .Case("SRV", llvm::to_underlying(dxbc::DescriptorRangeType::SRV))
+ .Case("UAV", llvm::to_underlying(dxbc::DescriptorRangeType::UAV))
+ .Case("Sampler",
+llvm::to_underlying(dxbc::DescriptorRangeType::Sampler))
+ .Default(llvm::to_underlying(dxbc::DescriptorRangeType::ERROR));
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 1))
+Range.NumDescriptors = *Val;
+ else
+return reportError(Ctx, "Invalid value for Number of Descriptor in Range");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 2))
+Range.BaseShaderRegister = *Val;
+ else
+return reportError(Ctx, "Invalid value for BaseShaderRegister");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 3))
+Range.RegisterSpace = *Val;
+ else
+return reportError(Ctx, "Invalid value for RegisterSpace");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 4))
+Range.OffsetInDescriptorsFromTableStart = *Val;
+ else
+return reportError(Ctx,
+ "Invalid value for OffsetInDescriptorsFromTableStart");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 5))
+Range.Flags = *Val;
+ else
+return reportError(Ctx, "Invalid value for Descriptor Range Flags");
+
+ Table.Ranges.push_back(Range);
+ return false;
+}
+
+static bool parseDescriptorTable(LLVMContext *Ctx,
+ mcdxbc::RootSignatureDesc &RSD,
+ MDNode *DescriptorTableNode) {
+ if (DescriptorTableNode->getNumOperands() < 2)
+return reportError(Ctx, "Invalid format for Descriptor Table");
+
+ dxbc::RTS0::v1::RootParameterHeader Header;
+ if (std::optional Val = extractMdIntValue(DescriptorTableNode, 1))
+Header.ShaderVisibility = *Val;
+ else
+return reportError(Ctx, "Invalid value for ShaderVisibility");
+
+ mcdxbc::Descri
[llvm-branch-commits] [llvm] [HLSL] Add descriptor table metadata parsing (PR #142492)
https://github.com/joaosaffran unassigned https://github.com/llvm/llvm-project/pull/142492 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [HLSL] Add descriptor table metadata parsing (PR #142492)
llvmbot wrote:
@llvm/pr-subscribers-backend-directx
@llvm/pr-subscribers-llvm-binary-utilities
Author: None (joaosaffran)
Changes
- adds parsing from metadata into dxcontainer binary
- adds validations as described in the spec
- adds testing scenarios
Closes: #[126640](https://github.com/llvm/llvm-project/issues/126640)
---
Patch is 20.71 KiB, truncated to 20.00 KiB below, full version:
https://github.com/llvm/llvm-project/pull/142492.diff
8 Files Affected:
- (modified) llvm/include/llvm/BinaryFormat/DXContainerConstants.def (+11)
- (modified) llvm/lib/Target/DirectX/DXILRootSignature.cpp (+201-5)
- (modified) llvm/lib/Target/DirectX/DXILRootSignature.h (+2-1)
- (added)
llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable-Invalid-Flag.ll
(+20)
- (added)
llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable-Invalid-RangeType.ll
(+20)
- (added)
llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable-Invalid-RegisterSpace.ll
(+20)
- (added)
llvm/test/CodeGen/DirectX/ContainerData/RootSignature-DescriptorTable.ll (+48)
- (modified)
llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Parameters.ll (+20-2)
``diff
diff --git a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
index 501ef0c31cdd0..fa66450c563c4 100644
--- a/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
+++ b/llvm/include/llvm/BinaryFormat/DXContainerConstants.def
@@ -98,6 +98,17 @@ DESCRIPTOR_RANGE_FLAG(16,
DESCRIPTORS_STATIC_KEEPING_BUFFER_BOUNDS_CHECKS)
#undef DESCRIPTOR_RANGE_FLAG
#endif // DESCRIPTOR_RANGE_FLAG
+// DESCRIPTOR_RANGE(value, name).
+#ifdef DESCRIPTOR_RANGE
+ DESCRIPTOR_RANGE(4, ERROR)
+ DESCRIPTOR_RANGE(0, SRV)
+ DESCRIPTOR_RANGE(1, UAV)
+ DESCRIPTOR_RANGE(2, CBV)
+ DESCRIPTOR_RANGE(3, Sampler)
+DESCRIPTOR_RANGE(0, NONE)
+#undef DESCRIPTOR_RANGE
+#endif // DESCRIPTOR_RANGE
+
#ifdef ROOT_PARAMETER
ROOT_PARAMETER(0, DescriptorTable)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 878272537d366..33a74d71027aa 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -12,6 +12,7 @@
//===--===//
#include "DXILRootSignature.h"
#include "DirectX.h"
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/DXILMetadataAnalysis.h"
@@ -27,6 +28,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
+#include
#include
#include
#include
@@ -166,6 +168,90 @@ static bool parseRootDescriptors(LLVMContext *Ctx,
return false;
}
+static bool parseDescriptorRange(LLVMContext *Ctx,
+ mcdxbc::RootSignatureDesc &RSD,
+ mcdxbc::DescriptorTable &Table,
+ MDNode *RangeDescriptorNode) {
+
+ if (RangeDescriptorNode->getNumOperands() != 6)
+return reportError(Ctx, "Invalid format for Descriptor Range");
+
+ dxbc::RTS0::v2::DescriptorRange Range;
+
+ std::optional ElementText =
+ extractMdStringValue(RangeDescriptorNode, 0);
+
+ if (!ElementText.has_value())
+return reportError(Ctx, "Descriptor Range, first element is not a
string.");
+
+ Range.RangeType =
+ StringSwitch(*ElementText)
+ .Case("CBV", llvm::to_underlying(dxbc::DescriptorRangeType::CBV))
+ .Case("SRV", llvm::to_underlying(dxbc::DescriptorRangeType::SRV))
+ .Case("UAV", llvm::to_underlying(dxbc::DescriptorRangeType::UAV))
+ .Case("Sampler",
+llvm::to_underlying(dxbc::DescriptorRangeType::Sampler))
+ .Default(llvm::to_underlying(dxbc::DescriptorRangeType::ERROR));
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 1))
+Range.NumDescriptors = *Val;
+ else
+return reportError(Ctx, "Invalid value for Number of Descriptor in Range");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 2))
+Range.BaseShaderRegister = *Val;
+ else
+return reportError(Ctx, "Invalid value for BaseShaderRegister");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 3))
+Range.RegisterSpace = *Val;
+ else
+return reportError(Ctx, "Invalid value for RegisterSpace");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 4))
+Range.OffsetInDescriptorsFromTableStart = *Val;
+ else
+return reportError(Ctx,
+ "Invalid value for OffsetInDescriptorsFromTableStart");
+
+ if (std::optional Val = extractMdIntValue(RangeDescriptorNode, 5))
+Range.Flags = *Val;
+ else
+return reportError(Ctx, "Invalid value for Descriptor Range Flags");
+
+ Table.Ranges.push_back(Range);
+ return false;
+}
+
+static bool parseDescri
