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 ByteOffset, llvm::endianness::little);
28 Stream.pwrite(reinterpret_cast<const char *>(&Value), sizeof(Value), Offset);
29 return ByteOffset;
30}
31
34 size_t StaticSamplersSize = sizeof(dxbc::RTS0::v1::StaticSampler);
35 if (Version > 2)
36 StaticSamplersSize = sizeof(dxbc::RTS0::v3::StaticSampler);
37
38 return size_t(StaticSamplersOffset) +
39 (StaticSamplersSize * StaticSamplers.size());
40}
41
45
48
51 switch (I.Type) {
52 case dxbc::RootParameterType::Constants32Bit:
54 break;
55 case dxbc::RootParameterType::CBV:
56 case dxbc::RootParameterType::SRV:
57 case dxbc::RootParameterType::UAV:
58 if (Version == 1)
60 else
62
63 break;
64 case dxbc::RootParameterType::DescriptorTable:
65 const DescriptorTable &Table =
66 ParametersContainer.getDescriptorTable(I.Location);
67
68 // 4 bytes for the number of ranges in table and
69 // 4 bytes for the ranges offset
70 Offset += 2 * sizeof(uint32_t);
71 if (Version == 1)
72 Offset += sizeof(dxbc::RTS0::v1::DescriptorRange) * Table.Ranges.size();
73 else
74 Offset += sizeof(dxbc::RTS0::v2::DescriptorRange) * Table.Ranges.size();
75 break;
76 }
77 }
78
79 return Offset;
80}
81
83 SmallString<256> Storage;
84 raw_svector_ostream BOS(Storage);
86
87 const uint32_t NumParameters = ParametersContainer.size();
88 const uint32_t NumSamplers = StaticSamplers.size();
93 uint32_t SSO = writePlaceholder(BOS);
95
96 SmallVector<uint32_t> ParamsOffsets;
100
101 ParamsOffsets.push_back(writePlaceholder(BOS));
102 }
103
104 assert(NumParameters == ParamsOffsets.size());
105 for (size_t I = 0; I < NumParameters; ++I) {
106 rewriteOffsetToCurrentByte(BOS, ParamsOffsets[I]);
107 const RootParameterInfo &Info = ParametersContainer.getInfo(I);
108 switch (Info.Type) {
109 case dxbc::RootParameterType::Constants32Bit: {
110 const mcdxbc::RootConstants &Constants =
111 ParametersContainer.getConstant(Info.Location);
112 support::endian::write(BOS, Constants.ShaderRegister,
114 support::endian::write(BOS, Constants.RegisterSpace,
116 support::endian::write(BOS, Constants.Num32BitValues,
118 break;
119 }
120 case dxbc::RootParameterType::CBV:
121 case dxbc::RootParameterType::SRV:
122 case dxbc::RootParameterType::UAV: {
123 const mcdxbc::RootDescriptor &Descriptor =
124 ParametersContainer.getRootDescriptor(Info.Location);
125
130 if (Version > 1)
132 break;
133 }
134 case dxbc::RootParameterType::DescriptorTable: {
135 const DescriptorTable &Table =
136 ParametersContainer.getDescriptorTable(Info.Location);
137 support::endian::write(BOS, (uint32_t)Table.Ranges.size(),
140 for (const auto &Range : Table) {
141 support::endian::write(BOS, static_cast<uint32_t>(Range.RangeType),
143 support::endian::write(BOS, Range.NumDescriptors,
145 support::endian::write(BOS, Range.BaseShaderRegister,
147 support::endian::write(BOS, Range.RegisterSpace,
149 if (Version > 1)
151 support::endian::write(BOS, Range.OffsetInDescriptorsFromTableStart,
153 }
154 break;
155 }
156 }
157 }
158 [[maybe_unused]] uint32_t Offset = rewriteOffsetToCurrentByte(BOS, SSO);
160 "Computed offset does not match written offset");
161 for (const auto &S : StaticSamplers) {
168 support::endian::write(BOS, S.ComparisonFunc, llvm::endianness::little);
172 support::endian::write(BOS, S.ShaderRegister, llvm::endianness::little);
174 support::endian::write(BOS, S.ShaderVisibility, llvm::endianness::little);
175
176 if (Version > 2)
178 }
179 assert(Storage.size() == getSize());
180 OS.write(Storage.data(), Storage.size());
181}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
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))
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
void push_back(const T &Elt)
pointer data()
Return a pointer to the vector's buffer, even if empty().
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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.
raw_ostream & write(unsigned char C)
void pwrite(const char *Ptr, size_t Size, uint64_t Offset)
A raw_ostream that writes to an SmallVector or SmallString.
void reserveExtraSpace(uint64_t ExtraSize) override
If possible, pre-allocate ExtraSize bytes for stream data.
value_type byte_swap(value_type value, endianness endian)
Definition Endian.h:44
void write(void *memory, value_type value, endianness endian)
Write a value to memory with a particular endianness.
Definition Endian.h:96
This is an optimization pass for GlobalISel generic memory operations.
@ Offset
Definition DWP.cpp:477
SmallVector< DescriptorRange > Ranges
LLVM_ABI uint32_t computeRootParametersOffset() const
LLVM_ABI void write(raw_ostream &OS) const
SmallVector< StaticSampler > StaticSamplers
LLVM_ABI uint32_t computeStaticSamplersOffset() const
mcdxbc::RootParametersContainer ParametersContainer