Open fralonra opened 1 year ago
Currently invalid shader input would panic at device.create_shader_module: https://github.com/fralonra/wgshadertoy/blob/87e36ac295b9c02f4c0e6dd1dc31231fa549ad59/src/runtime.rs#L280 Thus makes the whole program to crash.
device.create_shader_module
use device.on_uncaptured_error to catch it: https://github.com/fralonra/wgshadertoy/blob/87e36ac295b9c02f4c0e6dd1dc31231fa549ad59/src/context.rs#L48 However it would continuously generate errors and block the main thread:
device.on_uncaptured_error
[wgpu_core::present] No work has been submitted for this frame [wgshadertoy::context] Validation Err
use naga to validate the shader beforehand: https://github.com/fralonra/wgshadertoy/blob/f52e882d520b7896109119e1ad43846e61ca64b7/src/runtime.rs#L396 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 in wgpu-core: https://github.com/gfx-rs/wgpu/blob/9f82504d8a3b6e234599b19cc35c299bcec8b138/wgpu-core/src/device/mod.rs#L1249
naga
vec2(0.0, 2.0, 4.0)
wgpu-core
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: https://github.com/fralonra/wgshadertoy/commit/22705e420e78d3e22a2728a8d6a35c84817244b6
Issues
Currently invalid shader input would panic at
device.create_shader_module
: https://github.com/fralonra/wgshadertoy/blob/87e36ac295b9c02f4c0e6dd1dc31231fa549ad59/src/runtime.rs#L280 Thus makes the whole program to crash.The approaches I've tried
use
device.on_uncaptured_error
to catch it: https://github.com/fralonra/wgshadertoy/blob/87e36ac295b9c02f4c0e6dd1dc31231fa549ad59/src/context.rs#L48 However it would continuously generate errors and block the main thread:use
naga
to validate the shader beforehand: https://github.com/fralonra/wgshadertoy/blob/f52e882d520b7896109119e1ad43846e61ca64b7/src/runtime.rs#L396 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#L1249Helps needed
I'm glad to hear useful infomation about how to handle invalid shaders. Thanks a lot!