[clang] [HLSL] Collect explicit resource binding information (PR #111203)
Damyan Pepper via cfe-commits
cfe-commits at lists.llvm.org
Wed Oct 16 11:26:12 PDT 2024
================
@@ -58,31 +56,82 @@ static RegisterType getRegisterType(ResourceClass RC) {
llvm_unreachable("unexpected ResourceClass value");
}
-static RegisterType getRegisterType(StringRef Slot) {
+// Converts the first letter of string Slot to RegisterType.
+// Returns false if the letter does not correspond to a valid register type.
+static bool convertToRegisterType(StringRef Slot, RegisterType *RT) {
+ assert(RT != nullptr);
switch (Slot[0]) {
case 't':
case 'T':
- return RegisterType::SRV;
+ *RT = RegisterType::SRV;
+ return true;
case 'u':
case 'U':
- return RegisterType::UAV;
+ *RT = RegisterType::UAV;
+ return true;
case 'b':
case 'B':
- return RegisterType::CBuffer;
+ *RT = RegisterType::CBuffer;
+ return true;
case 's':
case 'S':
- return RegisterType::Sampler;
+ *RT = RegisterType::Sampler;
+ return true;
case 'c':
case 'C':
- return RegisterType::C;
+ *RT = RegisterType::C;
+ return true;
case 'i':
case 'I':
- return RegisterType::I;
+ *RT = RegisterType::I;
+ return true;
default:
- return RegisterType::Invalid;
+ return false;
}
}
+static ResourceClass getResourceClass(RegisterType RT) {
+ switch (RT) {
+ case RegisterType::SRV:
+ return ResourceClass::SRV;
+ case RegisterType::UAV:
+ return ResourceClass::UAV;
+ case RegisterType::CBuffer:
+ return ResourceClass::CBuffer;
+ case RegisterType::Sampler:
+ return ResourceClass::Sampler;
+ case RegisterType::C:
+ case RegisterType::I:
+ llvm_unreachable("unexpected RegisterType value");
+ }
+}
+
+DeclBindingInfo *ResourceBindings::addDeclBindingInfo(const VarDecl *VD,
+ ResourceClass ResClass) {
+ assert(getDeclBindingInfo(VD, ResClass) == nullptr &&
+ "DeclBindingInfo already added");
+ DeclToBindingListIndex.try_emplace(VD, BindingsList.size());
+ return &BindingsList.emplace_back(VD, ResClass);
+}
+
+DeclBindingInfo *ResourceBindings::getDeclBindingInfo(const VarDecl *VD,
+ ResourceClass ResClass) {
+ auto Entry = DeclToBindingListIndex.find(VD);
+ if (Entry != DeclToBindingListIndex.end()) {
+ unsigned Index = Entry->getSecond();
+ while (Index < BindingsList.size() && BindingsList[Index].Decl == VD) {
+ if (BindingsList[Index].ResClass == ResClass)
+ return &BindingsList[Index];
+ Index++;
+ }
----------------
damyanp wrote:
```suggestion
for (unsigned Index = Entry->getSecond(); Index < BindingsList.size() && BindingsList[Index].Decl == VD; ++Index) {
if (BindingsList[Index].ResClass == ResClass)
return &BindingsList[Index];
}
```
https://github.com/llvm/llvm-project/pull/111203
More information about the cfe-commits
mailing list