perf(agc): copy a pending block-compressed surface into its sampled texture on the GPU #4747
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/4747"
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 TideOPL on 2026-10-12T20:34:59Z.
What
A compute pass can write a block-compressed surface through an uncompressed storage view whose element is one block:
32_32_UINTfor 8-byte blocks (BC1, BC4) and32_32_32_32_UINTfor 16-byte blocks (BC2, BC3, BC5, BC6H, BC7). Unreal Engine's runtime virtual textures encode their physical pages this way every frame. Minecraft Dungeons II (PPSA16064) has three 4096x4096 pages (BC5, BC6H and BC7, 16 MiB each) that are written by compute and sampled in the same frame.cachedTexturefound the pending storage image but dropped it, becauseTexture::CanCopyFromrejects block-compressed descriptors. The lookup then took the snapshot path every time:StorageTexture::FlushPendingstored the whole 16 MiB surface to guest memory.UnchangedSince, soEqualsCommittedcompared all 16 MiB with the snapshot. That took 1 to 8 ms per lookup.ReadTextureSurfaceread the surface again and a new texture uploaded it.With this change the BC texture is a copy of the storage image instead:
Texture::CanBlockCopyFromaccepts a storage image over the same memory with:BlockCopyTagtexture owns a BC image.RefreshDepthCopyrefreshes it with onevkCmdCopyImageper level from the storage image, whenever the image'sVersion()moved. This is the same refresh-on-reuse scheme the depth copy uses: no flush, no CPU compare, no upload.cachedTexturekeeps such a pending source and makes or reuses the block copy, in both the cached and the uncached path.Sources for the semantics:
src/amd/common/ac_surface.c(ac_compute_surface:blk_w/blk_h= 4 andbpe= 8/16 for compressed formats) and addrlib'sGfx10Libelement-based swizzle equations cover this. An uncompressed view with the same element size and the extent in blocks therefore addresses the same bytes.vkCmdCopyImagebetween size-compatible uncompressed and compressed formats. Theextentis given in texels of the source image (Vulkan spec, "Copying Data Between Images",VkImageCopy).Tested
System: Windows 11 (26200), RTX 5070, NVIDIA Vulkan 1.4, WinLibs GCC, Release,
BUILD_TESTING=ON, rebased onmain90c683946. The block-copy texture is aPerUseCopy::RefreshedOnReusecopy like the depth copy, so it goes throughIsDepthCopy/RefreshDepthCopyunchanged.agc_driver_bc_block_copy(new execution test): for BC7 (through32_32_32_32_UINT) and BC1 (through32_32_UINT), a compute pass stores blocks, the test samples the BC view while the results are pending, then stores and samples again.mainwithsampling the compressed view stored the pending blocks to guest memory, and passes with this change.Suite:
ctest -R "^agc"after the rebase: 447 tests, all pass.agc_driver_stencil_ref_exportis skipped, as onmain. The new test fails on thismaintoo.Minecraft Dungeons II (PPSA16064), title screen. This is not a clean-
mainA/B: the title does not reach its title screen on plainmainyet (it needs #425 and #3816). I tested onmaine7c70a2dfplus those PRs and the local patches the title needs, none of which touch this path. Same capture window (APS5_TRACE_SECONDS=30:10), two runs of each:Resources.CompleteThe three pages became block copies. Screenshots of the title render the same as before.
Not run: Linux, lavapipe, AMD.
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 kr4y4 on 2026-10-13T04:33:02Z.
An Intel run, a second driver for the bit-exact check, and the full suite.
Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head
126a1e413merged intomain495bf91a0, which passes 1023 of 1023 on both GPUs.agc_driver_bc_block_copypasses on both GPUs with--repeat until-fail:3and printsbc block copy tests passedon each. So on the Intel driver too, the BC7 and BC1 texels sampled from the copy equal the separate surface's snapshot sample, and the results stay pending.ctest --timeout 120 --parallel 4): 1024 of 1024 on both GPUs.Texture.hpp,Texture.cppandShaderResources.cppas onmain, it fails on both GPUs withBC7 through 32x4 uint blocks: sampling the compressed view stored the pending blocks to guest memory, as in the description.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-13T15:27:41Z.
Checked on Linux (RADV):
agc_driver_bc_block_copypasses, and fails withTexture.hpp/Texture.cpp/ShaderResources.cppreverted. The layout condition inCanBlockCopyFrom(same tile mode, XOR, element size, extent in blocks, whole-block mips) is conservative and everything else keeps the old path. Cross-checked with kr4y4's Intel and NVIDIA runs (full suite green). Merging once the Windows build is green.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T01:28:34Z.
agc_driver_bc_block_copyfails on NVIDIA on currentmain(cd90ca50b, RTX 4090, driver 610.57.04, Linux):BC7 through 32x4 uint blocks: sample of blocks stored again: thread 0 component 0 read 1064168942, expected 1058905502. CI's lavapipe passes it. Could you check whether the stored-again sample depends on how the device reads back the copied blocks?Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-14T02:26:29Z.
Independent reproduction on the same reported main commit
cd90ca50bec81619f9a3d0913bc4cd3ecf2ca49d, Linux Release, SPIRV-Tools ON, no production changes:agc_driver_bc_block_copy, 3 independent runs1002:13c0), RADV Mesa 25.2.8Pinned ICDs, explicit GPU selection,
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1, serial CTest, unchanged 30-second limit. NVIDIA fails at the third BC7 sample before the BC1 case is reached:I then changed only the temporary fixture to inspect the result:
Settle(device, texels, bytes)immediately after the third store still fails 3/3 on NVIDIA, with that same stale vector.Settleflushes pending storage, waits idle, and collects writes.13572440,00000000,13572440,00000000on both GPUs: the new First pattern is present in the backing bytes. NVIDIA nevertheless samples the Second pattern; RADV samples correctly.So this reproduces on another NVIDIA generation/driver, and the explicit-settle control does not point to incorrect first-block bytes from GPU writeback. The stale copied/sampled image or its reuse remains to be isolated; these checks do not prove a particular cache or synchronization fix. The original fixture was restored byte-for-byte and the borrowed isolated checkout restored/rebuilt to its prior head. No title run in this report.
Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-10-14T04:19:57Z.
@TideOPL
agc_driver_bc_block_copyfails on Linux with an NVIDIA GPU (Ubuntu 24.04, RTX 4070 Ti, driver 580.142), both at this PR's merge commitaf991ac40and on currentmain:sample of blocks stored againreads the previous copy's blocks. On that sample the build takes the record's texture throughfastTexture, which does not decline a copy refreshed on reuse, soRefreshDepthCopyis never called. #5654 has a one-line fix; with it the test passes 10 of 10.AI-assisted: yes