Skip to content

Collect ideas of Any CPU support #732

@Akarinnnnn

Description

@Akarinnnnn

#699 asked whether can we provide Any CPU DLLs, later I created a PR(#714 ) that provided basic implementation. But, during the impl process, I have found some questions. I need some feedback.

  • For now, I decide to limit Any CPU DLLs will only built by new standalone project(that is, Steamworks.NET.Standard), and introduces a new platform macro. This is because, our major consumer, Unity is using a Mono based CLR. I'm not sure how expensive the Any CPU wrappers are on it. I believe CoreCLR and corresponding one on .NET Framework, can properly eliminate unused wrapping branch for other platforms, then inline whole Any CPU wrapper. If Unity can also optimize them properly, add this macro for performance reason should not be valid.
  • It is sure that Turn standalone version targeting to Any CPU #714 is too large for review, should be split into smaller pieces, and merge them into a draft branch. These code changes of Any CPU is involves code generator, generated code and some hand written code. Through most hand written files only added a macro, but I remember there are some other changes. For next, here is my split plan:
    1. Split original P/Invoke holder class header CodeGen/src/templates/nativemethods.txt into 2 file. First is header, contains original platform detect, class declaration and P/Invoke names. Second file nativemethods_dllimport.txt is P/Invoke definition of free function. By split this file into 2 parts, platform agnostic P/Invoke generation can reuse the definition later.
    2. Add P/Invoke holder class header for win64 and other platforms. File named nativemethods_win64.txt and nativemethods_general.txt
    3. Add forwarder header to nativemethods_anycpu.txt. Any CPU is implemented by replacing original imported steam functions in NativeMethods with forwarder. In forwarder, it will first detect what platform we are running on, then forward arguments to corresponding underlying version(win64 or other).
    4. Add essential variables in CodeGen/src/interfaces.py, they will be used in next step. Also, generated file creation is advanced to here.
    5. Add forwarder class generation to generator, this is a big change. In current implementation, to make generator runnable, this change will approximately be 40 lines.
    6. Handle const usage of Packsize.value, since Any CPU can't rely const field to indicate packsize, Currently, I use macro STEAMWORKS_STANDALONE_ANYCPU, to remove most Pack = Packsize.value in [StructLayout] of Any CPU usage. Pack size sentinel test still good.
    7. Do some finalization.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions