-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Add support for KTX image format so that we can use Basis Universal for GLTF #76572
Conversation
Is every single header of the library needed? 45k new lines of stuff are a lot and I think a bit too much for loading a new image container. Can you trim a bit the |
The biggest remaining file is |
I will try to review. Trying get some more opinions from the godot engine team members |
Weird error. Might have to hotpatch and send upstream? |
Hey, I was asked to review this by @fire and just wanted to add some supporting info: Slides from Khronos The goal here as far as I can understand is that we want to make exported games smaller and also we would like to reduce the amount of resource duplication. Basically apple/android uses ETC2 or ASTC. This means you export your game it includes them on windows both of them, potentially making things huge. So that means you import one texture: and it becomes 3 potentially. This unifies in a single format "basis universal" which can easily transcode into those formats. This moves texture import time outside of the editor time, without compromising performance/quality. For non subject matter experts: smaller game export, faster editor import time, faster boot time because the dataset for the export is smaller. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The only portion I dislike is the massive switch case but it looks simple enough and is OK that it is explicit, it's also fast so, I should not complain really 😅
Maybe recommend writing a very simple unit test for this if you can.
Some errors in the cicd and the pr isn’t squashed |
|
Does this PR allow loading arbitrary KTX images from the filesystem or a buffer in an exported project, similar to |
It doesn't add arbitrary loading like png, it only adds support for KTX file the same way DDS files are handled (as imported texture files) |
Do you know how much effort it is to load_ktx_from_buffer and load_ktx_from_file? Was curious. We'd need to add the api as @Calinou said for the basisu in gltf usecase |
A commit was added for KHR_texture_basisu support in glTF module NB: there is a shadow dependency in Sorry for the back and forthes of this review |
I'll try asking for support. Aside from that, there are some whitespace cicd errors. |
@acazuc With that test asset you posted, when I try to load
|
Note that #69085 implements run-time DDS loading. |
@aaronfranke that is strange, did you used the last commit (at least 6271fdd) ? |
@acazuc I just re-tested, this time with 8ca3bbc0e77ddcfb35c64878889c574a19ff7675, and it works. Although interestingly, the PNG and JPG version does not work. It might be the same issue as #76691. Well, now that I've tested that this works... As for giving this PR a review, I'm not really sold on this being in core due to the extremely large amount of code required. 30k lines is a lot. Regardless of whether we want this to be in core or not, I want to modify the code in GLTFDocument to allow GLTFDocumentExtension classes to extend the importer with arbitrary image formats, instead of just adding KTX to the current hard-coded code. As a first test I would like to implement |
Is it correct that thirdparty/libktx/lib/dfdutils/vulkan/vulkan_core.h is a duplicate because it costs 10,000 lines of code? |
@acazuc Do you require some help with removing the "GHA / 🐧 Linux / Editor w/ Mono (target=editor) (pull_request) Failing after 4m" Github action test failure? |
@fire yes, it was almost a duplicate (there was some ASTC VkFormat enum that aren't defined in |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you refresh the pr? |
Binary size comparison for a Linux x86_64 stripped release export template with LTO:
This PR adds about 107 KB. |
Just noting for reviewers that I still need to check the thirdparty code integration, but otherwise this should be good to merge once I've done that. |
Did a quick review pass, the integration of the thirdparty library is pretty good! Great job trimming down all the files we don't need to keep it minimal. Here's a diff with some further changes to properly document the copyright, and handle the fact that Godot can be compiled without diff --git a/COPYRIGHT.txt b/COPYRIGHT.txt
index 582784d78e..904b2adca2 100644
--- a/COPYRIGHT.txt
+++ b/COPYRIGHT.txt
@@ -256,6 +256,12 @@ Comment: jpeg-compressor
Copyright: 2012, Rich Geldreich
License: public-domain or Apache-2.0
+Files: ./thirdparty/libktx/
+Comment: KTX
+Copyright: 2013-2020, Mark Callow
+ 2010-2020 The Khronos Group, Inc.
+License: Apache-2.0
+
Files: ./thirdparty/libogg/
Comment: OggVorbis
Copyright: 2002, Xiph.org Foundation
diff --git a/modules/ktx/SCsub b/modules/ktx/SCsub
index 9507d5c4c8..9e45313701 100644
--- a/modules/ktx/SCsub
+++ b/modules/ktx/SCsub
@@ -11,7 +11,6 @@ thirdparty_obj = []
thirdparty_dir = "#thirdparty/libktx/"
thirdparty_sources = [
- "lib/basis_transcode.cpp",
"lib/checkheader.c",
"lib/filestream.c",
"lib/hashlist.c",
@@ -32,11 +31,19 @@ thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
env_ktx.Prepend(CPPPATH=[thirdparty_dir + "include"])
env_ktx.Prepend(CPPPATH=[thirdparty_dir + "utils"])
env_ktx.Prepend(CPPPATH=[thirdparty_dir + "lib"])
-env_ktx.Prepend(CPPPATH=[thirdparty_dir + "lib/dfdutils"])
env_ktx.Prepend(CPPPATH=[thirdparty_dir + "other_include"])
-env_ktx.Prepend(CPPPATH=["#thirdparty/basis_universal"])
-env_ktx.Prepend(CPPPATH=["#thirdparty/vulkan/include"])
-env_ktx.Prepend(CPPFLAGS=["-DKHRONOS_STATIC=1"])
+
+if env["module_basis_universal_enabled"]:
+ thirdparty_sources += [thirdparty_dir + "lib/basis_transcode.cpp"]
+ env_ktx.Prepend(CPPPATH=["#thirdparty/basis_universal"])
+
+if env["vulkan"]:
+ env_ktx.Prepend(CPPPATH=["#thirdparty/vulkan/include"])
+else:
+ # Falls back on bundled `vkformat_enum.h`.
+ env_ktx.Append(CPPDEFINES=["LIBKTX"])
+
+env_ktx.Append(CPPDEFINES=[("KHRONOS_STATIC", 1)])
env_thirdparty = env_ktx.Clone()
env_thirdparty.disable_warnings()
diff --git a/thirdparty/README.md b/thirdparty/README.md
index 611f63b02a..a4e4294a77 100644
--- a/thirdparty/README.md
+++ b/thirdparty/README.md
@@ -303,7 +303,7 @@ Files extracted from upstream source:
- Upstream: https://github.com/KhronosGroup/KTX-Software
- Version: 4.1.0 (d7255fe73cd53b856731ceb9f2c279181d0dbbca, 2023)
-- License: MIT
+- License: Apache-2.0
Files extracted from upstream source:
@@ -315,7 +315,7 @@ Files extracted from upstream source:
- `other_include/KHR/*`
- ifndef-protect NOMINMAX define in `lib/gl_format.h`
- remove `basisu/` prefix from `thirdparty/libktx/lib/basis_transcode.cpp` basisu includes
-- comment VK\_FORMAT\_ASTC_\*x\*x\*\_UNORM\_BLOCK\_EXT cases in lib/dfdutils/vk2dfd.inl
+- comment `VK_FORMAT_ASTC_*x*x*_UNORM_BLOCK_EXT` cases in `lib/dfdutils/vk2dfd.inl`
## libogg The instructions in We need to have precise documentation on which files to copy or not, so that future updates can be done easily. (E.g. there's already version 4.2.1 upstream which we might want to update too eventually). And this part might be best described as a
It's also a bit uncommon IMO to include files from a |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really good now!
The only bit I'm missing from my earlier review is improving the update instructions in thirdparty/README.md
, to know which files to copy and which ones to leave out.
Add support glTF KHR_texture_basisu extension
Amazing work, thanks! Congrats for your first merged Godot contribution 🎉 |
@acazuc What do you mean by the |
@nikitalita Thumbnails being broken is a sign that decompression is broken. You could test that theory by manually loading the texture in GDScript, decompressing, then displaying the resulting image |
@nikitalita I had the same problem with ETC compressed images in the KTX test suite |
@acazuc @nikitalita Have you noticed darker textures for those that After commenting this convertion, it works fine (at least for the texture I see darker) godot/modules/ktx/texture_loader_ktx.cpp Line 500 in 0c45ace
texture zipped |
@leanmendoza, can you make an issue for this? This will get lost here. |
Yes, I first wanted to give a try here, but done #99589 |
Bugsquad Edit: This implements KTX support with Basisu gltf extension and fixes: godotengine/godot-proposals#5873 The final binary size is ~100KB added.
Hello,
This merge request allows KTX file format texture loading
There are some limitations to supported KTX files: 2d images only, no cubemap, no array, no de-padding, only a limited list of godot Image formats
Decoding is done using libktx
I tested ktx files from ktxtext, most useful formats are working (rgb8, rgba8, astc, bc1-7, and some others), invalid / unsupported files are handled with error messages
KTX uses 4-bytes padding, and no de-padding is done here:
I guess it does help for godotengine/godot-proposals#5873
Compilation & tests has been done in amd64 target
Regards,