LLVM 22.0.0git
DXContainerRootSignature.cpp
Go to the documentation of this file.
1//===- llvm/MC/DXContainerRootSignature.cpp - RootSignature -*- 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
12
13using namespace llvm;
14using namespace llvm::mcdxbc;
15
17 const uint32_t DummyValue = std::numeric_limits<uint32_t>::max();
18 uint32_t Offset = Stream.tell();
20 return Offset;
21}
22
25 uint32_t ByteOffset = Stream.tell();
27 support::endian::byte_swap<uint32_t, llvm::endianness::little>(
28 ByteOffset);
29 Stream.pwrite(reinterpret_cast<const char *>(&Value), sizeof(Value), Offset);
30 return ByteOffset;
31}
32
35 size_t StaticSamplersSize =
37
38 return size_t(StaticSamplersOffset) + StaticSamplersSize;
39}
40
43}
44
47
50 switch (I.Type) {
51 case dxbc::RootParameterType::Constants32Bit:
53 break;
54 case dxbc::RootParameterType::CBV:
55 case dxbc::RootParameterType::SRV:
56 case dxbc::RootParameterType::UAV:
57 if (Version == 1)
59 else
61
62 break;
63 case dxbc::RootParameterType::DescriptorTable:
64 const DescriptorTable &Table =
66
67 // 4 bytes for the number of ranges in table and
68 // 4 bytes for the ranges offset
69 Offset += 2 * sizeof(uint32_t);
70 if (Version == 1)
71 Offset += sizeof(dxbc::RTS0::v1::DescriptorRange) * Table.Ranges.size();
72 else
73 Offset += sizeof(dxbc::RTS0::v2::DescriptorRange) * Table.Ranges.size();
74 break;
75 }
76 }
77
78 return Offset;
79}
80
82 SmallString<256> Storage;
83 raw_svector_ostream BOS(Storage);
85
86 const uint32_t NumParameters = ParametersContainer.size();
87 const uint32_t NumSamplers = StaticSamplers.size();
92 uint32_t SSO = writePlaceholder(BOS);
94
95 SmallVector<uint32_t> ParamsOffsets;
99
100 ParamsOffsets.push_back(writePlaceholder(BOS));
101 }
102
103 assert(NumParameters == ParamsOffsets.size());
104 for (size_t I = 0; I < NumParameters; ++I) {
105 rewriteOffsetToCurrentByte(BOS, ParamsOffsets[I]);
107 switch (Info.Type) {
108 case dxbc::RootParameterType::Constants32Bit: {
109 const mcdxbc::RootConstants &Constants =
111 support::endian::write(BOS, Constants.ShaderRegister,
113 support::endian::write(BOS, Constants.RegisterSpace,
115 support::endian::write(BOS, Constants.Num32BitValues,
117 break;
118 }
119 case dxbc::RootParameterType::CBV:
120 case dxbc::RootParameterType::SRV:
121 case dxbc::RootParameterType::UAV: {
122 const mcdxbc::RootDescriptor &Descriptor =
124
129 if (Version > 1)
131 break;
132 }
133 case dxbc::RootParameterType::DescriptorTable: {
134 const DescriptorTable &Table =
136 support::endian::write(BOS, (uint32_t)Table.Ranges.size(),
139 for (const auto &Range : Table) {
141 support::endian::write(BOS, Range.NumDescriptors,
143 support::endian::write(BOS, Range.BaseShaderRegister,
145 support::endian::write(BOS, Range.RegisterSpace,
147 if (Version > 1)
149 support::endian::write(BOS, Range.OffsetInDescriptorsFromTableStart,
151 }
152 break;
153 }
154 }
155 }
156 [[maybe_unused]] uint32_t Offset = rewriteOffsetToCurrentByte(BOS, SSO);
158 "Computed offset does not match written offset");
159 for (const auto &S : StaticSamplers) {
166 support::endian::write(BOS, S.ComparisonFunc, llvm::endianness::little);
170 support::endian::write(BOS, S.ShaderRegister, llvm::endianness::little);
172 support::endian::write(BOS, S.ShaderVisibility, llvm::endianness::little);
173 }
174 assert(Storage.size() == getSize());
175 OS.write(Storage.data(), Storage.size());
176}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
Analysis containing CSE Info
Definition: CSEInfo.cpp:27
static uint32_t rewriteOffsetToCurrentByte(raw_svector_ostream &Stream, uint32_t Offset)
static uint32_t writePlaceholder(raw_svector_ostream &Stream)
#define I(x, y, z)
Definition: MD5.cpp:58
ConstantRange Range(APInt(BitWidth, Low), APInt(BitWidth, High))
raw_pwrite_stream & OS
This file defines the SmallString class.
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
Definition: SmallString.h:26
size_t size() const
Definition: SmallVector.h:79
void push_back(const T &Elt)
Definition: SmallVector.h:414
pointer data()
Return a pointer to the vector's buffer, even if empty().
Definition: SmallVector.h:287
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
LLVM Value Representation.
Definition: Value.h:75
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:53
uint64_t tell() const
tell - Return the current offset with the file.
Definition: raw_ostream.h:148
raw_ostream & write(unsigned char C)
void pwrite(const char *Ptr, size_t Size, uint64_t Offset)
Definition: raw_ostream.h:443
A raw_ostream that writes to an SmallVector or SmallString.
Definition: raw_ostream.h:692
void reserveExtraSpace(uint64_t ExtraSize) override
If possible, pre-allocate ExtraSize bytes for stream data.
Definition: raw_ostream.h:724
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
Definition: Endian.h:92
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
@ Offset
Definition: DWP.cpp:477
SmallVector< dxbc::RTS0::v2::DescriptorRange > Ranges
const RootDescriptor & getRootDescriptor(size_t Index) const
const DescriptorTable & getDescriptorTable(size_t Index) const
const RootConstants & getConstant(size_t Index) const
const RootParameterInfo & getInfo(uint32_t Location) const
LLVM_ABI uint32_t computeRootParametersOffset() const
LLVM_ABI void write(raw_ostream &OS) const
LLVM_ABI uint32_t computeStaticSamplersOffset() const
SmallVector< dxbc::RTS0::v1::StaticSampler > StaticSamplers
mcdxbc::RootParametersContainer ParametersContainer