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

Handle mipmaps and VRAM compression for glTF binary images #62499

Merged
merged 1 commit into from
Jan 27, 2023

Conversation

fire
Copy link
Member

@fire fire commented Jun 28, 2022

Provide three options:

[ Ignore and Warn (default) | Optimize Loading Embedded as Basisu | Extract ]


Fixes: godotengine/godot-proposals#4271

Relates: #62436

Relates: #62295


Part of the V-Sekai group. https://github.com/v-sekai

@fire fire requested a review from a team as a code owner June 28, 2022 21:44
@fire fire force-pushed the gltf-binary-img-compression branch 3 times, most recently from 5f51c69 to 7ecee28 Compare June 28, 2022 22:00
@fire fire changed the title To keep performance, load gltf binary as compressed texture To keep runtime performance, load gltf binary as compressed texture Jun 28, 2022
@Calinou Calinou added this to the 4.0 milestone Jun 28, 2022
@fire
Copy link
Member Author

fire commented Jun 28, 2022

See also #59540 ( Directly compress mip maps from Basis Universal #59540 )

@fire fire marked this pull request as draft June 29, 2022 18:08
@fire
Copy link
Member Author

fire commented Jun 29, 2022

The change itself is good, but the basis universal compression is not fast enough. Will work on it or find an other approach like detect 3d.

@lyuma
Copy link
Contributor

lyuma commented Jun 29, 2022

@fire Do you have some data on the performance problems?

I think this is what we were trying to figure out when we were discussing the viability of Basis a few months ago.

Is the problem with import / compression (okay) or runtime / decompression / conversion to native VRAM compression (bad, affects game loading time)

Also, it would be nice if it can reuse the compressed textures if they have the same hash if I reimport the gltf

@fire
Copy link
Member Author

fire commented Jun 29, 2022

I think we need time limits for the import. I tested using a sample non commercial licensed avatar like https://github.com/Miraikomachi/MiraikomachiVRM/blob/master/Miraikomachi.vrm and it was very slow with our vrm addon.

I think we can disable uastc, and live with the worse etc1 quality for a speedup.

@fire fire force-pushed the gltf-binary-img-compression branch 2 times, most recently from 6dad928 to 94b1ef8 Compare July 7, 2022 20:52
@fire
Copy link
Member Author

fire commented Jul 7, 2022

Original use case:

  1. Have a single packed godot scene to store the entire level and expecting the level's texture images to work on android, mac and pc.
  2. Use basis u and portable compressed texture
  3. and the images will be portable compressed texture
  4. if one disables uastc, it will be bad quality

@fire fire force-pushed the gltf-binary-img-compression branch from 94b1ef8 to 5efe9e0 Compare July 7, 2022 21:38
@fire fire force-pushed the gltf-binary-img-compression branch from 5efe9e0 to 2903122 Compare July 19, 2022 01:10
@fire fire marked this pull request as ready for review July 19, 2022 01:50
@reduz
Copy link
Member

reduz commented Aug 7, 2022

I think we need a better way to tell users they exported their GLTF with built-in textures and by default Godot will take no action with them (we could make it optional what to do per scene in the GLTF import options).

@fire
Copy link
Member Author

fire commented Aug 7, 2022

Discussed with @reduz

We concluded with this design.

[ Ignore and Warn (default) | Optimize Loading Embedded as Basisu etc1s via 59540 | Extract ]

@fire
Copy link
Member Author

fire commented Aug 7, 2022

We discussed avoiding creating a folder.

Do filename.gltf -> filename[minus .gltf].texturename.png

I'll try to provide a pull request where the GLTF2 can compress to BasisU (etc1s) and extract to the folder using the above convention.

@fire fire force-pushed the gltf-binary-img-compression branch 2 times, most recently from 52b708f to b3e9e7e Compare August 7, 2022 21:19
@fire fire changed the title To keep runtime performance, load gltf binary as compressed texture Handle gltf binary Aug 7, 2022
@fire fire force-pushed the gltf-binary-img-compression branch 3 times, most recently from cc86d29 to 30e379b Compare August 7, 2022 21:33
@fire fire marked this pull request as draft December 26, 2022 07:17
@fire fire force-pushed the gltf-binary-img-compression branch 5 times, most recently from 54c3cb4 to dc8a8dd Compare December 26, 2022 09:34
@fire
Copy link
Member Author

fire commented Dec 26, 2022

image

A bug is the portable texture requires knowing about if the texture is a normal map or not but when we go through gltf -> portable compressed 2d texture -> basisu we lose that when compressing basisu as if it was a base color map.

@clayjohn
Copy link
Member

@fire what remains to be done on this PR before it is ready? It would be nice for this to make it in time for 4.0 so we can support .glb files better

@fire
Copy link
Member Author

fire commented Jan 18, 2023

I believe this was blocked on ASTC support (done by one of my prs), which is blocked on ASTC import (reduz expressed interest in doing this) which is blocked on Basisu changes (easy).

@fire
Copy link
Member Author

fire commented Jan 19, 2023

Use the image naming at the same level don't use a folder.

@fire
Copy link
Member Author

fire commented Jan 26, 2023

I am happy with regards to usability.

[ Extract (default) | Ignore and Warn | Optimize Loading Embedded as Basisu ]

@lyuma lyuma force-pushed the gltf-binary-img-compression branch from dc8a8dd to 3962109 Compare January 27, 2023 09:33
@lyuma lyuma marked this pull request as ready for review January 27, 2023 09:49
@lyuma lyuma requested review from a team as code owners January 27, 2023 09:49
core/string/ustring.cpp Outdated Show resolved Hide resolved
static const char *invalid_filename_characters = ": / \\ ? * \" | % < >";

String String::validate_filename() const {
Vector<String> chars = String(invalid_filename_characters).split(" ");
Copy link
Member

@akien-mga akien-mga Jan 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be LocalVector maybe.
Edit: Nevermind, I guess split() returns Vector<String> so you can't just assign it to a different container.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is .split() allocates a Vector. validate_node_name does the same. It's called infrequently in imoprt code.
I was originally thinking of doing .replace().replace()...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be for a follow-up PR if needed/relevant, but I guess invalid_filename_characters could be made a static LocalVector<CharString> with all the chars already split, so we don't need to redo this computation for what's going to always be the same every time we validate a filename.

core/string/ustring.cpp Outdated Show resolved Hide resolved
[ Ignore and Warn | Extract Textures (default) | Optimize Loading Embedded as Basisu ]

Enable compressed mip maps from Basis Universal for faster compressions.

Increase the quality of Basis to avoid corruption.

To keep compatibility use the first mip of the previous internal Godot format.

Because texture names may have invalid filename characters, adds String::validate_filename to sanitize filenames for import pipeline use.
@lyuma lyuma force-pushed the gltf-binary-img-compression branch from 3962109 to 39922d7 Compare January 27, 2023 10:02
@akien-mga akien-mga dismissed reduz’s stale review January 27, 2023 10:07

Changes done.

@akien-mga akien-mga merged commit 9d555f5 into godotengine:master Jan 27, 2023
@akien-mga
Copy link
Member

Thanks!

@akien-mga akien-mga changed the title Handle gltf binary images Handle mipmaps and VRAM compression for glTF binary images Jan 27, 2023
@fire fire deleted the gltf-binary-img-compression branch January 27, 2023 15:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Compress textures when importing a GLTF2 that has built-in textures as BasisU
6 participants