MADCSHARP Telegram 10
Finally managed to create a generic solution for direct function calling. This will even work under Burst, because it allows to use calli unmanaged cdecl calls, and .NET runtime can provide us this with Marshal.GetFunctionPointerForDelegate.

Tho this call creates some wrapper and reverse P/Invoke call, on IL2CPP it's absolutely useless, so we can call this function directly.

FuncIL2CPP/FuncIL2CPPStatic provides us this ability and we can safely use it within burst and call managed land functions without any conversion.

GetUnityCaller() returns a special call which can directly call IL2CPP methods without jumping to RuntimeMethodHandle->methodPtr again in again. This caller works in cross-runtime mode, so you can use it without unity without any limitations, tho it will give very little performance penalty.

For some reason IL2CPP doesn't compile the code where TReturn is returned by ref with Fully Shared Generics enabled, this is why I'm using RefReturn struct to overcome this behavior.

P.S. Different platforms using different function pointer alignment, WebGL doesn't restricts function to be aligned by 1 byte, which means I can't use first bit to store isIL2CPP flag, while Android ARMv7 (32bit) allows functions to store last bit, so I can't use it either. So for Unity IL2CPP direct calls I've made 64-bit field for funcPtr (even on 32-bit platforms) and use last (0x8000000000000000) bit as indicator for IL2CPP direct call. To make direct il2cpp calls faster it's possible to reinterpret to AsIL2CPP() if you are sure that you are running on IL2CPP.

#if ENABLE_IL2CPP
FuncIL2CPP func = unityCall.AsIL2CPP();
#else
FuncManaged func = unityCall.AsManaged();
#endif
👏3🔥2



tgoop.com/madcsharp/10
Create:
Last Update:

Finally managed to create a generic solution for direct function calling. This will even work under Burst, because it allows to use calli unmanaged cdecl calls, and .NET runtime can provide us this with Marshal.GetFunctionPointerForDelegate.

Tho this call creates some wrapper and reverse P/Invoke call, on IL2CPP it's absolutely useless, so we can call this function directly.

FuncIL2CPP/FuncIL2CPPStatic provides us this ability and we can safely use it within burst and call managed land functions without any conversion.

GetUnityCaller() returns a special call which can directly call IL2CPP methods without jumping to RuntimeMethodHandle->methodPtr again in again. This caller works in cross-runtime mode, so you can use it without unity without any limitations, tho it will give very little performance penalty.

For some reason IL2CPP doesn't compile the code where TReturn is returned by ref with Fully Shared Generics enabled, this is why I'm using RefReturn struct to overcome this behavior.

P.S. Different platforms using different function pointer alignment, WebGL doesn't restricts function to be aligned by 1 byte, which means I can't use first bit to store isIL2CPP flag, while Android ARMv7 (32bit) allows functions to store last bit, so I can't use it either. So for Unity IL2CPP direct calls I've made 64-bit field for funcPtr (even on 32-bit platforms) and use last (0x8000000000000000) bit as indicator for IL2CPP direct call. To make direct il2cpp calls faster it's possible to reinterpret to AsIL2CPP() if you are sure that you are running on IL2CPP.

#if ENABLE_IL2CPP
FuncIL2CPP func = unityCall.AsIL2CPP();
#else
FuncManaged func = unityCall.AsManaged();
#endif

BY MadSharp: Unsafe





Share with your friend now:
tgoop.com/madcsharp/10

View MORE
Open in Telegram


Telegram News

Date: |

How to create a business channel on Telegram? (Tutorial) A Hong Kong protester with a petrol bomb. File photo: Dylan Hollingsworth/HKFP. Ng, who had pleaded not guilty to all charges, had been detained for more than 20 months. His channel was said to have contained around 120 messages and photos that incited others to vandalise pro-government shops and commit criminal damage targeting police stations. So far, more than a dozen different members have contributed to the group, posting voice notes of themselves screaming, yelling, groaning, and wailing in various pitches and rhythms. Ng was convicted in April for conspiracy to incite a riot, public nuisance, arson, criminal damage, manufacturing of explosives, administering poison and wounding with intent to do grievous bodily harm between October 2019 and June 2020.
from us


Telegram MadSharp: Unsafe
FROM American