| 396 | } |
| 397 | |
| 398 | bool NtcMaterialLoader::TranscodeTiles(const std::vector<TranscodeTileInfo>& tiles, nvrhi::ICommandList* commandList, |
| 399 | bool enableBlockCompression) |
| 400 | { |
| 401 | if (tiles.empty()) |
| 402 | return true; |
| 403 | |
| 404 | assert(tiles.size() <= TRANSCODE_BATCH_SIZE); |
| 405 | |
| 406 | // Indices for grabbing the next available texture from the staging textures |
| 407 | uint32_t texTileColorR8Index = m_texTileColorR8Offset; |
| 408 | uint32_t texTileColorRGBAIndex = m_texTileColorRGBAOffset; |
| 409 | uint32_t texTileBlocksRGIndex = m_texTileBlocksRGOffset; |
| 410 | uint32_t texTileBlocksRGBAIndex = m_texTileBlocksRGBAOffset; |
| 411 | |
| 412 | // Write all descriptors for the color textures into the decompression pass descriptor table |
| 413 | for (int descriptorIndex = 0; descriptorIndex < m_texTileBlocksRGOffset; ++descriptorIndex) |
| 414 | { |
| 415 | nvrhi::BindingSetItem descriptor = nvrhi::BindingSetItem::Texture_UAV( |
| 416 | descriptorIndex, |
| 417 | m_texTranscodeTiles[descriptorIndex]); |
| 418 | m_graphicsDecompressionPass->WriteDescriptor(descriptor); |
| 419 | } |
| 420 | |
| 421 | // Indices which map every tile/textureIndex into the list of temporary textures |
| 422 | std::vector<uint32_t> colorTextureIndices; |
| 423 | std::vector<uint32_t> blockTextureIndices; |
| 424 | |
| 425 | std::array<bool, TRANSCODE_BATCH_SIZE> compressThisTexture; |
| 426 | |
| 427 | commandList->beginMarker("Transcode Tiles: NTC Decompression"); |
| 428 | |
| 429 | // Phase 1 - Select the temporary tile textures from the pool and make state transitions |
| 430 | for (size_t tileIndex = 0; tileIndex < tiles.size(); ++tileIndex) |
| 431 | { |
| 432 | const TranscodeTileInfo& transcodeTile = tiles[tileIndex]; |
| 433 | const NtcMaterial& material = *transcodeTile.material; |
| 434 | |
| 435 | int textureCount = int(material.transcodeMapping.size()); |
| 436 | assert(textureCount <= g_maxTileStagingTextures); // Maximum number of textures supported |
| 437 | |
| 438 | // TODO: Does this this need to be handled without faulting? |
| 439 | assert(material.transcodeMapping.empty() == false); |
| 440 | |
| 441 | for (int textureIndex = 0; textureIndex < textureCount; ++textureIndex) |
| 442 | { |
| 443 | const TextureTranscodeTask& transcodeTask = material.transcodeMapping[textureIndex]; |
| 444 | |
| 445 | bool const isSingleChannel = transcodeTask.numChannels == 1; |
| 446 | |
| 447 | // Select the color texture |
| 448 | uint32_t colorTextureIndex = isSingleChannel ? texTileColorR8Index++ : texTileColorRGBAIndex++; |
| 449 | colorTextureIndices.push_back(colorTextureIndex); |
| 450 | |
| 451 | compressThisTexture[tileIndex] = transcodeTask.bcFormat != ntc::BlockCompressedFormat::None |
| 452 | && enableBlockCompression; |
| 453 | if (compressThisTexture[tileIndex]) |
| 454 | { |
| 455 | // Select the block texture |
no test coverage detected