LLVM 19.0.0git
DXILResource.h
Go to the documentation of this file.
1//===- DXILResource.h - Tools to translate 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_TRANSFORMS_UTILS_DXILRESOURCE_H
10#define LLVM_TRANSFORMS_UTILS_DXILRESOURCE_H
11
12#include "llvm/IR/Metadata.h"
13#include "llvm/IR/Value.h"
15
16namespace llvm {
17namespace dxil {
18
23
24 bool operator==(const ResourceBinding &RHS) const {
25 return std::tie(Space, LowerBound, Size) ==
26 std::tie(RHS.Space, RHS.LowerBound, RHS.Size);
27 }
28 bool operator!=(const ResourceBinding &RHS) const { return !(*this == RHS); }
29};
30
32 struct UAVInfo {
33 bool GloballyCoherent;
34 bool HasCounter;
35 bool IsROV;
36
37 bool operator==(const UAVInfo &RHS) const {
38 return std::tie(GloballyCoherent, HasCounter, IsROV) ==
39 std::tie(RHS.GloballyCoherent, RHS.HasCounter, RHS.IsROV);
40 }
41 bool operator!=(const UAVInfo &RHS) const { return !(*this == RHS); }
42 };
43
44 struct StructInfo {
45 uint32_t Stride;
46 Align Alignment;
47
48 bool operator==(const StructInfo &RHS) const {
49 return std::tie(Stride, Alignment) == std::tie(RHS.Stride, RHS.Alignment);
50 }
51 bool operator!=(const StructInfo &RHS) const { return !(*this == RHS); }
52 };
53
54 struct TypedInfo {
55 dxil::ElementType ElementTy;
57
58 bool operator==(const TypedInfo &RHS) const {
59 return std::tie(ElementTy, ElementCount) ==
60 std::tie(RHS.ElementTy, RHS.ElementCount);
61 }
62 bool operator!=(const TypedInfo &RHS) const { return !(*this == RHS); }
63 };
64
65 struct MSInfo {
66 uint32_t Count;
67
68 bool operator==(const MSInfo &RHS) const { return Count == RHS.Count; }
69 bool operator!=(const MSInfo &RHS) const { return !(*this == RHS); }
70 };
71
72 struct FeedbackInfo {
74
75 bool operator==(const FeedbackInfo &RHS) const { return Type == RHS.Type; }
76 bool operator!=(const FeedbackInfo &RHS) const { return !(*this == RHS); }
77 };
78
79 // Universal properties.
80 Value *Symbol;
81 StringRef Name;
82
83 ResourceBinding Binding;
84 uint32_t UniqueID;
85
88
89 // Resource class dependent properties.
90 // CBuffer, Sampler, and RawBuffer end here.
91 union {
92 UAVInfo UAVFlags; // UAV
95 };
96
97 // Resource kind dependent properties.
98 union {
99 StructInfo Struct; // StructuredBuffer
100 TypedInfo Typed; // All SRV/UAV except Raw/StructuredBuffer
101 FeedbackInfo Feedback; // FeedbackTexture
102 };
103
104 MSInfo MultiSample;
105
106 // Conditions to check before accessing union members.
107 bool isUAV() const;
108 bool isCBuffer() const;
109 bool isSampler() const;
110 bool isStruct() const;
111 bool isTyped() const;
112 bool isFeedback() const;
113 bool isMultiSample() const;
114
116 StringRef Name, ResourceBinding Binding, uint32_t UniqueID)
117 : Symbol(Symbol), Name(Name), Binding(Binding), UniqueID(UniqueID),
118 RC(RC), Kind(Kind) {}
119
120public:
121 static ResourceInfo SRV(Value *Symbol, StringRef Name,
122 ResourceBinding Binding, uint32_t UniqueID,
124 dxil::ResourceKind Kind);
125 static ResourceInfo RawBuffer(Value *Symbol, StringRef Name,
126 ResourceBinding Binding, uint32_t UniqueID);
127 static ResourceInfo StructuredBuffer(Value *Symbol, StringRef Name,
128 ResourceBinding Binding,
129 uint32_t UniqueID, uint32_t Stride,
130 Align Alignment);
131 static ResourceInfo Texture2DMS(Value *Symbol, StringRef Name,
132 ResourceBinding Binding, uint32_t UniqueID,
133 dxil::ElementType ElementTy,
134 uint32_t ElementCount, uint32_t SampleCount);
135 static ResourceInfo
136 Texture2DMSArray(Value *Symbol, StringRef Name, ResourceBinding Binding,
137 uint32_t UniqueID, dxil::ElementType ElementTy,
138 uint32_t ElementCount, uint32_t SampleCount);
139
140 static ResourceInfo UAV(Value *Symbol, StringRef Name,
141 ResourceBinding Binding, uint32_t UniqueID,
143 bool GloballyCoherent, bool IsROV,
144 dxil::ResourceKind Kind);
145 static ResourceInfo RWRawBuffer(Value *Symbol, StringRef Name,
146 ResourceBinding Binding, uint32_t UniqueID,
147 bool GloballyCoherent, bool IsROV);
148 static ResourceInfo RWStructuredBuffer(Value *Symbol, StringRef Name,
149 ResourceBinding Binding,
150 uint32_t UniqueID, uint32_t Stride,
151 Align Alignment, bool GloballyCoherent,
152 bool IsROV, bool HasCounter);
153 static ResourceInfo RWTexture2DMS(Value *Symbol, StringRef Name,
154 ResourceBinding Binding, uint32_t UniqueID,
155 dxil::ElementType ElementTy,
156 uint32_t ElementCount, uint32_t SampleCount,
157 bool GloballyCoherent);
158 static ResourceInfo
159 RWTexture2DMSArray(Value *Symbol, StringRef Name, ResourceBinding Binding,
160 uint32_t UniqueID, dxil::ElementType ElementTy,
161 uint32_t ElementCount, uint32_t SampleCount,
162 bool GloballyCoherent);
163 static ResourceInfo FeedbackTexture2D(Value *Symbol, StringRef Name,
164 ResourceBinding Binding,
165 uint32_t UniqueID,
166 dxil::SamplerFeedbackType FeedbackTy);
167 static ResourceInfo
168 FeedbackTexture2DArray(Value *Symbol, StringRef Name, ResourceBinding Binding,
169 uint32_t UniqueID,
170 dxil::SamplerFeedbackType FeedbackTy);
171
172 static ResourceInfo CBuffer(Value *Symbol, StringRef Name,
173 ResourceBinding Binding, uint32_t UniqueID,
174 uint32_t Size);
175
176 static ResourceInfo Sampler(Value *Symbol, StringRef Name,
177 ResourceBinding Binding, uint32_t UniqueID,
179
180 bool operator==(const ResourceInfo &RHS) const;
181
182 MDTuple *getAsMetadata(LLVMContext &Ctx) const;
183
184 ResourceBinding getBinding() const { return Binding; }
185 std::pair<uint32_t, uint32_t> getAnnotateProps() const;
186};
187
188} // namespace dxil
189} // namespace llvm
190
191#endif // LLVM_TRANSFORMS_UTILS_DXILRESOURCE_H
uint64_t Size
This file contains the declarations for metadata subclasses.
Value * RHS
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Tuple of metadata.
Definition: Metadata.h:1470
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
static ResourceInfo RWTexture2DMSArray(Value *Symbol, StringRef Name, ResourceBinding Binding, uint32_t UniqueID, dxil::ElementType ElementTy, uint32_t ElementCount, uint32_t SampleCount, bool GloballyCoherent)
static ResourceInfo RWRawBuffer(Value *Symbol, StringRef Name, ResourceBinding Binding, uint32_t UniqueID, bool GloballyCoherent, bool IsROV)
std::pair< uint32_t, uint32_t > getAnnotateProps() const
dxil::SamplerType SamplerTy
Definition: DXILResource.h:94
static ResourceInfo RWStructuredBuffer(Value *Symbol, StringRef Name, ResourceBinding Binding, uint32_t UniqueID, uint32_t Stride, Align Alignment, bool GloballyCoherent, bool IsROV, bool HasCounter)
static ResourceInfo RWTexture2DMS(Value *Symbol, StringRef Name, ResourceBinding Binding, uint32_t UniqueID, dxil::ElementType ElementTy, uint32_t ElementCount, uint32_t SampleCount, bool GloballyCoherent)
MDTuple * getAsMetadata(LLVMContext &Ctx) const
ResourceBinding getBinding() const
Definition: DXILResource.h:184
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
bool operator==(const ResourceBinding &RHS) const
Definition: DXILResource.h:24
bool operator!=(const ResourceBinding &RHS) const
Definition: DXILResource.h:28