Skip to content

Commit 0f4cba3

Browse files
committed
tests: add test with matrix operations that does not translate to Metal properly
1 parent 32844e8 commit 0f4cba3

File tree

3 files changed

+143
-0
lines changed

3 files changed

+143
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#version 300 es
2+
out mediump vec4 _fragData;
3+
uniform highp float _Speed;
4+
uniform highp vec4 _Time;
5+
highp vec4 func( in highp vec2 uv )
6+
{
7+
highp float s = sin(_Speed * _Time.x);
8+
highp float c = cos(_Speed * _Time.x);
9+
10+
highp mat2 rotationMatrix = mat2(c, s, -s, c);
11+
// various operations on a matrix
12+
rotationMatrix = rotationMatrix * 2.0;
13+
rotationMatrix = rotationMatrix - 1.0;
14+
rotationMatrix = s - rotationMatrix;
15+
rotationMatrix = c + rotationMatrix;
16+
rotationMatrix /= s;
17+
18+
mediump mat2 halfMatrix = mat2(c, s, -s, c);
19+
halfMatrix = halfMatrix * 2.0;
20+
halfMatrix = halfMatrix - 1.0;
21+
halfMatrix = s - halfMatrix;
22+
halfMatrix = c + halfMatrix;
23+
halfMatrix /= s;
24+
25+
return vec4((rotationMatrix * uv), (halfMatrix * uv));
26+
}
27+
in highp vec2 uv;
28+
void main() {
29+
_fragData = func(uv);
30+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#version 300 es
2+
out mediump vec4 _fragData;
3+
uniform highp float _Speed;
4+
uniform highp vec4 _Time;
5+
in highp vec2 uv;
6+
void main ()
7+
{
8+
mediump mat2 halfMatrix_1;
9+
highp mat2 rotationMatrix_2;
10+
highp float tmpvar_3;
11+
highp float tmpvar_4;
12+
tmpvar_4 = (_Speed * _Time.x);
13+
tmpvar_3 = sin(tmpvar_4);
14+
highp float tmpvar_5;
15+
tmpvar_5 = cos(tmpvar_4);
16+
highp mat2 tmpvar_6;
17+
tmpvar_6[uint(0)].x = tmpvar_5;
18+
tmpvar_6[uint(0)].y = tmpvar_3;
19+
tmpvar_6[1u].x = -(tmpvar_3);
20+
tmpvar_6[1u].y = tmpvar_5;
21+
rotationMatrix_2 = (tmpvar_6 * 2.0);
22+
rotationMatrix_2 = (rotationMatrix_2 - 1.0);
23+
rotationMatrix_2 = (tmpvar_3 - rotationMatrix_2);
24+
rotationMatrix_2 = (tmpvar_5 + rotationMatrix_2);
25+
rotationMatrix_2 = (rotationMatrix_2 / tmpvar_3);
26+
highp mat2 tmpvar_7;
27+
tmpvar_7[uint(0)].x = tmpvar_5;
28+
tmpvar_7[uint(0)].y = tmpvar_3;
29+
tmpvar_7[1u].x = -(tmpvar_3);
30+
tmpvar_7[1u].y = tmpvar_5;
31+
halfMatrix_1 = tmpvar_7;
32+
halfMatrix_1 = (halfMatrix_1 * 2.0);
33+
halfMatrix_1 = (halfMatrix_1 - 1.0);
34+
halfMatrix_1 = (tmpvar_3 - halfMatrix_1);
35+
halfMatrix_1 = (tmpvar_5 + halfMatrix_1);
36+
halfMatrix_1 = (halfMatrix_1 / tmpvar_3);
37+
highp vec4 tmpvar_8;
38+
tmpvar_8.xy = (rotationMatrix_2 * uv);
39+
tmpvar_8.zw = (halfMatrix_1 * uv);
40+
_fragData = tmpvar_8;
41+
}
42+
43+
44+
// stats: 17 alu 0 tex 0 flow
45+
// inputs: 1
46+
// #0: uv (high float) 2x1 [-1]
47+
// uniforms: 2 (total size: 0)
48+
// #0: _Speed (high float) 1x1 [-1]
49+
// #1: _Time (high float) 4x1 [-1]
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include <metal_stdlib>
2+
using namespace metal;
3+
inline float4x4 _xlcast_float4x4(half4x4 v) { return float4x4(float4(v[0]), float4(v[1]), float4(v[2]), float4(v[3])); }
4+
inline float3x3 _xlcast_float3x3(half3x3 v) { return float3x3(float3(v[0]), float3(v[1]), float3(v[2])); }
5+
inline float2x2 _xlcast_float2x2(half2x2 v) { return float2x2(float2(v[0]), float2(v[1])); }
6+
inline half4x4 _xlcast_half4x4(float4x4 v) { return half4x4(half4(v[0]), half4(v[1]), half4(v[2]), half4(v[3])); }
7+
inline half3x3 _xlcast_half3x3(float3x3 v) { return half3x3(half3(v[0]), half3(v[1]), half3(v[2])); }
8+
inline half2x2 _xlcast_half2x2(float2x2 v) { return half2x2(half2(v[0]), half2(v[1])); }
9+
struct xlatMtlShaderInput {
10+
float2 uv;
11+
};
12+
struct xlatMtlShaderOutput {
13+
half4 _fragData [[color(0)]];
14+
};
15+
struct xlatMtlShaderUniform {
16+
float _Speed;
17+
float4 _Time;
18+
};
19+
fragment xlatMtlShaderOutput xlatMtlMain (xlatMtlShaderInput _mtl_i [[stage_in]], constant xlatMtlShaderUniform& _mtl_u [[buffer(0)]])
20+
{
21+
xlatMtlShaderOutput _mtl_o;
22+
half2x2 halfMatrix_1;
23+
float2x2 rotationMatrix_2;
24+
float tmpvar_3;
25+
float tmpvar_4;
26+
tmpvar_4 = (_mtl_u._Speed * _mtl_u._Time.x);
27+
tmpvar_3 = sin(tmpvar_4);
28+
float tmpvar_5;
29+
tmpvar_5 = cos(tmpvar_4);
30+
float2x2 tmpvar_6;
31+
tmpvar_6[0].x = tmpvar_5;
32+
tmpvar_6[0].y = tmpvar_3;
33+
tmpvar_6[1].x = -(tmpvar_3);
34+
tmpvar_6[1].y = tmpvar_5;
35+
rotationMatrix_2 = (tmpvar_6 * 2.0);
36+
rotationMatrix_2 = (rotationMatrix_2 - 1.0);
37+
rotationMatrix_2 = (tmpvar_3 - rotationMatrix_2);
38+
rotationMatrix_2 = (tmpvar_5 + rotationMatrix_2);
39+
rotationMatrix_2 = (rotationMatrix_2 / tmpvar_3);
40+
float2x2 tmpvar_7;
41+
tmpvar_7[0].x = tmpvar_5;
42+
tmpvar_7[0].y = tmpvar_3;
43+
tmpvar_7[1].x = -(tmpvar_3);
44+
tmpvar_7[1].y = tmpvar_5;
45+
halfMatrix_1 = _xlcast_half2x2(tmpvar_7);
46+
halfMatrix_1 = (halfMatrix_1 * (half)2.0);
47+
halfMatrix_1 = (halfMatrix_1 - (half)1.0);
48+
halfMatrix_1 = _xlcast_half2x2(((float2x2)((half)tmpvar_3 - halfMatrix_1)));
49+
halfMatrix_1 = _xlcast_half2x2(((float2x2)((half)tmpvar_5 + halfMatrix_1)));
50+
halfMatrix_1 = _xlcast_half2x2(((float2x2)(halfMatrix_1 / (half)tmpvar_3)));
51+
float4 tmpvar_8;
52+
tmpvar_8.xy = (rotationMatrix_2 * _mtl_i.uv);
53+
tmpvar_8.zw = ((float2)(halfMatrix_1 * (half2)_mtl_i.uv));
54+
_mtl_o._fragData = half4(tmpvar_8);
55+
return _mtl_o;
56+
}
57+
58+
59+
// stats: 17 alu 0 tex 0 flow
60+
// inputs: 1
61+
// #0: uv (high float) 2x1 [-1]
62+
// uniforms: 2 (total size: 32)
63+
// #0: _Speed (high float) 1x1 [-1] loc 0
64+
// #1: _Time (high float) 4x1 [-1] loc 16

0 commit comments

Comments
 (0)