mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-25 16:24:24 +00:00
Remove cargo-insta
This commit is contained in:
parent
f7fdf6b560
commit
c2c93e4ecd
2
.github/workflows/pipeline.yml
vendored
2
.github/workflows/pipeline.yml
vendored
@ -24,6 +24,8 @@ jobs:
|
||||
with:
|
||||
command: test
|
||||
args: --all-features
|
||||
- name: Check snapshots
|
||||
run: git diff --exit-code -- tests/out
|
||||
clippy:
|
||||
name: Clippy
|
||||
runs-on: ubuntu-latest
|
||||
|
@ -46,9 +46,8 @@ name = "convert"
|
||||
path = "bin/convert.rs"
|
||||
|
||||
[dev-dependencies]
|
||||
difference = "2.0"
|
||||
diff = "0.1"
|
||||
ron = "0.6"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
spirv = { package = "spirv_headers", version = "1.5", features = ["deserialize"] }
|
||||
insta = { version = "1.6", features = ["glob"] }
|
||||
rspirv = "0.7"
|
||||
|
42
Makefile
42
Makefile
@ -26,38 +26,34 @@ clean:
|
||||
%.png: %.dot
|
||||
dot -Tpng $< -o $@
|
||||
|
||||
# A command to remove the '---' YAML document start markers from the snapshots
|
||||
# before passing their contents to a validator.
|
||||
TRIM=sed -e '1d' -e '2,/---/d'
|
||||
|
||||
validate-spv: $(SNAPSHOTS_OUT)/*.spvasm.snap
|
||||
validate-spv: $(SNAPSHOTS_OUT)/*.spvasm
|
||||
@set -e && for file in $^ ; do \
|
||||
echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"}; \
|
||||
$(TRIM) $${file} | spirv-as --target-env vulkan1.0 -o - | spirv-val; \
|
||||
echo "Validating" $${file#"$(SNAPSHOTS_OUT)"}; \
|
||||
cat $${file} | spirv-as --target-env vulkan1.0 -o - | spirv-val; \
|
||||
done
|
||||
|
||||
validate-msl: $(SNAPSHOTS_OUT)/*.msl.snap
|
||||
validate-msl: $(SNAPSHOTS_OUT)/*.msl
|
||||
@set -e && for file in $^ ; do \
|
||||
echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"}; \
|
||||
$(TRIM) $${file} | xcrun -sdk macosx metal -mmacosx-version-min=10.11 -x metal - -o /dev/null; \
|
||||
echo "Validating" $${file#"$(SNAPSHOTS_OUT)"}; \
|
||||
cat $${file} | xcrun -sdk macosx metal -mmacosx-version-min=10.11 -x metal - -o /dev/null; \
|
||||
done
|
||||
|
||||
validate-glsl: $(SNAPSHOTS_OUT)/*.glsl.snap
|
||||
@set -e && for file in $(SNAPSHOTS_OUT)/*-Vertex.glsl.snap ; do \
|
||||
echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"};\
|
||||
$(TRIM) $${file} | glslangValidator --stdin -S vert; \
|
||||
validate-glsl: $(SNAPSHOTS_OUT)/*.glsl
|
||||
@set -e && for file in $(SNAPSHOTS_OUT)/*.Vertex.glsl ; do \
|
||||
echo "Validating" $${file#"$(SNAPSHOTS_OUT)"};\
|
||||
cat $${file} | glslangValidator --stdin -S vert; \
|
||||
done
|
||||
@set -e && for file in $(SNAPSHOTS_OUT)/*-Fragment.glsl.snap ; do \
|
||||
echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"};\
|
||||
$(TRIM) $${file} | glslangValidator --stdin -S frag; \
|
||||
@set -e && for file in $(SNAPSHOTS_OUT)/*.Fragment.glsl ; do \
|
||||
echo "Validating" $${file#"$(SNAPSHOTS_OUT)"};\
|
||||
cat $${file} | glslangValidator --stdin -S frag; \
|
||||
done
|
||||
@set -e && for file in $(SNAPSHOTS_OUT)/*-Compute.glsl.snap ; do \
|
||||
echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"};\
|
||||
$(TRIM) $${file} | glslangValidator --stdin -S comp; \
|
||||
@set -e && for file in $(SNAPSHOTS_OUT)/*.Compute.glsl ; do \
|
||||
echo "Validating" $${file#"$(SNAPSHOTS_OUT)"};\
|
||||
cat $${file} | glslangValidator --stdin -S comp; \
|
||||
done
|
||||
|
||||
validate-dot: $(SNAPSHOTS_OUT)/*.dot.snap
|
||||
validate-dot: $(SNAPSHOTS_OUT)/*.dot
|
||||
@set -e && for file in $^ ; do \
|
||||
echo "Validating" $${file#"$(SNAPSHOTS_OUT)/snapshots__"}; \
|
||||
$(TRIM) $${file} | dot -o /dev/null; \
|
||||
echo "Validating" $${file#"$(SNAPSHOTS_OUT)"}; \
|
||||
cat $${file} | dot -o /dev/null; \
|
||||
done
|
||||
|
@ -44,9 +44,8 @@ cargo run --features wgsl-in,glsl-out -- my_shader.wgsl my_shader.vert --profile
|
||||
## Development workflow
|
||||
|
||||
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.
|
||||
Any changes in the snapshots would then have to be reviewed with `cargo insta review`
|
||||
before being accepted into the code.
|
||||
which will run the unit tests, and also update all the snapshots. You'll see these
|
||||
changes in git before committing the code.
|
||||
|
||||
If working on a particular front-end or back-end, it may be convenient to
|
||||
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-msl # for Metal shaders, requires XCode command-line tools installed
|
||||
make validate-glsl # for OpenGL shaders, requires GLSLang installed
|
||||
make validate-dot # for dot files, requires GraphViz installed
|
||||
```
|
||||
|
114
tests/errors.rs
114
tests/errors.rs
@ -1,99 +1,99 @@
|
||||
#[cfg(feature = "wgsl-in")]
|
||||
macro_rules! err {
|
||||
($value:expr, @$snapshot:literal) => {
|
||||
::insta::assert_snapshot!(
|
||||
naga::front::wgsl::parse_str($value)
|
||||
.expect_err("expected parser error")
|
||||
.emit_to_string(),
|
||||
@$snapshot
|
||||
);
|
||||
};
|
||||
fn check(input: &str, snapshot: &str) {
|
||||
let output = naga::front::wgsl::parse_str(input)
|
||||
.expect_err("expected parser error")
|
||||
.emit_to_string();
|
||||
if output != snapshot {
|
||||
for diff in diff::lines(&output, 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")]
|
||||
#[test]
|
||||
fn function_without_identifier() {
|
||||
err!(
|
||||
check(
|
||||
"fn () {}",
|
||||
@r###"
|
||||
error: expected identifier, found '('
|
||||
┌─ wgsl:1:4
|
||||
│
|
||||
1 │ fn () {}
|
||||
│ ^ expected identifier
|
||||
r###"error: expected identifier, found '('
|
||||
┌─ wgsl:1:4
|
||||
│
|
||||
1 │ fn () {}
|
||||
│ ^ expected identifier
|
||||
|
||||
"###
|
||||
"###,
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "wgsl-in")]
|
||||
#[test]
|
||||
fn invalid_integer() {
|
||||
err!(
|
||||
check(
|
||||
"fn foo([location(1.)] x: i32) {}",
|
||||
@r###"
|
||||
error: expected identifier, found '['
|
||||
┌─ wgsl:1:8
|
||||
│
|
||||
1 │ fn foo([location(1.)] x: i32) {}
|
||||
│ ^ expected identifier
|
||||
r###"error: expected identifier, found '['
|
||||
┌─ wgsl:1:8
|
||||
│
|
||||
1 │ fn foo([location(1.)] x: i32) {}
|
||||
│ ^ expected identifier
|
||||
|
||||
"###
|
||||
"###,
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "wgsl-in")]
|
||||
#[test]
|
||||
fn invalid_float() {
|
||||
err!(
|
||||
check(
|
||||
"let scale: f32 = 1.1.;",
|
||||
@r###"
|
||||
error: expected floating-point literal, found `1.1.`
|
||||
┌─ wgsl:1:18
|
||||
│
|
||||
1 │ let scale: f32 = 1.1.;
|
||||
│ ^^^^ expected floating-point literal
|
||||
r###"error: expected floating-point literal, found `1.1.`
|
||||
┌─ wgsl:1:18
|
||||
│
|
||||
1 │ let scale: f32 = 1.1.;
|
||||
│ ^^^^ expected floating-point literal
|
||||
|
||||
"###
|
||||
"###,
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "wgsl-in")]
|
||||
#[test]
|
||||
fn invalid_scalar_width() {
|
||||
err!(
|
||||
check(
|
||||
"let scale: f32 = 1.1f1000;",
|
||||
@r###"
|
||||
error: invalid width of `1000` for literal
|
||||
┌─ wgsl:1:18
|
||||
│
|
||||
1 │ let scale: f32 = 1.1f1000;
|
||||
│ ^^^^^^^^ invalid width
|
||||
│
|
||||
= note: valid width is 32
|
||||
r###"error: invalid width of `1000` for literal
|
||||
┌─ wgsl:1:18
|
||||
│
|
||||
1 │ let scale: f32 = 1.1f1000;
|
||||
│ ^^^^^^^^ invalid width
|
||||
│
|
||||
= note: valid width is 32
|
||||
|
||||
"###
|
||||
"###,
|
||||
);
|
||||
}
|
||||
|
||||
#[cfg(feature = "wgsl-in")]
|
||||
#[test]
|
||||
fn invalid_accessor() {
|
||||
err!(
|
||||
check(
|
||||
r###"
|
||||
[[stage(vertex)]]
|
||||
fn vs_main() {
|
||||
var color: vec3<f32> = vec3<f32>(1.0, 2.0, 3.0);
|
||||
var i: f32 = color.a;
|
||||
}
|
||||
"###,
|
||||
@r###"
|
||||
error: invalid field accessor `a`
|
||||
┌─ wgsl:5:32
|
||||
│
|
||||
5 │ var i: f32 = color.a;
|
||||
│ ^ invalid accessor
|
||||
[[stage(vertex)]]
|
||||
fn vs_main() {
|
||||
var color: vec3<f32> = vec3<f32>(1.0, 2.0, 3.0);
|
||||
var i: f32 = color.a;
|
||||
}
|
||||
"###,
|
||||
r###"error: invalid field accessor `a`
|
||||
┌─ wgsl:5:24
|
||||
│
|
||||
5 │ var i: f32 = color.a;
|
||||
│ ^ invalid accessor
|
||||
|
||||
"###
|
||||
"###,
|
||||
);
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: msl
|
||||
---
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
@ -101,4 +97,3 @@ kernel void main1(
|
||||
particlesDst.particles[global_invocation_id.x].vel = vVel;
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: dis
|
||||
---
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: rspirv
|
||||
@ -332,4 +328,4 @@ OpStore %200 %199
|
||||
%202 = OpAccessChain %53 %25 %7 %46 %10
|
||||
OpStore %202 %201
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
OpFunctionEnd
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: output
|
||||
---
|
||||
(
|
||||
functions: [
|
||||
(
|
||||
@ -498,4 +494,4 @@ expression: output
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: msl
|
||||
---
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
@ -40,4 +36,3 @@ kernel void main1(
|
||||
v_indices.data[global_id.x] = _e9;
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: output
|
||||
---
|
||||
(
|
||||
types: [
|
||||
(
|
||||
@ -347,4 +343,4 @@ expression: output
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: dis
|
||||
---
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: rspirv
|
||||
@ -109,4 +105,4 @@ OpBranch %50
|
||||
%60 = OpAccessChain %53 %11 %56 %52
|
||||
OpStore %60 %59
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
OpFunctionEnd
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: string
|
||||
---
|
||||
#version 310 es
|
||||
|
||||
precision highp float;
|
||||
@ -13,4 +9,3 @@ void main() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
5
tests/out/empty.hlsl
Normal file
5
tests/out/empty.hlsl
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
void main()
|
||||
{
|
||||
return;
|
||||
}
|
@ -1,11 +0,0 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: hlsl
|
||||
|
||||
---
|
||||
|
||||
void main()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: msl
|
||||
---
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
@ -10,4 +6,3 @@ kernel void main1(
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: dis
|
||||
---
|
||||
; SPIR-V
|
||||
; Version: 1.1
|
||||
; Generator: rspirv
|
||||
@ -18,4 +14,4 @@ OpExecutionMode %4 LocalSize 1 1 1
|
||||
OpBranch %6
|
||||
%6 = OpLabel
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
OpFunctionEnd
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: msl
|
||||
---
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
@ -18,4 +14,3 @@ kernel void main1(
|
||||
image_dst.write(_e13, metal::uint(_e12.x));
|
||||
return;
|
||||
}
|
||||
|
@ -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,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
},
|
||||
)
|
@ -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
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: msl
|
||||
---
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
@ -56,4 +52,3 @@ vertex main2Output main2(
|
||||
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]} };
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: string
|
||||
---
|
||||
#version 310 es
|
||||
|
||||
precision highp float;
|
||||
@ -26,4 +22,3 @@ void main() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: string
|
||||
---
|
||||
#version 310 es
|
||||
|
||||
precision highp float;
|
||||
@ -26,4 +22,3 @@ void main() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: string
|
||||
---
|
||||
digraph Module {
|
||||
subgraph cluster_globals {
|
||||
label="Globals"
|
||||
@ -108,4 +104,3 @@ digraph Module {
|
||||
ep1_s8 -> ep1_e9 [ style=dotted ]
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: msl
|
||||
---
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
@ -50,4 +46,3 @@ fragment main2Output main2(
|
||||
}
|
||||
return main2Output { _e4.w * _e4 };
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: dis
|
||||
---
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: rspirv
|
||||
@ -118,4 +114,4 @@ OpKill
|
||||
%64 = OpVectorTimesScalar %8 %57 %63
|
||||
OpStore %50 %64
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
OpFunctionEnd
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: string
|
||||
---
|
||||
#version 310 es
|
||||
|
||||
precision highp float;
|
||||
@ -53,4 +49,3 @@ void main() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: output
|
||||
---
|
||||
(
|
||||
functions: [
|
||||
(
|
||||
@ -2873,4 +2869,4 @@ expression: output
|
||||
],
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: msl
|
||||
---
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
@ -67,4 +63,3 @@ fragment fs_mainOutput fs_main(
|
||||
}
|
||||
return fs_mainOutput { metal::float4(color1, 1.0) };
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: output
|
||||
---
|
||||
(
|
||||
types: [
|
||||
(
|
||||
@ -1572,4 +1568,4 @@ expression: output
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: dis
|
||||
---
|
||||
; SPIR-V
|
||||
; Version: 1.2
|
||||
; Generator: rspirv
|
||||
@ -209,4 +205,4 @@ OpBranch %87
|
||||
%135 = OpCompositeConstruct %16 %134 %5
|
||||
OpStore %79 %135
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
OpFunctionEnd
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: string
|
||||
---
|
||||
#version 310 es
|
||||
|
||||
precision highp float;
|
||||
@ -23,4 +19,3 @@ void main() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: string
|
||||
---
|
||||
#version 310 es
|
||||
|
||||
precision highp float;
|
||||
@ -34,4 +30,3 @@ void main() {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: msl
|
||||
---
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
@ -61,4 +57,3 @@ fragment fs_mainOutput fs_main(
|
||||
metal::float4 _e5 = r_texture.sample(r_sampler, in.uv);
|
||||
return fs_mainOutput { _e5 };
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: dis
|
||||
---
|
||||
; SPIR-V
|
||||
; Version: 1.0
|
||||
; Generator: rspirv
|
||||
@ -154,4 +150,4 @@ OpBranch %106
|
||||
%110 = OpImageSampleImplicitLod %10 %109 %107
|
||||
OpStore %102 %110
|
||||
OpReturn
|
||||
OpFunctionEnd
|
||||
OpFunctionEnd
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: msl
|
||||
---
|
||||
#include <metal_stdlib>
|
||||
#include <simd/simd.h>
|
||||
|
||||
@ -31,4 +27,3 @@ fragment main1Output main1(
|
||||
return main1Output { _e10 };
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,3 @@
|
||||
---
|
||||
source: tests/snapshots.rs
|
||||
expression: dis
|
||||
---
|
||||
; SPIR-V
|
||||
; Version: 1.5
|
||||
; Generator: rspirv
|
||||
@ -82,4 +78,4 @@ OpStore %22 %44
|
||||
OpReturn
|
||||
%37 = OpLabel
|
||||
OpBranch %29
|
||||
OpFunctionEnd
|
||||
OpFunctionEnd
|
@ -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! {
|
||||
struct Targets: u32 {
|
||||
const IR = 0x1;
|
||||
@ -27,17 +35,10 @@ struct Parameters {
|
||||
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)]
|
||||
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"),
|
||||
Err(_) => Parameters::default(),
|
||||
};
|
||||
@ -45,41 +46,39 @@ fn check_targets(module: &naga::Module, name: &str, targets: Targets) {
|
||||
.validate(module)
|
||||
.unwrap();
|
||||
|
||||
let dest = PathBuf::from(root).join(DIR_OUT).join(name);
|
||||
|
||||
#[cfg(feature = "serialize")]
|
||||
{
|
||||
if targets.contains(Targets::IR) {
|
||||
let config = ron::ser::PrettyConfig::default().with_new_line("\n".to_string());
|
||||
let output = ron::ser::to_string_pretty(module, config).unwrap();
|
||||
with_snapshot_settings(|| {
|
||||
insta::assert_snapshot!(format!("{}.ron", name), output);
|
||||
});
|
||||
let string = ron::ser::to_string_pretty(module, config).unwrap();
|
||||
fs::write(dest.with_extension("ron"), string).unwrap();
|
||||
}
|
||||
if targets.contains(Targets::ANALYSIS) {
|
||||
let config = ron::ser::PrettyConfig::default().with_new_line("\n".to_string());
|
||||
let output = ron::ser::to_string_pretty(&info, config).unwrap();
|
||||
with_snapshot_settings(|| {
|
||||
insta::assert_snapshot!(format!("{}.info.ron", name), output);
|
||||
});
|
||||
let string = ron::ser::to_string_pretty(&info, config).unwrap();
|
||||
fs::write(dest.with_extension("info.ron"), string).unwrap();
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "spv-out")]
|
||||
{
|
||||
if targets.contains(Targets::SPIRV) {
|
||||
check_output_spv(module, &info, name, ¶ms);
|
||||
check_output_spv(module, &info, &dest, ¶ms);
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "msl-out")]
|
||||
{
|
||||
if targets.contains(Targets::METAL) {
|
||||
check_output_msl(module, &info, name, ¶ms);
|
||||
check_output_msl(module, &info, &dest, ¶ms);
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "glsl-out")]
|
||||
{
|
||||
if targets.contains(Targets::GLSL) {
|
||||
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) {
|
||||
let string = naga::back::dot::write(module, Some(&info)).unwrap();
|
||||
with_snapshot_settings(|| {
|
||||
insta::assert_snapshot!(format!("{}.dot", name), string);
|
||||
});
|
||||
fs::write(dest.with_extension("dot"), string).unwrap();
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "hlsl-out")]
|
||||
{
|
||||
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(
|
||||
module: &naga::Module,
|
||||
info: &naga::valid::ModuleInfo,
|
||||
name: &str,
|
||||
destination: &PathBuf,
|
||||
params: &Parameters,
|
||||
) {
|
||||
use naga::back::spv;
|
||||
@ -128,16 +125,15 @@ fn check_output_spv(
|
||||
let dis = rspirv::dr::load_words(spv)
|
||||
.expect("Produced invalid SPIR-V")
|
||||
.disassemble();
|
||||
with_snapshot_settings(|| {
|
||||
insta::assert_snapshot!(format!("{}.spvasm", name), dis);
|
||||
});
|
||||
|
||||
fs::write(destination.with_extension("spvasm"), dis).unwrap();
|
||||
}
|
||||
|
||||
#[cfg(feature = "msl-out")]
|
||||
fn check_output_msl(
|
||||
module: &naga::Module,
|
||||
info: &naga::valid::ModuleInfo,
|
||||
name: &str,
|
||||
destination: &PathBuf,
|
||||
params: &Parameters,
|
||||
) {
|
||||
use naga::back::msl;
|
||||
@ -148,7 +144,7 @@ fn check_output_msl(
|
||||
let options = ¶ms.msl;
|
||||
#[cfg(not(feature = "deserialize"))]
|
||||
let options = if params.msl_custom {
|
||||
println!("Skipping {}", name);
|
||||
println!("Skipping {}", destination);
|
||||
return;
|
||||
} else {
|
||||
&default_options
|
||||
@ -158,18 +154,16 @@ fn check_output_msl(
|
||||
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(|| {
|
||||
insta::assert_snapshot!(format!("{}.msl", name), msl);
|
||||
});
|
||||
fs::write(destination.with_extension("msl"), string).unwrap();
|
||||
}
|
||||
|
||||
#[cfg(feature = "glsl-out")]
|
||||
fn check_output_glsl(
|
||||
module: &naga::Module,
|
||||
info: &naga::valid::ModuleInfo,
|
||||
name: &str,
|
||||
destination: &PathBuf,
|
||||
stage: naga::ShaderStage,
|
||||
ep_name: &str,
|
||||
) {
|
||||
@ -187,25 +181,24 @@ fn check_output_glsl(
|
||||
|
||||
let string = String::from_utf8(buffer).unwrap();
|
||||
|
||||
with_snapshot_settings(|| {
|
||||
insta::assert_snapshot!(format!("{}-{:?}.glsl", name, stage), string);
|
||||
});
|
||||
let ext = format!("{:?}.glsl", stage);
|
||||
fs::write(destination.with_extension(&ext), string).unwrap();
|
||||
}
|
||||
|
||||
#[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;
|
||||
|
||||
let hlsl = hlsl::write_string(module).unwrap();
|
||||
with_snapshot_settings(|| {
|
||||
insta::assert_snapshot!(format!("{}.hlsl", name), hlsl);
|
||||
});
|
||||
let string = hlsl::write_string(module).unwrap();
|
||||
|
||||
fs::write(destination.with_extension("hlsl"), string).unwrap();
|
||||
}
|
||||
|
||||
#[cfg(feature = "wgsl-in")]
|
||||
fn convert_wgsl(name: &str, targets: Targets) {
|
||||
let root = env!("CARGO_MANIFEST_DIR");
|
||||
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"),
|
||||
)
|
||||
.unwrap();
|
||||
@ -272,8 +265,9 @@ fn convert_wgsl_texture_array() {
|
||||
|
||||
#[cfg(feature = "spv-in")]
|
||||
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(
|
||||
&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 {
|
||||
adjust_coordinate_space,
|
||||
flow_graph_dump_prefix: None,
|
||||
@ -304,8 +298,9 @@ fn convert_glsl(
|
||||
entry_points: naga::FastHashMap<String, naga::ShaderStage>,
|
||||
_targets: Targets,
|
||||
) {
|
||||
let root = env!("CARGO_MANIFEST_DIR");
|
||||
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"),
|
||||
&naga::front::glsl::Options {
|
||||
entry_points,
|
||||
|
Loading…
Reference in New Issue
Block a user