Title buffer copies stand where the list has them (VICTORY_COPIES_IN_PLACE)
On by default. They were all done on the CPU when their submission was prepared, ahead of its first draw: of copy, draw, copy, draw both draws read the second, and a source a shader writes earlier in the submission was read as it was before. The list copies now, in the destination's host copy, out of the source's host copy where shaders write it, else out of upload memory filled at submission; copies into textures take what shaders wrote too. Title memory and the reference of the host copy take the bytes at submission as before, so the landing finds only what the card made of them. VICTORY_WINDOWS_OWN=1 (off): windows have two sides as well. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
193f50fe5a
commit
ebd9d33b72
7 files changed
+738
-23
No files matched your search
@@ -194,6 +194,8 @@ enum Does {
|
||||
Read { from: usize, to: usize, asked: bool },
|
||||
/// A refresh of a host copy (named by its address).
|
||||
Refresh { shadow: usize, from: usize, to: usize },
|
||||
/// A copy that its list does on the card ([`place`]).
|
||||
Placed { dst: usize, src: usize, len: usize },
|
||||
/// Anything, anywhere.
|
||||
Run,
|
||||
}
|
||||
@@ -271,6 +273,15 @@ fn plan(does: &[Does], stage: u32) -> Result<Vec<(usize, u32)>, &'static str> {
|
||||
}
|
||||
}
|
||||
}
|
||||
// A copy at its place in a list comes after what is done in front of all
|
||||
// of them.
|
||||
for d in does {
|
||||
if let Does::Placed { dst, src, len } = *d
|
||||
&& (touched(&read, (dst, dst + len)) || touched(&written, (dst, dst + len)) || touched(&written, (src, src + len)))
|
||||
{
|
||||
return Err("a copy at its place in a list writes what it reads, or reads or writes what it writes");
|
||||
}
|
||||
}
|
||||
let order: Vec<usize> = (0..does.len()).filter(|&i| taken[i]).collect();
|
||||
// What stays on the CPU and reads what an earlier taken copy writes
|
||||
// would read it too early.
|
||||
@@ -572,6 +583,7 @@ impl Host {
|
||||
to: *at + *len,
|
||||
},
|
||||
Step::Run(_) => Does::Run,
|
||||
Step::Placed(p) => Does::Placed { dst: p.dst, src: p.src, len: p.len },
|
||||
Step::GpuWrite(..) | Step::Host(..) => continue,
|
||||
});
|
||||
steps.push((std::ptr::from_ref::<HostList>(list) as usize, i));
|
||||
|
||||
@@ -0,0 +1,320 @@
|
||||
//! The title's buffer copies, done on the card at their place in the list
|
||||
//! (`VICTORY_COPIES_IN_PLACE`, on by default; `0`: all at submission, on the
|
||||
//! CPU, as before).
|
||||
//!
|
||||
//! A buffer copy was done in title memory when its list was submitted, before
|
||||
//! any draw of the submission ran, and the host copies refreshed after it.
|
||||
//! That is another order than the list's: draws ahead of the copy read what
|
||||
//! it put; of two copies to the same bytes with a draw behind each, both
|
||||
//! draws read the second; a source that a dispatch of the same submission
|
||||
//! writes first was read as it was before it; and a destination the
|
||||
//! submissions in the air still read changed under them (where its host copy
|
||||
//! has one side only, `crate::shadow::card_all`).
|
||||
//!
|
||||
//! Now the list copies, in the destination's host copy: out of the source's
|
||||
//! host copy where shaders write that one, else out of upload memory of the
|
||||
//! list that takes the source's bytes when the list is submitted (a source
|
||||
//! shaders never wrote is the title's CPU's, or a copy's put there earlier in
|
||||
//! the submission). What is written there is a shader's write from then on:
|
||||
//! the bytes are declared, and what the card made of them is put into title
|
||||
//! memory before the title is told of the submission.
|
||||
//!
|
||||
//! Title memory takes the copy at submission as well, as it did: fills of
|
||||
//! upload memory, textures and host copies that lie over the same bytes read
|
||||
//! it there. The reference of the destination's host copy takes the same
|
||||
//! bytes ([`Shadow::placed_copy`]), so what the landing finds is what the card
|
||||
//! made of them afterwards (a counter copied to zero and counted up; a source
|
||||
//! that a shader wrote in between), and nothing is sent up over it. Where
|
||||
//! flights in the air may write the source or the destination this is left to
|
||||
//! the landing: what they wrote is not in title memory yet, and what they
|
||||
//! will put there must not stand over this copy's bytes. If a step of the
|
||||
//! submission reads the destination on the CPU, it waits for them instead
|
||||
//! ([`Placed::waits`]).
|
||||
//!
|
||||
//! Copies to memory that has no host copy yet are done as before: nothing on
|
||||
//! the card has read or written it. So are those of more than 8 MiB out of
|
||||
//! memory shaders do not write (streaming).
|
||||
|
||||
use super::*;
|
||||
use crate::shadow::Shadow;
|
||||
|
||||
pub(super) fn on() -> bool {
|
||||
static ON: OnceLock<bool> = OnceLock::new();
|
||||
*ON.get_or_init(|| std::env::var_os("VICTORY_COPIES_IN_PLACE").is_none_or(|v| v != "0"))
|
||||
}
|
||||
|
||||
/// The most bytes copied out of memory shaders do not write.
|
||||
const MOST: usize = 8 << 20;
|
||||
|
||||
/// Since the last frame-rate line: copies at their place, their bytes, those
|
||||
/// out of a host copy, and texture copies out of one.
|
||||
pub(super) static STATS: [std::sync::atomic::AtomicU64; 4] = [const { std::sync::atomic::AtomicU64::new(0) }; 4];
|
||||
|
||||
/// What the CPU does at submission for a copy at its place in a list.
|
||||
pub(super) struct Placed {
|
||||
pub(super) dst: usize,
|
||||
pub(super) src: usize,
|
||||
pub(super) len: usize,
|
||||
/// The destination's host copy.
|
||||
pub(super) shadow: std::sync::Arc<Shadow>,
|
||||
/// Upload memory the list copies from, to be given the source's bytes.
|
||||
from: Option<usize>,
|
||||
}
|
||||
|
||||
impl Placed {
|
||||
/// Whether flights that write `written` are waited for.
|
||||
pub(super) fn waits(&self, written: &[(usize, usize)]) -> Waits {
|
||||
let source = touches(written, self.src, self.src + self.len);
|
||||
if source && self.from.is_some() {
|
||||
return Waits::Yes;
|
||||
}
|
||||
match source || touches(written, self.dst, self.dst + self.len) {
|
||||
true => Waits::ForReaders,
|
||||
false => Waits::No,
|
||||
}
|
||||
}
|
||||
|
||||
/// At submission, in the order of the steps: the list's upload memory
|
||||
/// takes the source's bytes and, if `free` (no flight in the air may write
|
||||
/// source or destination), title memory at the destination does. Gives
|
||||
/// the bytes if it took them.
|
||||
pub(super) fn prepare(&self, free: bool) -> Option<Vec<u8>> {
|
||||
if !free && self.from.is_none() {
|
||||
return None;
|
||||
}
|
||||
let mut bytes = vec![0u8; self.len];
|
||||
// (What is not there reads as zeros, as any copy's source.)
|
||||
copy_mapped(bytes.as_mut_ptr(), self.src as *const u8, self.len, false);
|
||||
if let Some(to) = self.from {
|
||||
// SAFETY: the list's own upload memory of that many bytes.
|
||||
unsafe { std::ptr::copy_nonoverlapping(bytes.as_ptr(), to as *mut u8, self.len) };
|
||||
}
|
||||
if !free {
|
||||
return None;
|
||||
}
|
||||
copy_mapped(self.dst as *mut u8, bytes.as_ptr(), self.len, true);
|
||||
crate::watch::wrote(self.dst, self.len);
|
||||
// Title memory that is not all there was left alone.
|
||||
let mut there = vec![0u8; self.len];
|
||||
(read_into(self.dst as *const u8, &mut there) && there == bytes).then_some(bytes)
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether a copy waits for flights before its submission is prepared: not;
|
||||
/// yes, as it takes a source on the CPU that they may write; or only if
|
||||
/// another step of the submission reads its destination on the CPU.
|
||||
pub(super) enum Waits {
|
||||
No,
|
||||
ForReaders,
|
||||
Yes,
|
||||
}
|
||||
|
||||
/// Whether a step of `runs` reads one of `ranges` on the CPU.
|
||||
pub(super) fn read_by(runs: &[&HostList], mut ranges: Vec<(usize, usize)>) -> bool {
|
||||
join_ranges(&mut ranges, []);
|
||||
runs.iter().any(|list| {
|
||||
list.deferred().copies.iter().any(|step| match step {
|
||||
&Step::Copy(_, src, len) | &Step::Fill(_, src, len, _) => touches(&ranges, src, src + len),
|
||||
Step::Texture(staging) => {
|
||||
let (at, len) = staging.memory();
|
||||
touches(&ranges, at, at + len)
|
||||
}
|
||||
Step::Host(_, (from, to)) => touches(&ranges, *from, *to),
|
||||
Step::Placed(p) => p.from.is_some() && touches(&ranges, p.src, p.src + p.len),
|
||||
_ => false,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
/// Everything recorded so far is done, and seen, before what follows.
|
||||
///
|
||||
/// # Safety
|
||||
/// An open list.
|
||||
unsafe fn wait_for_all(host: &Host, list: &ID3D12GraphicsCommandList) {
|
||||
static ENHANCED: OnceLock<bool> = OnceLock::new();
|
||||
let enhanced = *ENHANCED.get_or_init(|| {
|
||||
let mut o = D3D12_FEATURE_DATA_D3D12_OPTIONS12::default();
|
||||
// SAFETY: a feature structure of its size.
|
||||
let known = unsafe {
|
||||
host.device.CheckFeatureSupport(
|
||||
D3D12_FEATURE_D3D12_OPTIONS12,
|
||||
(&raw mut o).cast(),
|
||||
size_of::<D3D12_FEATURE_DATA_D3D12_OPTIONS12>() as u32,
|
||||
)
|
||||
};
|
||||
known.is_ok() && o.EnhancedBarriersSupported.as_bool()
|
||||
});
|
||||
// SAFETY: the caller's.
|
||||
unsafe {
|
||||
if enhanced && let Ok(list) = list.cast::<ID3D12GraphicsCommandList7>() {
|
||||
let all = [D3D12_GLOBAL_BARRIER {
|
||||
SyncBefore: D3D12_BARRIER_SYNC_ALL,
|
||||
SyncAfter: D3D12_BARRIER_SYNC_ALL,
|
||||
AccessBefore: D3D12_BARRIER_ACCESS_COMMON,
|
||||
AccessAfter: D3D12_BARRIER_ACCESS_COMMON,
|
||||
}];
|
||||
list.Barrier(&[D3D12_BARRIER_GROUP {
|
||||
Type: D3D12_BARRIER_TYPE_GLOBAL,
|
||||
NumBarriers: 1,
|
||||
Anonymous: D3D12_BARRIER_GROUP_0 {
|
||||
pGlobalBarriers: all.as_ptr(),
|
||||
},
|
||||
}]);
|
||||
return;
|
||||
}
|
||||
let alias = D3D12_RESOURCE_BARRIER {
|
||||
Type: D3D12_RESOURCE_BARRIER_TYPE_ALIASING,
|
||||
Flags: D3D12_RESOURCE_BARRIER_FLAG_NONE,
|
||||
Anonymous: D3D12_RESOURCE_BARRIER_0 {
|
||||
Aliasing: std::mem::ManuallyDrop::new(D3D12_RESOURCE_ALIASING_BARRIER {
|
||||
pResourceBefore: std::mem::ManuallyDrop::new(None),
|
||||
pResourceAfter: std::mem::ManuallyDrop::new(None),
|
||||
}),
|
||||
},
|
||||
};
|
||||
let uav = D3D12_RESOURCE_BARRIER {
|
||||
Type: D3D12_RESOURCE_BARRIER_TYPE_UAV,
|
||||
Flags: D3D12_RESOURCE_BARRIER_FLAG_NONE,
|
||||
Anonymous: D3D12_RESOURCE_BARRIER_0 {
|
||||
UAV: std::mem::ManuallyDrop::new(D3D12_RESOURCE_UAV_BARRIER {
|
||||
pResource: std::mem::ManuallyDrop::new(None),
|
||||
}),
|
||||
},
|
||||
};
|
||||
list.ResourceBarrier(&[alias, uav]);
|
||||
}
|
||||
}
|
||||
|
||||
/// The host copy of `[src, src + len)` if shaders write it: what it holds at
|
||||
/// a place in a list is not what title memory holds at submission.
|
||||
fn shaders_own(src: usize, len: usize) -> Option<std::sync::Arc<Shadow>> {
|
||||
crate::shadow::peek(src as u64, len as u64).filter(|s| s.written() && !s.in_place())
|
||||
}
|
||||
|
||||
impl HostList {
|
||||
/// Copies `len` bytes of title memory at `src` to `dst`, at this place of
|
||||
/// the list (see the file). `false` if it is to be done at submission.
|
||||
pub(crate) fn place_copy(&self, dst: usize, src: usize, len: usize) -> bool {
|
||||
if !on() {
|
||||
return false;
|
||||
}
|
||||
let Some(host) = host() else {
|
||||
return false;
|
||||
};
|
||||
let Some(to) = crate::shadow::peek(dst as u64, len as u64).filter(|s| !s.in_place()) else {
|
||||
return false;
|
||||
};
|
||||
let own = shaders_own(src, len);
|
||||
let scratch = match &own {
|
||||
Some(_) => None,
|
||||
None if len <= MOST => match self.scratch_at(len as u64) {
|
||||
Some(scratch) => Some(scratch),
|
||||
None => return false,
|
||||
},
|
||||
None => return false,
|
||||
};
|
||||
let at = to.offset(dst as u64);
|
||||
// What the title's CPU wrote around and under it so far goes first.
|
||||
to.refresh(self, dst as u64, len as u64);
|
||||
// SAFETY (both): an open list; live buffers (the list holds the
|
||||
// copies and its scratch memory), ranges inside them.
|
||||
unsafe { wait_for_all(host, &self.list) };
|
||||
match (&own, &scratch) {
|
||||
(Some(from), _) => {
|
||||
from.refresh(self, src as u64, len as u64);
|
||||
let offset = from.offset(src as u64);
|
||||
if from.buffer.as_raw() == to.buffer.as_raw() {
|
||||
let Some(between) = self.between(host, len as u64) else {
|
||||
return false;
|
||||
};
|
||||
unsafe {
|
||||
self.list.CopyBufferRegion(&between, 0, &from.buffer, offset, len as u64);
|
||||
self.list.ResourceBarrier(&[transition(&between, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE)]);
|
||||
wait_for_all(host, &self.list);
|
||||
self.list.CopyBufferRegion(&to.buffer, at, &between, 0, len as u64);
|
||||
}
|
||||
} else {
|
||||
unsafe { self.list.CopyBufferRegion(&to.buffer, at, &from.buffer, offset, len as u64) };
|
||||
}
|
||||
STATS[2].fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
(None, Some((from, offset, _))) => unsafe {
|
||||
self.list.CopyBufferRegion(&to.buffer, at, from, *offset, len as u64);
|
||||
},
|
||||
(None, None) => return false,
|
||||
}
|
||||
unsafe { wait_for_all(host, &self.list) };
|
||||
STATS[0].fetch_add(1, Ordering::Relaxed);
|
||||
STATS[1].fetch_add(len as u64, Ordering::Relaxed);
|
||||
to.gpu_writes(self, dst as u64, len as u64);
|
||||
let mut deferred = self.deferred();
|
||||
deferred.copies.push(Step::Placed(Placed {
|
||||
dst,
|
||||
src,
|
||||
len,
|
||||
shadow: to,
|
||||
from: scratch.map(|s| s.2 as usize),
|
||||
}));
|
||||
deferred.refreshed.clear();
|
||||
true
|
||||
}
|
||||
|
||||
/// For a copy of `[src, src + len)` into a texture: a buffer (readable by
|
||||
/// copies) that holds what shaders wrote there, at this place of the list.
|
||||
/// `None` where shaders do not write it.
|
||||
pub(crate) fn place_source(&self, src: usize, len: usize) -> Option<ID3D12Resource> {
|
||||
if !on() {
|
||||
return None;
|
||||
}
|
||||
let host = host()?;
|
||||
let from = shaders_own(src, len)?;
|
||||
let between = self.between(host, len as u64)?;
|
||||
from.refresh(self, src as u64, len as u64);
|
||||
STATS[3].fetch_add(1, Ordering::Relaxed);
|
||||
// SAFETY: an open list; live buffers, ranges inside them.
|
||||
unsafe {
|
||||
wait_for_all(host, &self.list);
|
||||
self.list.CopyBufferRegion(&between, 0, &from.buffer, from.offset(src as u64), len as u64);
|
||||
self.list.ResourceBarrier(&[transition(&between, D3D12_RESOURCE_STATE_COPY_DEST, D3D12_RESOURCE_STATE_COPY_SOURCE)]);
|
||||
wait_for_all(host, &self.list);
|
||||
}
|
||||
Some(between)
|
||||
}
|
||||
|
||||
/// A buffer on the card for this recording alone.
|
||||
fn between(&self, host: &Host, len: u64) -> Option<ID3D12Resource> {
|
||||
let buffer = host.uav_buffer(len.next_multiple_of(1 << 16))?;
|
||||
name(&buffer, || "bytes between copies".into());
|
||||
self.keep(&buffer);
|
||||
Some(buffer)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
/// What copies with two sides cost to make (ignored: a measurement for
|
||||
/// `VICTORY_CARD_ALL`): buffers of 64 KiB on the card and in the PC's
|
||||
/// memory.
|
||||
#[test]
|
||||
#[ignore]
|
||||
fn small_buffers_cost() {
|
||||
let Some(host) = super::host() else {
|
||||
return;
|
||||
};
|
||||
const N: usize = 1000;
|
||||
let used = || host.video_memory().map_or(0, |m| m[1] >> 20);
|
||||
let before = used();
|
||||
let t = std::time::Instant::now();
|
||||
let card: Vec<_> = (0..N).map(|_| host.uav_buffer(1 << 16)).collect();
|
||||
let card_us = t.elapsed().as_micros() as f64 / N as f64;
|
||||
let after = used();
|
||||
let t = std::time::Instant::now();
|
||||
let pc: Vec<_> = (0..N).map(|_| host.shared_buffer(1 << 16)).collect();
|
||||
let pc_us = t.elapsed().as_micros() as f64 / N as f64;
|
||||
println!(
|
||||
"{N} buffers of 64 KiB: on the card {card_us:.0} us each, {} MB of its memory; in the PC's memory {pc_us:.0} us each",
|
||||
after.saturating_sub(before)
|
||||
);
|
||||
drop((card, pc));
|
||||
}
|
||||
}
|
||||
@@ -954,6 +954,241 @@ mod tests {
|
||||
each_reads_its_own(256 << 10, 0x8888, std::env::var_os("VICTORY_CARD_ALL").is_some_and(|v| v == "1"));
|
||||
}
|
||||
|
||||
/// What a draw of `list` reads at `at`: comes to `out`.
|
||||
fn read_out(list: &HostList, shadow: &std::sync::Arc<Shadow>, at: usize, n: usize, out: (&ID3D12Resource, u64)) {
|
||||
shadow.refresh(list, shadow.span().0 + at as u64, n as u64);
|
||||
// SAFETY: an open list; live buffers.
|
||||
unsafe {
|
||||
list.list.CopyBufferRegion(out.0, out.1, &shadow.buffer, at as u64, n as u64);
|
||||
list.list
|
||||
.ResourceBarrier(&[transition(&shadow.buffer, D3D12_RESOURCE_STATE_COPY_SOURCE, D3D12_RESOURCE_STATE_COMMON)]);
|
||||
}
|
||||
}
|
||||
|
||||
/// Copies, shader writes and reads in random order, within lists and
|
||||
/// across submissions in the air, the title's CPU writing sources in
|
||||
/// between: every read sees what stands before it, and in the end title
|
||||
/// memory and the copies hold the last of everything.
|
||||
fn in_order(resource: usize, sizes: [usize; 3]) {
|
||||
let Some(host) = host() else {
|
||||
return;
|
||||
};
|
||||
let buffers: Vec<_> = sizes.iter().enumerate().map(|(i, &n)| title_of(resource + i, i == 0, n)).collect();
|
||||
let slow = Slow::new(host);
|
||||
let (out, out_data) = host.shared_buffer(1 << 20).unwrap();
|
||||
let mut seed = 0x9e37_79b9_7f4a_7c15u64 ^ resource as u64;
|
||||
let mut next = move |n: usize| {
|
||||
seed ^= seed << 13;
|
||||
seed ^= seed >> 7;
|
||||
seed ^= seed << 17;
|
||||
(seed >> 11) as usize % n
|
||||
};
|
||||
// Of each buffer: the first 4 KiB are the title's own (sources), the
|
||||
// next 12 are written by copies and shaders.
|
||||
const OWN: usize = 4096;
|
||||
const ALL: usize = 16384;
|
||||
// (Of the third only the first 4 KiB: shaders never write it.)
|
||||
let mut model = [vec![0u8; ALL], vec![0u8; ALL], vec![0u8; ALL]];
|
||||
let mut titles: Vec<&'static mut [u8]> = Vec::new();
|
||||
let mut made = Vec::new();
|
||||
for (title, start, shadow) in buffers {
|
||||
titles.push(title);
|
||||
made.push((start, shadow));
|
||||
}
|
||||
let mut lists = Vec::new();
|
||||
for (start, shadow) in &made {
|
||||
let all = host.new_list().unwrap();
|
||||
shadow.refresh(&all, *start as u64, ALL as u64);
|
||||
all.close();
|
||||
host.execute_own(&all);
|
||||
lists.push(all);
|
||||
}
|
||||
settle_now(WHY_SYNC);
|
||||
for round in 0..150 {
|
||||
// (offset in `out`, what was expected, where from)
|
||||
let mut expected: Vec<(usize, Vec<u8>, String)> = Vec::new();
|
||||
let mut told = String::new();
|
||||
for submission in 0..1 + next(5) {
|
||||
for _ in 0..next(6) {
|
||||
let (b, at) = (next(3), next(OWN / 64) * 64);
|
||||
let value = next(255) as u8 + 1;
|
||||
// (A copy with one side is what submissions in the air
|
||||
// read: the title's CPU waits for them, as it does.)
|
||||
if !made[b].1.carded() {
|
||||
settle_now(WHY_SYNC);
|
||||
}
|
||||
titles[b][at..at + 64].fill(value);
|
||||
model[b][at..at + 64].fill(value);
|
||||
}
|
||||
let list = host.new_list().unwrap();
|
||||
if next(3) == 0 {
|
||||
slow.record(&list, 4 + next(12));
|
||||
}
|
||||
for op in 0..1 + next(10) {
|
||||
let word = |next: &mut dyn FnMut(usize) -> usize| OWN + next((ALL - OWN - 256) / 4) * 4;
|
||||
match next(5) {
|
||||
0 | 1 => {
|
||||
let (d, s) = (next(2), next(3));
|
||||
let n = 4 * (1 + next(64));
|
||||
let to = word(&mut next);
|
||||
let from = if s == 2 || next(2) == 0 { next((OWN - 256) / 4) * 4 } else { word(&mut next) };
|
||||
if d == s && from < to + n && to < from + n {
|
||||
continue;
|
||||
}
|
||||
assert!(list.place_copy(made[d].0 + to, made[s].0 + from, n), "done in the list");
|
||||
let bytes = model[s][from..from + n].to_vec();
|
||||
model[d][to..to + n].copy_from_slice(&bytes);
|
||||
told += &format!("\n s{submission} op{op}: copy {d}+{to:#x} <- {s}+{from:#x} {n:#x}");
|
||||
}
|
||||
2 => {
|
||||
let (b, at, n) = (next(2), word(&mut next), 4 * (1 + next(32)));
|
||||
let value = next(255) as u8 + 1;
|
||||
let (start, shadow) = &made[b];
|
||||
shadow.refresh(&list, (*start + at) as u64, n as u64);
|
||||
shadow.gpu_writes(&list, (*start + at) as u64, n as u64);
|
||||
write(host, &list, shadow, at, &vec![value; n]);
|
||||
model[b][at..at + n].fill(value);
|
||||
told += &format!("\n s{submission} op{op}: shader {b}+{at:#x} {n:#x} = {value:#x}");
|
||||
}
|
||||
_ => {
|
||||
let (b, n) = (next(2), 256);
|
||||
let at = if next(4) == 0 { next((OWN - 256) / 4) * 4 } else { word(&mut next) };
|
||||
let place = expected.len() * 256;
|
||||
read_out(&list, &made[b].1, at, n, (&out, place as u64));
|
||||
expected.push((place, model[b][at..at + n].to_vec(), format!("s{submission} op{op}: read {b}+{at:#x}")));
|
||||
}
|
||||
}
|
||||
}
|
||||
list.close();
|
||||
host.execute_own(&list);
|
||||
lists.push(list);
|
||||
}
|
||||
settle_now(WHY_SYNC);
|
||||
for (at, bytes, what) in expected {
|
||||
// SAFETY: inside the mapping; the copies into it have run.
|
||||
let got = unsafe { std::slice::from_raw_parts(out_data.add(at), bytes.len()) };
|
||||
if let Some(k) = (0..bytes.len()).find(|&k| got[k] != bytes[k]) {
|
||||
panic!("round {round}, {what}: at +{k:#x} {:#x}, not {:#x}{told}", got[k], bytes[k]);
|
||||
}
|
||||
}
|
||||
for (b, title) in titles.iter().enumerate() {
|
||||
if let Some(k) = (0..ALL).find(|&k| title[k] != model[b][k]) {
|
||||
panic!("round {round}: title memory {b}+{k:#x} is {:#x}, not {:#x}{told}", title[k], model[b][k]);
|
||||
}
|
||||
}
|
||||
// Brought up to date by the next, the copies hold it too.
|
||||
let list = host.new_list().unwrap();
|
||||
for (b, (_, shadow)) in made.iter().enumerate() {
|
||||
read_out(&list, shadow, 0, ALL, (&out, (b * ALL) as u64));
|
||||
}
|
||||
list.close();
|
||||
host.execute_own(&list);
|
||||
lists.push(list);
|
||||
settle_now(WHY_SYNC);
|
||||
for (b, model) in model.iter().enumerate() {
|
||||
// SAFETY: as above.
|
||||
let got = unsafe { std::slice::from_raw_parts(out_data.add(b * ALL), ALL) };
|
||||
if let Some(k) = (0..ALL).find(|&k| got[k] != model[k]) {
|
||||
panic!("round {round}: the copy {b}+{k:#x} is {:#x}, not {:#x}{told}", got[k], model[k]);
|
||||
}
|
||||
}
|
||||
if on() {
|
||||
assert_eq!(look(host), Some(0), "round {round}");
|
||||
}
|
||||
}
|
||||
eprintln!(
|
||||
"copies at their place, bytes, out of host copies, into textures: {:?}",
|
||||
super::place::STATS.iter().map(|s| s.load(Ordering::Relaxed)).collect::<Vec<_>>()
|
||||
);
|
||||
}
|
||||
|
||||
/// Two buffers with two sides.
|
||||
#[test]
|
||||
#[ignore = "wants VICTORY_RELAY=2 VICTORY_RELAY_COPY=1 and a process of its own"]
|
||||
fn copies_stand_where_the_list_has_them_on_the_card() {
|
||||
in_order(0x9100, [LEN, LEN, LEN]);
|
||||
}
|
||||
|
||||
/// One in the card's memory, one in the PC's (one side without
|
||||
/// `VICTORY_CARD_ALL`).
|
||||
#[test]
|
||||
#[ignore = "wants VICTORY_RELAY=2 VICTORY_RELAY_COPY=1 and a process of its own"]
|
||||
fn copies_stand_where_the_list_has_them_mixed() {
|
||||
in_order(0x9200, [LEN, 256 << 10, 256 << 10]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "wants VICTORY_RELAY=2 VICTORY_RELAY_COPY=1 and a process of its own"]
|
||||
fn copies_stand_where_the_list_has_them_in_pc_memory() {
|
||||
in_order(0x9300, [256 << 10, 256 << 10, LEN]);
|
||||
}
|
||||
|
||||
/// As the title records it: copy, draw, copy, draw in one list; a source
|
||||
/// a shader writes first; a counter copied to zero and counted up.
|
||||
#[test]
|
||||
#[ignore = "wants VICTORY_RELAY=2 VICTORY_RELAY_COPY=1 and a process of its own"]
|
||||
fn copy_draw_copy_draw() {
|
||||
let Some(host) = host() else {
|
||||
return;
|
||||
};
|
||||
let (title, start, shadow) = title_of(0x9400, true, LEN);
|
||||
let (out, out_data) = host.shared_buffer(1 << 16).unwrap();
|
||||
let all = host.new_list().unwrap();
|
||||
shadow.refresh(&all, start as u64, LEN as u64);
|
||||
all.close();
|
||||
host.execute_own(&all);
|
||||
settle_now(WHY_SYNC);
|
||||
title[0..64].fill(1);
|
||||
title[64..128].fill(2);
|
||||
title[128..192].fill(0);
|
||||
let list = host.new_list().unwrap();
|
||||
const D: usize = 0x10000;
|
||||
const S: usize = 0x20000;
|
||||
assert!(list.place_copy(start + D, start, 64));
|
||||
read_out(&list, &shadow, D, 64, (&out, 0));
|
||||
assert!(list.place_copy(start + D, start + 64, 64));
|
||||
read_out(&list, &shadow, D, 64, (&out, 64));
|
||||
// A shader writes S, and it is copied on.
|
||||
shadow.gpu_writes(&list, (start + S) as u64, 64);
|
||||
write(host, &list, &shadow, S, &[7; 64]);
|
||||
assert!(list.place_copy(start + D + 64, start + S, 64));
|
||||
read_out(&list, &shadow, D + 64, 64, (&out, 128));
|
||||
// Zero, counted up, taken away.
|
||||
assert!(list.place_copy(start + D + 128, start + 128, 64));
|
||||
shadow.gpu_writes(&list, (start + D + 128) as u64, 64);
|
||||
write(host, &list, &shadow, D + 128, &[5; 64]);
|
||||
assert!(list.place_copy(start + D + 192, start + D + 128, 64));
|
||||
read_out(&list, &shadow, D + 192, 64, (&out, 192));
|
||||
// What a copy into a texture takes of S here.
|
||||
let between = list.place_source(start + S, 64).expect("shaders write it");
|
||||
shadow.gpu_writes(&list, (start + S) as u64, 64);
|
||||
write(host, &list, &shadow, S, &[9; 64]);
|
||||
// SAFETY: an open list; live buffers.
|
||||
unsafe { list.list.CopyBufferRegion(&out, 256, &between, 0, 64) };
|
||||
assert!(list.place_source(start + (1 << 20), 64).is_some(), "the buffer is written");
|
||||
// And zero for the next frame.
|
||||
assert!(list.place_copy(start + D + 128, start + 128, 64));
|
||||
list.close();
|
||||
host.execute_own(&list);
|
||||
settle_now(WHY_SYNC);
|
||||
// SAFETY: the mapping; the copies into it have run.
|
||||
let read = unsafe { std::slice::from_raw_parts(out_data, 320) };
|
||||
assert_eq!(read[256], 7, "what a texture takes");
|
||||
assert_eq!([read[0], read[64], read[128], read[192]], [1, 2, 7, 5], "what the draws read");
|
||||
assert_eq!(
|
||||
[title[D], title[D + 64], title[D + 128], title[D + 192], title[S]],
|
||||
[2, 7, 0, 5, 9],
|
||||
"title memory"
|
||||
);
|
||||
let holds = card(host, &shadow);
|
||||
assert_eq!([holds[D], holds[D + 64], holds[D + 128], holds[D + 192], holds[S]], [2, 7, 0, 5, 9], "the card");
|
||||
assert_eq!(look(host), Some(0));
|
||||
// With the debug layer.
|
||||
if let Some(said) = host.log_messages() {
|
||||
eprintln!("{said}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Declared writes beside the title's own, in the same 64 KiB pieces and
|
||||
/// dword by dword, flights landing while later ones are in the air: in
|
||||
/// the end title memory and the card hold what each wrote last. (A byte
|
||||
|
||||
Reference in new issue
Block a user