gpu: add 6GB VRAM mip dropping, 16GB RAM pool caps/OOM recovery, and clear_air +inf clamp

This commit is contained in:
theme613 committed 2026-11-28 13:19:56 +08:00
1 parent 63b902fe17
commit c9067a7d3f
8 files changed
+366 -51

No files matched your search

+57 -10
View File
@@ -456,6 +456,11 @@ fn sweep() {
if crate::residency::pressured() {
trim_spare_chunks();
}
if crate::residency::critical_commit() {
send::trim_spare();
crate::shadow::trim_snapshot_pool();
crate::list::trim_idle();
}
crate::pool::room(host().and_then(|h| h.video_memory()));
crate::pipeline::trim_library();
crate::shadow::let_go_idle();
@@ -4547,9 +4552,9 @@ impl Host {
/// An allocator and a closed list for a prelude.
fn make_prelude(&self) -> Option<Prelude> {
// SAFETY: plain object creation.
let made: windows::core::Result<Prelude> = unsafe {
(|| {
let create = || -> windows::core::Result<Prelude> {
// SAFETY: plain object creation.
unsafe {
let allocator: ID3D12CommandAllocator =
self.device.CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT)?;
let list: ID3D12GraphicsCommandList =
@@ -4557,8 +4562,18 @@ impl Host {
.CreateCommandList(0, D3D12_COMMAND_LIST_TYPE_DIRECT, &allocator, None)?;
list.Close()?;
Ok((allocator, list))
})()
}
};
let mut made = create();
if let Err(ref e) = made
&& e.code() == windows::Win32::Foundation::E_OUTOFMEMORY
{
crate::residency::allocation_error(e);
send::trim_spare();
crate::shadow::trim_snapshot_pool();
crate::list::trim_idle();
made = create();
}
LISTS[1].fetch_add(1, Ordering::Relaxed);
match made {
Ok(prelude) => {
@@ -4566,6 +4581,7 @@ impl Host {
Some(prelude)
}
Err(e) => {
crate::residency::allocation_error(&e);
tracing::warn!(error = %e, "no host list for a prelude");
None
}
@@ -7450,9 +7466,7 @@ impl HostList {
// skornuta/victory-memory-stack 57fb136, GPL-3.0.)
let fresh = allocator_refresh(allocator, made, &ALLOCATOR_TRIMS[1]);
let (allocator, list) = (&*allocator, &*list);
// SAFETY: the prelude is not executing (every submission is waited
// for); the textures are live. A fresh allocator is new and empty.
let recorded = unsafe {
let record = || unsafe {
(if fresh { Ok(()) } else { allocator.Reset() }).and_then(|()| {
list.Reset(allocator, None)?;
if !aliasing.is_empty() {
@@ -7473,7 +7487,18 @@ impl HostList {
list.Close()
})
};
let mut recorded = record();
if let Err(ref e) = recorded
&& e.code() == windows::Win32::Foundation::E_OUTOFMEMORY
{
crate::residency::allocation_error(e);
send::trim_spare();
crate::shadow::trim_snapshot_pool();
crate::list::trim_idle();
recorded = record();
}
if let Err(e) = recorded {
crate::residency::allocation_error(&e);
fail(format_args!("a host state prelude did not record ({e})"));
}
list.cast().ok()
@@ -7697,8 +7722,13 @@ impl HostList {
///
/// shortcut: one buffer per copy; pool them once uploads are frequent.
pub(crate) fn upload(&self, host: &Host, size: u64) -> Option<(ID3D12Resource, *mut u8)> {
// With [`card_steps`] the card may be the one that fills it.
let (buffer, data) = if card_steps::stage() > 1 { host.shared_buffer(size)? } else { host.upload_buffer(size)? };
// With [`card_steps`] the card may be the one that fills it; skip the
// copy-queue `mapped()` fence stall since direct-queue submission runs later.
let (buffer, data) = if card_steps::stage() > 1 {
host.shared_buffer_for_list(size)?
} else {
host.upload_buffer(size)?
};
name(&buffer, || format!("list upload {size:#x}"));
self.deferred().hold_upload(buffer.clone(), size);
Some((buffer, data))
@@ -10851,6 +10881,21 @@ impl Host {
/// [`Host::shared_buffer`], made now.
pub(crate) fn shared_buffer_now(&self, size: u64) -> Option<(ID3D12Resource, *mut u8)> {
self.shared_buffer_impl(size, true)
}
/// [`Host::shared_buffer`] for a command list upload without blocking on the
/// copy-queue `mapped()` fence wait.
pub(crate) fn shared_buffer_for_list(&self, size: u64) -> Option<(ID3D12Resource, *mut u8)> {
if size == crate::ahead::SIZE
&& let Some(made) = crate::ahead::shared()
{
return Some(made);
}
self.shared_buffer_impl(size, false)
}
fn shared_buffer_impl(&self, size: u64, wait_mapped: bool) -> Option<(ID3D12Resource, *mut u8)> {
MADE[2].fetch_add(1, Ordering::Relaxed);
MADE[3].fetch_add(size, Ordering::Relaxed);
let heap = D3D12_HEAP_PROPERTIES {
@@ -10889,7 +10934,9 @@ impl Host {
.and_then(|()| {
let b = buffer.as_ref().ok_or_else(windows::core::Error::empty)?;
resident(&self.device, b)?;
mapped(&self.device)?;
if wait_mapped {
mapped(&self.device)?;
}
b.Map(0, None, Some(&mut data))
})
};