bevyengine / bevyengine/bevy

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

Open
#22,676 4 comments 0 reactions 0 assignees View on GitHub
A-Assets A-Rendering C-Feature S-Needs-Design X-Contentious
Dominant language
Rust
Stars
48.2k
Forks
4.8k
Avg merge
3d 22h
Merged PRs (30d)
161

Description

## 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)~~](https://github.com/bevyengine/bevy/blob/67db8e8f365056d374566f67483eb2900ec755f1/crates/bevy_image/src/ktx2.rs#L221)

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.