mirror of
https://github.com/gfx-rs/wgpu.git
synced 2026-04-22 03:02:01 -04:00
[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:
@@ -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,
|
||||
|
||||
27
tests/in/glsl/210-bevy-2d-shader.frag
Normal file
27
tests/in/glsl/210-bevy-2d-shader.frag
Normal 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;
|
||||
}
|
||||
27
tests/in/glsl/210-bevy-2d-shader.vert
Normal file
27
tests/in/glsl/210-bevy-2d-shader.vert
Normal 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);
|
||||
}
|
||||
28
tests/in/glsl/210-bevy-shader.vert
Normal file
28
tests/in/glsl/210-bevy-shader.vert
Normal 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);
|
||||
}
|
||||
8
tests/in/glsl/277-casting.vert
Normal file
8
tests/in/glsl/277-casting.vert
Normal file
@@ -0,0 +1,8 @@
|
||||
// AUTHOR: Napokue
|
||||
// ISSUE: #277
|
||||
// FIX: #278
|
||||
#version 450
|
||||
|
||||
void main() {
|
||||
float a = float(1);
|
||||
}
|
||||
8
tests/in/glsl/280-matrix-cast.vert
Normal file
8
tests/in/glsl/280-matrix-cast.vert
Normal file
@@ -0,0 +1,8 @@
|
||||
// AUTHOR: pjoe
|
||||
// ISSUE: #280
|
||||
// FIX: #898
|
||||
#version 450
|
||||
|
||||
void main() {
|
||||
mat4 a = mat4(1);
|
||||
}
|
||||
10
tests/in/glsl/484-preprocessor-if.vert
Normal file
10
tests/in/glsl/484-preprocessor-if.vert
Normal 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() { }
|
||||
26
tests/in/glsl/800-out-of-bounds-panic.vert
Normal file
26
tests/in/glsl/800-out-of-bounds-panic.vert
Normal 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;
|
||||
}
|
||||
10
tests/in/glsl/896-push-constant.vert
Normal file
10
tests/in/glsl/896-push-constant.vert
Normal file
@@ -0,0 +1,10 @@
|
||||
// AUTHOR: Foltik
|
||||
// ISSUE: #896
|
||||
// FIX: #897
|
||||
#version 450
|
||||
|
||||
layout(push_constant) uniform PushConstants {
|
||||
float example;
|
||||
} c;
|
||||
|
||||
void main() {}
|
||||
10
tests/in/glsl/931-constant-emitting.vert
Normal file
10
tests/in/glsl/931-constant-emitting.vert
Normal file
@@ -0,0 +1,10 @@
|
||||
// AUTHOR: jakobhellermann
|
||||
// ISSUE: #931
|
||||
// FIX: #933
|
||||
#version 450
|
||||
|
||||
const int constant = 10;
|
||||
|
||||
float function() {
|
||||
return 0.0;
|
||||
}
|
||||
8
tests/in/glsl/932-for-loop-if.vert
Normal file
8
tests/in/glsl/932-for-loop-if.vert
Normal file
@@ -0,0 +1,8 @@
|
||||
// AUTHOR: jakobhellermann
|
||||
// ISSUE: #932
|
||||
// FIX: #935
|
||||
#version 450
|
||||
|
||||
void main() {
|
||||
for (int i = 0; i < 1; i += 1) {}
|
||||
}
|
||||
27
tests/out/210-bevy-2d-shader-frag.wgsl
Normal file
27
tests/out/210-bevy-2d-shader-frag.wgsl
Normal 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);
|
||||
}
|
||||
48
tests/out/210-bevy-2d-shader-vert.wgsl
Normal file
48
tests/out/210-bevy-2d-shader-vert.wgsl
Normal 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);
|
||||
}
|
||||
36
tests/out/800-out-of-bounds-panic-vert.wgsl
Normal file
36
tests/out/800-out-of-bounds-panic-vert.wgsl
Normal 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);
|
||||
}
|
||||
4
tests/out/931-constant-emitting-vert.wgsl
Normal file
4
tests/out/931-constant-emitting-vert.wgsl
Normal file
@@ -0,0 +1,4 @@
|
||||
fn function() -> f32 {
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user