|
34 | 34 | #include "llvm/Support/Alignment.h"
|
35 | 35 | #include "llvm/Support/ErrorHandling.h"
|
36 | 36 | #include "llvm/Support/FormatVariadic.h"
|
| 37 | +#include <utility> |
37 | 38 |
|
38 | 39 | using namespace clang;
|
39 | 40 | using namespace CodeGen;
|
@@ -235,6 +236,35 @@ static void fillPackoffsetLayout(const HLSLBufferDecl *BufDecl,
|
235 | 236 | }
|
236 | 237 | }
|
237 | 238 |
|
| 239 | +std::pair<llvm::Intrinsic::ID, bool> |
| 240 | +CGHLSLRuntime::getCreateHandleFromBindingIntrinsic() { |
| 241 | + switch (getArch()) { |
| 242 | + case llvm::Triple::dxil: |
| 243 | + return std::pair(llvm::Intrinsic::dx_resource_handlefrombinding, true); |
| 244 | + case llvm::Triple::spirv: |
| 245 | + return std::pair(llvm::Intrinsic::spv_resource_handlefrombinding, false); |
| 246 | + default: |
| 247 | + llvm_unreachable("Intrinsic resource_handlefrombinding not supported by " |
| 248 | + "target architecture"); |
| 249 | + } |
| 250 | +} |
| 251 | + |
| 252 | +std::pair<llvm::Intrinsic::ID, bool> |
| 253 | +CGHLSLRuntime::getCreateHandleFromImplicitBindingIntrinsic() { |
| 254 | + switch (getArch()) { |
| 255 | + case llvm::Triple::dxil: |
| 256 | + return std::pair(llvm::Intrinsic::dx_resource_handlefromimplicitbinding, |
| 257 | + true); |
| 258 | + case llvm::Triple::spirv: |
| 259 | + return std::pair(llvm::Intrinsic::spv_resource_handlefromimplicitbinding, |
| 260 | + false); |
| 261 | + default: |
| 262 | + llvm_unreachable( |
| 263 | + "Intrinsic resource_handlefromimplicitbinding not supported by " |
| 264 | + "target architecture"); |
| 265 | + } |
| 266 | +} |
| 267 | + |
238 | 268 | // Codegen for HLSLBufferDecl
|
239 | 269 | void CGHLSLRuntime::addBuffer(const HLSLBufferDecl *BufDecl) {
|
240 | 270 |
|
@@ -564,35 +594,35 @@ void CGHLSLRuntime::initializeBufferFromBinding(const HLSLBufferDecl *BufDecl,
|
564 | 594 | llvm::ConstantInt::get(CGM.IntTy, RBA ? RBA->getSpaceNumber() : 0);
|
565 | 595 | Value *Name = nullptr;
|
566 | 596 |
|
567 |
| - // DXIL intrinsic includes resource name |
568 |
| - if (getArch() == Triple::dxil) { |
569 |
| - std::string Str = std::string(BufDecl->getName()); |
570 |
| - std::string GlobalName = Str + ".str"; |
| 597 | + auto [IntrinsicID, HasNameArg] = |
| 598 | + RBA->hasRegisterSlot() |
| 599 | + ? CGM.getHLSLRuntime().getCreateHandleFromBindingIntrinsic() |
| 600 | + : CGM.getHLSLRuntime().getCreateHandleFromImplicitBindingIntrinsic(); |
| 601 | + |
| 602 | + if (HasNameArg) { |
| 603 | + std::string Str(BufDecl->getName()); |
| 604 | + std::string GlobalName(Str + ".str"); |
571 | 605 | Name = CGM.GetAddrOfConstantCString(Str, GlobalName.c_str()).getPointer();
|
572 | 606 | }
|
573 | 607 |
|
574 | 608 | // buffer with explicit binding
|
575 | 609 | if (RBA->hasRegisterSlot()) {
|
576 | 610 | auto *RegSlot = llvm::ConstantInt::get(CGM.IntTy, RBA->getSlotNumber());
|
577 |
| - Intrinsic::ID Intr = |
578 |
| - CGM.getHLSLRuntime().getCreateHandleFromBindingIntrinsic(); |
579 | 611 | if (Name)
|
580 |
| - initializeBuffer(CGM, GV, Intr, |
| 612 | + initializeBuffer(CGM, GV, IntrinsicID, |
581 | 613 | {Space, RegSlot, RangeSize, Index, NonUniform, Name});
|
582 | 614 | else
|
583 |
| - initializeBuffer(CGM, GV, Intr, |
| 615 | + initializeBuffer(CGM, GV, IntrinsicID, |
584 | 616 | {Space, RegSlot, RangeSize, Index, NonUniform});
|
585 | 617 | } else {
|
586 | 618 | // buffer with implicit binding
|
587 | 619 | auto *OrderID =
|
588 | 620 | llvm::ConstantInt::get(CGM.IntTy, RBA->getImplicitBindingOrderID());
|
589 |
| - Intrinsic::ID Intr = |
590 |
| - CGM.getHLSLRuntime().getCreateHandleFromImplicitBindingIntrinsic(); |
591 | 621 | if (Name)
|
592 |
| - initializeBuffer(CGM, GV, Intr, |
| 622 | + initializeBuffer(CGM, GV, IntrinsicID, |
593 | 623 | {OrderID, Space, RangeSize, Index, NonUniform, Name});
|
594 | 624 | else
|
595 |
| - initializeBuffer(CGM, GV, Intr, |
| 625 | + initializeBuffer(CGM, GV, IntrinsicID, |
596 | 626 | {OrderID, Space, RangeSize, Index, NonUniform});
|
597 | 627 | }
|
598 | 628 | }
|
|
0 commit comments