Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds native dependencies for win-arm64 #2644

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

azeno
Copy link
Collaborator

@azeno azeno commented Feb 16, 2025

PR Details

Allows to develop and also run games on win-arm64.

Needs MSVC v143 - VS2022 C++ ARM64 build tools (Latest)

  • The used versions of those dependencies are often rather dated and didn't build out of the box on win-arm64 / Visual Studio 2022, minimal patches had to be applied. Need to push/document those separately.
  • As far as I understood PVRTexLib is delivered as binary only and there's no win-arm64 - therefor added a check to not load it at all. In the end it's only needed by the asset compiler, which in turn is platform neutral. However when invoking it on a arm64 machine, the dotnet path/to/asset/compiler will launch it in arm64. If there would be some option to launch it in x64 we wouldn't have any issues with asset compiling. Still the editor might have issues, since its running in process?
  • Removed the FreeImageNET load - it's not used anywhere in code
  • Fixes some PInvoke signatures in DxtWrapper

The game studio also runs on arm64, but one must set the runtime identifiers in Stride.GameStudio/Editor/Assets.Presentation accordingly. Would be nice to add an arm64 version to the installer, but different topic I'd say.

FFmepg

checkout.bat says to use n3.3.3 tag however I didn't manage to get it to build. Was therefor using release/3.4 as a base.
Basically had to cherry-pick two commits from main branch in regards to arm64.
A quick test with importing a video asset and playing it later in the game worked.
https://github.com/azeno/FFmpeg/tree/win-arm64

FreeImage

  • Added a checkout.bat file which will also apply the needed fixes

Recast

Guessed the commit by comparing the checked in header files to those in the original repo. Added the used commit-id to checkout.bat file.

Needed PRs in other repos

Related Issue

#2397

Types of changes

  • Docs change / refactoring / dependency upgrade
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My change requires a change to the documentation.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • I have built and run the editor to try this change out.

Comment on lines -3 to +4
<StrideNativePathLibsWindows>libCompilerRt.lib libCelt.lib</StrideNativePathLibsWindows>
<StrideNativePathLibsUWP>libCompilerRt.lib libCelt.lib Xaudio2.lib</StrideNativePathLibsUWP>
<StrideNativePathLibsWindows>libCelt.lib</StrideNativePathLibsWindows>
<StrideNativePathLibsUWP>libCelt.lib Xaudio2.lib</StrideNativePathLibsUWP>
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure this lib is not necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The linker was happy. It would've complained I assume.

@@ -515,10 +515,10 @@ internal class Utilities
[DllImport("DxtWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Unicode), SuppressUnmanagedCodeSecurity]
private extern static void dxtComputePitch(DXGI_FORMAT fmt, int width, int height, out int rowPitch, out int slicePitch, CP_FLAGS flags);

[DllImport("DxtWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Auto), SuppressUnmanagedCodeSecurity]
[DllImport("DxtWrapper", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity]
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ansi ? Why?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If we look in the C header, the method is defined with char (1 byte). With Auto we don't know what it will take, clearly on arm64 it took the wrong one. I debugged that part, the data I got on unmanaged was garbage with Auto. With Ansi all good.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems legit. I quickly tested on Linux DDS and TGA files, no regression here 👍

@azeno azeno force-pushed the feature/win-arm64 branch from 11c7e9e to 6ceecf7 Compare February 17, 2025 17:34
@azeno
Copy link
Collaborator Author

azeno commented Feb 17, 2025

@Kryptos-FR @Jklawreszuk I just force pushed - added more info in the PR summary. For those deps where Stride maintains a fork I created PRs, and for those where it doesn't I added patch files or forked myself if the original repo was hosted on github.

@azeno azeno mentioned this pull request Feb 17, 2025
8 tasks
- The used versions of those dependencies are often rather dated and didn't build out of the box on win-arm64 / Visual Studio 2022, minimal patches had to be applied
- As far as I understood PVRTexLib is delivered as binary only and there's no win-arm64 - therefor added a check to not load it at all. In the end it's only needed by the asset compiler, which in turn is platform neutral. However when invoking it on a arm64 machine, the `dotnet path/to/asset/compiler` will launch it in arm64. If there would be some option to launch it in x64 we wouldn't have any issues with asset compiling. Still the editor might have issues, since its running in process?
- Removed the FreeImageNET load - it's not used anywhere in code
- Fixes some PInvoke signatures in DxtWrapper
@azeno azeno force-pushed the feature/win-arm64 branch from 6ceecf7 to aa6e55c Compare February 17, 2025 18:03
@Kryptos-FR Kryptos-FR requested a review from xen2 February 17, 2025 18:17
Copy link

@anthony-linaro anthony-linaro left a comment

Choose a reason for hiding this comment

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

A quick initial pass, just based on a read through

sources/native/Stride.Native.targets Outdated Show resolved Hide resolved
@@ -138,6 +144,11 @@
<Exec Condition="'%(StrideNativeCFile.Extension)' == '.cpp'" Command="&quot;$(StrideNativeClangCommand)&quot; -gcodeview -fno-ms-extensions -nobuiltininc -nostdinc++ $(StrideNativeClangCPP) $(StrideNativeClang) -DNEED_DLL_EXPORT -o &quot;$(OutputObjectPath)\win-x64\%(StrideNativeCFile.Filename).obj&quot; -c &quot;%(StrideNativeCFile.FullPath)&quot; -fms-extensions -DWINDOWS_DESKTOP -target x86_64-pc-windows-msvc" />
<MSBuild Projects="$(MSBuildThisFileDirectory)WindowsProjects\WindowsDesktop\WindowsDesktop.vcxproj" Targets="Build" Properties="StrideNativeOutputName=$(StrideNativeOutputName);StrideNativeOutputDir=$(StrideNativeOutputPath)\runtimes\win-x64\native;StrideDependenciesDir=$(MSBuildThisFileDirectory)..\..\deps\;StrideNativePathLibs=libNativePath.lib $(StrideNativePathLibsWindows);StrideNativeProjectFolder=$(ProjectDir);StrideNativeProjectObjFolder=$(OutputObjectPath)\win-x64;Configuration=$(Configuration);Platform=x64" StopOnFirstFailure="true" />

<MakeDir Directories="$(OutputObjectPath)\win-arm64" Condition="'$(StrideNativeWindowsArm64Enabled)' == 'true'"/>
<Exec Condition="'%(StrideNativeCFile.Extension)' != '.cpp' AND '$(StrideNativeWindowsArm64Enabled)' == 'true'" Command="&quot;$(StrideNativeClangCommand)&quot; -gcodeview -fno-ms-extensions -nobuiltininc -nostdinc++ $(StrideNativeClang) -DNEED_DLL_EXPORT -o &quot;$(OutputObjectPath)\win-arm64\%(StrideNativeCFile.Filename).obj&quot; -c &quot;%(StrideNativeCFile.FullPath)&quot; -fms-extensions -DWINDOWS_DESKTOP -target aarch64-pc-windows-msvc" />

Choose a reason for hiding this comment

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

Excuse my unfamiliarity with the Stride3D codebase here, but have you tested this with clang?

If it works, it might even be beneficial to compile everything with clang, instead of MSVC, I found when I moved Blender builds to clang-cl instead of MSVC, I got a 46% perf improvement in rendering workloads.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wanted to keep the changes arm64 related only. Modernising the native build chain would certainly be great but I believe that should be done separately. There are already attempts to so, for example one using zig which in turn uses clang.

Copy link
Member

Choose a reason for hiding this comment

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

Yes I think we need another issue for it.

@archanox
Copy link

Awesome job on picking this up again after I unceremoniously gave up.
Looks like you actually did the bits with the precompiled build artifacts successfully, which were too daunting for me due to how inconsistent it was.
Ideally it would be all built as part of the entire build process as to avoid future issues with additional platform bring-up.

I know my attempt was pretty messy, but hopefully there was something worthwhile to be taken from it, in particular the strange arm64 msbuild registry location.

@azeno
Copy link
Collaborator Author

azeno commented Feb 18, 2025

While trying to get a grip on the build error of the Visual Studio package on teamcity:

  • Did a console build locally ( msbuild Stride.VisualStudio.sln /v:m /m /nr:false /p:StrideSkipUnitTests=true /restore) and saw that one invocation of Stride.Core.Tasks was using a wrong path. See my commit above for details.
  • After that it was building fine locally. However on teamcity it's failing with a different error at MSBuildLocator.RegisterDefaults() in Stride.Core.Tasks - anyone any idea what's going on there?

@Kryptos-FR
Copy link
Member

Did you try to build on Linux or Windows? It's ok to fail on Linux because those package are for Visual Studio which is Windows-only.

@azeno
Copy link
Collaborator Author

azeno commented Feb 18, 2025

Turns out the Visual Studio update removed .NET 8 on the build machine. @xen2 just re-installed it, should be ok now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants