Skip to content

Commit 28fb609

Browse files
Joao SaffranJoao Saffran
authored andcommitted
clean up
1 parent ed4c553 commit 28fb609

File tree

6 files changed

+23
-128
lines changed

6 files changed

+23
-128
lines changed

llvm/include/llvm/Frontend/HLSL/RootSignatureValidations.h

Lines changed: 17 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -16,125 +16,30 @@
1616

1717
#include "llvm/ADT/IntervalMap.h"
1818
#include "llvm/Frontend/HLSL/HLSLRootSignature.h"
19+
#include "llvm/Support/Compiler.h"
1920

2021
namespace llvm {
2122
namespace hlsl {
2223
namespace rootsig {
2324

2425
// Basic verification of RootElements
2526

26-
bool verifyRootFlag(uint32_t Flags);
27-
bool verifyVersion(uint32_t Version);
28-
bool verifyRegisterValue(uint32_t RegisterValue);
29-
bool verifyRegisterSpace(uint32_t RegisterSpace);
30-
bool verifyRootDescriptorFlag(uint32_t Version, uint32_t FlagsVal);
31-
bool verifyRangeType(uint32_t Type);
32-
bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type,
33-
uint32_t FlagsVal);
34-
bool verifyNumDescriptors(uint32_t NumDescriptors);
35-
bool verifySamplerFilter(uint32_t Value);
36-
bool verifyAddress(uint32_t Address);
37-
bool verifyMipLODBias(float MipLODBias);
38-
bool verifyMaxAnisotropy(uint32_t MaxAnisotropy);
39-
bool verifyComparisonFunc(uint32_t ComparisonFunc);
40-
bool verifyBorderColor(uint32_t BorderColor);
41-
bool verifyLOD(float LOD);
42-
43-
struct RangeInfo {
44-
const static uint32_t Unbounded = ~0u;
45-
46-
// Interval information
47-
uint32_t LowerBound;
48-
uint32_t UpperBound;
49-
50-
// Information retained for determining overlap
51-
llvm::dxil::ResourceClass Class;
52-
uint32_t Space;
53-
llvm::dxbc::ShaderVisibility Visibility;
54-
};
55-
56-
class ResourceRange {
57-
public:
58-
using MapT = llvm::IntervalMap<uint32_t, const RangeInfo *, 16,
59-
llvm::IntervalMapInfo<uint32_t>>;
60-
61-
private:
62-
MapT Intervals;
63-
64-
public:
65-
ResourceRange(MapT::Allocator &Allocator) : Intervals(MapT(Allocator)) {}
66-
67-
// Returns a reference to the first RangeInfo that overlaps with
68-
// [Info.LowerBound;Info.UpperBound], or, std::nullopt if there is no overlap
69-
LLVM_ABI std::optional<const RangeInfo *>
70-
getOverlapping(const RangeInfo &Info) const;
71-
72-
// Return the mapped RangeInfo at X or nullptr if no mapping exists
73-
LLVM_ABI const RangeInfo *lookup(uint32_t X) const;
74-
75-
// Removes all entries of the ResourceRange
76-
LLVM_ABI void clear();
77-
78-
// Insert the required (sub-)intervals such that the interval of [a;b] =
79-
// [Info.LowerBound, Info.UpperBound] is covered and points to a valid
80-
// RangeInfo &.
81-
//
82-
// For instance consider the following chain of inserting RangeInfos with the
83-
// intervals denoting the Lower/Upper-bounds:
84-
//
85-
// A = [0;2]
86-
// insert(A) -> false
87-
// intervals: [0;2] -> &A
88-
// B = [5;7]
89-
// insert(B) -> false
90-
// intervals: [0;2] -> &A, [5;7] -> &B
91-
// C = [4;7]
92-
// insert(C) -> true
93-
// intervals: [0;2] -> &A, [4;7] -> &C
94-
// D = [1;5]
95-
// insert(D) -> true
96-
// intervals: [0;2] -> &A, [3;3] -> &D, [4;7] -> &C
97-
// E = [0;unbounded]
98-
// insert(E) -> true
99-
// intervals: [0;unbounded] -> E
100-
//
101-
// Returns a reference to the first RangeInfo that overlaps with
102-
// [Info.LowerBound;Info.UpperBound], or, std::nullopt if there is no overlap
103-
// (equivalent to getOverlapping)
104-
LLVM_ABI std::optional<const RangeInfo *> insert(const RangeInfo &Info);
105-
};
106-
107-
struct OverlappingRanges {
108-
const RangeInfo *A;
109-
const RangeInfo *B;
110-
111-
OverlappingRanges(const RangeInfo *A, const RangeInfo *B) : A(A), B(B) {}
112-
};
113-
114-
/// The following conducts analysis on resource ranges to detect and report
115-
/// any overlaps in resource ranges.
116-
///
117-
/// A resource range overlaps with another resource range if they have:
118-
/// - equivalent ResourceClass (SRV, UAV, CBuffer, Sampler)
119-
/// - equivalent resource space
120-
/// - overlapping visbility
121-
///
122-
/// The algorithm is implemented in the following steps:
123-
///
124-
/// 1. The user will collect RangeInfo from relevant RootElements:
125-
/// - RangeInfo will retain the interval, ResourceClass, Space and Visibility
126-
/// - It will also contain an index so that it can be associated to
127-
/// additional diagnostic information
128-
/// 2. Sort the RangeInfo's such that they are grouped together by
129-
/// ResourceClass and Space
130-
/// 3. Iterate through the collected RangeInfos by their groups
131-
/// - For each group we will have a ResourceRange for each visibility
132-
/// - As we iterate through we will:
133-
/// A: Insert the current RangeInfo into the corresponding Visibility
134-
/// ResourceRange
135-
/// B: Check for overlap with any overlapping Visibility ResourceRange
136-
LLVM_ABI llvm::SmallVector<OverlappingRanges>
137-
findOverlappingRanges(ArrayRef<RangeInfo> Infos);
27+
LLVM_ABI bool verifyRootFlag(uint32_t Flags);
28+
LLVM_ABI bool verifyVersion(uint32_t Version);
29+
LLVM_ABI bool verifyRegisterValue(uint32_t RegisterValue);
30+
LLVM_ABI bool verifyRegisterSpace(uint32_t RegisterSpace);
31+
LLVM_ABI bool verifyRootDescriptorFlag(uint32_t Version, uint32_t FlagsVal);
32+
LLVM_ABI bool verifyRangeType(uint32_t Type);
33+
LLVM_ABI bool verifyDescriptorRangeFlag(uint32_t Version, uint32_t Type,
34+
uint32_t FlagsVal);
35+
LLVM_ABI bool verifyNumDescriptors(uint32_t NumDescriptors);
36+
LLVM_ABI bool verifySamplerFilter(uint32_t Value);
37+
LLVM_ABI bool verifyAddress(uint32_t Address);
38+
LLVM_ABI bool verifyMipLODBias(float MipLODBias);
39+
LLVM_ABI bool verifyMaxAnisotropy(uint32_t MaxAnisotropy);
40+
LLVM_ABI bool verifyComparisonFunc(uint32_t ComparisonFunc);
41+
LLVM_ABI bool verifyBorderColor(uint32_t BorderColor);
42+
LLVM_ABI bool verifyLOD(float LOD);
13843

13944
} // namespace rootsig
14045
} // namespace hlsl

llvm/include/llvm/MC/DXContainerRootSignature.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
8+
89
#ifndef LLVM_MC_DXCONTAINERROOTSIGNATURE_H
910
#define LLVM_MC_DXCONTAINERROOTSIGNATURE_H
1011

@@ -119,4 +120,5 @@ struct RootSignatureDesc {
119120
};
120121
} // namespace mcdxbc
121122
} // namespace llvm
123+
122124
#endif // LLVM_MC_DXCONTAINERROOTSIGNATURE_H

llvm/lib/Target/DirectX/DXILPrepare.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ class DXILPrepareModule : public ModulePass {
300300
DXILPrepareModule() : ModulePass(ID) {}
301301
void getAnalysisUsage(AnalysisUsage &AU) const override {
302302
AU.addRequired<DXILMetadataAnalysisWrapperPass>();
303+
AU.addRequired<RootSignatureAnalysisWrapper>();
303304
AU.addPreserved<RootSignatureAnalysisWrapper>();
304305
AU.addPreserved<ShaderFlagsAnalysisWrapper>();
305306
AU.addPreserved<DXILMetadataAnalysisWrapperPass>();

llvm/lib/Target/DirectX/DXILRootSignature.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
#include "llvm/Support/ErrorHandling.h"
3030
#include "llvm/Support/raw_ostream.h"
3131
#include <cstdint>
32-
#include <optional>
33-
#include <utility>
3432

3533
using namespace llvm;
3634
using namespace llvm::dxil;
@@ -235,15 +233,14 @@ bool RootSignatureAnalysisWrapper::runOnModule(Module &M) {
235233

236234
void RootSignatureAnalysisWrapper::getAnalysisUsage(AnalysisUsage &AU) const {
237235
AU.setPreservesAll();
238-
AU.addRequired<DXILMetadataAnalysisWrapperPass>();
236+
AU.addPreserved<DXILMetadataAnalysisWrapperPass>();
239237
}
240238

241239
char RootSignatureAnalysisWrapper::ID = 0;
242240

243241
INITIALIZE_PASS_BEGIN(RootSignatureAnalysisWrapper,
244242
"dxil-root-signature-analysis",
245243
"DXIL Root Signature Analysis", true, true)
246-
INITIALIZE_PASS_DEPENDENCY(DXILMetadataAnalysisWrapperPass)
247244
INITIALIZE_PASS_END(RootSignatureAnalysisWrapper,
248245
"dxil-root-signature-analysis",
249246
"DXIL Root Signature Analysis", true, true)

llvm/lib/Target/DirectX/DXILRootSignature.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,6 @@
2626
namespace llvm {
2727
namespace dxil {
2828

29-
enum class RootSignatureElementKind {
30-
Error = 0,
31-
RootFlags = 1,
32-
RootConstants = 2,
33-
SRV = 3,
34-
UAV = 4,
35-
CBV = 5,
36-
DescriptorTable = 6,
37-
};
38-
3929
class RootSignatureBindingInfo {
4030
private:
4131
SmallDenseMap<const Function *, mcdxbc::RootSignatureDesc> FuncToRsMap;
@@ -106,4 +96,4 @@ class RootSignatureAnalysisPrinter
10696

10797
} // namespace dxil
10898
} // namespace llvm
109-
#endif // LLVM_LIB_TARGET_DIRECTX_DXILROOTSIGNATURE_H
99+
#endif

llvm/test/CodeGen/DirectX/rootsignature-validation-fail-cbuffer-range.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ entry:
1212
!1 = !{!2, !3}
1313
!2 = !{!"RootConstants", i32 0, i32 2, i32 0, i32 4}
1414
!3 = !{!"DescriptorTable", i32 0, !4}
15-
!4 = !{!"CBV", i32 3, i32 0, i32 0, i32 -1, i32 4}
15+
!4 = !{!"CBV", i32 3, i32 0, i32 0, i32 -1, i32 4}

0 commit comments

Comments
 (0)