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

[Merged by Bors] - Support array / cubemap / cubemap array textures in KTX2 #5325

Closed
wants to merge 13 commits into from

Conversation

superdump
Copy link
Contributor

@superdump superdump commented Jul 15, 2022

Objective

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.

@superdump superdump added C-Bug An unexpected or incorrect behavior C-Enhancement A new feature A-Rendering Drawing game state to the screen labels Jul 15, 2022
@superdump superdump added this to the Bevy 0.8 milestone Jul 15, 2022
@superdump superdump requested a review from cart July 15, 2022 09:56
@superdump superdump changed the title Ktx2 array cubemap Support array / cubemap / cubemap array textures in KTX2 Jul 15, 2022
@alice-i-cecile
Copy link
Member

Do we have a setup for testing this sort of thing in CI?

@superdump
Copy link
Contributor Author

Do we have a setup for testing this sort of thing in CI?

I want to, for sure. First I need a clean example that exercises the different cases. I currently have a mass of code locally. :)

@alice-i-cecile
Copy link
Member

bors try

bors bot added a commit that referenced this pull request Jul 18, 2022
…ical size

wgpu 0.13 has validation to ensure that the width and height specified for a
texture are both multiples of the respective block width and block height.
Using Extent3d's physical_size() method, that takes a TextureFormat argument,
ensures this.
Uses multiple different compressed texture formats for compatibility.
@superdump
Copy link
Contributor Author

Note that this adds the following textures to the repo:

 669336 assets/textures/Ryfjallet_cubemap.png
1451640 assets/textures/Ryfjallet_cubemap_astc4x4.ktx2
1360022 assets/textures/Ryfjallet_cubemap_bc7.ktx2
 603092 assets/textures/Ryfjallet_cubemap_etc2.ktx2

Cargo.toml Show resolved Hide resolved
Cargo.toml Outdated Show resolved Hide resolved
examples/README.md Outdated Show resolved Hide resolved
Copy link
Member

@alice-i-cecile alice-i-cecile left a comment

Choose a reason for hiding this comment

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

image

Seemingly rendering correctly for me on Windows 10. Colors and stitching are correct. The code itself looks fine from a quality perspective.

  1. We should clean up the example comment, as @mockersf notes.
  2. The camera controls aren't doing anything for me; does it makes sense for non-mouse controls to be enabled here?
  3. I'm getting a stream of warnings in the terminal:

2022-07-21T17:07:48.591226Z WARN bevy_asset::asset_server: no AssetLoader found for the following extension: ktx2
2022-07-21T17:07:51.591514Z INFO skybox: Skipping unsupported format: ("textures/Ryfjallet_cubemap_etc2.ktx2", ETC2)
2022-07-21T17:07:52.141224Z INFO skybox: Swapping to textures/Ryfjallet_cubemap.png...
2022-07-21T17:07:54.590887Z INFO skybox: Skipping unsupported format: ("textures/Ryfjallet_cubemap_astc4x4.ktx2", ASTC_LDR)

@mockersf
Copy link
Member

  1. The camera controls aren't doing anything for me; does it makes sense for non-mouse controls to be enabled here?

That's a skybox, moving the camera shouldn't change it. Maybe placing a cube to show that the camera is moving could be useful?

  1. I'm getting a stream of warnings in the terminal:

2022-07-21T17:07:48.591226Z WARN bevy_asset::asset_server: no AssetLoader found for the following extension: ktx2 2022-07-21T17:07:51.591514Z INFO skybox: Skipping unsupported format: ("textures/Ryfjallet_cubemap_etc2.ktx2", ETC2) 2022-07-21T17:07:52.141224Z INFO skybox: Swapping to textures/Ryfjallet_cubemap.png... 2022-07-21T17:07:54.590887Z INFO skybox: Skipping unsupported format: ("textures/Ryfjallet_cubemap_astc4x4.ktx2", ASTC_LDR)

You're GPU probably doesn't support compressed textures

@superdump
Copy link
Contributor Author

In the version of them example where I had environment mapped reflections, I had the grid of pbr spheres, but I quickly removed them from the example as they don't make sense without the reflections. But something to anchor the view I suppose. Even if it's just the 3d_scene setup. :)

@superdump
Copy link
Contributor Author

There's probably a clearer UX for showing which compressed formats are supported, and which is being used.

@cart cart removed this from the Bevy 0.8 milestone Jul 30, 2022
);
let (num_blocks_x, num_blocks_y) = (
((level_width + block_width_pixels - 1) / block_width_pixels) .max(1),
((level_height + block_height_pixels - 1) / block_height_pixels) .max(1),
Copy link
Contributor

Choose a reason for hiding this comment

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

Division rounding up is used often. Could we abstract this into a local definition of div_ceil until it's available?

Also, maybe NonZeroUsize could help to avoid most of the .max(1) suffixes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea! I was thinking of extracting the rounding code. Some functionality is in wgpu’s texture format description but there are other cases. I’m going to be out today so won’t have time to address this unfortunately.

Copy link
Member

Choose a reason for hiding this comment

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

Given that we're shotgunning this into 0.8 (and rob isn't available to make changes right now), I think this should be done later. Good idea though!

superdump and others added 2 commits July 30, 2022 08:38
Co-authored-by: François <mockersf@gmail.com>
Co-authored-by: François <mockersf@gmail.com>
@cart
Copy link
Member

cart commented Jul 30, 2022

bors r+

bors bot pushed a commit that referenced this pull request Jul 30, 2022
# Objective

- Fix / support KTX2 array / cubemap / cubemap array textures
- Fixes #4495 . Supersedes #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>
@bors bors bot changed the title Support array / cubemap / cubemap array textures in KTX2 [Merged by Bors] - Support array / cubemap / cubemap array textures in KTX2 Jul 30, 2022
@bors bors bot closed this Jul 30, 2022
inodentry pushed a commit to IyesGames/bevy that referenced this pull request 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 pull request 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 pull request 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-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Enhancement A new feature
Projects
Archived in project
Status: Done
Development

Successfully merging this pull request may close these issues.

Unable to load texture array file in ktx2 format
5 participants