fralonra/wgshadertoy

Handle invalid shaders

Opened this issue · 4 comments

Issues

Currently invalid shader input would panic at device.create_shader_module:

let fs_module = device.create_shader_module(wgpu::ShaderModuleDescriptor {

Thus makes the whole program to crash.

The approaches I've tried

  • use device.on_uncaptured_error to catch it:
    // device.on_uncaptured_error(|err| {

    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

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.