#Array wgsl issue: invalid final module due to missing the sized TypeFlag

9 messages · Page 1 of 1 (latest)

summer birch
#

When running the app, I get the following error immediately:

error: failed to build a valid final module: Global variable [4] 'params' is invalid
   ┌─ shaders/groups.wgsl:18:23
   │
18 │ @group(2) @binding(0) var<uniform> params: array<GroupParams>;
   │                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ naga::ir::GlobalVariable [4]
   │
   = Type flags TypeFlags(DATA | COPY | HOST_SHAREABLE | CREATION_RESOLVED) do not meet the required TypeFlags(DATA | SIZED | COPY | HOST_SHAREABLE | CREATION_RESOLVED)

So based on that error, it's pretty obvious that "SIZED" is the flag that's missing and that it's relevant to the array nature. However, I can't figure out how to fix it. array<T,N> seems valid in some circumstances but isn't working in this case.

Here's the type definitions:

#[repr(C)]
#[derive(Clone, Copy, ShaderType)]
struct GroupParams {
    base_color: Vec4,
    a: f32,
    b: f32,
    c: f32,
    d: f32,
    e: f32,
    f: f32,
    g: f32,
    h: f32,
}

#[repr(C)]
#[derive(Asset, AsBindGroup, Clone, TypePath)]
struct GroupsMaterial {
    #[uniform(0)]
    groups_params: [GroupParams; 10],
}

And then the definition in wgsl:

struct GroupParams {
    base_color: vec4<f32>,
    a: f32,
    b: f32,
    c: f32,
    d: f32,
    e: f32,
    f: f32,
    g: f32,
    h: f32,
}

@group(2) @binding(0) var<uniform> params: array<GroupParams>;

What am I missing? Thank you.

autumn seal
#

Is the definition of GroupParams on the same file as the @binding?

summer birch
#

The wgsl definition of GroupParams? Yeah, same file

autumn seal
#

var<uniform> params: array<GroupParams, 10>?

#

Since it is fixed length array, not runtime sized array

summer birch
#

Yea, I tried that and it doesn't work either. Does give a different error, but it's not clearer to me:

error: failed to build a valid final module: Entry point vertex at Vertex is invalid
   ┌─ shaders/groups.wgsl:18:23
   │
18 │ @group(2) @binding(0) var<uniform> params: array<GroupParams, 10>;
   │                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ naga::ir::GlobalVariable [4]
   │
   = Bindings for [4] conflict with other resource

Not sure what other resource it would be conflicting with. Suggests something about the vertex input maybe? But not clear to me why that would have anything to do with the uniform

struct Vertex {
    @builtin(instance_index) instance_index: u32,
    @location(0) position: vec3<f32>,
    @location(1) normal: vec3<f32>,
    @location(2) uv: vec2<f32>,
};

Thanks for taking a look at this

autumn seal
#

can you send the whole wgsl?

summer birch
#
#import bevy_pbr::{
    mesh_view_bindings::globals,
    mesh_functions::{get_world_from_local, mesh_position_local_to_clip, get_tag},
};

struct GroupParams {
    base_color: vec4<f32>,
    a: f32,
    b: f32,
    c: f32,
    d: f32,
    e: f32,
    f: f32,
    g: f32,
    h: f32,
}

@group(2) @binding(0) var<uniform> params: array<GroupParams, 10>;

struct Vertex {
    @builtin(instance_index) instance_index: u32,
    @location(0) position: vec3<f32>,
    @location(1) normal: vec3<f32>,
    @location(2) uv: vec2<f32>,
};

struct VertexOutput {
    @builtin(position) clip_position: vec4<f32>,
    @location(1) color: vec4<f32>,
};

@vertex
fn vertex(vertex: Vertex) -> VertexOutput {
    let dt = globals.delta_time;

    let i = get_tag(vertex.instance_index);
    let decay = params[i].a * exp(- params[i].b * dt);

    let position = decay * vertex.position;

    var out: VertexOutput;
    out.clip_position = mesh_position_local_to_clip(
        get_world_from_local(i),
        vec4<f32>(position, 1.0),
    );
    out.color = params[i].base_color;
    return out;
}

@fragment
fn fragment(in: VertexOutput) -> @location(0) vec4<f32> {
    return in.color;
}
autumn seal
#
@group(#{MATERIAL_BIND_GROUP}) @binding(0) var<uniform> params: array<GroupParams, 10>;