Skip to content

[Split] A failed guest read names its reader; a read through a null resource base is counted, not warned - #76

Open
xnetcat wants to merge 2 commits into
mainfrom
fix/split-null-base-reads
Open

xnetcat wants to merge 2 commits into
mainfrom
fix/split-null-base-reads

Conversation

@xnetcat

@xnetcat xnetcat commented Dec 3, 2026 •

Copy link
Copy Markdown
Collaborator

Before submitting

Please read our contribution guidelines before opening a pull request:

➡️ CONTRIBUTING.md

By opening this pull request, you confirm that you have read and agree to follow the contribution guidelines.

What this changes

A tester's Astro Bot log (split mode) has 16 warnings like "GPU read of guest 0x0+0x100 failed" followed by "0x18+0x4 failed", with the second address going 0x18, 0x30, 0x34, 0x58, 0x5C again and again. Nobody could tell which reader asked.

What reads them: the shader resource materializer evaluates every scalar read up front, including reads the shader skips at run time when a pointer is null. A read through a null base reads as zero by design (RuntimeValueEvaluator.ReadRawWord; upstream and the in-process path do the same). The read proof records those addresses as unreadable, and at every revalidation (once per draw) it reads them again to check they still find no memory (ResourceMaterializer.Holds). On the GPU process side the read goes through the Metal concurrent resolver's word read (MetalRenderHost.TryReadGuestWordConcurrentTested). That code first tries to fill the 256-byte line around the word, which fails, then reads the word itself, which fails too. So we get two warnings per word, five words of one null table pointer, for every draw. The values are the same as before (zero), so nothing is used wrongly. Only the warnings are wrong.

Changes:

  • New thread-static GuestReadContext (SharpEmu.HLE) with the reader kind, the shader hash and stage, and the work: queue, submit and packet on the command-stream thread, or the prefetch job on a resolver thread. Each is set by the code that knows it: ShaderProgramCache's readers, MaterializingShader, the proof recheck, GpuCommandInterpreter per packet, and ParallelProgramPrefetch per job. Nothing is formatted unless a read fails.
  • RemoteGuestAddressSpace reports one event per request. A word-line fill that misses is not reported by itself; it is folded into the report of the word read that follows. Every report names its reader. The first report has a managed stack. After the cap of 16, misses are counted and summarised at 64 misses and then each time the count grows fourfold (misses, reported, suppressed, null_base, line_fills).
  • Reads through a null base are marked (RuntimeValueEvaluator.ReadThroughBase at all five raw-read sites). Proof unreadables keep the mark in bit 63, so the recheck marks them too. In the split address space such a miss is counted and named once at INFO, not warned. A miss through a real base still warns. The read itself is still made (a null base plus an offset the shader computes can still name memory), so emulation behaviour does not change.

A tester's log will now show, once:
[GPU-SPLIT][INFO] GPU read of guest 0x0000000000000018+0x4 through a null resource base found no memory (its word line 0x0000000000000000+0x100 failed first); it reads as zero by design, later ones are counted (null_base=): reader=read-proof-unreadable shader=0x... stage=Pixel queue=0 submit=... packet=0x...

Cost on the hot paths: none per packet or per word read. The command-stream walker registers itself once per slice and is asked for its packet only when a read fails; a read made while a shader's resources are materialized is named resource-read without a scope of its own. A word-line fill and a null-base read each set one thread-static flag.

Testing

No game was run (none is available on this machine). Unit tests: RemoteGuestAddressSpaceTests (the report names its reader and the work it serves; a line fill and its word read are one report, the cap of 16 counts reports, the summary line; a null-base miss is counted and named once, not warned) and ReadProofTests (null-base reads are marked at the evaluation and at the proof recheck, which names its reader and shader). The ReadProofTests fail with the recheck change reverted. Release build with 0 errors, REUSE lint clean, full dotnet test SharpEmu.slnx -c Release: every project passed. The first run caught two allocation-test failures, ShaderPipelineCacheAllocationTests.ACachedDrawAllocatesOnlyItsResults (an Enum.ToString per cached draw); fixed with cached stage names, and the Libs (12638 passed), ShaderCompiler (3041) and GpuSplit (58) suites passed on rerun, and again after the hot-path follow-up commit. The Metal and other projects passed in the first full run and were not rerun after that commit, which does not touch them.

Checklist

By submitting this pull request, you confirm that:

  • I have read and followed CONTRIBUTING.md.
  • I tested my changes or marked the testing section as N/A.
  • I wrote this pull request description myself and did not paste AI-generated explanations.
  • I listed the game(s) I tested (or marked the testing section as N/A).

…ot a failed read

The resource materializer reads every scalar load up front, including loads through a null table pointer, which
read as zero by design. The read proof re-reads those addresses at every revalidation (once per draw). In the
split GPU process each of these reads is a line fill plus a word read in the Metal concurrent resolver, so it
showed up as a pair of "GPU read of guest 0x0+0x100 / 0x18+0x4 failed" warnings that named nobody.

- GuestReadContext (HLE, thread-static): reader kind, shader hash/stage, queue/submit/packet or prefetch job.
- RemoteGuestAddressSpace: one report per request (a line-fill miss folds into its word's report), the
  reader named, a stack on the first report, counted summaries after the cap of 16.
- Null-base reads marked at all raw-read sites and at the proof recheck (bit 63 in proof unreadables);
  in split mode they are counted and named once at INFO, not warned. Read behaviour is unchanged.
…er name per word read

The failed-read report's context cost three thread-static writes per command packet and a
scope per resource word read. The walker now registers itself once per slice and is asked
for its packet by the report; a read made while a shader's resources are materialized is
named resource-read without a scope of its own.
@github-actions

github-actions Bot commented Dec 3, 2026

Copy link
Copy Markdown

📦 Build artifacts — c67f6cb

Platform Download
macOS (osx-x64) sharpemu-osx-x64-e824ac9
macOS app bundle (osx-x64) sharpemu-osx-x64-app-e824ac9

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

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.

1 participant