Handle invalid shaders
Opened this issue · 4 comments
Issues
Currently invalid shader input would panic at device.create_shader_module
:
Line 280 in 87e36ac
Thus makes the whole program to crash.
The approaches I've tried
- use
device.on_uncaptured_error
to catch it:
Line 48 in 87e36ac
However it would continuously generate errors and block the main thread:
[wgpu_core::present] No work has been submitted for this frame
[wgshadertoy::context] Validation Err
- use
naga
to validate the shader beforehand:
Line 396 in f52e882
Unfortunately there are some times (vec2(0.0, 2.0, 4.0)
etc.) the shader has passed the naga check, but still failed at the same check period inwgpu-core
:
https://github.com/gfx-rs/wgpu/blob/9f82504d8a3b6e234599b19cc35c299bcec8b138/wgpu-core/src/device/mod.rs#L1249
Helps needed
I'm glad to hear useful infomation about how to handle invalid shaders. Thanks a lot!
Currently I skip the naga check, and use error scopes to capture validation error:
22705e4
I had a typo and mine output an error to the terminal and exited... I assume this is the same issue:
[2024-08-17T04:54:06Z ERROR wgshadertoy::core] Validation error: "Validation Error\n\nCaused by:\n In Device::create_shader_module\n note: label = `Shader`\n \nShader 'Shader' parsing error: no definition in scope for identifier: 'cenetered_coord'\n ┌─ wgsl:19:17\n │\n19 │ return vec4(cenetered_coord.x / u.resolution.x, centered_coord.y / u.resolution.y, 0., 1.0);\n │ ^^^^^^^^^^^^^^^ unknown identifier\n\n\n no definition in scope for identifier: 'cenetered_coord'\n"
I had a typo and mine output an error to the terminal and exited... I assume this is the same issue:
[2024-08-17T04:54:06Z ERROR wgshadertoy::core] Validation error: "Validation Error\n\nCaused by:\n In Device::create_shader_module\n note: label = `Shader`\n \nShader 'Shader' parsing error: no definition in scope for identifier: 'cenetered_coord'\n ┌─ wgsl:19:17\n │\n19 │ return vec4(cenetered_coord.x / u.resolution.x, centered_coord.y / u.resolution.y, 0., 1.0);\n │ ^^^^^^^^^^^^^^^ unknown identifier\n\n\n no definition in scope for identifier: 'cenetered_coord'\n"
Looks like the shader is missing the definition for cenetered_coord
Ah yeah, thank you, of course, but the risk of a typo in your code shouldn't be a crash and a loss of all code. I assumed that was what this issue was about.