perf(agc): read depth planes into storage images in a compute pass #12120
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/12120"
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 meh7an on 2026-10-27T21:56:04Z.
What
A depth surface's plane and the 32-bit color storage image that holds its texels are copied into each other whenever a shader reads or writes the plane as a storage image. On
main(#11685) that is onevkCmdCopyImagebetween the depth aspect and the color image whereVK_KHR_maintenance8allows it, else a copy through a staging buffer. On an RTX 2080 Ti the copy costs about 1.4 ms per 4K plane. Sonic Origins Plus does two per frame on its main menu, 2.88 ms of GPU time per frame.Where the device has
VK_KHR_push_descriptor, this PR reads a D32 plane into the storage image in a compute pass instead (DepthToStorage.comp):OpImageFetch, no sampler) and stores the bits unchanged through anr32uiview of the storage image (StorageTexture::AtomicView).copyPlane's rectangles as push constants, one dispatch each, so partial unit stores (StoreDepthPlane) use it too.vkCmdPushDescriptorSetKHR), so a recorded pass holds no descriptor set. The pipeline and its layouts are made once per device on first use and released inClearDepthSurfaces. Each surface keeps its depth-aspect view until it is released.VulkanDeviceenablesVK_KHR_push_descriptorwhen the device has it, and the graphicsContextcarries it aspushDescriptors. The newagc_embedded_shaderCMake function compiles aGraphics/shaderssource into an embedded SPIR-V header.Copies back into the depth plane keep
main's copy. A fragment shader's depth write can't stand in for it: on the 2080 Ti it flushed subnormals to ±0 and turned every NaN into -inf, and withoutVK_EXT_depth_range_unrestrictedit clamped to [0, 1]. Finite values outside [0, 1] survived with the extension only because the driver didn't clamp them: with a [0, 1] viewport the spec leaves them undefined, and a ±FLT_MAXviewport, which would make them defined, broke the store-back test on this driver. The round-trip results are under Tested.These keep
main's copies too: D16 planes, the stencil plane, multisampled surfaces,TakeStorageand the layered copies (LayeredDepthStorage::Copy). So does every plane whenAPS5_NO_DEPTH_TRANSFER_PASS=1is set; the variable has its row inENVIRONMENT.md. The copies still take #11685's direct path where it applies, andAPS5_NO_DIRECT_DEPTH_COPY=1still forces the staging buffer.What the pass keeps, by device configuration:
VK_EXT_depth_range_unrestricted: the pass gives back exactly whatmain's copy gives back, word for word. It reads the 32-bit texel without a sampler and stores its bits, and the spec defines no conversion for that read.FLT_MAX, ±inf, and quiet and signalling NaNs with payloads.Tests:
agc_driver_depth_storagestores the 16 words into a D32 plane and a D32S8 plane, then reads them back twice, copies only and with the pass. It requires word-for-word equal results and that the pass ran. It requires 0.25, 1 and +0 back in every configuration, and -0.5 and 2.0 back where the depth range is unrestricted. It reports which of the other words the copy changed: none on this GPU. Its device enablesVK_KHR_push_descriptorwhen the queue can draw, andVK_EXT_depth_range_unrestrictedunless--restricted-depthis given. The existing whole-plane data and stencil checks run through the pass as well.agc_driver_depth_storage_copiesruns it withAPS5_NO_DEPTH_TRANSFER_PASS=1and requires zero passes, with the data and stencil checks unchanged. Newagc_driver_depth_storage_restricted_depthruns it without the extension.agc_driver_depth_plane_partial_store(partial stores) runs in three modes. The default requires the pass where the device hasVK_KHR_push_descriptor. The newagc_driver_depth_plane_partial_store_image_copy(--image-copy) turns the pass off and requires direct copies whereVK_KHR_maintenance8is enabled.--buffer-copyturns both off.DepthSurfacegainsSetDepthTransferPassesandDepthTransferPassCountfor these tests, like #11685'sSetDirectDepthCopyandDirectDepthCopyCount.No open PR reads depth planes in a compute pass or enables
VK_KHR_push_descriptor.tools/pr_overlap.pyfinds no other open PR that changes the same code. It could not compare 92 PRs that conflict withmainand share a file with this one, and none of their diffs adds push descriptors or changescopyPlaneorDirectDepthCopy.Tested
Rebased onto
main2227f13661(57d63ac306). The round trips and S3K numbers below were measured onmainc02d287bd0, with this change as 05addcdbd1. The 120 commits between them change eight lines of the files this PR touches, inCMakeLists.txtandVulkanDevice.cpp, and nothing in the transfer path. On the rebased head the validation run below gives 18/18 again, with noVUID-line and no missing-layer line, andctestpasses 2815 of 2815.Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 2080 Ti, driver 617.14, i9-9900K.
Round trips. These ran with a temporary build that could also turn on the fragment depth write, which the review asked about. They store the 16 words into a D32 plane and a D32S8 plane through the store-back, then read them back through a storage view. Both formats gave the same results.
VK_EXT_depth_range_unrestrictedenabled--restricted-depth)main's copies, direct and through the staging bufferFLT_MAXand ±inf kept; subnormals flushed to ±0; every NaN came back as -infFLT_MAXviewport (dropped)S3K. Sonic Origins Plus (PPSA05324) on the Sonic 3 & Knuckles page of the main menu,
main's defaults.mainc02d287bd0againstmainwith this PR (05addcdbd1), both built from the same tree; nothing else is applied. Each build got a warm-up boot and oneAPS5_PROFILE_GPU=1boot. Then came two interleaved traced rounds (main, PR,main, PR;APS5_TRACE_SECONDS=200:15, six title FPS readings each).main[gputime]copy class per present (2 transfers, 63.3 MiB)[gputime]GPU time per present, all ranges, the same six blocks on the pagemain's copy, about 1.5 ms of the remaining 1.68 ms.Driver.Draw.shader_compile_and_linkinside the window,main's included, so the rounds compare like with like.Tests.
ctestonmainc02d287bd0plus this PR: 2776 of 2777 pass. The failure,agc_driver_mesh_barycentric_emulation, wasmain's own and passes on the rebased head.ctest --test-dir build -R "depth_plane_partial_store|depth_storage|depth_plane_sampling|depth_copy|native_depth" -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation: 15/15 onmainand 18/18 on this PR. The three extra tests areagc_driver_depth_plane_partial_store_image_copy,agc_driver_depth_storage_copiesandagc_driver_depth_storage_restricted_depth. Neither log haswas not found but was requested by env var VK_INSTANCE_LAYERS, and neither has aVUID-line. On this PR, the threedepth_storageruns report that the pass matches the copy and that the copy changed none of the 16 words. The copies run reports zero passes.All four traces are attached, one zip per round with the
mainand PR traces.depth-to-storage-s3k-c02d-round1.zip
depth-to-storage-s3k-c02d-round2.zip
Sonic 3 & Knuckles page, round 1, main
seconds 200:15 from present 4373: 250 presents, frame p50 58.3 / p90 65.6 / p99 82.2 / max 82.7 ms, GPU busy 53.6 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit
c02d287bd0, dropped: yesSonic 3 & Knuckles page, round 1, this PR
seconds 200:15 from present 4517: 248 presents, frame p50 59.2 / p90 64.0 / p99 82.2 / max 86.7 ms, GPU busy 52.6 ms per present
NVIDIA GeForce RTX 2080 Ti, NVIDIA 617.14, Windows 10.0.26300, 3840x2160, commit 05addcdbd111, dropped: yes
Checklist
main; no other open PR implements the same functionsNotImplemented_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)Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T03:06:17Z.
Review: CHANGES_REQUESTED
I independently checked the two concerns raised in the discussion on exact head
2c401e31988c7b18308bade0e7ed3a81ba4ed0df. Both are confirmed from the code: the pass is selected for 32-bit depth/storage pairs without constraining stored values, while the store-back shader writes the integer payload asgl_FragDepth; andagc_driver_depth_storageasserts a pass ran even whenAPS5_NO_DEPTH_TRANSFER_PASSdisables them. I also ranglslangValidator -V --target-env vulkan1.1on both new shaders successfully, and recheckedgit diff --check, current-main merge preview, the attached round-2 digest output, and the author's reported validation results. I am requesting changes for the two concrete issues below; the 16/16 focused GPU test result does not cover the arbitrary-bit round trip or the opt-out test configuration.Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-28T10:53:23Z.
Review: CHANGES_REQUESTED
Agreeing with the two points already raised at
2c401e3198, neither addressed yet:DepthSurface.cpp:80-82:depthTransferPassgates on format and push descriptors only, whileStorageToDepth.fragwrites any stored word throughgl_FragDepthandFromStoragefixes the viewport to 0..1. Values outside [0, 1] or NaN written through the storage alias are not kept bit for bit, andVK_EXT_depth_range_unrestrictedis enabled where available. Either keepmain's copy for values the pass can't reproduce exactly, or leave the pass opt-in until the equivalence is shown. Replace the blanket range claim with an argument per device configuration, and add enabled-versus-copy round-trip checks (-0.5, 2.0, signed zero, subnormals, NaN) stating bit preservation only as far as it holds.DepthStorage.cpp:367requiresDepthTransferPassCount() > 0wheneverpushDescriptorsis set, butAPS5_NO_DEPTH_TRANSFER_PASSstops every increment, so the test fails with the switch. Honor the switch there (asDepthPlanePartialStore.cpp:135does) and runagc_driver_depth_storageboth ways, expecting zero passes in the off run.Keep the copy fallbacks and the existing data, partial-rectangle and stencil checks.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-29T08:54:15Z.
Review: CHANGES_REQUESTED
Re-reviewed exact head
57d63ac306f22ea71b02075e0d738113c4728aa5. The earlier test concerns are addressed in this head:RunRoundTripscompares the pass with the copy path across the signed-zero, out-of-range, subnormal, infinity and NaN words, and its pass-count assertion now permitsAPS5_NO_DEPTH_TRANSFER_PASS; the pass-off case is separately selectable. The remaining blocker is the behavior limit raised in the latest review:depthToStoragePassis enabled by default for eligible format/push-descriptor devices, while the test only requires exact input preservation for [0,1] values and for out-of-range values when unrestricted depth is available. Please add the still-unmeasured bit-preservation scope and theAPS5_NO_DEPTH_TRANSFER_PASSfallback todocs/dev/debt/libSceAgcDriver.mdas requested, so the default behavior and its limits are explicit. Current-main merge preview is clean; exact-head Windows workflow passes, product Linux/GPU jobs are skipped. I did not run local GPU tests.