Skip to content

Port libSceAgcDriver imports and remaining libSceAgc rows to the Metal bridge - #373

Merged
RINNECODER merged 2 commits into
mainfrom
port/agc-driver
Oct 11, 2026
Merged

RINNECODER merged 2 commits into
mainfrom
port/agc-driver

Conversation

@RINNECODER

Copy link
Copy Markdown
Owner

Summary

Ports the 35 libSceAgcDriver imports and 17 of the 39 remaining libSceAgc imports the test title needs (52 rows). Every row resolves through SceAgcImports under the target admissions; no guest pointer is dereferenced on the host.

  • libSceAgcDriver leaf exports (35): resource registration, owners, workload streams, capture, submit validation, shader debugging status and the equeue event queries. They are bound through prx bridge descriptors (core/cpu/src/upstream-prx/AgcDriver.cpp, Marshal.hpp slot kinds) that compile the upstream bodies: integer outputs are copied in and written back, KernelEvent is copied from the guest, and pointers upstream discards are never read. RegisterResource/RegisterGdsResource take a seventh (stack) argument, so they get a hand thunk built from the same slots. SceAgcImports owns the graphics scope, so it looks these rows up in the descriptor table (new UpstreamDriver contract) instead of the generic bridge. None of these rows touches upstream's Vulkan driver. Submission, queues, labels and flips stay on the Metal path.
  • ACB flip / wait until safe for rendering (2): upstream still stubs both, so they are native. They emit the Metal driver's flip and rendering-wait packets (AgcDriver::FlipPacketHeader / RenderingWaitPacketHeader) into the compute command buffer, the same encoding as the DCB rows. The Metal submission path reserves flips and checks the video-output registry for any queue.
  • libSceAgc builders, patchers and queries (11): DCB/ACB marker spans (exactly length bytes are copied from the guest, without reading past them), occlusion query sizes, shader instrumentation, AcquireMemSetEngine, and BranchPatchSet{Then,Else}Target_0300.
  • Shader marshalling (4 of the 7 that Port remaining libSceAgc command builders, patchers and size queries #362 skipped):
    • GetRegisterDefaults2 and GetRegisterDefaults2Internal still call upstream to validate the version. Upstream returns host pointers, so the guest instead gets one stable copy of the same upstream tables per (version, internal) pair. That copy lives in a mapped window 4 MiB above the AGC gate table (core/cpu/agc/AgcRegisterDefaults.cpp, built from upstream RegisterDefaultsData.hpp).
    • CreatePrimState and UpdatePrimState run upstream on host copies of the stage type and special registers. Every other Shader pointer is cleared, which is safe because the stage ABI resolver does nothing on Metal. The register pairs are written back only on success.

Upstream sources

Skipped (22)

  • NOT-UPSTREAM (4): dbOlWdppb4o, vieBRwlh1Lw, LtTouSCZjHM, zARR5aCmkoY.
  • Not implemented upstream and no open upstream PR (15): GetDefaultCxStateFlat, SetAmmSemaphoreMemory, DebugRaiseException, GetGsPrimPayload, CbMemsetExclusive, DcbSetIndexIndirectArgs (and GetSize), GetSemaphoreLabel, Dcb/Acb SetWorkloadsActive/SetWorkloadComplete/SetWorkloadStreamInactive (6), AcbAtomicGds_0900. The packet encodings are unknown, so these were not invented.
  • Shader marshalling not tractable here (3):
    • GetFusedShaderSize_0080 and FuseShaderHalves_0200 need a deep copy of both halves (code, registers, semantics, user-data sharp tables). The fused result holds pointers into the scratch memory, its layout is aligned from the scratch address, and the front code's GPU address is encoded into registers, so every pointer would need relocating back to guest addresses.
    • GetGsOversubscription takes a float in xmm0, and Machine exposes no vector registers.

Evidence

  • New CTest anyps5_cpu_agc_driver_leaf was written first and failed with Unsupported SCE AGC service: 5CdQTZIQPxM. It now passes, including under MTL_DEBUG_LAYER=1 MTL_SHADER_VALIDATION=1 ANYPS5_NO_SHADER_CACHE=1 APS5_NO_SHADER_CACHE=1. It checks that:
    • all 52 rows resolve under TargetAgcAdmissions() and are rejected in the other library scope;
    • driver statuses match upstream, including sign-extended SCE codes;
    • integer outputs are written back, and failed calls leave guest outputs untouched;
    • the seventh argument is read from the stack;
    • equeue queries work on a guest KernelEvent;
    • marker spans are byte-exact with upstream, with the text placed at the end of a mapping;
    • ACB flip and wait produce the Metal packets;
    • occlusion sizes and instrumentation match upstream, and three patchers match upstream patching a host copy;
    • all 28 register-defaults tables match upstream entry by entry through guest pointers and are stable across calls;
    • Create/UpdatePrimState registers match upstream on a synthetic GS.
  • The test was added to NATIVE_REQUIRED_TESTS after anyps5_cpu_agc_target_events, and python3 -m unittest tools.tests.test_native_diagnostic_workflow passes (8 tests).
  • native-runner ctest: 146/146 passed
  • cpu-tcg ctest: 40/40 passed

Smoke (test title, native runner, --max-wall-ms 300000)

unresolved_import missing_module first blocker
origin/main 187 (libSceAgc 39, libSceAgcDriver 35) 10 sceKernelLoadStartModule (libkernel)
this branch 135 (libSceAgc 22, libSceAgcDriver 0) 10 sceKernelLoadStartModule (libkernel), unchanged

🤖 Generated with Claude Code

RINNECODER and others added 2 commits October 11, 2026 04:38
Ports upstream boykopovar/AnyPS5 open PRs into core/libs/prx (libs and
their tests only; docs excluded):
- boykopovar#2847 DCB/ACB marker span builders
- boykopovar#2848 occlusion query size queries
- boykopovar#2849 submit validation reported as unavailable
- boykopovar#2850 disabled shader instrumentation accepted
- boykopovar#2851 GPU capture reported as unavailable, shader debugging status
- boykopovar#1060 sceAgcAcquireMemSetEngine

Conflicts between the PRs (Unimplemented.cpp stubs and shared test
files) were resolved by keeping every change from both sides.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… Metal bridge

Binds the 35 libSceAgcDriver imports and 17 libSceAgc imports through
SceAgcImports without dereferencing guest pointers on the host:

- Driver leaf exports (resource registration, capture, submit
  validation, equeue queries) run the upstream bodies through prx bridge
  descriptors (upstream-prx/AgcDriver.cpp); the 7-argument registrations
  read user data from the caller stack.
- ACB flip and rendering wait emit the Metal driver packets, as the DCB
  rows do.
- Marker spans, occlusion sizes, shader instrumentation, AcquireMemSetEngine
  and branch _0300 patchers reuse upstream encoders on host copies.
- GetRegisterDefaults2(+Internal) publish the upstream tables in a guest
  window above the gate table; Create/UpdatePrimState run on host copies
  of the stage type and special registers.

New CTest anyps5_cpu_agc_driver_leaf is in NATIVE_REQUIRED_TESTS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Oct 11, 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: f8e28226-3d95-4d7f-9f66-141f750aab76

  • 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.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-11T09:55:24.933746Z 5b5c519 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5b5c519447

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

auto cx = registers<2>(guest, cxAt, false);
auto uc = registers<3>(guest, ucAt, false);
HostStage hs, gs;
const auto* hsShader = hs.Load(guest, arg(guest, 2));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Skip shader reads when no primitive outputs are requested

When both cxAt and ucAt are null, upstream sceAgcCreatePrimState returns success before inspecting either shader, but this unconditional hs.Load still reads and validates the guest HS pointer. Consequently, a no-output call with an arbitrary non-null shader pointer faults in the bridge instead of preserving upstream's successful no-op behavior; return early before loading either shader when both output pointers are null.

Useful? React with 👍 / 👎.

@RINNECODER
RINNECODER merged commit f25668e into main Oct 11, 2026
6 checks passed
@RINNECODER
RINNECODER deleted the port/agc-driver branch October 11, 2026 09:55
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