XG: CopyFromSubresource refuses a destination span it cannot write #3738
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3738"
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 ivall/xcl. Originally posted by Royalflamejlh on 2026-12-02T22:50:41Z.
Takes over #684 (its author has been inactive since 2026-11-24); keeps only its destination-span guard, since the ABI half landed in
adccb7d.The guard and its first tests are @JGonzalezRodriguez's, and the commit keeps him as its author; the writable check is the one @Marukooh proposed in #976. Thanks to both, and to everyone who tested #684.
CopyFromSubresourcewrites rows todstat the title's row and slice pitches without checking them. With a wrong pitch the rows land far past the destination and the process dies incopy_from(the first crash of #662, from the misread argument thatadccb7dfixed). With this change a row pitch under one row, a slice pitch under one slice (3D), or a span that is not writable memory returnsE_INVALIDARGand logs the call (8 at most), as #684 did.One change from #684: the span is checked with
dstorage::writable, notgpu::shader::readable. On today'smain,readableis wrong in both directions here: it refuses a destination in the title's lazy pages (mapped, committed on first use, which the copy itself would commit), and spans over 256 MiB; and it lets a committed read-only destination through, which then faults. Both cases fail underreadablein the tests below. That is #976's switch, so #976 has nothing left once this is in; #992 (the source check) can rebase onto it.Part of #662
What is in it
crates/xcl/src/hle/xg.rs: the span check incopy_from, aftercopy_args; testscopy_from_refuses_a_destination_span_it_cannot_writeandcopy_from_writes_a_padded_volume_into_lazy_pages.crates/xcl/src/hle/dstorage.rs:writableispub(super).copy_fromsignature, the doc-comment change and thexg_oracle.rschange (main'scopy_argstakes both forms), and its two round-trip tests (subresource_copies_take_both_argument_formsonmaincovers the 2D one; the 3D one is now the lazy-pages test).Tested
45a8d7b1bonmain078358a05.x86_64-pc-windows-gnu(debug), tests under Wine:cargo check --workspacewith and without--tests: no errors, no warnings in the two files.cargo test -p xcl --lib -- hle::xg::tests: 6 passed, 0 failed, 0 ignored.cargo test -p xcl --test xg_oracle: 6 passed, 0 failed, 12 ignored (XCL_SAMPLE_XGunset).copy_from_refuses_a_destination_span_it_cannot_writefails (row pitch under a row returnsS_OK). Withreadablein place ofwritable,copy_from_writes_a_padded_volume_into_lazy_pagesfails (the lazy destination refused) and the read-only case faults the test process.cargo test --workspace -- --test-threads=4: 3,008 passed, 0 failed, 52 ignored; 29SKIPPEDlines (22gpu_tests, 7 others),hle::xg::testsamong the passed.Regression run
RTX 2070 SUPER 8 GB (driver 621.01), Ryzen 7 5700X3D, Windows 11 Pro 26200, release builds by
scripts/smoke.ps1, the same retail title for 60 s each.main:this PR's head:
Not tested
xg_oracleagainst the console's library; a retail run that reaches a refused call (no run of #684 logged one).AI use
main, switched it towritable, wrote the tests, ran the builds and tests and wrote this description.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-02T22:53:28Z.
Review of
45a8d7b1(code reading only, not a merge-check; draft) · 1 nitIn short: The PR takes over #684's destination-span guard for
CopyFromSubresource. A row pitch under one row, a slice pitch under one slice (3D), or a destination span that is not writable memory now returnsE_INVALIDARGand is logged, at most 8 times. It checks the span withdstorage::writable, notgpu::shader::readableas #684 did. The guard and its arithmetic are right. Nothing blocks it; there is one test-hygiene nit.Nit
copy_from_writes_a_padded_volume_into_lazy_pagescallskernelx::lazy::mark(lazy)and thenVirtualFrees the reservation without unmarking it, soLAZYkeeps a stale entry. A laterlazy::ensureover that address in the same test process commits it. That includeswritablefrom another test, such as the 31 GB "rows past the allocation" span here. If the address is reused by another test's reservation, it gets committed under it. Unmark the page before freeing it, for example through a small#[cfg(test)]helper inlazy.rs, sinceunmarkispub(super).Checked and fine
m.heightrows ofrowbytes,row_pitchapart, so(m.height - 1) * row_pitch + row. 3D writesm.depthslices of those rows,slice_pitchapart. Theslice_pitch < rowscheck applies only whenm.depth > 1.u32pitch and at most 16K rows or slices, the products stay far belowusize::MAX, andwritableuseschecked_addfordst + span.writablecommits the destination's lazy pages first, as the copy itself would, then accepts the committed UMA window, sparse memory it knows, or regionsVirtualQueryreports committed and writable. That is why a lazy destination now passes and a read-only one is refused, both of whichreadablegot wrong.copy_args, so both argument forms are checked. The tests cover row pitch, a span past the allocation, read-only memory, slice pitch, and a padded volume into lazy pages compared row by row.writablebecomespub(super), and nothing else outsidexg.rschanges. #976 (the samewritableswitch) has nothing left once this lands, and #992 (the source check) can rebase onto it, as the description says.Written by Claude Code (Claude Opus 5.5) and posted by Foniass without a human check of each point.
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.