Skip to content

Upstream sync 6: shared AGC driver fixes onto Metal (slice A, second chunk: sample locations, #186) - #446

Merged
RINNECODER merged 2 commits into
mainfrom
upstream/agc-sync6b
Oct 13, 2026
Merged

RINNECODER merged 2 commits into
mainfrom
upstream/agc-sync6b

Conversation

@RINNECODER

Copy link
Copy Markdown
Owner

Part of #415. Refs #418 (second chunk; some shared MSAA logic still remains, see "Remaining"). Closes #186.

Follows #442. The AGC driver's real upstream base in the fork is a11c8f7f7. This chunk ports the shared-logic MSAA commits from a11c8f7f7..2ccbd376f that the Metal build compiles. They are ported by hand, function by function, onto the fork's MSAA model, because cherry-picks would replace that model. It also does #186, which #418's review asked for in this scope.

Ported

Custom MSAA sample locations: upstream c9e48e5ae, ae6dfd907 / 33efe5ac5 (8x sample 7 at (7, -7)), and the sample-location draw-key range from ebf361103

  • Decoding (Graphics/src/State.cpp). For a multisampled PA_SC_AA_CONFIG, the decoder now reads PA_SC_AA_SAMPLE_LOCS.
    • A pattern that varies over the 2x2 pixel grid is refused, as upstream does.
    • A uniform pattern is kept and flagged custom when it differs from the standard 2x/4x/8x table. The table includes the (7, -7) fix.
    • SampleLocations(state) returns the positions in [0, 1), with upstream's signature.
  • What the fork keeps:
  • Where it differs from upstream:
    • A custom pattern on a pass whose attachments fix another sample count (the EQAA depth case) is refused.
    • A context that never wrote the location registers keeps the standard pattern, as before. Existing fixtures and titles do not start throwing.
  • Metal. ConfigureSamplePositions sets programmable sample positions on the draw's render pass for a custom pattern, and throws if the device has none.
    • Standard patterns keep Metal's defaults. The test checks that these equal the standard tables for 2x, 4x and 8x.
    • Positions are render-pass state on Metal. So upstream's GPL keying (605741d39, fb7615e30) and its Vulkan depth-format check (e28dcc0c1, SAMPLE_LOCATIONS_COMPATIBLE_DEPTH) have no Metal counterpart.
  • MSAA_ENABLE clear on a multisampled draw. Upstream refuses it (ebf361103). The fork accepted it and rasterized at the standard positions, which was wrong. It now rasterizes every sample at the pixel center, which is what clearing MSAA_ENABLE means, through the same programmable positions.
  • Draw key. DrawKeyRegisters now covers 0x2fe..0x30d. The fork's single-sample MSAA_ENABLE path already read those registers without them being keyed.

#186: SET_*_REG_INDIRECT read at submit time on Metal (upstream de651c628 did this for Vulkan)

  • The new helper CaptureIndirectRegisterLists sits in the fork's shared submission code (Execution/src/SubmissionCapture.cpp). It fills Submission::registerLists and names the packet and DWORD in its errors. It is not a copy of the Vulkan function.
  • MetalDriver::Submit and ExecuteRewindTail call it after ValidateSubmission, still under the guest-capture lock and borrowed ranges.
  • The Metal worker applies the captured list with Pm4::ExecuteIndirectRegisters. Because the packet no longer reads guest memory there, its BeforeCpuRead wait is gone.

Not taken

  • Upstream's CB resolve pass and multisampled CMASK model (ebf361103 resolve mode, eeefb0654, d109f3966, 163947ef7). These need Metal-side features the fork does not have:

    • a resolve of a resident texture2d_ms into CB1;
    • CMASK-fill fast clears of resident MSAA targets;
    • throwing on guest access to their memory.

    The decode alone would only change which draws are refused. CB_COLOR_CONTROL mode 3 stays refused on Metal (colorControlSupported). They are listed under "Remaining".

  • Upstream refusing DCC over multisampled targets (ebf361103). The fork ignores DCC/CMASK keys for resident multisampled targets by design.

  • 22d662eda stencil reference export. It needs recompiler changes (StageIO, ShaderInfoCollector, emitter) and a Metal shader bridge [[stencil]] output. Those files are being changed by Metal shader bridge skips draws: "Subgroup builtins are not available" #443's work right now, so it is left for the shader slice.

  • The 16 Vulkan-side commits that conflicted in Upstream sync 6: shared AGC driver fixes onto Metal (slice A, first chunk) #442. I re-trialled them on top of this branch:

    • 7 apply cleanly: ef218ef92 eaf5ca240 ff349a9a5 63ddeb09f dc0c2cf8c d31b13f49 fd98327ba. But most are tests or follow-ups for the 9 that still conflict on missing a11c8f7f7..2ccbd376f prerequisites: 4de5726d3 b9b83cef2 1b4baaee2 b45232dda 29a843579 59db660f7 e785a902b 086f7d509 90d899d98.
    • None of these files build on macOS, so none of the 16 is compile-checked here. Not cheap to do safely, so not taken.

Remaining for #418

  • A CB resolve (mode 3) and CMASK fast-clear model for resident multisampled targets on Metal (upstream ebf361103, eeefb0654, d109f3966).
  • The Vulkan-side commits above, and the other a11c8f7f7..2ccbd376f Vulkan, recompiler and test commits.
  • 22d662eda stencil export (shader slice).

Tests

  • New in anyps5_metal_render_state: CustomSampleLocations. It decodes guest registers and renders through the Metal backend.
    • Standard 2x/4x/8x patterns decode as standard and equal getDefaultSamplePositions.
    • A uniform custom 4x pattern renders with no partly covered pixels: all samples at (-8,-8) cover 20 pixels and all at (7,7) cover 12. The standard pattern gives 8 partial edge pixels.
    • MSAA_ENABLE clear covers exactly the pixels a single-sample draw covers.
    • A pattern varying over the pixel grid, and a custom pattern on a 2-fragment pass under 4x, are refused.
    • Mutation checks:
      • With setSamplePositions removed, it fails ("samples at one custom position still gave partial coverage").
      • With the old (7, -8) table, it fails ("a standard sample pattern decoded as custom").
  • New in anyps5_metal_pm4_compute_replay: IndirectRegistersAtSubmit, run both as a plain submission and as a REWIND tail.
    • It holds the worker at a WAIT_REG_MEM, rewrites the SET_SH_REG_INDIRECT pair list to move the dispatch's output descriptor, then releases the worker. The dispatch writes the submit-time buffer and leaves the other one untouched.
    • With the old worker path, it fails: "SET_SH_REG_INDIRECT used the list rewritten after Submit". Without the tail capture, the rewind case fails too.
    • Passed 3 runs in a row.
  • macOS guest replay config (-DANYPS5_METAL_UTILITIES_ONLY=ON -DANYPS5_METAL_SHADER_BRIDGE=ON -DANYPS5_BUILD_METAL_SHADER_BRIDGE_TESTS=ON -DANYPS5_METAL_GUEST_REPLAY=ON): full build, ctest --output-on-failure --timeout 300 36/36 passed.
  • macOS shader bridge config: full build, ctest 4/4 passed.
  • macOS Rosetta libs (x86_64, -DANYPS5_ROSETTA_LIBS=ON):
    • Targets built: rosetta_libs rosetta_engine rosetta_launcher_tests direct_memory_darwin_tests metal_utility_tests rosetta_direct_graphics_tests rosetta_cpuid_tests rosetta_runtime_tests.
    • ctest -R 'direct_memory_darwin|metal_utility_tests|rosetta_direct_graphics|rosetta_lib_binds|rosetta_runtime|rosetta_launcher|rosetta_cpuid': 9/9 passed.

Game run (one, reference title)

  • Setup: tools/rosetta/run_title.py --wall 280 with this branch's Rosetta build, under with-lock eboot. The data image was a private APFS clone, mounted read-only (detached and deleted afterwards). Relink cache was a private empty one. Frame capture went to a scratch dir, and the captures were deleted afterwards.
  • Boot: guest entry after 0.6 s. 0 unresolved imports, 1 unimplemented call (an Ajm Opus mode, audio).
  • Frames: 9 periodic captures, frame indices 0 to 6272 over 240 s, so about 26 flips/s. The last captures show the early screen with a noisy strip at the top. I did not compare against a main run.
  • Logs: no AGC graphics: refusals, so none of the changed decode paths refused anything. The Subgroup builtins are not available skipped draws (Metal shader bridge skips draws: "Subgroup builtins are not available" #443) are still there; that code is unchanged here.
  • Exit: the same teardown abort as Upstream sync 6: shared AGC driver fixes onto Metal (slice A, first chunk) #442 after the wall-limit SIGTERM (DriverStopped from sceAgcSuspendPoint, exit 134). That code is unchanged.

🤖 Generated with Claude Code

https://claude.ai/code/session_01DgW4n3qYgi5jAAohEmXRQj

RINNECODER and others added 2 commits October 12, 2026 21:06
Hand port of upstream c9e48e5 ("support uniform custom MSAA sample
locations"), ae6dfd9 / 33efe5a (the standard 8x pattern's last
sample is at (7, -7)) and the PA_SC_AA_SAMPLE_LOCS draw-key range from
ebf3611, onto the fork's MSAA model.

- State.cpp decodes PA_SC_AA_SAMPLE_LOCS for a multisampled
  PA_SC_AA_CONFIG: a pattern that varies over the 2x2 pixel grid is
  refused, a uniform one is kept, flagged custom when it is not the
  standard 2x/4x/8x pattern. The fork's rasterSamples / attachment
  sample count model and its EQAA acceptance stay; a custom pattern on
  a pass whose attachments fix another sample count is refused.
- A context that never wrote PA_SC_AA_SAMPLE_LOCS keeps the standard
  pattern (as before), so fixtures and titles that leave them unset do
  not start throwing.
- Upstream refuses multisampling without MSAA_ENABLE (ebf3611); the
  fork accepted it and rasterized at the standard positions. It now
  rasterizes every sample at the pixel center, which is what clearing
  MSAA_ENABLE means, through the same programmable positions.
- SampleLocations() gives the positions in [0, 1); the standard ones
  equal Metal's default sample positions.
- Metal: ConfigureSamplePositions sets programmable sample positions on
  the draw's render pass for a custom pattern (refused when the device
  has none). Positions are pass state on Metal, so upstream's GPL
  pipeline keying (605741d, fb7615e) and Vulkan depth-format check
  (e28dcc0) have no Metal counterpart.
- DrawKeyRegisters covers 0x2fe..0x30d, which the decoder now reads
  (the single-sample MSAA_ENABLE path already read them).

Test: anyps5_metal_render_state CustomSampleLocations.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Upstream de651c6 made the Vulkan driver read the (offset, value) lists
of SET_SH/CONTEXT/UCONFIG_REG_INDIRECT when a command buffer is
submitted. The fork's Metal driver still read them on the queue worker,
so a title that reuses the list memory before the GPU reaches the packet
applied the rewritten registers, or threw on garbage offsets.

- SubmissionCapture gains CaptureIndirectRegisterLists, which fills
  Submission::registerLists from the captured commands (errors name the
  packet and DWORD offset, as upstream's do).
- MetalDriver::Submit and ExecuteRewindTail call it after
  ValidateSubmission, still under the guest-capture lock and borrowed
  ranges.
- The Metal worker applies the captured list with
  Pm4::ExecuteIndirectRegisters; the packet no longer reads guest memory
  there, so it no longer waits for GPU work that writes the list.

Test: anyps5_metal_pm4_compute_replay IndirectRegistersAtSubmit holds
the worker at a WAIT_REG_MEM, rewrites the list to move the dispatch's
output descriptor, then releases it; the dispatch writes the submit-time
buffer. Same for a REWIND tail. Fails on main with "SET_SH_REG_INDIRECT
used the list rewritten after Submit".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@coderabbitai

coderabbitai Bot commented Oct 13, 2026

Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 544b3da9-88b8-4bdd-a849-7835c6516c1c
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@RINNECODER
RINNECODER merged commit a1f6457 into main Oct 13, 2026
6 checks passed
@RINNECODER
RINNECODER deleted the upstream/agc-sync6b branch October 13, 2026 02:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant