Skip to content
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

[glsl-in] switch case using const int causes downstream panic #4644

Closed
Vipitis opened this issue Nov 6, 2023 · 2 comments
Closed

[glsl-in] switch case using const int causes downstream panic #4644

Vipitis opened this issue Nov 6, 2023 · 2 comments
Labels
area: naga front-end lang: GLSL OpenGL Shading Language naga Shader Translator type: enhancement New feature or request

Comments

@Vipitis
Copy link

Vipitis commented Nov 6, 2023

Description
Using switch/case in GLSL requires the use of integers. See this minimal example on Shadertoy: https://www.shadertoy.com/view/DtccWr

  1. This version is allowed but panics.
const int ID_left = 0;
const int ID_right = 1;

[...]

switch(side) {
    case ID_left:
    {
        col *= 4.0;
    }
    case ID_right:
    {
        col *= 2.0;
    }
}
  1. Equivalent version that is allowed and works with wgpu.
switch(side) {
    case 0:
    {
        col *= 4.0;
    }
    case 1:
    {
        col *= 2.0;
    }
}

(declaring non constant ints at the top is not allowed and throws and approbierte error during validation)

Using the shadertoy utility in wgpu-py to make it valid glsl and then trying to run it with wgpu-py results in the panic below.

See this gist of the fragment shadercode which is produced.
This fragment shadercode does validate with naga, but errors when translating to .wgsl: fall-through switch case block which might be related?

Full error trace:
thread '<unnamed>' panicked at src\conv.rs:557:58:
called `Result::unwrap()` on an `Err` value: [Error { kind: SemanticError("Case values can only be integers"), meta: Span { start: 697, end: 704 } }, Error { kind: SemanticError("Case values can only be integers"), meta: Span { start: 747, end: 755 } }]
stack backtrace:
   0:     0x7ffab9fd4cea - wgpu_render_pass_execute_bundles
   1:     0x7ffab9febb1b - wgpu_render_pass_execute_bundles
   2:     0x7ffab9fd20c1 - wgpu_render_pass_execute_bundles
   3:     0x7ffab9fd4a6a - wgpu_render_pass_execute_bundles
   4:     0x7ffab9fd6e1a - wgpu_render_pass_execute_bundles
   5:     0x7ffab9fd6a88 - wgpu_render_pass_execute_bundles
   6:     0x7ffab9fd74ce - wgpu_render_pass_execute_bundles
   7:     0x7ffab9fd73bd - wgpu_render_pass_execute_bundles
   8:     0x7ffab9fd56d9 - wgpu_render_pass_execute_bundles
   9:     0x7ffab9fd70c0 - wgpu_render_pass_execute_bundles
  10:     0x7ffaba017f15 - wgpu_render_pass_execute_bundles
  11:     0x7ffaba018374 - wgpu_render_pass_execute_bundles
  12:     0x7ffab9c9fe42 - wgpuDeviceCreateShaderModule
  13:     0x7ffaffd510f3 - <unknown>
  14:     0x7ffaffd6ac90 - PyInit__cffi_backend
  15:     0x7ffaffd574af - <unknown>
  16:     0x7ffabab4d44b - PyObject_Call
  17:     0x7ffabab2c65f - PyEval_EvalFrameDefault
  18:     0x7ffabab23963 - PyObject_GC_Del
  19:     0x7ffabab255a7 - PyFunction_Vectorcall
  20:     0x7ffabab2823d - PyEval_EvalFrameDefault
  21:     0x7ffabab23963 - PyObject_GC_Del
  22:     0x7ffabab2b182 - PyEval_EvalFrameDefault
  23:     0x7ffabab2812f - PyEval_EvalFrameDefault
  24:     0x7ffabab23963 - PyObject_GC_Del
  25:     0x7ffabab255a7 - PyFunction_Vectorcall
  26:     0x7ffabab78a6a - PyArg_ParseTuple_SizeT
  27:     0x7ffabab7699d - PyType_GenericNew
  28:     0x7ffababd30ac - PyObject_MakeTpCall
  29:     0x7ffabab2e073 - PyEval_EvalFrameDefault
  30:     0x7ffabab23963 - PyObject_GC_Del
  31:     0x7ffababe8bdd - PyEval_EvalCodeWithName
  32:     0x7ffababe8b1f - PyEval_EvalCodeEx
  33:     0x7ffababe8a7d - PyEval_EvalCode
  34:     0x7ffabab1587a - PyBytes_DecodeEscape
  35:     0x7ffabab157fa - PyBytes_DecodeEscape
  36:     0x7ffababb8083 - Py_wfopen
  37:     0x7ffababb6434 - Py_stat
  38:     0x7ffabab8a7ef - PyRun_SimpleFileExFlags
  39:     0x7ffabac82e04 - PyRun_AnyFileExFlags
  40:     0x7ffababb8dd2 - PyList_GetItem
  41:     0x7ffababba32c - Py_RunMain
  42:     0x7ffababba1b5 - Py_RunMain
  43:     0x7ffababb9e85 - Py_Main
  44:     0x7ff743131258 - <unknown>
  45:     0x7ffb39007344 - BaseThreadInitThunk
  46:     0x7ffb395626b1 - RtlUserThreadStart
@teoxoy teoxoy added type: enhancement New feature or request naga Shader Translator area: naga front-end lang: GLSL OpenGL Shading Language labels Nov 6, 2023
@Vipitis
Copy link
Author

Vipitis commented Nov 24, 2023

the original usecase no longer causes a panic with wgpu-native 0.18.1.2 now used in wgpu-py.
Naga cli 0.14.0 still throws the fall-through error. But since the downstream panic seems to be fixed, I will mark this as closed.

@Vipitis Vipitis closed this as completed Nov 24, 2023
@teoxoy
Copy link
Member

teoxoy commented Nov 24, 2023

Was fixed by gfx-rs/naga#2309.
The fall-through error is: #4415.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: naga front-end lang: GLSL OpenGL Shading Language naga Shader Translator type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants