1 //===- HLSLResource.h - HLSL Resource helper objects ----------------------===//
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 /// \file This file contains helper objects for working with HLSL Resources.
10 ///
11 //===----------------------------------------------------------------------===//
12 
13 #ifndef LLVM_FRONTEND_HLSL_HLSLRESOURCE_H
14 #define LLVM_FRONTEND_HLSL_HLSLRESOURCE_H
15 
16 #include "llvm/IR/Metadata.h"
17 #include "llvm/Support/DXILABI.h"
18 
19 namespace llvm {
20 class GlobalVariable;
21 
22 namespace hlsl {
23 
24 enum class ResourceClass : uint8_t {
25   SRV = 0,
26   UAV,
27   CBuffer,
28   Sampler,
29   Invalid,
30   NumClasses = Invalid,
31 };
32 
33 // For now we use DXIL ABI enum values directly. This may change in the future.
34 using dxil::ElementType;
35 using dxil::ResourceKind;
36 
37 class FrontendResource {
38   MDNode *Entry;
39 
40 public:
FrontendResource(MDNode * E)41   FrontendResource(MDNode *E) : Entry(E) {
42     assert(Entry->getNumOperands() == 6 && "Unexpected metadata shape");
43   }
44 
45   FrontendResource(GlobalVariable *GV, ResourceKind RK, ElementType ElTy,
46                    bool IsROV, uint32_t ResIndex, uint32_t Space);
47 
48   GlobalVariable *getGlobalVariable();
49   StringRef getSourceType();
50   ResourceKind getResourceKind();
51   ElementType getElementType();
52   bool getIsROV();
53   uint32_t getResourceIndex();
54   uint32_t getSpace();
getMetadata()55   MDNode *getMetadata() { return Entry; }
56 };
57 } // namespace hlsl
58 } // namespace llvm
59 
60 #endif // LLVM_FRONTEND_HLSL_HLSLRESOURCE_H
61