sharpemu icon indicating copy to clipboard operation
sharpemu copied to clipboard

Stray [PPSA02100]

Open AlexsandroZanella2 opened this issue 4 months ago • 4 comments

Game Name

Stray

Title ID

PPSA02100

Game Version

1.005

Current Status

Crashes on boot

Description

Crashes on boot, whithout any interface.

Log File

PPSA02100-20260722-101141.log

Last Milestone / First Error

[10:12:05.483] [LOADER][ERROR] Execution stalled with no import progress for 20s (imports=256).

Operating System

Windows 11

CPU

i5 8400

GPU

NVIDEA GeForce RTX 2060 OC Asus TUF 6GB

RAM

16 GB

Emulator Version / Commit

5f97031

Renderer

Vulkan

Additional Notes

commit https://github.com/sharpemu/sharpemu/commit/5f97031df5eb3347101f897938a4be6aae6392c5

AlexsandroZanella2 avatar Jul 22 '26 13:07 AlexsandroZanella2

Re-tested this (PPSA02101, EU SKU of the same title/build 01.002.000) on current main (ca90d17, plus my own unmerged import-logging PR #878 on top — unrelated to the render path below) with very different hardware than the original report: Windows 11, Ryzen 9 9800X3D, AMD RX 9070 XT (the original report used an Nvidia RTX 2060). The original "stalled with no import progress for 20s" symptom does not reproduce here — it gets much further, past module loading and into real rendering. Two distinct symptoms on 5 separate runs, both worth tracking:

1. Non-deterministic access violation inside the AMD driver's compute pipeline compiler — same signature as #870/#11 (Astro Bot)

1 of 5 runs crashed with the identical stack as the Astro Bot crash already reported on #870:

0xC0000005
   at Silk.NET.Vulkan.Vk.CreateComputePipelines(...)
   at SharpEmu.Libs.VideoOut.VulkanVideoPresenter+Presenter.CreateComputePipeline(...)
   at SharpEmu.Libs.VideoOut.VulkanVideoPresenter+Presenter.CreateComputeDispatchResources(...)
   at SharpEmu.Libs.VideoOut.VulkanVideoPresenter+Presenter.ExecuteComputeDispatchCore(...)

Dumped and disassembled the SPIR-V for the compute shaders submitted right around the crash point (SHARPEMU_SHADER_SPIRV_DUMP_DIR). Several of them use the same software wave64-over-two-wave32 emulation bridge discussed on #870 — wave64MaskScratch/wave64BroadcastScratch, GroupNonUniformBallot/GroupNonUniformVote, OpExecutionMode %main LocalSize 64 1 1 (and a couple at LocalSize 8 8 1, still 64 total invocations). All of them validate cleanly with spirv-val (exit 0, zero errors) — spec-valid SPIR-V, same as the Astro Bot case.

This is a second, independent title hitting the exact same driver crash through the exact same emulation code path, on the same RDNA4 hardware — meaningfully strengthens the case that #870's fix (native wave64 SPIR-V instead of the software bridge) isn't just a performance win, it may be sidestepping a real AMD driver compiler bug on RDNA4.

2. Non-determinism itself is notable. The very first run crashed. Re-running with SHARPEMU_SHADER_SPIRV_DUMP_DIR set (to capture the SPIR-V) hit the identical dispatch sequence (same submission count, same shader) but did not crash and ran cleanly for the rest of the observation window. 3 further bare re-runs also didn't crash. That's consistent with a driver-side race/timing sensitivity rather than a deterministic bad-input crash — possibly relevant if anyone ends up root-causing this against the driver itself.

3. When it doesn't crash: black screen, unresponsive, matches a real user report. All 4 non-crashing runs stop making visible progress at the same spot — right after that compute dispatch sequence, ExecuteOrderedGuestFlip (VulkanVideoPresenter.cs:5885) logs:

[LOADER][WARN] vk.flip_capture_failed version=1 queue=dcb.graphics addr=0x... found=False initialized=False

Looking at the code (VulkanVideoPresenter.cs:5889-5899), when the guest's flip target address isn't in _guestImages (or is but was never marked Initialized), the flip is silently dropped — no frame ever gets presented, but nothing crashes or logs an error either, just a [WARN]. That matches, symptom-for-symptom, what was observed interactively on this same run: game boots, goes fullscreen, black screen, no input response. Haven't traced why this particular render target's flip address never gets registered/initialized — flagging the exact log line and code location in case it's a fast diagnosis for someone who knows the AGC render-target registration path better.

Happy to pull further diagnostics (register dumps, more SPIR-V dumps, repeat-run counts) if useful — dumps and logs available on request.

theantipopau avatar Sep 11 '26 02:09 theantipopau

Follow-up after re-testing against latest main (post-#880/#881). Wanted to check whether either PR's fixes (the shader-header/register-pair handling in particular, since #880 explicitly targets "shader headers that do not contain embedded program-register pairs") touched this case.

Good news: #880 does fix one thing here. The agc.create_shader ... unexpected-registers type=8 / ORBIS_GEN2_ERROR_INVALID_ARGUMENT failures from my first round of testing are gone — those same type=8 shader headers now correctly go through the skip-pgm-patch path instead of being rejected. Confirmed via log diff between the two builds.

But the black screen (vk.flip_capture_failed ... found=False initialized=False) still reproduces 4/4 on latest main. Re-ran with the same rip, same hardware. Every run still stops making visible progress at the same point.

New lead from this round: right where progress stops, there's a burst of:

[LOADER][WARN] Import#4133197 result: ORBIS_GEN2_ERROR_DEADLOCK (9UK1vLZQft4) rdi=0x0000000807E2E680 ...
[LOADER][WARN] Import#4149712 result: ORBIS_GEN2_ERROR_DEADLOCK (9UK1vLZQft4) rdi=0x0000000807E2E680 ...

9UK1vLZQft4 = scePthreadMutexLock. Same guest mutex address (0x0000000807E2E680) repeatedly returning DEADLOCK, hundreds of thousands of import calls apart — looks like a real retry loop stuck permanently failing to acquire this lock, which would be consistent with whatever's supposed to draw into the real backbuffer never running.

I don't have proof this causes the black screen (correlation, not confirmed causation — no Demon's Souls-style definitive repro chain here), but while reading PthreadMutexLockCore (KernelPthreadCompatExports.cs) to check, I noticed something that looks worth a second pair of eyes: the self-owned/MutexTypeNormal case is checked twice with different outcomes.

  • First check, unsynchronized, KernelPthreadCompatExports.cs:853-864: if state.Type == MutexTypeNormal and the calling thread already owns it, a non-tryOnly call succeeds (IncrementRecursion(), returns OK).
  • Second check, same condition, this time under lock(state.SyncRoot), KernelPthreadCompatExports.cs:913-923: identical MutexTypeNormal + self-owned + non-tryOnly case instead returns ORBIS_GEN2_ERROR_DEADLOCK.

The second block is only reachable when the earlier unsynchronized read of state.OwnerThreadId at line 828 didn't match the current thread, but the later read under the lock at line 881 does. I can't fully explain how that sequence is reached without a live repro harness for this exact code path, but the two blocks disagreeing on the outcome for the literal same case seems like a real inconsistency regardless of the exact trigger — flagging in case it's a fast diagnosis for someone who knows this locking code's history better than I do. Happy to try to build a minimal repro/unit test for the discrepancy if that'd help, just didn't want to guess at a fix without being sure of the actual trigger path first.

theantipopau avatar Sep 11 '26 22:09 theantipopau

Correction/update to my mutex-lock comment above. Traced the git history of PthreadMutexLockCore (git log -p -L on both the fast-path and SyncRoot-protected self-owned/MutexTypeNormal checks) and found this isn't the bug I initially framed it as:

  • #451 added the fast-path check I originally cited — self-relock on NORMAL returns OK (compatibility recursion).
  • #748 deliberately reverted the other copy of this same check (the SyncRoot-protected one) back to a real EDEADLK, specifically because the permissive behavior was starving other threads on some other title. That's an intentional, evidence-based decision already made by the project — not a bug.

#748 just didn't update the fast-path copy from #451, so the two disagreed depending on which check a call happened to reach. That's a real but narrow inconsistency, fixed in #884 — but I tested it against this exact repro before opening that PR, and it does not change Stray's observed behavior. This title was already reaching the SyncRoot-protected check, which already returned EDEADLK before #884.

So the actual open question is unchanged from before: something is causing a genuine self-relock condition to be detected on this guest mutex in a tight retry loop. Given #748's fix was validated against a real title, this EDEADLK return is very likely correct/intentional emulation, not a SharpEmu bug — which shifts the real question to why the guest keeps hitting it and retrying forever (a real guest-side bug SharpEmu is correctly surfacing, vs. a SharpEmu thread-identity issue causing a false self-owned detection between what are actually two different guest threads). I don't have enough certainty to distinguish those two possibilities yet. Flagging the correction so this doesn't stay attributed to the wrong cause.

theantipopau avatar Sep 12 '26 11:09 theantipopau

One more correction/refinement on the mutex angle, now with direct per-call tracing (SHARPEMU_LOG_PTHREAD_MUTEX_FILTER) rather than just the sampled import-result log.

The spinning mutex is MutexTypeAdaptiveNp (type 4), not MutexTypeNormal. That means #884 (the fast/slow-path self-relock consistency fix I mentioned earlier) was never relevant to this hang at all — confirmed now by type, not just by the earlier before/after test showing no behavior change.

More importantly: this is not a failing lock. Traced one full run (62,378 calls to the same mutex address):

  • current= is one constant guest thread ID for every single call — no thread-identity confusion.
  • result=OK in 96% of calls (59,954 / 62,378). Only 4% (2,424) hit the adaptive-mutex DEADLOCK path.
  • owner= alternates between 0 and that same constant thread ID — a real, correctly-detected self-relock on the minority of calls, and a real, correctly-granted lock the rest of the time.

So characterizing this as "a mutex deadlock spin" was imprecise on my part — it's an extremely hot (thousands/sec), mostly successful lock/unlock loop that simply never leads anywhere. I pulled a guest RBP-chain walk (temporary, since removed) at the DEADLOCK call sites and got a real, stable caller chain (not corrupted memory) resolving to guest code — I don't have symbol/disassembly tooling in reach to name the actual function, so I can't say what shared state this loop is polling for or why it never sees it flip.

Net effect on where I think the actual blocker is: not in the pthread/kernel layer — the mutex primitive is behaving correctly. The real question is upstream of it (a missing wake signal on whatever this loop polls, or possibly just a legitimate idle worker-thread pattern with the true blocker sitting elsewhere entirely). Flagging so nobody spends time on the mutex implementation itself chasing this specific symptom — it's the wrong layer.

theantipopau avatar Sep 12 '26 21:09 theantipopau