Boot Marvel's Spider-Man: Miles Morales through the intro movie #427

Closed
github-bot wants to merge 18 commits from gh-pr/427/head into gh-pr/427/base
Owner

@⁠itsmemac on GitHub · 2026-08-31 18:41 UTC · original
itsmemac:spiderman-intro-movie → main · +3514 −277 · 89 files · 18 commits · closed without merging

What this does

Takes Marvel's Spider-Man: Miles Morales from failing on its third frame to playing the full intro movie, on a stock Windows build with no environment variables set.

Grouped into 18 commits so they can be cherry-picked independently. Each is described below with why it exists. Commits 1 and 11 are the ones to look at first — 1 is an unrelated build fix that stands alone, and 11 is the only one that changes behaviour for every title.

Testing

  • Windows, clang-cl, MSVC 14.29 (VS2019) STL, NVIDIA RTX 3060 Laptop (6 GB).
  • ctest: 33/35. shader_recompiler_compute and texture_cache_image_overlap fail — they fail identically on unmodified main, verified by building upstream with only commit 1 applied. This PR introduces no test regressions.
  • Spider-Man: reaches the end of the intro (~145 s, ~350 flips), then stops at masterSemaphore.cpp:56. The menu does not come up yet.
  • Astro's Playroom: stops on unmodified main at a shader CFG failure after 3-5 s; with this PR it gets past that and reaches a different, later failure in PM4 register decode (unknown sh reg at 01169: 0xca). Still not playable, but not a regression.
  • Not tested on Linux or macOS, and not tested on any other title.

The commits

1. build: fix clang-cl compile of ResourceTracking — main does not compile with clang-cl today. Tracker::IndirectImagePlan is in an anonymous namespace, so std::projected cannot be formed and the three std::ranges
algorithms over it are rejected. CI misses it because it never builds kyty_emulator. Independent of everything else here.

2-5. Self-contained shader fixes — V_CMP_LT_U64 was missing from the VOPC table; wave64 subgroup broadcast needs workgroup-wide lowering because OpGroupNonUniformShuffle at Subgroup scope only reaches 32 lanes (DS_BPERMUTE
and DS_SWIZZLE deliberately keep the raw subgroup id, being defined on independent halves); S_CMP against an exec mask is the "are any lanes live" idiom and needs a real ballot; buffer loads were clobbering lanes the exec mask had masked off.

6-8. Descriptor and control-flow resolution — typed phis and ReadFirstLane in the SRT walker (the latter only for non-image descriptors, where every lane holds the same handle); loops whose selection merge escapes the body; S_SWAPPC_B64 indirect calls resolved from the dispatch side, where the user data is already in hand, which is the only place that breaks the circular dependency described in the commit message.

9. recompiler: allow a shader to be refused instead of aborting - the change that actually unblocks the boot. CompileOptions.non_fatal / CompileResult.unsupported; the three give-up points record and unwind instead of EXIT. Nothing changes when non_fatal is clear.

10. Tessellation patch control points draws were hardcoded to 3 control points; take the real count from VGT_LS_HS_CONFIG.HS_NUM_INPUT_CP and key the pipeline cache on it.

11. graphics: size the buffer and page-table constants explicitly - this one changes behaviour for every title and is the one I would question.
DOWNLOAD_BUFFER_SIZE 32 -> 128 MiB, because this title asks for a single 80 MiB download allocation; and CACHING_ADDRESS_BITS 39 where the table previously covered 40 bits, halving the BDA page table to 256 MiB at the cost of
covering guest addresses only to 512 GiB. Both are tuned against one title. If the 1 TiB window matters elsewhere, take the naming and leave the value at 40.

12-13. Device-memory accounting and tiler scratch — the caches were deciding when to collect from the driver's process-wide estimate, which varied by ~4x between reads of the same moment here; read VMA's own accounting instead.
Tiler scratch was unbounded across a burst of detiles: measured 409 MiB across 40 live buffers while an image allocation was failing 414 MiB short.

14-18. Remaining fixes — image/tiling/video-out, decode and emitter corrections, kernel memory and event-flag paths, runtime linker, and test updates.

Known gaps

  • The menu still does not appear; this gets to the end of the intro only.
  • No test covers the non-fatal mechanism in commit 9.
  • Single platform, two titles.
**@⁠itsmemac** on GitHub · 2026-08-31 18:41 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/427) `itsmemac:spiderman-intro-movie` → `main` · +3514 −277 · 89 files · 18 commits · closed without merging ## What this does Takes Marvel's Spider-Man: Miles Morales from failing on its third frame to playing the full intro movie, on a stock Windows build with no environment variables set. Grouped into 18 commits so they can be cherry-picked independently. Each is described below with why it exists. **Commits 1 and 11 are the ones to look at first** — 1 is an unrelated build fix that stands alone, and 11 is the only one that changes behaviour for every title. ## Testing - Windows, clang-cl, MSVC 14.29 (VS2019) STL, NVIDIA RTX 3060 Laptop (6 GB). - `ctest`: 33/35. `shader_recompiler_compute` and `texture_cache_image_overlap` fail — **they fail identically on unmodified `main`**, verified by building upstream with only commit 1 applied. This PR introduces no test regressions. - Spider-Man: reaches the end of the intro (~145 s, ~350 flips), then stops at `masterSemaphore.cpp:56`. The menu does not come up yet. - Astro's Playroom: stops on unmodified `main` at a shader CFG failure after 3-5 s; with this PR it gets past that and reaches a different, later failure in PM4 register decode (`unknown sh reg at 01169: 0xca`). Still not playable, but not a regression. - Not tested on Linux or macOS, and not tested on any other title. ## The commits **1. `build: fix clang-cl compile of ResourceTracking`** — `main` does not compile with clang-cl today. `Tracker::IndirectImagePlan` is in an anonymous namespace, so `std::projected` cannot be formed and the three `std::ranges` algorithms over it are rejected. CI misses it because it never builds `kyty_emulator`. Independent of everything else here. **2-5. Self-contained shader fixes** — `V_CMP_LT_U64` was missing from the VOPC table; wave64 subgroup broadcast needs workgroup-wide lowering because `OpGroupNonUniformShuffle` at Subgroup scope only reaches 32 lanes (DS_BPERMUTE and DS_SWIZZLE deliberately keep the raw subgroup id, being defined on independent halves); `S_CMP` against an exec mask is the "are any lanes live" idiom and needs a real ballot; buffer loads were clobbering lanes the exec mask had masked off. **6-8. Descriptor and control-flow resolution** — typed phis and `ReadFirstLane` in the SRT walker (the latter only for non-image descriptors, where every lane holds the same handle); loops whose selection merge escapes the body; `S_SWAPPC_B64` indirect calls resolved from the dispatch side, where the user data is already in hand, which is the only place that breaks the circular dependency described in the commit message. **9. `recompiler: allow a shader to be refused instead of aborting`** - the change that actually unblocks the boot. `CompileOptions.non_fatal` / `CompileResult.unsupported`; the three give-up points record and unwind instead of `EXIT`. Nothing changes when `non_fatal` is clear. **10. Tessellation patch control points** draws were hardcoded to 3 control points; take the real count from `VGT_LS_HS_CONFIG.HS_NUM_INPUT_CP` and key the pipeline cache on it. **11. `graphics: size the buffer and page-table constants explicitly`** - **this one changes behaviour for every title and is the one I would question.** `DOWNLOAD_BUFFER_SIZE` 32 -> 128 MiB, because this title asks for a single 80 MiB download allocation; and `CACHING_ADDRESS_BITS` 39 where the table previously covered 40 bits, halving the BDA page table to 256 MiB at the cost of covering guest addresses only to 512 GiB. Both are tuned against one title. If the 1 TiB window matters elsewhere, take the naming and leave the value at 40. **12-13. Device-memory accounting and tiler scratch** — the caches were deciding when to collect from the driver's process-wide estimate, which varied by ~4x between reads of the same moment here; read VMA's own accounting instead. Tiler scratch was unbounded across a burst of detiles: measured 409 MiB across 40 live buffers while an image allocation was failing 414 MiB short. **14-18. Remaining fixes** — image/tiling/video-out, decode and emitter corrections, kernel memory and event-flag paths, runtime linker, and test updates. ## Known gaps - The menu still does not appear; this gets to the end of the intro only. - No test covers the non-fatal mechanism in commit 9. - Single platform, two titles.
Tracker::IndirectImagePlan lives in an anonymous namespace, so std::projected
cannot be formed for it and the three std::ranges algorithms over
m_indirect_images fail to compile under clang-cl with the MSVC STL:

  error: function 'std::projected<..., std::identity>::operator*' is used but
  not defined in this translation unit, and cannot be defined in any other
  translation unit because its type does not have linkage

Using the iterator-pair overloads compiles and is otherwise identical.

Seen with clang-cl and MSVC 14.29 (VS2019) STL. CI does not catch this because
its build targets are launcher and the smaller test binaries; kyty_emulator,
which is what pulls in this file, is never built there.
The 64-bit unsigned less-than compare was missing from the VOPC table, so any
shader using it failed to decode.
OpGroupNonUniformShuffle with Subgroup scope only reaches 32 lanes on this
hardware, but GCN wave64 code expects all 64. A decoupled-lookback prefix scan
broadcasts its ticket across the whole wave, so the subgroup-scoped lowering
silently read the wrong lane. Lower the broadcast across the workgroup instead.

DS_BPERMUTE and DS_SWIZZLE keep the raw subgroup id: they are defined on
independent 32-lane halves and must not be widened.
S_CMP_{EQ,LG}_U64 against a mask operand and zero is the idiom for 'are any
lanes live'. Treating it as a scalar compare loses the per-lane information, so
emit an actual ballot for that shape.
A buffer load wrote its destination unconditionally, clobbering lanes the exec
mask had masked off. Select against the previous value so inactive lanes keep
what they held.
Two descriptor chains this title uses could not be resolved:

- A descriptor whose address arrives through a phi. Walk the phi to its leaves
  and accept the result when they agree, or when exactly one is a real address
  and the rest are null/sentinel.
- A descriptor read through ReadFirstLane. This is safe for non-image
  descriptors, where every lane holds the same handle, so accept it there. Image
  descriptors keep the old restriction, gated by the dword count.
A conditional inside a loop where exactly one arm stays in the loop body has its
real merge at the arm that stays, not at the block the generic search finds.
Without this the CFG is rejected as unstructured and the shader falls back to
the dispatcher.

Also splits selection merges shared between a break and its continuation, which
the same shaders rely on.
The callee of an indirect call is not in the shader binary. It lives elsewhere
in guest memory and is never dispatched, so it is never compiled - the scan
finding zero S_SETPC_B64 across every compiled shader is the same fact seen from
the other side.

The target arrives through a descriptor chain rooted in user data. Resolving
that chain inside the recompiler would need the SRT walk, which needs the shader
to translate, which is what the unhandled S_SWAPPC_B64 prevents. Resolving it
from the dispatch side, where the user data is already in hand, avoids that
circle: find each call site, fetch the callee, and splice it in before
recompiling.

Each table entry is a {function, context} pair; the caller moves the first half
into the call-target registers and the second into the next pair as an argument,
so inlining at the call site needs no argument marshalling.
A shader the recompiler cannot translate is a gap in emulation, not a reason to
take the process down: skipping the draw or dispatch that wanted it costs some
rendering, while aborting costs the title.

CompileOptions gains non_fatal and CompileResult gains unsupported. With
non_fatal set, the three places the recompile path gives up - an opcode with no
IR translation, a CFG that will not build, and resource tracking that cannot
resolve a descriptor - record the failure and unwind rather than calling EXIT,
and Recompile returns a result marked unsupported. The caller skips that draw or
dispatch. Nothing changes when non_fatal is clear.

Marvel's Spider-Man: Miles Morales meets an untranslatable compute shader on its
third frame, so a strict build cannot pass the opening logo. Astro's Playroom is
also stopped by a shader today and reaches a later, different failure with this
in place.
Tessellation draws were created with a hardcoded 3 control points per patch.
Take the count from VGT_LS_HS_CONFIG.HS_NUM_INPUT_CP instead, and key the
pipeline cache on it so patches of different sizes do not share a pipeline.
Names the upload/stream/download/device-local buffer sizes instead of repeating
literals, and makes the BDA page-table address width explicit.

Two of these are behaviour changes and are the ones to look at:

- DOWNLOAD_BUFFER_SIZE is raised from 32 MiB to 128 MiB. Marvel's Spider-Man:
  Miles Morales asks for a single 80 MiB download allocation, which 32 MiB
  cannot serve; the run dies with 'failed to map reusable download buffer,
  size=0x5000000'. This costs every title the larger reservation.
- CACHING_ADDRESS_BITS is 39, where the table previously covered 40 bits. That
  halves the BDA page table from 512 MiB to 256 MiB, at the cost of covering
  guest addresses only to 512 GiB. 38 bits was tried first and was too narrow -
  it produced an intermittent DMA barrier on an address just past 2^38.

The address-width reduction in particular is tuned against one title; if the
1 TiB window is load-bearing for something else, take the naming and leave the
value at 40.
The caches decided when to collect from the driver's process-wide usage
estimate, which varied by about 4x between reads of the same moment on this
setup and is not what the allocator is holding. Read VMA's own accounting
instead, and let the collector stand down on the same figure it stood up on
rather than a stale tally.

Adds a small deferral guard so a completion callback cannot re-enter the
resource caches while the caller still holds their state.
TileManager takes a device buffer per detile and returns it through
DeferDestroy, which cannot run until the GPU retires the tick the free was
queued at. A burst therefore holds every one of those buffers at once, and
nothing bounded the total: measured at 409 MiB across 40 live buffers while an
image allocation was failing 414 MiB short of the budget.

Cap the outstanding scratch and drain the pending-operation queue before taking
more. FlushAndWait alone is not enough - it waits for the GPU but does not pop
the queue, so the frees have not run yet.
- Treat tile mode 0x10 as linear when computing a texture layout; it reaches
  here from this title and has no tiled interpretation.
- Add the video-out format policies this title asks for.
- Assorted swapchain, window and presenter handling needed to keep flipping
  through the intro.
Decode and SPIR-V emitter corrections this title's shaders need: image and
memory operand handling, scalar ALU forms, and the IR plumbing that goes with
them.
- Event flags gain a zero-timeout polling path, which this title uses heavily,
  and map their results to the right errno.
- Memory mapping, address-space and file-system corrections its startup path
  depends on.
- pthread condvar waits dispatch pending signals while waiting.
Runtime linker relocation and fault handling, plus the Ampr and Audio2 paths
this title exercises during startup.
Extends the recompiler, stage-runtime and memory-tracker tests for the decode,
SRT and cache changes, and uses the named buffer-size constants instead of
repeating their literals.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:20:17 +00:00
github-bot closed this pull request 2026-11-26 09:20:17 +00:00
Author
Owner

@⁠Nmzik on GitHub · 2026-09-24 17:01 UTC · original

Closing this in favor of your #780.

**@⁠Nmzik** on GitHub · 2026-09-24 17:01 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/427#issuecomment-5818548391) Closing this in favor of your #780.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.