feat(agc): draw DB depth copies with a driver pixel program #8999
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/8999"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T09:09:16Z.
What
#8975 has merged. This PR is now its one commit,
994337f614, onmain4ec064d29b.#8975 runs a draw with
DB_RENDER_CONTROL.DEPTH_COPYas a compute pass over the whole surface, chosen when the viewport and scissor cover it. The maintainers accepted that with its debt line, and asked for this as a follow-up: on #5499 they proposed running the copy 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". They were fine with a driver-owned guest pixel program marked as driver-authored in the debt file.This does that. The precheck rewrites a copy of the draw's registers and sends it through the normal draw path:
DB_RENDER_CONTROLbecomes 0, so nothing is tested or written. The decoder still requires no depth or stencil tests.SPI_SHADER_PGM_*_PS, the user SGPRs,SPI_PS_INPUT_ENA/ADDR(PERSP_CENTER | POS_FIXED_PT),SPI_SHADER_COL_FORMAT(32_R),CB_SHADER_MASK,DB_SHADER_CONTROLand alpha-to-mask are rewritten.The programs are hand-encoded RDNA2 and published beside the null pixel program, prepared at use:
v_and_b32/v_lshrrev_b32unpackPOS_FIXED_PT(v2) into x and y.image_loadreads one sample:2D_MSAAwith the sample index in s8 for a multisampled plane,2Dfor a one-sample plane.exp mrt0writes it.The T# comes from
DepthCopySourceWords, built from the plane asdecodeDepthdecodes it.decodeDepthPlaneis factored out ofdecodeDepth, so the address, pipe-bank XOR, slice and HTILE fields match the surface the draws registered;decodeDepthkeeps its own checks.Reading a multisampled plane. The draw's resources go through
DepthSurfaceTexture. For a multisampled plane, that path normally runs the guest-memory import checks of native multisample sampling (CheckCurrent, the creation-time owner), which a plane only the host draws have written doesn't pass. The decode marks a draw with the multisampled copy program (State::depthCopySource, placed in existing padding, sosizeof(State)is unchanged).Graphics::DrawandDrawWithRecipethen open aDepthCopySourceScope. Inside it,DepthSurfaceTextureandDepthSurfaceHoldsskip those checks for the plane, but still check the descriptor (CheckResource), apply a pending fast clear, and refresh the sample shadow as before. One-sample planes take the existing path unchanged.What goes: the compute pass (
DepthSample.compand its CMake loop),DispatchDepthSample,CopySample/CopyDepthSample,RunDepthCopyPassandVulkanDevice::DepthCopyPass. The copy is now an ordinary draw, so:What is still refused: stencil copies, depth tests, depth formats other than
Z_32_FLOAT, mipmapped or partially resident planes, a partial sample mask, color target 0 blending, indirect draws, and targets other than a single-sample R32 float of the plane's size. The debt entry is rewritten for the driver-authored program. It records one known difference from the console: withCOPY_CENTROIDit copies sample 0, so an edge pixel whose sample 0 the draw doesn't cover can differ.Tested
65a247ec66(rebased ontomain0bf13e4bb9; theDraw.hpp/Draw.cppconflict keepsmain'sPipelinedColorMetadataPassWrites,DrawPipelineEnabledandCommitTrimsand dropsRunDepthCopyPassas before). The 23 tests matching^agc_driver_graphics$|depth_copy|^agc_driver_depthpass 3 of 3 on Linux (Ubuntu 26.04.1, GCC 15.2, Release, RTX 4070 Ti, 615.71.09) and on the Windows 11 VM (GT 1030, 582.66, WinLibs GCC 15.2.0 r7).Earlier heads: Ubuntu 24.04, GCC 13.3, NVIDIA RTX 4070 Ti, driver 595.99.02, on #8975 at
127aba3ed6(mainf894ba69d3). The change was then rebased onto #8975's two lavapipe test commits (223e90289b,67cea1c314). They only edit a test case this PR removes, so the tree is the same as the tested one. Under lavapipe (llvmpipe, LLVM 20.1.2), the 31 depth tests,agc_driver_depth_copy_drawamong them, pass 3 of 3 at the rebased head.New execution test
agc_driver_depth_copy_draw(tests/execution/DepthCopyDraw.cpp). One submission holds three draws of the same triangle, whose edge crosses a 64x4 target:Every texel the reference wrote must hold 0.25 in the copy target, and every other texel must still hold -1.0. With #8975's compute copy, the same test stops at "DB depth copy into a target without a resident image is not implemented", because that pass needs a tiled resident target. On an R32 target it can take, the compute pass would write every texel.
Decode tests (
agc_driver_graphics,depthCopyPassTests):DecodeTextureResourcefor a two-sample and a one-sample plane;On
main2f161d4f33, after #8975 merged (3d17a2413d): the 32 tests matchingdepth|Depth|db_copy|DbCopy|^agc_driver_graphics$pass 3 of 3, exceptagc_driver_sample_order_recipe_depth_locations. That one is new onmainfrom #6683 and fails there on this card too; #9056 fixes it. Under lavapipe (llvmpipe, LLVM 20.1.2), all 32 pass.On
main4ec064d29b(994337f614, rebased over #6887, whoseDispatchMultisampleImagedeclaration sat next to the removedDispatchDepthSample): the 46 tests matchingdepth|Depth|^agc_driver_graphics$|multisample_readback|^agc_driver_msaapass 3 of 3, except the sameagc_driver_sample_order_recipe_depth_locations. They include #6887'sMultisampleReadbacktest.On
maincc0078595d(f5574fea1b). This rebase is over #7927 (depth mip levels) and #8992 (Graphics::Drawsplit into a prepare and a record step), with one conflict in each file:State.cpp: #7927 added its mip and view-slice handling insidedecodeDepth, while this PR moves that decoding intodecodeDepthPlane. The mip block now lives in the helper. A DB depth copy still refuses a mipmapped source before it decodes the plane, so the block only acts for draws.Draw.cpp: the depth copy source scope now opens in the newDraw, around both its prepare and its record step.^agc_driver_(depth_storage|graphics|depth_copy_draw)$passes 3 of 3. That set includes #7927's mip decode checks inagc_driver_graphics.Suites: the 31 tests matching
depth|Depth|^agc_driver_graphics$pass 3 of 3. Khronos validation layer 1.4.363 over^agc_driver_(depth_storage|graphics|depth_copy_draw): #8975's head passes 5 of 5 and this head 6 of 6, with no VUID on either.CoD Black Ops II (PPSA34502), whose depth copies are one-sample: release libs, 12 GB cap, the scripted 203 s run to the war-room menu. The log shows no driver failure or refusal. The menu renders as with #8975's compute copy: the same scene, with the blurred background behind its panel and dialog.
@clairtonmichel, AMD Radeon RX 7900 XTX (RADV, Mesa 26.2.5, Fedora): the 31 tests,
agc_driver_depth_copy_drawamong them, pass.Windows (Windows 11 VM, NVIDIA GeForce GT 1030, driver 582.78, WinLibs GCC 15.2.0, Release): an earlier head didn't build there.
DepthCopyDraw.cppaligned its depth memory withalignas(65536), and MinGW allows at most 8192. 564681799c instead aligns a span at run time inside an array 64 KiB larger, as #8310 does for another test. At this head,agc_driver_graphicsandagc_driver_depth_copy_drawbuild and pass 3 of 3. After the rebase ontomain895f47f4ee, at4478a90829,agc_driver_depth_storage,agc_driver_graphicsandagc_driver_depth_copy_drawpass 3 of 3 there again.macOS (Apple M2 Max, macOS 27.2, x86_64 under Rosetta 2, MoltenVK 1.4.2 from the 1.4.363 SDK and MoltenVK main with SPIRV-Cross #2704): @jotitadev ran it on #8658's macOS port (
maina6dcea9279plus the port), sincemainalone doesn't build there.agc_driver_depth_copy_drawandagc_driver_depth_storagepass 3 of 3 on both MoltenVK builds, so the hand-written driver pixel program compiles and runs there, two-sample read included. The full^agcsuite fails the same 15 tests as the port without this PR; two flaky tests differ in opposite directions and pass alone.Not tested: a multisampled source in an execution test (the decode and descriptor are tested; PPSA12361, the two-sample title, isn't available to me), Intel.
Checklist
main; no other open PR implements the same functions (overlaps the draft #1395)NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)main(they meet only indocs/dev/debt/libSceAgcDriver.md)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by clairtonmichel on 2026-10-21T09:13:48Z.
Tested on AMD Ryzen 7 9800X3D and AMD Radeon RX 7900 XTX (Fedora Linux, Mesa 26.2.5):
agc_driver_depth_copy_draw): 100% passed successfully (31/31 green).Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T09:23:12Z.
Thanks @clairtonmichel, that's the draw-based copy on AMD as well. I added it to the Tested section and the GPU line.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T12:49:15Z.
#8975 has merged, so this is rebased onto
main2f161d4f33. The head is3d17a2413d, the one draw-based copy commit. On that base the 32 depth tests pass 3 of 3 here, except #6683's newagc_driver_sample_order_recipe_depth_locations, which fails onmainon this card as well (#9056 fixes it). Under lavapipe all 32 pass. The description is updated: no dependency now.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-21T17:42:03Z.
Rebased onto
main4ec064d29bafter #6887 conflicted inTextureDetiler.hpp: its newDispatchMultisampleImagedeclaration was next to theDispatchDepthSamplethis PR removes. The head is now994337f614. On that base the 46 depth, graphics and multisample readback tests pass 3 of 3, exceptagc_driver_sample_order_recipe_depth_locations, which fails onmainon this card too (#9056 fixes it).AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T00:10:41Z.
Review: COMMENTED
First Apple GPU / MoltenVK run of this PR. The draw-based depth copy works here, including the multisampled read path.
Machine: Apple M2 Max, macOS 27.2, x86_64 under Rosetta 2. Vulkan loader + MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0), and MoltenVK main + SPIRV-Cross #2704. Release,
BUILD_TESTING=ON.Base/method: PR #8658
feat/macos-port@a1fb8e3e9c(currentmaina6dcea9279plus the macOS port), notmain—maindoes not build on macOS. This PR's diff (git diff merge-base..564681799 -- . ':!docs') applied on top, clean.Result (
--repeat until-fail:3, both drivers):agc_driver_depth_copy_drawandagc_driver_depth_storagepass 3/3 on each.So the driver pixel program path lands on MoltenVK: the hand-encoded RDNA2 program (
v_and_b32/v_lshrrev_b32unpack ofPOS_FIXED_PT,image_load,exp mrt0) compiles and runs, and the2D_MSAAimage_loadreads the right sample of the two-sample plane inside theDepthCopySourceScope.Full
^agcsuite with this PR (SDK, clean rebuild): 15 failures, the same set as the#8658base —agc_driver_depth_copy_drawis not among them. Two tests differ between the base and PR runs in opposite directions (agc_driver_cross_workgroup_flag,agc_driver_uint8x4_color_target); both are intermittent here and pass on their own--repeat until-fail:3, so neither is attributable to this PR. No new failure.GPUs tested: Apple M2 Max (MoltenVK 1.4.2; and MoltenVK main + SPIRV-Cross #2704).
Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-22T00:12:28Z.
Thanks @jotitadev. That's the first Apple GPU run, and it's good to know the hand-written RDNA2 copy program runs through MoltenVK and SPIRV-Cross, the two-sample
image_loadincluded. I added it to the Tested section and the GPU line.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-22T10:06:05Z.
Rebased onto
maincc0078595dasf5574fea1b. #7927 (depth mip levels) and #8992 (theGraphics::Drawprepare/record split) each overlapped one hunk:decodeDepthPlane.Draw.The focused tests pass 3 of 3. Details in Tested.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by EagleBearerYS on 2026-10-22T12:42:31Z.
@milescoviello a merge-order note: #9533, with #9717 and #9742 stacked on it, adds
if (stencil) found->RequireStencilProven();to the native depth branch inDepthSurface.cppthat this PR splits ondepthCopySourceActive. Composed, the stencil check goes in yourelsebranch afterCheckCurrent(). If a depth copy can also read the stencil plane, it belongs in the copy-source branch too; I'd check that in the rebase. #9533 goes after this PR and rebases over it, the same order #9717's body lists.Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-22T12:43:45Z.
@EagleBearerYS agreed on the order: this PR first, and #9533 rebases over it.
A DB depth copy here never reads the stencil plane.
DecodeDepthCopyPassaccepts onlyDEPTH_COPY, the centroid bit and the copy sample ofDB_RENDER_CONTROL. It refusesSTENCIL_COPY(bit 3), along with clears, resummarize and decompress, with "DB depth copy combined with a stencil copy, clear, resummarize or decompress", and the copy draw samples only the depth plane. SoRequireStencilProven()belongs only in theelsebranch afterCheckCurrent(), as you composed it. If a later change adds stencil copies, that branch will need the check too.AI-assisted: yes (Claude Code)