|
16 | 16 |
|
17 | 17 | #include "llvm/ADT/IntervalMap.h" |
18 | 18 | #include "llvm/Frontend/HLSL/HLSLRootSignature.h" |
| 19 | +#include "llvm/Support/Compiler.h" |
19 | 20 |
|
20 | 21 | namespace llvm { |
21 | 22 | namespace hlsl { |
22 | 23 | namespace rootsig { |
23 | 24 |
|
24 | 25 | // Basic verification of RootElements |
25 | 26 |
|
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); |
138 | 43 |
|
139 | 44 | } // namespace rootsig |
140 | 45 | } // namespace hlsl |
|
0 commit comments