Skip to content
This repository has been archived by the owner on Jan 29, 2025. It is now read-only.

Commit

Permalink
Add array-in-function-return-type test
Browse files Browse the repository at this point in the history
  • Loading branch information
Gordon-F authored and teoxoy committed Jun 15, 2023
1 parent 304ba58 commit f31093f
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/in/array-in-function-return-type.param.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(
)
9 changes: 9 additions & 0 deletions tests/in/array-in-function-return-type.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn ret_array() -> array<f32, 2> {
return array<f32, 2>(1.0, 2.0);
}

@fragment
fn main() -> @location(0) vec4<f32> {
let a = ret_array();
return vec4<f32>(a[0], a[1], 0.0, 1.0);
}
17 changes: 17 additions & 0 deletions tests/out/glsl/array-in-function-return-type.main.Fragment.glsl
Original file line number Diff line number Diff line change
@@ -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;
}

23 changes: 23 additions & 0 deletions tests/out/msl/array-in-function-return-type.msl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// language: metal2.0
#include <metal_stdlib>
#include <simd/simd.h>

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) };
}
44 changes: 44 additions & 0 deletions tests/out/spv/array-in-function-return-type.spvasm
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tests/out/wgsl/array-in-function-return-type.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
fn ret_array() -> array<f32, 2> {
return array<f32, 2>(1.0, 2.0);
}

@fragment
fn main() -> @location(0) vec4<f32> {
let _e0 = ret_array();
return vec4<f32>(_e0[0], _e0[1], 0.0, 1.0);
}
5 changes: 5 additions & 0 deletions tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f31093f

Please sign in to comment.