A copy's buffer is asked for its bytes when they are first needed (copies of tests have none)
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
e7c7210657
commit
bfe6e4a73c
1 file changed
+5
-6
@@ -26,8 +26,8 @@ use crate::watch::PAGE;
|
|||||||
|
|
||||||
/// A title buffer's host copy.
|
/// A title buffer's host copy.
|
||||||
pub(crate) struct Shadow {
|
pub(crate) struct Shadow {
|
||||||
/// The bytes of `buffer`.
|
/// The bytes of `buffer`, once asked.
|
||||||
width: u64,
|
width: std::sync::OnceLock<u64>,
|
||||||
pub(crate) buffer: ID3D12Resource,
|
pub(crate) buffer: ID3D12Resource,
|
||||||
data: *mut u8,
|
data: *mut u8,
|
||||||
gpu: u64,
|
gpu: u64,
|
||||||
@@ -2745,17 +2745,16 @@ impl Shadow {
|
|||||||
|
|
||||||
/// The bytes of the host buffer.
|
/// The bytes of the host buffer.
|
||||||
pub(crate) fn width(&self) -> u64 {
|
pub(crate) fn width(&self) -> u64 {
|
||||||
self.width
|
// SAFETY: a live buffer.
|
||||||
|
*self.width.get_or_init(|| unsafe { self.buffer.GetDesc() }.Width)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn new(buffer: ID3D12Resource, data: *mut u8, gpu: u64, start: u64, len: u64) -> Shadow {
|
fn new(buffer: ID3D12Resource, data: *mut u8, gpu: u64, start: u64, len: u64) -> Shadow {
|
||||||
// SAFETY: a live buffer.
|
|
||||||
let width = unsafe { buffer.GetDesc() }.Width;
|
|
||||||
let pages = (start + len).div_ceil(PAGE as u64) - start / PAGE as u64;
|
let pages = (start + len).div_ceil(PAGE as u64) - start / PAGE as u64;
|
||||||
LIVE[0].fetch_add(1, Ordering::Relaxed);
|
LIVE[0].fetch_add(1, Ordering::Relaxed);
|
||||||
LIVE[1].fetch_add(len, Ordering::Relaxed);
|
LIVE[1].fetch_add(len, Ordering::Relaxed);
|
||||||
Shadow {
|
Shadow {
|
||||||
width,
|
width: Default::default(),
|
||||||
buffer,
|
buffer,
|
||||||
data,
|
data,
|
||||||
gpu,
|
gpu,
|
||||||
|
|||||||
Reference in new issue
Block a user