fix(agc): probe sparse dma-buf binds before binding imports sparsely #21649
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21649"
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 GiannisG1 on 2026-11-16T14:07:42Z.
What
On lavapipe before Mesa 26.0.0, a GPU write through a sparse buffer bound to dma-buf memory never reaches that memory.
agc_driver_scattered_runsfails on llvmpipe (Mesa 25.2.8) withscattered import: the second run's GPU write did not land at its scattered file offset. A lavapipe run on #16831 listsscattered_runsamong the tests that already fail onmain194eab3677 (issuecomment-6715872289).The cause is in Mesa 25.x
src/gallium/drivers/llvmpipe/lp_texture.c:llvmpipe_import_memory_fdkeeps an imported dma-buf inalloc->dmabuf_fdand never setsalloc->fd, whichCALLOC_STRUCTleaves at 0.llvmpipe_resource_bind_backingcallsmmap(..., MAP_SHARED | MAP_FIXED, mem->fd, ...)with that descriptor 0 and ignores the result.So the buffer keeps its own anonymous pages, and GPU writes through it never reach the shared memory. Mesa fixed this in 67d54fd5 ("llvmpipe: support sparse resource with LLVMPIPE_MEMORY_FD_TYPE_DMABUF", MR !38074), first released in 26.0.0. Ubuntu 24.04 ships 25.2.8.
On such a driver,
createSparseDmaBufImportloses data without any error. Since #2434, llvmpipe imports shared memory through dma-buf, not host pointers. So when/dev/udmabufis accessible, every shared range of several runs, or across a 64 MiB chunk, that is imported under the GPU lock goes this way. lavapipe has no second queue family, so imports made at map time without the lock already fall back.Since 11-17
main's self-hosted Linux runners open/dev/udmabuf, andagc_driver_scattered_runssplits the same way there: it fails with "the second run's GPU write did not land at its scattered file offset" on the Mesa 25.2.8 runners and passes on the Mesa 26.0.8 ones (EagleBearerYS: https://github.com/boykopovar/AnyPS5/pull/21649#issuecomment-6945095444).This PR measures that instead of trusting it. It does not gate on a driver ID: like the write-watch import probes (
decideImportWatch) and the float-controls probes, it measures the behaviour. A version gate would also miss a lavapipe built from an older branch with the fix backported.ProbeSparseDmaBufImportmakes a 64 KiB memfd and imports it as a udmabuf. It binds the dma-buf to a sparse buffer on the queue the sparse imports use. It then copies 4 bytes inside the buffer on the main queue and reads the memfd back.PrepareImportWatch), or at the first import for a context that was not set up there.createBackingImportskips the sparse path. The range then takes the paths it already had: one udmabuf of the list, or, when udmabuf refuses it, a host-pointer import or a copy.[gpu] GPU copies through a sparse buffer bound to dma-buf memory reach that memory: yes|no (…)reports the result.APS5_SPARSE_DMA_BUF_IMPORTS=probe|on|offoverrides it (docs/dev/ENVIRONMENT.md). The mock-device testagc_host_import_sparsesetson, since itsvkCmdCopyBufferdoes nothing.Tests:
agc_driver_scattered_runsnow checks that the GPU write lands at its scattered file offset whichever import serves the range. Only then does it skip when no run list was bound. It names the new reason ("the device does not keep GPU copies through a sparse buffer in the dma-buf memory bound to it"), separately from the existing host-pointer one.agc_driver_selected_sparse_dma_buf_failureskips on a device that does not select sparse dma-buf imports. It decides that before swapping in its refusingvkCreateBuffer.Tested
Rebased 2026-11-21 after #24555. #24555 widened the sparse path: a run list now takes it at any size, and so does a single run above 32 MiB that is not inside one chunk. Both changes are inside
createSparseDmaBufImport, which this PR's probe gates at its call site, so the probe still decides every sparse import. #24555's new chunk windows only change which single-run ranges fit one chunk import. On Mesa 25.2.8 llvmpipe, more ranges than this test now lose their GPU writes without this PR (issue #24834 tracksmain's Linux runners that failagc_driver_scattered_runs). The two edits of the "Sparse dma-buf imports" debt bullet are merged into one:main's text plus this PR's probe clause. Head50119d8d84onmainccc2f49630, which merges cleanly withb23daffaf9.git range-diffwith69ead9933ashows the same code; only context lines moved, wheremainadded a host-pointer fallback around the same call. On that head, the same machine and setup:agc_driver_dma_buf_chunk_window,mainccc2f49630against this PR, all four devices.mainfailsagc_driver_scattered_runson llvmpipe 25.2.8 (the second run's GPU write did not land at its scattered file offset). This PR passes or skips all 15 on every device, 3 runs plain and 1 with the Khronos layer 1.4.363.1, which was inserted in 14 of 15 and printed noVUID-,SYNC-HAZARD-orUNASSIGNED-message.check_skips.pyaccepts every skip.tools/suite.py -j2):check_conventions.py(only the existing length warning on the debt entry),check_main_sync.py,check_compile.py(4 translation units),check_test_registration.pyanddebt_fold.py --checkare clean.pr_overlap.py --branch: no overlap among the pull requests it could compare. 86 that share files conflict withmain. In their diffs, no line this PR changes is changed. #12840, #15295 and #15296 insert next to the same generictry {lines, #4448 next to the import-watch declarations, and #23244 next to anENVIRONMENT.mdtable row.Rebased 2026-11-20. #23272 was reverted (#24052), so this PR is back to its first commit, now on
main223b1645d2(head69ead9933a;git range-diffwith the first head: the same patch). On that head, the same machine and setup:main223b1645d2against this PR, all four devices:mainfailsagc_driver_scattered_runson llvmpipe 25.2.8, the rest as in the table below. This PR passes or skips all 14 on every device, 3 runs plain and 1 with the Khronos layer 1.4.363.1 (inserted in 13 of 14, noVUID-,SYNC-HAZARD-orUNASSIGNED-message);check_skips.pyaccepts every skip.main's Linux job runs llvmpipe from Ubuntu's Mesa 25.2.8 and failsagc_driver_scattered_runswith the message below (run 44639208734); with this PR it skips there.main0626a8334f's own run on this machine. llvmpipe 1456, 2 failed:agc_driver_image_gather_lod(Mesa 25.2.8's size query, #24100) andagc_driver_image_table_packed_guards(#21255), both also failing in that job.check_conventions.py(only the existing length warning on the debt entry),check_main_sync.py(merges cleanly with currentmain; #22072, #23770 and #23812 changedGuestBufferMemory.cppsince this base, in other lines),check_compile.py,debt_fold.py --checkandgit diff --checkare clean.pr_overlap.py --branch: no overlap among the pull requests it could compare. 29 that share files conflict withmain; in their diffs no line this PR changes is changed. #23613 changes the lines around thecreateSharedBackingImportcall this PR extends, not the call.The results below are from the first head, on
maine4caa07950.Linux Mint 22.3, kernel 7.0.0-38, GCC 13.3.0, Release,
BUILD_TESTING=ON, head onmaine4caa07950, under Xvfb, with/dev/udmabufaccess. To check the probe on a driver with the fix, lavapipe from Mesa 26.0.8 was built from the release tarball (sha256 as in the release notes) and selected withVK_DRIVER_FILES.Probe line at set-up:
no (0x0c0ffee5 copied, 0x0b5e55ed in the memory after it)yes (0x0c0ffee5 copied, 0x0c0ffee5 in the memory after it)Focused set, 14 tests (
agc_driver_scattered_runs,agc_driver_selected_sparse_dma_buf_failure,agc_host_import_sparse,agc_driver_sparse_dma_buf_import,agc_sparse_run_import*,agc_driver_host_import_at_map,agc_driver_host_import_dma_buf_watch,agc_driver_selected_dma_buf_list_refusal*,agc_driver_linear_target_dma_buf_*),mainagainst this PR:mainagc_driver_scattered_runsfails ("the second run's GPU write did not land at its scattered file offset");agc_driver_selected_sparse_dma_buf_failurepasses (its refusal is injected into a path that loses writes)agc_driver_scattered_runs: the range is imported through a host pointer after udmabuf refuses the list, the GPU write lands at the scattered offset, then the test skips with the new reason;agc_driver_selected_sparse_dma_buf_failureskips; the other 12 unchangedcheck_skips.pyaccepts every skip.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1,ctest -V -j1, on the focused set,main0766863ef6against this PR's commit on it (it merges cleanly), on all four devices.tools/suite.py: every test once, GPU tests on all three devices) on this PR, compared withmaine4caa07950's own full run on the same machine. No new failure caused by this PR:check_conventions.py(its only finding is the existing length warning on the debt entry, already over the limit onmain),check_test_registration.py,check_main_sync.py,check_compile.pyandgit diff --checkare clean.pr_overlap.py --branch: no overlap among the pull requests it could compare. 101 conflict withmainand could not be compared. In their diffs, no line this PR changes is changed. #4448 changesSetImportWatch's signature next to the newSparseDmaBufImportSelected, which is a different function.Update 2026-11-25 (head
78280d30c9): rebased ontomaind237f5d065. The one conflict was inHostImportSparseDmaBuf.cpp:main'sretireSnapshot ? "watch" : "unwatch"is kept, with this PR'sAPS5_SPARSE_DMA_BUF_IMPORTSline after it. On this head:mainor here.maind237f5d065run, except llvmpipe'sagc_driver_scattered_runs, which fails onmainand skips here (Mesa 25.2.8, #24834).Update 2026-12-03 (head
f11b9de910): rebased ontomain10c3156e1c; it merges cleanly withmainac7ee4bb72. The one conflict was inGuestBufferMemory.cpp: #26652 added the Windows-onlysettlesPrivateImportswhere this PR adds the non-WindowssparseDmaBufImports, and both are kept. On this head:mainor here.main10c3156e1crun on the GTX 1050 Ti and llvmpipe, except llvmpipe'sagc_driver_scattered_runs, which fails onmainand skips here, as before. The HD 630 shard of thatmainrun is not usable, because the device was missing from Vulkan during it. This PR's 14 HD 630 failures are the 14 thatmain4cb7752e50has on this machine.check_conventions.pyhas only the existing length warning).pr_overlap.py --branch: of the 222 pull requests it compared, only #28411 overlaps. It adds a macOS retry right after thecreateImportcall this PR extends, and its retry callscreateImportwithout the newsparseDmaBufargument. Whichever lands second passes it there. The 91 it could not compare conflict withmain.Update 2026-12-03 (head
a53f368386): CodeRabbit's two findings. The probe's copy target is half of the buffer's own size, not half of its memory requirement, which a driver may report larger than the 64 KiB buffer. The debt entry change moved into the fragmentdocs/dev/debt/changes/fix-agc-sparse-dma-buf-probe.md. On this head, the focused set passes 3/3 on all four devices with no validation-layer messages, the checkers anddebt_fold.py --checkare clean, and the split suite fails the same tests as atf11b9de910(GTX 1050 Ti: none).2869d2bc31only corrects the fragment's text (a run list takes the sparse path at any size), so nothing was rebuilt;debt_fold.py --checkandcheck_conventions.pypass.Update 2026-12-04 (head
6686cc3cf2): the verdict was cached byVkDevicehandle, so a device created later with a reused handle could have taken an earlier device's verdict (ligmaSec).PrepareImportWatch, which a device runs once at setup, now decides it again for every device; a live device keeps its verdict. New testagc_driver_sparse_dma_buf_probe_reset: it fails on lavapipe 26.0.8 with the previous code and passes now. It skips where no verdict of yes exists (llvmpipe 25.2.8, the GTX 1050 Ti and the HD 630). The focused set and the new test pass 3/3 on four devices, a validation-layer run logged nothing, the checkers are clean, and the split suite fails the same tests as ata53f368386.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)🤖 Generated with Claude Code
Summary by CodeRabbit
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T05:17:12Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the reviewed code provides a behavior probe for sparse dma-buf imports and avoids that path when the probe fails or reports lost writes.
What I ran
Reviewed head
e074c5e7a23a321dfe70927b450cd93d417976ee. I read the prepared description, commits, manifest, diff, all included changed files, and the relevant portions ofGuestBufferMemory.cppplus queue-sharing context inVulkanDevice.cppwas located but not read. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full
GuestBufferMemory.cppfile and the locatedVulkanDevice.cppqueue initialization were not read. The PR's build, test, validation-layer, and hardware results were not independently verified. The included changed files read wereGuestBufferMemory.hpp,HostImportSparseDmaBuf.cpp,LinearTargetImportCreation.cpp,ScatteredRuns.cpp,ENVIRONMENT.md, anddebt/libSceAgcDriver.md;GuestBufferMemory.cppwas read only in targeted ranges.files.jsonwas not available in the prepared bundle; the manifest marksGuestBufferMemory.cppas excluded fromfiles/because it is too large. No other exclusions are reported by the file listing.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-20T07:16:43Z.
Review: COMMENTED
Reviewed — comments
Material review context is incomplete because the prepared diff is available, but the reader did not expose the changed-file inventory or test outcomes needed to confirm the full change.
What I ran
69ead9933acd2b8a3f945f9acc99835de2d6f349.ProbeSparseDmaBufImportimplementation inGuestBufferMemory.cppthrough the pinned reader.Results
Findings
Blocking
None verified.
Non-blocking
None.
Not verified
GuestBufferMemory.cppas too large for the review folder. Although the probe implementation was read, I could not read the relevant import-selection/caller code at the pinned head: the reader returned no files for the requested repository paths.files.jsonwas not available in the review folder, so excluded-file details beyond the manifest were not confirmed.To get this to a good state
Nothing is required. Optional: make the changed-file inventory and caller/test context available to complete verification.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-21T08:22:38Z.
Review: COMMENTED
Reviewed — comments
The change appears internally consistent, but I could not run checks on the pinned head, so a formal approval is not justified.
What I ran
Read the prepared review bundle and changed source hunks at head
50119d8d84fbfcd936e3d2ef42193349461cb61fusingrepo_read.py. No commands or tests were run; the environment provides read-only access.Read:
description.md,commits.md,manifest.json,diff.patch; changed filesGuestBufferMemory.hpp,GuestBufferMemory.cpp(targeted ranges),HostImportSparseDmaBuf.cpp,LinearTargetImportCreation.cpp,ScatteredRuns.cpp,ENVIRONMENT.md, andlibSceAgcDriver.md.Excluded: no changed files were excluded by the review bundle; the full text of
GuestBufferMemory.cppwas too large for the bundle, so I read the relevant ranges through the reader.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author reports focused tests, broader suites and checkers passing on the PR head. I did not run or independently verify those results. Other code outside the changed files and targeted call paths was not reviewed.
To get this to a good state
Nothing is required. The reported test and checker results remain author supplied.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T22:56:10Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the inspected code supports the probe-based fallback, and the reported checks are author-supplied rather than run here.
What I ran
Reviewed head
78280d30c99d864e63f512df6e0fc48e9d1151fc. No commands or tests were run; I inspected the prepared diff and targeted code throughrepo_read.py.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
The full
GuestBufferMemory.cppwas not read; targeted ranges around the changed logic and probe were read throughrepo_read.py. All other changed files listed as included in the manifest were read at their changed lines. No tests, build, checker, or physical-console behavior were independently verified.files.jsonwas not available as a review document; the review-folder listing identifiedGuestBufferMemory.cppas excluded because it was too large.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T00:36:27Z.
Review: APPROVED
Reviewed — looks good
The probe gates sparse dma-buf imports on observed copy behavior, and I found no blocking defect in the changed code.
What I ran
Reviewed head
f11b9de91004c32a1556da48c5a730663069b3ecusing the prepared diff and pinned reader for the changed hunks and relevant helper and caller context. No executable checks or tests were run. All seven files listed underreviewedinfiles.jsonwere inspected;files.jsonlists no excluded files.Results
Negative control
Not run; no test was modified for a negative control.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
Runtime behavior on the reported GPUs and the author-reported test results were not independently reproduced. Unchanged portions of the large
GuestBufferMemory.cppfile were not read.To get this to a good state
Nothing required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T00:40:05Z.
Review: COMMENTED
Actionable comments
18c4d76e-969c-483d-8a56-c18827fd36b0Reviewing files that changed from the base of the PR and between
ac7ee4bb72andf11b9de910.core/libs/prx/libSceAgcDriver/Graphics/include/GuestBufferMemory.hppcore/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/HostImportSparseDmaBuf.cppcore/libs/prx/libSceAgcDriver/tests/execution/LinearTargetImportCreation.cppcore/libs/prx/libSceAgcDriver/tests/execution/ScatteredRuns.cppdocs/dev/ENVIRONMENT.mddocs/dev/debt/libSceAgcDriver.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T05:20:15Z.
Review: APPROVED
Reviewed — looks good
The sparse dma-buf probe gates sparse imports on observed copy behavior, and the changed code supports the stated fallback; I found no blocking defect.
What I ran
Reviewed head
a53f368386b587ac130d4022900fac6c8f40fb9dagainst basemain; I did not run a merged-preview check. I inspected the prepared diff and files, and usedrepo_read.pyfor targeted source context.Results
Negative control
Not run; no tests were executed in this review.
Findings
Blocking
None.
Non-blocking
None.
Sources
The probe creates a sparse buffer, binds imported dma-buf memory, copies within the buffer, and checks the backing file before selecting the import path: GuestBufferMemory.cpp at the reviewed head. The scattered-runs test checks the GPU write before skipping when no run list was bound: ScatteredRuns.cpp at the reviewed head.
Not verified
Runtime behavior and the tests/checkers reported in the PR description were not independently run. I read the changed hunks and relevant source context for all seven reviewed paths.
GuestBufferMemory.cppwas too large for the prepared folder, so I read targeted ranges from the pinned head; no files were excluded by thefiles.jsonrules.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T05:27:54Z.
Review: COMMENTED
Actionable comments
c4c7f358-3cda-45b4-a676-a5f15a79904dReviewing files that changed from the base of the PR and between
f11b9de910anda53f368386.core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppdocs/dev/debt/changes/fix-agc-sparse-dma-buf-probe.mdIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-03T06:00:42Z.
Review: APPROVED
Reviewed — looks good
The probe gates sparse dma-buf imports on observed copy behavior and retains the existing fallback when the result is unsupported or unknown.
What I ran
Reviewed head
2869d2bc314b98b1d3d9cc63b58afa397bd45e35againstmainusing the prepared review materials andrepo_read.pyfor targeted source searches and ranges. No merged-preview check, test, build, or other programmatic check was run; no compiler or toolchain was invoked.Results
Negative control
No negative control was run because no test was run.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
The reported device runs, validation-layer checks, and repository checkers in the PR description were not independently rerun. Reviewed files:
GuestBufferMemory.hpp,GuestBufferMemory.cpp,HostImportSparseDmaBuf.cpp,LinearTargetImportCreation.cpp,ScatteredRuns.cpp,ENVIRONMENT.md, andfix-agc-sparse-dma-buf-probe.md.files.jsonlists no excluded paths. The fullGuestBufferMemory.cpptext was not in the review folder; its changed and relevant surrounding ranges were read withrepo_read.py.To get this to a good state
Nothing is required.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T17:48:02Z.
Review: COMMENTED
ClearHostImports(device)leavessparseDmaBufDeviceand the cached probe result intact. If Vulkan reuses theVkDevicehandle for a new logical device,sparseDmaBufImports()reuses the previous device's verdict without checking the new device's capabilities or probing it. A previoustruecan enable the sparse path on a device that has never passed the probe. Clear the matching cache entry duringClearHostImports, before the early return for a device that owns no host imports.On Linux lavapipe,
agc_driver_gcn_scalar_buffer_basepassed on9d362fb088and with2869d2bc31applied. Both logs showed insertion of Khronos validation 1.4.369 with no missing-layer warnings orVUID-errors. The three dma-buf and sparse-import fixtures skipped because this host has no/dev/udmabuf.AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by coderabbitai[bot] on 2026-12-03T23:24:10Z.
Review: COMMENTED
Actionable comments
586c7c1f-6f58-4266-bdd7-c33d522d58dfReviewing files that changed from the base of the PR and between
2869d2bc31and6686cc3cf2.core/libs/prx/libSceAgcDriver/Graphics/src/GuestBufferMemory.cppcore/libs/prx/libSceAgcDriver/tests/execution/SparseDmaBufProbeReset.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-12-04T00:28:56Z.
Review: APPROVED
Reviewed — looks good
The reviewed changes gate sparse dma-buf imports on a per-device probe, and the inspected code shows no blocking defect.
What I ran
Reviewed head
6686cc3cf26702679ce1e3d6aa8dcdc108bd9dfausingrepo_read.pyagainst the pinned source and the prepared diff. No build or runtime tests were run.Also read the changed ranges in the included files listed below. No compiler or test tool was invoked.
Results
Negative control
Not run independently. The description reports that the new reset test fails with the previous code and passes on this head.
Findings
Blocking
None.
Non-blocking
None.
Sources
Not verified
Runtime behavior, validation-layer output, build results, and the author-reported test runs were not independently verified. The full 9,567-line
GuestBufferMemory.cppwas not read; its changed ranges and relevant helpers and callers were inspected.files.jsonlists no excluded files. Reviewed files:GuestBufferMemory.hpp,GuestBufferMemory.cpp(changed ranges),HostImportSparseDmaBuf.cpp,LinearTargetImportCreation.cpp,ScatteredRuns.cpp,SparseDmaBufProbeReset.cpp,ENVIRONMENT.md, andfix-agc-sparse-dma-buf-probe.md.To get this to a good state
Nothing is required.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.