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 18 namespace llvm { 19 class GlobalVariable; 20 21 namespace hlsl { 22 23 enum class ResourceClass : uint8_t { 24 SRV = 0, 25 UAV, 26 CBuffer, 27 Sampler, 28 Invalid, 29 NumClasses = Invalid, 30 }; 31 32 // The value ordering of this enumeration is part of the DXIL ABI. Elements 33 // can only be added to the end, and not removed. 34 enum class ResourceKind : uint32_t { 35 Invalid = 0, 36 Texture1D, 37 Texture2D, 38 Texture2DMS, 39 Texture3D, 40 TextureCube, 41 Texture1DArray, 42 Texture2DArray, 43 Texture2DMSArray, 44 TextureCubeArray, 45 TypedBuffer, 46 RawBuffer, 47 StructuredBuffer, 48 CBuffer, 49 Sampler, 50 TBuffer, 51 RTAccelerationStructure, 52 FeedbackTexture2D, 53 FeedbackTexture2DArray, 54 NumEntries, 55 }; 56 57 // The value ordering of this enumeration is part of the DXIL ABI. Elements 58 // can only be added to the end, and not removed. 59 enum class ElementType : uint32_t { 60 Invalid = 0, 61 I1, 62 I16, 63 U16, 64 I32, 65 U32, 66 I64, 67 U64, 68 F16, 69 F32, 70 F64, 71 SNormF16, 72 UNormF16, 73 SNormF32, 74 UNormF32, 75 SNormF64, 76 UNormF64, 77 PackedS8x32, 78 PackedU8x32, 79 }; 80 81 class FrontendResource { 82 MDNode *Entry; 83 84 public: FrontendResource(MDNode * E)85 FrontendResource(MDNode *E) : Entry(E) { 86 assert(Entry->getNumOperands() == 6 && "Unexpected metadata shape"); 87 } 88 89 FrontendResource(GlobalVariable *GV, ResourceKind RK, ElementType ElTy, 90 bool IsROV, uint32_t ResIndex, uint32_t Space); 91 92 GlobalVariable *getGlobalVariable(); 93 StringRef getSourceType(); 94 ResourceKind getResourceKind(); 95 ElementType getElementType(); 96 bool getIsROV(); 97 uint32_t getResourceIndex(); 98 uint32_t getSpace(); getMetadata()99 MDNode *getMetadata() { return Entry; } 100 }; 101 } // namespace hlsl 102 } // namespace llvm 103 104 #endif // LLVM_FRONTEND_HLSL_HLSLRESOURCE_H 105