-
Notifications
You must be signed in to change notification settings - Fork 963
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 glsl backend errors regarding samplerCubeArrayShadow #5171
Conversation
5799a2f
to
775b2fc
Compare
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 is all very cool!
I feel like this requires a wgpu
downlevel flag, so users can know if GL_EXT_texture_shadow_lod
is allowed and avoid a runtime crash.
Sure, I could do that. But I don't fully understand yet why we would need / want that. We don't have any alternatives to using the extension. If we want users to be able to get better error messages (custom ones instead of what their driver ends up reporting for missing extensions), wouldn't that apply to all our used GL extensions, and be out of scope for this PR? |
The downlevel flag would still be a good idea since there's one case we can't emulate even with EXT_texture_shadow_lod: samplerCubeArrayShadow on textureGrad. |
I kept the backend error that we had before this PR for that case @magcius . What is the behavior you would like to see instead? (with / without the downlevel flag set) |
Thank you for taking a look at this. You're definitely right that the criteria for using the extension / workaround weren't quite perfect yet. There's a conversation to be had here about the exact GL / GLES version requirements of the sampling functions, which currently aren't enforced properly. This is especially problematic since we currently default to GLES 3.1, which lacks some of the features we're using here. While that's potentially out of scope for this PR, I would be willing to work on that.
|
de68635
to
70d203e
Compare
Thanks for sharing the table! The only discrepancy I found was that
The only restrictions from our base of GLSL 1.3 & GLSL ES 3.0 seem to be:
We seem to check for availability of |
glslangValidator v13.1.0 (released on 2023-10-13) added support for @cwfitzgerald do you know how we could get v13.1.0 on CI? |
Installing the vulkan sdk is a good way of getting an up to date copy of the glsl tooling |
#5202 landed; @cmrschwarz could you rebase on top of it to see if the CI failure goes away? |
fa69db1
to
fc44de9
Compare
Demonstration test: wgsl: @group(0) @binding(0) var texture: texture_cube<f32>;
@group(0) @binding(1) var texture_sampler: sampler;
@fragment
fn main() -> @location(0) vec4<f32> {
return textureGather(0, texture, texture_sampler, vec3<f32>(0.0));
} ron: (
glsl: (
writer_flags: (""),
version: Desktop(140),
binding_map: {},
zero_initialize_workgroup_memory: true,
),
) output:
Things that currently require an extension for but don't have to:
Maybe not too really relevant, but we currently don't seem to support GL 1.3, only GL 1.4. I assume that's intended. |
Right, I mistyped, should have been: "We don't seem to check for availability of |
No worries :) Thanks for addressing all the feedback!
Yeah, that sounds the best. |
35dbd9d
to
58f5190
Compare
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 stuff!
Ah, I forgot about the downlevel flag request. Would you be able to add a downlevel flag for the The role of downlevel flags is letting users know what functionality is available before they use it. The presence of all dowlevel flags also signifies that the device implements the WebGPU API fully. |
Oh! When I initially submitted this, I wasn't too familiar with the library, so I was thinking Rust feature flag, not My initial comments regarding this probably didn't make any sense at all 😅 . Sorry for my ignorance. Since this comment thread is getting pretty long, and as the downlevel flag sort of addresses an issue that was present before this PR, I would prefer doing a follow up PR, if thats ok for you guys. |
we will add the downlevel flag in a follow-up PR
hey, would it be possible to cut a new release? Using this PR would be super useful for a personal project of mine. If not, no worries. Hope I'm not bugging yall :) |
* add GL_EXT_texture_shadow_lod feature detection * allow more cases of cube depth texture sampling in glsl * add test for sampling a cubemap array depth texture with lod * add test for chosing GL_EXT_texture_shadow_lod over the grad workaround if instructed * add changelog entry for GL_EXT_texture_shadow_lod * fix criteria for requiring and using TEXTURE_SHADOW_LOD * require gles 320 for textureSampling over cubeArrayShadow * prevent false positives in TEXTURE_SHADOW_LOD in checks * make workaround_lod_with_grad usecase selection less context dependant * move 3d array texture error into the validator * correct ImageSample logic errors
Just landed in 0.19.2 :) |
You guys are awesome |
Connections
Offers a solution for #4455, and the related downstream issues ( see bevyengine/bevy#7320 )
Description
GL's
textureLod
does not support sampling from a cube depth texture with an explicit LOD.This is made significantly worse by the fact that the only way to use wgsl's
textureSampleCompare
fromnon uniform control flow is to use
textureSampleCompareLevel
, which forces us to specify an LOD (0).This currently triggers a backend error that has been observed downstream multiple times,
e.g. breaking bevy's PBR pipeline for the GL backend, and therefore many Intel Graphics Cards.
This PR mostly solves this problem by changing the behavior for this case from a backend error to a
GL feature requirement on GL_EXT_texture_shadow_lod , as was previously suggested by @magcius .
Fortunately, this extension seems to be available on many of the affected devices.
The existing functionality around
workaround_lod_array_shadow_as_grad
is preserved, and preferred over requiring the extension where possible.Some impossible cases still remain (
textureGrad
still doesn't supportsamplerCubeArrayShadow
), but those should be far less common.Testing
A testcase showing the extension working was added in b2ea9fe.
A testcase around overriding the workaround if instructed was added in cd4108f.
Checklist
cargo fmt
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.