| 776 | } |
| 777 | |
| 778 | bool OptimizeBlockCompression( |
| 779 | ntc::IContext* context, |
| 780 | ntc::ITextureSetMetadata* textureSetMetadata, |
| 781 | nvrhi::IDevice* device, |
| 782 | nvrhi::ICommandList* commandList, |
| 783 | float psnrThreshold, |
| 784 | GraphicsResourcesForTextureSet const& graphicsResources) |
| 785 | { |
| 786 | assert(device); |
| 787 | |
| 788 | bool anyBC7Textures = false; |
| 789 | for (int textureIndex = 0; textureIndex < textureSetMetadata->GetTextureCount(); ++textureIndex) |
| 790 | { |
| 791 | ntc::ITextureMetadata* textureMetadata = textureSetMetadata->GetTexture(textureIndex); |
| 792 | if (textureMetadata->GetBlockCompressedFormat() == ntc::BlockCompressedFormat::BC7) |
| 793 | { |
| 794 | anyBC7Textures = true; |
| 795 | break; |
| 796 | } |
| 797 | } |
| 798 | |
| 799 | if (!anyBC7Textures) |
| 800 | return true; |
| 801 | |
| 802 | GraphicsBlockCompressionPass blockCompressionPass(device, 1); |
| 803 | if (!blockCompressionPass.Init()) |
| 804 | return false; |
| 805 | |
| 806 | GraphicsImageDifferencePass compareImagesPass(device); |
| 807 | if (!compareImagesPass.Init()) |
| 808 | return false; |
| 809 | |
| 810 | ntc::TextureSetDesc const& textureSetDesc = textureSetMetadata->GetDesc(); |
| 811 | |
| 812 | nvrhi::BufferHandle modeBuffer; |
| 813 | std::vector<uint8_t> blockCompressedData; |
| 814 | |
| 815 | for (int textureIndex = 0; textureIndex < textureSetMetadata->GetTextureCount(); ++textureIndex) |
| 816 | { |
| 817 | ntc::ITextureMetadata* textureMetadata = textureSetMetadata->GetTexture(textureIndex); |
| 818 | if (textureMetadata->GetBlockCompressedFormat() != ntc::BlockCompressedFormat::BC7) |
| 819 | continue; |
| 820 | |
| 821 | GraphicsResourcesForTexture const& textureResources = graphicsResources.perTexture[textureIndex]; |
| 822 | |
| 823 | for (int mipLevel = 0; mipLevel < textureSetDesc.mips; ++mipLevel) |
| 824 | { |
| 825 | int mipWidth = std::max(textureSetDesc.width >> mipLevel, 1); |
| 826 | int mipHeight = std::max(textureSetDesc.height >> mipLevel, 1); |
| 827 | int mipWidthInBlocks = (mipWidth + 3) / 4; |
| 828 | int mipHeightInBlocks = (mipHeight + 3) / 4; |
| 829 | |
| 830 | // First pass - compress without the mode buffer, doing an exhaustive mode search for each block |
| 831 | |
| 832 | ntc::MakeBlockCompressionComputePassParameters compressionParams; |
| 833 | compressionParams.srcRect.width = mipWidth; |
| 834 | compressionParams.srcRect.height = mipHeight; |
| 835 | compressionParams.dstFormat = textureMetadata->GetBlockCompressedFormat(); |
no test coverage detected