Thanks to visit codestin.com
Credit goes to clang.llvm.org

clang 22.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/Support/raw_ostream.h"
24
25namespace clang {
26
27class HLSLResourceBindingAttr;
28class HLSLRVkBindingAttr;
29
30namespace hlsl {
31
33 HLSLResourceBindingAttr *RegBinding;
34 HLSLVkBindingAttr *VkBinding;
35
37 RegBinding = D->getAttr<HLSLResourceBindingAttr>();
38 bool IsSpirv = D->getASTContext().getTargetInfo().getTriple().isSPIRV();
39 VkBinding = IsSpirv ? D->getAttr<HLSLVkBindingAttr>() : nullptr;
40 }
41
42 bool hasBinding() const { return RegBinding || VkBinding; }
43 bool isExplicit() const {
44 return (RegBinding && RegBinding->hasRegisterSlot()) || VkBinding;
45 }
46
47 unsigned getSlot() const {
48 assert(isExplicit() && "no explicit binding");
49 if (VkBinding)
50 return VkBinding->getBinding();
51 if (RegBinding && RegBinding->hasRegisterSlot())
52 return RegBinding->getSlotNumber();
53 llvm_unreachable("no explicit binding");
54 }
55
56 unsigned getSpace() const {
57 if (VkBinding)
58 return VkBinding->getSet();
59 if (RegBinding)
60 return RegBinding->getSpaceNumber();
61 return 0;
62 }
63
64 bool hasImplicitOrderID() const {
65 return RegBinding && RegBinding->hasImplicitBindingOrderID();
66 }
67
68 unsigned getImplicitOrderID() const {
69 assert(hasImplicitOrderID());
70 return RegBinding->getImplicitBindingOrderID();
71 }
72};
73
74} // namespace hlsl
75
76} // namespace clang
77
78#endif // LLVM_CLANG_AST_HLSLRESOURCE_H
Defines the clang::ASTContext interface.
const TargetInfo & getTargetInfo() const
Definition ASTContext.h:891
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:524
const llvm::Triple & getTriple() const
Returns the target triple of the primary target.
Defines the clang::TargetInfo interface.
The JSON file list parser is used to communicate input to InstallAPI.
HLSLResourceBindingAttr * RegBinding