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

Naga invariant error is confusing #30

Open
robtfm opened this issue Jul 11, 2023 · 4 comments
Open

Naga invariant error is confusing #30

robtfm opened this issue Jul 11, 2023 · 4 comments

Comments

@robtfm
Copy link
Collaborator

robtfm commented Jul 11, 2023

We can at least call out the most common case of ending an imported item with a number.

Ideally find a way to remap so that users don’t need to worry about it

@viridia
Copy link

viridia commented Jul 25, 2023

I get the following error whenever I define a function that ends with a digit:

╭ fn foo2() -> f32 {
14 │ │   return 1.;
   │ ╰────────────^ Composable module identifiers must not require substitution according to naga writeback rules: `"shaderlib/permute.wgsl"::foo2`

The error happens whether I import the function or not.

This is annoying because there are a lot of functions that end with digits (permute2, permute3, etc.) due to the non-support of function overloading in WGSL.

@Neopallium
Copy link

I was getting that same error before bevy 0.11 release. But now I get this when trying to import a function that ends with a digit:

ERROR bevy_render::render_resource::pipeline_cache: failed to process shader:
error: no definition in scope for identifier: 'bevy_water::noise::vnoise::vnoise2'
  ┌─ /home/robert/projects/rust/bevy_water/assets/shaders/noise/fbm.wgsl:9:10
  │
9 │   return bevy_water::noise::vnoise::vnoise2(v);
  │          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown identifier
  │
  = no definition in scope for identifier: 'bevy_water::noise::vnoise::vnoise2'

I can't remember how I cause that Composable module identifiers.... error before.

vnoise.wgsl:

#define_import_path bevy_water::noise::vnoise

#import bevy_water::noise::random random2di, cubic_hermite_curve_2d

fn vnoise2(v: vec2<f32>) -> f32 {
        let i = floor(v);
        let f = fract(v);

        // corners.
        let a = random2di(i);
        let b = random2di(i + vec2<f32>(1.0, 0.0));
        let c = random2di(i + vec2<f32>(0.0, 1.0));
        let d = random2di(i + vec2<f32>(1.0, 1.0));

        // Smooth
  let u = cubic_hermite_curve_2d(f);

        // Mix
        return mix(a, b, u.x) +
                (c - a) * u.y * (1.0 - u.x) +
                (d - b) * u.x * u.y;
}

fbm.wgsl:

#define_import_path bevy_water::noise::fbm

#import bevy_water::noise::vnoise vnoise2

fn noise2(v: vec2<f32>) -> f32 {
  return vnoise2(v);
}

fn fbm(v2: vec2<f32>) -> f32 {
  let m2 = mat2x2<f32>(vec2<f32>(0.8, 0.6), vec2<f32>(-0.6, 0.8));
  var p = v2;
  var f = 0.;
  f = f + 0.5000 * noise2(p); p = m2 * p * 2.02;
  f = f + 0.2500 * noise2(p); p = m2 * p * 2.03;
  f = f + 0.1250 * noise2(p); p = m2 * p * 2.01;
  f = f + 0.0625 * noise2(p);
  return f / 0.9375;
}

Those shaders were modified from: https://github.com/Neopallium/bevy_water/tree/main/assets/shaders/noise
Adding d to the end of the vnoise2 function and the error goes away.

@Cifram
Copy link

Cifram commented Jul 28, 2023

I just encountered the exact same issue. Spent a couple hours trying in vain to debug it, before I looked up the naga_oil repo to see if there was a bug about this, and here it is! In my case, it was a random_f32 function, but I've currently renamed to random_float to sidestep this. Hopefully I won't need random f16 or f64 values any time soon.

I initially did a similar test, renaming it to random_f32x, and that also fixed it. From what I can tell, any attempt to import a function which ends in a number will hit this issue.

@Bcompartment
Copy link

We can at least call out the most common case of ending an imported item with a number.

Ideally find a way to remap so that users don’t need to worry about it

I found similar error to this thread #71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants