Skip to content

Commit

Permalink
restore GLKEffectPropertyTransform
Browse files Browse the repository at this point in the history
  • Loading branch information
StephaneDelcroix committed Jan 26, 2022
1 parent c5b5d36 commit 714f92b
Show file tree
Hide file tree
Showing 6 changed files with 198 additions and 17 deletions.
15 changes: 14 additions & 1 deletion runtime/bindings-generator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ static IEnumerable<FunctionData> GetFunctionData (bool isDotNet = false)
Types.Vector2i = isDotNet ? Types.NVector2i : Types.OpenTK_Vector2i;
Types.Vector3i = isDotNet ? Types.NVector3i : Types.OpenTK_Vector3i;
Types.Vector4i = isDotNet ? Types.NVector4i : Types.OpenTK_Vector4i;
Types.Matrix3f = isDotNet ? Types.RMatrix3f : Types.OpenTK_Matrix3f;
Types.Matrix4f = isDotNet ? Types.Numerics_Matrix4f : Types.OpenTK_Matrix4f;
Types.QuatD = isDotNet ? Types.NQuaterniond : Types.OpenTK_QuatD;

Expand Down Expand Up @@ -2705,6 +2706,7 @@ static void MarshalToManaged (StringWriter writer, TypeData type, string nativeV
writer.WriteLine ("\t}");
break;
case "Matrix3":
case "RMatrix3":
case "NMatrix3":
writer.WriteLine ("\tfor (int i = 0; i < 3; i++) {");
writer.WriteLine ("\t\t{0}{2}columns [i].a = {1}.columns [i] [0];", managedVariable, nativeVariable, accessor);
Expand Down Expand Up @@ -2852,6 +2854,7 @@ static void MarshalToNative (StringWriter writer, TypeData type, string nativeVa
writer.WriteLine ("\t}");
break;
case "Matrix3":
case "RMatrix3":
case "NMatrix3":
writer.WriteLine ("\tfor (int i = 0; i < 3; i++) {");
writer.WriteLine ("\t\t{0}.columns [i][0] = {1}{2}columns [i].a;", nativeVariable, managedVariable, accessor);
Expand Down Expand Up @@ -3463,7 +3466,8 @@ public static class Types {
IsX86Stret = true,
IsX64Stret = false,
};
public static TypeData Matrix3f = new TypeData {
public static TypeData Matrix3f;
public static TypeData OpenTK_Matrix3f = new TypeData {
ManagedType = "Matrix3",
NativeType = "matrix_float3x3",
NativeWrapperType = "struct Matrix3f",
Expand All @@ -3472,6 +3476,15 @@ public static class Types {
IsX86Stret = true,
IsX64Stret = true,
};
public static TypeData RMatrix3f = new TypeData {
ManagedType = "RMatrix3",
NativeType = "matrix_float3x3",
NativeWrapperType = "struct Matrix3f",
RequireMarshal = true,
IsARMStret = true,
IsX86Stret = true,
IsX64Stret = true,
};
public static TypeData NMatrix3 = new TypeData {
ManagedType = "NMatrix3",
NativeType = "matrix_float3x3",
Expand Down
168 changes: 168 additions & 0 deletions src/Simd/MatrixFloat3x3RM.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
//
// Authors:
// Stephane Delcroix <[email protected]>
//
// Copyright (c) 2022 Microsoft Inc
//

//
// This represents the native matrix_float3x3 type, which has a row-major layout
// (same as OpenTK.Matrix3).
//

using System;
using System.Runtime.InteropServices;

#if NET
namespace CoreGraphics
{
[StructLayout (LayoutKind.Sequential)]
public struct RMatrix3 : IEquatable<RMatrix3>
{
public float R0C0;
public float R0C1;
public float R0C2;
public float R1C0;
public float R1C1;
public float R1C2;
public float R2C0;
public float R2C1;
public float R2C2;

public RMatrix3 (
float r0c0, float r0c1, float r0c2,
float r1c0, float r1c1, float r1c2,
float r2c0, float r2c1, float r2c2)
{
R0C0 = r0c0;
R1C0 = r1c0;
R2C0 = r2c0;
R0C1 = r0c1;
R1C1 = r1c1;
R2C1 = r2c1;
R0C2 = r0c2;
R1C2 = r1c2;
R2C2 = r2c2;
}

public float Determinant {
get {
return
R0C0 * (R1C1 * R2C2 - R1C2 * R2C1) -
R0C1 * (R1C0 * R2C2 - R1C2 * R2C0) +
R0C2 * (R1C0 * R2C1 - R1C1 * R2C0);
}
}

public void Transpose ()
{
this = Transpose (this);
}

public static RMatrix3 Transpose (RMatrix3 mat)
{
RMatrix3 result = new RMatrix3 ();
Transpose (ref mat, out result);
return result;
}

public static void Transpose (ref RMatrix3 mat, out RMatrix3 result)
{
result.R0C0 = mat.R0C0;
result.R1C0 = mat.R0C1;
result.R2C0 = mat.R0C2;
result.R0C1 = mat.R1C0;
result.R1C1 = mat.R1C1;
result.R2C1 = mat.R1C2;
result.R0C2 = mat.R2C0;
result.R1C2 = mat.R2C1;
result.R2C2 = mat.R2C2;
}

public static RMatrix3 Multiply (RMatrix3 left, RMatrix3 right)
{
RMatrix3 result;
Multiply (ref left, ref right, out result);
return result;
}

public static void Multiply (ref RMatrix3 left, ref RMatrix3 right, out RMatrix3 result)
{
result.R0C0 = left.R0C0 * right.R0C0 + left.R0C1 * right.R1C0 + left.R0C2 * right.R2C0;
result.R0C1 = left.R0C0 * right.R0C1 + left.R0C1 * right.R1C1 + left.R0C2 * right.R2C1;
result.R0C2 = left.R0C0 * right.R0C2 + left.R0C1 * right.R1C2 + left.R0C2 * right.R2C2;

result.R1C0 = left.R1C0 * right.R0C0 + left.R1C1 * right.R1C0 + left.R1C2 * right.R2C0;
result.R1C1 = left.R1C0 * right.R0C1 + left.R1C1 * right.R1C1 + left.R1C2 * right.R2C1;
result.R1C2 = left.R1C0 * right.R0C2 + left.R1C1 * right.R1C2 + left.R1C2 * right.R2C2;

result.R2C0 = left.R2C0 * right.R0C0 + left.R2C1 * right.R1C0 + left.R2C2 * right.R2C0;
result.R2C1 = left.R2C0 * right.R0C1 + left.R2C1 * right.R1C1 + left.R2C2 * right.R2C1;
result.R2C2 = left.R2C0 * right.R0C2 + left.R2C1 * right.R1C2 + left.R2C2 * right.R2C2;
}

public static RMatrix3 operator * (RMatrix3 left, RMatrix3 right)
{
return Multiply (left, right);
}

public static bool operator == (RMatrix3 left, RMatrix3 right)
{
return left.Equals (right);
}

public static bool operator != (RMatrix3 left, RMatrix3 right)
{
return !left.Equals (right);
}

public static explicit operator NMatrix3 (RMatrix3 value)
{
return new NMatrix3 (
value.R0C0, value.R0C1, value.R0C2,
value.R1C0, value.R1C1, value.R1C2,
value.R2C0, value.R2C1, value.R2C2);
}

public static explicit operator RMatrix3 (NMatrix3 value)
{
return new RMatrix3 (
value.R0C0, value.R0C1, value.R0C2,
value.R1C0, value.R1C1, value.R1C2,
value.R2C0, value.R2C1, value.R2C2);
}

public override string ToString ()
{
return
$"({R0C0}, {R0C1}, {R0C2})\n" +
$"({R1C0}, {R1C1}, {R1C2})\n" +
$"({R2C0}, {R2C1}, {R2C2})";
}

public override int GetHashCode ()
{
return
R0C0.GetHashCode () ^ R0C1.GetHashCode () ^ R0C2.GetHashCode () ^
R1C0.GetHashCode () ^ R1C1.GetHashCode () ^ R1C2.GetHashCode () ^
R2C0.GetHashCode () ^ R2C1.GetHashCode () ^ R2C2.GetHashCode ();
}

public override bool Equals (object obj)
{
if (!(obj is RMatrix3))
return false;

return Equals ((RMatrix3) obj);
}

public bool Equals (RMatrix3 other)
{
return
R0C0 == other.R0C0 && R0C1 == other.R0C1 && R0C2 == other.R0C2 &&
R1C0 == other.R1C0 && R1C1 == other.R1C1 && R1C2 == other.R1C2 &&
R2C0 == other.R2C0 && R2C1 == other.R2C1 && R2C2 == other.R2C2;
}
}
}
#endif
1 change: 1 addition & 0 deletions src/frameworks.sources
Original file line number Diff line number Diff line change
Expand Up @@ -1867,6 +1867,7 @@ SHARED_CORE_SOURCES = \
Simd/MatrixDouble4x4.cs \
Simd/MatrixFloat2x2.cs \
Simd/MatrixFloat3x3.cs \
Simd/MatrixFloat3x3RM.cs \
Simd/MatrixFloat4x3.cs \
Simd/MatrixFloat4x4.cs \
Simd/VectorDouble2.cs \
Expand Down
11 changes: 3 additions & 8 deletions src/glkit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#if NET
using Vector3 = global::System.Numerics.Vector3;
using Vector4 = global::System.Numerics.Vector4;
using Matrix3 = global::CoreGraphics.RMatrix3;
using Matrix4 = global::System.Numerics.Matrix4x4;
#else
using Vector3 = global::OpenTK.Vector3;
using Vector4 = global::OpenTK.Vector4;
Expand Down Expand Up @@ -87,10 +89,9 @@ interface GLKBaseEffect : GLKNamedEffect {
[Export ("useConstantColor", ArgumentSemantic.Assign)]
bool UseConstantColor { get; set; }

#if !NET
[Export ("transform")]
GLKEffectPropertyTransform Transform { get; }
#endif

[Export ("light0")]
GLKEffectPropertyLight Light0 { get; }

Expand Down Expand Up @@ -200,11 +201,9 @@ interface GLKEffectPropertyLight {
[Export ("quadraticAttenuation", ArgumentSemantic.Assign)]
float QuadraticAttenuation { get; set; } /* GLfloat = float */

#if !NET
[NullAllowed] // by default this property is null
[Export ("transform", ArgumentSemantic.Retain)]
GLKEffectPropertyTransform Transform { get; set; }
#endif

[Export ("enabled", ArgumentSemantic.Assign)]
bool Enabled { get; set; }
Expand Down Expand Up @@ -251,7 +250,6 @@ interface GLKEffectPropertyTexture {

}

#if !NET
[Deprecated (PlatformName.iOS, 12,0, message: "Use 'Metal' instead.")]
[Deprecated (PlatformName.TvOS, 12,0, message: "Use 'Metal' instead.")]
[Deprecated (PlatformName.MacOSX, 10,14, message: "Use 'Metal' instead.")]
Expand All @@ -266,7 +264,6 @@ interface GLKEffectPropertyTransform {
[Export ("projectionMatrix", ArgumentSemantic.Assign)]
Matrix4 ProjectionMatrix { [Align (16)] get; set; }
}
#endif

[Deprecated (PlatformName.iOS, 12,0, message: "Use 'Metal' instead.")]
[Deprecated (PlatformName.TvOS, 12,0, message: "Use 'Metal' instead.")]
Expand Down Expand Up @@ -373,10 +370,8 @@ interface GLKSkyboxEffect : GLKNamedEffect {
[Export ("textureCubeMap")]
GLKEffectPropertyTexture TextureCubeMap { get; }

#if !NET
[Export ("transform")]
GLKEffectPropertyTransform Transform { get; }
#endif

[NullAllowed] // by default this property is null
[Export ("label", ArgumentSemantic.Copy)]
Expand Down
11 changes: 10 additions & 1 deletion tests/monotouch-test/SceneKit/SCNMatrixTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,19 @@
using CoreAnimation;
using Foundation;
using SceneKit;
using OpenTK;

using NUnit.Framework;

#if NET
using Vector3 = global::System.Numerics.Vector3;
using Vector3d = global::CoreGraphics.NVector3d;
using Vector4 = global::System.Numerics.Vector4;
using Quaternion = global::System.Numerics.Quaternion;
using Quaterniond = global::CoreGraphics.NQuaterniond;
#else
using OpenTK;
#endif

#if __MACOS__
#if NET
using pfloat = ObjCRuntime.nfloat;
Expand Down
9 changes: 2 additions & 7 deletions tests/monotouch-test/SpriteKit/UniformTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using ObjCRuntime;

#if NET
using CoreGraphics;
using MatrixFloat2x2 = global::CoreGraphics.NMatrix2;
using MatrixFloat3x3 = global::CoreGraphics.NMatrix3;
using MatrixFloat4x4 = global::CoreGraphics.NMatrix4;
Expand Down Expand Up @@ -68,7 +69,6 @@ public void Ctors ()
Asserts.AreEqual (Vector2.Zero, obj.FloatVector2Value, "1 FloatVector2Value");
Asserts.AreEqual (Vector3.Zero, obj.FloatVector3Value, "1 FloatVector3Value");
Asserts.AreEqual (Vector4.Zero, obj.FloatVector4Value, "1 FloatVector4Value");
#if !NET
Asserts.AreEqual (Matrix2.Zero, obj.FloatMatrix2Value, "1 FloatMatrix2Value");
#endif
Asserts.AreEqual (N2Zero, obj.MatrixFloat2x2Value, "1 MatrixFloat2x2Value");
Expand Down Expand Up @@ -109,26 +109,21 @@ public void Ctors ()
obj.FloatVector4Value = V4;
Asserts.AreEqual (V4, obj.FloatVector4Value, "2 FloatVector4Value");

#if !NET
obj.FloatMatrix2Value = M2;
Asserts.AreEqual (M2, obj.FloatMatrix2Value, "2 FloatMatrix2Value");
#endif
obj.MatrixFloat2x2Value = M2x2;
Asserts.AreEqual (M2x2, obj.MatrixFloat2x2Value, "2 MatrixFloat2x2Value");

#if !NET
obj.FloatMatrix3Value = M3;
Asserts.AreEqual (M3, obj.FloatMatrix3Value, "2 FloatMatrix3Value");
#endif
obj.MatrixFloat3x3Value = M3x3;
Asserts.AreEqual (M3x3, obj.MatrixFloat3x3Value, "2 MatrixFloat3x3Value");

#if !NET
obj.FloatMatrix4Value = M4;
Asserts.AreEqual (M4, obj.FloatMatrix4Value, "2 FloatMatrix4Value");
#endif
obj.MatrixFloat4x4Value = M4x4;
Asserts.AreEqual (M4x4, obj.MatrixFloat4x4Value, "2 MatrixFloat4x4Value");
#endif
}

bool hasSimdConstructors = TestRuntime.CheckXcodeVersion (8, 0);
Expand Down

3 comments on commit 714f92b

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ [CI Build] Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

API Current PR diff

ℹ️ API Diff (from PR only) (please review changes)

View API diff
View dotnet API diff
View dotnet legacy API diff
View dotnet iOS-MacCatalayst API diff

Generator diff

ℹ️ Generator Diff (please review changes)

Packages generated

View packages

Test results

35 tests failed, 200 tests passed.

Failed tests

  • monotouch-test/Mac [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 2559 Passed: 2401 Inconclusive: 9 Failed: 2 Ignored: 156)
  • monotouch-test/Mac [dotnet]/Debug (static registrar) [dotnet]: Failed (Test run failed.
    Tests run: 2556 Passed: 2399 Inconclusive: 9 Failed: 2 Ignored: 155)
  • monotouch-test/Mac Catalyst [dotnet]/Debug [dotnet]: Failed (Test run failed.
    Tests run: 2699 Passed: 2500 Inconclusive: 11 Failed: 4 Ignored: 195)
  • monotouch-test/iOS Unified 64-bits - simulator/Debug [dotnet]: BuildFailure
  • monotouch-test/iOS Unified 64-bits - simulator/Debug: BuildFailure
  • monotouch-test/iOS Unified 64-bits - simulator/Debug (LinkSdk) [dotnet]: BuildFailure ( (failed to parse the logs: The Writer is closed or in error state.))
  • monotouch-test/iOS Unified 64-bits - simulator/Debug (static registrar) [dotnet]: BuildFailure
  • monotouch-test/iOS Unified 64-bits - simulator/Release (all optimizations) [dotnet]: BuildFailure
  • monotouch-test/iOS Unified 64-bits - simulator/Debug (all optimizations) [dotnet]: BuildFailure
  • monotouch-test/iOS Unified 64-bits - simulator/Debug (LinkSdk): BuildFailure
  • monotouch-test/iOS Unified 64-bits - simulator/Debug (static registrar): BuildFailure
  • monotouch-test/iOS Unified 64-bits - simulator/Release (all optimizations): BuildFailure
  • monotouch-test/iOS Unified 64-bits - simulator/Debug (all optimizations): BuildFailure
  • monotouch-test/tvOS - simulator/Debug [dotnet]: Failed
  • monotouch-test/tvOS - simulator/Debug: BuildFailure
  • monotouch-test/tvOS - simulator/Debug (LinkSdk) [dotnet]: Failed
  • monotouch-test/tvOS - simulator/Debug (static registrar) [dotnet]: Failed
  • monotouch-test/tvOS - simulator/Release (all optimizations) [dotnet]: Failed
  • monotouch-test/tvOS - simulator/Debug (all optimizations) [dotnet]: Failed
  • monotouch-test/tvOS - simulator/Debug (LinkSdk): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (static registrar): BuildFailure
  • monotouch-test/tvOS - simulator/Release (all optimizations): BuildFailure
  • monotouch-test/tvOS - simulator/Debug (all optimizations): BuildFailure
  • monotouch-test/watchOS 32-bits - simulator/Debug: BuildFailure
  • monotouch-test/watchOS 32-bits - simulator/Debug (LinkSdk): BuildFailure
  • monotouch-test/watchOS 32-bits - simulator/Debug (static registrar): BuildFailure
  • monotouch-test/watchOS 32-bits - simulator/Release (all optimizations): BuildFailure
  • monotouch-test/watchOS 32-bits - simulator/Debug (all optimizations): BuildFailure
  • xammac tests/Mac Modern/Debug: BuildFailure
  • xammac tests/Mac Modern/Debug (all optimizations): BuildFailure
  • xammac tests/Mac Modern/Release: BuildFailure
  • xammac tests/Mac Modern/Release (all optimizations): BuildFailure
  • Xtro/.NET: BuildFailure
  • MTouch tests/NUnit: Failed (Execution failed with exit code 1)
  • DotNet tests: Failed (Execution failed with exit code 1)

Pipeline on Agent XAMMINI-071.BigSur'
restore GLKEffectPropertyTransform

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Tests failed catastrophically on VSTS: device tests iOS (no summary found). 🔥

Result file D:\a\1\s\Reports\TestSummary-iOS64\TestSummary.md not found.

Pipeline on Agent
restore GLKEffectPropertyTransform

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥 Tests failed catastrophically on VSTS: device tests tvOS (no summary found). 🔥

Result file D:\a\1\s\Reports\TestSummary-tvos\TestSummary.md not found.

Pipeline on Agent
restore GLKEffectPropertyTransform

Please sign in to comment.