From d031749c13654953b294fc705c9173a5d4fdd124 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Thu, 17 Dec 2020 15:40:15 +0100 Subject: [PATCH 1/3] Fix assembler and validte cli args, opt threw me off --- src/assembler/tool.rs | 2 +- src/opt/tool.rs | 4 ++++ src/val/tool.rs | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/assembler/tool.rs b/src/assembler/tool.rs index 87ae224..b8a0d7a 100644 --- a/src/assembler/tool.rs +++ b/src/assembler/tool.rs @@ -15,7 +15,7 @@ impl Assembler for ToolAssembler { options: super::AssemblerOptions, ) -> Result { let mut cmd = std::process::Command::new("spirv-as"); - cmd.arg(format!("--target-env={}", self.target_env)); + cmd.arg("--target-env").arg(self.target_env.to_string()); if options.preserve_numeric_ids { cmd.arg("--preserve-numeric-ids"); diff --git a/src/opt/tool.rs b/src/opt/tool.rs index b714a2d..4ca1a98 100644 --- a/src/opt/tool.rs +++ b/src/opt/tool.rs @@ -28,6 +28,10 @@ impl Optimizer for ToolOptimizer { options: Option, ) -> Result { let mut cmd = std::process::Command::new("spirv-opt"); + + // Note here that we don't do cmd.arg("--target-env").arg(self.target_env.to_string()); + // like with the other tools, because opt is "special" and will fail to parse + // command line options correctly if we don't give join them with the = cmd.arg(format!("--target-env={}", self.target_env)); cmd.args( diff --git a/src/val/tool.rs b/src/val/tool.rs index 1b523ed..b8b941a 100644 --- a/src/val/tool.rs +++ b/src/val/tool.rs @@ -19,7 +19,7 @@ impl Validator for ToolValidator { ) -> Result<(), crate::error::Error> { let mut cmd = Command::new("spirv-val"); - cmd.arg(format!("--target-env={}", self.target_env)); + cmd.arg("--target-env").arg(self.target_env.to_string()); if let Some(opts) = options { // We reuse add options when we run the validator before optimizing, From 4024deccf53f71a2ddf02b11758281e08b260a72 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Thu, 17 Dec 2020 15:40:23 +0100 Subject: [PATCH 2/3] Add assembler test --- Cargo.toml | 4 + tests/assembler.rs | 35 ++++++ tests/test_content.txt | 248 ++--------------------------------------- 3 files changed, 49 insertions(+), 238 deletions(-) create mode 100644 tests/assembler.rs diff --git a/Cargo.toml b/Cargo.toml index a9ed974..60a136a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,3 +37,7 @@ required-features = ["use-compiled-tools"] [[test]] name = "optimizer" required-features = ["use-compiled-tools", "use-installed-tools"] + +[[test]] +name = "assembler" +required-features = ["use-compiled-tools", "use-installed-tools"] diff --git a/tests/assembler.rs b/tests/assembler.rs new file mode 100644 index 0000000..b940b9e --- /dev/null +++ b/tests/assembler.rs @@ -0,0 +1,35 @@ +//const TEXT_INPUT: &str = include_str!("test_content.txt"); +const ASSEMBLY_INPUT: &str = include_str!("test_content.txt"); + +use spirv_tools as spv; + +use spv::{assembler::Assembler, val::Validator}; +use std::convert::TryFrom; + +#[test] +fn assemblers_match() { + let mut cas = spv::assembler::compiled::CompiledAssembler::default(); + let mut ias = spv::assembler::tool::ToolAssembler::default(); + + let mut cval = spv::val::compiled::CompiledValidator::default(); + let mut ival = spv::val::tool::ToolValidator::default(); + + let cassembled = cas + .assemble(ASSEMBLY_INPUT, spv::assembler::AssemblerOptions::default()) + .expect("compiled failed to assemble"); + let iassembled = ias + .assemble(ASSEMBLY_INPUT, spv::assembler::AssemblerOptions::default()) + .expect("tool failed to assemble"); + + cval.validate(&cassembled, None) + .expect("failed to validate input assembly"); + + ival.validate(&cassembled, None) + .expect("failed to validate input assembly"); + + cval.validate(&iassembled, None) + .expect("failed to validate input assembly"); + + ival.validate(&iassembled, None) + .expect("failed to validate input assembly"); +} diff --git a/tests/test_content.txt b/tests/test_content.txt index 8acf9d0..6b28d3c 100644 --- a/tests/test_content.txt +++ b/tests/test_content.txt @@ -1,238 +1,10 @@ -; SPIR-V -; Version: 1.0 -; Generator: Google rspirv; 0 -; Bound: 145 -; Schema: 0 - OpCapability Shader - OpCapability VariablePointers - OpCapability DerivativeControl - OpExtension "SPV_KHR_variable_pointers" - OpMemoryModel Logical GLSL450 - OpEntryPoint Fragment %1 "main_fs" %out_color %frag_coord - OpExecutionMode %1 OriginUpperLeft - OpName %Uniforms "Uniforms" - OpMemberName %Uniforms 0 "resolution" - OpMemberName %Uniforms 1 "mouse" - OpMemberName %Uniforms 2 "date" - OpMemberName %Uniforms 3 "time" - OpMemberName %Uniforms 4 "sample_rate" - OpMemberName %Uniforms 5 "frame" - OpMemberName %Uniforms 6 "time_delta" - OpMemberName %Uniforms 7 "frame_rate" - OpMemberName %Uniforms 8 "channel_time" - OpMemberName %Uniforms 9 "channel_resolution" - OpName %_minimal__Uniforms___main_image "::main_image" - OpName %out_color "out_color" - OpName %frag_coord "frag_coord" - OpName %iChannel0 "iChannel0" - OpName %iChannel1 "iChannel1" - OpName %iChannel2 "iChannel2" - OpName %iChannel3 "iChannel3" - OpName %iResolution "iResolution" - OpName %iTime "iTime" - OpName %iMouse "iMouse" - OpName %iDate "iDate" - OpName %iSampleRate "iSampleRate" - OpName %iFrame "iFrame" - OpName %iTimeDelta "iTimeDelta" - OpName %iFrameRate "iFrameRate" - OpName %iChannelTime "iChannelTime" - OpName %iChannelResolution "iChannelResolution" - OpDecorate %_arr_v3float_uint_4 ArrayStride 16 - OpDecorate %_arr_float_uint_4 ArrayStride 4 - OpMemberDecorate %Uniforms 0 Offset 0 - OpMemberDecorate %Uniforms 1 Offset 16 - OpMemberDecorate %Uniforms 2 Offset 32 - OpMemberDecorate %Uniforms 3 Offset 48 - OpMemberDecorate %Uniforms 4 Offset 52 - OpMemberDecorate %Uniforms 5 Offset 56 - OpMemberDecorate %Uniforms 6 Offset 60 - OpMemberDecorate %Uniforms 7 Offset 64 - OpMemberDecorate %Uniforms 8 Offset 68 - OpMemberDecorate %Uniforms 9 Offset 96 - OpDecorate %out_color Location 0 - OpDecorate %frag_coord BuiltIn FragCoord - OpDecorate %iChannel0 DescriptorSet 1 - OpDecorate %iChannel1 DescriptorSet 1 - OpDecorate %iChannel2 DescriptorSet 1 - OpDecorate %iChannel3 DescriptorSet 1 - OpDecorate %iResolution DescriptorSet 1 - OpDecorate %iTime DescriptorSet 1 - OpDecorate %iMouse DescriptorSet 1 - OpDecorate %iDate DescriptorSet 1 - OpDecorate %iSampleRate DescriptorSet 1 - OpDecorate %iFrame DescriptorSet 1 - OpDecorate %iTimeDelta DescriptorSet 1 - OpDecorate %iFrameRate DescriptorSet 1 - OpDecorate %iChannelTime DescriptorSet 1 - OpDecorate %iChannelResolution DescriptorSet 1 - %float = OpTypeFloat 32 - %v3float = OpTypeVector %float 3 - %uint = OpTypeInt 32 0 - %uint_4 = OpConstant %uint 4 -%_arr_v3float_uint_4 = OpTypeArray %v3float %uint_4 -%_ptr_Function__arr_v3float_uint_4 = OpTypePointer Function %_arr_v3float_uint_4 - %void = OpTypeVoid -%_ptr_UniformConstant__arr_v3float_uint_4 = OpTypePointer UniformConstant %_arr_v3float_uint_4 -%_ptr_Function__ptr_UniformConstant__arr_v3float_uint_4 = OpTypePointer Function %_ptr_UniformConstant__arr_v3float_uint_4 -%_arr_float_uint_4 = OpTypeArray %float %uint_4 -%_ptr_Function__arr_float_uint_4 = OpTypePointer Function %_arr_float_uint_4 -%_ptr_UniformConstant__arr_float_uint_4 = OpTypePointer UniformConstant %_arr_float_uint_4 -%_ptr_Function__ptr_UniformConstant__arr_float_uint_4 = OpTypePointer Function %_ptr_UniformConstant__arr_float_uint_4 - %33 = OpTypeImage %float 2D 0 0 0 1 Unknown - %34 = OpTypeSampledImage %33 -%_ptr_UniformConstant_34 = OpTypePointer UniformConstant %34 -%_ptr_Function__ptr_UniformConstant_34 = OpTypePointer Function %_ptr_UniformConstant_34 - %v4float = OpTypeVector %float 4 -%_ptr_Function_v4float = OpTypePointer Function %v4float -%_ptr_UniformConstant_v4float = OpTypePointer UniformConstant %v4float -%_ptr_Function__ptr_UniformConstant_v4float = OpTypePointer Function %_ptr_UniformConstant_v4float -%_ptr_Function_v3float = OpTypePointer Function %v3float -%_ptr_UniformConstant_v3float = OpTypePointer UniformConstant %v3float -%_ptr_Function__ptr_UniformConstant_v3float = OpTypePointer Function %_ptr_UniformConstant_v3float -%_ptr_UniformConstant_float = OpTypePointer UniformConstant %float -%_ptr_Function__ptr_UniformConstant_float = OpTypePointer Function %_ptr_UniformConstant_float - %int = OpTypeInt 32 1 -%_ptr_UniformConstant_int = OpTypePointer UniformConstant %int -%_ptr_Function__ptr_UniformConstant_int = OpTypePointer Function %_ptr_UniformConstant_int -%_ptr_Output_v4float = OpTypePointer Output %v4float -%_ptr_Function__ptr_Output_v4float = OpTypePointer Function %_ptr_Output_v4float -%_ptr_Input_v4float = OpTypePointer Input %v4float -%_ptr_Function__ptr_Input_v4float = OpTypePointer Function %_ptr_Input_v4float - %v2float = OpTypeVector %float 2 -%_ptr_Function_v2float = OpTypePointer Function %v2float - %Uniforms = OpTypeStruct %v3float %v4float %v4float %float %float %int %float %float %_arr_float_uint_4 %_arr_v3float_uint_4 -%_ptr_Function_Uniforms = OpTypePointer Function %Uniforms - %56 = OpTypeFunction %void %_ptr_Function_Uniforms %_ptr_Function_v4float %_ptr_Function_v2float %34 %34 %34 %34 - %57 = OpTypeFunction %void - %out_color = OpVariable %_ptr_Output_v4float Output - %frag_coord = OpVariable %_ptr_Input_v4float Input - %iChannel0 = OpVariable %_ptr_UniformConstant_34 UniformConstant - %iChannel1 = OpVariable %_ptr_UniformConstant_34 UniformConstant - %iChannel2 = OpVariable %_ptr_UniformConstant_34 UniformConstant - %iChannel3 = OpVariable %_ptr_UniformConstant_34 UniformConstant -%iResolution = OpVariable %_ptr_UniformConstant_v3float UniformConstant - %iTime = OpVariable %_ptr_UniformConstant_float UniformConstant - %iMouse = OpVariable %_ptr_UniformConstant_v4float UniformConstant - %iDate = OpVariable %_ptr_UniformConstant_v4float UniformConstant -%iSampleRate = OpVariable %_ptr_UniformConstant_float UniformConstant - %iFrame = OpVariable %_ptr_UniformConstant_int UniformConstant - %iTimeDelta = OpVariable %_ptr_UniformConstant_float UniformConstant - %iFrameRate = OpVariable %_ptr_UniformConstant_float UniformConstant -%iChannelTime = OpVariable %_ptr_UniformConstant__arr_float_uint_4 UniformConstant -%iChannelResolution = OpVariable %_ptr_UniformConstant__arr_v3float_uint_4 UniformConstant -%_ptr_Function_34 = OpTypePointer Function %34 -%_ptr_Function_float = OpTypePointer Function %float -%_ptr_Function_int = OpTypePointer Function %int - %uint_0 = OpConstant %uint 0 - %uint_1 = OpConstant %uint 1 - %uint_2 = OpConstant %uint 2 - %uint_3 = OpConstant %uint 3 - %float_1 = OpConstant %float 1 - %uint_5 = OpConstant %uint 5 - %uint_6 = OpConstant %uint 6 - %uint_7 = OpConstant %uint 7 - %uint_8 = OpConstant %uint 8 - %uint_9 = OpConstant %uint 9 - %float_0 = OpConstant %float 0 - %72 = OpUndef %v2float - %73 = OpUndef %v4float -%_minimal__Uniforms___main_image = OpFunction %void None %56 - %74 = OpFunctionParameter %_ptr_Function_Uniforms - %75 = OpFunctionParameter %_ptr_Function_v4float - %76 = OpFunctionParameter %_ptr_Function_v2float - %77 = OpFunctionParameter %34 - %78 = OpFunctionParameter %34 - %79 = OpFunctionParameter %34 - %80 = OpFunctionParameter %34 - %81 = OpLabel - %82 = OpLoad %v2float %76 - %83 = OpAccessChain %_ptr_Function_v3float %74 %uint_0 - %84 = OpLoad %v3float %83 - %85 = OpCompositeExtract %float %84 0 - %86 = OpCompositeExtract %float %84 1 - %87 = OpCompositeInsert %v2float %85 %72 0 - %88 = OpCompositeInsert %v2float %86 %87 1 - %89 = OpCompositeExtract %float %82 0 - %90 = OpCompositeExtract %float %88 0 - %91 = OpFDiv %float %89 %90 - %92 = OpCompositeExtract %float %82 1 - %93 = OpCompositeExtract %float %88 1 - %94 = OpFDiv %float %92 %93 - %95 = OpCompositeInsert %v2float %91 %72 0 - %96 = OpCompositeInsert %v2float %94 %95 1 - %97 = OpCompositeExtract %float %96 0 - %98 = OpCompositeExtract %float %96 1 - %99 = OpCompositeInsert %v4float %97 %73 0 - %100 = OpCompositeInsert %v4float %98 %99 1 - %101 = OpCompositeInsert %v4float %float_1 %100 2 - %102 = OpCompositeInsert %v4float %float_1 %101 3 - OpStore %75 %102 - OpReturn - OpFunctionEnd - %1 = OpFunction %void None %57 - %103 = OpLabel - %104 = OpVariable %_ptr_Function__arr_float_uint_4 Function - %105 = OpVariable %_ptr_Function__arr_v3float_uint_4 Function - %106 = OpVariable %_ptr_Function_Uniforms Function - %107 = OpVariable %_ptr_Function__arr_float_uint_4 Function - %108 = OpVariable %_ptr_Function__arr_v3float_uint_4 Function - %109 = OpVariable %_ptr_Function_v4float Function - %110 = OpVariable %_ptr_Function_v2float Function - %111 = OpLoad %v4float %frag_coord - %112 = OpLoad %34 %iChannel0 - %113 = OpLoad %34 %iChannel1 - %114 = OpLoad %34 %iChannel2 - %115 = OpLoad %34 %iChannel3 - %116 = OpLoad %v3float %iResolution - %117 = OpLoad %float %iTime - %118 = OpLoad %v4float %iMouse - %119 = OpLoad %v4float %iDate - %120 = OpLoad %float %iSampleRate - %121 = OpLoad %int %iFrame - %122 = OpLoad %float %iTimeDelta - %123 = OpLoad %float %iFrameRate - OpCopyMemory %104 %iChannelTime - OpCopyMemory %105 %iChannelResolution - OpCopyMemory %107 %104 - OpCopyMemory %108 %105 - %124 = OpAccessChain %_ptr_Function_v3float %106 %uint_0 - OpStore %124 %116 - %125 = OpAccessChain %_ptr_Function_v4float %106 %uint_1 - OpStore %125 %118 - %126 = OpAccessChain %_ptr_Function_v4float %106 %uint_2 - OpStore %126 %119 - %127 = OpAccessChain %_ptr_Function_float %106 %uint_3 - OpStore %127 %117 - %128 = OpAccessChain %_ptr_Function_float %106 %uint_4 - OpStore %128 %120 - %129 = OpAccessChain %_ptr_Function_int %106 %uint_5 - OpStore %129 %121 - %130 = OpAccessChain %_ptr_Function_float %106 %uint_6 - OpStore %130 %122 - %131 = OpAccessChain %_ptr_Function_float %106 %uint_7 - OpStore %131 %123 - %132 = OpAccessChain %_ptr_Function__arr_float_uint_4 %106 %uint_8 - OpCopyMemory %132 %107 - %133 = OpAccessChain %_ptr_Function__arr_v3float_uint_4 %106 %uint_9 - OpCopyMemory %133 %108 - %134 = OpCompositeExtract %float %111 0 - %135 = OpCompositeExtract %float %111 1 - %136 = OpCompositeInsert %v2float %134 %72 0 - %137 = OpCompositeInsert %v2float %135 %136 1 - %138 = OpAccessChain %_ptr_Function_float %109 %uint_0 - OpStore %138 %float_0 - %139 = OpAccessChain %_ptr_Function_float %109 %uint_1 - OpStore %139 %float_0 - %140 = OpAccessChain %_ptr_Function_float %109 %uint_2 - OpStore %140 %float_0 - %141 = OpAccessChain %_ptr_Function_float %109 %uint_3 - OpStore %141 %float_1 - OpStore %110 %137 - %142 = OpFunctionCall %void %_minimal__Uniforms___main_image %106 %109 %110 %112 %113 %114 %115 - %143 = OpAccessChain %_ptr_Function_float %109 %uint_3 - OpStore %143 %float_1 - %144 = OpLoad %v4float %109 - OpStore %out_color %144 - OpReturn - OpFunctionEnd + OpCapability Shader + OpMemoryModel Logical Simple + OpEntryPoint GLCompute %3 "main" + OpExecutionMode %3 LocalSize 64 64 1 +%1 = OpTypeVoid +%2 = OpTypeFunction %1 +%3 = OpFunction %1 None %2 +%4 = OpLabel + OpReturn + OpFunctionEnd \ No newline at end of file From f755ea382a73ad4418b1cae972ef85d93cb50c96 Mon Sep 17 00:00:00 2001 From: Jake Shadle Date: Thu, 17 Dec 2020 15:43:04 +0100 Subject: [PATCH 3/3] Update CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41304f3..014ee33 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - ReleaseDate +### Fixed +- [PR#13](https://github.com/EmbarkStudios/spirv-tools-rs/pull/13) Fix the spirv-as and spirv-val tool arguments that were broken by [PR#12](https://github.com/EmbarkStudios/spirv-tools-rs/pull/12). + ## [0.3.0] - 2020-12-17 ### Added - [PR#12](https://github.com/EmbarkStudios/spirv-tools-rs/pull/12) Added the ability to disassemble binary to text.