Skip to content

Replace basis-universal-rs with basisu_c_sys to improve basis universal support#23672

Open
beicause wants to merge 17 commits intobevyengine:mainfrom
beicause:bevy_basisu
Open

Replace basis-universal-rs with basisu_c_sys to improve basis universal support#23672
beicause wants to merge 17 commits intobevyengine:mainfrom
beicause:bevy_basisu

Conversation

@beicause
Copy link
Copy Markdown
Contributor

@beicause beicause commented Apr 5, 2026

Objective

Closes #23597

Solution

  1. Add ASTC HDR to CompressedImageFormats, and ktx2 loader.
  2. Remove basis-universal crate and .basis format support from bevy_image.
  3. Replace CompressedImageSaver with BasisuSaver/BasisUniversalProcessorPlugin asset processor. Enable basis_universal feature to enable loading support. Enable basis_universal_saver feature to enable saver and asset processor.

Testing

basisu_c_sys is tested in https://github.com/beicause/bevy_basisu_loader.

Run with --features basis_universal_saver,asset_processor:

//! Displays a single [`Sprite`], created from an image.

use bevy::image::BasisUniversalProcessorPlugin;
use bevy::prelude::*;

fn main() {
    App::new()
        .add_plugins((
            DefaultPlugins
                .set(bevy::log::LogPlugin {
                    filter: "bevy_image=debug,bevy_asset=debug,wgpu=warn".to_string(),
                    ..Default::default()
                })
                .set(AssetPlugin {
                    mode: AssetMode::Processed,
                    ..Default::default()
                }),
            BasisUniversalProcessorPlugin::default(),
        ))
        .add_systems(Startup, setup)
        .run();
}

fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
    commands.spawn(Camera2d);

    commands.spawn(Sprite::from_image(
        asset_server.load("branding/bevy_bird_dark.png"),
    ));
}

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Rendering Drawing game state to the screen A-Assets Load files from disk to use for things like images, models, and sounds S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Apr 6, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in Assets Apr 6, 2026
@github-project-automation github-project-automation bot moved this to Needs SME Triage in Rendering Apr 6, 2026
@beicause
Copy link
Copy Markdown
Contributor Author

beicause commented Apr 6, 2026

Another option is checking "KTXwriter" key in ktx2 file so that we can support basisu in ktx2_buffer_to_image and don't need a new crate.

Update: Done.

@ChristopherBiscardi
Copy link
Copy Markdown
Contributor

This introduces a dependency on basisu_c_sys, which has only existed for 5 days. Why isn't that also included here to be upstreamed? Do you plan on maintaining it moving forward?

How does this PR impact basisu support in Bevy? ex: does it work on wasm? The file extension required to use basisu is changed by this PR and .basis files seem unsupported. The new module could use documentation, especially since most users are unfamiliar with what basisu is, how to create the files, and what that means for platform support.

There don't seem to be any usage examples or tests. How should someone determine if this code works now and in the future?

@beicause
Copy link
Copy Markdown
Contributor Author

beicause commented Apr 6, 2026

basisu_c_sys depends on the cpp library and the wasm_bindgen bindings to emscripten's prebuilt wasm for web support, so yes.

It includes transcoding and encoding tests in my repository. I expect to maintain it, but I'm willing to transfer it to the bevy organization if bevy wants.

The lack of .basis support is because it's relatively outdated and not supported by the C API.

@beicause beicause changed the title bevy_basis_universal Replace basis-universal-rs with basisu_c_sys to improve basis universal support Apr 6, 2026
@alice-i-cecile alice-i-cecile added X-Contentious There are nontrivial implications that should be thought through D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes labels Apr 6, 2026
@atlv24
Copy link
Copy Markdown
Contributor

atlv24 commented Apr 6, 2026

@cwfitzgerald is working on a texture compression library, he may have something to say

@cwfitzgerald
Copy link
Copy Markdown

cwfitzgerald commented Apr 6, 2026

I don't have much too much of substance to add. I think having up to date bindings would be good and moving to standardized ktx2 files is an improvement over custom basis files. I do plan on adding basis support to ctt, likely through this set of crates, which @JMS55 will integrate with the bevy stack, but that's still a bit out and I'm not sure how that would relate to this PR as this seems to also have tools at runtime.

@alice-i-cecile alice-i-cecile added C-Dependencies A change to the crates that Bevy depends on X-Needs-SME This type of work requires an SME to approve it. and removed X-Contentious There are nontrivial implications that should be thought through labels Apr 6, 2026
@alice-i-cecile
Copy link
Copy Markdown
Member

Note: I've marked this as particularly controversial because it swaps our dependencies out. This is a classic supply chain threat model, so we need to have a careful plan here.

@beicause, this isn't personal to you; you've done fantastic work elsewhere and are rapidly building trust. It's just a matter of policy and best practices.

@beicause
Copy link
Copy Markdown
Contributor Author

beicause commented Apr 8, 2026

I do plan on adding basis support to ctt, likely through this set of crates, which @JMS55 will integrate with the bevy stack, but that's still a bit out and I'm not sure how that would relate to this PR as this seems to also have tools at runtime.

I know #23567 and from what I saw it's a processor for native gpu compressed formats.

I think basisu should be a separate processor as it has different encode params and needs runtime transcoding and wasm32-unknown-unknown shims. So this can be independent.

This introduces a dependency on basisu_c_sys, which has only existed for 5 days. Why isn't that also included here to be upstreamed?

+: I have worked on the basisu binding several months ago and basisu_c_sys is refactored from bevy_basisu_loader_sys. It should not be included here because it has cpp dependency and tens of MB of snapshot in tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Assets Load files from disk to use for things like images, models, and sounds A-Rendering Drawing game state to the screen C-Dependencies A change to the crates that Bevy depends on C-Feature A new feature, making something new possible D-Modest A "normal" level of difficulty; suitable for simple features or challenging fixes S-Needs-Review Needs reviewer attention (from anyone!) to move forward X-Needs-SME This type of work requires an SME to approve it.

Projects

Status: Needs SME Triage
Status: Needs SME Triage

Development

Successfully merging this pull request may close these issues.

Upstream bevy_basisu_loader / use basisu_c_sys

5 participants