clang 23.0.0git
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
18#include "clang/AST/Attr.h"
19#include "clang/AST/Attrs.inc"
20#include "clang/AST/DeclBase.h"
23#include "llvm/Frontend/HLSL/HLSLResource.h"
24#include "llvm/Support/raw_ostream.h"
25
26namespace clang {
27
28class HLSLResourceBindingAttr;
29class HLSLRVkBindingAttr;
30
31namespace hlsl {
32
34 HLSLResourceBindingAttr *RegBinding;
35 HLSLVkBindingAttr *VkBinding;
36
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 {
80 RegBinding->setImplicitCounterBindingOrderID(Value);
81 }
82
84 return RegBinding && RegBinding->hasImplicitCounterBindingOrderID();
85 }
86
87 unsigned getCounterImplicitOrderID() const {
89 return RegBinding->getImplicitCounterBindingOrderID();
90 }
91};
92
93inline 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
Defines the clang::ASTContext interface.
const TargetInfo & getTargetInfo() const
Definition ASTContext.h:909
Decl - This represents one declaration (or definition), e.g.
Definition DeclBase.h:86
T * getAttr() const
Definition DeclBase.h:573
ASTContext & getASTContext() const LLVM_READONLY
Definition DeclBase.cpp:546
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Defines the clang::TargetInfo interface.
uint32_t getResourceDimensions(llvm::dxil::ResourceDimension Dim)
The JSON file list parser is used to communicate input to InstallAPI.
void setCounterImplicitOrderID(unsigned Value) const
unsigned getCounterImplicitOrderID() const
HLSLResourceBindingAttr * RegBinding
void setImplicitOrderID(unsigned Value) const