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] naga panic: index out of bound in swizzle expression #4773

Closed
Vipitis opened this issue Nov 25, 2023 · 0 comments · Fixed by #4858
Closed

[glsl-in] naga panic: index out of bound in swizzle expression #4773

Vipitis opened this issue Nov 25, 2023 · 0 comments · Fixed by #4858
Labels
area: naga front-end lang: GLSL OpenGL Shading Language naga Shader Translator type: bug Something isn't working

Comments

@Vipitis
Copy link

Vipitis commented Nov 25, 2023

I encountered this panic while working with shadertoys through wgpu-py. The original shader where this happened: https://www.shadertoy.com/view/clB3D3 and a minimal reconstruction: https://www.shadertoy.com/view/cltfRn

case that panics:

#define MIX2(c) mix(c.xy, c.xy, 0.5)
const vec2 blank = MIX2(vec2(0.0,1.0));
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = fragCoord/iResolution.xy;
    vec2 col = MIX2(uv);
    fragColor = vec4(col,0.0,1.0);
}

equivalent case that works (comment out the unused const)

#define MIX2(c) mix(c.xy, c.xy, 0.5)
// const vec2 blank = MIX2(vec2(0.0,1.0));
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = fragCoord/iResolution.xy;
    vec2 col = MIX2(uv);
    fragColor = vec4(col,0.0,1.0);
}

equivalent case that throws an error without swizzle (error might be with the implementation, but at least it doesn't panic)

#define MIX2(c) mix(c, c, 0.5)
const vec2 blank = MIX2(vec2(0.0,1.0));
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{
    vec2 uv = fragCoord/iResolution.xy;
    vec2 col = MIX2(uv);
    fragColor = vec4(col,0.0,1.0);
}

I used naga-cli 0.14.0 and wgpu-py shadertoy util to add the compatibility code for shadertoy syntax.

Full error trace:
naga panic_shader4.frag 
thread 'main' panicked at ~\.cargo\registry\src\index.crates.io-6f17d22bba15001f\naga-0.14.0\src\front\glsl\variables.rs:336:28:
index out of bounds: the len is 12 but the index is 15
stack backtrace:
   0:     0x7ff6c169c3da - <unknown>
   1:     0x7ff6c16b4acb - <unknown>
   2:     0x7ff6c16992e1 - <unknown>
   3:     0x7ff6c169c15a - <unknown>
   4:     0x7ff6c169e75a - <unknown>
   5:     0x7ff6c169e3c8 - <unknown>
   6:     0x7ff6c169ee0e - <unknown>
   7:     0x7ff6c169ecfd - <unknown>
   8:     0x7ff6c169cdc9 - <unknown>
   9:     0x7ff6c169ea00 - <unknown>
  10:     0x7ff6c16d7b35 - <unknown>
  11:     0x7ff6c16d7cae - <unknown>
  12:     0x7ff6c15818a9 - <unknown>
  13:     0x7ff6c1527077 - <unknown>
  14:     0x7ff6c15746b5 - <unknown>
  15:     0x7ff6c15277bc - <unknown>
  16:     0x7ff6c1525d2d - <unknown>
  17:     0x7ff6c15ed931 - <unknown>
  18:     0x7ff6c15ee8b9 - <unknown>
  19:     0x7ff6c15f02bd - <unknown>
  20:     0x7ff6c15ff25d - <unknown>
  21:     0x7ff6c158308f - <unknown>
  22:     0x7ff6c13effb5 - <unknown>
  23:     0x7ff6c13fd636 - <unknown>
  24:     0x7ff6c13fd64c - <unknown>
  25:     0x7ff6c1693348 - <unknown>
  26:     0x7ff6c13f4f8c - <unknown>
  27:     0x7ff6c16bca68 - <unknown>
  28:     0x7ffd609e7344 - BaseThreadInitThunk
  29:     0x7ffd60b226b1 - RtlUserThreadStart

the perma link to the line it mentions:

} = ctx[expression]

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: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants