[llvm] [SPIRV] Implement handle_fromBinding intrinsic. (PR #111052)

Nathan Gauër via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 4 01:02:31 PDT 2024


================
@@ -713,6 +713,29 @@ Register SPIRVGlobalRegistry::buildGlobalVariable(
   return Reg;
 }
 
+Register SPIRVGlobalRegistry::getOrCreateGlobalVariableWithBinding(
+    const SPIRVType *VarType, uint32_t Set, uint32_t Binding,
+    MachineIRBuilder &MIRBuilder) {
+  SPIRVType *VarPointerTypeReg = getOrCreateSPIRVPointerType(
+      VarType, MIRBuilder, SPIRV::StorageClass::UniformConstant);
+  Register VarReg =
+      MIRBuilder.getMRI()->createVirtualRegister(&SPIRV::iIDRegClass);
+
+  // TODO: The name should come from the llvm-ir, but how that name will be
+  // passed from the HLSL to the backend has not been decided. Using this place
+  // holder for now. We use the result register of the type in the name.
+  std::string name = ("__resource_" + Twine(VarType->getOperand(0).getReg()) +
+                      "_" + Twine(Set) + "_" + Twine(Binding))
+                         .str();
+  buildGlobalVariable(VarReg, VarPointerTypeReg, name, nullptr,
----------------
Keenuts wrote:

```suggestion
  std::string Name = ("__resource_" + Twine(VarType->getOperand(0).getReg()) +
                      "_" + Twine(Set) + "_" + Twine(Binding))
                         .str();
  buildGlobalVariable(VarReg, VarPointerTypeReg, Name, nullptr,
```

https://github.com/llvm/llvm-project/pull/111052


More information about the llvm-commits mailing list