Repository navigation
Conversation
|
I confirmed a recoverable allocation failure in the current-head path. The pool stores readback buffers by exact size. When a request misses its size bucket and A bounded fix is to reclaim the idle readback buffers only for Local candidate verification
Candidate diffdiff --git a/crates/xcl/src/hle/d3d12x/title_textures.rs b/crates/xcl/src/hle/d3d12x/title_textures.rs
@@
fn take(&mut self, device: usize, queue_type: i32, size: u64) -> (Option<S>, Option<B>) {
@@
(set, buffer)
}
+
+ fn drain_buffers(&mut self) -> BTreeMap<(usize, u64), Vec<B>> {
+ self.buffer_bytes = 0;
+ std::mem::take(&mut self.buffers)
+ }
@@
static DOWNLOAD_POOL: Mutex<DownloadPool<(DownloadCommands, ID3D12Device), (ID3D12Resource, ID3D12Device)>> =
Mutex::new(DownloadPool::new());
+fn reclaim_idle_download_buffers<S, B>(pool: &Mutex<DownloadPool<S, B>>) {
+ let buffers = {
+ let mut pool = pool.lock().unwrap();
+ pool.drain_buffers()
+ };
+ drop(buffers);
+}
+
+fn retry_after_oom<T, E>(
+ mut create: impl FnMut() -> Result<T, E>,
+ is_oom: impl Fn(&E) -> bool,
+ reclaim: impl FnOnce(),
+) -> Result<T, E> {
+ match create() {
+ Err(error) if is_oom(&error) => {
+ reclaim();
+ create()
+ }
+ result => result,
+ }
+}
@@
Some((readback, _)) => readback,
None => {
let mut readback = None;
- dev.CreateCommittedResource(
- &D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_READBACK, ..Default::default() },
- D3D12_HEAP_FLAG_NONE,
- &D3D12_RESOURCE_DESC {
- Dimension: D3D12_RESOURCE_DIMENSION_BUFFER,
- Width: readback_size,
- Height: 1,
- DepthOrArraySize: 1,
- MipLevels: 1,
- SampleDesc: windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
- Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
- ..Default::default()
- },
- D3D12_RESOURCE_STATE_COPY_DEST,
- None,
- &mut readback,
- ).map_err(|e| e.to_string())?;
+ retry_after_oom(
+ || {
+ readback = None;
+ dev.CreateCommittedResource(
+ &D3D12_HEAP_PROPERTIES { Type: D3D12_HEAP_TYPE_READBACK, ..Default::default() },
+ D3D12_HEAP_FLAG_NONE,
+ &D3D12_RESOURCE_DESC {
+ Dimension: D3D12_RESOURCE_DIMENSION_BUFFER,
+ Width: readback_size,
+ Height: 1,
+ DepthOrArraySize: 1,
+ MipLevels: 1,
+ SampleDesc: windows::Win32::Graphics::Dxgi::Common::DXGI_SAMPLE_DESC { Count: 1, Quality: 0 },
+ Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
+ ..Default::default()
+ },
+ D3D12_RESOURCE_STATE_COPY_DEST,
+ None,
+ &mut readback,
+ )
+ },
+ |e| e.code() == windows::core::HRESULT(crate::util::E_OUTOFMEMORY),
+ || reclaim_idle_download_buffers(&DOWNLOAD_POOL),
+ ).map_err(|e| e.to_string())?;
readback.ok_or("no readback resource")?
}
@@
fn download_pool_caps_idle_sets_and_readback_bytes_independently() {
@@
assert_eq!(pool.buffer_bytes, 2 * size);
}
+ #[test]
+ fn download_pool_releases_other_size_buckets_before_retrying_out_of_memory() {
+ struct ReclaimProbe {
+ pool: std::sync::Weak<Mutex<DownloadPool<(), ReclaimProbe>>>,
+ released: Arc<AtomicBool>,
+ lock_free: Arc<AtomicBool>,
+ }
+ impl Drop for ReclaimProbe {
+ fn drop(&mut self) {
+ let lock_free = self.pool.upgrade().is_some_and(|pool| pool.try_lock().is_ok());
+ self.lock_free.store(lock_free, Ordering::SeqCst);
+ self.released.store(true, Ordering::SeqCst);
+ }
+ }
+
+ let pool: Arc<Mutex<DownloadPool<(), ReclaimProbe>>> = Arc::new(Mutex::new(DownloadPool::new()));
+ let released = Arc::new(AtomicBool::new(false));
+ let lock_free = Arc::new(AtomicBool::new(false));
+ let (set, buffer) = pool.lock().unwrap().put(
+ 1,
+ 0,
+ DOWNLOAD_POOL_BYTES,
+ None,
+ ReclaimProbe { pool: Arc::downgrade(&pool), released: Arc::clone(&released), lock_free: Arc::clone(&lock_free) },
+ );
+ assert!(set.is_none());
+ assert!(buffer.is_none());
+ let mut attempts = 0;
+ let result = retry_after_oom(
+ || {
+ attempts += 1;
+ if released.load(Ordering::SeqCst) { Ok(42) } else { Err(crate::util::E_OUTOFMEMORY) }
+ },
+ |error| *error == crate::util::E_OUTOFMEMORY,
+ || reclaim_idle_download_buffers(&pool),
+ );
+ assert_eq!(result, Ok(42));
+ assert_eq!(attempts, 2);
+ assert!(released.load(Ordering::SeqCst));
+ assert!(lock_free.load(Ordering::SeqCst), "COM buffers must be released after dropping the pool lock");
+ let pool = pool.lock().unwrap();
+ assert!(pool.buffers.is_empty());
+ assert_eq!(pool.buffer_bytes, 0);
+ }
+
+ #[test]
+ fn download_pool_does_not_reclaim_or_retry_non_out_of_memory_errors() {
+ let pool = Mutex::new(DownloadPool::<(), i32>::new());
+ assert_eq!(pool.lock().unwrap().put(1, 0, 0x10000, None, 7), (None, None));
+ let mut attempts = 0;
+ let mut reclaimed = false;
+ let result: Result<(), _> = retry_after_oom(
+ || {
+ attempts += 1;
+ Err(crate::util::E_INVALIDARG)
+ },
+ |error| *error == crate::util::E_OUTOFMEMORY,
+ || {
+ reclaimed = true;
+ reclaim_idle_download_buffers(&pool);
+ },
+ );
+ assert_eq!(result, Err(crate::util::E_INVALIDARG));
+ assert_eq!(attempts, 1);
+ assert!(!reclaimed);
+ assert_eq!(pool.lock().unwrap().buffer_bytes, 0x10000);
+ }
+
#[test]
fn download_plans_use_writer_capable_queue_types() {AI use: Codex (GPT-6.2 Sol) prepared and tested this candidate; GPT-6.2 Astra independently reviewed the reclaim, lock, and retry path. |
…wnloads Texture download preparation repeatedly creates the same D3D12 objects during streaming. Reuse each allocator, command list and private fence by device and queue type. Reuse committed readback buffers separately by device and 64 KiB-rounded size. Return objects only after their private fence confirms GPU completion. Cap idle storage at 1,024 command sets and 1 GiB of readback buffers. Each idle entry owns a device reference, so its raw device address cannot be reused while the entry is cached. Assisted-by: Codex (GPT-6)
3e00f2b to
58815f7
Compare
|
Thanks, that is a real hole: with up to 1 GiB idle in other size buckets, an allocation that would have succeeded before the pool can now fail and leave the texture's CPU copy stale. Taken in 58815f7 (folded into the PR's commit): on Rerun on the new head (RTX 5070 Ti): AI use: Claude Code, Claude Fable 5.2 wrote the change and this comment and ran the tests. |
|
@BBareth I tested completed texture-download reuse on my RTX 3080 10 GB (driver 616.92). I added one test fixture on top of After fence value 1, all 4,096 texels read back as An independent repeat in a fresh process reproduced both values and the same object reuse. Both runs passed with zero skips. This confirms the reused buffer returned fresh contents on this GPU. I also ran the CPU retry test with its stand-in allocator. A real D3D12 out-of-memory failure remains untested. I used Codex GPT-6.2 Sol to add the fixture and run the first test. Codex GPT-6.1 Terra independently reviewed and repeated it. Codex GPT-6.2 Astra drafted this comment. I reviewed and approved this comment before posting. |
|
merge-check claim |
|
merge-check
No difference above the run-to-run spread (the two A runs differ by 157 CPU-s). This covers the boot and the loading screen only, not the world, where the description measured the gain; I do not know how many texture downloads this phase makes, so it shows no cost, not the absence of the gain. |
|
Test report for the intermittent failure noted in the merge check above (
AI use: Claude Code, Claude Fable 5.2 ran the tests and wrote this report. |
|
merge-check AI-written and posted by Foniass without a human check of each point. |
|
No open or merged PR pools texture-download command objects or readback buffers (#3389, #3549, #3550 touch the same download path for other reasons). AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human. |
|
On the triage note above: the description now states the memory cost (idle readback buffers, up to the 1 GiB limit, stay committed for the life of the process and are released only when a new readback buffer runs out of memory). The two misplaced comments (above AI use: Claude Code, Claude Fable 5.2 wrote this comment. |
A GPU-written title texture is copied back into the title's memory through a readback buffer, a command allocator, a command list and a fence.
prepare_texture_downloadcreated all four for every download and released them when the download was published. A title that has hundreds of such downloads every second pays for that on the thread that signals its queues.This keeps the objects of a finished download and hands them to the next one.
What is in it
crates/xcl/src/hle/d3d12x/title_textures.rs:DownloadPoolholds idle command sets (allocator, list, fence) by device and list type, and idle readback buffers by device and size (sizes rounded up to 64 KiB). Limits: 1024 sets and 1 GiB of buffers; anything over is released as before. Idle objects stay for the life of the process, so the pool can hold up to 1 GiB of committed readback memory thatmainwould have released; it is given back only when a new readback buffer runs out of memory (below).Drop for PendingDownloadreturns the objects once the download's fence has completed; an incomplete one is released, not pooled. A pooled fence continues from its last value and is retired before the value could wrap.crates/xcl/src/hle/d3d12x/real.rs:create_download_fencemakes the pool's fences without entering them in the title fence registry (they are XCL's own, the title never sees them).E_OUTOFMEMORY), the pool's idle buffers are released, outside the pool's lock, and the allocation is tried once more (retry_after_reclaim). Other errors are returned as before. Raised in review by thehollowedone.download_pool_rounds_readback_sizes,download_pool_keys_sets_by_queue_type_and_buffers_by_size,download_pool_caps_idle_sets_and_readback_bytes_independently,download_pool_gives_up_its_idle_buffers_for_one_retry_after_out_of_memory.Tested
cargo build --workspace, thencargo test --workspace --no-fail-fast -- --test-threads=4: 2880 passed, 1 failed, 51 ignored, 28SKIPPEDlines.gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16("2D D16 resinfo clobbered v2/v3"). It fails the same way on main d52ff48 on this machine (cargo test -p xcl --lib gpu_direct_image_get_resinfo_d16: 0 passed, 1 failed) and is in code this change does not touch.Regression run
A second round: main 3034 frames, peak 28276 MB, device removals 0, crashes 0; this PR 3018 frames, peak 29705 MB, device removals 0, crashes 0. The main runs are from before this PR's last push (same main commit, same machine, about two hours earlier); the PR's runs are of its head. Each build had one warm-up run; the A button is pressed once at 70 s and was seen in all four runs.
Not tested
AI use
Codex (GPT-6.2-Sol) ported the change and wrote the tests from a brief; Claude Code (Claude Fable 5.2) wrote the original experiment, reviewed the diff, ran the suite and the smoke runs and wrote this description.
🤖 Generated with Claude Code