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

DDS cube map that DirectXTex corrupts faces when extracting #560

Closed
0xC0000054 opened this issue Nov 27, 2024 · 7 comments · Fixed by #567
Closed

DDS cube map that DirectXTex corrupts faces when extracting #560

0xC0000054 opened this issue Nov 27, 2024 · 7 comments · Fixed by #567
Assignees
Labels

Comments

@0xC0000054
Copy link
Contributor

The following DDS image has the 2nd through 6th cube map faces corrupted when trying to extract it.

https://github.com/vsg-dev/vsgExamples/blob/master/data/textures/skybox.dds

DirectXTex output (horizontal cross):

Image

DDSView renders the image correctly:

Image

The API call I am using to extract the top-level faces is:

const DirectX::Image* face = image.GetImage(0, i, 0);
@walbourn
Copy link
Member

Thank you for the report and repro. It also loads correctly in Visual Studio which uses DirectXTex. I'll look into it.

@walbourn
Copy link
Member

DDS Dump output for this file:

(size: 124) Flags 0002100f: CAPS HEIGHT WIDTH PITCH PIXELFORMAT MIPMAPCOUNT
512 x 512
Pitch: 2048
Mipmap count: 10
Surface flags: 00401008: COMPLEX TEXTURE MIPMAP
Cubemap flags: 0000fe00: CUBEMAP POSX POSY POSZ NEGX NEGY NEGZ
PIXELFORMAT (size 32): 00000004: FOURCC
FourCC = 808540228 'DX10'
dxgiFormat = 28: DXGI_FORMAT_R8G8B8A8_UNORM
resourceDim = 3: DDS_DIMENSION_TEXTURE2D
miscFlag = 00000004: TEXTURECUBE
arraySize = 1

@walbourn
Copy link
Member

walbourn commented Nov 28, 2024

Well, texassemble's hcross operation works fine.

Image

And this code does:

            for (size_t index = 0; index < 6; ++index)
            {
                auto img = (*src)->GetImage(0, index, 0);

So basically the same thing as you.

What are you doing with each face->rowPitch and face->pixels value to produce your corrupted image?

@0xC0000054
Copy link
Contributor Author

What are you doing with each face->rowPitch and face->pixels value to produce your corrupted image?

Calling DirectXTex::SaveToWICFile. My test application is: https://github.com/0xC0000054/DumpDdsCubeMapFaces/blob/main/DumpDdsCubeMapFaces.cpp

The bug was initially reported in my Paint.NET plugin, it treats face->rowPitch as the stride and face->pixels as a pointer to the start of the first row (scan0).

@0xC0000054
Copy link
Contributor Author

0xC0000054 commented Nov 30, 2024

I discovered the source of the bug, it is the presence of the DirectX::DDS_FLAGS_IGNORE_MIPS flag. It appears that the presence of that flag is causing DirectXTex to read the wrong image data when loading a cube map with mipmaps.

I can remove that flag as a workaround. but ideally the DirectX::DDS_FLAGS_IGNORE_MIPS flag behavior with decoding multiple images should be fixed.

@walbourn
Copy link
Member

walbourn commented Dec 2, 2024

Thanks! yes, I see that ignoremips doesn't work an array, cubemap, or cubemap array as written.

It will work fine for 1D, 2D, and 3D textures which have the data in miplevel order (volumes store depth in 'slices' with one slice per mip).

@walbourn walbourn added bug and removed question labels Dec 2, 2024
@walbourn walbourn self-assigned this Dec 2, 2024
@walbourn
Copy link
Member

The purpose of ignoremips is a simple header hack for some malformed files. I'm making it so that flag is ignored for all arrays/cubemaps.

@walbourn walbourn linked a pull request Dec 14, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants