LLVM 20.0.0git
DXILResource.h
Go to the documentation of this file.
1//===- DXILResource.h - DXIL 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 DXIL Resources.
10///
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_TARGET_DIRECTX_DXILRESOURCE_H
14#define LLVM_TARGET_DIRECTX_DXILRESOURCE_H
15
17#include "llvm/ADT/StringRef.h"
19#include "llvm/IR/Metadata.h"
22#include <cstdint>
23
24namespace llvm {
25class Module;
26class GlobalVariable;
27
28namespace dxil {
29class CBufferDataLayout;
30
32protected:
40
41 void write(LLVMContext &Ctx, MutableArrayRef<Metadata *> Entries) const;
42
43 void print(raw_ostream &O, StringRef IDPrefix, StringRef BindingPrefix) const;
45 static void printKind(dxil::ResourceKind Kind, unsigned Alignment,
46 raw_ostream &OS, bool SRV = false,
47 bool HasCounter = false, uint32_t SampleCount = 0);
48
50 static void printElementType(dxil::ResourceKind Kind,
51 dxil::ElementType CompType, unsigned Alignment,
53
54public:
56 std::optional<dxil::ElementType> ElementType;
57
58 // The value ordering of this enumeration is part of the DXIL ABI. Elements
59 // can only be added to the end, and not removed.
60 enum Tags : uint32_t {
65 };
66
67 MDNode *write(LLVMContext &Ctx) const;
68 };
69};
70
71class UAVResource : public ResourceBase {
73 bool GloballyCoherent;
74 bool HasCounter;
75 bool IsROV;
77
78 void parseSourceType(StringRef S);
79
80public:
82 : ResourceBase(I, R), Shape(R.getResourceKind()), GloballyCoherent(false),
83 HasCounter(false), IsROV(R.getIsROV()), ExtProps{R.getElementType()} {}
84
85 MDNode *write() const;
86 void print(raw_ostream &O) const;
87};
88
90 uint32_t CBufferSizeInBytes = 0; // Cbuffer used size in bytes.
91public:
94 MDNode *write() const;
95 void print(raw_ostream &O) const;
96};
97
98template <typename T> class ResourceTable {
99 StringRef MDName;
100
102
103public:
105 void collect(Module &M);
106 MDNode *write(Module &M) const;
107 void print(raw_ostream &O) const;
108};
109
110// FIXME: Fully computing the resource structures requires analyzing the IR
111// because some flags are set based on what operations are performed on the
112// resource. This partial patch handles some of the leg work, but not all of it.
113// See issue https://github.com/llvm/llvm-project/issues/57936.
115 ResourceTable<UAVResource> UAVs = {"hlsl.uavs"};
116 ResourceTable<ConstantBuffer> CBuffers = {"hlsl.cbufs"};
117
118public:
119 void collect(Module &M);
120 void write(Module &M) const;
121 void print(raw_ostream &O) const;
122 LLVM_DUMP_METHOD void dump() const;
123};
124
125} // namespace dxil
126} // namespace llvm
127
128#endif // LLVM_TARGET_DIRECTX_DXILRESOURCE_H
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
#define LLVM_DUMP_METHOD
Mark debug helper function definitions like dump() that should not be stripped from debug builds.
Definition: Compiler.h:537
std::string Name
#define I(x, y, z)
Definition: MD5.cpp:58
Machine Check Debug Module
This file contains the declarations for metadata subclasses.
raw_pwrite_stream & OS
This file defines the SmallVector class.
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:67
Metadata node.
Definition: Metadata.h:1069
A Module instance is used to store all the information related to an LLVM module.
Definition: Module.h:65
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1210
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
void setSize(CBufferDataLayout &DL)
void print(raw_ostream &O) const
static StringRef getElementTypeName(dxil::ElementType CompType)
void print(raw_ostream &O, StringRef IDPrefix, StringRef BindingPrefix) const
GlobalVariable * GV
Definition: DXILResource.h:34
static void printElementType(dxil::ResourceKind Kind, dxil::ElementType CompType, unsigned Alignment, raw_ostream &OS)
static void printKind(dxil::ResourceKind Kind, unsigned Alignment, raw_ostream &OS, bool SRV=false, bool HasCounter=false, uint32_t SampleCount=0)
static StringRef getKindName(dxil::ResourceKind Kind)
void write(LLVMContext &Ctx, MutableArrayRef< Metadata * > Entries) const
void print(raw_ostream &O) const
MDNode * write(Module &M) const
ResourceTable(StringRef Name)
Definition: DXILResource.h:104
LLVM_DUMP_METHOD void dump() const
void print(raw_ostream &O) const
void write(Module &M) const
void collect(Module &M)
MDNode * write() const
UAVResource(uint32_t I, hlsl::FrontendResource R)
Definition: DXILResource.h:81
void print(raw_ostream &O) const
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
ResourceKind
The kind of resource for an SRV or UAV resource.
Definition: DXILABI.h:51
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
MDNode * write(LLVMContext &Ctx) const
std::optional< dxil::ElementType > ElementType
Definition: DXILResource.h:56