Blinue / Magpie

An all-purpose window upscaler for Windows 10/11.
GNU General Public License v3.0
9.05k stars 478 forks source link

ARM64 适配 #308

Closed MikeWang000000 closed 8 months ago

MikeWang000000 commented 2 years ago

Expected behavior 预期的功能

与 #161 不同,微软目前提出了新的 ABI(即ARM64EC),可以让使用 x86 或 x64 依赖的程序生成 arm64 兼容代码。

Magpie 目前基于 .Net 6.0,亦拥有 arm64 支持。这让编译程序为 arm64 架构成为可能。

事实上,在目前最新的 Windows 11 on ARM 并装有 .NET 6.0 (x64) 的情况下,借助系统内部的二进制翻译,Magpie 已经能够完美运行。

但是,如果能提供 ARM64EC build,Surface Pro X 和 Apple Silicon 虚拟机用户将能获得更高的性能体验。


Different from #161, Microsoft has announced a new ABI (ARM64EC) that allows programs that use x86 or x64 dependencies to generate arm64 compatible code.

Magpie is currently based on .Net 6.0 which also has arm64 support. This makes it possible to compile programs for the arm64 architecture.

In fact, with the latest Windows 11 on ARM with .NET 6.0 (x64) installed, Magpie already works fine thanks to the binary translation inside the system.

But Surface Pro X and Apple Silicon virtual machine users will be able to get a higher performance experience if ARM64EC builds are available.

Reference:


目前ARM64EC还在Preview,不过还是希望可以作为Magpie的将来考虑。

Alternative behavior (optional) 近似的功能(可选)

No response

Blinue commented 2 years ago

感谢建议,ARM64EC 解决了将 Magpie 移植为 ARM64 的主要困难。感觉微软为了推广ARM平台不遗余力了

我已经决定在未来添加 ARM64 的支持,可能是原生或者 ARM64EC

Blinue commented 2 years ago

arm64.zip 这是一个原生 ARM64 的 demo,可以正常运行吗?

我没有 ARM64 设备,不知道有没有这方面的模拟器。

MikeWang000000 commented 2 years ago

非常高兴得知 Magpie 在 arm64 方面有了新的进展!🎉

不过,目前的环境中,Magpie(arm64) 还不能正常运作。

已知情况:

  1. 测试机器 CPU 为 M1(arm64),操作系统为 Parallels Desktop 上的 Windows 11。
  2. 在 x64 版本中,配合 x64 的 .NET Runtime 和 MSVC Runtime,可由 Windows 内置的指令转译程序正常启动,所有功能均正常,Anime4K_Upscale_S 可满帧率,虽然是以较大的耗电量。
  3. 在给出的 arm64 版本中,配合 arm64 的 .NET Runtime 和 MSVC Runtime,双击运行无任何反应。可见错误的系统日志。
[ 日志 ] > ```yaml Faulting application name: Magpie.exe, version: 0.0.0.0, time stamp: 0x6296e6c3 Faulting module name: ucrtbase.dll, version: 10.0.22000.376, time stamp: 0x3188e391 Exception code: 0xc0000409 Fault offset: 0x000000000007615c Faulting process id: 0xcec Faulting application start time: 0x01d8756f85ba687a Faulting application path: C:\Users\Admin\Desktop\arm64\Magpie.exe Faulting module path: C:\Windows\System32\ucrtbase.dll Report Id: 023ec435-0e65-474f-a0d8-1f4f99849c2a Faulting package full name: Faulting package-relative application ID: ```
[ 错误报告 ] > ```ini ================================================== Process File : Magpie.exe Event Name : Stopped working Event Time : 6/1/2022 12:25:33 PM User Name : All Users Exception Code : 0xc0000409 Exception Code Description: The system detected an overrun of a stack-based buffer in this application. This overrun could potentially allow a malicious user to gain control of this application. Exception Offset : 0x0007615c Fault Module Name : ucrtbase.dll Fault Module Version: 10.0.22000.376 Process Path : C:\Users\Admin\Desktop\arm64\Magpie.exe Report File Size : 10,544 Report File Path : C:\Users\All Users\Microsoft\Windows\WER\ReportArchive\AppCrash_Magpie.exe_e353f891693f298ff5dac99a6236a94ca9b6b_d53c5fb1_ef77ddb1-f2fa-4457-bfc3-e688a1ca29fd\Report.wer ================================================== Version=1 EventType=BEX64 EventTime=132985311337147710 ReportType=2 Consent=1 UploadTime=132985311338397387 ReportStatus=268435456 ReportIdentifier=ef77ddb1-f2fa-4457-bfc3-e688a1ca29fd IntegratorReportIdentifier=bc8d7a8c-078f-4f8a-97e5-1c08d37564ef Wow64Host=43620 NsAppName=Magpie.exe AppSessionGuid=00001fd8-0002-001e-76f7-85a26f75d801 TargetAppId=W:0006873a8abcc9dce360bc6bcfd9b4687a1d0000ffff!00001f1dc5e40b93aa4facbd5c4f2173cc2e56c4a1b8!Magpie.exe TargetAppVer=2022//06//01:04:10:43!0!Magpie.exe BootId=4294967295 TargetAsId=11305 IsFatal=1 EtwNonCollectReason=1 Response.BucketId=cdc8848909ff6272d88e7ca8a8b5625a Response.BucketTable=5 Response.LegacyBucketId=1769488767429993050 Response.type=4 Sig[0].Name=Application Name Sig[0].Value=Magpie.exe Sig[1].Name=Application Version Sig[1].Value=0.0.0.0 Sig[2].Name=Application Timestamp Sig[2].Value=6296e6c3 Sig[3].Name=Fault Module Name Sig[3].Value=ucrtbase.dll Sig[4].Name=Fault Module Version Sig[4].Value=10.0.22000.376 Sig[5].Name=Fault Module Timestamp Sig[5].Value=3188e391 Sig[6].Name=Exception Offset Sig[6].Value=000000000007615c Sig[7].Name=Exception Code Sig[7].Value=c0000409 Sig[8].Name=Exception Data Sig[8].Value=0000000000000000 DynamicSig[1].Name=OS Version DynamicSig[1].Value=10.0.22000.2.0.0.256.48 DynamicSig[2].Name=Locale ID DynamicSig[2].Value=1033 DynamicSig[22].Name=Additional Information 1 DynamicSig[22].Value=3a18 DynamicSig[23].Name=Additional Information 2 DynamicSig[23].Value=3a18228d91dd523c7942bd33ca6aa08c DynamicSig[24].Name=Additional Information 3 DynamicSig[24].Value=d580 DynamicSig[25].Name=Additional Information 4 DynamicSig[25].Value=d5808a25785b2ef4ee5736d48516f03c UI[2]=C:\Users\Admin\Desktop\arm64\Magpie.exe LoadedModule[0]=C:\Users\Admin\Desktop\arm64\Magpie.exe LoadedModule[1]=C:\Windows\SYSTEM32\ntdll.dll LoadedModule[2]=C:\Windows\System32\KERNEL32.DLL LoadedModule[3]=C:\Windows\System32\KERNELBASE.dll LoadedModule[4]=C:\Windows\System32\USER32.dll LoadedModule[5]=C:\Windows\System32\win32u.dll LoadedModule[6]=C:\Windows\System32\GDI32.dll LoadedModule[7]=C:\Windows\System32\gdi32full.dll LoadedModule[8]=C:\Windows\System32\msvcp_win.dll LoadedModule[9]=C:\Windows\System32\ucrtbase.dll LoadedModule[10]=C:\Windows\System32\ole32.dll LoadedModule[11]=C:\Windows\System32\combase.dll LoadedModule[12]=C:\Windows\System32\RPCRT4.dll LoadedModule[13]=C:\Windows\System32\OLEAUT32.dll LoadedModule[14]=C:\Windows\SYSTEM32\UxTheme.dll LoadedModule[15]=C:\Windows\SYSTEM32\VCRUNTIME140.dll LoadedModule[16]=C:\Windows\SYSTEM32\MSVCP140.dll LoadedModule[17]=C:\Windows\System32\IMM32.DLL LoadedModule[18]=C:\Windows\SYSTEM32\kernel.appcore.dll LoadedModule[19]=C:\Windows\System32\msvcrt.dll LoadedModule[20]=C:\Windows\System32\bcryptPrimitives.dll LoadedModule[21]=C:\Windows\System32\clbcatq.dll LoadedModule[22]=C:\Windows\System32\WinTypes.dll LoadedModule[23]=C:\Windows\System32\Windows.UI.Xaml.dll LoadedModule[24]=C:\Windows\System32\d2d1.dll LoadedModule[25]=C:\Windows\SYSTEM32\powrprof.dll LoadedModule[26]=C:\Windows\SYSTEM32\UMPDC.dll LoadedModule[27]=C:\Windows\SYSTEM32\bcrypt.dll LoadedModule[28]=C:\Windows\System32\sechost.dll State[0].Key=Transport.DoneStage1 State[0].Value=1 OsInfo[0].Key=vermaj OsInfo[0].Value=10 OsInfo[1].Key=vermin OsInfo[1].Value=0 OsInfo[2].Key=verbld OsInfo[2].Value=22000 OsInfo[3].Key=ubr OsInfo[3].Value=376 OsInfo[4].Key=versp OsInfo[4].Value=0 OsInfo[5].Key=arch OsInfo[5].Value=12 OsInfo[6].Key=lcid OsInfo[6].Value=2052 OsInfo[7].Key=geoid OsInfo[7].Value=244 OsInfo[8].Key=sku OsInfo[8].Value=48 OsInfo[9].Key=domain OsInfo[9].Value=0 OsInfo[10].Key=prodsuite OsInfo[10].Value=256 OsInfo[11].Key=ntprodtype OsInfo[11].Value=1 OsInfo[12].Key=platid OsInfo[12].Value=10 OsInfo[13].Key=sr OsInfo[13].Value=0 OsInfo[14].Key=tmsi OsInfo[14].Value=221639452 OsInfo[15].Key=osinsty OsInfo[15].Value=2 OsInfo[16].Key=iever OsInfo[16].Value=11.1.22000.0-11.0.1000 OsInfo[17].Key=portos OsInfo[17].Value=0 OsInfo[18].Key=ram OsInfo[18].Value=4096 OsInfo[19].Key=svolsz OsInfo[19].Value=31 OsInfo[20].Key=wimbt OsInfo[20].Value=0 OsInfo[21].Key=blddt OsInfo[21].Value=210604 OsInfo[22].Key=bldtm OsInfo[22].Value=1628 OsInfo[23].Key=bldbrch OsInfo[23].Value=co_release OsInfo[24].Key=bldchk OsInfo[24].Value=0 OsInfo[25].Key=wpvermaj OsInfo[25].Value=0 OsInfo[26].Key=wpvermin OsInfo[26].Value=0 OsInfo[27].Key=wpbuildmaj OsInfo[27].Value=0 OsInfo[28].Key=wpbuildmin OsInfo[28].Value=0 OsInfo[29].Key=osver OsInfo[29].Value=10.0.22000.376.arm64fre.co_release.210604-1628 OsInfo[30].Key=buildflightid OsInfo[31].Key=edition OsInfo[31].Value=Professional OsInfo[32].Key=ring OsInfo[32].Value=Retail OsInfo[33].Key=expid OsInfo[34].Key=fconid OsInfo[34].Value=25704915,1,2,1 OsInfo[35].Key=containerid OsInfo[36].Key=containertype OsInfo[37].Key=edu OsInfo[37].Value=0 OsInfo[38].Key=servicinginprogress OsInfo[38].Value=0 FriendlyEventName=Stopped working ConsentKey=BEX64 AppName=Magpie.exe AppPath=C:\Users\Admin\Desktop\arm64\Magpie.exe NsPartner=windows NsGroup=windows8 ApplicationIdentity=4D82C53C1821F330284A24E9CCB62E30 MetadataHash=1340164409 ```

总的来说,系统由于The system detected an overrun of a stack-based buffer in this application. This overrun could potentially allow a malicious user to gain control of this application.结束了进程。

我没有这方面的经验,暂时无法判断是不是我自身环境依赖的问题。

不过,如有需要,我可以随时提供测试:)

Blinue commented 2 years ago

有条件的话我推荐你自行编译。切换到 mega/xaml 分支选择 ARM64 平台即可。

编译为 ARM64 是完全可能的,v0.10 不再使用 .NET,且所有依赖都可以使用 conan 编译为 ARM64。运行不了的原因我没有头绪...

MikeWang000000 commented 2 years ago

非常感谢。 我会尝试自行编译,如果有有用的信息会在这里汇报。 (近期有些个人事务,可能更新不太及时哈)

MikeWang000000 commented 2 years ago

有条件的话我推荐你自行编译。切换到 mega/xaml 分支选择 ARM64 平台即可。

编译为 ARM64 是完全可能的,v0.10 不再使用 .NET,且所有依赖都可以使用 conan 编译为 ARM64。运行不了的原因我没有头绪...

mega/xaml 分支在我这里无法编译(x64, arm64 均不可),主分支 x64 我是可以编译的。

The Windows SDK version 10.0.17134.0 (or later) was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution".

而我是有 10.0.22000.0 的 SDK 的,不知道编译环境发生了什么样的改变?

Blinue commented 2 years ago

mega/xaml 使用了完全不同的技术,你需要安装 UWP 开发环境。SDK 只要求 22000,你可以重定目标解决方案。

(mega/xaml 分支没实现任何功能,还在开发中)

MikeWang000000 commented 1 year ago

隔了很久以后的回复: ARM64 的适配没有我想象的那么简单,辛苦 Magpie 开发者了。

目前编译 ARM64 中可能会遇到的困难有:

ARM64 中缺少 _umul128() 支持: https://github.com/Blinue/Magpie/blob/25107154c76e60319196254bcaff5e1b7dfa4f3d/src/Shared/Utils.cpp#L47

ARM64 中缺少 __cpuid() 支持: https://github.com/Blinue/Magpie/blob/25107154c76e60319196254bcaff5e1b7dfa4f3d/src/Magpie.Core/OverlayDrawer.cpp#L376-L402

ARM64 中 yas 依赖中判断大小端代码中的宏存在问题,上游将下面 PR 合并后可解决: niXman/yas #121

此外,因为以下更新的影响,22000 的 SDK 已经不能编译了(这是题外话) https://github.com/Blinue/Magpie/blob/25107154c76e60319196254bcaff5e1b7dfa4f3d/src/Magpie/XamlApp.cpp#L375-L379

然而编译完成之后仍会出现 The Application Was Unable To Start Correctly (0xc00007b) 错误。
由于 Visual Studio 要求对 ARM64 设备 “remotely target”,我还不具备这种调试的条件,因此现在还没有新进展。


现在仔细分析了一下,ARM64 下,Magpie 在微软的 x64 实时二进制翻译下可以完美运行,而 Magpie 本身是 GPU 密集型的,CPU 占用率不到 1%,因此性能损失也不是很大。 Magpie 使用的 DirectX 部分则是以原生 ARM64 的方式工作的,而 GPU 的部分则更不用谈二进制翻译了。 原生 ARM64 作为将来的一个选项保留着不错,现在可能还不太成熟...

Blinue commented 1 year ago

谢谢做了这么多工作!

winui是一个笨重的框架,可能的话我会实现原生arm64。现在程序里确实使用了x86机器指令,因此需要一些适配工作。

sdk版本已升级为22621。

你试试https://github.com/Blinue/Xaml-Islands-Cpp 能编译成arm64吗?

Blinue commented 1 year ago

姑且修复了 ARM64 的编译错误。

_umul128 和 __cpuid 已修复。 YAS 暂时使用 workaround 修复编译。 https://github.com/Blinue/Magpie/blob/440d6a7688dcee20e8f838fd8efa6ee6093ec8e6/src/Magpie.Core/EffectCacheManager.cpp#L10-L14

Blinue commented 1 year ago

我发现了一个愚蠢的错误,Magpie.Core 在 ARM64 配置下居然编译了 x64 版本。现在已修复,有空的话你可以再试试。

https://github.com/Blinue/Magpie/blob/0d043df1df8290f1005cd5fc72bd55240c4c0e59/Magpie.sln#L85-L86

MikeWang000000 commented 1 year ago

dev 分支编译一切正常了。另外,我仍是使用 22000 编译的。

不过依然是 0xc0000409,与您在 6 月时提供的二进制文件是同一个问题。

表现为启动时创建了 logs\magpie.log 目录和文件,没有 UI 呈现,并 crash 。magpie.log 内容为空。事件查看器显示 0xc0000409

同样地 Xaml-Islands-Cpp 可编译,但亦无法运行:0xc0000409

编译出的二进制和 crash dump 均放在附件了,不知能否有所帮助。

环境:

Windows 11 Pro 21H2 (10.0.22000.376)
64-bit operating system, ARM-based processor
Blinue commented 1 year ago

非常感谢测试。如果不能亲自调试的话恐怕找不出这个错误。这个功能只能暂且搁置了,希望尽快有 ARM64 的虚拟机吧。

Blinue commented 1 year ago

@all-contributors please add @MikeWang000000 for userTesting

allcontributors[bot] commented 1 year ago

@Blinue

I've put up a pull request to add @MikeWang000000! :tada:

Blinue commented 8 months ago

这个 issue 已经很久,我终于通过 QEMU 成功运行 Win11 ARM64。正在调查崩溃问题!

Blinue commented 8 months ago

经过艰苦的调试,终于解决了。原因是 ARM64 配置下不会自动导出 DllGetActivationFactory,不知道为什么和 x64 不同,可能是编译器的 bug。就连官方示例都因为这个错误无法在 ARM64 上运行。

这是一个能正常运行的 XAML Islands 程序:XamlIslandsCpp.zip

Blinue commented 8 months ago

下载 ARM64 版本 -> https://github.com/Blinue/Magpie/actions/runs/7348817673/artifacts/1138027062

因为虚拟机太慢了,我只进行了简单的测试,基本功能是没问题的。

MikeWang000000 commented 8 months ago

感谢 Blinue 大佬的工作,目前这个版本在我的机器上可以正常运行。 进行了简单的测试工作,目前四种捕获方式中:

Blinue commented 8 months ago

arm64 分支是从 #643 分叉的,Desktop Duplication 和 DwmSharedSurface 还没有实现。资源管理器的问题是因为 GDI 无法捕获到 XAML Islands,是捕获方式的固有缺陷,GDI 也无法捕获 Magpie 主窗口。

现有代码没有对 ARM64 做适配,所以可能会有 bug,遇到的话请提新 issue🥳

MikeWang000000 commented 8 months ago

Good job! 那这样基本功能都是处于通过可用的状态了。

刚刚测试 ARM 版本遇到的另一个小问题,就是 FPS 指示没有工作,不知道是不是这个分支还没有实现?

Blinue commented 8 months ago

刚刚测试 ARM 版本遇到的另一个小问题,就是 FPS 指示没有工作,不知道是不是这个分支还没有实现?

还没有实现。新架构有两种帧率,有点复杂。

luojunyuan commented 8 months ago

虽然有点本末倒置还是好奇有没有可能临时让arm版本Desktop Duplication正常工作,比如调用x86的接口。。不太指望得上微软将来哪一天会支持这些边边角角的问题。

请问Blinue大人是否可以私信我留下电子邮箱地址,我可以无偿提供arm设备,如果您不方便的话就算了。

Blinue commented 8 months ago

@luojunyuan 你可能误解了,还有两种捕获方式没有实现是因为 PR 还没有完成,而不是实现不了。另外在新架构中,Desktop Duplication 没有功耗优势了,Graphics Capture 是最推荐的。

请问Blinue大人是否可以私信我留下电子邮箱地址,我可以无偿提供arm设备,如果您不方便的话就算了。

谢谢好意,但不必麻烦了。ARM64 已经适配完成,请等待 v1.0 发布。