Skip to content

Sync fork with upstream, unbreak CI, and add real SelfLoader tests - #26

Merged
manupawickramasinghe merged 22 commits into
mainfrom
sync-upstream
Jul 30, 2026
Merged

Sync fork with upstream, unbreak CI, and add real SelfLoader tests#26
manupawickramasinghe merged 22 commits into
mainfrom
sync-upstream

Conversation

@manupawickramasinghe

Copy link
Copy Markdown
Member

Supersedes #25 (which was sharpemu/sharpemu:main -> here and could not merge: mergeable_state: dirty).

What this does

Merges the 21 upstream commits from sharpemu/sharpemu into this fork and resolves the conflicts, then fixes the reasons CI has been red since 2026-07-26.

Conflicts (2 real; git auto-merged the other 5 overlapping files)

All other fork optimisations survived intact and were verified present: FormatHexBytes + IsEnabled guards (#5), PipelineKey readonly struct (#15), chunked guest strcmp (#2/#13), and the guest-image version retirement rework (#1/#14). Nothing was dropped.

Also restores upstream's workflow.yml, undoing a bot downgrade of actions/checkout from v6 to v4.

Why CI was red

workflow.yml gates build on needs: [init, reuse], and the reuse job hard-errored:

Error: Found both 'REUSE.toml' and '.reuse/dep5'. You cannot keep both files
simultaneously; they are not intercompatible.

So the Windows build and the whole test suite have not actually run on this fork since 26 Jul. Removed the files the bot PR runs committed by accident: .reuse/dep5, a duplicate reuse.yml workflow, patch.diff..patch10.diff, fix_reuse*.diff, root-level Program.cs / run_bench.cs / test_perf3.cs / benchmark_project.csproj, and committed .orig / .rej patch leftovers. (The .rej hunk was checked first — it was already applied, nothing lost.)

SelfLoader tests

tests/SharpEmu.Core.Tests/Loader/SelfLoaderTests.cs was not a test: class SelfLoaderBenchmarks, zero [Fact]/[Theory], a Main(), no .csproj, and absent from SharpEmu.slnx — it had never compiled. Replaced with real xunit coverage of import-stub eligibility and relocation value arithmetic, wired up via a new SharpEmu.Core.Tests project registered in the solution.

Those paths were previously asserted only in RunRelocationSelfChecks, which is [Conditional("DEBUG")] — CI builds Release, so they never ran. Six SelfLoader members were widened private -> internal for test access; no behaviour change.

Testing

N/A for runtime behaviour — no game was run. Local build could not be used as a gate: the dev machine had ~250 MB RAM free with 27.9/29.7 GB swap in use, so dotnet restore was OOM-killed before downloading a package. This PR exists so CI is the verification — please treat the Build Archive job (restore, build, dotnet test, shader-dump validation) on windows-latest as the gate, and do not merge until it is green.

🤖 Generated with Claude Code

MarcelMediaDev and others added 22 commits July 27, 2026 01:58
…harpemu#650)

* fix(kernel): implement APR ResolveFilepathsWithPrefixToIdsAndFileSizes

Resource streamers resolve relative paths against a shared prefix; without
this HLE every call returned NOT_FOUND and assets never got real ids/sizes.

* fix(remoteplay): stub Initialize and GetConnectionStatus as disconnected

Titles probe Remote Play during pad/network bring-up; unresolved imports
returned NOT_FOUND. Report initialized + disconnected so callers take the
normal offline path.

* fix(agc): accept Gen5 hull shaders that omit PGM_LO/HI in CreateShader

Type-5 headers can start with RSRC1/RSRC2; rejecting them left null handles
and Main Thread AVs. Scan the SH table and skip PGM patch when absent.

Co-authored-by: Cursor <cursoragent@cursor.com>

* fix(kernel): reject getdents on file fds and emit . / .. for empty dirs

Returning rax=0 for non-directory or empty listings looked like EOF and
let GTA treat the fd as a pointer (fiWriteAsyncDataWorker AV at 0xB1).

* fix(hle): enable GuestImageWriteTracker CPU sync on Windows

Windows previously hard-disabled the tracker, so CPU-written guest
planes never marked dirty and host textures stayed empty. Arm pages
with VirtualProtect, handle write AVs in VEH, and warm/test on
VirtualAlloc memory so protect cannot poison the CRT heap.

* fix(agc): skip CB metadata draws for EliminateFastClear/Fmask/DCC

CB_COLOR_CONTROL modes 2/5/6 are colour-buffer metadata ops; applying
the bound shader as a normal colour draw corrupts subsequent composites.
Decode MODE from bits [6:4] and return before translate.

* fix(agc): merge Prospero attrib-table formats onto IR vertex inputs

IR-discovered BufferLoadFormat often keeps a stale float sharp format;
patch DataFormat/offset from the AGC attrib table (semantic index),
allow offen fetches, and map quirks 113/121 through NarrowVk for host
vertex input.

* fix(audio): harden AudioOut2 stack out-buffer writes against canary smash

Titles that stack-allocate AudioOut2 outs next to the frame canary were
corrupted by oversized or mistyped HLE writes; keep ContextPush pacing.

* Revert "fix(memory): reserve only large regions (sharpemu#608)"

This reverts commit 8f94562.

* fix(gpu): decode Gen5 R16 and RG32 render-target formats

* fix(audio): AudioOut2 host beds, deeper waveOut queue, AJM MP3

GTA V Enhanced routes intro/menu audio through AudioOut2 and FMOD's AJM
MP3 path. Wire PortCreate/PortSetAttributes/ContextPush to dual host
stereo streams, deepen WinMM queue to 128KiB, and decode AJM codec 0
with a stateful NLayer helper so menu music is not silent.

* fix(agc): map PS interpolants via SPI_PS_INPUT_CNTL semantics

Identity ATTR→param wiring ignored hardware remapping, so UI draws
got wrong (or empty) interpolants. Pack CNTL from matched PS/GS
semantics, thread it into Vulkan/Metal as Location/Flat, and fingerprint
it in the graphics shader cache key.

* fix(agc): rect-list/NGG strips, Index8 expand, and GE_INDX_OFFSET

NGG single-rect UI needs triangle-strip expansion; Prospero Index8 must
expand to host u16; glyphs need base vertex from GE_INDX_OFFSET. Skip
param-less rect-lists instead of inventing colour draws.

* fix(np): report GTA Story Mode addcont entitlements as owned

NpEntitlementAccess was returning an empty add-on list, so GTA V Enhanced offered Buy Story Mode. Publish the installed license labels and stub premium-event registration so offline sessions take the owned path.

* fix(cpu): prefer native workers for all guest entry stubs

Route thread entry, continuation, and main entry through RunGuestEntryStub so guest stubs are not invoked above CLR-managed frames (UnmanagedCallersOnly FailFast). Keep requireNativeWorker for tbb_thead; other paths prefer workers with calli fallback.

* fix(agc): implement Rewind/Jump writers and IT_REWIND waits

GTA Subrender AVs came from AcbJumpGetSize / DcbRewind returning NOT_FOUND as packet sizes. Add IT_REWIND and INDIRECT_BUFFER writers, patch SetRewindState into the GPU wait registry, and nest-parse 4-dword jumps.

* fix(gpu): use AddrLib ExactXor for Gen5 Standard256B (mode 1)

Mode 5 already had Standard4K ExactXor; mode 1 still used the generic StandardSwizzle block table, which mis-detiles Gen5 UI atlases.

* Revert "fix(cpu): prefer native workers for all guest entry stubs"

This reverts commit 31c4db0.

* fix(memory): commit-first large maps; reserve only on failure

Replace the sharpemu#608 always-reserve-only exact-map path with allocate-first and lazy reserve fallback when a huge non-exec commit cannot be satisfied. Prime and widen GetPointer commit so the fallback path is safer for native walkers. Drops the need for a hard sharpemu#608 revert.

* [Agc] Implement fused shader half exports

* fix(agc): accept optional hull state in CreatePrimState

Port the CreatePrimState hull-optional path from sharpemu#583 so fused HS pipelines (GTA) are not rejected with INVALID_ARGUMENT. Geometry-derived CX/UC writes are unchanged; hull is traced only.

* fix(videoout): restore thread-safe VulkanHostBufferPool (sharpemu#564)

The 6db095e wipe dropped CasualcoderDev's lock-ordering-safe pool. Concurrent Return/TryTake without the gate races after the first present and can hang the submit path.

* Revert "fix(agc): implement Rewind/Jump writers and IT_REWIND waits"

This reverts commit bec77bf.

* test(memory): align lazy-commit expectations with commit-first policy

Fake hosts must reject Allocate so reserve-only paths still run, and GetPointer asserts the 32 MiB prime range including AlignUp spill.

* diag(gpu): log guest-queue backlog breakdown under backpressure

Rate-limit top work types and ordered debugName prefixes when the Vulkan guest work queue stalls, so North Yankton logs show acquire/label vs draw traffic instead of only VulkanOrderedGuestAction.

* perf(agc): coalesce acquire flushes and batch non-DMA label wakes

Flush pending ACQUIRE_MEM invalidation at draw/dispatch/dma/flip boundaries instead of before every packet, and complete release/write-data producers in the same ordered action so load paths enqueue far fewer VulkanOrderedGuestAction items.

* perf(gpu): wait for ordered-action fences and keep draining sync

On Windows/Linux, block briefly for queue-visibility fences instead of deferring the whole logical queue for the tick. Prefer ordered sync/flip heads under backlog pressure, and keep macOS non-blocking defer behavior.

* perf(gpu): raise sync-item ceiling above payload guest-work cap

Apply SHARPEMU_PENDING_GUEST_WORK_ITEMS mainly to compute/draw/image payload work, and allow a higher SHARPEMU_PENDING_GUEST_SYNC_ITEMS ceiling for zero-payload ordered actions and flip markers. Keep the byte budget as the RAM safety valve.

* fix(gta): stub Voice ports and implement sceKernelCheckReachability

Resolve North Yankton-path Voice Create/Delete/Connect/Disconnect/End NIDs and EnumerationThread reachability checks so leftover unresolved imports are not on the critical path.

* diag(gta): arm flip/present/wait probes after North Audio

Rate-limited load_progress TRACE for flip submit, ordered flip enqueue, present taken/not-taken, and GPU wait backlog so North Yankton freezes can be classified without full AGC tracing.

* fix(ampr): restore sequential offset=-1 reads for streamer packs

Re-wire PakDirectoryTracker into sceAmprAprCommandBufferReadFile (dropped in sharpemu#216) so RAGE sequential pack reads no longer fail while the North Yankton UI keeps flipping. Also rate-limit CheckReachability miss paths for EnumerationThread diagnosis.

* fix(hle/videoout): Windows GuestImage opt-in and keep GTA intro without sync

Default the tracker off on Windows to avoid VirtualProtect thrash, gate AGC
texel-copy skips on Enabled so guest Bink planes keep shipping pixels, and
drain CPU-written images on the present thread when sync is opted in.

* fix(videoout): probe guest content when tracker off so UI can skip copies

Restores upload-known/texture-cache skips for Dead Cells menus, and uses a
sparse guest-memory fingerprint when GuestImageWriteTracker is disabled so
CPU-updated Bink planes still force texel copies for GTA intro.

* fix(audio): keep 128KiB host queue AudioOut2-only

Restore the default 32 KiB (~171 ms) PCM bed for classic AudioOut so
titles like Dreaming Sarah stay in sync; only AudioOut2 opens the deeper
queue needed for bursty FMOD Push on GTA.

---------

Co-authored-by: samto6 <123419830+samto6@users.noreply.github.com>
…mu#666)

* [GUI] bump to avalonia 12

* [GUI] add compiled bindings for cards/console logs/game metas

* [GUI] enable compiled bindings across launcher XAML
* [audio] added sdl audio backend and in-tree atrac9 decoder

* [input] replaced per-platform pad readers with sdl gamepad input

* [video] added sdl window and host display plumbing

* [gui] added host display options and per-game render settings

* [bink] synced host movie playback to the guest audio clock

* [cpu] hooked windows write faults into guest image tracking

* [perf] added guest and render profiling, reserved host cpu lanes

* [kernel] fixed stale pthread mutex handle alias

* [host] wired the sdl session, save-data paths and project references

* [audio] hoisted ajm trace stackalloc out of its loop

* [video] Add guest image sync setting

* [build] Strip native symbols

* reuse
* [audio] fixed demons souls audioout2 output path

* [video] restored texture cache bound and gated present diagnostics

* [cpu] made guest image cpu sync opt-in
* [agc] Add indirect draws

* [video] Match render target views

* [savedata] Allow dialog reinit

* [ime] Add default profile

* [GUI] update missing translations for profile box
* [GUI] Add horizontal game tiles

* [GUI] Update launching elements layout

* [GUI] Change cards format to squares
* fix vulkan error from astrobot

* a bit of a clean

* a bit of a clean
Syncs the fork with 21 upstream commits (PR #25), covering the SDL host
window backend, AGC shader translation fixes, AudioOut2 host beds, kernel
memory/getdents fixes and the Avalonia 12 / SDL3 dependency bump.

Conflict resolution (upstream wins on semantics, fork perf tweaks reapplied):

- VulkanHostSurface.cs: deleted upstream by "Sdl backend (sharpemu#670)", which
  replaces it with SdlHostWindow.cs. The fork only had expression-body ->
  block-body edits here (PRs #9/#11), so the deletion is taken as-is.
- VulkanVideoPresenter.cs: took upstream's new baseVertex argument and kept
  the fork's allocation fix that drops the defensive targets.ToArray() copy,
  matching the five sibling call sites that merged cleanly.

Restores upstream's workflow.yml, undoing a bot downgrade of
actions/checkout from v6 to v4.

Removes files committed by accident during the bot PR runs, which had been
failing CI since 2026-07-26: .reuse/dep5 (REUSE lint hard-errors when both
it and REUSE.toml exist, and the reuse job gates the build job, so the
Windows build and tests had not run since), a duplicate reuse.yml workflow,
patch*.diff / fix_reuse*.diff, root-level benchmark scaffolding, and
committed .orig/.rej patch leftovers.

Replaces tests/SharpEmu.Core.Tests/Loader/SelfLoaderTests.cs, which was a
benchmark script with no test attributes, no csproj and no solution entry,
with real xunit coverage of SelfLoader's import-stub eligibility rules and
relocation value arithmetic. These paths were previously asserted only in
RunRelocationSelfChecks, which is [Conditional("DEBUG")] and so never ran
in CI's Release build. Widens six SelfLoader members from private to
internal for test access; no behaviour change.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings July 30, 2026 16:02

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot wasn't able to review this pull request because it exceeds the maximum number of lines (20,000). Try reducing the number of changed lines and requesting a review from Copilot again.

@github-actions

Copy link
Copy Markdown

📦 Build artifacts — 1b886f4

Platform Download
Windows (win-x64) sharpemu-win-x64-b27984e
Linux (linux-x64) sharpemu-linux-x64-b27984e
macOS (osx-x64) sharpemu-osx-x64-b27984e

From build run #51. Downloads require a GitHub login and expire after 90 days.

@manupawickramasinghe
manupawickramasinghe merged commit d9f8d46 into main Jul 30, 2026
12 checks passed
@manupawickramasinghe
manupawickramasinghe deleted the sync-upstream branch July 30, 2026 16:06
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.

6 participants