From 5b94ecd9b2608ad3c03634498fa3bf0da1850f43 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 8 Feb 2021 12:30:21 -0500 Subject: [PATCH] Add a snapshot for parsing spirv input --- src/front/spv/mod.rs | 2 - src/front/spv/rosetta.rs | 23 - tests/in/shadow.spv | Bin 0 -> 4764 bytes tests/out/shadow.ron.snap | 1150 +++++++++++++++++++++++++++++++++++++ tests/snapshots.rs | 25 + 5 files changed, 1175 insertions(+), 25 deletions(-) delete mode 100644 src/front/spv/rosetta.rs create mode 100644 tests/in/shadow.spv create mode 100644 tests/out/shadow.ron.snap diff --git a/src/front/spv/mod.rs b/src/front/spv/mod.rs index e37f94972e..e13753ab48 100644 --- a/src/front/spv/mod.rs +++ b/src/front/spv/mod.rs @@ -16,8 +16,6 @@ mod error; mod flow; mod function; mod image; -#[cfg(all(test, feature = "serialize"))] -mod rosetta; use convert::*; use error::Error; diff --git a/src/front/spv/rosetta.rs b/src/front/spv/rosetta.rs deleted file mode 100644 index 027c0d0adc..0000000000 --- a/src/front/spv/rosetta.rs +++ /dev/null @@ -1,23 +0,0 @@ -use std::{fs, path::Path}; - -const TEST_PATH: &str = "test-data"; - -fn rosetta_test(file_name: &str) { - if true { - return; //TODO: fix this test - } - let file_path = Path::new(TEST_PATH).join(file_name); - let input = fs::read(&file_path).unwrap(); - - let module = super::parse_u8_slice(&input, &Default::default()).unwrap(); - let output = ron::ser::to_string_pretty(&module, Default::default()).unwrap(); - - let expected = fs::read_to_string(file_path.with_extension("expected.ron")).unwrap(); - - difference::assert_diff!(output.as_str(), expected.as_str(), "", 0); -} - -#[test] -fn simple() { - rosetta_test("simple/simple.spv") -} diff --git a/tests/in/shadow.spv b/tests/in/shadow.spv new file mode 100644 index 0000000000000000000000000000000000000000..265cf65fc08335dfb5180801283e218430a0fd67 GIT binary patch literal 4764 zcmZve2X|Ig7KU$3v499-FPMmq9ebtQ!i;eQdk>!=5KZ#MB z55>5T-{xs5PQ@%rMm{Z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&Hboo2bcQiN#IGeh&I=i;KwmI5LXYl)W9PnInrjyWfFALD; zf_b0|WXx&k8FM=NDZn^+&!8JQ8_4$n^ZXX~g4tpF4mbnU!DZxVpA3wV-8Is8ul4LJWIkn{foJ?B3g{jb0{dGq{U{{_e|269V~ zX94+hfVG_OTp(}EQsf1|eiwr5cM*E_TZVoiEJUjnk>yB7TlV4S>p*C8(l^4ACFH~KOleN}U*wUB25=hL6h z#r^2{TEND0J_O{S1-b9%f;aDF^p}ABUIE$fRrKul8v2XCIC=A4N4@~$ z-w5tac!e-hlM$ajGJXCV81 z9(>;G7ufFEIrRDc^Ine!`n-cB!5xc!9MCs~+nR)w^F4Pk()XM)=l&nMb1x>}d-^Ys p8wJeQCujZvNb?Uwn(qu>1AF-W9fSNPxMrmJUk3LxPmtfEUjed&gEasE literal 0 HcmV?d00001 diff --git a/tests/out/shadow.ron.snap b/tests/out/shadow.ron.snap new file mode 100644 index 0000000000..e42f1c2cef --- /dev/null +++ b/tests/out/shadow.ron.snap @@ -0,0 +1,1150 @@ +--- +source: tests/snapshots.rs +expression: output +--- +( + header: ( + version: (1, 0, 0), + generator: 0, + ), + types: [ + ( + name: None, + inner: Scalar( + kind: Float, + width: 4, + ), + ), + ( + name: None, + inner: Vector( + size: Tri, + kind: Float, + width: 4, + ), + ), + ( + name: None, + inner: Scalar( + kind: Uint, + width: 4, + ), + ), + ( + name: None, + inner: Vector( + size: Quad, + kind: Float, + width: 4, + ), + ), + ( + name: None, + inner: Scalar( + kind: Bool, + width: 1, + ), + ), + ( + name: None, + inner: Vector( + size: Bi, + kind: Float, + width: 4, + ), + ), + ( + name: None, + inner: Image( + dim: D2, + arrayed: true, + class: Sampled( + kind: Float, + multi: false, + ), + ), + ), + ( + name: None, + inner: Sampler( + comparison: false, + ), + ), + ( + name: None, + inner: Vector( + size: Bi, + kind: Float, + width: 4, + ), + ), + ( + name: None, + inner: Scalar( + kind: Sint, + width: 4, + ), + ), + ( + name: None, + inner: Vector( + size: Quad, + kind: Uint, + width: 4, + ), + ), + ( + name: Some("Globals"), + inner: Struct( + block: true, + members: [ + ( + name: Some("num_lights"), + span: None, + ty: 11, + ), + ], + ), + ), + ( + name: None, + inner: Matrix( + columns: Quad, + rows: Quad, + width: 4, + ), + ), + ( + name: Some("Light"), + inner: Struct( + block: true, + members: [ + ( + name: Some("proj"), + span: None, + ty: 13, + ), + ( + name: Some("pos"), + span: None, + ty: 4, + ), + ( + name: Some("color"), + span: None, + ty: 4, + ), + ], + ), + ), + ( + name: None, + inner: Array( + base: 14, + size: Dynamic, + stride: Some(96), + ), + ), + ( + name: Some("Lights"), + inner: Struct( + block: true, + members: [ + ( + name: Some("data"), + span: None, + ty: 15, + ), + ], + ), + ), + ( + name: None, + inner: Image( + dim: D2, + arrayed: true, + class: Depth, + ), + ), + ( + name: None, + inner: Sampler( + comparison: true, + ), + ), + ], + constants: [ + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Float(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Float(1), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Float(0.5), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Float(-0.5), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Float(0.05000000074505806), + ), + ), + ( + name: None, + specialization: None, + inner: Composite( + ty: 2, + components: [ + 5, + 5, + 5, + ], + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Uint(10), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Uint(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Uint(1), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Float(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(1), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(1), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(1), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(1), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(2), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(1), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(2), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(2), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(2), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(1), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(0), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(2), + ), + ), + ( + name: None, + specialization: None, + inner: Scalar( + width: 4, + value: Sint(2), + ), + ), + ], + global_variables: [ + ( + name: Some("t_shadow"), + class: Handle, + binding: Some(Resource( + group: 0, + binding: 2, + )), + ty: 17, + init: None, + interpolation: None, + storage_access: ( + bits: 0, + ), + ), + ( + name: Some("sampler_shadow"), + class: Handle, + binding: Some(Resource( + group: 0, + binding: 3, + )), + ty: 18, + init: None, + interpolation: None, + storage_access: ( + bits: 0, + ), + ), + ( + name: Some("u_globals"), + class: Uniform, + binding: Some(Resource( + group: 0, + binding: 0, + )), + ty: 12, + init: None, + interpolation: None, + storage_access: ( + bits: 0, + ), + ), + ( + name: Some("s_lights"), + class: Storage, + binding: Some(Resource( + group: 0, + binding: 1, + )), + ty: 16, + init: None, + interpolation: None, + storage_access: ( + bits: 1, + ), + ), + ( + name: Some("in_position_fs"), + class: Input, + binding: Some(Location(1)), + ty: 4, + init: None, + interpolation: None, + storage_access: ( + bits: 0, + ), + ), + ( + name: Some("in_normal_fs"), + class: Input, + binding: Some(Location(0)), + ty: 2, + init: None, + interpolation: None, + storage_access: ( + bits: 0, + ), + ), + ( + name: Some("out_color_fs"), + class: Output, + binding: Some(Location(0)), + ty: 4, + init: None, + interpolation: None, + storage_access: ( + bits: 0, + ), + ), + ], + functions: [ + ( + name: None, + arguments: [ + ( + name: None, + ty: 3, + ), + ( + name: None, + ty: 4, + ), + ], + return_type: Some(1), + global_usage: [ + ( + bits: 1, + ), + ( + bits: 1, + ), + ( + bits: 0, + ), + ( + bits: 0, + ), + ( + bits: 0, + ), + ( + bits: 0, + ), + ( + bits: 0, + ), + ], + local_variables: [], + expressions: [ + GlobalVariable(3), + GlobalVariable(6), + GlobalVariable(5), + GlobalVariable(1), + GlobalVariable(2), + GlobalVariable(4), + GlobalVariable(7), + Constant(16), + Constant(3), + Constant(29), + Constant(27), + Constant(25), + Constant(23), + Constant(21), + Constant(11), + Constant(8), + Constant(19), + Constant(4), + Constant(32), + Constant(30), + Constant(10), + Constant(28), + Constant(26), + Constant(13), + Constant(22), + Constant(35), + Constant(9), + Constant(7), + Constant(5), + Constant(2), + Constant(17), + Constant(31), + Constant(15), + Constant(33), + Constant(14), + Constant(24), + Constant(12), + Constant(20), + Constant(34), + Constant(18), + Constant(6), + Constant(1), + FunctionArgument(0), + FunctionArgument(1), + AccessIndex( + base: 44, + index: 3, + ), + Binary( + op: LessEqual, + left: 45, + right: 42, + ), + AccessIndex( + base: 44, + index: 0, + ), + AccessIndex( + base: 44, + index: 1, + ), + Compose( + ty: 9, + components: [ + 47, + 48, + ], + ), + Compose( + ty: 9, + components: [ + 9, + 18, + ], + ), + Binary( + op: Multiply, + left: 49, + right: 50, + ), + AccessIndex( + base: 44, + index: 3, + ), + Binary( + op: Divide, + left: 30, + right: 52, + ), + Binary( + op: Multiply, + left: 51, + right: 53, + ), + Compose( + ty: 9, + components: [ + 9, + 9, + ], + ), + Binary( + op: Add, + left: 54, + right: 55, + ), + AccessIndex( + base: 56, + index: 0, + ), + AccessIndex( + base: 56, + index: 1, + ), + As( + expr: 43, + kind: Sint, + convert: false, + ), + As( + expr: 59, + kind: Float, + convert: true, + ), + Compose( + ty: 2, + components: [ + 57, + 58, + 60, + ], + ), + AccessIndex( + base: 44, + index: 2, + ), + AccessIndex( + base: 44, + index: 3, + ), + Binary( + op: Divide, + left: 30, + right: 63, + ), + Binary( + op: Multiply, + left: 62, + right: 64, + ), + AccessIndex( + base: 61, + index: 0, + ), + AccessIndex( + base: 61, + index: 1, + ), + Compose( + ty: 6, + components: [ + 66, + 67, + ], + ), + AccessIndex( + base: 61, + index: 2, + ), + As( + expr: 69, + kind: Uint, + convert: true, + ), + ImageSample( + image: 4, + sampler: 5, + coordinate: 68, + array_index: Some(70), + offset: None, + level: Exact(21), + depth_ref: Some(65), + ), + ], + body: [ + If( + condition: 46, + accept: [ + Return( + value: Some(30), + ), + ], + reject: [], + ), + Return( + value: Some(71), + ), + ], + ), + ], + entry_points: { + (Fragment, "fs_main"): ( + early_depth_test: None, + workgroup_size: (0, 0, 0), + function: ( + name: Some("fs_main"), + arguments: [], + return_type: None, + global_usage: [ + ( + bits: 0, + ), + ( + bits: 0, + ), + ( + bits: 1, + ), + ( + bits: 1, + ), + ( + bits: 1, + ), + ( + bits: 1, + ), + ( + bits: 2, + ), + ], + local_variables: [ + ( + name: Some("color"), + ty: 2, + init: Some(6), + ), + ( + name: Some("i"), + ty: 3, + init: Some(8), + ), + ], + expressions: [ + GlobalVariable(3), + GlobalVariable(6), + GlobalVariable(5), + GlobalVariable(1), + GlobalVariable(2), + GlobalVariable(4), + GlobalVariable(7), + Constant(16), + Constant(3), + Constant(29), + Constant(27), + Constant(25), + Constant(23), + Constant(21), + Constant(11), + Constant(8), + Constant(19), + Constant(4), + Constant(32), + Constant(30), + Constant(10), + Constant(28), + Constant(26), + Constant(13), + Constant(22), + Constant(35), + Constant(9), + Constant(7), + Constant(5), + Constant(2), + Constant(17), + Constant(31), + Constant(15), + Constant(33), + Constant(14), + Constant(24), + Constant(12), + Constant(20), + Constant(34), + Constant(18), + Constant(6), + Constant(1), + LocalVariable(1), + LocalVariable(2), + AccessIndex( + base: 1, + index: 0, + ), + Access( + base: 45, + index: 37, + ), + Math( + fun: Min, + arg: 46, + arg1: Some(28), + arg2: None, + ), + Binary( + op: GreaterEqual, + left: 44, + right: 47, + ), + AccessIndex( + base: 6, + index: 0, + ), + Access( + base: 49, + index: 44, + ), + AccessIndex( + base: 50, + index: 0, + ), + Binary( + op: Multiply, + left: 51, + right: 3, + ), + Call( + function: 1, + arguments: [ + 44, + 52, + ], + ), + Math( + fun: Normalize, + arg: 2, + arg1: None, + arg2: None, + ), + AccessIndex( + base: 6, + index: 0, + ), + Access( + base: 55, + index: 44, + ), + AccessIndex( + base: 56, + index: 1, + ), + Access( + base: 57, + index: 31, + ), + AccessIndex( + base: 6, + index: 0, + ), + Access( + base: 59, + index: 44, + ), + AccessIndex( + base: 60, + index: 1, + ), + Access( + base: 61, + index: 38, + ), + AccessIndex( + base: 6, + index: 0, + ), + Access( + base: 63, + index: 44, + ), + AccessIndex( + base: 64, + index: 1, + ), + Access( + base: 65, + index: 13, + ), + Compose( + ty: 2, + components: [ + 58, + 62, + 66, + ], + ), + Access( + base: 3, + index: 36, + ), + Access( + base: 3, + index: 12, + ), + Access( + base: 3, + index: 23, + ), + Compose( + ty: 2, + components: [ + 68, + 69, + 70, + ], + ), + Binary( + op: Subtract, + left: 67, + right: 71, + ), + Math( + fun: Normalize, + arg: 72, + arg1: None, + arg2: None, + ), + Math( + fun: Dot, + arg: 54, + arg1: Some(73), + arg2: None, + ), + Math( + fun: Max, + arg: 42, + arg1: Some(74), + arg2: None, + ), + Binary( + op: Multiply, + left: 53, + right: 75, + ), + AccessIndex( + base: 6, + index: 0, + ), + Access( + base: 77, + index: 44, + ), + AccessIndex( + base: 78, + index: 2, + ), + Access( + base: 79, + index: 10, + ), + AccessIndex( + base: 6, + index: 0, + ), + Access( + base: 81, + index: 44, + ), + AccessIndex( + base: 82, + index: 2, + ), + Access( + base: 83, + index: 19, + ), + AccessIndex( + base: 6, + index: 0, + ), + Access( + base: 85, + index: 44, + ), + AccessIndex( + base: 86, + index: 2, + ), + Access( + base: 87, + index: 26, + ), + Compose( + ty: 2, + components: [ + 80, + 84, + 88, + ], + ), + Binary( + op: Multiply, + left: 89, + right: 76, + ), + Binary( + op: Add, + left: 43, + right: 90, + ), + Binary( + op: Add, + left: 44, + right: 27, + ), + Compose( + ty: 4, + components: [ + 43, + 30, + ], + ), + ], + body: [ + Loop( + body: [ + If( + condition: 48, + accept: [ + Break, + ], + reject: [], + ), + Store( + pointer: 43, + value: 91, + ), + Store( + pointer: 44, + value: 92, + ), + Continue, + ], + continuing: [ + Store( + pointer: 44, + value: 92, + ), + ], + ), + Store( + pointer: 7, + value: 93, + ), + Return( + value: None, + ), + ], + ), + ), + }, +) diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 934160c5c5..40b472fb56 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -208,3 +208,28 @@ fn convert_wgsl_shadow() { fn convert_wgsl_texture_array() { convert_wgsl("texture-array", Language::SPIRV); } + +#[cfg(feature = "spv-in")] +fn convert_spv(name: &str) { + let module = naga::front::spv::parse_u8_slice( + &std::fs::read(format!("tests/in/{}{}", name, ".spv")).expect("Couldn't find spv file"), + &Default::default(), + ) + .unwrap(); + naga::proc::Validator::new().validate(&module).unwrap(); + + #[cfg(feature = "serialize")] + { + let config = ron::ser::PrettyConfig::default(); + let output = ron::ser::to_string_pretty(&module, config).unwrap(); + with_snapshot_settings(|| { + insta::assert_snapshot!(format!("{}.ron", name), output); + }); + } +} + +#[cfg(feature = "spv-in")] +#[test] +fn convert_spv_shadow() { + convert_spv("shadow"); +}