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

Rust bindings assume all vertex shaders in a file have the same input, even if they don't #44

Open
Gonkalbell opened this issue Aug 22, 2024 · 1 comment

Comments

@Gonkalbell
Copy link

I have a file with multiple vertex shaders, like this:

struct VertexInput {
    @location(0) position: vec3f,
};

struct InstanceInput {
    @location(1) position: vec3f,
};

@vertex
fn dummy_vertex_shader(vert_in: VertexInput) -> @builtin(position) vec4f {
    return vec4f(vert_in.position, 1);
}

@vertex
fn dummy_instanced_vertex_shader(vert_in: VertexInput, instance_in: InstanceInput) -> @builtin(position) vec4f {
    return vec4f(vert_in.position + instance_in.position, 1);
}

In the generated rust bindings, there's a generated VERTEX_ATTRIBUTES and vertex_buffer_layout for VertexInput, but not for InstanceInput. Also, their _vertex_shader_entrys are the same, even though dummy_instanced_vertex_shader should have 2 inputs instead of one:

    pub fn dummy_vertex_shader_entry(
        vertex_input: wgpu::VertexStepMode,
    ) -> VertexEntry<1> {
        VertexEntry {
            entry_point: ENTRY_DUMMY_VERTEX_SHADER,
            buffers: [VertexInput::vertex_buffer_layout(vertex_input)],
            constants: Default::default(),
        }
    }
    pub fn dummy_instanced_vertex_shader_entry(
        vertex_input: wgpu::VertexStepMode,
    ) -> VertexEntry<1> {
        VertexEntry {
            entry_point: ENTRY_DUMMY_INSTANCED_VERTEX_SHADER,
            buffers: [VertexInput::vertex_buffer_layout(vertex_input)],
            constants: Default::default(),
        }
    }

If I move dummy_instanced_vertex_shader to be before dummy_vertex_shader in that file, I then get a VERTEX_ATTRIBUTES and vertex_buffer_layout for both VertexInput and InstanceInput. However, now dummy_vertex_shader_entry is incorrect:

    pub fn dummy_instanced_vertex_shader_entry(
        vertex_input: wgpu::VertexStepMode,
        instance_input: wgpu::VertexStepMode,
    ) -> VertexEntry<2> {
        VertexEntry {
            entry_point: ENTRY_DUMMY_INSTANCED_VERTEX_SHADER,
            buffers: [
                VertexInput::vertex_buffer_layout(vertex_input),
                InstanceInput::vertex_buffer_layout(instance_input),
            ],
            constants: Default::default(),
        }
    }
    pub fn dummy_vertex_shader_entry(
        vertex_input: wgpu::VertexStepMode,
        instance_input: wgpu::VertexStepMode,
    ) -> VertexEntry<2> {
        VertexEntry {
            entry_point: ENTRY_DUMMY_VERTEX_SHADER,
            buffers: [
                VertexInput::vertex_buffer_layout(vertex_input),
                InstanceInput::vertex_buffer_layout(instance_input),
            ],
            constants: Default::default(),
        }
    }

So it seems like wgsl_bindgen assumes that every vertex shader in a file shares the same input as the first vertex shader.

@Gonkalbell Gonkalbell changed the title All All vertex shaders in a file assume they have the same inputs Aug 22, 2024
@Gonkalbell Gonkalbell changed the title All vertex shaders in a file assume they have the same inputs Rust bindings assume all vertex shaders in a file have the same input, even if they don't Aug 22, 2024
@Swoorup
Copy link
Owner

Swoorup commented Sep 1, 2024

Should be fairly straightforward to fix. Will take a look. Been a bit busy with other stuff.

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

2 participants