Skip to content

Commit

Permalink
gltfpack: Reduce size overhead of Basis encoders
Browse files Browse the repository at this point in the history
Encoders rely on some parts of transcoder source (eg BC7 and UASTC) but
that also includes various formats that add a lot of unnecessary
overhead as we are never going to try to decode into them.

Disabling all of these seems to be safe and saves ~600 KB binary size.
  • Loading branch information
zeux committed Oct 7, 2024
1 parent 2df0a25 commit d1633d0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions gltf/basislib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@
#define BASISU_SUPPORT_SSE 1
#endif

// disable as many transcoder formats as possible to save code size
#define BASISD_SUPPORT_ASTC 0
#define BASISD_SUPPORT_ATC 0
#define BASISD_SUPPORT_BC7_MODE5 0
#define BASISD_SUPPORT_DXT1 0
#define BASISD_SUPPORT_DXT5A 0
#define BASISD_SUPPORT_ETC2_EAC_A8 0
#define BASISD_SUPPORT_ETC2_EAC_RG11 0
#define BASISD_SUPPORT_FXT1 0
#define BASISD_SUPPORT_PVRTC1 0
#define BASISD_SUPPORT_PVRTC2 0

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define NOMINMAX
Expand Down

4 comments on commit d1633d0

@mosra
Copy link
Contributor

@mosra mosra commented on d1633d0 Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, this is what we did in Magnum to remove the png/jpeg/exr/... image loading code (as the we provide all that already elsewhere), feel free to reuse in case you're doing something similar: https://github.com/mosra/magnum-plugins/blob/master/src/external/basis-uncrapifier/image-loading-stubs.cpp

@zeux
Copy link
Owner Author

@zeux zeux commented on d1633d0 Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do need both PNG/JPEG loaders as there's nowhere else to get them from :) it might be useful to go through some more recent changes in Basis and figure out how to trim them, eg they added HDR support which gltfpack doesn't need and that doesn't have a simple way to compile it out, and it's integrated in a way that is not easily strippable by linker.

@mosra
Copy link
Contributor

@mosra mosra commented on d1633d0 Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, alright, sorry -- somehow I thought you were using stb_image in gltfpack already and could just rewire it to feed data into Basis as well.

@zeux
Copy link
Owner Author

@zeux zeux commented on d1633d0 Oct 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no. I briefly explored this as a way to re-encode images but stb_image_write PNG writer is not great, so abandoned this for now. Other than that gltfpack only needs to parse image metadata outside of Basis encoding context, which I just hand-rolled for simplicity.

Please sign in to comment.