perf(agc): store whole words of 1- and 2-byte texels in the detile shader #6905
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6905"
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 parl0v on 2026-10-16T17:34:24Z.
What
TextureDetile.compmoves one element per invocation. For 1- and 2-byte elements (R8, R16 and the other 8/16-bit formats) the destination word is shared by 4 or 2 invocations, so every element is written with anatomicAnd+atomicOrpair on that word (copyElementin the buffer paths,loadElementin the image retile). Neighbouring invocations hit the same word, and those paths run at 9-44 GB/s on an RTX 4060 against 253 GB/s for 4-byte elements.-DWORD_GROUPS=1, buffer and image) combine the elements of each destination word in workgroup shared memory and store the word once. Each invocation still locates its own element (locate, the per-element addressing split out ofmainunchanged); after a barrier, a group of 4 (1-byte) or 2 (2-byte) neighbouring invocations whose elements are all in the window's range and land in one aligned 4-byte word, in order, store that word with a plain write. Any other group (a row or window edge, a partial word at a range boundary, an unaligned base) falls back to the existing per-element atomic path, so the bytes written are exactly the old ones.TextureDetiler::pipeline) picks the word variants only where they help: 1- and 2-byte buffer detiles (the linear destination always keeps neighbours in one word), and retiles of the linear and standard (non-equation) layouts. Equation-swizzled retiles (_X, thick) keep the old shader: their tiled words hold elements of other rows, and grouping them measured slower. 4-, 8- and 16-byte elements are unchanged and use the same SPIR-V as before.agc_detile_small_elements(agc_driver_recorder_tests --small-element-detile-only) runs the buffer retile, buffer detile and image retile on the device for 1- and 2-byte elements overSW_64KB_S,SW_4KB_S,SW_64KB_R_Xand linear, odd sizes (37x21, 70x9, 37x5), a tail mip of each 64 KB mode, and three windows (whole mip, a byte range with unaligned ends, columns 3 to width-2). Every byte of each destination is compared with a CPU reference (the swizzle equations for_X, the shader's standard-swizzle bit layout forSW_*_S), including the bytes no element maps to. Breaking the word store (^ 1u) fails it at the first byte.This is a throughput fix for those paths: no title I have is bound by 1- or 2-byte detiles yet, so it makes no frame-rate claim (title runs under Tested).
Tested
Windows 10 19045, MinGW GCC, Release.
agc_detile_small_elements,agc_driver_graphics,agc_unit_shadow,agc_shadowed_key_storesand theagc_storage_*tests pass.--detile-benchharness timing 20 dispatches per path with timestamp queries, 1920x1080, median;main452494439vs this PR in the same build tree, two runs each, mean of the two):mainSW_64KB_SSW_64KB_R_XSW_64KB_SSW_64KB_SSW_64KB_R_XSW_64KB_SSW_64KB_R_XAPS5_PROFILE_GPU=1: no change, because their per-frame write-backs are not 1- or 2-byte standard-layout retiles. Minecraft Dungeons II (PPSA16064): 6.60 / 6.71 / 6.60 FPS onmain, 6.68 / 6.58 / 6.67 with this PR,storage-writeback17.3-17.6 ms per present on both. Sword of the Sea (PPSA25344): 9.62 / 9.60 FPS onmain, 9.60 / 9.60 with this PR,storage-writeback15.3-15.5 ms andstorage-upload5.0-5.1 ms per present on both. The paths this speeds up are the buffer detile of 8- and 16-bit textures (sampled texture uploads) and the standard-layout storage write-backs of such images; I have no title scene yet that is bound by them, so this is offered as a throughput fix with the benchmark above, not a frame-rate claim.tools/check_conventions.py --base upstream/mainpasses.Performance capture (as the Performance report form describes): Minecraft Dungeons II (PPSA16064) title screen, RTX 3060 12 GB (i5-12400F), NVIDIA 617.42, Windows 10.0.19045, 3840x2160 output. Only
APS5_TRACE_SECONDS=120:12set, caches warm (the title ran once on the build and was restarted), stderr not redirected.main48d61f53b4against this PR's head 283b057afe16:Frame and GPU times (ms):
Top phases (ms per frame):
Traces:
aps5-trace-48d61f53b46f-9720.json.gz(main) andaps5-trace-283b057afe16-15136.json.gz(this PR), attached below.trace_digest.py, main
seconds 120:12 from present 2158: 99 presents, frame p50 117.2 / p90 145.0 / p99 158.4 / max 158.4 ms, GPU busy 100.7 ms per present
NVIDIA GeForce RTX 3060, NVIDIA 617.42, Windows 10.0.19045, 3840x2160, commit
48d61f53b4, dropped: noSlowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 235.3, batch 100.7, Driver.Packet.dispatch 86.1, Driver.Dispatch 85.2, Driver.Packet.memory_wait 68.0, Vulkan.Dispatch 39.4, Vulkan.Dispatch.shader_resources 37.1, Driver.Packet.device_lock 32.2, Driver.Packet.prepare_memory 27.8, Recorder.Sync 20.7
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
trace_digest.py, this PR
seconds 120:12 from present 2159: 100 presents, frame p50 116.9 / p90 144.8 / p99 163.7 / max 163.7 ms, GPU busy 100.6 ms per present
NVIDIA GeForce RTX 3060, NVIDIA 617.42, Windows 10.0.19045, 3840x2160, commit 283b057afe16, dropped: no
Slowest frames (largest slices inside each, inclusive)
Threads (ms per frame)
Largest slices (ms per frame, inclusive, all threads): Driver.Packet 233.6, batch 100.5, Driver.Packet.dispatch 83.9, Driver.Dispatch 83.0, Driver.Packet.memory_wait 67.5, Vulkan.Dispatch 38.4, Vulkan.Dispatch.shader_resources 36.1, Driver.Packet.device_lock 34.3, Driver.Packet.prepare_memory 26.5, Recorder.WaitSerial 20.3
Longest waits
Largest GPU batches (GPU ranges inside, and the CPU slices that recorded each, inclusive)
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 CnRJay on 2026-10-16T22:10:01Z.
Review: COMMENTED
Good PR: the microbenchmark is clear (buffer detile 1-byte
SW_64KB_S228.9 to 37.9 us, 6x; image retile 2.2x), unchanged SPIR-V for 4/8/16-byte elements is shown (0.98-1.05x), the fallback to the per-element atomic path keeps the bytes identical, and the test compares every byte against a CPU reference including bytes no element maps to.WORD_GROUPS, buffer and image) are compiled for every title that detiles 1- or 2-byte formats. Please state the extra compile time on a cold cache and whether the variants are built on first use or prewarmed (the journal/prewarm path has to know them, otherwise they compile on the queue worker at the first write-back).agc_detile_small_elementswould show the barrier path is correct there too.Imported from boykopovar/AnyPS5. Originally posted by keravyn-ops on 2026-10-17T09:26:03Z.
AMD / Windows run of this PR at 1061179c8: Radeon 780M (RDNA 3, 0x15bf), AMD driver 25.10.20.01 (32.0.21020.1007), Windows 11 Home 10.0.26100, WinLibs GCC 15.2.0 r7, Release.
agc_detile_small_elements: pass (0.65 s)agc_driver_graphics: pass (4.95 s)agc_unit_shadow,agc_shadowed_key_stores: passagc_storage_kept_unit_settle,agc_storage_baseline_settled,agc_storage_integer_clear,agc_storage_upload_lifetime,agc_storage_upload_failure,agc_storage_written_buffer_order,agc_storage_split_writeback,agc_storage_cpu_snapshot: passNo benchmark run on this device.
AI-assisted: yes (runs made on the device above).
Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-17T16:56:26Z.
@CnRJay thanks for the review. On the three points:
Latent, not game-level. Agreed. I have no title yet whose frames are bound by 1- or 2-byte detiles: Minecraft Dungeons II and Sword of the Sea write back other formats each frame, so they show no change. I've changed the description to say that this is a throughput fix for those paths and that it makes no frame-rate claim. The title only names what the shader does.
Compile cost and prewarm.
TextureDetiler::pipelinecreates each one on first use, keyed by (tile mode, element size, retile, thick, image), throughcontext.pipelineCache, and that is unchanged here.words = elementBytes < 4 && ...), so a title that detiles a 1-byteSW_64KB_Stexture still creates one pipeline for that key, compiled from the word SPIR-V instead of the old one.vkCreateShaderModuleper variant on first use. The difference in pipeline compile time is that of a shader with 3 shared arrays and a barrier over the same addressing code.vkCreateComputePipelinestime for both variants on my RTX 4060 and post it here; my test box is off for the weekend.Shared memory and other vendors.
groupWords[32],groupLanes[32]andgroupDestinations[64]are 128uints, 512 bytes per 8x8 workgroup. That's 3 % of the 16 KiB Vulkan minimum formaxComputeSharedMemorySize, about 1 % of NVIDIA's 48 KiB and 0.8 % of the 64 KiB LDS on RDNA, so shared memory doesn't limit occupancy on any of them. On the barrier path on AMD: thanks @keravyn-ops for the Radeon 780M (RDNA 3) run at 1061179c8.agc_detile_small_elementspasses there, and so doagc_driver_graphics,agc_unit_shadowand the storage tests. Intel hasn't been run yet.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-18T12:22:36Z.
Review: COMMENTED
Apple GPU run of the new word-group detile variants. This is a third vendor after NVIDIA and AMD, and Apple GPUs differ here in threadgroup memory and in subgroup width (32).
Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta. Head 1061179c8. Method: macos-port @ b7eb6b6b + ImportWatched + PR diff, not main. The shader,
TextureDetiler.cppand the shader build rules applied cleanly. Three conflicts came from code the port doesn't have, and I resolved them by hand:TextureDetiler.hpp: added the two new module handles and kept the port's image descriptor pools (the port has noDescriptorRing).CMakeLists.txt: added theagc_detile_small_elementstest next to the port's tests.Recorder.cpp: inserted theSmallElementDetileTestnamespace and the--small-element-detile-onlydispatch without the other recorder tests from main.agc_detile_small_elementspasses on MoltenVK 1.4.2 (small element detile tests passed) and on MoltenVK main + SPIRV-Cross #2704. With--repeat until-fail:10it passes 10/10 on each driver.The word path really runs on this device: with the whole-word store in
TextureDetile.compchanged togroupWords[slot] ^ 1u(local mutation, reverted afterwards), the test fails at its first case:SW_64KB_S 1B 37x21, whole mip, buffer retile: byte 0 is 10, expected 11. So the host selects the word variant on Apple, and the test catches a wrong combined word.Neighbouring tests pass:
agc_storage_baseline_settled,agc_storage_upload_lifetime,agc_storage_upload_failureandagc_unit_shadow.No timing measured.
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 github-actions[bot] on 2026-10-18T20:48:24Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-18T22:09:10Z.
Traces of the performance capture in the description (they open in ui.perfetto.dev):
main48d61f53b: aps5-trace-48d61f53b46f-9720.json.gzImported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T00:00:58Z.
Follow-up to my Apple run above: the full suite, which I left out there, is now done.
Full
^agcsuite with the PR on Apple M2 Max (MoltenVK 1.4.2,-j1 --timeout 30, flip/display/lds_atomics64 excluded; macos-port @ b7eb6b6b + ImportWatched + PR diff, not main): 14 failures out of 434, the same 14 as the unchanged port on this machine today (14 out of 433). The extra test isagc_detile_small_elements, which passes. No timeouts.The new head 283b057af is a rebase:
git range-diffagainst 1061179c8 shows only context lines frommain, so this applies to it too.Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-20T18:11:21Z.
@parl0v this now conflicts with
maininGraphics/src/TextureDetiler.cpp(around lines 171-182). #6436 merged today and routes every shader module creation throughGraphics::CreateShaderModule(..., label), so modules are keyed by the pipeline-library mode. This PR still builds its word-variant modules inline with its ownVkShaderModuleCreateInfo.Could you rebase onto current
mainand create the word variants (words/imageWordModule) throughCreateShaderModule, each with its own label? The other files merge cleanly. Once the head moves we'll re-review the delta and re-run CI.Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-21T01:11:44Z.
@oneandonlydean rebased onto current
main(f41aa9598). The word variants now go throughCreateShaderModule, each with its own label:vkCreateShaderModule detile wordsfor the buffer word module andvkCreateShaderModule detile image wordsforimageWordModule; the existing image module keeps its label. Nothing else changed in the PR.RTX 4060 (NVIDIA 617.42, Windows 10 19045), with
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1:agc_detile_small_elements,agc_import_watchand the other recorder/detile/retile tests pass (6 of 6), 0VUID-lines, and the layer loaded.