Skip to content

feat(agc): run DB depth copies into a single-sample R32 float target - #5499

Closed
codingreapermaps wants to merge 1 commit into
boykopovar:mainfrom
codingreapermaps:feat/agc-db-depth-copy
Closed

codingreapermaps wants to merge 1 commit into
boykopovar:mainfrom
codingreapermaps:feat/agc-db-depth-copy

Conversation

@codingreapermaps

Copy link
Copy Markdown
Contributor

What

A draw with DB_RENDER_CONTROL.DEPTH_COPY threw DB_RENDER_CONTROL depth copy, resummarize or decompress is unsupported. PPSA12361 (Transport Fever 2: Console Edition) issues one in every frame of a map: DB_RENDER_CONTROL = 0x84 (DEPTH_COPY with COPY_CENTROID), a two-sample Z_32_FLOAT depth surface (2688x1512) and a single-sample R32 float color target of the same size that its ambient occlusion pass samples next.

  • DecodeDepthCopyPass recognises the draw before shader compilation: depth copy only (no stencil copy, clear, resummarize or decompress), no depth or stencil tests, a Z_32_FLOAT depth plane, color writes to the red channel of color target 0 alone, a single-sample R32 float target of the depth surface's extent, the full PA_SC_AA_MASK and a viewport and scissor covering the whole surface. Anything else throws, and draws without DEPTH_COPY are unchanged.
  • The copy runs as a compute pass (DepthSample.comp) that fetches one sample of the host depth image and stores it into the target's resident storage image, which is then marked dirty like any other GPU write.
  • With COPY_CENTROID the copied sample is the first one the draw covers. radeonsi programs its DB to CB copies with COPY_CENTROID and a one-sample mask per sample (loop in si_blit_dbcb_copy); under the full sample mask required here that is sample 0. Without COPY_CENTROID, COPY_SAMPLE selects it. The console is not measured; this is recorded in docs/dev/debt/libSceAgcDriver.md.
  • Multisampled depth surfaces are created with SAMPLED usage when the device can sample their format at their sample count; single-sample surfaces keep it unconditionally as before.
  • The viewport and scissor check of the CB metadata pass moves into a shared drawCovers and is reused here.

Overlap with #1395. That draft also recognises depth copy draws (DecodeDepthCopyPass) together with depth clears, and is blocked on proving that a draw selected from register state really covers the whole surface. This PR has the same limitation: the copy is chosen from the viewport and scissor, not from the draw's geometry. It is narrower (depth copies into an R32 float target only) and adds a title that needs it (PPSA12361) and an execution test of the copy on the GPU. If the maintainers prefer to land the copy through #1395, this can be closed in its favour and the title data moved there.

Tested

Windows 11, MinGW-w64 GCC 15.2.0, NVIDIA GeForce MX450 (driver 581.83).

  • agc_driver_graphics_tests: new depthCopyPassTests decode the PPSA12361 register state and refuse a stencil copy, a missing sample, a partial sample mask, depth tests, a non-Z_32_FLOAT plane, writes beyond the red channel, a non-R32 float target and a viewport over part of the surface. All graphics tests pass.
  • agc_driver_depth_storage_tests: new DepthCopyCase copies samples 0 and 1 of a cleared two-sample depth surface into a RenderTarget-tiled R32 float target and reads the cleared depth back from every texel of guest memory; a copy without a depth surface, of a third sample and of another extent are refused. The suite passes. On this machine the first Vulkan device is an Intel Iris Xe without shaderInt64, so it ran with VK_LOADER_DRIVERS_SELECT=*nv*.
  • PPSA12361: without the change it stops at the first frame of a map with the error above; with it, and the other local changes the title still needs, the map renders. A RenderDoc capture shows the R32 float target holding the resolved depth that the ambient occlusion pass reads.
  • Built and tested on main at 0aa4cb1c2.

Checklist

  • Based on current main; no other open PR implements the same functions (overlaps the draft feat(agc): add experimental depth clear and copy recognition #1395, see above)
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA12361 (no Game bring-up discussion yet)
  • GPUs tested: NVIDIA GeForce MX450, driver 581.83, Windows 11
  • AI-assisted: yes

A draw with DB_RENDER_CONTROL.DEPTH_COPY copies one sample of the
Z_32_FLOAT depth surface into color target 0. It now runs as a compute
pass that fetches that sample and stores it into the R32 float target,
when the draw covers the whole surface without depth or stencil tests.
With COPY_CENTROID the sample is the first one the draw covers, which is
sample 0 under the full sample mask the driver requires, as radeonsi
programs its per-sample DB to CB copies.

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

Copy link
Copy Markdown
Collaborator

The copy is picked from the viewport and scissor, not from what the draw covers, which is the same open problem as #1395. Could the copy run as the draw itself (a pixel shader reading the depth sample, rasterized from the title's geometry) so coverage comes from the draw and nothing needs guessing?
Also, SAMPLED usage on every multisampled depth surface changes surfaces that work on main today; please say which titles you ran with that part.

@github-actions github-actions Bot added the needs rebase Conflicts with main, rebase needed label Oct 14, 2026
@codingreapermaps

Copy link
Copy Markdown
Contributor Author

Only PPSA12361 ran with the SAMPLED part; no other title was run with it. I'll take that out of the general path.

Running the copy as the draw itself makes sense, and it's the only way I see to close the coverage gap #1395 is also stuck on. Before rewriting I'd like to check the design with you, since it reaches beyond this PR:

  1. When a draw has DEPTH_COPY, the driver runs it through the normal draw path on a copy of the register state: the title's vertex stage and geometry, DB_RENDER_CONTROL cleared, no depth target bound, and a driver-owned pixel program in place of the title's (like NullPixelCode). That program reads the depth sample with image_load on a 2D MSAA T# that describes the depth plane, at the pixel position, and exports it to MRT0. Coverage, culling, clipping, viewport and scissor then come from rasterising the title's draw. The sample is the one chosen today (COPY_CENTROID → first covered sample under the full mask, otherwise COPY_SAMPLE; the console is still unmeasured, debt entry kept).
  2. For that read to work, a multisampled depth surface has to be sampleable through the normal texture path. Today GuestTextureResource rejects MSAA descriptors and DepthSurface::Sampled requires one sample. Instead of adding SAMPLED to every multisampled depth image, the sampled view would come from a lazily created shadow image with the same sample count, refreshed with vkCmdCopyImage from the depth image (it already has TRANSFER_SRC) when the surface was written since the last copy. Surfaces that work on main keep their usage.

Two questions:

  • Is a driver-owned guest pixel program acceptable here, or would you rather have a host-written fragment module with its own descriptor (no MSAA guest descriptor support needed, but a new host-image binding role in ShaderResources)?
  • Should MSAA depth sampling (point 2) be its own PR first, with this one depending on it?

I'll convert this PR to draft until the design is settled.

@MarcZX10

Copy link
Copy Markdown
Contributor

A second concrete workload is now reported in issue #6304: DB_RENDER_CONTROL=0x84, a single-sample D32 source, and a same-size R32_FLOAT destination on PPSA34501. Your current PR description and execution case focus on the two-sample PPSA12361 path. This could be useful as an additional regression shape for the single-sample branch, if the current decoder and pass support it; I have not verified that path locally.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Both parts make sense. Yes, please put MSAA depth sampling through the shadow image in its own PR first, with a test that sampling returns the depth values at each sample count, and this one depending on it. A driver-owned guest pixel program is fine with me: it keeps everything on the normal draw path; just mark it in the debt file as driver-authored code. For the single-sample case from #6304, either a sampler2D path with its own test, or an explicit rejection, as MarcZX100 asked.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Checking in, since #6304 now has a second region (PPSA34502) reproducing the same 0x84 abort on Linux. Where this stands against current main:

  • It no longer merges cleanly: DepthSurface.cpp, TextureDetiler.cpp/.hpp and the debt doc conflict. Main's MSAA depth sampleable handling now covers what the SAMPLED usage hunk did, so that hunk can go.
  • feat(libSceVoice): implement sceVoiceGetPortAttr #5956 isn't a dependency. It is a libSceVoice export that is already on main; the earlier tester's tree just predated it.
  • Still open: a 1-sample source binds a single-sample view to sampler2DMS, which is invalid in Vulkan and only happens to work on NVIDIA. That is PPSA34501's case.
  • Also still open is the plan from 16 Oct: do the copy as a draw with a driver pixel program, with MSAA shadow sampling as a separate PR first.

The Z32 to R32 copy and the sample pick look right. When you have a rebased head with the 1-sample case fixed, we'll review and run full CI.

@MarcZX10

Copy link
Copy Markdown
Contributor

I opened #7318 as the separate multisample depth shadow-image prerequisite requested here. It copies the native depth samples into a same-format, same-sample-count sampled image and leaves sampled usage off the attachment. The focused target builds on Linux; its runtime stops at this host's CPU-feature guard before device selection, so I have no GPU result for this change. If the implementation matches the planned path, #5499 can rebase on it and list it as a dependency after review/merge.

@MarcZX10

Copy link
Copy Markdown
Contributor

The drawnDepth propagation and native-attachment usage review findings are now fixed on #7318 at head 132dbd1f0. Its isolated DepthSurfaceReuse fixture passes; I could not run GPU validation here, and the GitHub platform build/test jobs are skipped. If this path is still needed, please rebase/integrate #7318 after its review, then rerun the reported GPU regression. The separate single-sample sampler2DMS mismatch and the agreed draw-based copy design still need to be addressed in this PR.

@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Oct 18, 2026
@frankea

frankea commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Datapoint from a third title on the DB_RENDER_CONTROL = 0x84 stop: Horizon Call of the Mountain (PPSA05666, v01.004.011, PS VR2-only). On a local tree that gets the title through its PS VR2 set-up (main 324e0e4 + #7658 + #7690 and environment-gated stubs, see D6214 and #7649), it aborts at its first draw on DB_RENDER_CONTROL depth copy, resummarize or decompress is unsupported (register 0x0 = 0x00000084), 3 of 3. With this PR (head c483040, hand-merged) the depth copy runs every frame, and the title stops on the next DB pass of the same frame:

[gpu] driver failure: DB_RENDER_CONTROL depth copy, resummarize or decompress is unsupported (register 0x0 = 0x00000088)

0x88 is STENCIL_COPY with COPY_CENTROID, which DecodeDepthCopyPass refuses by design. The register state of that draw: DB_DEPTH_CONTROL 0, DB_Z_INFO 0xa0000183 (Z_32_FLOAT, 1 sample), DB_STENCIL_INFO 0x20000181, surface 2304x1184 in the first frame and 3328x1664 afterwards, colour target 0 VK_FORMAT_R8_UINT of the same extent (1 sample, tile mode 24), CB_TARGET_MASK 0x2 and CB_SHADER_MASK 0x3 with CB_COLOR0_INFO 0x00050c04 (COMP_SWAP ALT), full sample mask, viewport and scissor covering the surface. So the stencil export lands in the green channel and the swap routes it into the target's one 8-bit channel; a rule that only admits the red channel refuses it.

A stencil variant of the pass, written locally to see what comes next: DecodeDepthCopyPass also accepts bit 3 (stencil plane required instead of Z_32_FLOAT, 8-bit single-sample target instead of R32 float, write mask 1 or 2), CopySample takes a stencil flag and creates a VK_IMAGE_ASPECT_STENCIL_BIT view of the same image, and a second compute shader that differs from DepthSample.comp only in usampler2DMS / r8ui uimage2D writes through the target's R8_UINT view. With it the title runs both copies every frame and renders its first VR scene, 3 of 3 full-cap runs, no throw. Not checked: the shaders read with sampler2DMS although this surface has one sample (fine on NVIDIA 616.92, validation layers off), and whether COPY_CENTROID on a one-sample surface means sample 0. The diff is about 100 lines over 9 files; I can post it here or open it as a follow-up once the pass lands, whichever suits the split into #7318 and this PR.

Setup. Windows 11 (26200), RTX 4090 (NVIDIA 616.92), WinLibs GCC 15.2.0 r7 (UCRT), Release libs target; runs on 2026-10-18, 600 s cap, no input.

AI-assisted: yes (Claude Code)

@frankea frankea mentioned this pull request Oct 19, 2026
@MarcZX10

Copy link
Copy Markdown
Contributor

Status update: the proposed multisample-depth shadow prerequisite, #7318, has now merged. On the current #5499 head (c483040e), the earlier review points still apply: the copy is selected from viewport/scissor rather than title geometry, and the decoder accepts a one-sample source for a sampler2DMS shader. The new Horizon Call of the Mountain report’s DB_RENDER_CONTROL=0x88 is a separate stencil-copy case; the local stencil experiment is not yet validated, so it can remain out of this depth-copy scope.

@milescoviello

Copy link
Copy Markdown
Contributor

@codingreapermaps, I rebased this onto current main and fixed the one-sample case, since PPSA34501 and PPSA34502 (#6304) both stop on this refusal. The branch is milescoviello/AnyPS5 rebase/5499-db-depth-copy (815c622, on main d0852de). It holds your commit (22b93dc, your authorship) and one of mine on top.

Rebase. It conflicted in CMakeLists.txt, TextureDetiler.hpp/.cpp, DepthSurface.cpp and the debt file.

  • When the surface uses feat(agc): sample multisampled depth through a shadow image #7318's sample shadow, CopySample reads through it, as the texture path does: it creates the shadow, refreshes it, and the recorder keeps it. The SAMPLED usage hunk is gone, as @oneandonlydean said.
  • The copy's descriptor sets come from a DescriptorRing through allocateFrom, as main's other detiler passes do now, instead of a pool of their own.

815c622: the one-sample case (@oneandonlydean's and @MarcZX10's point):

  • DepthSample.comp is built twice, once with sampler2DMS and once with sampler2D (-DMULTISAMPLED, as MultisampleSampledReadback.comp is built). The copy picks the variant by the surface's sample count.
  • The copy no longer requires samplingActive. I added that check in my first rebase, copied from the texture path. It concerns importing guest memory into a native multisample image, but the copy reads the host image that the draws rendered. With the check in place, the existing two-sample case failed (native multisample depth sampling requires its creation-time owner).
  • Both barriers now name VK_PIPELINE_STAGE_HOST_BIT next to ALL_COMMANDS, as the CMASK clear's do, because their access masks include host bits.
  • Tests: depthCopyPassTests now decodes a one-sample plane and refuses its sample 1. DepthCopyCase, after the two-sample checks, copies from a one-sample D32 surface, expects its clear value in every texel, and refuses sample 1.

Tested on Ubuntu 24.04, GCC 13.3, RTX 4070 Ti, driver 595.99.02:

  • agc_driver_depth_storage and agc_driver_graphics: both pass 3 of 3.
  • ctest -R '^(agc_|shader_cache)': 834 of 835 pass, and the usual three skip themselves. The one failure, agc_driver_lookup_log_fits_build, failed once in that -j4 run and passed 7 of 7 reruns. This branch doesn't touch its code.
  • Khronos validation layer (LunarG SDK 1.4.363) over agc_driver_depth_storage* and agc_driver_graphics:
    • With the old shader (only the new tests and the dropped check applied), 4 of 4 pass with VUID-RuntimeSpirv-samples-08726 ×2 (the one-sample view bound to sampler2DMS), plus VUID-vkCmdPipelineBarrier-srcAccessMask-02815 ×6 and -dstAccessMask-02816 ×12 (host bits on ALL_COMMANDS).
    • With 815c622, 4 of 4 pass with no VUID.
  • PPSA34502, release libs, 12 GB cap, on the display, with the harness's periodic button presses:
    • main 661f8b7 stops at 15 s with DB_RENDER_CONTROL depth copy, resummarize or decompress is unsupported (register 0x0 = 0x00000084).
    • On 1df1618 (the rebase alone) and on 815c622, it runs to the 300 s limit, with a peak RSS of 7.0 and 7.1 GB, and no driver failure or refusal in either log.
    • In screenshots of the runs, the menu's 3D scene (the war room with the globe) renders at about 0.7 to 1 FPS. On 815c622 the presses then take it through the "Safe Area Adjustment" screen to an outdoor 3D scene, at about 1 FPS.

Still open from the review: the copy is chosen from the viewport and scissor and isn't drawn from the title's geometry (the driver pixel program plan from 16 Oct). I haven't started on that.

Would you reset this PR's branch to mine? That would be git fetch https://github.com/milescoviello/AnyPS5 rebase/5499-db-depth-copy, then git reset --hard FETCH_HEAD and a force-push. If you'd rather not, I can open it as a separate PR with your commit and authorship and link it here.

AI-assisted: yes (Claude Code)

@alexpournaras

Copy link
Copy Markdown
Contributor

@milescoviello, I tested your branch with PPSA34501 and it gets past the 0x00000084 error. Whether it lands in this PR or in one of your own, your changes resolve #6304 too. Great work!

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@codingreapermaps @milescoviello alexpournaras reports above that milescoviello's rebase of this PR (rebase/5499-db-depth-copy at 815c622 on their fork: this PR's commit on current main, plus a one-sample fix) gets PPSA34501 past the 0x00000084 error, which also covers #6304.

To get that reviewed and merged, could the rebased branch become this PR's head? @codingreapermaps, if you're happy to, reset this branch to 815c622 (your commit is kept as is). If you'd rather not, @milescoviello could open it as a new PR crediting you, and we'd close this one in its favour. Either works for us. Tell us which you prefer. The draw-based copy and sampler2DMS points from MarcZX10's review still apply to whichever PR carries it.

@milescoviello

Copy link
Copy Markdown
Contributor

Thanks @alexpournaras. That's the single-sample case from #6304 on the other region's release, so both regions now get past the 0x84 stop with 815c622.

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor

Thanks @oneandonlydean. Either way works for me too. I'll wait for @codingreapermaps until tomorrow before opening anything.

One correction: the sampler2DMS point is the one-sample fix in 815c622. A one-sample surface now goes through a sampler2D build of the shader, and VUID-RuntimeSpirv-samples-08726 is gone from the validation run (details in my comment above). The open point is the draw-based copy. If I end up carrying this, I'll take that one on in the new PR.

AI-assisted: yes (Claude Code)

@JJenkx

JJenkx commented Oct 20, 2026

Copy link
Copy Markdown
Contributor

Another title stops on the same draw: Metal Gear & Metal Gear 2: Solid Snake (PPSA14408, #8737). Its game executable (started with sceSystemServiceLoadExec from the launcher) stops on its first depth-copy draw with DB_RENDER_CONTROL depth copy, resummarize or decompress is unsupported (register 0x0 = 0x00000084) on main 61d0fa5b3c (Linux, RX 6650 XT, RADV). This branch currently conflicts with main, and its relinker predates --module-dir . beside --executable, so I could not test the title with it. I can run it again once the branch is rebased.

@milescoviello

Copy link
Copy Markdown
Contributor

@JJenkx a rebased copy is on my fork: milescoviello:rebase/5499-db-depth-copy, head 95ca794 on main eea640a. It holds codingreapermaps's commit plus my one-sample fix from above, unchanged; only the base moved (previous head 815c622). It also merges cleanly onto today's main 4e79d81, and its relinker has --module-dir.

At this head, on Linux, RTX 4070 Ti (NVIDIA 595.99.02), GCC 13.3, Release, ctest -R '^agc_' passes 843 of 844. The one failure is agc_driver_lookup_log_fits_build, which fails under load on main too (#8601); it passes 3 of 3 run alone. I haven't rerun the validation layer or a title at this head yet.

AI-assisted: yes (Claude Code)

@milescoviello

Copy link
Copy Markdown
Contributor

As @oneandonlydean offered, I opened the carry as #8975. It holds @codingreapermaps's commit, with their authorship, plus my one-sample fix, rebased onto main f894ba6 (the 29 depth tests pass). It's a draft until the draw-based copy (the driver pixel program from the 16 Oct plan) is in. #8975 says #5499 can be closed in its favour, whenever you're ready.

@JJenkx: the fork branch rebase/5499-db-depth-copy moved to that head (120900a342), so PPSA14408 can be tested against #8975 directly.

AI-assisted: yes (Claude Code)

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@milescoviello thanks for opening #8975 with @codingreapermaps's authorship kept. We'll review it once it's out of draft with the draw-based copy, and close this one in its favour then.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

@milescoviello your rebase (95ca794) passes our review, including your one-sample fix, and we'd like to merge it. Could you open it as a PR from your branch, crediting @codingreapermaps (their commits kept, or a Co-authored-by line)? Then we'll run full CI and merge it, and close this one as carried by yours. The whole-surface compute copy is fine for now; please keep the debt line for it.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Carried by #8975, which landed this change with credit. Thanks for the original work here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* build docs needs rebase Conflicts with main, rebase needed unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants