-
Notifications
You must be signed in to change notification settings - Fork 235
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
No option to apply zstd
/zlib
compression via JNI
#877
Comments
I'm surprised The native methods are in |
When you phrase it like that, then I hope that it's OK to ask this a bit more broadly. (With a huge disclaimer: I just started looking more closely into all of this, so I often don't have and idea how everything around KTX is supposed to work, at all). Some functions should certainly not be exposed to Java, because they are "too specific for the language". Other functions currently are exposed, but one could make a strong case for not exposing them. For example: I wouldn't have included (You might see the similarities to the point of having to twiddle with 'temp' files in the Maven issue : There should definitely be a way to load raw KTX data from some buffer/array, without having to put it into a temp file...) So the broader question is: Which functions should be exposed? I won't claim to know the answer here. But I'll try to allocate some time to create a PR for The general approach for this is: "When in doubt, leave it out". One can always expose additional functions, but changing or removing one that was previously exposed always is a breaking change. |
I agree I last worked with Java when I was part of JSR184 and JSR257 (3D graphics for J2ME, aka M3G) and developed an M3G engine more than 15 years ago. I no longer remember much of the nitty-gritty. I am happy to receive guidance from experts with current Java knowledge. @ShukantPal would you like to comment? |
I'm also not entirely up to date here. I started https://github.com/jcuda and https://github.com/gpu/JOCL (also ~15 years ago), where I blindly dumped out the whole API (with automatic JNI code generation and such). In the meantime, a lot has happened in this area - mainly in the context of https://openjdk.org/projects/panama/ , which recently has become part of the latest releases, but I have not yet looked at the details. I'll try to go through the list of functions in For example (and this does not really refer to the Java/JNI part): Imagine I have a KTX file, load it into a |
When it comes to anything to do with creating KTX files, Java should be limited to KTX v2.
What do you mean by decoded here? Do you just mean get the image payload data from the file or do you really want RGBA? libktx does not contain decoders for any block-compressed formats except ETC[12]. So you can't get RGBA for BC1-7, ASTC, etc. These are usually used by uploading to a GPU. The BasisU formats can be decoded to RGBA with |
(I'd probably have to insert too many disclaimers here, and could hardly have a profound discussion, because I'm in no way involved in the technicalities of the format itself (or rather, the formatS - from what I heard, KTX itself is merely a "container"...)). But yes, I mean the actual RGBA pixel values. I know that this is not what KTX is supposed to be used for. But in that regard, one might have to ask what the purpose of the JNI bindings should be in the first place. The I know, I know, that's naive, and it's not that simple. But maybe there are some steps that at least go in that direction, and make it easier for "average" developers to handle KTX... |
The Java bindings are just a one to one mapping for the functionality libktx provides in the C/C++ interface. Uncompressing textures is not implemented in the native library, which is probably why it won’t be in Java; otherwise we’d have to re implement that logic in each other language binding too. The reason why it’s not implemented is probably because KTX is a container file format, and not an encoding format. But it would certainly make sense to support manipulation of the encoding if there’s sufficient demand. In the case of GL2 upload, we would want to be careful not to be prescriptive of which Java binding you use with Vulcan. Usually you can simply upload the byte array to these APIs so there’s not much value add to adding a GL2 upload helper. But I’m certainly not against it. |
The approach of a 1:1 mapping does make sense (on a low level - I used this for JCuda and JOCL as well). And I cannot say anything about the ~"uncompression logic" (I'd have to spend faaaar more time in the source code for this). But from a high-level, naive perspective: There currently seems to be a command-line functionality in the KTX software that converts a KTX into one or multiple PNG files. And I wondered whether this could, theoretically be implemented in Java, using only the JNI bindings. (I think that there are some functions that are not exposed in the |
@ShukantPal I have to ask for a quick confirmation (actually, for the unit test that is supposed to be added to #876 ) : I assume that the string KTX-Software/interface/java_binding/src/test/java/org/khronos/ktx/test/KtxTestLibraryLoader.java Line 46 in 5414bd0
"ktx-jni" (the name of the DLL that is generated).
Is that correct? Otherwise, I don't really understand the purpose of this class... |
I think on Linux it's libktx-jni.so |
Right, I forgot. That explains it. Depending on whether something like the LibUtils will (have to) be added as part of a Maven release in the context of #624 , this might already cover the functionality of figuring out the actual name of the library ( |
You can pass
The second thing to recognize is that many formats are compressed and we do not have decoders for all of them. Generally they are just uploaded to the GPU in compressed form.
It does not decompress BC1-7 or ETC. Those formats can only be saved to raw files. libktx has functions to obtain pointers to any layer, level or faceSlice in the file from which you can then copy the data.
Is there a Vulkan binding for Java?
Libraries for both GNU/Linux and macOS are named libktx-jni.{so.dylib}. I think this class is used to find the library, via the environment variable |
There are several comments in various places (the issues and PRs that I opened recently - and sorry that this is not more organized, but I just started diving into that, there are many loose ends to tie up). I'll try to keep the response here short, and move some of the more general questions to the #880 where appropriate.
This was a misunderstanding. These
These are all points to keep in mind when I actually try to create this library (on top of the JNI bindings). But this library should initially be stupidly simple, with not much more than these two functions, focussed on ~"converting files" (and not on uploading things like 'half-float' to the GPU or so). I know that for the goal of having such a But... coincidentally, the comment that you casually threw in at #876 (comment) may be an important one here: It sounds like my library could just call
There is, as part of https://www.lwjgl.org/ - for example, https://github.com/LWJGL/lwjgl3/blob/master/modules/samples/src/test/java/org/lwjgl/demo/vulkan/HelloVulkan.java I have not used these Vulkan bindings yet. But for OpenGL, I did ~"mix different JNI libraries" that only communicated via some
Yes, I figured that out in the meantime: By default, and independent of the OS, the tests are run with the installed version of the libraries (by calling But as you said, for tests, it is imortant to be able to refer to the build output, by setting an environment variable like But right now this class assumes that the name of the file starts with
(I'll try to sneak that into one of the upcoming PRs...) |
Indeed. You can follow https://github.com/KhronosGroup/KTX-Software/blob/main/tools/ktx/command_extract.cpp as a model. It does all the things you mention including which input formats it can decompressed, or not. By the way, you should not limit your thinking to 32-bit RGBA pixels. . But right now this class assumes that the name of the file starts with libktx-jni, wheras on Windows, it starts with ktx-jni. So this class does not work on Windows, with the (trivial) fix, in pseudocode That is my analysis too but somehow the tests are working our Windows CI. Best to figure out how before attempting to fix the class. |
I think that just means that the test is run after the actual installation procedure. The installation is putting the binaries into the default installation directory of the build machine and sets up the |
That's right. There were probably a bunch of small mistakes like this in my original implementation, and I'm glad that they are being fixed based on actual usage of the Java bindings! It was hard for me to support Windows fully since I don't develop on Windows. |
@ShukantPal Ideally, this class will not be required (or rather: significantly changed) in the future, because ideally, it should not be necessary to call |
Our CI does not build any CMake install targets. They are only run as dependencies of packaging which sets its own root to install the files in a temporary hierarchy. Perhaps the POM build for the Java target does an install. I don't think that is true though because I can build Java locally without having to do |
About the But whether or not the
Maybe I'll have another look (e.g. at CI build logs). I locally started generalizing the |
The test is run under CMake's |
There are methods for
ktxTexture2_DeflateZstd
(andZLIB
, respectively). They are members of thektxTexture2
class (even though, for whatever reason, they are in somewriter2.c
file...).It looks like these methods are not exposed via the Java
KtxTexture2
class. This means that there does not seem to be a way to apply ZLIB/zstd compression via Java.Should/could these methods be exposed? Or are there any caveats with that, or specific reasons why they should not be exported?
(Otherwise, I might give this a try, pragmatically, following the same patterns as the existing (native) methods in the
KtxTexture2
class...)The text was updated successfully, but these errors were encountered: