Add TextureFormat::srgb_view_formats#9435
Conversation
|
It would be nice if we could do away with this use of Getting rid of it in wgpu doesn't look too bad: d261c07 But it is more complicated in Bevy because the texture descriptor structure is used in various places in various ways. |
This actually isn't true, see See also this piece of code in my tests |
cwfitzgerald
left a comment
There was a problem hiding this comment.
Bleh this is annoying that we need it.
| /// Returns the srgb view formats if the format has an srgb variant, otherwise returns an empty slice. | ||
| /// | ||
| /// The return result covers all the results of [`TextureFormat::add_srgb_suffix`]. | ||
| pub fn srgb_view_formats(&self) -> &'static [TextureFormat] { |
There was a problem hiding this comment.
Could we just get a test to make sure this matches add_srgb_suffix
|
Then what about Actually I think changing it to use smallvec on the bevy side is also good. |
|
I proposed changes in bevy bevyengine/bevy#24056 |
Description
Bevy needs this functionality because of
TextureDescriptor::view_formatstaking a&'static [TextureFormat]:https://github.com/bevyengine/bevy/blob/2d39c4f8e4cdd021881d0bba1ab4dd174d6db0ab/crates/bevy_image/src/image.rs#L57
https://github.com/bevyengine/bevy/blob/2d39c4f8e4cdd021881d0bba1ab4dd174d6db0ab/crates/bevy_image/src/image.rs#L1267
We don't need exactly this, we could do a more straightforward
TextureFormat -> &[TextureFormat]function that doesnt add srgb, and combine it with the existing add_srgb_suffix, but that ends up being 400 lines of code and not really more useful: view_formats only allows diverging from the actual texture format by srgb suffix. The only other argument in favor of it is that it would be an exhaustive implementation, which would ensure that when new TextureFormats are added the function must be updated. If this is preferred I can PR that instead. Either way, it just feels wrong for this code to live in bevy, as it is paving over a wgpu api deficiency and likely will be needed by other wgpu users.Testing
Its been in use in bevy for a while.
Squash or Rebase?
Squash
Checklist
cargo fmt.taplo format.cargo clippy --tests. If applicable, add:--target wasm32-unknown-unknowncargo xtask testto run tests.CHANGELOG.mdentry.