Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load texture array file in ktx2 format #4495

Closed
FishHawk opened this issue Apr 16, 2022 · 3 comments
Closed

Unable to load texture array file in ktx2 format #4495

FishHawk opened this issue Apr 16, 2022 · 3 comments
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-Bug An unexpected or incorrect behavior

Comments

@FishHawk
Copy link

FishHawk commented Apr 16, 2022

Bevy version

0.7.0

Operating system & version

Manjaro

What you did

  • Generate a texture array file in ktx2 format with basisu -ktx2 -uastc -tex_array a.png b.png.
  • Load it with asset_server.load("c.ktx2").

What you expected to happen

Should be loaded successfully.

What actually happened

Runs with an error. Error message:

thread 'main' panicked at 'range end index 1048576 out of range for slice of length 524288', library/core/src/slice/index.rs:73:5
stack backtrace:
   0:     0x7f5da6c9e22d - std::backtrace_rs::backtrace::libunwind::trace::h35daaff92d098ed0
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/../../backtrace/src/backtrace/libunwind.rs:93:5
   1:     0x7f5da6c9e22d - std::backtrace_rs::backtrace::trace_unsynchronized::h2a49b328879f3c62
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5
   2:     0x7f5da6c9e22d - std::sys_common::backtrace::_print_fmt::hbf865a25210831d9
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/sys_common/backtrace.rs:66:5
   3:     0x7f5da6c9e22d - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h320151e111e06ced
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/sys_common/backtrace.rs:45:22
   4:     0x7f5da6cf808c - core::fmt::write::h7413aa28bee1cfbc
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/fmt/mod.rs:1194:17
   5:     0x7f5da6c8f781 - std::io::Write::write_fmt::h0e72b6ed17789afa
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/io/mod.rs:1655:15
   6:     0x7f5da6ca1315 - std::sys_common::backtrace::_print::h983440bc61c2f2c3
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/sys_common/backtrace.rs:48:5
   7:     0x7f5da6ca1315 - std::sys_common::backtrace::print::ha1f03110bb78cc22
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/sys_common/backtrace.rs:35:9
   8:     0x7f5da6ca1315 - std::panicking::default_hook::{{closure}}::heffa35a5a8b52a05
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/panicking.rs:295:22
   9:     0x7f5da6ca0fc9 - std::panicking::default_hook::h7c0cbeac47c399c7
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/panicking.rs:314:9
  10:     0x7f5da6ca19b2 - std::panicking::rust_panic_with_hook::hffbd90fcd9b72f27
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/panicking.rs:698:17
  11:     0x7f5da6ca1897 - std::panicking::begin_panic_handler::{{closure}}::h0f77f2c8e7085cd5
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/panicking.rs:588:13
  12:     0x7f5da6c9e6e4 - std::sys_common::backtrace::__rust_end_short_backtrace::h28c89a19b94c2378
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/sys_common/backtrace.rs:138:18
  13:     0x7f5da6ca15c9 - rust_begin_unwind
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/panicking.rs:584:5
  14:     0x7f5da6c65713 - core::panicking::panic_fmt::h3125391edcfdcf8d
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/panicking.rs:143:14
  15:     0x7f5da6cfa7e6 - core::slice::index::slice_end_index_len_fail_rt::h493a6b5e8024446f
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/slice/index.rs:73:5
  16:     0x7f5da6cedca7 - core::ops::function::FnOnce::call_once::hbaf2e71c84be90d3
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/ops/function.rs:227:5
  17:     0x7f5da6cf3bb6 - core::intrinsics::const_eval_select::h9dc0f307c31ffada
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/intrinsics.rs:2361:5
  18:     0x7f5da6c65826 - core::slice::index::slice_end_index_len_fail::hc8c70d9750178b9f
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/slice/index.rs:67:9
  19:     0x7f5da8c155cd - <core::ops::range::Range<usize> as core::slice::index::SliceIndex<[T]>>::index::h1c16295a0b7953d4
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/slice/index.rs:303:13
  20:     0x7f5da8c155cd - core::slice::index::<impl core::ops::index::Index<I> for [T]>::index::h40ed29ef6e1b0401
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/slice/index.rs:18:9
  21:     0x7f5da8c155cd - <wgpu::Device as wgpu::util::device::DeviceExt>::create_texture_with_data::hc10f537afcaf4a20
                               at /home/xx/.cargo/registry/src/github.com-1ecc6299db9ec823/wgpu-0.12.0/src/util/device.rs:128:22
  22:     0x7f5da87e5903 - bevy_render::renderer::render_device::RenderDevice::create_texture_with_data::haf0edabb37881ed4
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_render/src/renderer/render_device.rs:136:28
  23:     0x7f5da87e5903 - <bevy_render::texture::image::Image as bevy_render::render_asset::RenderAsset>::prepare_asset::hec184748db387b6f
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_render/src/texture/image.rs:562:13
  24:     0x7f5da87f41ad - bevy_render::render_asset::prepare_assets::h20c1da272b880407
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_render/src/render_asset.rs:204:15
  25:     0x7f5da87f41ad - core::ops::function::FnMut::call_mut::hca5c269926e38184
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/ops/function.rs:150:5
  26:     0x7f5da87f41ad - core::ops::function::impls::<impl core::ops::function::FnMut<A> for &mut F>::call_mut::h37f7aadf5974c218
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/ops/function.rs:269:13
  27:     0x7f5da87ee823 - <Func as bevy_ecs::system::function_system::SystemParamFunction<(),Out,(F0,F1,F2,F3),()>>::run::call_inner::hda28a3fd465d2d5b
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_ecs/src/system/function_system.rs:525:21
  28:     0x7f5da87ee823 - <Func as bevy_ecs::system::function_system::SystemParamFunction<(),Out,(F0,F1,F2,F3),()>>::run::h6f12cf377d89591d
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_ecs/src/system/function_system.rs:528:17
  29:     0x7f5da87ee823 - <bevy_ecs::system::function_system::FunctionSystem<In,Out,Param,Marker,F> as bevy_ecs::system::system::System>::run_unsafe::h88dfd0228f2d6253
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_ecs/src/system/function_system.rs:399:19
  30:     0x7f5da93fa32c - bevy_ecs::schedule::executor_parallel::ParallelExecutor::prepare_systems::{{closure}}::hb1e0b85206b2b3af
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_ecs/src/schedule/executor_parallel.rs:196:30
  31:     0x7f5da93fa32c - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::ha573c00f34cc3604
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/future/mod.rs:91:19
  32:     0x7f5da93f9197 - async_executor::Executor::spawn::{{closure}}::h648cdeeb5c07e365
                               at /home/xx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-executor-1.4.1/src/lib.rs:144:19
  33:     0x7f5da93f9197 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h1461d3b0911659ba
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/future/mod.rs:91:19
  34:     0x7f5da93d3813 - async_task::raw::RawTask<F,T,S>::run::h1ad8bb31029f65b0
                               at /home/xx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-task-4.2.0/src/raw.rs:489:20
  35:     0x7f5da940a502 - async_executor::Executor::try_tick::h7cee8d4246ccd0d8
                               at /home/xx/.cargo/registry/src/github.com-1ecc6299db9ec823/async-executor-1.4.1/src/lib.rs:181:17
  36:     0x7f5da93b3f2f - bevy_tasks::task_pool::TaskPool::scope::{{closure}}::h8e81370706d56001
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_tasks/src/task_pool.rs:233:21
  37:     0x7f5da93b3f2f - std::thread::local::LocalKey<T>::try_with::ha8218cc8c428d9db
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/thread/local.rs:442:16
  38:     0x7f5da93b3f2f - std::thread::local::LocalKey<T>::with::h85904f7b5dba493c
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/thread/local.rs:418:9
  39:     0x7f5da93b3f2f - bevy_tasks::task_pool::TaskPool::scope::hfe5ab490cd8aa28c
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_tasks/src/task_pool.rs:180:9
  40:     0x7f5da93caa77 - <bevy_ecs::schedule::executor_parallel::ParallelExecutor as bevy_ecs::schedule::executor::ParallelSystemExecutor>::run_systems::hbcc5d740ffd92969
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_ecs/src/schedule/executor_parallel.rs:129:9
  41:     0x7f5da93eafce - <bevy_ecs::schedule::stage::SystemStage as bevy_ecs::schedule::stage::Stage>::run::hc803f9c28caebcf9
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_ecs/src/schedule/stage.rs:852:17
  42:     0x7f5da88592d9 - <bevy_render::RenderPlugin as bevy_app::plugin::Plugin>::build::{{closure}}::h58305ed0962b3ecc
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_render/src/lib.rs:223:21
  43:     0x7f5da9394beb - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::hc2ed313b19b549c2
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/alloc/src/boxed.rs:1875:9
  44:     0x7f5da9394beb - bevy_app::app::App::update::hd97233e3642e4d9a
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_app/src/app.rs:116:13
  45:     0x7f5da7e48d22 - bevy_winit::winit_runner_with::{{closure}}::ha084ea67d2dfbd92
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_winit/src/lib.rs:563:21
  46:     0x7f5da7e65a4a - winit::platform_impl::platform::sticky_exit_callback::h02eb27666407f278
                               at /home/xx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/linux/mod.rs:753:5
  47:     0x7f5da7e65a4a - winit::platform_impl::platform::x11::EventLoop<T>::run_return::hee3f2a971f3ebf6d
                               at /home/xx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/linux/x11/mod.rs:293:17
  48:     0x7f5da7e662a9 - winit::platform_impl::platform::x11::EventLoop<T>::run::h85db1368f53af0af
                               at /home/xx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/linux/x11/mod.rs:392:9
  49:     0x7f5da7e475ec - winit::platform_impl::platform::EventLoop<T>::run::h7508ed602940ab86
                               at /home/xx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/platform_impl/linux/mod.rs:669:56
  50:     0x7f5da7e7df2c - winit::event_loop::EventLoop<T>::run::hced646a0f709b419
                               at /home/xx/.cargo/registry/src/github.com-1ecc6299db9ec823/winit-0.26.1/src/event_loop.rs:154:9
  51:     0x7f5da7e819cc - bevy_winit::run::h3acda91c35d44236
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_winit/src/lib.rs:180:5
  52:     0x7f5da7e8251d - bevy_winit::winit_runner_with::hea76666e4a434fb4
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_winit/src/lib.rs:604:9
  53:     0x7f5da7e62a24 - bevy_winit::winit_runner::h7f1605361358c9d8
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_winit/src/lib.rs:220:5
  54:     0x7f5da7e62a24 - core::ops::function::Fn::call::h3910591a8bdab206
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/ops/function.rs:70:5
  55:     0x7f5da9394ded - <alloc::boxed::Box<F,A> as core::ops::function::Fn<Args>>::call::h6ca520cec3b7d023
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/alloc/src/boxed.rs:1875:9
  56:     0x7f5da9394ded - bevy_app::app::App::run::hf40b1a61b61ba258
                               at /home/xx/.cargo/git/checkouts/bevy-f7ffde730c324c74/83c6ffb/crates/bevy_app/src/app.rs:130:9
  57:     0x557d44808785 - deep::main::h7b88112f51499135
                               at /home/xx/Projects/deep/src/main.rs:13:5
  58:     0x557d448275c3 - core::ops::function::FnOnce::call_once::h8fdcc299ac68ce09
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/ops/function.rs:227:5
  59:     0x557d448275c3 - std::sys_common::backtrace::__rust_begin_short_backtrace::hb8a24fd5cb209aca
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/sys_common/backtrace.rs:122:18
  60:     0x557d4481e9e9 - std::rt::lang_start::{{closure}}::hfe6efb8e3e3c1e3f
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/rt.rs:145:18
  61:     0x7f5da6c7ffbe - core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once::h5c071915d75cd829
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/core/src/ops/function.rs:259:13
  62:     0x7f5da6c7ffbe - std::panicking::try::do_call::h08843c3ac1a8e5a3
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/panicking.rs:492:40
  63:     0x7f5da6c7ffbe - std::panicking::try::h4bd4483e759d3fb2
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/panicking.rs:456:19
  64:     0x7f5da6c7ffbe - std::panic::catch_unwind::h95c3030cb73fa2c8
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/panic.rs:137:14
  65:     0x7f5da6c7ffbe - std::rt::lang_start_internal::{{closure}}::hb916b8f5e47e7d77
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/rt.rs:128:48
  66:     0x7f5da6c7ffbe - std::panicking::try::do_call::h2626835d15a1ba22
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/panicking.rs:492:40
  67:     0x7f5da6c7ffbe - std::panicking::try::h553a474c5bf334b2
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/panicking.rs:456:19
  68:     0x7f5da6c7ffbe - std::panic::catch_unwind::h349dcbfb0acf7e28
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/panic.rs:137:14
  69:     0x7f5da6c7ffbe - std::rt::lang_start_internal::hc61e09f23af3880d
                               at /rustc/6af09d2505f38e4f1df291df56d497fb2ad935ed/library/std/src/rt.rs:128:20
  70:     0x557d44808ed8 - main
  71:     0x7f5da6a23310 - __libc_start_call_main
  72:     0x7f5da6a233c1 - __libc_start_main@GLIBC_2.2.5
  73:     0x557d44806075 - _start
  74:                0x0 - <unknown>

Additional information

When using basisu -ktx2 -uastc -tex_array a.png to generate a texture array which contains only 1 image, it can be loaded successfully. Also, the same images can be loaded using basis.

The ktx2 file used:
stack.zip

@FishHawk FishHawk added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels Apr 16, 2022
@alice-i-cecile alice-i-cecile added A-Assets Load files from disk to use for things like images, models, and sounds and removed S-Needs-Triage This issue needs to be labelled labels Apr 16, 2022
@alice-i-cecile
Copy link
Member

Are you able to link to / upload the asset? It's much easier to debug these with the file available to test with.

@FishHawk
Copy link
Author

Are you able to link to / upload the asset? It's much easier to debug these with the file available to test with.

OK, I have uploaded it.

@superdump superdump added the A-Rendering Drawing game state to the screen label Apr 16, 2022
@superdump
Copy link
Contributor

This should be fixed in #4514. I had to do a bit of hacking to test it, but I did test it. :) Thanks for the bug report and particularly for uploading the problematic texture. That was a big help in fixing the bug!

@bors bors bot closed this as completed in 05e5008 Jul 30, 2022
inodentry pushed a commit to IyesGames/bevy that referenced this issue Aug 8, 2022
…5325)

# Objective

- Fix / support KTX2 array / cubemap / cubemap array textures
- Fixes bevyengine#4495 . Supersedes bevyengine#4514 .

## Solution

- Add `Option<TextureViewDescriptor>` to `Image` to enable configuration of the `TextureViewDimension` of a texture.
  - This allows users to set `D2Array`, `D3`, `Cube`, `CubeArray` or whatever they need
  - Automatically configure this when loading KTX2
- Transcode all layers and faces instead of just one
- Use the UASTC block size of 128 bits, and the number of blocks in x/y for a given mip level in order to determine the offset of the layer and face within the KTX2 mip level data
- `wgpu` wants data ordered as layer 0 mip 0..n, layer 1 mip 0..n, etc. See https://docs.rs/wgpu/latest/wgpu/util/trait.DeviceExt.html#tymethod.create_texture_with_data
- Reorder the data KTX2 mip X layer Y face Z to `wgpu` layer Y face Z mip X order
- Add a `skybox` example to demonstrate / test loading cubemaps from PNG and KTX2, including ASTC 4x4, BC7, and ETC2 compression for support everywhere. Note that you need to enable the `ktx2,zstd` features to be able to load the compressed textures.

---

## Changelog

- Fixed: KTX2 array / cubemap / cubemap array textures
- Fixes: Validation failure for compressed textures stored in KTX2 where the width/height are not a multiple of the block dimensions.
- Added: `Image` now has an `Option<TextureViewDescriptor>` field to enable configuration of the texture view. This is useful for configuring the `TextureViewDimension` when it is not just a plain 2D texture and the loader could/did not identify what it should be.

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
james7132 pushed a commit to james7132/bevy that referenced this issue Oct 28, 2022
…5325)

# Objective

- Fix / support KTX2 array / cubemap / cubemap array textures
- Fixes bevyengine#4495 . Supersedes bevyengine#4514 .

## Solution

- Add `Option<TextureViewDescriptor>` to `Image` to enable configuration of the `TextureViewDimension` of a texture.
  - This allows users to set `D2Array`, `D3`, `Cube`, `CubeArray` or whatever they need
  - Automatically configure this when loading KTX2
- Transcode all layers and faces instead of just one
- Use the UASTC block size of 128 bits, and the number of blocks in x/y for a given mip level in order to determine the offset of the layer and face within the KTX2 mip level data
- `wgpu` wants data ordered as layer 0 mip 0..n, layer 1 mip 0..n, etc. See https://docs.rs/wgpu/latest/wgpu/util/trait.DeviceExt.html#tymethod.create_texture_with_data
- Reorder the data KTX2 mip X layer Y face Z to `wgpu` layer Y face Z mip X order
- Add a `skybox` example to demonstrate / test loading cubemaps from PNG and KTX2, including ASTC 4x4, BC7, and ETC2 compression for support everywhere. Note that you need to enable the `ktx2,zstd` features to be able to load the compressed textures.

---

## Changelog

- Fixed: KTX2 array / cubemap / cubemap array textures
- Fixes: Validation failure for compressed textures stored in KTX2 where the width/height are not a multiple of the block dimensions.
- Added: `Image` now has an `Option<TextureViewDescriptor>` field to enable configuration of the texture view. This is useful for configuring the `TextureViewDimension` when it is not just a plain 2D texture and the loader could/did not identify what it should be.

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
ItsDoot pushed a commit to ItsDoot/bevy that referenced this issue Feb 1, 2023
…5325)

# Objective

- Fix / support KTX2 array / cubemap / cubemap array textures
- Fixes bevyengine#4495 . Supersedes bevyengine#4514 .

## Solution

- Add `Option<TextureViewDescriptor>` to `Image` to enable configuration of the `TextureViewDimension` of a texture.
  - This allows users to set `D2Array`, `D3`, `Cube`, `CubeArray` or whatever they need
  - Automatically configure this when loading KTX2
- Transcode all layers and faces instead of just one
- Use the UASTC block size of 128 bits, and the number of blocks in x/y for a given mip level in order to determine the offset of the layer and face within the KTX2 mip level data
- `wgpu` wants data ordered as layer 0 mip 0..n, layer 1 mip 0..n, etc. See https://docs.rs/wgpu/latest/wgpu/util/trait.DeviceExt.html#tymethod.create_texture_with_data
- Reorder the data KTX2 mip X layer Y face Z to `wgpu` layer Y face Z mip X order
- Add a `skybox` example to demonstrate / test loading cubemaps from PNG and KTX2, including ASTC 4x4, BC7, and ETC2 compression for support everywhere. Note that you need to enable the `ktx2,zstd` features to be able to load the compressed textures.

---

## Changelog

- Fixed: KTX2 array / cubemap / cubemap array textures
- Fixes: Validation failure for compressed textures stored in KTX2 where the width/height are not a multiple of the block dimensions.
- Added: `Image` now has an `Option<TextureViewDescriptor>` field to enable configuration of the texture view. This is useful for configuring the `TextureViewDimension` when it is not just a plain 2D texture and the loader could/did not identify what it should be.

Co-authored-by: Carter Anderson <mcanders1@gmail.com>
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-Bug An unexpected or incorrect behavior
Projects
Status: Done
3 participants