-
Notifications
You must be signed in to change notification settings - Fork 237
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
JNI improvements #886
JNI improvements #886
Conversation
# Conflicts: # interface/java_binding/src/test/java/org/khronos/ktx/test/KtxTexture2Test.java
I locally started a few updates, including some basic error handling, so that things like One thing that could/should be done next: The /**
* Destroy the KTX texture and free memory image resources
*
* NOTE: If you try to use a {@link KTXTexture} after it's destroyed, that will cause a segmentation
* fault (the texture pointer is set to NULL).
*/
public native void destroy(); Now, the goal is: No segmentation faults. And we'll probably not be able to completely avoid this I think that trying to use a |
There currently are two functions in the
(The latter has been added as part of this PR) Many libraries that are using JNI expect direct On the Java side, the byte array[] = ...;
t = KtxTexture2.createFromMemory(ByteBuffer.wrap(array), ...); But as a middle-ground, I'd suggest to...
An aside: The documentation of the
This statement is not true, and will be updated accordingly. Remotely related: There currently is a function |
What does "passed data" refer to here? Is it the data at the pointer location that was passed to setImageFromMemory? Not that it matters since you say it isn't true. Indeed the data is copied into the ktxTexture object. |
There are multiple "layers" here, and this revolves exactly about the question where data is copied. Imagine the following Java pseudo code, similar to what could appear in the KTX JNI bindings: byte input[] = new byte[10];
// Create a texture from the input
KtxTexture2 texture = KtxTexture2.createFrom(input);
// XXX Will this affect the result?
input[5] = 123;
// Encode the input data that was given earlier
texture.encode(); The comment suggested that this |
A detail @ShukantPal : Currently, the bindings are set up for Java 11. I don't see a strong reason for that. Unless there is a reason, I'd suggest lowering the version requirement to "the lowest version that works" (and I think that 8 should do it). |
The last sequence of commits are...
The last one appears to be related to the (open) question about how to handle the absence of Visual Studio even points this out: So I changed that check to
|
I think that the build failure should already have been sorted out - right now, it marks some actions as 'failed' because they have been cancelled (maybe because I edited the first post while the build was running?). In doubt, I could push ... "some change" ... to trigger a re-run (because I apparently cannot request a re-run manually). Apart from that, this PR should be 'Ready for review' (which might be short, because intermediate states have already been reviewed and discussed). Miscellaneous:
|
In GitHub Actions when a job in a workflow fails the remaining jobs are cancelled. The VS2019 job in the Windows workflow is failing. I just tried re-running this job but it still fails in the same place: problems creating the Javadoc. I will try rerunning the cancelled jobs. Some of the Linux build jobs are failing for a similar reason. I did not try to re-run them. I'm don't know yet why some macOS jobs are failing. When you add more commits to a PR, existing queued builds are cancelled, running builds may be cancelled. A new build is started for the new commit when an existing job is cancelled or finishes. All this means in this case that the errors remain in the code of the most recent commit because a build was done using it. |
The failures in the Emscripten jobs look to be due to an updated clang in the latest Emscripten Docker image. Research is needed. |
Yup. It appears clang 20 now warns about |
Yes, I didn't dive deeply enough into the travis output for that one. This was caused by a |
Status update. I worked around the new spam warning from clang 20 fixing the Emscripten build but GitHub just deployed a new version of its Windows runner which breaks builds with python due to python-cffi/cffi#117. I don't think I can do anything until a new version of cffi with PR python-cffi/cffi#118 merged is released. There is no way to tell GitHub Actions to use a particular version of the runner otherwise I'd make it use the previous working version. This is incredibly frustrating and is adding to the issues that have stalled successful builds for going on 4 weeks now. I have at least 5 fixes backed up in local branches waiting until CI is unblocked. The time taken to deal with all of this is why I have not completed review of this PR. |
Thanks for the update. I've recently heard about a bunch of trouble in CIs, due to ~"updates of the GitHub Windows/MSVC version". It should really be possible to pinpoint that to a specific version in CI. That reminds me of one thing regarding the JNI that is also related to versioning (mentioned as a side note in an earlier comment ) : Right now, the JNI part assumes Java 11. Unless there is a strong reason to require Java 11, I'd change that to "the lowest version that works" (likely Java 8). However, I assume that this PR will eventually be merged without many modifications (because the current hassle is pretty unrelated to JNI). So I'll probably start addressing things like the Maven issue locally, based on the state of this PR, and ... when the dust has settled here, open a PR for that. |
I reviewed all the recent commits. They look good except that I was expecting you to use the new ktxErrorString function in the I don't understand why you saw the warning or error about "Unchecked lower bound" and we didn't see it in CI and I don't see it in Intellicode in the IDE. We have warning level W4 set and warnings as errors. I have Microsoft Visual Studio Community 2022 Version 17.10.1 VisualStudio.17.Release/17.10.1+34928.147 and Visual C++ 2022 00482-90000-00000-AA364. Anyway thank you for the fix. I think I have found a workaround for the python issue on GitHub. Build in progress. Still having issues with Travis. I am appalled to see this PR has been open for 6 months. Sorry for the loooong delay. |
At this point, it's only a matter of consistency. The
made sense. But if you prefer, I can change it to replace the |
Please merge the latest changes from main, which includes the fix for clang 20 in the Emscripten build. After a successful build this PR will be ready for merge. Please provide a summary of the changes, particularly any breaking changes, that I can use as the commit message and can include in the Release Notes. |
Technically, there is a whole bunch of "breaking changes", because certain parts have nearly been a "rewrite". But as I mentioned earlier: I think that hardly anybody really used the previous state, so it should not cause too much trouble. The build is currently running. I'll try to write a summary of the changes soon. |
I had a short look at the current Java WrapperThere was a larger refactoring of the Java Wrapper, focussing on error handling, documentation, completeness, and usability improvements ( #886 ). This includes several breaking changes. Not all breaking changes can be listed here explicitly. But in all cases, it should be easy for clients to update their code to the new state. The most important changes for the Java Wrapper are:
(Feel free to edit or adjust that (or request changes) as you see fit) An aside: Is there a reason why the
that are not linked, as in
? |
Thanks Marco. Your summary looks good.
Because that information is not in Git. It is only on GitHub. The script that builds the list of commits operates on the Git repo. When you view the Release Notes that have been copied to the Releases section of the GitHub repo GitHub renders the page with links. For some reason when it renders the MarkDown page it does not. I have not been bothered enough by this to spend time seeing if it is possible to update the script to add links. I usually read the release notes in Releases . |
Addresses #880
I know, the title is too generic. It would be better to clearly lay out a work plan and create a clean sequence of self-contained, specific PRs. But there are just too many (unrelated) things to do. "You can't cross a chasm in two small jumps". The first pass has to be tackled somewhat holistically. The result may not be as 'good' as I'd like it to be, but I hope that it will be 'better' along many dimensions. If this is not considered to be a viable approach, then that's OK. Then I'll just create my own repo with JNI bindings for KTX, with blackjack and error handling.
The preliminary task list that I tried to create in the linked issue is now replicated here, and I'll try to update it and extend it as we move on:
CreateFromMemory
stringFor
... methods to convert them to stringsAligned the names of all constants with the native versionAligned the names of constants with the other bindings (see JNI improvements #886 (comment) )
Added documentation and string functions for all constants, except for...
KtxInternalformat
VkFormat
(See Synchronizing auto-generated files with bindings #887 )
NOTES:
ktxTexture2.supercompressionScheme
does not appear in the native documentationKtxPackAstcEncoderMode
are not documented on the native sideKtxTestLibraryLoader
to also work on Windowsenv->GetFieldID(ktx_texture_class, "instance", "J");
are called in each function. ThejfieldID
should be obtained once initially.null
to any method should throw aNullPointerException
.destroy()
was called should throw anIllegalStateException
.create...
methods) now generally throw aKtxException
when the implementation caused an error code that was notKTX_SUCCESS
ktxErrorString
Not (yet) supposed to be addressed here:
Try to find a clean solution for JAR release to Maven Central #624
There are a few cases where we might have to think about how to handle the absence of
unsigned
types in Java. For example, when callingcreateInfo.setBaseWidth(-123); // INVALID!
, then this value is implicitly converted into aktx_uint32_t
.Update the documentation ofdeflateZstd
anddeflateZLIB
EDIT: This was now done as part of Expose supercompression functions via JNI #879, but only for the native side and for the Java bindings (other bindings are still missing the doc update or the functions)
deflateZLIB
function is still missing in the Python binding (and thedeflate*
functions are just about to be added to the Java binding), so ... this may have to be tracked and addressed separatelyImprove thoroughness of
deflate*
tests by comparing the deflated valuesdeflate*
functions should compare the result of inflating the data again to the original input. Theinflate*
methods are not yet exposed (anywhere), so this may have to be deferred for nowAdd test for input swizzling in ASTC
Consider consistent formatting. I know, it's a detail, but just auto-formatting everything with the Eclipse default could already be an improvement. I do have strong preferences for my own projects, but here, the main point is that the formatting should be consistent...
The ktxHash... functionalities are not yet mapped through from the native side.
findKeyValue
,addKVPair
anddeleteKVPair
methods to the ktxTexture2 object rather than exposingktxHashList
.