-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Fix the WebGL 2 backend by giving the visibility_ranges
array a fixed length.
#13210
Fix the WebGL 2 backend by giving the visibility_ranges
array a fixed length.
#13210
Conversation
length. WebGL 2 doesn't support variable-length uniform buffer arrays. Since we never loop over the array in the shader, we don't actually care what the size is, so this is harmless.
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.
Added a suggestion with a comment to explain what you said in the description
@@ -38,7 +38,7 @@ | |||
#if AVAILABLE_STORAGE_BUFFER_BINDINGS >= 6 | |||
@group(0) @binding(12) var<storage> visibility_ranges: array<vec4<f32>>; | |||
#else | |||
@group(0) @binding(12) var<uniform> visibility_ranges: array<vec4<f32>>; | |||
@group(0) @binding(12) var<uniform> visibility_ranges: array<vec4<f32>, 1024u>; |
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.
@group(0) @binding(12) var<uniform> visibility_ranges: array<vec4<f32>, 1024u>; | |
// In WebGL2 we never loop over this array so the size number is not important. We only set it to something so it compiles correctly | |
@group(0) @binding(12) var<uniform> visibility_ranges: array<vec4<f32>, 1024u>; |
I just tested it and it gives me a new error. The error seems to be that arrayLength doesn't work with fixed size uniform buffer array. That's really annoying but a way to avoid this error seems to be to use this ugly hack inside #if AVAILABLE_STORAGE_BUFFER_BINDINGS >= 6
if (visibility_buffer_index > arrayLength(&visibility_ranges)) {
return -16;
}
#else
// In WebGL2 we use a uniform buffer array with a fixed size and this doesn't work with arrayLength()
if (visibility_buffer_index > 1024u) {
return -16;
}
#endif It gets rid of the error but no meshes are visible. I'm not sure if that's expected. |
Weird, on this PR I don't get this error on the 3d_scene example where I encountered the original error, it just seems to work. Which example are you running? |
Ah, yeah, that's when running the visibility_range example. I should have clarified. It still shows the shadows but not the mesh. |
I don't get any error in 3d_scene in webgl2 on main personally. So I didn't realize the error was in another example. |
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.
I don't see the errors that IceSentry is seeing, which is weird, but this definitely fixes it for me.
OK, I was wrong here: WebGL 2 actually does require the size to be exact if you end up using the UBO. So I set the size arbitrarily to 64. This fixes all the issues for me. |
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.
This resolved all the issues for me too.
I'll make a PR to your branch with this suggestion. It's possible to use a const
instead of the hard coded value so we don't have to change it in 2 places. It's not a blocker though. I'd rather get this merged quickly to fix the error. We could even use shader_defs for that I think, but this would require a few more changes because that would be the first case of shader_defs that only exist for the mesh_view_bindings. So definitely out of scope here.
use VISIBILITY_RANGE_UNIFORM_BUFFER_SIZE const
Sure, that sounds good. I merged your PR. |
WebGL 2 doesn't support variable-length uniform buffer arrays. So we arbitrarily set the length of the visibility ranges field to 64 on that platform.