Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent results between R8_UNORM and RGBA #557

Open
jandk opened this issue Nov 17, 2024 · 2 comments
Open

Inconsistent results between R8_UNORM and RGBA #557

jandk opened this issue Nov 17, 2024 · 2 comments
Assignees
Labels

Comments

@jandk
Copy link

jandk commented Nov 17, 2024

Hello,

I'm writing a library to decompress BCn textures, and while getting reference from BC4S by decoding through texconv, I noticed the values are not the same between R8_UNORM and RGBA.

Looking at the code it seems that for R8G8B8A8_UNORM you do add the 0.5/255.0 bias, but not for R8_UNORM.

Is this how it's supposed to be, or is this an issue? I couldn't find anything in the documentation, maybe you could provide more insight?

Greetings
Jan

@jandk jandk closed this as completed Nov 18, 2024
@jandk jandk reopened this Nov 18, 2024
@walbourn
Copy link
Member

Can you provide the specific format input and output? I can take a look at the code paths.

@walbourn walbourn added the bug label Nov 18, 2024
@walbourn walbourn self-assigned this Nov 18, 2024
@jandk
Copy link
Author

jandk commented Nov 18, 2024

Hi, thanks for the quick response. I did some testing and it gets even more confusing...

If I run texconv.exe -ft png -f R8_UNORM .\bc4s.dds, it calls ConvertScanline with inFormat DXGI_FORMAT_R8_SNORM and outFormat DXGI_FORMAT_R8_UNORM which ends up going with XMVectorMultiplyAdd(v, g_XMOneHalf, g_XMOneHalf), which seems completely normal. But then the call to StoreScanline ends up in the switch case DXGI_FORMAT_R8_UNORM, which does not have the extra bit bias.

If I run texconv.exe -ft png -f RGBA .\bc4s.dds it does the same until the StoreScanline where it ends up in the DXGI_FORMAT_R8G8B8A8_UNORM branch, which does add the g_8BitBias.

But both of them don't seem to line up with what I expect. If I open the dds file in paint.net (which uses the ddsfiletype-plus plugin, which uses DirectXTex under the hood), which ends up in this method:
https://github.com/0xC0000054/pdn-ddsfiletype-plus/blob/master/src/DdsFileTypePlusIO/DdsFileTypePlusIO.cpp#L243

If I do this, it does end up calling the Convert function with what seems to be the same DXGI_FORMAT_R8G8B8A8_UNORM. Except this time the result actually seems to be the steps I follow. Unpack SNORM, do the bc4 signed lerps, and pack snorm to unorm.

I've attached the dds file, and the three results as well.

images.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants