Giter Site home page Giter Site logo

Comments (7)

tannergooding avatar tannergooding commented on July 23, 2024

Was just going to comment the same 😄

C# emits classes using LayoutKind.Auto while it emits structs using LayoutKind.Sequential by default (the latter differs from the same type declared directly in IL) and while we (the .NET Libraries Team) don't necessarily guarantee any struct will always stay blittable or that it won't have the underlying layout changed, the Vector2/3/4, Matrix3x2, Matrix4x4, Plane, and Quaternion types in particular won't change as they publicly expose their fields and have explicit size/layout requirements.

from vrmac.

Const-me avatar Const-me commented on July 23, 2024

Thanks for the tip. Will leave this issue open and upgrade when I’ll have time.

Will definitely work for vectors, quaternions and 4x4 matrices

About 3x2 matrices, do you happen to know have someone tested Matrix3x2 from .NET against the corresponding C++ class from Windows SDK? https://docs.microsoft.com/en-us/windows/win32/api/d2d1helper/nl-d2d1helper-matrix3x2f

I did and I think I had to make some compatibility adjustments to my initial implementation of these matrices.

from vrmac.

tannergooding avatar tannergooding commented on July 23, 2024

Matrix3x2F is not a C++03 POD ("Plain Old Data") type and so it may have different marshaling characteristics/requirements. We should be largely compatible with D2D_MATRIX_3X2_F but that will likely depend on the underlying ABI (Application Binary Interface), that is the Calling Convention used, as D2D_MATRIX_3X2_F is a struct containing a union of two structs (each having 6x float fields) and a byval array that is 3x2 in width while System.Numerics.Matrix3x2 is simply a struct containing 6x float fields

from vrmac.

Const-me avatar Const-me commented on July 23, 2024

An example of the upper layer of the ABI: https://github.com/Const-me/Vrmac/blob/master/VrmacInterop/Draw/Direct2D/iDrawContext.cs#L29 There’re more methods passing them between C++ and C#, they are used a lot over both 2D backends.

When running on Windows, my COM runtime compiles that method into unmanaged delegate with CallingConvention.StdCall applied: https://github.com/Const-me/ComLightInterop/blob/master/ComLight/Emit/NativeDelegates.cs#L43-L48

On Windows, the layer below that are C++ methods with __stdcall convention, built by Visual Studio 2017 for AMD64. I have no intentions to change that any time soon, in my experience platform-default compilers cause least amount of issues, on Windows this means MSVC, on Linux GCC.

Does this mean the 3x2 matrices from .NET Numerics are binary compatible with D2D matrices?

Also, do you happen to know the operations on these matrices, especially vector transform and inversion, are identical (apart from inevitable float precision issues caused by FMA and other factors, I’m fine with them) across the 2 implementations, in .NET and D2D?

from vrmac.

tannergooding avatar tannergooding commented on July 23, 2024

Does this mean the 3x2 matrices from .NET Numerics are binary compatible with D2D matrices?

It would depend on the underlying ABI and would require more investigation. I believe in the case of Matrix3x2 they are compatible, but there can be lots of tiny nuances when you actually dig into things: https://docs.microsoft.com/en-us/cpp/build/x64-calling-convention?view=vs-2019#return-values

Also, do you happen to know the operations on these matrices, especially vector transform and inversion, are identical (apart from inevitable float precision issues caused by FMA and other factors, I’m fine with them) across the 2 implementations, in .NET and D2D?

I haven't done any analysis to determine if we are or are not compatible with the Direct2D algorithms (or DirectX Math). In general, I would expect results to at least be similar.

from vrmac.

Const-me avatar Const-me commented on July 23, 2024

@tannergooding Fixed now. Will release 1.1 after improving couple more things.

Had no compatibility issues with 3x2 matrices, tested both 2D backends on Windows, and my custom one on Linux.

But I had a couple with 4x4 ones: https://github.com/Const-me/Vrmac/blob/master/Vrmac/Utils/Math/DiligentMatrices.cs The projection was expected, but I forgot I have also patched LookAt in the old MonoGame-based code.

from vrmac.

Const-me avatar Const-me commented on July 23, 2024

Fixed in 1.1

from vrmac.

Related Issues (3)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.