From 9bea6d8dc1870326fdcb4e244827954638ef18cf Mon Sep 17 00:00:00 2001 From: Elie Michel Date: Sat, 2 Sep 2023 15:12:55 +0200 Subject: [PATCH 1/3] Add support for .frag.glsl files --- cli/src/bin/naga.rs | 16 ++++++++++++- tests/in/glsl/210-bevy-2d-shader.frag.glsl | 27 ++++++++++++++++++++++ tests/in/glsl/210-bevy-2d-shader.vert.glsl | 27 ++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 tests/in/glsl/210-bevy-2d-shader.frag.glsl create mode 100644 tests/in/glsl/210-bevy-2d-shader.vert.glsl diff --git a/cli/src/bin/naga.rs b/cli/src/bin/naga.rs index 8f57984f56..8bd73b87f2 100644 --- a/cli/src/bin/naga.rs +++ b/cli/src/bin/naga.rs @@ -302,7 +302,7 @@ fn run() -> Result<(), Box> { } } } - ext @ ("vert" | "frag" | "comp") => { + ext @ ("vert" | "frag" | "comp" | "glsl") => { let input = String::from_utf8(input)?; let mut parser = naga::front::glsl::Frontend::default(); @@ -314,6 +314,20 @@ fn run() -> Result<(), Box> { "vert" => naga::ShaderStage::Vertex, "frag" => naga::ShaderStage::Fragment, "comp" => naga::ShaderStage::Compute, + "glsl" => { + let internal_name = input_path.to_string_lossy(); + match Path::new(&internal_name[..internal_name.len()-5]) + .extension() + .ok_or(CliError("Input filename ending with .glsl has no internal extension"))? + .to_str() + .ok_or(CliError("Input filename not valid unicode"))? + { + "vert" => naga::ShaderStage::Vertex, + "frag" => naga::ShaderStage::Fragment, + "comp" => naga::ShaderStage::Compute, + _ => unreachable!(), + } + }, _ => unreachable!(), }, defines: Default::default(), diff --git a/tests/in/glsl/210-bevy-2d-shader.frag.glsl b/tests/in/glsl/210-bevy-2d-shader.frag.glsl new file mode 100644 index 0000000000..93119ef259 --- /dev/null +++ b/tests/in/glsl/210-bevy-2d-shader.frag.glsl @@ -0,0 +1,27 @@ +// AUTHOR: mrk-its +// ISSUE: #210 +// FIX: #898 +#version 450 + +layout(location = 0) in vec2 v_Uv; + +layout(location = 0) out vec4 o_Target; + +layout(set = 1, binding = 0) uniform ColorMaterial_color { + vec4 Color; +}; + +# ifdef COLORMATERIAL_TEXTURE +layout(set = 1, binding = 1) uniform texture2D ColorMaterial_texture; +layout(set = 1, binding = 2) uniform sampler ColorMaterial_texture_sampler; +# endif + +void main() { + vec4 color = Color; +# ifdef COLORMATERIAL_TEXTURE + color *= texture( + sampler2D(ColorMaterial_texture, ColorMaterial_texture_sampler), + v_Uv); +# endif + o_Target = color; +} diff --git a/tests/in/glsl/210-bevy-2d-shader.vert.glsl b/tests/in/glsl/210-bevy-2d-shader.vert.glsl new file mode 100644 index 0000000000..1d99e1b177 --- /dev/null +++ b/tests/in/glsl/210-bevy-2d-shader.vert.glsl @@ -0,0 +1,27 @@ +// AUTHOR: mrk-its +// ISSUE: #210 +// FIX: #898 +#version 450 + +layout(location = 0) in vec3 Vertex_Position; +layout(location = 1) in vec3 Vertex_Normal; +layout(location = 2) in vec2 Vertex_Uv; + +layout(location = 0) out vec2 v_Uv; + +layout(set = 0, binding = 0) uniform Camera { + mat4 ViewProj; +}; + +layout(set = 2, binding = 0) uniform Transform { + mat4 Model; +}; +layout(set = 2, binding = 1) uniform Sprite_size { + vec2 size; +}; + +void main() { + v_Uv = Vertex_Uv; + vec3 position = Vertex_Position * vec3(size, 1.0); + gl_Position = ViewProj * Model * vec4(position, 1.0); +} From 38ad768e819607aca20c0f1e36e0d92b684d7d06 Mon Sep 17 00:00:00 2001 From: Elie Michel Date: Tue, 12 Sep 2023 23:55:52 +0200 Subject: [PATCH 2/3] Delete tests/in/glsl/210-bevy-2d-shader.vert.glsl --- tests/in/glsl/210-bevy-2d-shader.vert.glsl | 27 ---------------------- 1 file changed, 27 deletions(-) delete mode 100644 tests/in/glsl/210-bevy-2d-shader.vert.glsl diff --git a/tests/in/glsl/210-bevy-2d-shader.vert.glsl b/tests/in/glsl/210-bevy-2d-shader.vert.glsl deleted file mode 100644 index 1d99e1b177..0000000000 --- a/tests/in/glsl/210-bevy-2d-shader.vert.glsl +++ /dev/null @@ -1,27 +0,0 @@ -// AUTHOR: mrk-its -// ISSUE: #210 -// FIX: #898 -#version 450 - -layout(location = 0) in vec3 Vertex_Position; -layout(location = 1) in vec3 Vertex_Normal; -layout(location = 2) in vec2 Vertex_Uv; - -layout(location = 0) out vec2 v_Uv; - -layout(set = 0, binding = 0) uniform Camera { - mat4 ViewProj; -}; - -layout(set = 2, binding = 0) uniform Transform { - mat4 Model; -}; -layout(set = 2, binding = 1) uniform Sprite_size { - vec2 size; -}; - -void main() { - v_Uv = Vertex_Uv; - vec3 position = Vertex_Position * vec3(size, 1.0); - gl_Position = ViewProj * Model * vec4(position, 1.0); -} From d7435f45d8bd2fa2a550ebad6e3f9e6437e8ae8d Mon Sep 17 00:00:00 2001 From: Elie Michel Date: Tue, 12 Sep 2023 23:56:09 +0200 Subject: [PATCH 3/3] Delete tests/in/glsl/210-bevy-2d-shader.frag.glsl --- tests/in/glsl/210-bevy-2d-shader.frag.glsl | 27 ---------------------- 1 file changed, 27 deletions(-) delete mode 100644 tests/in/glsl/210-bevy-2d-shader.frag.glsl diff --git a/tests/in/glsl/210-bevy-2d-shader.frag.glsl b/tests/in/glsl/210-bevy-2d-shader.frag.glsl deleted file mode 100644 index 93119ef259..0000000000 --- a/tests/in/glsl/210-bevy-2d-shader.frag.glsl +++ /dev/null @@ -1,27 +0,0 @@ -// AUTHOR: mrk-its -// ISSUE: #210 -// FIX: #898 -#version 450 - -layout(location = 0) in vec2 v_Uv; - -layout(location = 0) out vec4 o_Target; - -layout(set = 1, binding = 0) uniform ColorMaterial_color { - vec4 Color; -}; - -# ifdef COLORMATERIAL_TEXTURE -layout(set = 1, binding = 1) uniform texture2D ColorMaterial_texture; -layout(set = 1, binding = 2) uniform sampler ColorMaterial_texture_sampler; -# endif - -void main() { - vec4 color = Color; -# ifdef COLORMATERIAL_TEXTURE - color *= texture( - sampler2D(ColorMaterial_texture, ColorMaterial_texture_sampler), - v_Uv); -# endif - o_Target = color; -}