-
Notifications
You must be signed in to change notification settings - Fork 620
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
Automate compression method detection #1616
Automate compression method detection #1616
Conversation
I left this PR as draft, as people tend to have strong views about building stuff. |
That's really neat! Those functions that detail the compression types are going to be really useful. The automatic generation certainly simplifies adding a compression type, but that doesn't happen very frequently. I wonder whether it might be worth moving |
Thanks for all the suggestions @peterhillman ! I also noticed two CI problems:
|
See CMakeLists.txt for details. Signed-off-by: Philippe Leprince <[email protected]>
Signed-off-by: Philippe Leprince <[email protected]>
Signed-off-by: Philippe Leprince <[email protected]>
suggested by @peterhillman. Signed-off-by: Philippe Leprince <[email protected]>
5e93f23
to
175efde
Compare
Signed-off-by: Philippe Leprince <[email protected]>
@peterhillman Shouldn't I also generate |
Signed-off-by: Philippe Leprince <[email protected]>
Not really: we are using the map to quickly query a compression method's specs in |
@pleprince yes, you did need to generate ImfCRgbaFile too, since that's a pure C wrapper so can't include the C++ files. Speaking of C, the OpenEXRCore implementation would still have hard-coded compression types. If/when the C++ library is reimplemented on top of OpenEXRCore, then all this automatic compression method stuff would disappear, unless it was reimplemented in OpenEXRCore. Doing a similar thing with CMake parsing files also seems possible for OpenEXRCore, but would be easier if there was some refactoring to centralize all compression logic into a single file, to limit the amount of files that CMake has to mess with at configure time. Maybe @kdt3rd has thoughts about that? With IdToDesc, I understood that it's a map indexed by an enum. I was thinking you could make a vector of CompressionDescs, and index it by casting Compression to an unsigned int And regarding bazel and other build systems, it isn't necessary that the files are generated every time CMake is run, since they should be the same for everyone who is building the library. Is there a way to arrange it so library developers can manually run the file generation step using CMake whenever they modify the compression code, and commit the resultant files into the repository? Then only a CMake implementation would be required, no matter what build system is used elsewhere. |
I wonder if the same thing could not be achieved with pure C++ template or macro magic? For instance Mitsuba has a nice If you see code generation as the only option I would go with Python (or C++) (there are IDEs with nice debugging & refactoring support for Python - this is not the case for CMake). We could then run the Python script to update the compressors. The Python script could also be called from a CMake build or a Bazel build, e.g.:
Regarding the Bazel integration - would go with Python here: py_binary(
name = "generate_ImfCompression_h",
srcs = ["generate_ImfCompression_h.py"],
)
genrule(
name = "generate_ImfCompression_h_gen",
outs = ["ImfCompression.h"],
cmd = "./$(location //:generate_ImfCompression_h) > \"$@\"",
tools = ["//:generate_ImfCompression_h"],
)
cc_binary(
name = "OpenEXRDemo",
srcs = [
...
"ImfCompression.h",
],
)
#!/usr/bin/env python3
print("print text that should go into ImfCompression.h") Another option would be to use "pure" Bazel (Starlark) or to include a header that was pre-genreated with CMake. |
Looks like this uses cmake_path which was added in cmake 3.20, but OpenEXR currently requires only v3.12, hence the build failure. Could you possibly provide an alternate implementation? |
@Vertexwahn Note that I had originally written a python script to do this, but realized it was introducing a new build-time dependency. |
Signed-off-by: Philippe Leprince <[email protected]>
Signed-off-by: Philippe Leprince <[email protected]>
Signed-off-by: Philippe Leprince <[email protected]>
… by @cary-ilm. Signed-off-by: Philippe Leprince <[email protected]>
All files are generated during configuration, making them available for bazel. See comments at the top of src/lib/OpenEXR/CMakeLists.txt. Signed-off-by: Philippe Leprince <[email protected]>
I should have addressed all comments now. I will now write some tests for sanity checking. |
I am a bit confused... How do you make a test fail ? |
Typically tests use assert. |
It can not work in release mode: assert() is a macro that evaluates to nothing when NDEBUG is defined. |
Test files all do this:
|
spotted by @peterhillman Signed-off-by: Philippe Leprince <[email protected]>
suggested by @peterhillman. Signed-off-by: Philippe Leprince <[email protected]>
Signed-off-by: Philippe Leprince <[email protected]>
There are a number of other tests that could use the compression API function to enumerate appropriate compression methods:
I also left aside What do you reckon ? |
Suggested by @peterhillman. Signed-off-by: Philippe Leprince <[email protected]>
Signed-off-by: Philippe Leprince <[email protected]>
If the CI passes, I will remove the draft status of this PR. |
An alternative to generating Imath.py could be adding a test that makes sure that the python Compression object is consistent with the C++ types. That way, Imath.py stays freely editable, but a new compression type cannot be added without manually adding it to Imath.py too. The OpenEXRCoreTest is tricky because the Core library itself doesn't have access to the compression API. Again, a test could be generated to confirm the C++ and Core APIs are consistent. Personally I'd be a little wary of changing existing tests: although it's easy to confirm that test still passes after the change, it's harder to confirm it still correctly detects all the same issues the original test did. Perhaps it would be better to update those when new compression types are added. |
This implementation of Imath.py needs to change significantly, so I wouldn't bother with it now. It's a stub substituting for the proper Imath module, but it also contains stuff it shouldn't. Compression types shouldn't appear in Imath. This is part of the ongoing adoption of the openexr python bindings, still in progress. |
Thanks for the feedback @peterhillman and @cary-ilm . |
…n-method-detection
I updated the PR with the latest in |
Hi @peterhillman & @cary-ilm |
@pleprince, we discussed this briefly in the last steering committee meeting. We're concerned that is a fair bit of overhead and additional infrastructure with potential future maintenance burden, all to facilitate something that happens very rarely, since we don't expect to add compression types to the format frequently. It's true that we're contemplating a couple instances of that now, your zstd contribution in particular, but our sense is that we'd actually prefer the more straightforward brute force approach. I appreciate all the careful thought you put into the design. @peterhillman, can you make any further recommendations? |
I think API extensions are definitely worthwhile, providing methods for accessing names for each compression type and whether they are lossy or lossless etc, and we should keep those. The test you added makes it easy to spot a mistake in manually updating files whenever there's a new compression type. |
Fair enough: I will do that. Thanks :-) |
Thanks to @cary-ilm and @peterhillman. Signed-off-by: Philippe Leprince <[email protected]> Fixed: I missed a couple of lines in the CI setup. Signed-off-by: Philippe Leprince <[email protected]> fix whitespace to minimize diff Signed-off-by: Philippe Leprince <[email protected]> fix whitespace to minimize diff Signed-off-by: Philippe Leprince <[email protected]> fix whitespace to minimize diff Signed-off-by: Philippe Leprince <[email protected]>
d961e74
to
bd763ef
Compare
@cary-ilm , @peterhillman, please review. Cheers |
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 good, just a couple of queries
Signed-off-by: Philippe Leprince <[email protected]>
…rom ImfCompressor to ImfCompression. - simplify logic in isLossyCompression and isValidDeepCompression. - additional clarifications in comments / doc strings. Signed-off-by: Philippe Leprince <[email protected]>
If / when this gets merged, I will update the Zstd PR. Cheers |
This looks good, I'll look it over in more detail in a bit but we'll merge it shortly, for the next minor release. Thanks! It would be good to include a comment, maybe at the top of |
I'm going to merge this as is, we can follow up later with further changes as needed. Stating the obvious, but this covers only the C++ API, not OpenEXRCore, which should be kept in sync. |
This change lets cmake generate
ImfCompression.h
andImfCompressor.cpp
based on metadata found in each compressor's header (i.e.ImfRleCompression.h
). One header can declare multiple compressors.exrmaketiled
and displayed in the command-line help.This is a pure cmake implementation (no additional dependency).