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();
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
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 =
65 ParametersContainer.getDescriptorTable(I.Location);
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]);
106 const RootParameterInfo &Info = ParametersContainer.getInfo(I);
107 switch (Info.Type) {
108 case dxbc::RootParameterType::Constants32Bit: {
109 const mcdxbc::RootConstants &Constants =
110 ParametersContainer.getConstant(Info.Location);
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 =
123 ParametersContainer.getRootDescriptor(Info.Location);
124
129 if (Version > 1)
131 break;
132 }
133 case dxbc::RootParameterType::DescriptorTable: {
134 const DescriptorTable &Table =
135 ParametersContainer.getDescriptorTable(Info.Location);
136 support::endian::write(BOS, (uint32_t)Table.Ranges.size(),
139 for (const auto &Range : Table) {
140 support::endian::write(BOS, static_cast<uint32_t>(Range.RangeType),
142 support::endian::write(BOS, Range.NumDescriptors,
144 support::endian::write(BOS, Range.BaseShaderRegister,
146 support::endian::write(BOS, Range.RegisterSpace,
148 if (Version > 1)
150 support::endian::write(BOS, Range.OffsetInDescriptorsFromTableStart,
152 }
153 break;
154 }
155 }
156 }
157 [[maybe_unused]] uint32_t Offset = rewriteOffsetToCurrentByte(BOS, SSO);
159 "Computed offset does not match written offset");
160 for (const auto &S : StaticSamplers) {
167 support::endian::write(BOS, S.ComparisonFunc, llvm::endianness::little);
171 support::endian::write(BOS, S.ShaderRegister, llvm::endianness::little);
173 support::endian::write(BOS, S.ShaderVisibility, llvm::endianness::little);
174 }
175 assert(Storage.size() == getSize());
176 OS.write(Storage.data(), Storage.size());
177}
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:92
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