GPUOpen-Tools / compressonator

Tool suite for Texture and 3D Model Compression, Optimization and Analysis using CPUs, GPUs and APUs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BC6H CPU (Core) encoder produces artifacts

man-in-black382 opened this issue · comments

CompressBlockBC6 from cmp_core\shaders\bc6_encode_kernel.cpp produces heavy artifacts:
Screenshot 2023-10-27 184830

While the the Compressonator GUI app does not:
Screenshot 2023-10-27 184706

GUI app uses, what looks to be, functionally identical implementation of the BC6 compression code, which is contained in BC6HBlockEncoder::CompressBlock (and lot of other functions) in cmp_compressonatorlib\bc6h\bc6h_encode.cpp, but, obviously, it's not completely identical, otherwise both approaches would produce a non-currupted image. I wasn't able to spot the deficiency, it's a massive codebase after all.

In order to reproduce this, one can add

unsigned short inputs[BC6H_MAX_SUBSET_SIZE][3];

for (int i = 0; i < BC6H_MAX_SUBSET_SIZE; i++)
{
    inputs[i][0] = CMP_HALF(in[i][0]).bits();
    inputs[i][1] = CMP_HALF(in[i][1]).bits();
    inputs[i][2] = CMP_HALF(in[i][2]).bits();
}

CompressBlockBC6(&inputs[0][0], 3, out, nullptr);
return 0;

in the beginning of float BC6HBlockEncoder::CompressBlock(float in[MAX_SUBSET_SIZE][MAX_DIMENSION_BIG], BYTE out[COMPRESSED_BLOCK_SIZE]) in cmp_compressonatorlib\bc6h\bc6h_encode.cpp. Pretty much the same thing is performed under #ifdef USE_CMP_BC7_CORE in BC7BlockEncoder::CompressBlock in cmp_compressonatorlib\bc7\bc7_encode.cpp (just for reference).

This replaces the seemingly identical compression code with that from the core library. Generated image has heavy artifacts.

Note on = CMP_HALF(in[i][0]).bits();. I ommitted handling NaNs and such (skipped calling MapToF16). I made sure that it's not relevant to the problem.

Changing compression options, such as quality or mask, didn't change the outcome.

Thanks in advance!

@man-in-black382 Thanks for the issue report! We'll definitely have to investigate this to figure out what could be causing this difference.