Skip to content

KTX2: Selective layer loading for 2D texture arrays (D2Array) #22676

@Farori

Description

@Farori

What problem does this solve or what need does it fill?

Current Bevy KTX2 texture loader loads the entire file into memory, which is inefficient for large KTX2 files containing 2D texture arrays (D2Array). For games or applications with massive texture atlases (e.g., hundreds of layers), this causes high memory usage and long load times, especially on lower-end hardware or when streaming assets.

The KTX2 format supports parsing the header to get layer offsets/sizes, allowing selective reading of a specific layer (e.g., by index) without loading the full file. This enables streaming/on-demand loading for better performance in open-world games or virtual texture systems.

I'm talking about different textures and not specifically mipmaps.

What solution would you like?

Possibility to get a layer from a ktx2 file by indexes.

What alternative(s) have you considered?

In the current version of Bevy (0.18), the optimal ratio is 1 ktx2 file per texture file (with Normal and Roughness, this comes out to 3 files per texture). For several hundred or thousands, this would be something to optimize.

No existing Bevy issues/PRs cover selective layer loading from KTX2.

Additional context

KTX formats: astc | uastc | etc1s(BasisLZ)

Bevy has low-level support for streaming file reading.
One of the optimization options is to store the ktx2 file header in RAM for subsequent retrieval of other d2 textures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-FeatureA new feature, making something new possibleS-Needs-TriageThis issue needs to be labelled

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions