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-cli] add --defines options for the glsl parser #5859

Merged
merged 3 commits into from
Jun 23, 2024

Conversation

theomonnom
Copy link
Contributor

@theomonnom theomonnom commented Jun 22, 2024

Description
The motivation is to enable one glsl shader file that includes both vertex and fragment stages separated through preprocessing. This matches the behaviour of glslangValidator

Example of this particular glsl shader:

#version 450 core

#ifdef VERTEX_SHADER
struct VertexInput {
    vec3 position;
    vec2 tex_coord;
};

layout(location = 0) in vec3 in_position;
layout(location = 1) in vec2 in_tex_coord;
layout(location = 0) out vec2 frag_tex_coord;

void main() {
    VertexInput vertex;
    vertex.position = in_position;
    vertex.tex_coord = in_tex_coord;

    frag_tex_coord = vertex.tex_coord;
    gl_Position = vec4(vertex.position, 1.0);
}
#endif

#ifdef FRAGMENT_SHADER
layout(location = 0) in vec2 frag_tex_coord;
layout(location = 0) out vec4 out_color;

void main() {
    out_color = vec4(frag_tex_coord, 0.0, 1.0);
}
#endif

Testing

cargo run -- my_shader.glsl my_shader.frag.wgsl --shader-stage fragment --entry-point main -D FRAGMENT_SHADER
cargo run -- my_shader.glsl my_shader.vert.wgsl --shader-stage vertex --entry-point main -D VERTEX_SHADER

Checklist

  • Run cargo fmt.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests.
  • Add change to CHANGELOG.md. See simple instructions inside file.

@theomonnom theomonnom requested a review from a team as a code owner June 22, 2024 20:35
@theomonnom theomonnom changed the title support defines parameters for the glsl parser [naga] support defines parameters for the glsl parser Jun 22, 2024
@theomonnom theomonnom changed the title [naga] support defines parameters for the glsl parser [naga-cli] support defines parameters for the glsl parser Jun 22, 2024
@theomonnom theomonnom changed the title [naga-cli] support defines parameters for the glsl parser [naga-cli] add --defines options for the glsl parser Jun 22, 2024
Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@jimblandy jimblandy enabled auto-merge (squash) June 23, 2024 07:08
@jimblandy jimblandy merged commit 0f6abc9 into gfx-rs:trunk Jun 23, 2024
25 checks passed
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

Successfully merging this pull request may close these issues.

2 participants