-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
[Merged by Bors] - Support array / cubemap / cubemap array textures in KTX2 #5325
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
Conversation
This allows configuration of custom TextureViewDimension for cubemaps, etc.
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. :) |
bors try |
…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.
Note that this adds the following textures to the repo:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seemingly rendering correctly for me on Windows 10. Colors and stitching are correct. The code itself looks fine from a quality perspective.
- We should clean up the example comment, as @mockersf notes.
- The camera controls aren't doing anything for me; does it makes sense for non-mouse controls to be enabled here?
- 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)
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?
You're GPU probably doesn't support compressed textures |
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. :) |
There's probably a clearer UX for showing which compressed formats are supported, and which is being used. |
); | ||
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), |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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!
Co-authored-by: François <mockersf@gmail.com>
Co-authored-by: François <mockersf@gmail.com>
bors r+ |
# 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>
Pull request successfully merged into main. Build succeeded: |
…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>
…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>
…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>
Objective
Solution
Option<TextureViewDescriptor>
toImage
to enable configuration of theTextureViewDimension
of a texture.D2Array
,D3
,Cube
,CubeArray
or whatever they needwgpu
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_datawgpu
layer Y face Z mip X orderskybox
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 thektx2,zstd
features to be able to load the compressed textures.Changelog
Image
now has anOption<TextureViewDescriptor>
field to enable configuration of the texture view. This is useful for configuring theTextureViewDimension
when it is not just a plain 2D texture and the loader could/did not identify what it should be.