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

macOS: Apple Silicon support (interpreter only) #1255

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from

Conversation

exverge-0
Copy link
Contributor

@exverge-0 exverge-0 commented Jul 11, 2024

Fixes #396(?), supersedes #1211 (I don't own BOTW and haven't been able to reproduce the issue on other games, but this fixes a similar error that only occurred on Apple Silicon)

The re-compiler hasn't been implemented and only the interpreter works. (and there's already an WIP aarch64 recompiler for cemu android, assuming that they plan on merging into this repo)

@exverge-0 exverge-0 changed the title macOS: Apple Silicon (interpreter only) macOS: Apple Silicon support (interpreter only) Jul 11, 2024
@Exzap
Copy link
Member

Exzap commented Jul 11, 2024

I'll be honest, it will probably be a while until we have a decent ARM recompiler that will outperform Rosetta so this seems a bit early. But I generally don't want to stand in the way of adding new target platforms. That said, the changes made here are detrimental for other platforms. Just on a quick glance some obvious issues:

  • Putting gx2WriteGatherPipe access behind a mutex is absolutely gonna wreck performance. Better to work with atomic pointers or manually insert memory barriers where needed.
  • mmuRange_HIGHMEM is supposed to match Wii U's memory map. I get that there is a 16KB page size restriction but other platforms don't have this so it should be conditional.
  • Lots of changes in the h264 decoder, would be nice if you could give an explanation?

@exverge-0
Copy link
Contributor Author

exverge-0 commented Jul 11, 2024

Lots of changes in the h264 decoder, would be nice if you could give an explanation?

On OSX, C functions are compiled with a leading underscore and the header files define the ASM functions as a normal C function, resulting in functions being called with a leading underscore but defined without one.
Admittedly now I see this could probably be done by just marking them with extern, I'll do that instead This results in the same thing.

Putting gx2WriteGatherPipe access behind a mutex is absolutely gonna wreck performance. Better to work with atomic pointers or manually insert memory barriers where needed.

Makes sense, I'll revert that and try something else

mmuRange_HIGHMEM is supposed to match Wii U's memory map. I get that there is a 16KB page size restriction but other platforms don't have this so it should be conditional.

Ah, I wasn't sure but that's what I somewhat assumed.

@exverge-0 exverge-0 marked this pull request as draft July 11, 2024 17:50
@exverge-0 exverge-0 force-pushed the macos-arm64 branch 4 times, most recently from e9a00d3 to 0328901 Compare July 12, 2024 02:33
@exverge-0 exverge-0 force-pushed the macos-arm64 branch 6 times, most recently from 6998fdd to ebb249c Compare July 20, 2024 19:35
…m64 rather than aarch64

cmake: Fix compiling for Apple Silicon
I've changed the range to accommodate for the Project Zero bug stated however I'm not sure if causes any other issues or if this is used, however it seems to work fine. Please correct me if true.
On Apple Silicon, PPCTimer estimates a terribily inaccurate RSTSC frequency and results in games (specifically tested Color Splash & MK8) run extremely fast especially in the title screens which unsurpisingly doesn't work that well.
The value hardcoded is the same frequency as on Rosetta.
Admittedly this probably isn't the best solution however it is accurate and it works.
"A MenuItem ID of Zero does not work under Mac"
Despite being disabled in InitBlendState, this still causes errors on MoltenVk, so just skip it altogether
Seemingly fixes cemu-project#396 (there's a multitude of errors there in the comments, specifically referring to the issue), however I don't own BOTW and can't confirm
Apple seemed to not have offsets for arguments on the stack
Either that or the offsets were just wrong, I'll test on a Linux VM and remove the conditonal if this still happens
For some reason, compiling with LLVM causes a segfault when any popup opens. This is specific to LLVM and works fine with the default compiler.
@exverge-0 exverge-0 marked this pull request as ready for review July 21, 2024 19:33
@exverge-0 exverge-0 marked this pull request as draft August 7, 2024 22:23
Revert "MMU: Make HIGHMEM address conditional"

This reverts commit f24fc3e.

Revert "MMU: Align pre-core memory space for 16kib page size"

This reverts commit dc1dc44.
@exverge-0 exverge-0 marked this pull request as ready for review August 8, 2024 00:22
src/gui/MainWindow.cpp Outdated Show resolved Hide resolved
Comment on lines 991 to 992
if (!_IsVkIntegerFormat(m_renderPassObj->GetColorFormat(0)))
pipelineInfo.pColorBlendState = &colorBlending;
Copy link
Member

Choose a reason for hiding this comment

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

This should iterate each color attachment and when an integer format is used then disable blending only for that specific attachment. Having one color attachment in integer format does not prevent blending for all the non-integer attachments.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Having one color attachment in integer format does not prevent blending for all the non-integer attachments.

I see how that could be an issue, however the main issue is that they are disabled, yet for some reason creating the pipeline on MoltenVk results in this error. The only other solution I could think of is to remove the color attachments entirely in InitBlendState if they are integer formats, though I'm not sure how that could be done without massively rewriting the code for what appears to be an issue with MoltenVk.

I originally made it like this since, at least on MK8, only the first color attachment would ever be in integer format, and if it were, the rest followed by empty attachments, though I see that this wouldn't be the case for all games. Other than the potential solution above, I'm not sure how else to deal with this.

Copy link
Member

Choose a reason for hiding this comment

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

I see. I don't want to chalk this down as a bug in MoltenVk yet because it seems to be too big of an oversight to me. I checked their code and I couldn't really see any logic that would enable blending if we didn't specifically ask for it. But more digging is required to understand this fully.

In the meantime an acceptable temporary workaround would be to disable all blending if ANY of the color attachments are integer format instead of only checking index 0. I also suggest making the workaround apply to MacOS/MoltenVk only.

exverge-0 and others added 3 commits August 8, 2024 12:21
Co-authored-by: Exzap <13877693+Exzap@users.noreply.github.com>
This reverts commit 6b6a538.
[skip ci]
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.

[MacOS] Corrupt pipeline cache when when booting game a 2nd time
2 participants