| 1 | //===- DXContainer.cpp - DXContainer object file implementation -----------===// |
| 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 | |
| 9 | #include "llvm/Object/DXContainer.h" |
| 10 | #include "llvm/BinaryFormat/DXContainer.h" |
| 11 | #include "llvm/Object/Error.h" |
| 12 | #include "llvm/Support/Alignment.h" |
| 13 | #include "llvm/Support/Endian.h" |
| 14 | #include "llvm/Support/FormatVariadic.h" |
| 15 | |
| 16 | using namespace llvm; |
| 17 | using namespace llvm::object; |
| 18 | |
| 19 | static Error parseFailed(const Twine &Msg) { |
| 20 | return make_error<GenericBinaryError>(Args: Msg.str(), Args: object_error::parse_failed); |
| 21 | } |
| 22 | |
| 23 | template <typename T> |
| 24 | static Error readStruct(StringRef Buffer, const char *Src, T &Struct) { |
| 25 | // Don't read before the beginning or past the end of the file |
| 26 | if (Src < Buffer.begin() || Src + sizeof(T) > Buffer.end()) |
| 27 | return parseFailed(Msg: "Reading structure out of file bounds" ); |
| 28 | |
| 29 | memcpy(&Struct, Src, sizeof(T)); |
| 30 | // DXContainer is always little endian |
| 31 | if (sys::IsBigEndianHost) |
| 32 | Struct.swapBytes(); |
| 33 | return Error::success(); |
| 34 | } |
| 35 | |
| 36 | template <typename T> |
| 37 | static Error readInteger(StringRef Buffer, const char *Src, T &Val, |
| 38 | Twine Str = "structure" ) { |
| 39 | static_assert(std::is_integral_v<T>, |
| 40 | "Cannot call readInteger on non-integral type." ); |
| 41 | // Don't read before the beginning or past the end of the file |
| 42 | if (Src < Buffer.begin() || Src + sizeof(T) > Buffer.end()) |
| 43 | return parseFailed(Msg: Twine("Reading " ) + Str + " out of file bounds" ); |
| 44 | |
| 45 | // The DXContainer offset table is comprised of uint32_t values but not padded |
| 46 | // to a 64-bit boundary. So Parts may start unaligned if there is an odd |
| 47 | // number of parts and part data itself is not required to be padded. |
| 48 | if (reinterpret_cast<uintptr_t>(Src) % alignof(T) != 0) |
| 49 | memcpy(dest: reinterpret_cast<char *>(&Val), src: Src, n: sizeof(T)); |
| 50 | else |
| 51 | Val = *reinterpret_cast<const T *>(Src); |
| 52 | // DXContainer is always little endian |
| 53 | if (sys::IsBigEndianHost) |
| 54 | sys::swapByteOrder(Val); |
| 55 | return Error::success(); |
| 56 | } |
| 57 | |
| 58 | DXContainer::DXContainer(MemoryBufferRef O) : Data(O) {} |
| 59 | |
| 60 | Error DXContainer::() { |
| 61 | return readStruct(Buffer: Data.getBuffer(), Src: Data.getBuffer().data(), Struct&: Header); |
| 62 | } |
| 63 | |
| 64 | Error DXContainer::(StringRef Part) { |
| 65 | if (DXIL) |
| 66 | return parseFailed(Msg: "More than one DXIL part is present in the file" ); |
| 67 | const char *Current = Part.begin(); |
| 68 | dxbc::ProgramHeader ; |
| 69 | if (Error Err = readStruct(Buffer: Part, Src: Current, Struct&: Header)) |
| 70 | return Err; |
| 71 | Current += offsetof(dxbc::ProgramHeader, Bitcode) + Header.Bitcode.Offset; |
| 72 | DXIL.emplace(args: std::make_pair(x&: Header, y&: Current)); |
| 73 | return Error::success(); |
| 74 | } |
| 75 | |
| 76 | Error DXContainer::parseShaderFeatureFlags(StringRef Part) { |
| 77 | if (ShaderFeatureFlags) |
| 78 | return parseFailed(Msg: "More than one SFI0 part is present in the file" ); |
| 79 | uint64_t FlagValue = 0; |
| 80 | if (Error Err = readInteger(Buffer: Part, Src: Part.begin(), Val&: FlagValue)) |
| 81 | return Err; |
| 82 | ShaderFeatureFlags = FlagValue; |
| 83 | return Error::success(); |
| 84 | } |
| 85 | |
| 86 | Error DXContainer::parseHash(StringRef Part) { |
| 87 | if (Hash) |
| 88 | return parseFailed(Msg: "More than one HASH part is present in the file" ); |
| 89 | dxbc::ShaderHash ReadHash; |
| 90 | if (Error Err = readStruct(Buffer: Part, Src: Part.begin(), Struct&: ReadHash)) |
| 91 | return Err; |
| 92 | Hash = ReadHash; |
| 93 | return Error::success(); |
| 94 | } |
| 95 | |
| 96 | Error DXContainer::parseRootSignature(StringRef Part) { |
| 97 | if (RootSignature) |
| 98 | return parseFailed(Msg: "More than one RTS0 part is present in the file" ); |
| 99 | RootSignature = DirectX::RootSignature(Part); |
| 100 | if (Error Err = RootSignature->parse()) |
| 101 | return Err; |
| 102 | return Error::success(); |
| 103 | } |
| 104 | |
| 105 | Error DXContainer::parsePSVInfo(StringRef Part) { |
| 106 | if (PSVInfo) |
| 107 | return parseFailed(Msg: "More than one PSV0 part is present in the file" ); |
| 108 | PSVInfo = DirectX::PSVRuntimeInfo(Part); |
| 109 | // Parsing the PSVRuntime info occurs late because we need to read data from |
| 110 | // other parts first. |
| 111 | return Error::success(); |
| 112 | } |
| 113 | |
| 114 | Error DirectX::Signature::initialize(StringRef Part) { |
| 115 | dxbc::ProgramSignatureHeader ; |
| 116 | if (Error Err = readStruct(Buffer: Part, Src: Part.begin(), Struct&: SigHeader)) |
| 117 | return Err; |
| 118 | size_t Size = sizeof(dxbc::ProgramSignatureElement) * SigHeader.ParamCount; |
| 119 | |
| 120 | if (Part.size() < Size + SigHeader.FirstParamOffset) |
| 121 | return parseFailed(Msg: "Signature parameters extend beyond the part boundary" ); |
| 122 | |
| 123 | Parameters.Data = Part.substr(Start: SigHeader.FirstParamOffset, N: Size); |
| 124 | |
| 125 | StringTableOffset = SigHeader.FirstParamOffset + static_cast<uint32_t>(Size); |
| 126 | StringTable = Part.substr(Start: SigHeader.FirstParamOffset + Size); |
| 127 | |
| 128 | for (const auto &Param : Parameters) { |
| 129 | if (Param.NameOffset < StringTableOffset) |
| 130 | return parseFailed(Msg: "Invalid parameter name offset: name starts before " |
| 131 | "the first name offset" ); |
| 132 | if (Param.NameOffset - StringTableOffset > StringTable.size()) |
| 133 | return parseFailed(Msg: "Invalid parameter name offset: name starts after the " |
| 134 | "end of the part data" ); |
| 135 | } |
| 136 | return Error::success(); |
| 137 | } |
| 138 | |
| 139 | Error DXContainer::parsePartOffsets() { |
| 140 | uint32_t LastOffset = |
| 141 | sizeof(dxbc::Header) + (Header.PartCount * sizeof(uint32_t)); |
| 142 | const char *Current = Data.getBuffer().data() + sizeof(dxbc::Header); |
| 143 | for (uint32_t Part = 0; Part < Header.PartCount; ++Part) { |
| 144 | uint32_t PartOffset; |
| 145 | if (Error Err = readInteger(Buffer: Data.getBuffer(), Src: Current, Val&: PartOffset)) |
| 146 | return Err; |
| 147 | if (PartOffset < LastOffset) |
| 148 | return parseFailed( |
| 149 | Msg: formatv( |
| 150 | Fmt: "Part offset for part {0} begins before the previous part ends" , |
| 151 | Vals&: Part) |
| 152 | .str()); |
| 153 | Current += sizeof(uint32_t); |
| 154 | if (PartOffset >= Data.getBufferSize()) |
| 155 | return parseFailed(Msg: "Part offset points beyond boundary of the file" ); |
| 156 | // To prevent overflow when reading the part name, we subtract the part name |
| 157 | // size from the buffer size, rather than adding to the offset. Since the |
| 158 | // file header is larger than the part header we can't reach this code |
| 159 | // unless the buffer is at least as large as a part header, so this |
| 160 | // subtraction can't underflow. |
| 161 | if (PartOffset >= Data.getBufferSize() - sizeof(dxbc::PartHeader::Name)) |
| 162 | return parseFailed(Msg: "File not large enough to read part name" ); |
| 163 | PartOffsets.push_back(Elt: PartOffset); |
| 164 | |
| 165 | dxbc::PartType PT = |
| 166 | dxbc::parsePartType(S: Data.getBuffer().substr(Start: PartOffset, N: 4)); |
| 167 | uint32_t PartDataStart = PartOffset + sizeof(dxbc::PartHeader); |
| 168 | uint32_t PartSize; |
| 169 | if (Error Err = readInteger(Buffer: Data.getBuffer(), |
| 170 | Src: Data.getBufferStart() + PartOffset + 4, |
| 171 | Val&: PartSize, Str: "part size" )) |
| 172 | return Err; |
| 173 | StringRef PartData = Data.getBuffer().substr(Start: PartDataStart, N: PartSize); |
| 174 | LastOffset = PartOffset + PartSize; |
| 175 | switch (PT) { |
| 176 | case dxbc::PartType::DXIL: |
| 177 | if (Error Err = parseDXILHeader(Part: PartData)) |
| 178 | return Err; |
| 179 | break; |
| 180 | case dxbc::PartType::SFI0: |
| 181 | if (Error Err = parseShaderFeatureFlags(Part: PartData)) |
| 182 | return Err; |
| 183 | break; |
| 184 | case dxbc::PartType::HASH: |
| 185 | if (Error Err = parseHash(Part: PartData)) |
| 186 | return Err; |
| 187 | break; |
| 188 | case dxbc::PartType::PSV0: |
| 189 | if (Error Err = parsePSVInfo(Part: PartData)) |
| 190 | return Err; |
| 191 | break; |
| 192 | case dxbc::PartType::ISG1: |
| 193 | if (Error Err = InputSignature.initialize(Part: PartData)) |
| 194 | return Err; |
| 195 | break; |
| 196 | case dxbc::PartType::OSG1: |
| 197 | if (Error Err = OutputSignature.initialize(Part: PartData)) |
| 198 | return Err; |
| 199 | break; |
| 200 | case dxbc::PartType::PSG1: |
| 201 | if (Error Err = PatchConstantSignature.initialize(Part: PartData)) |
| 202 | return Err; |
| 203 | break; |
| 204 | case dxbc::PartType::Unknown: |
| 205 | break; |
| 206 | case dxbc::PartType::RTS0: |
| 207 | if (Error Err = parseRootSignature(Part: PartData)) |
| 208 | return Err; |
| 209 | break; |
| 210 | } |
| 211 | } |
| 212 | |
| 213 | // Fully parsing the PSVInfo requires knowing the shader kind which we read |
| 214 | // out of the program header in the DXIL part. |
| 215 | if (PSVInfo) { |
| 216 | if (!DXIL) |
| 217 | return parseFailed(Msg: "Cannot fully parse pipeline state validation " |
| 218 | "information without DXIL part." ); |
| 219 | if (Error Err = PSVInfo->parse(ShaderKind: DXIL->first.ShaderKind)) |
| 220 | return Err; |
| 221 | } |
| 222 | return Error::success(); |
| 223 | } |
| 224 | |
| 225 | Expected<DXContainer> DXContainer::create(MemoryBufferRef Object) { |
| 226 | DXContainer Container(Object); |
| 227 | if (Error Err = Container.parseHeader()) |
| 228 | return std::move(Err); |
| 229 | if (Error Err = Container.parsePartOffsets()) |
| 230 | return std::move(Err); |
| 231 | return Container; |
| 232 | } |
| 233 | |
| 234 | void DXContainer::PartIterator::updateIteratorImpl(const uint32_t Offset) { |
| 235 | StringRef Buffer = Container.Data.getBuffer(); |
| 236 | const char *Current = Buffer.data() + Offset; |
| 237 | // Offsets are validated during parsing, so all offsets in the container are |
| 238 | // valid and contain enough readable data to read a header. |
| 239 | cantFail(Err: readStruct(Buffer, Src: Current, Struct&: IteratorState.Part)); |
| 240 | IteratorState.Data = |
| 241 | StringRef(Current + sizeof(dxbc::PartHeader), IteratorState.Part.Size); |
| 242 | IteratorState.Offset = Offset; |
| 243 | } |
| 244 | |
| 245 | Error DirectX::RootSignature::parse() { |
| 246 | const char *Current = PartData.begin(); |
| 247 | |
| 248 | // Root Signature headers expects 6 integers to be present. |
| 249 | if (PartData.size() < 6 * sizeof(uint32_t)) |
| 250 | return parseFailed( |
| 251 | Msg: "Invalid root signature, insufficient space for header." ); |
| 252 | |
| 253 | Version = support::endian::read<uint32_t, llvm::endianness::little>(P: Current); |
| 254 | Current += sizeof(uint32_t); |
| 255 | |
| 256 | NumParameters = |
| 257 | support::endian::read<uint32_t, llvm::endianness::little>(P: Current); |
| 258 | Current += sizeof(uint32_t); |
| 259 | |
| 260 | RootParametersOffset = |
| 261 | support::endian::read<uint32_t, llvm::endianness::little>(P: Current); |
| 262 | Current += sizeof(uint32_t); |
| 263 | |
| 264 | NumStaticSamplers = |
| 265 | support::endian::read<uint32_t, llvm::endianness::little>(P: Current); |
| 266 | Current += sizeof(uint32_t); |
| 267 | |
| 268 | StaticSamplersOffset = |
| 269 | support::endian::read<uint32_t, llvm::endianness::little>(P: Current); |
| 270 | Current += sizeof(uint32_t); |
| 271 | |
| 272 | Flags = support::endian::read<uint32_t, llvm::endianness::little>(P: Current); |
| 273 | Current += sizeof(uint32_t); |
| 274 | |
| 275 | ParametersHeaders.Data = PartData.substr( |
| 276 | Start: RootParametersOffset, |
| 277 | N: NumParameters * sizeof(dxbc::RTS0::v1::RootParameterHeader)); |
| 278 | |
| 279 | StaticSamplers.Stride = sizeof(dxbc::RTS0::v1::StaticSampler); |
| 280 | StaticSamplers.Data = PartData.substr( |
| 281 | Start: StaticSamplersOffset, |
| 282 | N: NumStaticSamplers * sizeof(dxbc::RTS0::v1::StaticSampler)); |
| 283 | |
| 284 | return Error::success(); |
| 285 | } |
| 286 | |
| 287 | Error DirectX::PSVRuntimeInfo::parse(uint16_t ShaderKind) { |
| 288 | Triple::EnvironmentType ShaderStage = dxbc::getShaderStage(Kind: ShaderKind); |
| 289 | |
| 290 | const char *Current = Data.begin(); |
| 291 | if (Error Err = readInteger(Buffer: Data, Src: Current, Val&: Size)) |
| 292 | return Err; |
| 293 | Current += sizeof(uint32_t); |
| 294 | |
| 295 | StringRef PSVInfoData = Data.substr(Start: sizeof(uint32_t), N: Size); |
| 296 | |
| 297 | if (PSVInfoData.size() < Size) |
| 298 | return parseFailed( |
| 299 | Msg: "Pipeline state data extends beyond the bounds of the part" ); |
| 300 | |
| 301 | using namespace dxbc::PSV; |
| 302 | |
| 303 | const uint32_t PSVVersion = getVersion(); |
| 304 | |
| 305 | // Detect the PSVVersion by looking at the size field. |
| 306 | if (PSVVersion == 3) { |
| 307 | v3::RuntimeInfo Info; |
| 308 | if (Error Err = readStruct(Buffer: PSVInfoData, Src: Current, Struct&: Info)) |
| 309 | return Err; |
| 310 | if (sys::IsBigEndianHost) |
| 311 | Info.swapBytes(Stage: ShaderStage); |
| 312 | BasicInfo = Info; |
| 313 | } else if (PSVVersion == 2) { |
| 314 | v2::RuntimeInfo Info; |
| 315 | if (Error Err = readStruct(Buffer: PSVInfoData, Src: Current, Struct&: Info)) |
| 316 | return Err; |
| 317 | if (sys::IsBigEndianHost) |
| 318 | Info.swapBytes(Stage: ShaderStage); |
| 319 | BasicInfo = Info; |
| 320 | } else if (PSVVersion == 1) { |
| 321 | v1::RuntimeInfo Info; |
| 322 | if (Error Err = readStruct(Buffer: PSVInfoData, Src: Current, Struct&: Info)) |
| 323 | return Err; |
| 324 | if (sys::IsBigEndianHost) |
| 325 | Info.swapBytes(Stage: ShaderStage); |
| 326 | BasicInfo = Info; |
| 327 | } else if (PSVVersion == 0) { |
| 328 | v0::RuntimeInfo Info; |
| 329 | if (Error Err = readStruct(Buffer: PSVInfoData, Src: Current, Struct&: Info)) |
| 330 | return Err; |
| 331 | if (sys::IsBigEndianHost) |
| 332 | Info.swapBytes(Stage: ShaderStage); |
| 333 | BasicInfo = Info; |
| 334 | } else |
| 335 | return parseFailed( |
| 336 | Msg: "Cannot read PSV Runtime Info, unsupported PSV version." ); |
| 337 | |
| 338 | Current += Size; |
| 339 | |
| 340 | uint32_t ResourceCount = 0; |
| 341 | if (Error Err = readInteger(Buffer: Data, Src: Current, Val&: ResourceCount)) |
| 342 | return Err; |
| 343 | Current += sizeof(uint32_t); |
| 344 | |
| 345 | if (ResourceCount > 0) { |
| 346 | if (Error Err = readInteger(Buffer: Data, Src: Current, Val&: Resources.Stride)) |
| 347 | return Err; |
| 348 | Current += sizeof(uint32_t); |
| 349 | |
| 350 | size_t BindingDataSize = Resources.Stride * ResourceCount; |
| 351 | Resources.Data = Data.substr(Start: Current - Data.begin(), N: BindingDataSize); |
| 352 | |
| 353 | if (Resources.Data.size() < BindingDataSize) |
| 354 | return parseFailed( |
| 355 | Msg: "Resource binding data extends beyond the bounds of the part" ); |
| 356 | |
| 357 | Current += BindingDataSize; |
| 358 | } else |
| 359 | Resources.Stride = sizeof(v2::ResourceBindInfo); |
| 360 | |
| 361 | // PSV version 0 ends after the resource bindings. |
| 362 | if (PSVVersion == 0) |
| 363 | return Error::success(); |
| 364 | |
| 365 | // String table starts at a 4-byte offset. |
| 366 | Current = reinterpret_cast<const char *>( |
| 367 | alignTo<4>(Value: reinterpret_cast<uintptr_t>(Current))); |
| 368 | |
| 369 | uint32_t StringTableSize = 0; |
| 370 | if (Error Err = readInteger(Buffer: Data, Src: Current, Val&: StringTableSize)) |
| 371 | return Err; |
| 372 | if (StringTableSize % 4 != 0) |
| 373 | return parseFailed(Msg: "String table misaligned" ); |
| 374 | Current += sizeof(uint32_t); |
| 375 | StringTable = StringRef(Current, StringTableSize); |
| 376 | |
| 377 | Current += StringTableSize; |
| 378 | |
| 379 | uint32_t SemanticIndexTableSize = 0; |
| 380 | if (Error Err = readInteger(Buffer: Data, Src: Current, Val&: SemanticIndexTableSize)) |
| 381 | return Err; |
| 382 | Current += sizeof(uint32_t); |
| 383 | |
| 384 | SemanticIndexTable.reserve(N: SemanticIndexTableSize); |
| 385 | for (uint32_t I = 0; I < SemanticIndexTableSize; ++I) { |
| 386 | uint32_t Index = 0; |
| 387 | if (Error Err = readInteger(Buffer: Data, Src: Current, Val&: Index)) |
| 388 | return Err; |
| 389 | Current += sizeof(uint32_t); |
| 390 | SemanticIndexTable.push_back(Elt: Index); |
| 391 | } |
| 392 | |
| 393 | uint8_t InputCount = getSigInputCount(); |
| 394 | uint8_t OutputCount = getSigOutputCount(); |
| 395 | uint8_t PatchOrPrimCount = getSigPatchOrPrimCount(); |
| 396 | |
| 397 | uint32_t ElementCount = InputCount + OutputCount + PatchOrPrimCount; |
| 398 | |
| 399 | if (ElementCount > 0) { |
| 400 | if (Error Err = readInteger(Buffer: Data, Src: Current, Val&: SigInputElements.Stride)) |
| 401 | return Err; |
| 402 | Current += sizeof(uint32_t); |
| 403 | // Assign the stride to all the arrays. |
| 404 | SigOutputElements.Stride = SigPatchOrPrimElements.Stride = |
| 405 | SigInputElements.Stride; |
| 406 | |
| 407 | if (Data.end() - Current < |
| 408 | (ptrdiff_t)(ElementCount * SigInputElements.Stride)) |
| 409 | return parseFailed( |
| 410 | Msg: "Signature elements extend beyond the size of the part" ); |
| 411 | |
| 412 | size_t InputSize = SigInputElements.Stride * InputCount; |
| 413 | SigInputElements.Data = Data.substr(Start: Current - Data.begin(), N: InputSize); |
| 414 | Current += InputSize; |
| 415 | |
| 416 | size_t OutputSize = SigOutputElements.Stride * OutputCount; |
| 417 | SigOutputElements.Data = Data.substr(Start: Current - Data.begin(), N: OutputSize); |
| 418 | Current += OutputSize; |
| 419 | |
| 420 | size_t PSize = SigPatchOrPrimElements.Stride * PatchOrPrimCount; |
| 421 | SigPatchOrPrimElements.Data = Data.substr(Start: Current - Data.begin(), N: PSize); |
| 422 | Current += PSize; |
| 423 | } |
| 424 | |
| 425 | ArrayRef<uint8_t> OutputVectorCounts = getOutputVectorCounts(); |
| 426 | uint8_t PatchConstOrPrimVectorCount = getPatchConstOrPrimVectorCount(); |
| 427 | uint8_t InputVectorCount = getInputVectorCount(); |
| 428 | |
| 429 | auto maskDwordSize = [](uint8_t Vector) { |
| 430 | return (static_cast<uint32_t>(Vector) + 7) >> 3; |
| 431 | }; |
| 432 | |
| 433 | auto mapTableSize = [maskDwordSize](uint8_t X, uint8_t Y) { |
| 434 | return maskDwordSize(Y) * X * 4; |
| 435 | }; |
| 436 | |
| 437 | if (usesViewID()) { |
| 438 | for (uint32_t I = 0; I < OutputVectorCounts.size(); ++I) { |
| 439 | // The vector mask is one bit per component and 4 components per vector. |
| 440 | // We can compute the number of dwords required by rounding up to the next |
| 441 | // multiple of 8. |
| 442 | uint32_t NumDwords = |
| 443 | maskDwordSize(static_cast<uint32_t>(OutputVectorCounts[I])); |
| 444 | size_t NumBytes = NumDwords * sizeof(uint32_t); |
| 445 | OutputVectorMasks[I].Data = Data.substr(Start: Current - Data.begin(), N: NumBytes); |
| 446 | Current += NumBytes; |
| 447 | } |
| 448 | |
| 449 | if (ShaderStage == Triple::Hull && PatchConstOrPrimVectorCount > 0) { |
| 450 | uint32_t NumDwords = maskDwordSize(PatchConstOrPrimVectorCount); |
| 451 | size_t NumBytes = NumDwords * sizeof(uint32_t); |
| 452 | PatchOrPrimMasks.Data = Data.substr(Start: Current - Data.begin(), N: NumBytes); |
| 453 | Current += NumBytes; |
| 454 | } |
| 455 | } |
| 456 | |
| 457 | // Input/Output mapping table |
| 458 | for (uint32_t I = 0; I < OutputVectorCounts.size(); ++I) { |
| 459 | if (InputVectorCount == 0 || OutputVectorCounts[I] == 0) |
| 460 | continue; |
| 461 | uint32_t NumDwords = mapTableSize(InputVectorCount, OutputVectorCounts[I]); |
| 462 | size_t NumBytes = NumDwords * sizeof(uint32_t); |
| 463 | InputOutputMap[I].Data = Data.substr(Start: Current - Data.begin(), N: NumBytes); |
| 464 | Current += NumBytes; |
| 465 | } |
| 466 | |
| 467 | // Hull shader: Input/Patch mapping table |
| 468 | if (ShaderStage == Triple::Hull && PatchConstOrPrimVectorCount > 0 && |
| 469 | InputVectorCount > 0) { |
| 470 | uint32_t NumDwords = |
| 471 | mapTableSize(InputVectorCount, PatchConstOrPrimVectorCount); |
| 472 | size_t NumBytes = NumDwords * sizeof(uint32_t); |
| 473 | InputPatchMap.Data = Data.substr(Start: Current - Data.begin(), N: NumBytes); |
| 474 | Current += NumBytes; |
| 475 | } |
| 476 | |
| 477 | // Domain Shader: Patch/Output mapping table |
| 478 | if (ShaderStage == Triple::Domain && PatchConstOrPrimVectorCount > 0 && |
| 479 | OutputVectorCounts[0] > 0) { |
| 480 | uint32_t NumDwords = |
| 481 | mapTableSize(PatchConstOrPrimVectorCount, OutputVectorCounts[0]); |
| 482 | size_t NumBytes = NumDwords * sizeof(uint32_t); |
| 483 | PatchOutputMap.Data = Data.substr(Start: Current - Data.begin(), N: NumBytes); |
| 484 | Current += NumBytes; |
| 485 | } |
| 486 | |
| 487 | return Error::success(); |
| 488 | } |
| 489 | |
| 490 | uint8_t DirectX::PSVRuntimeInfo::getSigInputCount() const { |
| 491 | if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(ptr: &BasicInfo)) |
| 492 | return P->SigInputElements; |
| 493 | if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(ptr: &BasicInfo)) |
| 494 | return P->SigInputElements; |
| 495 | if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(ptr: &BasicInfo)) |
| 496 | return P->SigInputElements; |
| 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | uint8_t DirectX::PSVRuntimeInfo::getSigOutputCount() const { |
| 501 | if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(ptr: &BasicInfo)) |
| 502 | return P->SigOutputElements; |
| 503 | if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(ptr: &BasicInfo)) |
| 504 | return P->SigOutputElements; |
| 505 | if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(ptr: &BasicInfo)) |
| 506 | return P->SigOutputElements; |
| 507 | return 0; |
| 508 | } |
| 509 | |
| 510 | uint8_t DirectX::PSVRuntimeInfo::getSigPatchOrPrimCount() const { |
| 511 | if (const auto *P = std::get_if<dxbc::PSV::v3::RuntimeInfo>(ptr: &BasicInfo)) |
| 512 | return P->SigPatchOrPrimElements; |
| 513 | if (const auto *P = std::get_if<dxbc::PSV::v2::RuntimeInfo>(ptr: &BasicInfo)) |
| 514 | return P->SigPatchOrPrimElements; |
| 515 | if (const auto *P = std::get_if<dxbc::PSV::v1::RuntimeInfo>(ptr: &BasicInfo)) |
| 516 | return P->SigPatchOrPrimElements; |
| 517 | return 0; |
| 518 | } |
| 519 | |