Path: blob/main/contrib/llvm-project/llvm/lib/Target/DirectX/DXILResource.h
35294 views
//===- DXILResource.h - DXIL Resource helper objects ----------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file This file contains helper objects for working with DXIL Resources.9///10//===----------------------------------------------------------------------===//1112#ifndef LLVM_TARGET_DIRECTX_DXILRESOURCE_H13#define LLVM_TARGET_DIRECTX_DXILRESOURCE_H1415#include "llvm/ADT/SmallVector.h"16#include "llvm/ADT/StringRef.h"17#include "llvm/Frontend/HLSL/HLSLResource.h"18#include "llvm/IR/Metadata.h"19#include "llvm/Support/Compiler.h"20#include "llvm/Support/DXILABI.h"21#include <cstdint>2223namespace llvm {24class Module;25class GlobalVariable;2627namespace dxil {28class CBufferDataLayout;2930class ResourceBase {31protected:32uint32_t ID;33GlobalVariable *GV;34StringRef Name;35uint32_t Space;36uint32_t LowerBound;37uint32_t RangeSize;38ResourceBase(uint32_t I, hlsl::FrontendResource R);3940void write(LLVMContext &Ctx, MutableArrayRef<Metadata *> Entries) const;4142void print(raw_ostream &O, StringRef IDPrefix, StringRef BindingPrefix) const;43static StringRef getKindName(dxil::ResourceKind Kind);44static void printKind(dxil::ResourceKind Kind, unsigned Alignment,45raw_ostream &OS, bool SRV = false,46bool HasCounter = false, uint32_t SampleCount = 0);4748static StringRef getElementTypeName(dxil::ElementType CompType);49static void printElementType(dxil::ResourceKind Kind,50dxil::ElementType CompType, unsigned Alignment,51raw_ostream &OS);5253public:54struct ExtendedProperties {55std::optional<dxil::ElementType> ElementType;5657// The value ordering of this enumeration is part of the DXIL ABI. Elements58// can only be added to the end, and not removed.59enum Tags : uint32_t {60TypedBufferElementType = 0,61StructuredBufferElementStride,62SamplerFeedbackKind,63Atomic64Use64};6566MDNode *write(LLVMContext &Ctx) const;67};68};6970class UAVResource : public ResourceBase {71dxil::ResourceKind Shape;72bool GloballyCoherent;73bool HasCounter;74bool IsROV;75ResourceBase::ExtendedProperties ExtProps;7677void parseSourceType(StringRef S);7879public:80UAVResource(uint32_t I, hlsl::FrontendResource R)81: ResourceBase(I, R), Shape(R.getResourceKind()), GloballyCoherent(false),82HasCounter(false), IsROV(R.getIsROV()), ExtProps{R.getElementType()} {}8384MDNode *write() const;85void print(raw_ostream &O) const;86};8788class ConstantBuffer : public ResourceBase {89uint32_t CBufferSizeInBytes = 0; // Cbuffer used size in bytes.90public:91ConstantBuffer(uint32_t I, hlsl::FrontendResource R);92void setSize(CBufferDataLayout &DL);93MDNode *write() const;94void print(raw_ostream &O) const;95};9697template <typename T> class ResourceTable {98StringRef MDName;99100llvm::SmallVector<T> Data;101102public:103ResourceTable(StringRef Name) : MDName(Name) {}104void collect(Module &M);105MDNode *write(Module &M) const;106void print(raw_ostream &O) const;107};108109// FIXME: Fully computing the resource structures requires analyzing the IR110// because some flags are set based on what operations are performed on the111// resource. This partial patch handles some of the leg work, but not all of it.112// See issue https://github.com/llvm/llvm-project/issues/57936.113class Resources {114ResourceTable<UAVResource> UAVs = {"hlsl.uavs"};115ResourceTable<ConstantBuffer> CBuffers = {"hlsl.cbufs"};116117public:118void collect(Module &M);119void write(Module &M) const;120void print(raw_ostream &O) const;121LLVM_DUMP_METHOD void dump() const;122};123124} // namespace dxil125} // namespace llvm126127#endif // LLVM_TARGET_DIRECTX_DXILRESOURCE_H128129130