Skip to content

Basis Compression Tool#1290

Merged
erikwijmans merged 20 commits intomasterfrom
basis
Jun 11, 2021
Merged

Basis Compression Tool#1290
erikwijmans merged 20 commits intomasterfrom
basis

Conversation

@erikwijmans
Copy link
Copy Markdown
Contributor

Motivation and Context

  • Add a tool to create basis compressed basis GLBs
  • Compile the basis compressor, conditionally
  • Add support for using cmake from pip install cmake that way people can easily get a more recent version of cmake as compiling requires a newer version

Testing

Compressing various datasets!

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Jun 3, 2021
@Skylion007
Copy link
Copy Markdown
Contributor

@erikwijmans Are we still against making Basis a submodule? Because now we are adding quite a few files.

Comment thread tools/create_basis_compressed_glbs.py Outdated
@erikwijmans
Copy link
Copy Markdown
Contributor Author

I don't have a strong preference against a submodule, but that repo does have a lot of extra stuff that we aren't using

Comment thread src/deps/basis-universal/basisu.sln Outdated
Copy link
Copy Markdown
Contributor

@jturner65 jturner65 left a comment

Choose a reason for hiding this comment

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

I would think a submodule would be preferable for future support and bug fixes.

@aclegg3
Copy link
Copy Markdown
Contributor

aclegg3 commented Jun 3, 2021

Thanks for packaging this up and publishing it here, @erikwijmans. Should be very useful for all of us and the community to have an easy way to do this conversion!

I agree with other comments that it would be best to avoid pulling all of this code into Habitat-sim if we can find another way (dependency or submodule) to do so.

@erikwijmans
Copy link
Copy Markdown
Contributor Author

erikwijmans commented Jun 3, 2021

The download for the basis git repo is ~200 MB, which is 100x larger than taking just what we need (I had forgotten just how big that repo's history is). I pushed the submodule so just an FYI

@Skylion007
Copy link
Copy Markdown
Contributor

200mb is not unreasonable for a submodule, and similar to the size of some other submodules we have like Bullet. I vote to keep it as submodule for easy upgrades, bugfixes, etc.

@Skylion007
Copy link
Copy Markdown
Contributor

If we are worried about this being cloned a lot even when it's a relatively rarely used submodule, we could make a CMAKE external project: https://cmake.org/cmake/help/git-stage/module/ExternalProject.html

@erikwijmans
Copy link
Copy Markdown
Contributor Author

That's a new 3.20 feature and pretty buggy from what I've heard

@Skylion007
Copy link
Copy Markdown
Contributor

My vote remains keeping it in as a submodule.

@mosra
Copy link
Copy Markdown
Contributor

mosra commented Jun 5, 2021

I vote for including just the files, as you did originally, especially since this dependency is not needed for 90% users (unlike Bullet or Assimp). Updating it would mean just replacing the files, I see no problem there (this is how I do it for Homebrew and Arch packages already anyway) -- it's actually more likely that I would need to apply manual patches to get rid of various silly warnings, and a submodule makes that harder.

Basis has a "I hate Git"-style maintenance and that they don't care doesn't mean we should be careless too ;) Bundling it as a submodule would also act as a dangerous precedent for other dependencies ("hey, it's fine to bundle this gigabyte dataset, the other submodules are 500 MB already anyway") 😝

Copy link
Copy Markdown
Contributor

@mosra mosra left a comment

Choose a reason for hiding this comment

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

About the submodule, see my comment above :)

Comment thread src/CMakeLists.txt Outdated
Comment thread src/CMakeLists.txt Outdated
Comment thread src/cmake/dependencies.cmake Outdated
@erikwijmans
Copy link
Copy Markdown
Contributor Author

@aclegg3 @jturner65 @Skylion007 -- Mosra made some good points wrt. keeping things as files instead of a submodule. It also doesn't seem like basis is keeping their API very stable (they are changing functions, args, etc) so upgrading likely isn't trivial.

@mosra
Copy link
Copy Markdown
Contributor

mosra commented Jun 7, 2021

doesn't seem like basis is keeping their API very stable

Yeah, one reason why Magnum is still stuck on the pre-UASTC version of Basis (and backporting various patches to it). The APIs changed significantly since, certain things that worked previously are crashing now and I didn't find the courage to look into the changes yet.

@jturner65
Copy link
Copy Markdown
Contributor

doesn't seem like basis is keeping their API very stable

Yeah, one reason why Magnum is still stuck on the pre-UASTC version of Basis (and backporting various patches to it). The APIs changed significantly since, certain things that worked previously are crashing now and I didn't find the courage to look into the changes yet.

Is there a way we could access this functionality through Magnum?

@mosra
Copy link
Copy Markdown
Contributor

mosra commented Jun 7, 2021

What do you mean? The functionality is exposed and used through Magnum's BasisImporter and BasisImageConverter plugins, yes. (But not the glTF repacking part because that waits on the SceneData APIs and a glTF exporter being done, so there's a python script doing that instead.)

Copy link
Copy Markdown
Contributor

@eundersander eundersander left a comment

Choose a reason for hiding this comment

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

LGTM. I left some minor comments.

I don't have a strong opinion on submodule versus duplicated files. I do wish there was a workflow for "optional submodules". 90% of Hab users will never use this. Similarly, 90% of Hab users will never use our VHACD functionality. I wish a user could just init/clone specific submodules as needed.

Comment thread tools/create_basis_compressed_glbs.py Outdated

IMAGE_CONVERTER = osp.realpath(
osp.join(
osp.dirname(__file__), "..", "build/utils/imageconverter/magnum-imageconverter"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In my experience using this script, I have to locally modify here because I don't usually name my build directory "build". It would be nice to offer a friendly error message like "build directory not found" for users like me.

Comment thread tools/create_basis_compressed_glbs.py Outdated
def convert_image_to_basis(img: str) -> None:
basis_img = img_name_to_basis(img)

settings = "threads=4,mip_gen=true,compression_level=2"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's compression_level? Can we document here? Is this an interesting choice for the user?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Basis doesn't document it with anything more descriptive than "the overall effort the compressor uses on a 1-5 scale". I'll expose it, but there isn't a great rule of thumb for setting it when you can't manually verify if there are compression artifacts (higher may reduce them). I just put its as high as I could while still keeping things to a reasonable amount of time and checked a few meshes for artifacts.

@mosra
Copy link
Copy Markdown
Contributor

mosra commented Jun 9, 2021

I wish a user could just init/clone specific submodules as needed.

There is a way, but as far as i know, it's not possible for the repo itself to specify that (would be great if it could be said in .gitmodules), the users have to know what submodules they want and what not, which isn't really user-friendly. This is what I use locally -- as I have system-wide Assimp, GLFW, Bullet, Magnum, Eigen... installation, instead of git submodule update --init I init just the modules that are actually used:

cd src/deps
git submodule init glog
git submodule init googletest
git submodule init imgui
git submodule init recastnavigation
git submodule init Sophus
git submodule init tinyobjloader
git submodule init tinyxml2
git submodule init v-hacd
git submodule update # clones / fetches only the submodules that were init'd

@erikwijmans
Copy link
Copy Markdown
Contributor Author

I switched back to just including the files since upgrading basis is a more involved process than just changing a commit, so we don't get the biggest benefit of a submodule but get all its downsides.

Copy link
Copy Markdown
Contributor

@mosra mosra left a comment

Choose a reason for hiding this comment

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

The basisu_tool.cpp doesn't need to be included, as that's just the source of their basisu console tool, which the plugin doesn't use in any way. For the record, here's the set of cpp files Magnum uses, I think all other files besides this one are needed.

Besides that, this looks good to me :)

@erikwijmans
Copy link
Copy Markdown
Contributor Author

Ah darn. I found that source list and I thought I had removed everything that wasn't needed. Thanks for the catch!

@erikwijmans erikwijmans merged commit 395cabe into master Jun 11, 2021
@erikwijmans erikwijmans deleted the basis branch June 11, 2021 14:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Do not delete this pull request or issue due to inactivity.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants