[llvm-branch-commits] [llvm] [DirectX] Add static sampler support to root signature (PR #143422)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Jun 12 16:50:55 PDT 2025
https://github.com/joaosaffran updated https://github.com/llvm/llvm-project/pull/143422
>From 9f51858f2050720c50c09ddd18108d3bcde5a68b Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Wed, 4 Jun 2025 21:42:20 +0000
Subject: [PATCH 1/6] adding metadata support for static samplers
---
llvm/lib/MC/DXContainerRootSignature.cpp | 42 +++++----
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 89 +++++++++++++++++++
llvm/lib/Target/DirectX/DXILRootSignature.h | 1 +
.../RootSignature-StaticSamplers.ll | 42 +++++++++
4 files changed, 157 insertions(+), 17 deletions(-)
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers.ll
diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp
index 6c71823a51f85..d67babf13a432 100644
--- a/llvm/lib/MC/DXContainerRootSignature.cpp
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -9,6 +9,7 @@
#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/EndianStream.h"
+#include <cstdint>
using namespace llvm;
using namespace llvm::mcdxbc;
@@ -71,12 +72,16 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
BOS.reserveExtraSpace(getSize());
const uint32_t NumParameters = ParametersContainer.size();
-
+ const uint32_t NumSamplers = StaticSamplers.size();
support::endian::write(BOS, Version, llvm::endianness::little);
support::endian::write(BOS, NumParameters, llvm::endianness::little);
support::endian::write(BOS, RootParameterOffset, llvm::endianness::little);
- support::endian::write(BOS, NumStaticSamplers, llvm::endianness::little);
- support::endian::write(BOS, StaticSamplersOffset, llvm::endianness::little);
+ support::endian::write(BOS, NumSamplers, llvm::endianness::little);
+ uint32_t SSO = StaticSamplersOffset;
+ if (NumSamplers > 0)
+ SSO = writePlaceholder(BOS);
+ else
+ support::endian::write(BOS, SSO, llvm::endianness::little);
support::endian::write(BOS, Flags, llvm::endianness::little);
SmallVector<uint32_t> ParamsOffsets;
@@ -142,20 +147,23 @@ void RootSignatureDesc::write(raw_ostream &OS) const {
}
}
}
- for (const auto &S : StaticSamplers) {
- support::endian::write(BOS, S.Filter, llvm::endianness::little);
- support::endian::write(BOS, S.AddressU, llvm::endianness::little);
- support::endian::write(BOS, S.AddressV, llvm::endianness::little);
- support::endian::write(BOS, S.AddressW, llvm::endianness::little);
- support::endian::write(BOS, S.MipLODBias, llvm::endianness::little);
- support::endian::write(BOS, S.MaxAnisotropy, llvm::endianness::little);
- support::endian::write(BOS, S.ComparisonFunc, llvm::endianness::little);
- support::endian::write(BOS, S.BorderColor, llvm::endianness::little);
- support::endian::write(BOS, S.MinLOD, llvm::endianness::little);
- support::endian::write(BOS, S.MaxLOD, llvm::endianness::little);
- support::endian::write(BOS, S.ShaderRegister, llvm::endianness::little);
- support::endian::write(BOS, S.RegisterSpace, llvm::endianness::little);
- support::endian::write(BOS, S.ShaderVisibility, llvm::endianness::little);
+ if (NumSamplers > 0) {
+ rewriteOffsetToCurrentByte(BOS, SSO);
+ for (const auto &S : StaticSamplers) {
+ support::endian::write(BOS, S.Filter, llvm::endianness::little);
+ support::endian::write(BOS, S.AddressU, llvm::endianness::little);
+ support::endian::write(BOS, S.AddressV, llvm::endianness::little);
+ support::endian::write(BOS, S.AddressW, llvm::endianness::little);
+ support::endian::write(BOS, S.MipLODBias, llvm::endianness::little);
+ support::endian::write(BOS, S.MaxAnisotropy, llvm::endianness::little);
+ support::endian::write(BOS, S.ComparisonFunc, llvm::endianness::little);
+ support::endian::write(BOS, S.BorderColor, llvm::endianness::little);
+ support::endian::write(BOS, S.MinLOD, llvm::endianness::little);
+ support::endian::write(BOS, S.MaxLOD, llvm::endianness::little);
+ support::endian::write(BOS, S.ShaderRegister, llvm::endianness::little);
+ support::endian::write(BOS, S.RegisterSpace, llvm::endianness::little);
+ support::endian::write(BOS, S.ShaderVisibility, llvm::endianness::little);
+ }
}
assert(Storage.size() == getSize());
OS.write(Storage.data(), Storage.size());
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index e51bd6796fb84..dfe9900b21df2 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/APFloat.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/DXILMetadataAnalysis.h"
@@ -55,6 +56,13 @@ static std::optional<uint32_t> extractMdIntValue(MDNode *Node,
return std::nullopt;
}
+static std::optional<APFloat> extractMdFloatValue(MDNode *Node,
+ unsigned int OpId) {
+ if (auto *CI = mdconst::dyn_extract<ConstantFP>(Node->getOperand(OpId).get()))
+ return CI->getValue();
+ return std::nullopt;
+}
+
static std::optional<StringRef> extractMdStringValue(MDNode *Node,
unsigned int OpId) {
MDString *NodeText = dyn_cast<MDString>(Node->getOperand(OpId));
@@ -262,6 +270,81 @@ static bool parseDescriptorTable(LLVMContext *Ctx,
return false;
}
+static bool parseStaticSampler(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD,
+ MDNode *StaticSamplerNode) {
+ if (StaticSamplerNode->getNumOperands() != 14)
+ return reportError(Ctx, "Invalid format for Static Sampler");
+
+ dxbc::RTS0::v1::StaticSampler Sampler;
+ if (std::optional<uint32_t> Val = extractMdIntValue(StaticSamplerNode, 1))
+ Sampler.Filter = *Val;
+ else
+ return reportError(Ctx, "Invalid value for Filter");
+
+ if (std::optional<uint32_t> Val = extractMdIntValue(StaticSamplerNode, 2))
+ Sampler.AddressU = *Val;
+ else
+ return reportError(Ctx, "Invalid value for AddressU");
+
+ if (std::optional<uint32_t> Val = extractMdIntValue(StaticSamplerNode, 3))
+ Sampler.AddressV = *Val;
+ else
+ return reportError(Ctx, "Invalid value for AddressV");
+
+ if (std::optional<uint32_t> Val = extractMdIntValue(StaticSamplerNode, 4))
+ Sampler.AddressW = *Val;
+ else
+ return reportError(Ctx, "Invalid value for AddressW");
+
+ if (std::optional<APFloat> Val = extractMdFloatValue(StaticSamplerNode, 5))
+ Sampler.MipLODBias = Val->convertToFloat();
+ else
+ return reportError(Ctx, "Invalid value for MipLODBias");
+
+ if (std::optional<uint32_t> Val = extractMdIntValue(StaticSamplerNode, 6))
+ Sampler.MaxAnisotropy = *Val;
+ else
+ return reportError(Ctx, "Invalid value for MaxAnisotropy");
+
+ if (std::optional<uint32_t> Val = extractMdIntValue(StaticSamplerNode, 7))
+ Sampler.ComparisonFunc = *Val;
+ else
+ return reportError(Ctx, "Invalid value for ComparisonFunc ");
+
+ if (std::optional<uint32_t> Val = extractMdIntValue(StaticSamplerNode, 8))
+ Sampler.BorderColor = *Val;
+ else
+ return reportError(Ctx, "Invalid value for ComparisonFunc ");
+
+ if (std::optional<APFloat> Val = extractMdFloatValue(StaticSamplerNode, 9))
+ Sampler.MinLOD = Val->convertToFloat();
+ else
+ return reportError(Ctx, "Invalid value for MinLOD");
+
+ if (std::optional<APFloat> Val = extractMdFloatValue(StaticSamplerNode, 10))
+ Sampler.MaxLOD = Val->convertToFloat();
+ else
+ return reportError(Ctx, "Invalid value for MaxLOD");
+
+ if (std::optional<uint32_t> Val = extractMdIntValue(StaticSamplerNode, 11))
+ Sampler.ShaderRegister = *Val;
+ else
+ return reportError(Ctx, "Invalid value for ShaderRegister");
+
+ if (std::optional<uint32_t> Val = extractMdIntValue(StaticSamplerNode, 12))
+ Sampler.RegisterSpace = *Val;
+ else
+ return reportError(Ctx, "Invalid value for RegisterSpace");
+
+ if (std::optional<uint32_t> Val = extractMdIntValue(StaticSamplerNode, 13))
+ Sampler.ShaderVisibility = *Val;
+ else
+ return reportError(Ctx, "Invalid value for ShaderVisibility");
+
+ RSD.StaticSamplers.push_back(Sampler);
+ return false;
+}
+
static bool parseRootSignatureElement(LLVMContext *Ctx,
mcdxbc::RootSignatureDesc &RSD,
MDNode *Element) {
@@ -277,6 +360,7 @@ static bool parseRootSignatureElement(LLVMContext *Ctx,
.Case("RootSRV", RootSignatureElementKind::SRV)
.Case("RootUAV", RootSignatureElementKind::UAV)
.Case("DescriptorTable", RootSignatureElementKind::DescriptorTable)
+ .Case("StaticSampler", RootSignatureElementKind::StaticSamplers)
.Default(RootSignatureElementKind::Error);
switch (ElementKind) {
@@ -291,6 +375,8 @@ static bool parseRootSignatureElement(LLVMContext *Ctx,
return parseRootDescriptors(Ctx, RSD, Element, ElementKind);
case RootSignatureElementKind::DescriptorTable:
return parseDescriptorTable(Ctx, RSD, Element);
+ case RootSignatureElementKind::StaticSamplers:
+ return parseStaticSampler(Ctx, RSD, Element);
case RootSignatureElementKind::Error:
return reportError(Ctx, "Invalid Root Signature Element: " + *ElementText);
}
@@ -522,6 +608,9 @@ analyzeModule(Module &M) {
// offset will always equal to the header size.
RSD.RootParameterOffset = sizeof(dxbc::RTS0::v1::RootSignatureHeader);
+ // static sampler offset is calculated when writting dxcontainer.
+ RSD.StaticSamplersOffset = 0u;
+
if (parse(Ctx, RSD, RootElementListNode) || validate(Ctx, RSD)) {
return RSDMap;
}
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.h b/llvm/lib/Target/DirectX/DXILRootSignature.h
index b45cebc15fd39..be5cc78bc6bdf 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.h
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.h
@@ -32,6 +32,7 @@ enum class RootSignatureElementKind {
UAV = 4,
CBV = 5,
DescriptorTable = 6,
+ StaticSamplers = 7
};
class RootSignatureAnalysis : public AnalysisInfoMixin<RootSignatureAnalysis> {
friend AnalysisInfoMixin<RootSignatureAnalysis>;
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers.ll
new file mode 100644
index 0000000000000..35a8fb53248f9
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers.ll
@@ -0,0 +1,42 @@
+; 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 [76 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 = !{ !5 } ; list of root signature elements
+!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x40403999A0000000, i32 9, i32 3, i32 2, float -1.280000e+02, float 1.280000e+02, i32 42, i32 0, i32 0 }
+
+; DXC: - Name: RTS0
+; DXC-NEXT: Size: 76
+; DXC-NEXT: RootSignature:
+; DXC-NEXT: Version: 2
+; DXC-NEXT: NumRootParameters: 0
+; DXC-NEXT: RootParametersOffset: 24
+; DXC-NEXT: NumStaticSamplers: 1
+; DXC-NEXT: StaticSamplersOffset: 24
+; DXC-NEXT: Parameters: []
+; DXC-NEXT: Samplers:
+; DXC-NEXT: - Filter: 4
+; DXC-NEXT: AddressU: 2
+; DXC-NEXT: AddressV: 3
+; DXC-NEXT: AddressW: 5
+; DXC-NEXT: MipLODBias: 32.45
+; DXC-NEXT: MaxAnisotropy: 9
+; DXC-NEXT: ComparisonFunc: 3
+; DXC-NEXT: BorderColor: 2
+; DXC-NEXT: MinLOD: -128
+; DXC-NEXT: MaxLOD: 128
+; DXC-NEXT: ShaderRegister: 42
+; DXC-NEXT: RegisterSpace: 0
+; DXC-NEXT: ShaderVisibility: 0
>From fb9c7c47e1af70911c7c97233ebb90d16ef29737 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 5 Jun 2025 00:59:42 +0000
Subject: [PATCH 2/6] add validations
---
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 168 ++++++++++++++++++
.../RootSignature-StaticSamplers.ll | 4 +-
2 files changed, 170 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index dfe9900b21df2..a6d87611a94d0 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -13,6 +13,7 @@
#include "DXILRootSignature.h"
#include "DirectX.h"
#include "llvm/ADT/APFloat.h"
+#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/DXILMetadataAnalysis.h"
@@ -28,6 +29,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
+#include <cmath>
#include <cstdint>
#include <optional>
#include <utility>
@@ -478,6 +480,127 @@ static bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type,
return (Flags & ~DataFlags) == FlagT::NONE;
}
+static bool verifySamplerFilter(uint32_t Filter) {
+ switch (Filter) {
+ case llvm::to_underlying(dxbc::StaticSamplerFilter::MIN_MAG_MIP_POINT):
+ case llvm::to_underlying(dxbc::StaticSamplerFilter::MIN_MAG_POINT_MIP_LINEAR):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MIN_POINT_MAG_LINEAR_MIP_POINT):
+ case llvm::to_underlying(dxbc::StaticSamplerFilter::MIN_POINT_MAG_MIP_LINEAR):
+ case llvm::to_underlying(dxbc::StaticSamplerFilter::MIN_LINEAR_MAG_MIP_POINT):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MIN_LINEAR_MAG_POINT_MIP_LINEAR):
+ case llvm::to_underlying(dxbc::StaticSamplerFilter::MIN_MAG_LINEAR_MIP_POINT):
+ case llvm::to_underlying(dxbc::StaticSamplerFilter::MIN_MAG_MIP_LINEAR):
+ case llvm::to_underlying(dxbc::StaticSamplerFilter::ANISOTROPIC):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::COMPARISON_MIN_MAG_MIP_POINT):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::COMPARISON_MIN_MAG_POINT_MIP_LINEAR):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::COMPARISON_MIN_POINT_MAG_LINEAR_MIP_POINT):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::COMPARISON_MIN_POINT_MAG_MIP_LINEAR):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::COMPARISON_MIN_LINEAR_MAG_MIP_POINT):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::COMPARISON_MIN_LINEAR_MAG_POINT_MIP_LINEAR):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::COMPARISON_MIN_MAG_LINEAR_MIP_POINT):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::COMPARISON_MIN_MAG_MIP_LINEAR):
+ case llvm::to_underlying(dxbc::StaticSamplerFilter::COMPARISON_ANISOTROPIC):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MINIMUM_MIN_MAG_MIP_POINT):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MINIMUM_MIN_MAG_POINT_MIP_LINEAR):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MINIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MINIMUM_MIN_POINT_MAG_MIP_LINEAR):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MINIMUM_MIN_LINEAR_MAG_MIP_POINT):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MINIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MINIMUM_MIN_MAG_LINEAR_MIP_POINT):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MINIMUM_MIN_MAG_MIP_LINEAR):
+ case llvm::to_underlying(dxbc::StaticSamplerFilter::MINIMUM_ANISOTROPIC):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MAXIMUM_MIN_MAG_MIP_POINT):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MAXIMUM_MIN_MAG_POINT_MIP_LINEAR):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MAXIMUM_MIN_POINT_MAG_LINEAR_MIP_POINT):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MAXIMUM_MIN_POINT_MAG_MIP_LINEAR):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MAXIMUM_MIN_LINEAR_MAG_MIP_POINT):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MAXIMUM_MIN_LINEAR_MAG_POINT_MIP_LINEAR):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MAXIMUM_MIN_MAG_LINEAR_MIP_POINT):
+ case llvm::to_underlying(
+ dxbc::StaticSamplerFilter::MAXIMUM_MIN_MAG_MIP_LINEAR):
+ case llvm::to_underlying(dxbc::StaticSamplerFilter::MAXIMUM_ANISOTROPIC):
+ return true;
+ }
+ return false;
+}
+
+// Values allowed here:
+// https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_texture_address_mode#syntax
+static bool verifyAddress(uint32_t Address) {
+ switch (Address) {
+ case llvm::to_underlying(dxbc::TextureAddressMode::Border):
+ case llvm::to_underlying(dxbc::TextureAddressMode::Clamp):
+ case llvm::to_underlying(dxbc::TextureAddressMode::Mirror):
+ case llvm::to_underlying(dxbc::TextureAddressMode::MirrorOnce):
+ case llvm::to_underlying(dxbc::TextureAddressMode::Wrap):
+ return true;
+ }
+
+ return false;
+}
+
+static bool verifyMipLODBias(float MipLODBias) {
+ return MipLODBias >= -16.f && MipLODBias <= 16.f;
+}
+
+static bool verifyMaxAnisotropy(uint32_t MaxAnisotropy) {
+ return MaxAnisotropy <= 16u;
+}
+
+static bool verifyComparisonFunc(uint32_t ComparisonFunc) {
+ switch (ComparisonFunc) {
+ case llvm::to_underlying(dxbc::SamplersComparisonFunction::Never):
+ case llvm::to_underlying(dxbc::SamplersComparisonFunction::Less):
+ case llvm::to_underlying(dxbc::SamplersComparisonFunction::Equal):
+ case llvm::to_underlying(dxbc::SamplersComparisonFunction::LessEqual):
+ case llvm::to_underlying(dxbc::SamplersComparisonFunction::Greater):
+ case llvm::to_underlying(dxbc::SamplersComparisonFunction::NotEqual):
+ case llvm::to_underlying(dxbc::SamplersComparisonFunction::GreaterEqual):
+ case llvm::to_underlying(dxbc::SamplersComparisonFunction::Always):
+ return true;
+ }
+ return false;
+}
+
+static bool verifyBorderColor(uint32_t BorderColor) {
+ switch (BorderColor) {
+ case llvm::to_underlying(dxbc::SamplersBorderColor::TransparentBlack):
+ case llvm::to_underlying(dxbc::SamplersBorderColor::OpaqueBlack):
+ case llvm::to_underlying(dxbc::SamplersBorderColor::OpaqueWhite):
+ case llvm::to_underlying(dxbc::SamplersBorderColor::OpaqueBlackUint):
+ case llvm::to_underlying(dxbc::SamplersBorderColor::OpaqueWhiteUint):
+ return true;
+ }
+ return false;
+}
+
+static bool verifyLOD(float LOD) { return !std::isnan(LOD); }
+
static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
if (!verifyVersion(RSD.Version)) {
@@ -535,6 +658,51 @@ static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
}
}
+ for (const dxbc::RTS0::v1::StaticSampler &Sampler : RSD.StaticSamplers) {
+ if (!verifySamplerFilter(Sampler.Filter))
+ return reportValueError(Ctx, "Filter", Sampler.Filter);
+
+ if (!verifyAddress(Sampler.AddressU))
+ return reportValueError(Ctx, "AddressU", Sampler.AddressU);
+
+ if (!verifyAddress(Sampler.AddressV))
+ return reportValueError(Ctx, "AddressU", Sampler.AddressV);
+
+ if (!verifyAddress(Sampler.AddressW))
+ return reportValueError(Ctx, "AddressU", Sampler.AddressW);
+
+ if (!verifyMipLODBias(Sampler.MipLODBias))
+ return reportValueError(Ctx, "MipLODBias", Sampler.MipLODBias);
+
+ if (!verifyMaxAnisotropy(Sampler.MaxAnisotropy))
+ return reportValueError(Ctx, "MaxAnisotropy", Sampler.MaxAnisotropy);
+
+ if (!verifyComparisonFunc(Sampler.ComparisonFunc))
+ return reportValueError(Ctx, "ComparisonFunc", Sampler.ComparisonFunc);
+
+ if (!verifyComparisonFunc(Sampler.ComparisonFunc))
+ return reportValueError(Ctx, "ComparisonFunc", Sampler.ComparisonFunc);
+
+ if (!verifyBorderColor(Sampler.BorderColor))
+ return reportValueError(Ctx, "BorderColor ", Sampler.BorderColor);
+
+ if (!verifyLOD(Sampler.MinLOD))
+ return reportValueError(Ctx, "MinLOD ", Sampler.MinLOD);
+
+ if (!verifyLOD(Sampler.MaxLOD))
+ return reportValueError(Ctx, "MaxLOD ", Sampler.MaxLOD);
+
+ if (!verifyRegisterValue(Sampler.ShaderRegister))
+ return reportValueError(Ctx, "ShaderRegister", Sampler.ShaderRegister);
+
+ if (!verifyRegisterSpace(Sampler.RegisterSpace))
+ return reportValueError(Ctx, "RegisterSpace", Sampler.RegisterSpace);
+
+ if (!dxbc::isValidShaderVisibility(Sampler.ShaderVisibility))
+ return reportValueError(Ctx, "ShaderVisibility",
+ Sampler.ShaderVisibility);
+ }
+
return false;
}
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers.ll
index 35a8fb53248f9..77965064a4228 100644
--- a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers.ll
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers.ll
@@ -15,7 +15,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
!dx.rootsignatures = !{!2} ; list of function/root signature pairs
!2 = !{ ptr @main, !3 } ; function, root signature
!3 = !{ !5 } ; list of root signature elements
-!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x40403999A0000000, i32 9, i32 3, i32 2, float -1.280000e+02, float 1.280000e+02, i32 42, i32 0, i32 0 }
+!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6CCCCC0000000, i32 9, i32 3, i32 2, float -1.280000e+02, float 1.280000e+02, i32 42, i32 0, i32 0 }
; DXC: - Name: RTS0
; DXC-NEXT: Size: 76
@@ -31,7 +31,7 @@ attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
; DXC-NEXT: AddressU: 2
; DXC-NEXT: AddressV: 3
; DXC-NEXT: AddressW: 5
-; DXC-NEXT: MipLODBias: 32.45
+; DXC-NEXT: MipLODBias: 1.425
; DXC-NEXT: MaxAnisotropy: 9
; DXC-NEXT: ComparisonFunc: 3
; DXC-NEXT: BorderColor: 2
>From 611f0bb69a34960521c1e7288b30b94a3dc7a775 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Fri, 6 Jun 2025 06:54:07 +0000
Subject: [PATCH 3/6] adding tests
---
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 13 +++++--------
...gnature-StaticSamplers-Invalid-AddressU.ll | 19 +++++++++++++++++++
...gnature-StaticSamplers-Invalid-AddressV.ll | 19 +++++++++++++++++++
...gnature-StaticSamplers-Invalid-AddressW.ll | 19 +++++++++++++++++++
...ture-StaticSamplers-Invalid-BorderColor.ll | 19 +++++++++++++++++++
...e-StaticSamplers-Invalid-ComparisonFunc.ll | 19 +++++++++++++++++++
...Signature-StaticSamplers-Invalid-Filter.ll | 19 +++++++++++++++++++
...re-StaticSamplers-Invalid-MaxAnisotropy.ll | 19 +++++++++++++++++++
...Signature-StaticSamplers-Invalid-MaxLod.ll | 19 +++++++++++++++++++
...Signature-StaticSamplers-Invalid-MinLod.ll | 19 +++++++++++++++++++
...ature-StaticSamplers-Invalid-MinLopBias.ll | 19 +++++++++++++++++++
...re-StaticSamplers-Invalid-RegisterSpace.ll | 19 +++++++++++++++++++
...e-StaticSamplers-Invalid-ShaderRegister.ll | 19 +++++++++++++++++++
...StaticSamplers-Invalid-ShaderVisibility.ll | 19 +++++++++++++++++++
14 files changed, 252 insertions(+), 8 deletions(-)
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressV.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressW.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-BorderColor.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-ComparisonFunc.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-Filter.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MaxAnisotropy.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MaxLod.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MinLod.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MinLopBias.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-RegisterSpace.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-ShaderRegister.ll
create mode 100644 llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-ShaderVisibility.ll
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index a6d87611a94d0..47e4d23532ef5 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -666,10 +666,10 @@ static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
return reportValueError(Ctx, "AddressU", Sampler.AddressU);
if (!verifyAddress(Sampler.AddressV))
- return reportValueError(Ctx, "AddressU", Sampler.AddressV);
+ return reportValueError(Ctx, "AddressV", Sampler.AddressV);
if (!verifyAddress(Sampler.AddressW))
- return reportValueError(Ctx, "AddressU", Sampler.AddressW);
+ return reportValueError(Ctx, "AddressW", Sampler.AddressW);
if (!verifyMipLODBias(Sampler.MipLODBias))
return reportValueError(Ctx, "MipLODBias", Sampler.MipLODBias);
@@ -680,17 +680,14 @@ static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
if (!verifyComparisonFunc(Sampler.ComparisonFunc))
return reportValueError(Ctx, "ComparisonFunc", Sampler.ComparisonFunc);
- if (!verifyComparisonFunc(Sampler.ComparisonFunc))
- return reportValueError(Ctx, "ComparisonFunc", Sampler.ComparisonFunc);
-
if (!verifyBorderColor(Sampler.BorderColor))
- return reportValueError(Ctx, "BorderColor ", Sampler.BorderColor);
+ return reportValueError(Ctx, "BorderColor", Sampler.BorderColor);
if (!verifyLOD(Sampler.MinLOD))
- return reportValueError(Ctx, "MinLOD ", Sampler.MinLOD);
+ return reportValueError(Ctx, "MinLOD", Sampler.MinLOD);
if (!verifyLOD(Sampler.MaxLOD))
- return reportValueError(Ctx, "MaxLOD ", Sampler.MaxLOD);
+ return reportValueError(Ctx, "MaxLOD", Sampler.MaxLOD);
if (!verifyRegisterValue(Sampler.ShaderRegister))
return reportValueError(Ctx, "ShaderRegister", Sampler.ShaderRegister);
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll
new file mode 100644
index 0000000000000..124803e36a450
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressU.ll
@@ -0,0 +1,19 @@
+; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
+
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: error: Invalid value for AddressU: 666
+; CHECK-NOT: Root Signature Definitions
+
+define void @main() #0 {
+entry:
+ ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!2} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3 } ; function, root signature
+!3 = !{ !5 } ; list of root signature elements
+!5 = !{ !"StaticSampler", i32 4, i32 666, i32 3, i32 5, float 0x3FF6CCCCC0000000, i32 9, i32 3, i32 2, float -1.280000e+02, float 1.280000e+02, i32 42, i32 0, i32 0 }
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressV.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressV.ll
new file mode 100644
index 0000000000000..e2c5de1c36a0c
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressV.ll
@@ -0,0 +1,19 @@
+; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
+
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: error: Invalid value for AddressV: 666
+; CHECK-NOT: Root Signature Definitions
+
+define void @main() #0 {
+entry:
+ ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!2} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3 } ; function, root signature
+!3 = !{ !5 } ; list of root signature elements
+!5 = !{ !"StaticSampler", i32 4, i32 2, i32 666, i32 5, float 0x3FF6CCCCC0000000, i32 9, i32 3, i32 2, float -1.280000e+02, float 1.280000e+02, i32 42, i32 0, i32 0 }
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressW.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressW.ll
new file mode 100644
index 0000000000000..08fc8fa9e5093
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-AddressW.ll
@@ -0,0 +1,19 @@
+; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
+
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: error: Invalid value for AddressW: 666
+; CHECK-NOT: Root Signature Definitions
+
+define void @main() #0 {
+entry:
+ ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!2} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3 } ; function, root signature
+!3 = !{ !5 } ; list of root signature elements
+!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 666, float 0x3FF6CCCCC0000000, i32 9, i32 3, i32 2, float -1.280000e+02, float 1.280000e+02, i32 42, i32 0, i32 0 }
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-BorderColor.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-BorderColor.ll
new file mode 100644
index 0000000000000..83b31594b2bec
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-BorderColor.ll
@@ -0,0 +1,19 @@
+; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
+
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: error: Invalid value for BorderColor: 666
+; CHECK-NOT: Root Signature Definitions
+
+define void @main() #0 {
+entry:
+ ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!2} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3 } ; function, root signature
+!3 = !{ !5 } ; list of root signature elements
+!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6CCCCC0000000, i32 9, i32 3, i32 666, float -1.280000e+02, float 1.280000e+02, i32 42, i32 0, i32 0 }
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-ComparisonFunc.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-ComparisonFunc.ll
new file mode 100644
index 0000000000000..b9cd1d9093325
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-ComparisonFunc.ll
@@ -0,0 +1,19 @@
+; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
+
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: error: Invalid value for ComparisonFunc: 666
+; CHECK-NOT: Root Signature Definitions
+
+define void @main() #0 {
+entry:
+ ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!2} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3 } ; function, root signature
+!3 = !{ !5 } ; list of root signature elements
+!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6CCCCC0000000, i32 9, i32 666, i32 2, float -1.280000e+02, float 1.280000e+02, i32 42, i32 0, i32 0 }
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-Filter.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-Filter.ll
new file mode 100644
index 0000000000000..303dc5defaf52
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-Filter.ll
@@ -0,0 +1,19 @@
+; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
+
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: error: Invalid value for Filter: 666
+; CHECK-NOT: Root Signature Definitions
+
+define void @main() #0 {
+entry:
+ ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!2} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3 } ; function, root signature
+!3 = !{ !5 } ; list of root signature elements
+!5 = !{ !"StaticSampler", i32 666, i32 2, i32 3, i32 5, float 0x3FF6CCCCC0000000, i32 9, i32 3, i32 2, float -1.280000e+02, float 1.280000e+02, i32 42, i32 0, i32 0 }
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MaxAnisotropy.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MaxAnisotropy.ll
new file mode 100644
index 0000000000000..084d6b326a67f
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MaxAnisotropy.ll
@@ -0,0 +1,19 @@
+; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
+
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: error: Invalid value for MaxAnisotropy: 666
+; CHECK-NOT: Root Signature Definitions
+
+define void @main() #0 {
+entry:
+ ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!2} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3 } ; function, root signature
+!3 = !{ !5 } ; list of root signature elements
+!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6CCCCC0000000, i32 666, i32 3, i32 2, float -1.280000e+02, float 1.280000e+02, i32 42, i32 0, i32 0 }
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MaxLod.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MaxLod.ll
new file mode 100644
index 0000000000000..b4d33197ca150
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MaxLod.ll
@@ -0,0 +1,19 @@
+; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
+
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: error: Invalid value for MaxLOD: 0
+; CHECK-NOT: Root Signature Definitions
+
+define void @main() #0 {
+entry:
+ ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!2} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3 } ; function, root signature
+!3 = !{ !5 } ; list of root signature elements
+!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6CCCCC0000000, i32 9, i32 3, i32 2, float -1.280000e+02, float 0x7FF8000000000000, i32 42, i32 0, i32 0 }
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MinLod.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MinLod.ll
new file mode 100644
index 0000000000000..97fa803f4c165
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MinLod.ll
@@ -0,0 +1,19 @@
+; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
+
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: error: Invalid value for MinLOD: 0
+; CHECK-NOT: Root Signature Definitions
+
+define void @main() #0 {
+entry:
+ ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!2} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3 } ; function, root signature
+!3 = !{ !5 } ; list of root signature elements
+!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6CCCCC0000000, i32 9, i32 3, i32 2, float 0x7FF8000000000000, float 1.280000e+02, i32 42, i32 0, i32 0 }
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MinLopBias.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MinLopBias.ll
new file mode 100644
index 0000000000000..cd4079d8edd74
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-MinLopBias.ll
@@ -0,0 +1,19 @@
+; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
+
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: error: Invalid value for MipLODBias: 666
+; CHECK-NOT: Root Signature Definitions
+
+define void @main() #0 {
+entry:
+ ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!2} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3 } ; function, root signature
+!3 = !{ !5 } ; list of root signature elements
+!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 6.660000e+02, i32 9, i32 3, i32 2, float -1.280000e+02, float 1.280000e+02, i32 42, i32 0, i32 0 }
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-RegisterSpace.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-RegisterSpace.ll
new file mode 100644
index 0000000000000..eeea8821afd07
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-RegisterSpace.ll
@@ -0,0 +1,19 @@
+; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
+
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: error: Invalid value for RegisterSpace: 4294967280
+; CHECK-NOT: Root Signature Definitions
+
+define void @main() #0 {
+entry:
+ ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!2} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3 } ; function, root signature
+!3 = !{ !5 } ; list of root signature elements
+!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6CCCCC0000000, i32 9, i32 3, i32 2, float -1.280000e+02, float 1.280000e+02, i32 42, i32 4294967280, i32 0 }
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-ShaderRegister.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-ShaderRegister.ll
new file mode 100644
index 0000000000000..6750cdc1b77fa
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-ShaderRegister.ll
@@ -0,0 +1,19 @@
+; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
+
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: error: Invalid value for ShaderRegister: 4294967295
+; CHECK-NOT: Root Signature Definitions
+
+define void @main() #0 {
+entry:
+ ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!2} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3 } ; function, root signature
+!3 = !{ !5 } ; list of root signature elements
+!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6CCCCC0000000, i32 9, i32 3, i32 2, float -1.280000e+02, float 1.280000e+02, i32 4294967295, i32 0, i32 0 }
diff --git a/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-ShaderVisibility.ll b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-ShaderVisibility.ll
new file mode 100644
index 0000000000000..4db55cf9c4b89
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/ContainerData/RootSignature-StaticSamplers-Invalid-ShaderVisibility.ll
@@ -0,0 +1,19 @@
+; RUN: not opt -passes='print<dxil-root-signature>' %s -S -o - 2>&1 | FileCheck %s
+
+
+target triple = "dxil-unknown-shadermodel6.0-compute"
+
+; CHECK: error: Invalid value for ShaderVisibility: 666
+; CHECK-NOT: Root Signature Definitions
+
+define void @main() #0 {
+entry:
+ ret void
+}
+attributes #0 = { "hlsl.numthreads"="1,1,1" "hlsl.shader"="compute" }
+
+
+!dx.rootsignatures = !{!2} ; list of function/root signature pairs
+!2 = !{ ptr @main, !3 } ; function, root signature
+!3 = !{ !5 } ; list of root signature elements
+!5 = !{ !"StaticSampler", i32 4, i32 2, i32 3, i32 5, float 0x3FF6CCCCC0000000, i32 9, i32 3, i32 2, float -1.280000e+02, float 1.280000e+02, i32 42, i32 0, i32 666 }
>From 42beb33b922119d0a6129b8e5816bd596419e5cf Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Fri, 6 Jun 2025 18:35:08 +0000
Subject: [PATCH 4/6] addressing comments
---
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 47e4d23532ef5..31b77512da407 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -432,6 +432,11 @@ static bool verifyRangeType(uint32_t Type) {
return false;
}
+template <typename... FlagTypes>
+static bool isFlagSet(uint32_t Flags, FlagTypes... FlagsToCheck) {
+ return ((Flags & llvm::to_underlying(FlagsToCheck)) | ...) == Flags;
+}
+
static bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type,
uint32_t FlagsVal) {
using FlagT = dxbc::DescriptorRangeFlag;
>From 0995050ca13db79a6b32ff7495d03fba0ee2ad29 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Mon, 9 Jun 2025 18:44:50 +0000
Subject: [PATCH 5/6] fix
---
llvm/lib/MC/DXContainerRootSignature.cpp | 1 -
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 3 ---
2 files changed, 4 deletions(-)
diff --git a/llvm/lib/MC/DXContainerRootSignature.cpp b/llvm/lib/MC/DXContainerRootSignature.cpp
index d67babf13a432..77d648a739b87 100644
--- a/llvm/lib/MC/DXContainerRootSignature.cpp
+++ b/llvm/lib/MC/DXContainerRootSignature.cpp
@@ -9,7 +9,6 @@
#include "llvm/MC/DXContainerRootSignature.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/EndianStream.h"
-#include <cstdint>
using namespace llvm;
using namespace llvm::mcdxbc;
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 31b77512da407..50a2fe3347dcf 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -12,8 +12,6 @@
//===----------------------------------------------------------------------===//
#include "DXILRootSignature.h"
#include "DirectX.h"
-#include "llvm/ADT/APFloat.h"
-#include "llvm/ADT/STLForwardCompat.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Analysis/DXILMetadataAnalysis.h"
@@ -29,7 +27,6 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
-#include <cmath>
#include <cstdint>
#include <optional>
#include <utility>
>From 24f38bd9506bfff566fd753f1180b581b8f448f9 Mon Sep 17 00:00:00 2001
From: joaosaffran <joao.saffran at microsoft.com>
Date: Thu, 12 Jun 2025 23:50:27 +0000
Subject: [PATCH 6/6] rebase
---
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 1 +
1 file changed, 1 insertion(+)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 50a2fe3347dcf..3aef7d3eb1e69 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -27,6 +27,7 @@
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/raw_ostream.h"
+#include <cmath>
#include <cstdint>
#include <optional>
#include <utility>
More information about the llvm-branch-commits
mailing list