Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved Compilation post processing

Discussion in 'Scripting Dev Blitz Day 2023 - Q&A' started by OndrejP, Feb 22, 2023.

  1. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    303
    Is there some special compilation post processing, which will be required to make everything work?
    How will be Unity internal calls handled?

    Please go a bit into detail if possible :)
     
    Last edited: Feb 22, 2023
  2. Thaina

    Thaina

    Joined:
    Jul 13, 2012
    Posts:
    1,157
    [InitializeOnload] ?
     
  3. xoofx

    xoofx

    Unity Technologies

    Joined:
    Nov 5, 2016
    Posts:
    416
    I'm not entirely sure about this question. Could you clarify what do you mean by ""post processing that would be required to make everything work"?

    @JoshPeterson has shared a few blog posts already that shed some lights about how we are tackling this problem:
    Expect to have more blog posts giving more details like this in the future!
     
  4. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    303
    Currently there's this:

    Code (CSharp):
    1.         [MethodImpl(MethodImplOptions.InternalCall)]
    2.         [NativeMethod(Name = "SetSelfActive")]
    3.         public extern void SetActive(bool value);
    What happens when this method is called in .NET Core?
    I'm guessing Mono runtime was modified somehow to call native method named "SetSelfActive".
    I'm not sure how exactly it worked, but I'm interested in knowing more.

    By post processing I meant if there's some compilation step which changes the IL code generated by compiler.
    How does .NET Core know what native method to call?
    The way I see is that either IL or .NET runtime has to be modified to allow this.

    I've read both articles and they provide great detail, they tell me what happens on the C++ side, but not how the execution gets there.
     
  5. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    In this case the .NET Runtime knows what to do. It understands how to look up that method in a table of known internal call methods, and invoke the proper function pointer.

    In some cases, we can pre-bake that information into the build (this is what IL2CPP does) to avoid the need for a one-time lookup of the function pointer at runtime.
     
    OndrejP likes this.
  6. OndrejP

    OndrejP

    Joined:
    Jul 19, 2017
    Posts:
    303
    Oh, I didn't know you can add function pointers into table of known internal calls. That sounds great, thank you!

    What's the lookup based on? I'd guess assembly name, type name and method name?
    Or is it something else (e.g. tokens?)
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,920
    The matching is based on method and type names.
     
    OndrejP likes this.