Remove cargo-insta

This commit is contained in:
Dzmitry Malyshau 2021-04-14 14:20:48 -04:00 committed by Dzmitry Malyshau
parent f7fdf6b560
commit c2c93e4ecd
37 changed files with 139 additions and 564 deletions

View File

@ -24,6 +24,8 @@ jobs:
with: with:
command: test command: test
args: --all-features args: --all-features
- name: Check snapshots
run: git diff --exit-code -- tests/out
clippy: clippy:
name: Clippy name: Clippy
runs-on: ubuntu-latest runs-on: ubuntu-latest

View File

@ -46,9 +46,8 @@ name = "convert"
path = "bin/convert.rs" path = "bin/convert.rs"
[dev-dependencies] [dev-dependencies]
difference = "2.0" diff = "0.1"
ron = "0.6" ron = "0.6"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
spirv = { package = "spirv_headers", version = "1.5", features = ["deserialize"] } spirv = { package = "spirv_headers", version = "1.5", features = ["deserialize"] }
insta = { version = "1.6", features = ["glob"] }
rspirv = "0.7" rspirv = "0.7"

View File

@ -26,38 +26,34 @@ clean:
%.png: %.dot %.png: %.dot
dot -Tpng $< -o $@ dot -Tpng $< -o $@
# A command to remove the '---' YAML document start markers from the snapshots validate-spv: $(SNAPSHOTS_OUT)/*.spvasm
# before passing their contents to a validator.
TRIM=sed -e '1d' -e '2,/---/d'
validate-spv: $(SNAPSHOTS_OUT)/*.spvasm.snap
@set -e && for file in $^ ; do \ @set -e && for file in $^ ; do \
echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"}; \ echo "Validating" $${file#"$(SNAPSHOTS_OUT)"}; \
$(TRIM) $${file} | spirv-as --target-env vulkan1.0 -o - | spirv-val; \ cat $${file} | spirv-as --target-env vulkan1.0 -o - | spirv-val; \
done done
validate-msl: $(SNAPSHOTS_OUT)/*.msl.snap validate-msl: $(SNAPSHOTS_OUT)/*.msl
@set -e && for file in $^ ; do \ @set -e && for file in $^ ; do \
echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"}; \ echo "Validating" $${file#"$(SNAPSHOTS_OUT)"}; \
$(TRIM) $${file} | xcrun -sdk macosx metal -mmacosx-version-min=10.11 -x metal - -o /dev/null; \ cat $${file} | xcrun -sdk macosx metal -mmacosx-version-min=10.11 -x metal - -o /dev/null; \
done done
validate-glsl: $(SNAPSHOTS_OUT)/*.glsl.snap validate-glsl: $(SNAPSHOTS_OUT)/*.glsl
@set -e && for file in $(SNAPSHOTS_OUT)/*-Vertex.glsl.snap ; do \ @set -e && for file in $(SNAPSHOTS_OUT)/*.Vertex.glsl ; do \
echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"};\ echo "Validating" $${file#"$(SNAPSHOTS_OUT)"};\
$(TRIM) $${file} | glslangValidator --stdin -S vert; \ cat $${file} | glslangValidator --stdin -S vert; \
done done
@set -e && for file in $(SNAPSHOTS_OUT)/*-Fragment.glsl.snap ; do \ @set -e && for file in $(SNAPSHOTS_OUT)/*.Fragment.glsl ; do \
echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"};\ echo "Validating" $${file#"$(SNAPSHOTS_OUT)"};\
$(TRIM) $${file} | glslangValidator --stdin -S frag; \ cat $${file} | glslangValidator --stdin -S frag; \
done done
@set -e && for file in $(SNAPSHOTS_OUT)/*-Compute.glsl.snap ; do \ @set -e && for file in $(SNAPSHOTS_OUT)/*.Compute.glsl ; do \
echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"};\ echo "Validating" $${file#"$(SNAPSHOTS_OUT)"};\
$(TRIM) $${file} | glslangValidator --stdin -S comp; \ cat $${file} | glslangValidator --stdin -S comp; \
done done
validate-dot: $(SNAPSHOTS_OUT)/*.dot.snap validate-dot: $(SNAPSHOTS_OUT)/*.dot
@set -e && for file in $^ ; do \ @set -e && for file in $^ ; do \
echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"}; \ echo "Validating" $${file#"$(SNAPSHOTS_OUT)"}; \
$(TRIM) $${file} | dot -o /dev/null; \ cat $${file} | dot -o /dev/null; \
done done

View File

@ -44,9 +44,8 @@ cargo run --features wgsl-in,glsl-out -- my_shader.wgsl my_shader.vert --profile
## Development workflow ## Development workflow
The main instrument aiding the development is the good old `cargo test --all-features`, The main instrument aiding the development is the good old `cargo test --all-features`,
which will run the snapshot tests as well as the unit tests. which will run the unit tests, and also update all the snapshots. You'll see these
Any changes in the snapshots would then have to be reviewed with `cargo insta review` changes in git before committing the code.
before being accepted into the code.
If working on a particular front-end or back-end, it may be convenient to If working on a particular front-end or back-end, it may be convenient to
enable the relevant features in `Cargo.toml`, e.g. enable the relevant features in `Cargo.toml`, e.g.
@ -61,4 +60,5 @@ are indeed valid for the target platforms they are compiled for. We automate thi
make validate-spv # for Vulkan shaders, requires SPIRV-Tools installed make validate-spv # for Vulkan shaders, requires SPIRV-Tools installed
make validate-msl # for Metal shaders, requires XCode command-line tools installed make validate-msl # for Metal shaders, requires XCode command-line tools installed
make validate-glsl # for OpenGL shaders, requires GLSLang installed make validate-glsl # for OpenGL shaders, requires GLSLang installed
make validate-dot # for dot files, requires GraphViz installed
``` ```

View File

@ -1,99 +1,99 @@
#[cfg(feature = "wgsl-in")] #[cfg(feature = "wgsl-in")]
macro_rules! err { fn check(input: &str, snapshot: &str) {
($value:expr, @$snapshot:literal) => { let output = naga::front::wgsl::parse_str(input)
::insta::assert_snapshot!( .expect_err("expected parser error")
naga::front::wgsl::parse_str($value) .emit_to_string();
.expect_err("expected parser error") if output != snapshot {
.emit_to_string(), for diff in diff::lines(&output, snapshot) {
@$snapshot match diff {
); diff::Result::Left(l) => println!("-{}", l),
}; diff::Result::Both(l, _) => println!(" {}", l),
diff::Result::Right(r) => println!("+{}", r),
}
}
panic!("Error snapshot failed");
}
} }
#[cfg(feature = "wgsl-in")] #[cfg(feature = "wgsl-in")]
#[test] #[test]
fn function_without_identifier() { fn function_without_identifier() {
err!( check(
"fn () {}", "fn () {}",
@r###" r###"error: expected identifier, found '('
error: expected identifier, found '(' wgsl:1:4
wgsl:1:4
1 fn () {}
1 fn () {} ^ expected identifier
^ expected identifier
"### "###,
); );
} }
#[cfg(feature = "wgsl-in")] #[cfg(feature = "wgsl-in")]
#[test] #[test]
fn invalid_integer() { fn invalid_integer() {
err!( check(
"fn foo([location(1.)] x: i32) {}", "fn foo([location(1.)] x: i32) {}",
@r###" r###"error: expected identifier, found '['
error: expected identifier, found '[' wgsl:1:8
wgsl:1:8
1 fn foo([location(1.)] x: i32) {}
1 fn foo([location(1.)] x: i32) {} ^ expected identifier
^ expected identifier
"### "###,
); );
} }
#[cfg(feature = "wgsl-in")] #[cfg(feature = "wgsl-in")]
#[test] #[test]
fn invalid_float() { fn invalid_float() {
err!( check(
"let scale: f32 = 1.1.;", "let scale: f32 = 1.1.;",
@r###" r###"error: expected floating-point literal, found `1.1.`
error: expected floating-point literal, found `1.1.` wgsl:1:18
wgsl:1:18
1 let scale: f32 = 1.1.;
1 let scale: f32 = 1.1.; ^^^^ expected floating-point literal
^^^^ expected floating-point literal
"### "###,
); );
} }
#[cfg(feature = "wgsl-in")] #[cfg(feature = "wgsl-in")]
#[test] #[test]
fn invalid_scalar_width() { fn invalid_scalar_width() {
err!( check(
"let scale: f32 = 1.1f1000;", "let scale: f32 = 1.1f1000;",
@r###" r###"error: invalid width of `1000` for literal
error: invalid width of `1000` for literal wgsl:1:18
wgsl:1:18
1 let scale: f32 = 1.1f1000;
1 let scale: f32 = 1.1f1000; ^^^^^^^^ invalid width
^^^^^^^^ invalid width
= note: valid width is 32
= note: valid width is 32
"### "###,
); );
} }
#[cfg(feature = "wgsl-in")] #[cfg(feature = "wgsl-in")]
#[test] #[test]
fn invalid_accessor() { fn invalid_accessor() {
err!( check(
r###" r###"
[[stage(vertex)]] [[stage(vertex)]]
fn vs_main() { fn vs_main() {
var color: vec3<f32> = vec3<f32>(1.0, 2.0, 3.0); var color: vec3<f32> = vec3<f32>(1.0, 2.0, 3.0);
var i: f32 = color.a; var i: f32 = color.a;
} }
"###, "###,
@r###" r###"error: invalid field accessor `a`
error: invalid field accessor `a` wgsl:5:24
wgsl:5:32
5 var i: f32 = color.a;
5 var i: f32 = color.a; ^ invalid accessor
^ invalid accessor
"### "###,
); );
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: msl
---
#include <metal_stdlib> #include <metal_stdlib>
#include <simd/simd.h> #include <simd/simd.h>
@ -101,4 +97,3 @@ kernel void main1(
particlesDst.particles[global_invocation_id.x].vel = vVel; particlesDst.particles[global_invocation_id.x].vel = vVel;
return; return;
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: dis
---
; SPIR-V ; SPIR-V
; Version: 1.0 ; Version: 1.0
; Generator: rspirv ; Generator: rspirv
@ -332,4 +328,4 @@ OpStore %200 %199
%202 = OpAccessChain %53 %25 %7 %46 %10 %202 = OpAccessChain %53 %25 %7 %46 %10
OpStore %202 %201 OpStore %202 %201
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: output
---
( (
functions: [ functions: [
( (
@ -498,4 +494,4 @@ expression: output
], ],
), ),
], ],
) )

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: msl
---
#include <metal_stdlib> #include <metal_stdlib>
#include <simd/simd.h> #include <simd/simd.h>
@ -40,4 +36,3 @@ kernel void main1(
v_indices.data[global_id.x] = _e9; v_indices.data[global_id.x] = _e9;
return; return;
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: output
---
( (
types: [ types: [
( (
@ -347,4 +343,4 @@ expression: output
), ),
), ),
], ],
) )

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: dis
---
; SPIR-V ; SPIR-V
; Version: 1.0 ; Version: 1.0
; Generator: rspirv ; Generator: rspirv
@ -109,4 +105,4 @@ OpBranch %50
%60 = OpAccessChain %53 %11 %56 %52 %60 = OpAccessChain %53 %11 %56 %52
OpStore %60 %59 OpStore %60 %59
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: string
---
#version 310 es #version 310 es
precision highp float; precision highp float;
@ -13,4 +9,3 @@ void main() {
return; return;
} }

5
tests/out/empty.hlsl Normal file
View File

@ -0,0 +1,5 @@
void main()
{
return;
}

View File

@ -1,11 +0,0 @@
---
source: tests/snapshots.rs
expression: hlsl
---
void main()
{
return;
}

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: msl
---
#include <metal_stdlib> #include <metal_stdlib>
#include <simd/simd.h> #include <simd/simd.h>
@ -10,4 +6,3 @@ kernel void main1(
) { ) {
return; return;
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: dis
---
; SPIR-V ; SPIR-V
; Version: 1.1 ; Version: 1.1
; Generator: rspirv ; Generator: rspirv
@ -18,4 +14,4 @@ OpExecutionMode %4 LocalSize 1 1 1
OpBranch %6 OpBranch %6
%6 = OpLabel %6 = OpLabel
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: msl
---
#include <metal_stdlib> #include <metal_stdlib>
#include <simd/simd.h> #include <simd/simd.h>
@ -18,4 +14,3 @@ kernel void main1(
image_dst.write(_e13, metal::uint(_e12.x)); image_dst.write(_e13, metal::uint(_e12.x));
return; return;
} }

View File

@ -1,224 +0,0 @@
---
source: tests/snapshots.rs
expression: output
---
(
types: [
(
name: None,
inner: Scalar(
kind: Float,
width: 4,
),
),
(
name: None,
inner: Vector(
size: Bi,
kind: Float,
width: 4,
),
),
(
name: None,
inner: Vector(
size: Quad,
kind: Float,
width: 4,
),
),
],
constants: [
(
name: None,
specialization: None,
inner: Scalar(
width: 4,
value: Float(1.2000000476837158),
),
),
(
name: Some("c_scale"),
specialization: None,
inner: Scalar(
width: 4,
value: Float(1.2000000476837158),
),
),
(
name: None,
specialization: None,
inner: Scalar(
width: 4,
value: Float(0),
),
),
(
name: None,
specialization: None,
inner: Scalar(
width: 4,
value: Float(1),
),
),
],
global_variables: [
(
name: Some("a_pos"),
class: Input,
binding: Some(Location(0)),
ty: 2,
init: None,
interpolation: None,
storage_access: (
bits: 0,
),
),
(
name: Some("a_uv"),
class: Input,
binding: Some(Location(1)),
ty: 2,
init: None,
interpolation: None,
storage_access: (
bits: 0,
),
),
(
name: Some("v_uv"),
class: Output,
binding: Some(Location(0)),
ty: 2,
init: None,
interpolation: None,
storage_access: (
bits: 0,
),
),
(
name: Some("gl_Position"),
class: Output,
binding: Some(BuiltIn(Position)),
ty: 3,
init: None,
interpolation: None,
storage_access: (
bits: 0,
),
),
(
name: Some("v_uv"),
class: Input,
binding: Some(Location(0)),
ty: 2,
init: None,
interpolation: None,
storage_access: (
bits: 0,
),
),
(
name: Some("o_color"),
class: Output,
binding: Some(Location(0)),
ty: 3,
init: None,
interpolation: None,
storage_access: (
bits: 0,
),
),
],
functions: [],
entry_points: {
(Fragment, "frag_main"): (
early_depth_test: None,
workgroup_size: (0, 0, 0),
function: (
name: Some("frag_main"),
arguments: [],
return_type: None,
local_variables: [],
expressions: [
GlobalVariable(1),
GlobalVariable(2),
GlobalVariable(3),
GlobalVariable(4),
GlobalVariable(5),
GlobalVariable(6),
Constant(2),
Constant(4),
Constant(4),
Constant(4),
Constant(4),
Compose(
ty: 3,
components: [
8,
9,
10,
11,
],
),
],
body: [
Store(
pointer: 6,
value: 12,
),
Return(
value: None,
),
],
),
),
(Vertex, "vert_main"): (
early_depth_test: None,
workgroup_size: (0, 0, 0),
function: (
name: Some("vert_main"),
arguments: [],
return_type: None,
local_variables: [],
expressions: [
Constant(1),
Constant(2),
GlobalVariable(1),
GlobalVariable(2),
GlobalVariable(3),
Constant(2),
GlobalVariable(4),
Binary(
op: Multiply,
left: 6,
right: 3,
),
Constant(3),
Constant(4),
Compose(
ty: 3,
components: [
8,
9,
10,
],
),
],
body: [
Store(
pointer: 5,
value: 4,
),
Store(
pointer: 7,
value: 11,
),
Return(
value: None,
),
],
),
),
},
)

View File

@ -1,63 +0,0 @@
---
source: tests/snapshots.rs
expression: dis
---
; SPIR-V
; Version: 1.0
; Generator: rspirv
; Bound: 28
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %8 "frag_main" %12
OpEntryPoint Vertex %15 "vert_main" %25 %20 %18 %23
OpExecutionMode %8 OriginUpperLeft
OpSource GLSL 450
OpName %5 "c_scale"
OpName %8 "frag_main"
OpName %12 "o_color"
OpName %8 "frag_main"
OpName %15 "vert_main"
OpName %18 "v_uv"
OpName %20 "a_uv"
OpName %23 "gl_Position"
OpName %25 "a_pos"
OpName %15 "vert_main"
OpDecorate %12 Location 0
OpDecorate %18 Location 0
OpDecorate %20 Location 1
OpDecorate %23 BuiltIn Position
OpDecorate %25 Location 0
%2 = OpTypeVoid
%4 = OpTypeFloat 32
%3 = OpConstant %4 1.2
%5 = OpConstant %4 1.2
%6 = OpConstant %4 0.0
%7 = OpConstant %4 1.0
%9 = OpTypeFunction %2
%11 = OpTypeVector %4 4
%13 = OpTypePointer Output %11
%12 = OpVariable %13 Output
%17 = OpTypeVector %4 2
%19 = OpTypePointer Output %17
%18 = OpVariable %19 Output
%21 = OpTypePointer Input %17
%20 = OpVariable %21 Input
%23 = OpVariable %13 Output
%25 = OpVariable %21 Input
%8 = OpFunction %2 None %9
%10 = OpLabel
%14 = OpCompositeConstruct %11 %7 %7 %7 %7
OpStore %12 %14
OpReturn
OpFunctionEnd
%15 = OpFunction %2 None %9
%16 = OpLabel
%22 = OpLoad %17 %20
OpStore %18 %22
%26 = OpLoad %17 %25
%24 = OpVectorTimesScalar %17 %26 %5
%27 = OpCompositeConstruct %11 %24 %6 %7
OpStore %23 %27
OpReturn
OpFunctionEnd

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: msl
---
#include <metal_stdlib> #include <metal_stdlib>
#include <simd/simd.h> #include <simd/simd.h>
@ -56,4 +52,3 @@ vertex main2Output main2(
const auto _tmp = type10 {v_uv, _.gl_Position, _.gl_PointSize, {_.gl_ClipDistance[0]}}; const auto _tmp = type10 {v_uv, _.gl_Position, _.gl_PointSize, {_.gl_ClipDistance[0]}};
return main2Output { _tmp.member, _tmp.gl_Position1, _tmp.gl_PointSize1, {_tmp.gl_ClipDistance1[0]} }; return main2Output { _tmp.member, _tmp.gl_Position1, _tmp.gl_PointSize1, {_tmp.gl_ClipDistance1[0]} };
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: string
---
#version 310 es #version 310 es
precision highp float; precision highp float;
@ -26,4 +22,3 @@ void main() {
return; return;
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: string
---
#version 310 es #version 310 es
precision highp float; precision highp float;
@ -26,4 +22,3 @@ void main() {
return; return;
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: string
---
digraph Module { digraph Module {
subgraph cluster_globals { subgraph cluster_globals {
label="Globals" label="Globals"
@ -108,4 +104,3 @@ digraph Module {
ep1_s8 -> ep1_e9 [ style=dotted ] ep1_s8 -> ep1_e9 [ style=dotted ]
} }
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: msl
---
#include <metal_stdlib> #include <metal_stdlib>
#include <simd/simd.h> #include <simd/simd.h>
@ -50,4 +46,3 @@ fragment main2Output main2(
} }
return main2Output { _e4.w * _e4 }; return main2Output { _e4.w * _e4 };
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: dis
---
; SPIR-V ; SPIR-V
; Version: 1.0 ; Version: 1.0
; Generator: rspirv ; Generator: rspirv
@ -118,4 +114,4 @@ OpKill
%64 = OpVectorTimesScalar %8 %57 %63 %64 = OpVectorTimesScalar %8 %57 %63
OpStore %50 %64 OpStore %50 %64
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: string
---
#version 310 es #version 310 es
precision highp float; precision highp float;
@ -53,4 +49,3 @@ void main() {
return; return;
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: output
---
( (
functions: [ functions: [
( (
@ -2873,4 +2869,4 @@ expression: output
], ],
), ),
], ],
) )

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: msl
---
#include <metal_stdlib> #include <metal_stdlib>
#include <simd/simd.h> #include <simd/simd.h>
@ -67,4 +63,3 @@ fragment fs_mainOutput fs_main(
} }
return fs_mainOutput { metal::float4(color1, 1.0) }; return fs_mainOutput { metal::float4(color1, 1.0) };
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: output
---
( (
types: [ types: [
( (
@ -1572,4 +1568,4 @@ expression: output
), ),
), ),
], ],
) )

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: dis
---
; SPIR-V ; SPIR-V
; Version: 1.2 ; Version: 1.2
; Generator: rspirv ; Generator: rspirv
@ -209,4 +205,4 @@ OpBranch %87
%135 = OpCompositeConstruct %16 %134 %5 %135 = OpCompositeConstruct %16 %134 %5
OpStore %79 %135 OpStore %79 %135
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: string
---
#version 310 es #version 310 es
precision highp float; precision highp float;
@ -23,4 +19,3 @@ void main() {
return; return;
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: string
---
#version 310 es #version 310 es
precision highp float; precision highp float;
@ -34,4 +30,3 @@ void main() {
return; return;
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: msl
---
#include <metal_stdlib> #include <metal_stdlib>
#include <simd/simd.h> #include <simd/simd.h>
@ -61,4 +57,3 @@ fragment fs_mainOutput fs_main(
metal::float4 _e5 = r_texture.sample(r_sampler, in.uv); metal::float4 _e5 = r_texture.sample(r_sampler, in.uv);
return fs_mainOutput { _e5 }; return fs_mainOutput { _e5 };
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: dis
---
; SPIR-V ; SPIR-V
; Version: 1.0 ; Version: 1.0
; Generator: rspirv ; Generator: rspirv
@ -154,4 +150,4 @@ OpBranch %106
%110 = OpImageSampleImplicitLod %10 %109 %107 %110 = OpImageSampleImplicitLod %10 %109 %107
OpStore %102 %110 OpStore %102 %110
OpReturn OpReturn
OpFunctionEnd OpFunctionEnd

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: msl
---
#include <metal_stdlib> #include <metal_stdlib>
#include <simd/simd.h> #include <simd/simd.h>
@ -31,4 +27,3 @@ fragment main1Output main1(
return main1Output { _e10 }; return main1Output { _e10 };
} }
} }

View File

@ -1,7 +1,3 @@
---
source: tests/snapshots.rs
expression: dis
---
; SPIR-V ; SPIR-V
; Version: 1.5 ; Version: 1.5
; Generator: rspirv ; Generator: rspirv
@ -82,4 +78,4 @@ OpStore %22 %44
OpReturn OpReturn
%37 = OpLabel %37 = OpLabel
OpBranch %29 OpBranch %29
OpFunctionEnd OpFunctionEnd

View File

@ -1,3 +1,11 @@
//TODO: move this to a binary target once Rust supports
// binary-specific dependencies.
use std::{fs, path::PathBuf};
const DIR_IN: &str = "tests/in";
const DIR_OUT: &str = "tests/out";
bitflags::bitflags! { bitflags::bitflags! {
struct Targets: u32 { struct Targets: u32 {
const IR = 0x1; const IR = 0x1;
@ -27,17 +35,10 @@ struct Parameters {
msl_custom: bool, msl_custom: bool,
} }
#[allow(dead_code)]
fn with_snapshot_settings<F: FnOnce() -> ()>(snapshot_assertion: F) {
let mut settings = insta::Settings::new();
settings.set_snapshot_path("out");
settings.set_prepend_module_to_snapshot(false);
settings.bind(|| snapshot_assertion());
}
#[allow(dead_code, unused_variables)] #[allow(dead_code, unused_variables)]
fn check_targets(module: &naga::Module, name: &str, targets: Targets) { fn check_targets(module: &naga::Module, name: &str, targets: Targets) {
let params = match std::fs::read_to_string(format!("tests/in/{}{}", name, ".param.ron")) { let root = env!("CARGO_MANIFEST_DIR");
let params = match fs::read_to_string(format!("{}/{}/{}.param.ron", root, DIR_IN, name)) {
Ok(string) => ron::de::from_str(&string).expect("Couldn't find param file"), Ok(string) => ron::de::from_str(&string).expect("Couldn't find param file"),
Err(_) => Parameters::default(), Err(_) => Parameters::default(),
}; };
@ -45,41 +46,39 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) {
.validate(module) .validate(module)
.unwrap(); .unwrap();
let dest = PathBuf::from(root).join(DIR_OUT).join(name);
#[cfg(feature = "serialize")] #[cfg(feature = "serialize")]
{ {
if targets.contains(Targets::IR) { if targets.contains(Targets::IR) {
let config = ron::ser::PrettyConfig::default().with_new_line("\n".to_string()); let config = ron::ser::PrettyConfig::default().with_new_line("\n".to_string());
let output = ron::ser::to_string_pretty(module, config).unwrap(); let string = ron::ser::to_string_pretty(module, config).unwrap();
with_snapshot_settings(|| { fs::write(dest.with_extension("ron"), string).unwrap();
insta::assert_snapshot!(format!("{}.ron", name), output);
});
} }
if targets.contains(Targets::ANALYSIS) { if targets.contains(Targets::ANALYSIS) {
let config = ron::ser::PrettyConfig::default().with_new_line("\n".to_string()); let config = ron::ser::PrettyConfig::default().with_new_line("\n".to_string());
let output = ron::ser::to_string_pretty(&info, config).unwrap(); let string = ron::ser::to_string_pretty(&info, config).unwrap();
with_snapshot_settings(|| { fs::write(dest.with_extension("info.ron"), string).unwrap();
insta::assert_snapshot!(format!("{}.info.ron", name), output);
});
} }
} }
#[cfg(feature = "spv-out")] #[cfg(feature = "spv-out")]
{ {
if targets.contains(Targets::SPIRV) { if targets.contains(Targets::SPIRV) {
check_output_spv(module, &info, name, &params); check_output_spv(module, &info, &dest, &params);
} }
} }
#[cfg(feature = "msl-out")] #[cfg(feature = "msl-out")]
{ {
if targets.contains(Targets::METAL) { if targets.contains(Targets::METAL) {
check_output_msl(module, &info, name, &params); check_output_msl(module, &info, &dest, &params);
} }
} }
#[cfg(feature = "glsl-out")] #[cfg(feature = "glsl-out")]
{ {
if targets.contains(Targets::GLSL) { if targets.contains(Targets::GLSL) {
for ep in module.entry_points.iter() { for ep in module.entry_points.iter() {
check_output_glsl(module, &info, name, ep.stage, &ep.name); check_output_glsl(module, &info, &dest, ep.stage, &ep.name);
} }
} }
} }
@ -87,15 +86,13 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) {
{ {
if targets.contains(Targets::DOT) { if targets.contains(Targets::DOT) {
let string = naga::back::dot::write(module, Some(&info)).unwrap(); let string = naga::back::dot::write(module, Some(&info)).unwrap();
with_snapshot_settings(|| { fs::write(dest.with_extension("dot"), string).unwrap();
insta::assert_snapshot!(format!("{}.dot", name), string);
});
} }
} }
#[cfg(feature = "hlsl-out")] #[cfg(feature = "hlsl-out")]
{ {
if targets.contains(Targets::HLSL) { if targets.contains(Targets::HLSL) {
check_output_hlsl(module, name); check_output_hlsl(module, &dest);
} }
} }
} }
@ -104,7 +101,7 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) {
fn check_output_spv( fn check_output_spv(
module: &naga::Module, module: &naga::Module,
info: &naga::valid::ModuleInfo, info: &naga::valid::ModuleInfo,
name: &str, destination: &PathBuf,
params: &Parameters, params: &Parameters,
) { ) {
use naga::back::spv; use naga::back::spv;
@ -128,16 +125,15 @@ fn check_output_spv(
let dis = rspirv::dr::load_words(spv) let dis = rspirv::dr::load_words(spv)
.expect("Produced invalid SPIR-V") .expect("Produced invalid SPIR-V")
.disassemble(); .disassemble();
with_snapshot_settings(|| {
insta::assert_snapshot!(format!("{}.spvasm", name), dis); fs::write(destination.with_extension("spvasm"), dis).unwrap();
});
} }
#[cfg(feature = "msl-out")] #[cfg(feature = "msl-out")]
fn check_output_msl( fn check_output_msl(
module: &naga::Module, module: &naga::Module,
info: &naga::valid::ModuleInfo, info: &naga::valid::ModuleInfo,
name: &str, destination: &PathBuf,
params: &Parameters, params: &Parameters,
) { ) {
use naga::back::msl; use naga::back::msl;
@ -148,7 +144,7 @@ fn check_output_msl(
let options = &params.msl; let options = &params.msl;
#[cfg(not(feature = "deserialize"))] #[cfg(not(feature = "deserialize"))]
let options = if params.msl_custom { let options = if params.msl_custom {
println!("Skipping {}", name); println!("Skipping {}", destination);
return; return;
} else { } else {
&default_options &default_options
@ -158,18 +154,16 @@ fn check_output_msl(
allow_point_size: true, allow_point_size: true,
}; };
let (msl, _) = msl::write_string(module, info, options, &pipeline_options).unwrap(); let (string, _) = msl::write_string(module, info, options, &pipeline_options).unwrap();
with_snapshot_settings(|| { fs::write(destination.with_extension("msl"), string).unwrap();
insta::assert_snapshot!(format!("{}.msl", name), msl);
});
} }
#[cfg(feature = "glsl-out")] #[cfg(feature = "glsl-out")]
fn check_output_glsl( fn check_output_glsl(
module: &naga::Module, module: &naga::Module,
info: &naga::valid::ModuleInfo, info: &naga::valid::ModuleInfo,
name: &str, destination: &PathBuf,
stage: naga::ShaderStage, stage: naga::ShaderStage,
ep_name: &str, ep_name: &str,
) { ) {
@ -187,25 +181,24 @@ fn check_output_glsl(
let string = String::from_utf8(buffer).unwrap(); let string = String::from_utf8(buffer).unwrap();
with_snapshot_settings(|| { let ext = format!("{:?}.glsl", stage);
insta::assert_snapshot!(format!("{}-{:?}.glsl", name, stage), string); fs::write(destination.with_extension(&ext), string).unwrap();
});
} }
#[cfg(feature = "hlsl-out")] #[cfg(feature = "hlsl-out")]
fn check_output_hlsl(module: &naga::Module, name: &str) { fn check_output_hlsl(module: &naga::Module, destination: &PathBuf) {
use naga::back::hlsl; use naga::back::hlsl;
let hlsl = hlsl::write_string(module).unwrap(); let string = hlsl::write_string(module).unwrap();
with_snapshot_settings(|| {
insta::assert_snapshot!(format!("{}.hlsl", name), hlsl); fs::write(destination.with_extension("hlsl"), string).unwrap();
});
} }
#[cfg(feature = "wgsl-in")] #[cfg(feature = "wgsl-in")]
fn convert_wgsl(name: &str, targets: Targets) { fn convert_wgsl(name: &str, targets: Targets) {
let root = env!("CARGO_MANIFEST_DIR");
let module = naga::front::wgsl::parse_str( let module = naga::front::wgsl::parse_str(
&std::fs::read_to_string(format!("tests/in/{}{}", name, ".wgsl")) &fs::read_to_string(format!("{}/{}/{}.wgsl", root, DIR_IN, name))
.expect("Couldn't find wgsl file"), .expect("Couldn't find wgsl file"),
) )
.unwrap(); .unwrap();
@ -272,8 +265,9 @@ fn convert_wgsl_texture_array() {
#[cfg(feature = "spv-in")] #[cfg(feature = "spv-in")]
fn convert_spv(name: &str, adjust_coordinate_space: bool, targets: Targets) { fn convert_spv(name: &str, adjust_coordinate_space: bool, targets: Targets) {
let root = env!("CARGO_MANIFEST_DIR");
let module = naga::front::spv::parse_u8_slice( let module = naga::front::spv::parse_u8_slice(
&std::fs::read(format!("tests/in/{}{}", name, ".spv")).expect("Couldn't find spv file"), &fs::read(format!("{}/{}/{}.spv", root, DIR_IN, name)).expect("Couldn't find spv file"),
&naga::front::spv::Options { &naga::front::spv::Options {
adjust_coordinate_space, adjust_coordinate_space,
flow_graph_dump_prefix: None, flow_graph_dump_prefix: None,
@ -304,8 +298,9 @@ fn convert_glsl(
entry_points: naga::FastHashMap<String, naga::ShaderStage>, entry_points: naga::FastHashMap<String, naga::ShaderStage>,
_targets: Targets, _targets: Targets,
) { ) {
let root = env!("CARGO_MANIFEST_DIR");
let _module = naga::front::glsl::parse_str( let _module = naga::front::glsl::parse_str(
&std::fs::read_to_string(format!("tests/in/{}{}", name, ".glsl")) &fs::read_to_string(format!("{}/{}/{}.glsl", root, DIR_IN, name))
.expect("Couldn't find glsl file"), .expect("Couldn't find glsl file"),
&naga::front::glsl::Options { &naga::front::glsl::Options {
entry_points, entry_points,