BC7 CPU codec optimization to skip mode 7 for opaque blocks

This commit is contained in:
Chuck Walbourn 2018-07-03 19:33:07 -07:00
parent a884753044
commit ba30da0945

View File

@ -2733,6 +2733,7 @@ void D3DX_BC7::Encode(DWORD flags, const HDRColorA* const pIn)
D3DX_BC7 final = *this;
EncodeParams EP(pIn);
float fMSEBest = FLT_MAX;
uint32_t alphaMask = 0xFF;
for (size_t i = 0; i < NUM_PIXELS_PER_BLOCK; ++i)
{
@ -2740,8 +2741,11 @@ void D3DX_BC7::Encode(DWORD flags, const HDRColorA* const pIn)
EP.aLDRPixels[i].g = uint8_t(std::max<float>(0.0f, std::min<float>(255.0f, pIn[i].g * 255.0f + 0.01f)));
EP.aLDRPixels[i].b = uint8_t(std::max<float>(0.0f, std::min<float>(255.0f, pIn[i].b * 255.0f + 0.01f)));
EP.aLDRPixels[i].a = uint8_t(std::max<float>(0.0f, std::min<float>(255.0f, pIn[i].a * 255.0f + 0.01f)));
alphaMask &= EP.aLDRPixels[i].a;
}
const bool bHasAlpha = (alphaMask != 0xFF);
for (EP.uMode = 0; EP.uMode < 8 && fMSEBest > 0; ++EP.uMode)
{
if (!(flags & BC_FLAGS_USE_3SUBSETS) && (EP.uMode == 0 || EP.uMode == 2))
@ -2756,6 +2760,12 @@ void D3DX_BC7::Encode(DWORD flags, const HDRColorA* const pIn)
continue;
}
if ((!bHasAlpha) && (EP.uMode == 7))
{
// There is no value in using mode 7 for completely opaque blocks (the other 2 subset modes handle this case for opaque blocks), so skip it for a small perf win.
continue;
}
const size_t uShapes = size_t(1) << ms_aInfo[EP.uMode].uPartitionBits;
assert(uShapes <= BC7_MAX_SHAPES);
_Analysis_assume_(uShapes <= BC7_MAX_SHAPES);