From 16be1a92379d7bdf3d0e88f7f7b2aca2dfd187b4 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Wed, 1 Feb 2023 03:24:05 -0800 Subject: [PATCH] spv-out: support version 1.4 (#2230) * spv-out: support version 1.4 * Extract SPV version numner from the comment --- Makefile | 4 +++- src/back/msl/writer.rs | 2 +- src/back/spv/writer.rs | 6 ++++++ tests/in/sprite.param.ron | 5 +++++ tests/in/sprite.wgsl | 7 ++++++ tests/out/spv/sprite.spvasm | 43 +++++++++++++++++++++++++++++++++++++ tests/snapshots.rs | 1 + 7 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 tests/in/sprite.param.ron create mode 100644 tests/in/sprite.wgsl create mode 100644 tests/out/spv/sprite.spvasm diff --git a/Makefile b/Makefile index de27e30493..744d8a2254 100644 --- a/Makefile +++ b/Makefile @@ -33,7 +33,9 @@ bench: validate-spv: $(SNAPSHOTS_BASE_OUT)/spv/*.spvasm @set -e && for file in $^ ; do \ echo "Validating" $${file#"$(SNAPSHOTS_BASE_OUT)/"}; \ - cat $${file} | spirv-as --target-env vulkan1.0 -o - | spirv-val; \ + version_line=$$(head -2 $${file} | tail -1); \ + version=$${version_line#"; Version: "};\ + cat $${file} | spirv-as --target-env spv$${version} -o - | spirv-val; \ done validate-msl: $(SNAPSHOTS_BASE_OUT)/msl/*.msl diff --git a/src/back/msl/writer.rs b/src/back/msl/writer.rs index 04c1fed213..d424c11b20 100644 --- a/src/back/msl/writer.rs +++ b/src/back/msl/writer.rs @@ -4221,7 +4221,7 @@ fn test_stack_size() { let stack_size = addresses_end - addresses_start; // check the size (in debug only) // last observed macOS value: 19152 (CI) - if !(9500..=20000).contains(&stack_size) { + if !(9000..=20000).contains(&stack_size) { panic!("`put_block` stack size {stack_size} has changed!"); } } diff --git a/src/back/spv/writer.rs b/src/back/spv/writer.rs index f19d83e454..caf3f72ce6 100644 --- a/src/back/spv/writer.rs +++ b/src/back/spv/writer.rs @@ -585,6 +585,12 @@ impl Writer { } let mut gv = self.global_variables[handle.index()].clone(); + if let Some(ref mut iface) = interface { + // Have to include global variables in the interface + if self.physical_layout.version >= 0x10400 { + iface.varying_ids.push(gv.var_id); + } + } // Handle globals are pre-emitted and should be loaded automatically. // diff --git a/tests/in/sprite.param.ron b/tests/in/sprite.param.ron new file mode 100644 index 0000000000..08598faeef --- /dev/null +++ b/tests/in/sprite.param.ron @@ -0,0 +1,5 @@ +( + spv: ( + version: (1, 4), + ), +) diff --git a/tests/in/sprite.wgsl b/tests/in/sprite.wgsl new file mode 100644 index 0000000000..6828b29465 --- /dev/null +++ b/tests/in/sprite.wgsl @@ -0,0 +1,7 @@ +@group(0) @binding(0) var u_texture : texture_2d; +@group(0) @binding(1) var u_sampler : sampler; + +@fragment +fn main(@location(0) uv : vec2) -> @location(0) vec4 { + return textureSample(u_texture, u_sampler, uv); +} diff --git a/tests/out/spv/sprite.spvasm b/tests/out/spv/sprite.spvasm new file mode 100644 index 0000000000..f3a574b28a --- /dev/null +++ b/tests/out/spv/sprite.spvasm @@ -0,0 +1,43 @@ +; SPIR-V +; Version: 1.4 +; Generator: rspirv +; Bound: 26 +OpCapability Shader +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Fragment %18 "main" %13 %16 %8 %10 +OpExecutionMode %18 OriginUpperLeft +OpDecorate %8 DescriptorSet 0 +OpDecorate %8 Binding 0 +OpDecorate %10 DescriptorSet 0 +OpDecorate %10 Binding 1 +OpDecorate %13 Location 0 +OpDecorate %16 Location 0 +%2 = OpTypeVoid +%4 = OpTypeFloat 32 +%3 = OpTypeImage %4 2D 0 0 0 1 Unknown +%5 = OpTypeSampler +%6 = OpTypeVector %4 2 +%7 = OpTypeVector %4 4 +%9 = OpTypePointer UniformConstant %3 +%8 = OpVariable %9 UniformConstant +%11 = OpTypePointer UniformConstant %5 +%10 = OpVariable %11 UniformConstant +%14 = OpTypePointer Input %6 +%13 = OpVariable %14 Input +%17 = OpTypePointer Output %7 +%16 = OpVariable %17 Output +%19 = OpTypeFunction %2 +%23 = OpTypeSampledImage %3 +%18 = OpFunction %2 None %19 +%12 = OpLabel +%15 = OpLoad %6 %13 +%20 = OpLoad %3 %8 +%21 = OpLoad %5 %10 +OpBranch %22 +%22 = OpLabel +%24 = OpSampledImage %23 %20 %21 +%25 = OpImageSampleImplicitLod %7 %24 %15 +OpStore %16 %25 +OpReturn +OpFunctionEnd \ No newline at end of file diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 466f1739f0..25f307c110 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -556,6 +556,7 @@ fn convert_wgsl() { "workgroup-var-init", Targets::WGSL | Targets::GLSL | Targets::SPIRV | Targets::HLSL | Targets::METAL, ), + ("sprite", Targets::SPIRV), ]; for &(name, targets) in inputs.iter() {