[wgpu.image] Workaround WGPU OpenGL heuristics#2259
Merged
hecrj merged 3 commits intoiced-rs:masterfrom Feb 19, 2024
PolyMeilex:wgpu-image-workaround-wgpu-gl-heuristics
Merged
[wgpu.image] Workaround WGPU OpenGL heuristics#2259hecrj merged 3 commits intoiced-rs:masterfrom PolyMeilex:wgpu-image-workaround-wgpu-gl-heuristics
hecrj merged 3 commits intoiced-rs:masterfrom
PolyMeilex:wgpu-image-workaround-wgpu-gl-heuristics
Conversation
Contributor
Author
|
Great, when the amount of layers is a multiple of 6 we will lose images again, as wgpu hard-codes 6 to a cube map 🤦 |
Member
|
@PolyMeilex Looking at the code, if we are hitting the first branch of the |
hecrj
approved these changes
Feb 19, 2024
Member
hecrj
left a comment
There was a problem hiding this comment.
Thank you! Long-standing issues gone 🥳
Comment on lines
+26
to
+33
| pub fn new(device: &wgpu::Device, backend: wgpu::Backend) -> Self { | ||
| let layers = match backend { | ||
| // On the GL backend we start with 2 layers, to help wgpu figure | ||
| // out that this texture is `GL_TEXTURE_2D_ARRAY` rather than `GL_TEXTURE_2D` | ||
| // https://github.com/gfx-rs/wgpu/blob/004e3efe84a320d9331371ed31fa50baa2414911/wgpu-hal/src/gles/mod.rs#L371 | ||
| wgpu::Backend::Gl => vec![Layer::Empty, Layer::Empty], | ||
| _ => vec![Layer::Empty], | ||
| }; |
Member
There was a problem hiding this comment.
Made it so that the additional memory is only allocated when using OpenGL.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
wgpu OpenGL image rendering has been broken for years (every image is a black rectangle), but finally I accumulated enough willpower to debug and fix this.
So, it turns out that wgpu has to use heuristics to guess that the texture we are creating will be used as
TEXTURE_2D_ARRAYrather thanTEXTURE_2D, and OpenGL needs to know that ahead of time, otherwise it will refuse to bind it because of type mismatch.The real fix should be on wgpu side, but that seems to be known and not obvious problem.
So in the meantime, I just increased default layers allocation in the atlas to 2. That way wgpu will see layer depth 2 and correctly assume that we want to use this texture as
TEXTURE_2D_ARRAYEDIT: Found an issue that mentions the array layer limitations: gfx-rs/wgpu#1574
Fixes #1774.
Fixes #2180.