GPUOpen-Tools / compressonator

Tool suite for Texture and 3D Model Compression, Optimization and Analysis using CPUs, GPUs and APUs
1.3k stars 198 forks source link

Incorrect default channel swizzle for DXTC codec #59

Closed cdwfs closed 5 years ago

cdwfs commented 6 years ago

I'm running some 32-bit RGBA texture data through the Compressonator library using the high-level CMP_ConvertTexture() API, and I noticed that while the output looks correct if I choose CMP_FORMAT_BC7 as the output format, choosing CMP_FORMAT_BC1 or CMP_FORMAT_BC3 results in the red and blue channels swapped in the output, using otherwise identical input data and compression settings.

I dug around a bit and found an m_bSwizzleChannels variable that controls whether the input data is treated as BGRA (the default) or RGBA. I see no corresponding option in CMP_CompressOptions to change this value, aside from using the (largely undocumented) CmdSet array to set "SwizzleChannels" to a non-zero value. But, shouldn't the default be determined based on the src texture format -- if it's CMP_FORMAT_RGBA_*, shouldn't m_bSwizzleChannels automatically default to true instead of false?

NPCompress commented 6 years ago

@cdwfs This issue is been fixed, the following codec formats have the same problem.

CMP_FORMAT_BC1, CMP_FORMAT_DXT1. CMP_FORMAT_BC2, CMP_FORMAT_DXT3. CMP_FORMAT_BC3, CMP_FORMAT_DXT5. CMP_FORMAT_BC4, CMP_FORMAT_ATI1N, CMP_FORMAT_ATI2N. CMP_FORMAT_BC5, CMP_FORMAT_ATI2N_XY, CMP_FORMAT_ATI2N_DXT5. CMP_FORMAT_ATC_RGB, CMP_FORMAT_ATC_RGBA_Explicit, CMP_FORMAT_ATC_RGBA_Interpolated.

These are checked by a call to bool NeedSwizzle(CMP_FORMAT destformat) in compress.cpp which returns true for formats requiring swizzle.

The SDK contains multi channel swapping code "void CMP_Map_Bytes(...)" in Compressonator.cpp that is under the compile directive #ifndef USE_OLD_SWIZZLE, which is been developed for the fix.

"if it's CMP_FORMATRGBA*, shouldn't m_bSwizzleChannels automatically default to true instead of false?" yes this should, this bug will be fixed.

cdwfs commented 6 years ago

Thank you for the prompt response! Now that I know the issue, I'd be happy to work on a pull request if that would get a fix in faster. Just let me know which you'd prefer.

NPCompress commented 6 years ago

We welcome and encourage all pull requests. Thanks for your support.

AshwinKumarVijay commented 5 years ago

This issue affects the release CLI and GUI as well, right?