aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/SemaHLSL.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib/Sema/SemaHLSL.cpp')
-rw-r--r--clang/lib/Sema/SemaHLSL.cpp31
1 files changed, 11 insertions, 20 deletions
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 940d510..129b03c 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -19,6 +19,7 @@
#include "clang/AST/DeclarationName.h"
#include "clang/AST/DynamicRecursiveASTVisitor.h"
#include "clang/AST/Expr.h"
+#include "clang/AST/HLSLResource.h"
#include "clang/AST/Type.h"
#include "clang/AST/TypeLoc.h"
#include "clang/Basic/Builtins.h"
@@ -52,6 +53,7 @@
#include <utility>
using namespace clang;
+using namespace clang::hlsl;
using RegisterType = HLSLResourceBindingAttr::RegisterType;
static CXXRecordDecl *createHostLayoutStruct(Sema &S,
@@ -3799,19 +3801,8 @@ bool SemaHLSL::initGlobalResourceDecl(VarDecl *VD) {
uint64_t UIntTySize = AST.getTypeSize(AST.UnsignedIntTy);
uint64_t IntTySize = AST.getTypeSize(AST.IntTy);
- // Gather resource binding information from attributes.
- HLSLResourceBindingAttr *RBA = VD->getAttr<HLSLResourceBindingAttr>();
- HLSLVkBindingAttr *VkBinding = VD->getAttr<HLSLVkBindingAttr>();
- std::optional<uint32_t> RegisterSlot;
- uint32_t SpaceNo = 0;
- if (VkBinding) {
- RegisterSlot = VkBinding->getBinding();
- SpaceNo = VkBinding->getSet();
- } else if (RBA) {
- if (RBA->hasRegisterSlot())
- RegisterSlot = RBA->getSlotNumber();
- SpaceNo = RBA->getSpaceNumber();
- }
+ // Gather resource binding attributes.
+ ResourceBindingAttrs Binding(VD);
// Find correct initialization method and create its arguments.
QualType ResourceTy = VD->getType();
@@ -3819,21 +3810,21 @@ bool SemaHLSL::initGlobalResourceDecl(VarDecl *VD) {
CXXMethodDecl *CreateMethod = nullptr;
llvm::SmallVector<Expr *> Args;
- if (RegisterSlot.has_value()) {
+ if (Binding.isExplicit()) {
// The resource has explicit binding.
CreateMethod = lookupMethod(SemaRef, ResourceDecl, "__createFromBinding",
VD->getLocation());
- IntegerLiteral *RegSlot = IntegerLiteral::Create(
- AST, llvm::APInt(UIntTySize, RegisterSlot.value()), AST.UnsignedIntTy,
- SourceLocation());
+ IntegerLiteral *RegSlot =
+ IntegerLiteral::Create(AST, llvm::APInt(UIntTySize, Binding.getSlot()),
+ AST.UnsignedIntTy, SourceLocation());
Args.push_back(RegSlot);
} else {
// The resource has implicit binding.
CreateMethod =
lookupMethod(SemaRef, ResourceDecl, "__createFromImplicitBinding",
VD->getLocation());
- uint32_t OrderID = (RBA && RBA->hasImplicitBindingOrderID())
- ? RBA->getImplicitBindingOrderID()
+ uint32_t OrderID = (Binding.hasImplicitOrderID())
+ ? Binding.getImplicitOrderID()
: getNextImplicitBindingOrderID();
IntegerLiteral *OrderId =
IntegerLiteral::Create(AST, llvm::APInt(UIntTySize, OrderID),
@@ -3848,7 +3839,7 @@ bool SemaHLSL::initGlobalResourceDecl(VarDecl *VD) {
return false;
IntegerLiteral *Space =
- IntegerLiteral::Create(AST, llvm::APInt(UIntTySize, SpaceNo),
+ IntegerLiteral::Create(AST, llvm::APInt(UIntTySize, Binding.getSpace()),
AST.UnsignedIntTy, SourceLocation());
Args.push_back(Space);