LLVM 20.0.0git
DXILResource.h
Go to the documentation of this file.
1//===- DXILResource.h - Representations of DXIL resources -------*- C++ -*-===//
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#ifndef LLVM_ANALYSIS_DXILRESOURCE_H
10#define LLVM_ANALYSIS_DXILRESOURCE_H
11
12#include "llvm/IR/Value.h"
14
15namespace llvm {
16class MDTuple;
17
18namespace dxil {
19
21 struct ResourceBinding {
22 uint32_t UniqueID;
23 uint32_t Space;
24 uint32_t LowerBound;
25 uint32_t Size;
26
27 bool operator==(const ResourceBinding &RHS) const {
28 return std::tie(UniqueID, Space, LowerBound, Size) ==
29 std::tie(RHS.UniqueID, RHS.Space, RHS.LowerBound, RHS.Size);
30 }
31 bool operator!=(const ResourceBinding &RHS) const {
32 return !(*this == RHS);
33 }
34 };
35
36 struct UAVInfo {
37 bool GloballyCoherent;
38 bool HasCounter;
39 bool IsROV;
40
41 bool operator==(const UAVInfo &RHS) const {
42 return std::tie(GloballyCoherent, HasCounter, IsROV) ==
43 std::tie(RHS.GloballyCoherent, RHS.HasCounter, RHS.IsROV);
44 }
45 bool operator!=(const UAVInfo &RHS) const { return !(*this == RHS); }
46 };
47
48 struct StructInfo {
49 uint32_t Stride;
50 Align Alignment;
51
52 bool operator==(const StructInfo &RHS) const {
53 return std::tie(Stride, Alignment) == std::tie(RHS.Stride, RHS.Alignment);
54 }
55 bool operator!=(const StructInfo &RHS) const { return !(*this == RHS); }
56 };
57
58 struct TypedInfo {
59 dxil::ElementType ElementTy;
61
62 bool operator==(const TypedInfo &RHS) const {
63 return std::tie(ElementTy, ElementCount) ==
64 std::tie(RHS.ElementTy, RHS.ElementCount);
65 }
66 bool operator!=(const TypedInfo &RHS) const { return !(*this == RHS); }
67 };
68
69 struct MSInfo {
70 uint32_t Count;
71
72 bool operator==(const MSInfo &RHS) const { return Count == RHS.Count; }
73 bool operator!=(const MSInfo &RHS) const { return !(*this == RHS); }
74 };
75
76 struct FeedbackInfo {
78
79 bool operator==(const FeedbackInfo &RHS) const { return Type == RHS.Type; }
80 bool operator!=(const FeedbackInfo &RHS) const { return !(*this == RHS); }
81 };
82
83 // Universal properties.
84 Value *Symbol;
85 StringRef Name;
86
89
90 ResourceBinding Binding = {};
91
92 // Resource class dependent properties.
93 // CBuffer, Sampler, and RawBuffer end here.
94 union {
95 UAVInfo UAVFlags; // UAV
98 };
99
100 // Resource kind dependent properties.
101 union {
102 StructInfo Struct; // StructuredBuffer
103 TypedInfo Typed; // All SRV/UAV except Raw/StructuredBuffer
104 FeedbackInfo Feedback; // FeedbackTexture
105 };
106
107 MSInfo MultiSample;
108
109 // Conditions to check before accessing union members.
110 bool isUAV() const;
111 bool isCBuffer() const;
112 bool isSampler() const;
113 bool isStruct() const;
114 bool isTyped() const;
115 bool isFeedback() const;
116 bool isMultiSample() const;
117
119 StringRef Name)
120 : Symbol(Symbol), Name(Name), RC(RC), Kind(Kind) {}
121
122public:
123 static ResourceInfo SRV(Value *Symbol, StringRef Name,
125 dxil::ResourceKind Kind);
126 static ResourceInfo RawBuffer(Value *Symbol, StringRef Name);
127 static ResourceInfo StructuredBuffer(Value *Symbol, StringRef Name,
128 uint32_t Stride, Align Alignment);
129 static ResourceInfo Texture2DMS(Value *Symbol, StringRef Name,
130 dxil::ElementType ElementTy,
131 uint32_t ElementCount, uint32_t SampleCount);
132 static ResourceInfo Texture2DMSArray(Value *Symbol, StringRef Name,
133 dxil::ElementType ElementTy,
135 uint32_t SampleCount);
136
137 static ResourceInfo UAV(Value *Symbol, StringRef Name,
139 bool GloballyCoherent, bool IsROV,
140 dxil::ResourceKind Kind);
141 static ResourceInfo RWRawBuffer(Value *Symbol, StringRef Name,
142 bool GloballyCoherent, bool IsROV);
143 static ResourceInfo RWStructuredBuffer(Value *Symbol, StringRef Name,
144 uint32_t Stride,
145 Align Alignment, bool GloballyCoherent,
146 bool IsROV, bool HasCounter);
147 static ResourceInfo RWTexture2DMS(Value *Symbol, StringRef Name,
148 dxil::ElementType ElementTy,
149 uint32_t ElementCount, uint32_t SampleCount,
150 bool GloballyCoherent);
151 static ResourceInfo RWTexture2DMSArray(Value *Symbol, StringRef Name,
152 dxil::ElementType ElementTy,
154 uint32_t SampleCount,
155 bool GloballyCoherent);
156 static ResourceInfo FeedbackTexture2D(Value *Symbol, StringRef Name,
157 dxil::SamplerFeedbackType FeedbackTy);
158 static ResourceInfo
160 dxil::SamplerFeedbackType FeedbackTy);
161
162 static ResourceInfo CBuffer(Value *Symbol, StringRef Name, uint32_t Size);
163
164 static ResourceInfo Sampler(Value *Symbol, StringRef Name,
166
167 void bind(uint32_t UniqueID, uint32_t Space, uint32_t LowerBound,
168 uint32_t Size) {
169 Binding.UniqueID = UniqueID;
170 Binding.Space = Space;
171 Binding.LowerBound = LowerBound;
172 Binding.Size = Size;
173 }
174
175 bool operator==(const ResourceInfo &RHS) const;
176
177 MDTuple *getAsMetadata(LLVMContext &Ctx) const;
178
179 ResourceBinding getBinding() const { return Binding; }
180 std::pair<uint32_t, uint32_t> getAnnotateProps() const;
181};
182
183} // namespace dxil
184} // namespace llvm
185
186#endif // LLVM_ANALYSIS_DXILRESOURCE_H
uint64_t Size
Value * RHS
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Tuple of metadata.
Definition: Metadata.h:1472
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
The instances of the Type class are immutable: once they are created, they are never changed.
Definition: Type.h:45
LLVM Value Representation.
Definition: Value.h:74
void bind(uint32_t UniqueID, uint32_t Space, uint32_t LowerBound, uint32_t Size)
Definition: DXILResource.h:167
static ResourceInfo RWTexture2DMS(Value *Symbol, StringRef Name, dxil::ElementType ElementTy, uint32_t ElementCount, uint32_t SampleCount, bool GloballyCoherent)
static ResourceInfo RWStructuredBuffer(Value *Symbol, StringRef Name, uint32_t Stride, Align Alignment, bool GloballyCoherent, bool IsROV, bool HasCounter)
std::pair< uint32_t, uint32_t > getAnnotateProps() const
static ResourceInfo RWRawBuffer(Value *Symbol, StringRef Name, bool GloballyCoherent, bool IsROV)
dxil::SamplerType SamplerTy
Definition: DXILResource.h:97
static ResourceInfo RWTexture2DMSArray(Value *Symbol, StringRef Name, dxil::ElementType ElementTy, uint32_t ElementCount, uint32_t SampleCount, bool GloballyCoherent)
MDTuple * getAsMetadata(LLVMContext &Ctx) const
ResourceBinding getBinding() const
Definition: DXILResource.h:179
ResourceKind
The kind of resource for an SRV or UAV resource.
Definition: DXILABI.h:51
ResourceClass
Definition: DXILABI.h:42
SamplerFeedbackType
Definition: DXILABI.h:111
ElementType
The element type of an SRV or UAV resource.
Definition: DXILABI.h:75
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
bool operator!=(uint64_t V1, const APInt &V2)
Definition: APInt.h:2062
bool operator==(const AddressRangeValuePair &LHS, const AddressRangeValuePair &RHS)
This struct is a compact representation of a valid (non-zero power of two) alignment.
Definition: Alignment.h:39