From f31093fb3b0c8183069037fcac99a90d3adef2bd Mon Sep 17 00:00:00 2001 From: Igor Shaposhnik Date: Wed, 14 Jun 2023 22:41:43 +0300 Subject: [PATCH] Add array-in-function-return-type test --- .../array-in-function-return-type.param.ron | 2 + tests/in/array-in-function-return-type.wgsl | 9 ++++ ...in-function-return-type.main.Fragment.glsl | 17 +++++++ .../out/msl/array-in-function-return-type.msl | 23 ++++++++++ .../spv/array-in-function-return-type.spvasm | 44 +++++++++++++++++++ .../wgsl/array-in-function-return-type.wgsl | 9 ++++ tests/snapshots.rs | 5 +++ 7 files changed, 109 insertions(+) create mode 100644 tests/in/array-in-function-return-type.param.ron create mode 100644 tests/in/array-in-function-return-type.wgsl create mode 100644 tests/out/glsl/array-in-function-return-type.main.Fragment.glsl create mode 100644 tests/out/msl/array-in-function-return-type.msl create mode 100644 tests/out/spv/array-in-function-return-type.spvasm create mode 100644 tests/out/wgsl/array-in-function-return-type.wgsl diff --git a/tests/in/array-in-function-return-type.param.ron b/tests/in/array-in-function-return-type.param.ron new file mode 100644 index 0000000000..72873dd667 --- /dev/null +++ b/tests/in/array-in-function-return-type.param.ron @@ -0,0 +1,2 @@ +( +) diff --git a/tests/in/array-in-function-return-type.wgsl b/tests/in/array-in-function-return-type.wgsl new file mode 100644 index 0000000000..21e2012e78 --- /dev/null +++ b/tests/in/array-in-function-return-type.wgsl @@ -0,0 +1,9 @@ +fn ret_array() -> array { + return array(1.0, 2.0); +} + +@fragment +fn main() -> @location(0) vec4 { + let a = ret_array(); + return vec4(a[0], a[1], 0.0, 1.0); +} diff --git a/tests/out/glsl/array-in-function-return-type.main.Fragment.glsl b/tests/out/glsl/array-in-function-return-type.main.Fragment.glsl new file mode 100644 index 0000000000..45fc31a622 --- /dev/null +++ b/tests/out/glsl/array-in-function-return-type.main.Fragment.glsl @@ -0,0 +1,17 @@ +#version 310 es + +precision highp float; +precision highp int; + +layout(location = 0) out vec4 _fs2p_location0; + +float[2] ret_array() { + return float[2](1.0, 2.0); +} + +void main() { + float _e0[2] = ret_array(); + _fs2p_location0 = vec4(_e0[0], _e0[1], 0.0, 1.0); + return; +} + diff --git a/tests/out/msl/array-in-function-return-type.msl b/tests/out/msl/array-in-function-return-type.msl new file mode 100644 index 0000000000..c2c2379cce --- /dev/null +++ b/tests/out/msl/array-in-function-return-type.msl @@ -0,0 +1,23 @@ +// language: metal2.0 +#include +#include + +using metal::uint; + +struct type_1 { + float inner[2]; +}; + +type_1 ret_array( +) { + return type_1 {1.0, 2.0}; +} + +struct main_Output { + metal::float4 member [[color(0)]]; +}; +fragment main_Output main_( +) { + type_1 _e0 = ret_array(); + return main_Output { metal::float4(_e0.inner[0], _e0.inner[1], 0.0, 1.0) }; +} diff --git a/tests/out/spv/array-in-function-return-type.spvasm b/tests/out/spv/array-in-function-return-type.spvasm new file mode 100644 index 0000000000..e704340251 --- /dev/null +++ b/tests/out/spv/array-in-function-return-type.spvasm @@ -0,0 +1,44 @@ +; SPIR-V +; Version: 1.1 +; Generator: rspirv +; Bound: 28 +OpCapability Shader +%1 = OpExtInstImport "GLSL.std.450" +OpMemoryModel Logical GLSL450 +OpEntryPoint Fragment %20 "main" %18 +OpExecutionMode %20 OriginUpperLeft +OpDecorate %6 ArrayStride 4 +OpDecorate %18 Location 0 +%2 = OpTypeVoid +%4 = OpTypeInt 32 1 +%3 = OpConstant %4 2 +%5 = OpTypeFloat 32 +%8 = OpTypeInt 32 0 +%7 = OpConstant %8 2 +%6 = OpTypeArray %5 %7 +%9 = OpTypeVector %5 4 +%12 = OpTypeFunction %6 +%13 = OpConstant %5 1.0 +%14 = OpConstant %5 2.0 +%19 = OpTypePointer Output %9 +%18 = OpVariable %19 Output +%21 = OpTypeFunction %2 +%22 = OpConstant %5 0.0 +%11 = OpFunction %6 None %12 +%10 = OpLabel +OpBranch %15 +%15 = OpLabel +%16 = OpCompositeConstruct %6 %13 %14 +OpReturnValue %16 +OpFunctionEnd +%20 = OpFunction %2 None %21 +%17 = OpLabel +OpBranch %23 +%23 = OpLabel +%24 = OpFunctionCall %6 %11 +%25 = OpCompositeExtract %5 %24 0 +%26 = OpCompositeExtract %5 %24 1 +%27 = OpCompositeConstruct %9 %25 %26 %22 %13 +OpStore %18 %27 +OpReturn +OpFunctionEnd \ No newline at end of file diff --git a/tests/out/wgsl/array-in-function-return-type.wgsl b/tests/out/wgsl/array-in-function-return-type.wgsl new file mode 100644 index 0000000000..2d5b1e84aa --- /dev/null +++ b/tests/out/wgsl/array-in-function-return-type.wgsl @@ -0,0 +1,9 @@ +fn ret_array() -> array { + return array(1.0, 2.0); +} + +@fragment +fn main() -> @location(0) vec4 { + let _e0 = ret_array(); + return vec4(_e0[0], _e0[1], 0.0, 1.0); +} diff --git a/tests/snapshots.rs b/tests/snapshots.rs index 1ea52b46ce..2aab4f29fc 100644 --- a/tests/snapshots.rs +++ b/tests/snapshots.rs @@ -401,10 +401,15 @@ fn convert_wgsl() { let root = env!("CARGO_MANIFEST_DIR"); let inputs = [ + // TODO: merge array-in-ctor and array-in-function-return-type tests after fix HLSL issue https://github.com/gfx-rs/naga/issues/1930 ( "array-in-ctor", Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL, ), + ( + "array-in-function-return-type", + Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::WGSL, + ), ( "empty", Targets::SPIRV | Targets::METAL | Targets::GLSL | Targets::HLSL | Targets::WGSL,