[glsl-in] Add integration tests to CI (#943)

* [glsl-in] Add glsl snapshots folder

* [glsl-in] Fix incorrect angle brackets parsing

* [glsl-in] Temporarily remove wgsl snapshot output
This commit is contained in:
João Capucho
2021-06-03 20:34:54 +01:00
committed by GitHub
parent db3dd63bdd
commit 87748a2fe3
16 changed files with 326 additions and 2 deletions

View File

@@ -1075,8 +1075,8 @@ impl<'source, 'program, 'options> Parser<'source, 'program, 'options> {
TokenValue::NotEqual => BinaryOperator::NotEqual,
TokenValue::GreaterEqual => BinaryOperator::GreaterEqual,
TokenValue::LessEqual => BinaryOperator::LessEqual,
TokenValue::LeftAngle => BinaryOperator::Greater,
TokenValue::RightAngle => BinaryOperator::Less,
TokenValue::LeftAngle => BinaryOperator::Less,
TokenValue::RightAngle => BinaryOperator::Greater,
TokenValue::LeftShift => BinaryOperator::ShiftLeft,
TokenValue::RightShift => BinaryOperator::ShiftRight,
TokenValue::Plus => BinaryOperator::Add,

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -0,0 +1,28 @@
// AUTHOR: enfipy
// 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 vec3 v_Position;
layout(location = 1) out vec3 v_Normal;
layout(location = 2) out vec2 v_Uv;
layout(set = 0, binding = 0) uniform Camera {
mat4 ViewProj;
};
layout(set = 2, binding = 0) uniform Transform {
mat4 Model;
};
void main() {
v_Normal = (Model * vec4(Vertex_Normal, 1.0)).xyz;
v_Normal = mat3(Model) * Vertex_Normal;
v_Position = (Model * vec4(Vertex_Position, 1.0)).xyz;
v_Uv = Vertex_Uv;
gl_Position = ViewProj * vec4(v_Position, 1.0);
}

View File

@@ -0,0 +1,8 @@
// AUTHOR: Napokue
// ISSUE: #277
// FIX: #278
#version 450
void main() {
float a = float(1);
}

View File

@@ -0,0 +1,8 @@
// AUTHOR: pjoe
// ISSUE: #280
// FIX: #898
#version 450
void main() {
mat4 a = mat4(1);
}

View File

@@ -0,0 +1,10 @@
// AUTHOR: fintelia
// ISSUE: #484
// FIX: https://github.com/Kangz/glslpp-rs/pull/30
// NOTE: Shader altered to use correct syntax
#version 450 core
#if 0
#endif
void main() { }

View File

@@ -0,0 +1,26 @@
// AUTHOR: Herschel
// ISSUE: #800
// FIX: #901
#version 450
// Set 0: globals
layout(set = 0, binding = 0) uniform Globals {
mat4 view_matrix;
};
// Push constants: matrix + color
layout(push_constant) uniform VertexPushConstants {
mat4 world_matrix;
};
layout(location = 0) in vec2 position;
layout(location = 1) in vec4 color;
layout(location = 0) out vec4 frag_color;
void main() {
frag_color = color;
gl_Position = view_matrix * world_matrix * vec4(position, 0.0, 1.0);
// TODO: https://github.com/gfx-rs/naga/issues/901
// gl_Position.z = (gl_Position.z + gl_Position.w) / 2.0;
}

View File

@@ -0,0 +1,10 @@
// AUTHOR: Foltik
// ISSUE: #896
// FIX: #897
#version 450
layout(push_constant) uniform PushConstants {
float example;
} c;
void main() {}

View File

@@ -0,0 +1,10 @@
// AUTHOR: jakobhellermann
// ISSUE: #931
// FIX: #933
#version 450
const int constant = 10;
float function() {
return 0.0;
}

View File

@@ -0,0 +1,8 @@
// AUTHOR: jakobhellermann
// ISSUE: #932
// FIX: #935
#version 450
void main() {
for (int i = 0; i < 1; i += 1) {}
}

View File

@@ -0,0 +1,27 @@
[[block]]
struct ColorMaterial_color {
Color: vec4<f32>;
};
struct FragmentOutput {
[[location(0), interpolate(perspective)]] member: vec4<f32>;
};
var<private> v_Uv: vec2<f32>;
var<private> o_Target: vec4<f32>;
[[group(1), binding(0)]]
var<uniform> global: ColorMaterial_color;
fn main() {
var color: vec4<f32>;
color = global.Color;
o_Target = color;
return;
}
[[stage(fragment)]]
fn main1() -> FragmentOutput {
main();
return FragmentOutput(o_Target);
}

View File

@@ -0,0 +1,48 @@
[[block]]
struct Camera {
ViewProj: mat4x4<f32>;
};
[[block]]
struct Transform {
Model: mat4x4<f32>;
};
[[block]]
struct Sprite_size {
size: vec2<f32>;
};
struct VertexOutput {
[[location(0), interpolate(perspective)]] member: vec2<f32>;
[[builtin(position)]] member1: vec4<f32>;
};
var<private> Vertex_Position: vec3<f32>;
var<private> Vertex_Normal: vec3<f32>;
var<private> Vertex_Uv: vec2<f32>;
var<private> v_Uv: vec2<f32>;
[[group(0), binding(0)]]
var<uniform> global: Camera;
[[group(2), binding(0)]]
var<uniform> global1: Transform;
[[group(2), binding(1)]]
var<uniform> global2: Sprite_size;
var<private> gl_Position: vec4<f32>;
fn main() {
var position: vec3<f32>;
v_Uv = Vertex_Uv;
position = (Vertex_Position * vec3<f32>(global2.size, 1.0));
gl_Position = ((global.ViewProj * global1.Model) * vec4<f32>(position, 1.0));
return;
}
[[stage(vertex)]]
fn main1([[location(0), interpolate(perspective)]] param: vec3<f32>, [[location(2), interpolate(perspective)]] param1: vec2<f32>) -> VertexOutput {
Vertex_Position = param;
Vertex_Uv = param1;
main();
return VertexOutput(v_Uv, gl_Position);
}

View File

@@ -0,0 +1,36 @@
[[block]]
struct Globals {
view_matrix: mat4x4<f32>;
};
[[block]]
struct VertexPushConstants {
world_matrix: mat4x4<f32>;
};
struct VertexOutput {
[[location(0), interpolate(perspective)]] member: vec4<f32>;
[[builtin(position)]] member1: vec4<f32>;
};
[[group(0), binding(0)]]
var<uniform> global: Globals;
var<push_constant> global1: VertexPushConstants;
var<private> position: vec2<f32>;
var<private> color: vec4<f32>;
var<private> frag_color: vec4<f32>;
var<private> gl_Position: vec4<f32>;
fn main() {
frag_color = color;
gl_Position = ((global.view_matrix * global1.world_matrix) * vec4<f32>(position, 0.0, 1.0));
return;
}
[[stage(vertex)]]
fn main1([[location(0), interpolate(perspective)]] param: vec2<f32>, [[location(1), interpolate(perspective)]] param1: vec4<f32>) -> VertexOutput {
position = param;
color = param1;
main();
return VertexOutput(frag_color, gl_Position);
}

View File

@@ -0,0 +1,4 @@
fn function() -> f32 {
return 0.0;
}

View File

@@ -368,6 +368,53 @@ fn convert_glsl(
check_targets(&module, name, targets);
}
#[cfg(feature = "glsl-in")]
#[allow(unused_variables)]
#[test]
fn convert_glsl_folder() {
let root = env!("CARGO_MANIFEST_DIR");
for entry in std::fs::read_dir(format!("{}/{}/glsl", root, DIR_IN)).unwrap() {
let entry = entry.unwrap();
let file_name = entry.file_name().into_string().unwrap();
println!("Processing {}", file_name);
let mut entry_points = naga::FastHashMap::default();
let stage = match entry.path().extension().and_then(|s| s.to_str()).unwrap() {
"vert" => naga::ShaderStage::Vertex,
"frag" => naga::ShaderStage::Fragment,
"comp" => naga::ShaderStage::Compute,
ext => panic!("Unknown extension for glsl file {}", ext),
};
entry_points.insert("main".to_string(), stage);
let module = naga::front::glsl::parse_str(
&fs::read_to_string(entry.path()).expect("Couldn't find glsl file"),
&naga::front::glsl::Options {
entry_points,
defines: Default::default(),
},
)
.unwrap();
let info = naga::valid::Validator::new(
naga::valid::ValidationFlags::all(),
naga::valid::Capabilities::all(),
)
.validate(&module)
.unwrap();
let dest = PathBuf::from(root)
.join(DIR_OUT)
.join(&file_name.replace(".", "-"));
// FIXME: https://github.com/gfx-rs/naga/issues/945
// #[cfg(feature = "wgsl-out")]
// check_output_wgsl(&module, &info, &dest);
}
}
#[cfg(feature = "glsl-in")]
#[test]
fn convert_glsl_quad() {