clang
23.0.0git
include
clang
AST
HLSLResource.h
Go to the documentation of this file.
1
//===- HLSLResource.h - Routines for HLSL resources and bindings ----------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
//
9
// This file provides shared routines to help analyze HLSL resources and
10
// theirs bindings during Sema and CodeGen.
11
//
12
//===----------------------------------------------------------------------===//
13
14
#ifndef LLVM_CLANG_AST_HLSLRESOURCE_H
15
#define LLVM_CLANG_AST_HLSLRESOURCE_H
16
17
#include "
clang/AST/ASTContext.h
"
18
#include "
clang/AST/Attr.h
"
19
#include "clang/AST/Attrs.inc"
20
#include "
clang/AST/DeclBase.h
"
21
#include "
clang/Basic/TargetInfo.h
"
22
#include "
clang/Support/Compiler.h
"
23
#include "llvm/Frontend/HLSL/HLSLResource.h"
24
#include "llvm/Support/raw_ostream.h"
25
26
namespace
clang
{
27
28
class
HLSLResourceBindingAttr;
29
class
HLSLRVkBindingAttr;
30
31
namespace
hlsl
{
32
33
struct
ResourceBindingAttrs
{
34
HLSLResourceBindingAttr *
RegBinding
;
35
HLSLVkBindingAttr *
VkBinding
;
36
37
ResourceBindingAttrs
(
const
Decl
*D) {
38
RegBinding
= D->
getAttr
<HLSLResourceBindingAttr>();
39
bool
IsSpirv = D->
getASTContext
().
getTargetInfo
().
getTriple
().isSPIRV();
40
VkBinding
= IsSpirv ? D->
getAttr
<HLSLVkBindingAttr>() :
nullptr
;
41
}
42
43
bool
hasBinding
()
const
{
return
RegBinding
||
VkBinding
; }
44
bool
isExplicit
()
const
{
45
return
(
RegBinding
&&
RegBinding
->hasRegisterSlot()) ||
VkBinding
;
46
}
47
48
unsigned
getSlot
()
const
{
49
assert(
isExplicit
() &&
"no explicit binding"
);
50
if
(
VkBinding
)
51
return
VkBinding
->getBinding();
52
if
(
RegBinding
&&
RegBinding
->hasRegisterSlot())
53
return
RegBinding
->getSlotNumber();
54
llvm_unreachable(
"no explicit binding"
);
55
}
56
57
unsigned
getSpace
()
const
{
58
if
(
VkBinding
)
59
return
VkBinding
->getSet();
60
if
(
RegBinding
)
61
return
RegBinding
->getSpaceNumber();
62
return
0;
63
}
64
65
bool
hasImplicitOrderID
()
const
{
66
return
RegBinding
&&
RegBinding
->hasImplicitBindingOrderID();
67
}
68
69
unsigned
getImplicitOrderID
()
const
{
70
assert(
hasImplicitOrderID
());
71
return
RegBinding
->getImplicitBindingOrderID();
72
}
73
74
void
setImplicitOrderID
(
unsigned
Value
)
const
{
75
assert(
hasBinding
() && !
isExplicit
() && !
hasImplicitOrderID
());
76
RegBinding
->setImplicitBindingOrderID(
Value
);
77
}
78
void
setCounterImplicitOrderID
(
unsigned
Value
)
const
{
79
assert(
hasBinding
() && !
hasCounterImplicitOrderID
());
80
RegBinding
->setImplicitCounterBindingOrderID(
Value
);
81
}
82
83
bool
hasCounterImplicitOrderID
()
const
{
84
return
RegBinding
&&
RegBinding
->hasImplicitCounterBindingOrderID();
85
}
86
87
unsigned
getCounterImplicitOrderID
()
const
{
88
assert(
hasCounterImplicitOrderID
());
89
return
RegBinding
->getImplicitCounterBindingOrderID();
90
}
91
};
92
93
inline
uint32_t
getResourceDimensions
(llvm::dxil::ResourceDimension
Dim
) {
94
switch
(
Dim
) {
95
case
llvm::dxil::ResourceDimension::Dim1D:
96
return
1;
97
break
;
98
case
llvm::dxil::ResourceDimension::Dim2D:
99
return
2;
100
break
;
101
case
llvm::dxil::ResourceDimension::Dim3D:
102
case
llvm::dxil::ResourceDimension::Cube:
103
return
3;
104
break
;
105
case
llvm::dxil::ResourceDimension::Unknown:
106
llvm_unreachable(
107
"We cannot get the dimension of a resource with unknown dimension."
);
108
}
109
}
110
111
}
// namespace hlsl
112
113
}
// namespace clang
114
115
#endif
// LLVM_CLANG_AST_HLSLRESOURCE_H
ASTContext.h
Defines the clang::ASTContext interface.
Attr.h
DeclBase.h
clang::ASTContext::getTargetInfo
const TargetInfo & getTargetInfo() const
Definition
ASTContext.h:909
clang::Decl
Decl - This represents one declaration (or definition), e.g.
Definition
DeclBase.h:86
clang::Decl::getAttr
T * getAttr() const
Definition
DeclBase.h:573
clang::Decl::getASTContext
ASTContext & getASTContext() const LLVM_READONLY
Definition
DeclBase.cpp:546
clang::TargetInfo::getTriple
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Definition
TargetInfo.h:1319
clang::Value
Definition
Value.h:95
TargetInfo.h
Defines the clang::TargetInfo interface.
Compiler.h
clang::hlsl::getResourceDimensions
uint32_t getResourceDimensions(llvm::dxil::ResourceDimension Dim)
Definition
HLSLResource.h:93
clang
The JSON file list parser is used to communicate input to InstallAPI.
Definition
CalledOnceCheck.h:17
clang::OpenACCGangKind::Dim
@ Dim
dim:
Definition
OpenACCKinds.h:610
hlsl
Definition
hlsl_alias_intrinsics.h:12
clang::hlsl::ResourceBindingAttrs::isExplicit
bool isExplicit() const
Definition
HLSLResource.h:44
clang::hlsl::ResourceBindingAttrs::getImplicitOrderID
unsigned getImplicitOrderID() const
Definition
HLSLResource.h:69
clang::hlsl::ResourceBindingAttrs::setCounterImplicitOrderID
void setCounterImplicitOrderID(unsigned Value) const
Definition
HLSLResource.h:78
clang::hlsl::ResourceBindingAttrs::hasCounterImplicitOrderID
bool hasCounterImplicitOrderID() const
Definition
HLSLResource.h:83
clang::hlsl::ResourceBindingAttrs::getSpace
unsigned getSpace() const
Definition
HLSLResource.h:57
clang::hlsl::ResourceBindingAttrs::VkBinding
HLSLVkBindingAttr * VkBinding
Definition
HLSLResource.h:35
clang::hlsl::ResourceBindingAttrs::getCounterImplicitOrderID
unsigned getCounterImplicitOrderID() const
Definition
HLSLResource.h:87
clang::hlsl::ResourceBindingAttrs::hasBinding
bool hasBinding() const
Definition
HLSLResource.h:43
clang::hlsl::ResourceBindingAttrs::ResourceBindingAttrs
ResourceBindingAttrs(const Decl *D)
Definition
HLSLResource.h:37
clang::hlsl::ResourceBindingAttrs::hasImplicitOrderID
bool hasImplicitOrderID() const
Definition
HLSLResource.h:65
clang::hlsl::ResourceBindingAttrs::getSlot
unsigned getSlot() const
Definition
HLSLResource.h:48
clang::hlsl::ResourceBindingAttrs::RegBinding
HLSLResourceBindingAttr * RegBinding
Definition
HLSLResource.h:34
clang::hlsl::ResourceBindingAttrs::setImplicitOrderID
void setImplicitOrderID(unsigned Value) const
Definition
HLSLResource.h:74
Generated on
for clang by
1.14.0