Skip to content

Commit bf9b30c

Browse files
committed
refactoring isBound to return the bound reg
1 parent c7cedb4 commit bf9b30c

File tree

2 files changed

+27
-26
lines changed

2 files changed

+27
-26
lines changed

llvm/include/llvm/Frontend/HLSL/HLSLBinding.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -133,27 +133,21 @@ class BoundRegs {
133133
public:
134134
BoundRegs(SmallVector<Binding> &&Bindings) : Bindings(std::move(Bindings)) {}
135135

136-
bool isBound(dxil::ResourceClass RC, uint32_t Space, uint32_t LowerBound,
137-
uint32_t UpperBound) const {
136+
std::optional<const Binding *> getBoundRegister(dxil::ResourceClass RC,
137+
uint32_t Space,
138+
uint32_t LowerBound,
139+
uint32_t UpperBound) const {
138140
// UpperBound and Cookie are given dummy values, since they aren't
139141
// interesting for operator<
140142
const Binding *It =
141143
llvm::upper_bound(Bindings, Binding{RC, Space, LowerBound, 0, nullptr});
142144
if (It == Bindings.begin())
143-
return false;
145+
return std::nullopt;
144146
--It;
145-
return It->RC == RC && It->Space == Space && It->LowerBound <= LowerBound &&
146-
It->UpperBound >= UpperBound;
147-
}
148-
149-
const Binding *getReg(dxil::ResourceClass RC, uint32_t Space,
150-
uint32_t LowerBound) const {
151-
// UpperBound and Cookie are not used in operator<
152-
const Binding *It =
153-
llvm::upper_bound(Bindings, Binding{RC, Space, LowerBound, 0, nullptr});
154-
if (It == Bindings.begin())
155-
llvm_unreachable("getReg expectes to be called only when isBound is true");
156-
return --It;
147+
if (It->RC == RC && It->Space == Space && It->LowerBound <= LowerBound &&
148+
It->UpperBound >= UpperBound)
149+
return It;
150+
return std::nullopt;
157151
}
158152
};
159153

llvm/lib/Target/DirectX/DXILPostOptimizationValidation.cpp

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -249,18 +249,25 @@ static void validateRootSignature(Module &M,
249249
const dxil::ResourceTypeInfo &RTI = DRTM[RI.getHandleTy()];
250250
dxil::ResourceClass RC = RTI.getResourceClass();
251251
dxil::ResourceKind RK = RTI.getResourceKind();
252-
if (!BoundRegs.isBound(RC, Binding.Space, Binding.LowerBound,
253-
Binding.LowerBound + Binding.Size - 1)) {
254-
reportRegNotBound(M, RC, Binding);
252+
253+
std::optional<const llvm::hlsl::Binding *> Reg =
254+
BoundRegs.getBoundRegister(RC, Binding.Space, Binding.LowerBound,
255+
Binding.LowerBound + Binding.Size - 1);
256+
257+
if (Reg.has_value()) {
258+
const auto *ParamInfo =
259+
static_cast<const mcdxbc::RootParameterInfo *>((*Reg)->Cookie);
260+
261+
if (RC != ResourceClass::SRV && RC != ResourceClass::UAV)
262+
continue;
263+
264+
if (ParamInfo->Type == dxbc::RootParameterType::DescriptorTable)
265+
continue;
266+
267+
if (RK != ResourceKind::RawBuffer && RK != ResourceKind::StructuredBuffer)
268+
reportInvalidHandleTyError(M, RC, Binding);
255269
} else {
256-
const llvm::hlsl::Binding *Reg =
257-
BoundRegs.getReg(RC, Binding.Space, Binding.LowerBound);
258-
const mcdxbc::RootParameterInfo *ParamInfo = static_cast<const mcdxbc::RootParameterInfo *>(Reg->Cookie);
259-
260-
if((RC == ResourceClass::SRV || RC == ResourceClass::UAV) &&
261-
ParamInfo->Type != dxbc::RootParameterType::DescriptorTable &&
262-
!(RK == ResourceKind::RawBuffer || RK == ResourceKind::StructuredBuffer))
263-
reportInvalidHandleTyError(M, RC, Binding);
270+
reportRegNotBound(M, RC, Binding);
264271
}
265272
}
266273
}

0 commit comments

Comments
 (0)