Repository navigation
feat(agc): draw DB depth copies with a driver pixel program - #8999
Conversation
|
Tested on AMD Ryzen 7 9800X3D and AMD Radeon RX 7900 XTX (Fedora Linux, Mesa 26.2.5):
|
|
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) |
|
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
31d3a6b to
1a20e39
Compare
1a20e39 to
3d17a24
Compare
|
#8975 has merged, so this is rebased onto AI-assisted: yes (Claude Code) |
3d17a24 to
994337f
Compare
|
Rebased onto AI-assisted: yes (Claude Code) |
jotitadev
left a comment
There was a problem hiding this comment.
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 (current main a6dcea9279 plus the macOS port), not main — main does 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_draw and agc_driver_depth_storage pass 3/3 on each.
the DB depth copy wrote the drawn depth exactly where its draw rasterized
So the driver pixel program path lands on MoltenVK: the hand-encoded RDNA2 program (v_and_b32/v_lshrrev_b32 unpack of POS_FIXED_PT, image_load, exp mrt0) compiles and runs, and the 2D_MSAA image_load reads the right sample of the two-sample plane inside the DepthCopySourceScope.
Full ^agc suite with this PR (SDK, clean rebuild): 15 failures, the same set as the #8658 base — agc_driver_depth_copy_draw is 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.
|
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 AI-assisted: yes (Claude Code) |
5646817 to
f5574fe
Compare
|
Rebased onto
The focused tests pass 3 of 3. Details in Tested. AI-assisted: yes (Claude Code) |
|
@milescoviello a merge-order note: #9533, with #9717 and #9742 stacked on it, adds |
|
@EagleBearerYS agreed on the order: this PR first, and #9533 rebases over it. A DB depth copy here never reads the stencil plane. AI-assisted: yes (Claude Code) |
f5574fe to
4478a90
Compare
|
Rebased onto One conflict, in
AI-assisted: yes (Claude Code) |
4478a90 to
65a247e
Compare
|
Rebased onto
AI-assisted: yes (Claude Code) |
65a247e to
22b2a18
Compare
A draw with DB_RENDER_CONTROL.DEPTH_COPY ran as a compute pass over the whole surface, chosen when the viewport and scissor covered it. It now runs as the title's own draw: the precheck rewrites the draw's registers to bind no depth target and a driver-authored guest pixel program, then draws it through the normal path. The program reads POS_FIXED_PT, loads one sample of the Z_32_FLOAT plane through a T# built from the DB registers (DepthCopySourceWords), and exports it to color target 0 as 32_R, so only the pixels the draw covers are written, and the normal draw path orders it after the draws that rendered the plane. - The plane is decoded by decodeDepthPlane, factored out of decodeDepth, so its address, pipe-bank XOR and slice match the registered surface. - Two programs, one per source kind: image_load 2D_MSAA with the sample in s8, and image_load 2D. They are published with the null pixel program and prepared at use. - A multisampled plane is read from its host image or sample shadow without the guest-memory import checks of native multisample sampling, inside a DepthCopySourceScope opened by Graphics::Draw for draws whose decode found the multisampled copy program (State::depthCopySource). - The compute pass, its shader and the CopySample path are removed. - A new execution test draws depth over a triangle, copies it with the same triangle and compares the covered texels with a reference draw. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The test declared its depth plane alignas(65536). WinLibs GCC 15.2
rejects static objects aligned above 8192 bytes ("requested alignment
'65536' exceeds object file maximum 8192"), so agc_driver_depth_copy_draw
did not build on Windows. The plane is now a 64 KiB aligned span inside
a larger array, as boykopovar#8310 does for the array window test, and the test
checks the alignment.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
22b2a18 to
9f9c60f
Compare
|
|
|
@adriadam10 thank you for the rebase and the merge. AI-assisted: yes (Claude Code) |
What
#8975 has merged. This PR is now its one commit,
994337f614, onmain4ec064d.#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 ontomain0bf13e4; 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(mainf894ba6). 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
main2f161d4, 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
main4ec064d (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
maincc00785 (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: feat(agc): render into depth mip levels #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. 5646817 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 ontomain895f47f, 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 (
maina6dcea9 plus 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 feat(agc): add experimental depth clear and copy recognition #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