blob: 9cdd81b2d8dab714de39d3575ab32607bde15f50 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
//===- HLSLResource.h - Routines for HLSL resources and bindings ----------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file provides shared routines to help analyze HLSL resources and
// theirs bindings during Sema and CodeGen.
//
//===----------------------------------------------------------------------===//
#ifndef LLVM_CLANG_AST_HLSLRESOURCE_H
#define LLVM_CLANG_AST_HLSLRESOURCE_H
#include "clang/AST/ASTContext.h"
#include "clang/AST/Attr.h"
#include "clang/AST/Attrs.inc"
#include "clang/AST/DeclBase.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Support/Compiler.h"
#include "llvm/Support/raw_ostream.h"
namespace clang {
class HLSLResourceBindingAttr;
class HLSLRVkBindingAttr;
namespace hlsl {
struct ResourceBindingAttrs {
HLSLResourceBindingAttr *RegBinding;
HLSLVkBindingAttr *VkBinding;
ResourceBindingAttrs(const Decl *D) {
RegBinding = D->getAttr<HLSLResourceBindingAttr>();
bool IsSpirv = D->getASTContext().getTargetInfo().getTriple().isSPIRV();
VkBinding = IsSpirv ? D->getAttr<HLSLVkBindingAttr>() : nullptr;
}
bool hasBinding() const { return RegBinding || VkBinding; }
bool isExplicit() const {
return (RegBinding && RegBinding->hasRegisterSlot()) || VkBinding;
}
unsigned getSlot() const {
assert(isExplicit() && "no explicit binding");
if (VkBinding)
return VkBinding->getBinding();
if (RegBinding && RegBinding->hasRegisterSlot())
return RegBinding->getSlotNumber();
llvm_unreachable("no explicit binding");
}
unsigned getSpace() const {
if (VkBinding)
return VkBinding->getSet();
if (RegBinding)
return RegBinding->getSpaceNumber();
return 0;
}
bool hasImplicitOrderID() const {
return RegBinding && RegBinding->hasImplicitBindingOrderID();
}
unsigned getImplicitOrderID() const {
assert(hasImplicitOrderID());
return RegBinding->getImplicitBindingOrderID();
}
};
} // namespace hlsl
} // namespace clang
#endif // LLVM_CLANG_AST_HLSLRESOURCE_H
|