Skip to content

Commit d4eab0d

Browse files
committed
misc clean up
1 parent 7339028 commit d4eab0d

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1155,10 +1155,9 @@ bool SemaHLSL::handleRootSignatureElements(
11551155
}
11561156
}
11571157

1158-
// Sort as specified
1159-
auto ComparePairs = [](InfoPair A, InfoPair B) { return A.first < B.first; };
1160-
1161-
std::sort(InfoPairs.begin(), InfoPairs.end(), ComparePairs);
1158+
// 2. Sort with the RangeInfo <operator to prepare it for findOverlapping
1159+
std::sort(InfoPairs.begin(), InfoPairs.end(),
1160+
[](InfoPair A, InfoPair B) { return A.first < B.first; });
11621161

11631162
llvm::SmallVector<RangeInfo> Infos;
11641163
for (const InfoPair &Pair : InfoPairs)
@@ -1170,12 +1169,22 @@ bool SemaHLSL::handleRootSignatureElements(
11701169
const hlsl::RootSignatureElement *>;
11711170
auto GetElemPair = [&Infos, &InfoPairs, &DuplicateCounter](
11721171
OverlappingRanges Overlap) -> ElemPair {
1172+
// Given we sorted the InfoPairs (and by implication) Infos, and,
1173+
// that Overlap.B is the item retrieved from the ResourceRange. Then it is
1174+
// guarenteed that Overlap.B <= Overlap.A.
1175+
//
1176+
// So we will find Overlap.B first and then continue to find Overlap.A
1177+
// after
11731178
auto InfoB = std::lower_bound(Infos.begin(), Infos.end(), *Overlap.B);
11741179
auto DistB = std::distance(Infos.begin(), InfoB);
11751180
auto PairB = InfoPairs.begin();
11761181
std::advance(PairB, DistB);
11771182

11781183
auto InfoA = std::lower_bound(InfoB, Infos.end(), *Overlap.A);
1184+
// Similarily, from the property that we have sorted the RangeInfos,
1185+
// all duplicates will be processed one after the other. So
1186+
// DuplicateCounter can be re-used for each set of duplicates we
1187+
// encounter as we handle incoming errors
11791188
DuplicateCounter = InfoA == InfoB ? DuplicateCounter + 1 : 0;
11801189
auto DistA = std::distance(InfoB, InfoA) + DuplicateCounter;
11811190
auto PairA = PairB;
@@ -1205,6 +1214,7 @@ bool SemaHLSL::handleRootSignatureElements(
12051214
this->Diag(OElem->getLocation(), diag::note_hlsl_resource_range_here);
12061215
};
12071216

1217+
// 3. Invoke find overlapping ranges
12081218
llvm::SmallVector<OverlappingRanges> Overlaps =
12091219
llvm::hlsl::rootsig::findOverlappingRanges(Infos);
12101220
for (OverlappingRanges Overlap : Overlaps)

clang/test/SemaHLSL/RootSignature-resource-ranges-err.hlsl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,32 +107,32 @@ void valid_root_signature_13() {}
107107
void bad_root_signature_14() {}
108108

109109
#define DuplicatesRootSignature \
110-
"CBV(b0), CBV(b0), CBV(b0), CBV(b0)"
110+
"CBV(b0), CBV(b0), CBV(b0), DescriptorTable(CBV(b0, numDescriptors = 2))"
111111

112112
// CHECK: [[@LINE-2]]:13: note: expanded from macro 'DuplicatesRootSignature'
113-
// CHECK-NEXT: [[@LINE-3]] | "CBV(b0), CBV(b0), CBV(b0), CBV(b0)"
113+
// CHECK-NEXT: [[@LINE-3]] | "CBV(b0), CBV(b0), CBV(b0), DescriptorTable(CBV(b0, numDescriptors = 2))"
114114
// CHECK-NEXT: | ^
115115
// CHECK: [[@LINE-5]]:4: note: expanded from macro 'DuplicatesRootSignature'
116-
// CHECK-NEXT: [[@LINE-6]] | "CBV(b0), CBV(b0), CBV(b0), CBV(b0)"
116+
// CHECK-NEXT: [[@LINE-6]] | "CBV(b0), CBV(b0), CBV(b0), DescriptorTable(CBV(b0, numDescriptors = 2))"
117117
// CHECK-NEXT: | ^
118118
// CHECK: [[@LINE-8]]:22: note: expanded from macro 'DuplicatesRootSignature'
119-
// CHECK-NEXT: [[@LINE-9]] | "CBV(b0), CBV(b0), CBV(b0), CBV(b0)"
119+
// CHECK-NEXT: [[@LINE-9]] | "CBV(b0), CBV(b0), CBV(b0), DescriptorTable(CBV(b0, numDescriptors = 2))"
120120
// CHECK-NEXT: | ^
121121
// CHECK: [[@LINE-11]]:4: note: expanded from macro 'DuplicatesRootSignature'
122-
// CHECK-NEXT: [[@LINE-12]] | "CBV(b0), CBV(b0), CBV(b0), CBV(b0)"
122+
// CHECK-NEXT: [[@LINE-12]] | "CBV(b0), CBV(b0), CBV(b0), DescriptorTable(CBV(b0, numDescriptors = 2))"
123123
// CHECK-NEXT: | ^
124-
// CHECK: [[@LINE-14]]:31: note: expanded from macro 'DuplicatesRootSignature'
125-
// CHECK-NEXT: [[@LINE-15]] | "CBV(b0), CBV(b0), CBV(b0), CBV(b0)"
126-
// CHECK-NEXT: | ^
124+
// CHECK: [[@LINE-14]]:47: note: expanded from macro 'DuplicatesRootSignature'
125+
// CHECK-NEXT: [[@LINE-15]] | "CBV(b0), CBV(b0), CBV(b0), DescriptorTable(CBV(b0, numDescriptors = 2))"
126+
// CHECK-NEXT: | ^
127127
// CHECK: [[@LINE-17]]:4: note: expanded from macro 'DuplicatesRootSignature'
128-
// CHECK-NEXT: [[@LINE-18]] | "CBV(b0), CBV(b0), CBV(b0), CBV(b0)"
128+
// CHECK-NEXT: [[@LINE-18]] | "CBV(b0), CBV(b0), CBV(b0), DescriptorTable(CBV(b0, numDescriptors = 2))"
129129
// CHECK-NEXT: | ^
130130

131131
// expected-error@+6 {{resource ranges b[0;0] and b[0;0] overlap within space = 0 and visibility = All}}
132132
// expected-note@+5 {{overlapping resource range here}}
133133
// expected-error@+4 {{resource ranges b[0;0] and b[0;0] overlap within space = 0 and visibility = All}}
134134
// expected-note@+3 {{overlapping resource range here}}
135-
// expected-error@+2 {{resource ranges b[0;0] and b[0;0] overlap within space = 0 and visibility = All}}
135+
// expected-error@+2 {{resource ranges b[0;1] and b[0;0] overlap within space = 0 and visibility = All}}
136136
// expected-note@+1 {{overlapping resource range here}}
137137
[RootSignature(DuplicatesRootSignature)]
138138
void valid_root_signature_15() {}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ struct OverlappingRanges {
137137
/// - RangeInfo will retain the interval, ResourceClass, Space and Visibility
138138
/// - It will also contain an index so that it can be associated to
139139
/// additional diagnostic information
140-
/// 2. Sort the RangeInfo's such that they are grouped together by
141-
/// ResourceClass and Space
140+
/// 2. The user is required to sort the RangeInfo's such that they are grouped
141+
/// together by ResourceClass and Space
142142
/// 3. Iterate through the collected RangeInfos by their groups
143143
/// - For each group we will have a ResourceRange for each visibility
144144
/// - As we iterate through we will:

llvm/lib/Frontend/HLSL/RootSignatureValidations.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,8 @@ std::optional<const RangeInfo *> ResourceRange::insert(const RangeInfo &Info) {
245245

246246
llvm::SmallVector<OverlappingRanges>
247247
findOverlappingRanges(ArrayRef<RangeInfo> Infos) {
248-
// 1. The user has provided the corresponding range information
248+
// It is expected that Infos is filled with valid RangeInfos and that
249+
// they are sorted with respect to the RangeInfo <operator
249250
llvm::SmallVector<OverlappingRanges> Overlaps;
250251
using GroupT = std::pair<dxil::ResourceClass, /*Space*/ uint32_t>;
251252

0 commit comments

Comments
 (0)