aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGHLSLRuntime.cpp
diff options
context:
space:
mode:
authorSteven Perron <stevenperron@google.com>2025-06-13 12:21:38 -0400
committerGitHub <noreply@github.com>2025-06-13 12:21:38 -0400
commitbd33eef7f1013bea24289a898f788a2efe9d8282 (patch)
tree52f5c0548cf1adc9001a8047af0e6affc9a9f28e /clang/lib/CodeGen/CGHLSLRuntime.cpp
parentdec576514cb7106c59a5059ac6d52ebdf5de5275 (diff)
downloadllvm-bd33eef7f1013bea24289a898f788a2efe9d8282.zip
llvm-bd33eef7f1013bea24289a898f788a2efe9d8282.tar.gz
llvm-bd33eef7f1013bea24289a898f788a2efe9d8282.tar.bz2
[HLSL][SPIRV] Use resource names (#143412)
The SPIR-V backend does not have access to the original name of a resource in the source, so it tries to create a name. This leads to some problems with reflection. That is why start to pass the name of the resource from Clang to the SPIR-V backend. Fixes #138533
Diffstat (limited to 'clang/lib/CodeGen/CGHLSLRuntime.cpp')
-rw-r--r--clang/lib/CodeGen/CGHLSLRuntime.cpp49
1 files changed, 8 insertions, 41 deletions
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 720dac8..977ff79 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -237,35 +237,6 @@ static void fillPackoffsetLayout(const HLSLBufferDecl *BufDecl,
}
}
-std::pair<llvm::Intrinsic::ID, bool>
-CGHLSLRuntime::getCreateHandleFromBindingIntrinsic() {
- switch (getArch()) {
- case llvm::Triple::dxil:
- return std::pair(llvm::Intrinsic::dx_resource_handlefrombinding, true);
- case llvm::Triple::spirv:
- return std::pair(llvm::Intrinsic::spv_resource_handlefrombinding, false);
- default:
- llvm_unreachable("Intrinsic resource_handlefrombinding not supported by "
- "target architecture");
- }
-}
-
-std::pair<llvm::Intrinsic::ID, bool>
-CGHLSLRuntime::getCreateHandleFromImplicitBindingIntrinsic() {
- switch (getArch()) {
- case llvm::Triple::dxil:
- return std::pair(llvm::Intrinsic::dx_resource_handlefromimplicitbinding,
- true);
- case llvm::Triple::spirv:
- return std::pair(llvm::Intrinsic::spv_resource_handlefromimplicitbinding,
- false);
- default:
- llvm_unreachable(
- "Intrinsic resource_handlefromimplicitbinding not supported by "
- "target architecture");
- }
-}
-
// Codegen for HLSLBufferDecl
void CGHLSLRuntime::addBuffer(const HLSLBufferDecl *BufDecl) {
@@ -625,31 +596,27 @@ void CGHLSLRuntime::initializeBufferFromBinding(const HLSLBufferDecl *BufDecl,
llvm::ConstantInt::get(CGM.IntTy, RBA ? RBA->getSpaceNumber() : 0);
Value *Name = nullptr;
- auto [IntrinsicID, HasNameArg] =
+ llvm::Intrinsic::ID IntrinsicID =
RBA->hasRegisterSlot()
? CGM.getHLSLRuntime().getCreateHandleFromBindingIntrinsic()
: CGM.getHLSLRuntime().getCreateHandleFromImplicitBindingIntrinsic();
- if (HasNameArg) {
- std::string Str(BufDecl->getName());
- std::string GlobalName(Str + ".str");
- Name = CGM.GetAddrOfConstantCString(Str, GlobalName.c_str()).getPointer();
- }
+ std::string Str(BufDecl->getName());
+ std::string GlobalName(Str + ".str");
+ Name = CGM.GetAddrOfConstantCString(Str, GlobalName.c_str()).getPointer();
// buffer with explicit binding
if (RBA->hasRegisterSlot()) {
auto *RegSlot = llvm::ConstantInt::get(CGM.IntTy, RBA->getSlotNumber());
- SmallVector<Value *> Args{Space, RegSlot, RangeSize, Index, NonUniform};
- if (Name)
- Args.push_back(Name);
+ SmallVector<Value *> Args{Space, RegSlot, RangeSize,
+ Index, NonUniform, Name};
initializeBuffer(CGM, GV, IntrinsicID, Args);
} else {
// buffer with implicit binding
auto *OrderID =
llvm::ConstantInt::get(CGM.IntTy, RBA->getImplicitBindingOrderID());
- SmallVector<Value *> Args{OrderID, Space, RangeSize, Index, NonUniform};
- if (Name)
- Args.push_back(Name);
+ SmallVector<Value *> Args{OrderID, Space, RangeSize,
+ Index, NonUniform, Name};
initializeBuffer(CGM, GV, IntrinsicID, Args);
}
}