Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix as and val cli #13

Merged
merged 3 commits into from
Dec 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

<!-- next-header -->
## [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.
Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion src/assembler/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl Assembler for ToolAssembler {
options: super::AssemblerOptions,
) -> Result<crate::binary::Binary, crate::error::Error> {
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");
Expand Down
4 changes: 4 additions & 0 deletions src/opt/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ impl Optimizer for ToolOptimizer {
options: Option<super::Options>,
) -> Result<crate::binary::Binary, crate::Error> {
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(
Expand Down
2 changes: 1 addition & 1 deletion src/val/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 35 additions & 0 deletions tests/assembler.rs
Original file line number Diff line number Diff line change
@@ -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");
}
248 changes: 10 additions & 238 deletions tests/test_content.txt
Original file line number Diff line number Diff line change
@@ -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 "<minimal::Uniforms>::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