LLVM 23.0.0git
DXContainer.cpp
Go to the documentation of this file.
1
2//===-- llvm/BinaryFormat/DXContainer.cpp - DXContainer Utils ----*- C++-*-===//
3//
4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
5// See https://llvm.org/LICENSE.txt for license information.
6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7//
8//===----------------------------------------------------------------------===//
9//
10// This file contains utility functions for working with DXContainers.
11//
12//===----------------------------------------------------------------------===//
13
17
18using namespace llvm;
19using namespace llvm::dxbc;
20
21#define ROOT_PARAMETER(Val, Enum) \
22 case Val: \
23 return true;
25 switch (V) {
26#include "llvm/BinaryFormat/DXContainerConstants.def"
27 }
28 return false;
29}
30
34
35#define SHADER_VISIBILITY(Val, Enum) \
36 case Val: \
37 return true;
39 switch (V) {
40#include "llvm/BinaryFormat/DXContainerConstants.def"
41 }
42 return false;
43}
44
45#define FILTER(Val, Enum) \
46 case Val: \
47 return true;
49 switch (V) {
50#include "llvm/BinaryFormat/DXContainerConstants.def"
51 }
52 return false;
53}
54
55#define TEXTURE_ADDRESS_MODE(Val, Enum) \
56 case Val: \
57 return true;
59 switch (V) {
60#include "llvm/BinaryFormat/DXContainerConstants.def"
61 }
62 return false;
63}
64
65#define COMPARISON_FUNC(Val, Enum) \
66 case Val: \
67 return true;
69 switch (V) {
70#include "llvm/BinaryFormat/DXContainerConstants.def"
71 }
72 return false;
73}
74
75#define STATIC_BORDER_COLOR(Val, Enum) \
76 case Val: \
77 return true;
79 switch (V) {
80#include "llvm/BinaryFormat/DXContainerConstants.def"
81 }
82 return false;
83}
84
85template <typename FlagT>
86static bool isValidFlags(std::underlying_type_t<FlagT> V) {
87 decltype(V) LargestValue =
88 llvm::to_underlying(FlagT::LLVM_BITMASK_LARGEST_ENUMERATOR);
89 return V < NextPowerOf2(LargestValue);
90}
91
95
99
103
107
108template <typename EnumT>
109static bool isValidEnumValue(std::underlying_type_t<EnumT> V) {
110 decltype(V) LargestValue =
111 llvm::to_underlying(EnumT::LLVM_BITMASK_LARGEST_ENUMERATOR);
112 return V <= LargestValue;
113}
114
118
122
124#define CONTAINER_PART(PartName) .Case(#PartName, PartType::PartName)
126#include "llvm/BinaryFormat/DXContainerConstants.def"
128}
129
130bool dxbc::isDebugProgramPart(PartType PT) { return PT == PartType::ILDB; }
131
132const char *dxbc::getProgramPartName(bool IsDebug) {
133 return IsDebug ? "ILDB" : "DXIL";
134}
135
137 return PartName == "DXIL" || PartName == "ILDB";
138}
139
141 static uint8_t Zeros[16] = {0};
142 return Flags > 0 || 0 != memcmp(&Digest, &Zeros, 16);
143}
144
145#define COMPONENT_PRECISION(Val, Enum) {#Enum, SigMinPrecision::Enum},
146
148#include "llvm/BinaryFormat/DXContainerConstants.def"
149};
150
154
155#define D3D_SYSTEM_VALUE(Val, Enum) {#Enum, D3DSystemValue::Enum},
156
158#include "llvm/BinaryFormat/DXContainerConstants.def"
159};
160
164
165#define COMPONENT_TYPE(Val, Enum) {#Enum, SigComponentType::Enum},
166
168#include "llvm/BinaryFormat/DXContainerConstants.def"
169};
170
174
176#define ROOT_SIGNATURE_FLAG(Val, Enum) {#Enum, RootFlags::Enum},
177#include "llvm/BinaryFormat/DXContainerConstants.def"
178};
179
183
185#define ROOT_DESCRIPTOR_FLAG(Val, Enum, Flag) \
186 {#Enum, RootDescriptorFlags::Enum},
187#include "llvm/BinaryFormat/DXContainerConstants.def"
188};
189
193
195#define DESCRIPTOR_RANGE_FLAG(Val, Enum, Flag) \
196 {#Enum, DescriptorRangeFlags::Enum},
197#include "llvm/BinaryFormat/DXContainerConstants.def"
198};
199
203
205#define STATIC_SAMPLER_FLAG(Val, Enum, Flag) {#Enum, StaticSamplerFlags::Enum},
206#include "llvm/BinaryFormat/DXContainerConstants.def"
207};
208
212
213#define SHADER_VISIBILITY(Val, Enum) {#Enum, ShaderVisibility::Enum},
214
216#include "llvm/BinaryFormat/DXContainerConstants.def"
217};
218
222
223#define FILTER(Val, Enum) {#Enum, SamplerFilter::Enum},
224
226#include "llvm/BinaryFormat/DXContainerConstants.def"
227};
228
232
233#define TEXTURE_ADDRESS_MODE(Val, Enum) {#Enum, TextureAddressMode::Enum},
234
236#include "llvm/BinaryFormat/DXContainerConstants.def"
237};
238
242
243#define COMPARISON_FUNC(Val, Enum) {#Enum, ComparisonFunc::Enum},
244
246#include "llvm/BinaryFormat/DXContainerConstants.def"
247};
248
252
253#define STATIC_BORDER_COLOR(Val, Enum) {#Enum, StaticBorderColor::Enum},
254
256#include "llvm/BinaryFormat/DXContainerConstants.def"
257};
258
262
263#define ROOT_PARAMETER(Val, Enum) {#Enum, RootParameterType::Enum},
264
266#include "llvm/BinaryFormat/DXContainerConstants.def"
267};
268
272
273#define SEMANTIC_KIND(Val, Enum) {#Enum, PSV::SemanticKind::Enum},
274
276#include "llvm/BinaryFormat/DXContainerConstants.def"
277};
278
282
283#define COMPONENT_TYPE(Val, Enum) {#Enum, PSV::ComponentType::Enum},
284
286#include "llvm/BinaryFormat/DXContainerConstants.def"
287};
288
292
293#define INTERPOLATION_MODE(Val, Enum) {#Enum, PSV::InterpolationMode::Enum},
294
296#include "llvm/BinaryFormat/DXContainerConstants.def"
297};
298
302
303#define RESOURCE_TYPE(Val, Enum) {#Enum, PSV::ResourceType::Enum},
304
306#include "llvm/BinaryFormat/DXContainerConstants.def"
307};
308
312
313#define RESOURCE_KIND(Val, Enum) {#Enum, PSV::ResourceKind::Enum},
314
316#include "llvm/BinaryFormat/DXContainerConstants.def"
317};
318
322
324#define SOURCE_INFO_TYPE(Num, Val) {#Val, SourceInfo::SectionType::Val},
325#include "llvm/BinaryFormat/DXContainerConstants.def"
326};
327
331
338
341#define COMPRESSION_TYPE(Num, Val) \
342 {#Val, SourceInfo::Contents::CompressionType::Val},
343#include "llvm/BinaryFormat/DXContainerConstants.def"
344};
345
static const EnumEntry< DescriptorRangeFlags > DescriptorRangeFlagNames[]
static const EnumEntry< ShaderVisibility > ShaderVisibilityValues[]
static const EnumEntry< SourceInfo::Contents::CompressionType > CompressionTypes[]
static const EnumEntry< D3DSystemValue > D3DSystemValueNames[]
static bool isValidEnumValue(std::underlying_type_t< EnumT > V)
static const EnumEntry< PSV::InterpolationMode > InterpolationModeNames[]
static const EnumEntry< SigMinPrecision > SigMinPrecisionNames[]
static const EnumEntry< StaticSamplerFlags > StaticSamplerFlagNames[]
static const EnumEntry< SamplerFilter > SamplerFilterNames[]
static const EnumEntry< RootParameterType > RootParameterTypes[]
static const EnumEntry< PSV::SemanticKind > SemanticKindNames[]
static bool isValidFlags(std::underlying_type_t< FlagT > V)
static const EnumEntry< PSV::ResourceType > ResourceTypeNames[]
static const EnumEntry< StaticBorderColor > StaticBorderColorValues[]
static const EnumEntry< RootFlags > RootFlagNames[]
static const EnumEntry< ComparisonFunc > ComparisonFuncNames[]
static const EnumEntry< PSV::ResourceKind > ResourceKindNames[]
static const EnumEntry< RootDescriptorFlags > RootDescriptorFlagNames[]
static const EnumEntry< TextureAddressMode > TextureAddressModeNames[]
static const EnumEntry< SigComponentType > SigComponentTypes[]
static const EnumEntry< PSV::ComponentType > ComponentTypeNames[]
This file implements the StringSwitch template, which mimics a switch() statement whose cases are str...
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
A switch()-like statement whose cases are string literals.
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
static constexpr StringLiteral SectionNames[SectionKindsNum]
LLVM_ABI ArrayRef< EnumEntry< ResourceKind > > getResourceKinds()
LLVM_ABI ArrayRef< EnumEntry< ComponentType > > getComponentTypes()
LLVM_ABI ArrayRef< EnumEntry< ResourceType > > getResourceTypes()
LLVM_ABI ArrayRef< EnumEntry< SemanticKind > > getSemanticKinds()
LLVM_ABI ArrayRef< EnumEntry< InterpolationMode > > getInterpolationModes()
LLVM_ABI ArrayRef< EnumEntry< CompressionType > > getCompressionTypes()
bool isValidCompressionType(uint16_t V)
LLVM_ABI bool isValidSectionType(uint16_t V)
LLVM_ABI ArrayRef< EnumEntry< SectionType > > getSectionTypes()
LLVM_ABI StringRef getSectionName(SectionType Type)
LLVM_ABI ArrayRef< EnumEntry< ComparisonFunc > > getComparisonFuncs()
LLVM_ABI ArrayRef< EnumEntry< ShaderVisibility > > getShaderVisibility()
bool isValidShaderVisibility(uint32_t V)
LLVM_ABI PartType parsePartType(StringRef S)
bool isValidSamplerFilter(uint32_t V)
bool isValidStaticSamplerFlags(uint32_t V)
LLVM_ABI ArrayRef< EnumEntry< RootFlags > > getRootFlags()
LLVM_ABI ArrayRef< EnumEntry< RootParameterType > > getRootParameterTypes()
bool isValidRootDesciptorFlags(uint32_t V)
LLVM_ABI ArrayRef< EnumEntry< SigComponentType > > getSigComponentTypes()
bool isDebugProgramPart(PartType PT)
LLVM_ABI ArrayRef< EnumEntry< SigMinPrecision > > getSigMinPrecisions()
bool isProgramPart(StringRef PartName)
LLVM_ABI ArrayRef< EnumEntry< DescriptorRangeFlags > > getDescriptorRangeFlags()
bool isValidCompilerVersionFlags(uint32_t V)
LLVM_ABI ArrayRef< EnumEntry< SamplerFilter > > getSamplerFilters()
LLVM_ABI ArrayRef< EnumEntry< D3DSystemValue > > getD3DSystemValues()
bool isValidDescriptorRangeFlags(uint32_t V)
bool isValidBorderColor(uint32_t V)
bool isValidComparisonFunc(uint32_t V)
LLVM_ABI_FOR_TEST bool isValidParameterType(uint32_t V)
const char * getProgramPartName(bool IsDebug)
LLVM_ABI ArrayRef< EnumEntry< StaticBorderColor > > getStaticBorderColors()
bool isValidAddress(uint32_t V)
LLVM_ABI ArrayRef< EnumEntry< TextureAddressMode > > getTextureAddressModes()
bool isValidRangeType(uint32_t V)
LLVM_ABI ArrayRef< EnumEntry< StaticSamplerFlags > > getStaticSamplerFlags()
LLVM_ABI ArrayRef< EnumEntry< RootDescriptorFlags > > getRootDescriptorFlags()
This is an optimization pass for GlobalISel generic memory operations.
constexpr std::underlying_type_t< Enum > to_underlying(Enum E)
Returns underlying integer value of an enum.
ArrayRef(const T &OneElt) -> ArrayRef< T >
constexpr uint64_t NextPowerOf2(uint64_t A)
Returns the next power of two (in 64-bits) that is strictly greater than A.
Definition MathExtras.h:373
LLVM_ABI bool isPopulated()