Card memory the CPU maps: windows, sends and scratch (VICTORY_WINDOWS_BAR_MB, VICTORY_SEND_BAR, VICTORY_SCRATCH_BAR); the card's own stamps (VICTORY_CARD_SPANS)
GPU_UPLOAD heaps, all off by default. Replayed yard frame (capture play-1125-0127): 36.3 ms; windows in the card's memory 31.9, sends 32.7. Replay: --pace, --breadcrumbs, copies counted by the memory they cross. VICTORY_GPU_LOAD_MS: what the title's GPU timestamps show. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
0abcb9fd89
commit
26b15e8fe3
9 files changed
+549
-12
No files matched your search
@@ -1579,6 +1579,15 @@ impl<T> Spare<T> {
|
||||
/// Scratch chunks no list holds.
|
||||
static SPARE: Mutex<Spare<Chunk>> = Mutex::new(Spare::new());
|
||||
|
||||
/// Whether lists' scratch memory (constants and tables, which shaders read)
|
||||
/// lies in the card's memory, written by the CPU through the bus
|
||||
/// (`VICTORY_SCRATCH_BAR=1`; the default is upload memory, which the card
|
||||
/// reads through it).
|
||||
fn scratch_on_card() -> bool {
|
||||
static ON: OnceLock<bool> = OnceLock::new();
|
||||
*ON.get_or_init(|| std::env::var_os("VICTORY_SCRATCH_BAR").is_some_and(|v| v == "1"))
|
||||
}
|
||||
|
||||
/// A scratch chunk of `size` bytes: one kept ([`SPARE`]) or a new one.
|
||||
fn take_chunk(host: &Host, size: u64) -> Option<Chunk> {
|
||||
if scratch_pool()
|
||||
@@ -1589,7 +1598,11 @@ fn take_chunk(host: &Host, size: u64) -> Option<Chunk> {
|
||||
ALIVE[5].fetch_add(1, Ordering::Relaxed);
|
||||
return Some(chunk);
|
||||
}
|
||||
let (buffer, data) = host.upload_buffer(size)?;
|
||||
let mapped = if scratch_on_card() { host.mapped_card_buffer(size, false) } else { None };
|
||||
let (buffer, data) = match mapped {
|
||||
Some(made) => made,
|
||||
None => host.upload_buffer(size)?,
|
||||
};
|
||||
name(&buffer, || "list scratch".into());
|
||||
ALIVE[1].fetch_add(1, Ordering::Relaxed);
|
||||
ALIVE[2].fetch_add(size, Ordering::Relaxed);
|
||||
@@ -3157,6 +3170,8 @@ fn late_line(frames: f64) {
|
||||
mod card_steps;
|
||||
mod place;
|
||||
mod send;
|
||||
#[cfg(feature = "diagnostics")]
|
||||
pub(crate) mod spans;
|
||||
mod torn;
|
||||
pub(crate) mod upcheck;
|
||||
|
||||
@@ -5005,6 +5020,11 @@ impl Host {
|
||||
let prepared = std::time::Instant::now();
|
||||
if late {
|
||||
*submitted += 1;
|
||||
#[cfg(feature = "diagnostics")]
|
||||
if let Some([front, behind]) = self.span_lists() {
|
||||
lists.insert(0, Some(front));
|
||||
lists.push(Some(behind));
|
||||
}
|
||||
// SAFETY: closed lists; the fence is ours.
|
||||
let signalled = unsafe {
|
||||
self.queue.ExecuteCommandLists(&lists);
|
||||
@@ -7318,6 +7338,8 @@ impl Meter {
|
||||
crate::descriptor::sync_line(frames);
|
||||
late_line(frames);
|
||||
card_clock_line(frames, ms);
|
||||
#[cfg(feature = "diagnostics")]
|
||||
spans::line(frames);
|
||||
crate::shadow::back_line(frames);
|
||||
#[cfg(feature = "diagnostics")]
|
||||
split_line(frames);
|
||||
@@ -7891,6 +7913,87 @@ impl Host {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether buffers can lie in the card's memory and be mapped by the CPU
|
||||
/// (`D3D12_HEAP_TYPE_GPU_UPLOAD`: a resizable BAR, and a system and driver
|
||||
/// that offer it); logged once.
|
||||
pub(crate) fn mapped_card_memory(&self) -> bool {
|
||||
static THERE: OnceLock<bool> = OnceLock::new();
|
||||
*THERE.get_or_init(|| {
|
||||
let mut options = D3D12_FEATURE_DATA_D3D12_OPTIONS16::default();
|
||||
// SAFETY: writes `options` of the given size.
|
||||
let ok = unsafe {
|
||||
self.device
|
||||
.CheckFeatureSupport(
|
||||
D3D12_FEATURE_D3D12_OPTIONS16,
|
||||
(&raw mut options).cast(),
|
||||
size_of_val(&options) as u32,
|
||||
)
|
||||
.is_ok()
|
||||
};
|
||||
let supported = ok && options.GPUUploadHeapSupported.as_bool();
|
||||
tracing::info!(supported, "card memory the CPU maps");
|
||||
supported
|
||||
})
|
||||
}
|
||||
|
||||
/// A buffer in the card's own memory that the CPU maps, shaders read and
|
||||
/// (with `written`) may write. The CPU should only write it: a read of the
|
||||
/// mapping crosses the bus a few bytes at a time.
|
||||
pub(crate) fn mapped_card_buffer(&self, size: u64, written: bool) -> Option<(ID3D12Resource, *mut u8)> {
|
||||
if !self.mapped_card_memory() {
|
||||
return None;
|
||||
}
|
||||
MADE[4].fetch_add(1, Ordering::Relaxed);
|
||||
MADE[5].fetch_add(size, Ordering::Relaxed);
|
||||
let heap = D3D12_HEAP_PROPERTIES {
|
||||
Type: D3D12_HEAP_TYPE_GPU_UPLOAD,
|
||||
..Default::default()
|
||||
};
|
||||
let desc = D3D12_RESOURCE_DESC {
|
||||
Dimension: D3D12_RESOURCE_DIMENSION_BUFFER,
|
||||
Width: size.max(1),
|
||||
Height: 1,
|
||||
DepthOrArraySize: 1,
|
||||
MipLevels: 1,
|
||||
SampleDesc: DXGI_SAMPLE_DESC {
|
||||
Count: 1,
|
||||
Quality: 0,
|
||||
},
|
||||
Layout: D3D12_TEXTURE_LAYOUT_ROW_MAJOR,
|
||||
Flags: if written {
|
||||
D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS
|
||||
} else {
|
||||
D3D12_RESOURCE_FLAG_NONE
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
let mut buffer: Option<ID3D12Resource> = None;
|
||||
let mut data = std::ptr::null_mut();
|
||||
// SAFETY: plain creation and mapping of a CPU-visible buffer.
|
||||
let made = unsafe {
|
||||
self.device
|
||||
.CreateCommittedResource(
|
||||
&heap,
|
||||
D3D12_HEAP_FLAG_NONE,
|
||||
&desc,
|
||||
D3D12_RESOURCE_STATE_COMMON,
|
||||
None,
|
||||
&mut buffer,
|
||||
)
|
||||
.and_then(|()| {
|
||||
let b = buffer.as_ref().ok_or_else(windows::core::Error::empty)?;
|
||||
b.Map(0, None, Some(&mut data))
|
||||
})
|
||||
};
|
||||
match made {
|
||||
Ok(()) => Some((buffer?, data.cast())),
|
||||
Err(e) => {
|
||||
tracing::warn!(error = %e, size, "no buffer in card memory the CPU maps");
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A device-local buffer shaders may write (unordered access) and indirect
|
||||
/// execution may read, starting in the common state.
|
||||
pub(crate) fn uav_buffer(&self, size: u64) -> Option<ID3D12Resource> {
|
||||
|
||||
Reference in new issue
Block a user