-
Notifications
You must be signed in to change notification settings - Fork 659
Add gdeflate compression and decompression with NVIDIA fork of libdeflate. #2153
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
Open
MarkLeone
wants to merge
1
commit into
AcademySoftwareFoundation:main
Choose a base branch
from
MarkLeone:gdeflate
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -202,9 +202,14 @@ endif() | |
| set (ILMTHREAD_USE_TBB ${OPENEXR_USE_TBB}) | ||
|
|
||
| option(OPENEXR_FORCE_INTERNAL_DEFLATE "Force using an internal libdeflate" OFF) | ||
| option(OPENEXR_FORCE_FETCHCONTENT_DEFLATE "Force fetching libdeflate from git repo (NVIDIA fork with gdeflate)" OFF) | ||
| set(OPENEXR_DEFLATE_REPO "https://github.com/NVIDIA/libdeflate.git" CACHE STRING "Git repo for FetchContent libdeflate source") | ||
| set(OPENEXR_DEFLATE_TAG "gdeflate" CACHE STRING "Git tag/branch for FetchContent libdeflate source") | ||
|
|
||
| set (OPENEXR_USE_INTERNAL_DEFLATE OFF) | ||
| set (OPENEXR_USE_FETCHCONTENT_DEFLATE OFF) | ||
|
|
||
| if(NOT OPENEXR_FORCE_INTERNAL_DEFLATE) | ||
| if(NOT OPENEXR_FORCE_INTERNAL_DEFLATE AND NOT OPENEXR_FORCE_FETCHCONTENT_DEFLATE) | ||
| #TODO: ^^ Release should not clone from main, this is a place holder | ||
| set(CMAKE_IGNORE_PATH "${CMAKE_CURRENT_BINARY_DIR}/_deps/deflate-src/config;${CMAKE_CURRENT_BINARY_DIR}/_deps/deflate-build/config") | ||
| # First try cmake config | ||
|
|
@@ -238,6 +243,50 @@ if(EXR_DEFLATE_LIB) | |
| message(STATUS "Using externally provided libdeflate: ${EXR_DEFLATE_VERSION}") | ||
| # For OpenEXR.pc.in for static build | ||
| set(EXR_DEFLATE_PKGCONFIG_REQUIRES "libdeflate >= ${EXR_DEFLATE_VERSION}") | ||
| elseif(OPENEXR_FORCE_FETCHCONTENT_DEFLATE) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Otherwise the check for gdeflate support below doesn't work if both are somehow set to ON. Or have a mechanism (throw an error?) to ensure they're exclusive? |
||
| # Using FetchContent to get NVIDIA fork | ||
| message(STATUS "Fetching libdeflate from ${OPENEXR_DEFLATE_REPO} @ ${OPENEXR_DEFLATE_TAG}") | ||
|
|
||
| include(FetchContent) | ||
| FetchContent_Declare(Deflate | ||
| GIT_REPOSITORY ${OPENEXR_DEFLATE_REPO} | ||
| GIT_TAG ${OPENEXR_DEFLATE_TAG} | ||
| GIT_SHALLOW ON | ||
| ) | ||
|
|
||
| FetchContent_GetProperties(Deflate) | ||
| if(NOT Deflate_POPULATED) | ||
| FetchContent_Populate(Deflate) | ||
| endif() | ||
|
|
||
| # Build libdeflate as an OBJECT library to avoid symbol conflicts | ||
| # OBJECT libraries compile source files but don't create a standalone library, | ||
| # so symbols remain private when linked into OpenEXRCore | ||
| add_library(deflate_internal OBJECT | ||
| ${deflate_SOURCE_DIR}/lib/arm/cpu_features.c | ||
| ${deflate_SOURCE_DIR}/lib/x86/cpu_features.c | ||
| ${deflate_SOURCE_DIR}/lib/utils.c | ||
| ${deflate_SOURCE_DIR}/lib/deflate_compress.c | ||
| ${deflate_SOURCE_DIR}/lib/deflate_decompress.c | ||
| ${deflate_SOURCE_DIR}/lib/adler32.c | ||
| ${deflate_SOURCE_DIR}/lib/gdeflate_compress.c | ||
| ${deflate_SOURCE_DIR}/lib/gdeflate_decompress.c | ||
| ${deflate_SOURCE_DIR}/lib/zlib_compress.c | ||
| ${deflate_SOURCE_DIR}/lib/zlib_decompress.c | ||
| ) | ||
|
|
||
| target_include_directories(deflate_internal PUBLIC ${deflate_SOURCE_DIR}) | ||
|
|
||
| # Hide all symbols by default to prevent conflicts | ||
| set_target_properties(deflate_internal PROPERTIES | ||
| C_VISIBILITY_PRESET hidden | ||
| VISIBILITY_INLINES_HIDDEN YES | ||
| POSITION_INDEPENDENT_CODE ON | ||
| ) | ||
|
|
||
| set(EXR_DEFLATE_LIB deflate_internal) | ||
| set(OPENEXR_USE_FETCHCONTENT_DEFLATE ON) | ||
| message(STATUS "Using FetchContent libdeflate with gdeflate support") | ||
| else() | ||
| # Using internal deflate | ||
| if(OPENEXR_FORCE_INTERNAL_DEFLATE) | ||
|
|
@@ -250,6 +299,41 @@ else() | |
| set(EXR_DEFLATE_LIB) | ||
| endif() | ||
|
|
||
| ####################################### | ||
| # Check for gdeflate support in libdeflate | ||
| ####################################### | ||
|
|
||
| if(OPENEXR_USE_INTERNAL_DEFLATE) | ||
| # Internal libdeflate currently lacks gdeflate support | ||
| set(OPENEXR_ENABLE_GDEFLATE OFF) | ||
| message(STATUS "Using internal libdeflate - gdeflate DISABLED") | ||
| elseif(OPENEXR_USE_FETCHCONTENT_DEFLATE) | ||
| set(OPENEXR_ENABLE_GDEFLATE ON) | ||
| message(STATUS "Using FetchContent libdeflate from NVIDIA fork - gdeflate ENABLED") | ||
| else() | ||
| # Check if external libdeflate has gdeflate support | ||
| include(CheckCSourceCompiles) | ||
| set(CMAKE_REQUIRED_LIBRARIES ${EXR_DEFLATE_LIB}) | ||
| check_c_source_compiles(" | ||
| #include <libdeflate.h> | ||
| int main() { | ||
| struct libdeflate_gdeflate_compressor* c = | ||
| libdeflate_alloc_gdeflate_compressor(1); | ||
| libdeflate_free_gdeflate_compressor(c); | ||
| return 0; | ||
| } | ||
| " HAVE_LIBDEFLATE_GDEFLATE) | ||
| set(CMAKE_REQUIRED_LIBRARIES) | ||
|
|
||
| if(HAVE_LIBDEFLATE_GDEFLATE) | ||
| set(OPENEXR_ENABLE_GDEFLATE ON) | ||
| message(STATUS "External libdeflate has gdeflate support - ENABLED") | ||
| else() | ||
| set(OPENEXR_ENABLE_GDEFLATE OFF) | ||
| message(STATUS "External libdeflate lacks gdeflate support - DISABLED") | ||
| endif() | ||
| endif() | ||
|
|
||
|
|
||
| ####################################### | ||
| # Find or download OpenJPH | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| // | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // Copyright (c) Contributors to the OpenEXR Project. | ||
| // | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| // | ||
| // class GdeflateCompressor | ||
| // | ||
| //----------------------------------------------------------------------------- | ||
|
|
||
| #include "ImfGdeflateCompressor.h" | ||
| #include "OpenEXRConfigInternal.h" | ||
|
|
||
| #ifndef OPENEXR_ENABLE_GDEFLATE | ||
| #include "IexBaseExc.h" | ||
| #endif | ||
|
|
||
| OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_ENTER | ||
|
|
||
| #ifdef OPENEXR_ENABLE_GDEFLATE | ||
|
|
||
| GdeflateCompressor::GdeflateCompressor ( | ||
| const Header& hdr, size_t maxScanLineSize, int numScanLines) | ||
| : Compressor ( | ||
| hdr, | ||
| EXR_COMPRESSION_GDEFLATE, | ||
| maxScanLineSize, | ||
| numScanLines) | ||
| { | ||
| } | ||
|
|
||
| GdeflateCompressor::~GdeflateCompressor () | ||
| { | ||
| } | ||
|
|
||
| #else | ||
|
|
||
| GdeflateCompressor::GdeflateCompressor ( | ||
| const Header& hdr, size_t maxScanLineSize, int numScanLines) | ||
| : Compressor (hdr, EXR_COMPRESSION_LAST_TYPE, maxScanLineSize, numScanLines) | ||
| { | ||
| throw IEX_NAMESPACE::NoImplExc ( | ||
| "Gdeflate support is not enabled in this build of OpenEXR."); | ||
| } | ||
|
|
||
| GdeflateCompressor::~GdeflateCompressor () | ||
| { | ||
| } | ||
|
|
||
| #endif | ||
|
|
||
| OPENEXR_IMF_INTERNAL_NAMESPACE_SOURCE_EXIT | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // Copyright (c) Contributors to the OpenEXR Project. | ||
| // | ||
|
|
||
| #ifndef INCLUDED_IMF_GDEFLATE_COMPRESSOR_H | ||
| #define INCLUDED_IMF_GDEFLATE_COMPRESSOR_H | ||
|
|
||
| //----------------------------------------------------------------------------- | ||
| // | ||
| // class GdeflateCompressor -- performs gdeflate compression | ||
| // | ||
| //----------------------------------------------------------------------------- | ||
|
|
||
| #include "ImfCompressor.h" | ||
|
|
||
| OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_ENTER | ||
|
|
||
| class GdeflateCompressor : public Compressor | ||
| { | ||
| public: | ||
| GdeflateCompressor ( | ||
| const Header& hdr, size_t maxScanLineSize, int numScanLines); | ||
|
|
||
| virtual ~GdeflateCompressor (); | ||
|
|
||
| GdeflateCompressor (const GdeflateCompressor& other) = delete; | ||
| GdeflateCompressor& operator= (const GdeflateCompressor& other) = delete; | ||
| GdeflateCompressor (GdeflateCompressor&& other) = delete; | ||
| GdeflateCompressor& operator= (GdeflateCompressor&& other) = delete; | ||
| }; | ||
|
|
||
| OPENEXR_IMF_INTERNAL_NAMESPACE_HEADER_EXIT | ||
|
|
||
| #endif | ||
|
|
||
|
|
||
|
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
we could have a flag - like in https://github.com/bazelbuild/bazel-central-registry/blob/0040dfca0c14b4eda9e079fb51fde2567c39a8d9/modules/boost.asio/1.89.0/overlay/BUILD.bazel#L5
In boost.asio one can decide to use OpenSSLvs. BoringSLL vs. No SSL support
Untested (inspiered by boost.asio):
Someone who uses OpenEXR (or your CI job) can than add the flag
build --@openexr//:deflate=libdeflate_nv(this could also be added to the .bazelrc)