GPU: the world stays up; indirect execution behind a switch
The host device was removed seconds into the world because a shader read a descriptor of the wrong kind: empty slots held a null 2D texture view where the shader expected a buffer, which gave a garbage heap index and a read far past the view heap. Null descriptors now have the kind the shader expects (raw buffer, constant buffer, or a texture of the title's own dimension). The world then ran to a 240 s time limit with no removal. Also: - Host lists hold the textures, pipelines, root signatures and heaps they name, and heap slots hold the resource they view (the title releases objects before submitting lists that use them). - The device-removed report places the fault against the host descriptor heaps and names our own uploads; VICTORY_D3D12_GBV turns on GPU-based validation, VICTORY_DUMP_TARGETS works. - Indirect execution (draw, indexed draw, dispatch, mesh dispatch): the world draws most of its geometry this way. Arguments are clamped and charged to a per-list budget by a small compute pass first, so garbage cannot hang the GPU. Off by default (VICTORY_INDIRECT=1): with it on the title's own GPU watchdog ends the run about 30 s into the world. - Shader-written ranges are copied back once per submission and only where they differ; refreshes beside them copy only stale pages. The frame-rate line counts copy-backs and dropped draws. Not working yet: the world's picture is black (indirect draws off, and hundreds of draws per frame have no translated shader). Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
1 parent
1922261412
commit
d50f2368cb
14 files changed
+973
-151
No files matched your search
@@ -106,6 +106,13 @@ pub(crate) fn take_frame() -> Vec<String> {
|
||||
std::mem::take(&mut *FRAME.lock().unwrap_or_else(|e| e.into_inner()))
|
||||
}
|
||||
|
||||
/// Draws, mesh dispatches and dispatches recorded but not run on the host
|
||||
/// (no host pipeline) since the last call.
|
||||
pub(crate) fn take_dropped() -> u64 {
|
||||
DROPPED.swap(0, Ordering::Relaxed)
|
||||
}
|
||||
static DROPPED: AtomicU64 = AtomicU64::new(0);
|
||||
|
||||
/// Marks the last traced draw as not run on the host.
|
||||
#[cfg(feature = "diagnostics")]
|
||||
fn dropped() {
|
||||
@@ -403,6 +410,7 @@ impl State {
|
||||
.filter_map(|&h| crate::descriptor::heap(h as This).host())
|
||||
.map(|h| Some(h.heap.clone()))
|
||||
.collect();
|
||||
heaps.iter().flatten().for_each(|h| list.keep(h));
|
||||
// SAFETY: an open list and shader-visible heaps.
|
||||
unsafe { l.SetDescriptorHeaps(&heaps) };
|
||||
self.host_heaps = self.heaps;
|
||||
@@ -420,11 +428,16 @@ impl State {
|
||||
}
|
||||
self.host_roots[usize::from(compute)] = root;
|
||||
}
|
||||
if self.host_pipeline != self.pipeline {
|
||||
// By host object: a title pipeline released and another made at its
|
||||
// address is another host pipeline (the list keeps the old one).
|
||||
if self.host_pipeline != p.pso.as_raw() as usize {
|
||||
// SAFETY: an open list and a live pipeline.
|
||||
unsafe { l.SetPipelineState(&p.pso) };
|
||||
self.host_pipeline = self.pipeline;
|
||||
self.host_pipeline = p.pso.as_raw() as usize;
|
||||
list.used_pipeline(&p.name);
|
||||
// The title may release the pipeline before it submits the list.
|
||||
list.keep(&p.pso);
|
||||
list.keep(&p.root);
|
||||
}
|
||||
for stage in &p.stages {
|
||||
let t = stage.translated();
|
||||
@@ -480,6 +493,7 @@ impl State {
|
||||
pipeline = format_args!("{:#x}", self.pipeline),
|
||||
"a dispatch without a host pipeline dropped"
|
||||
);
|
||||
DROPPED.fetch_add(1, Ordering::Relaxed);
|
||||
return;
|
||||
};
|
||||
if !p.compute {
|
||||
@@ -548,12 +562,11 @@ impl State {
|
||||
}
|
||||
Err(_) => false,
|
||||
};
|
||||
#[cfg(feature = "diagnostics")]
|
||||
if !ran {
|
||||
DROPPED.fetch_add(1, Ordering::Relaxed);
|
||||
#[cfg(feature = "diagnostics")]
|
||||
dropped();
|
||||
}
|
||||
#[cfg(not(feature = "diagnostics"))]
|
||||
let _ = ran;
|
||||
}
|
||||
|
||||
fn roots_ref(&self, compute: bool) -> &Vec<Root> {
|
||||
@@ -781,8 +794,9 @@ impl State {
|
||||
};
|
||||
DRAWN.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
#[cfg(feature = "diagnostics")]
|
||||
if !ran {
|
||||
DROPPED.fetch_add(1, Ordering::Relaxed);
|
||||
#[cfg(feature = "diagnostics")]
|
||||
dropped();
|
||||
}
|
||||
}
|
||||
@@ -867,13 +881,139 @@ impl State {
|
||||
};
|
||||
DRAWN.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
#[cfg(feature = "diagnostics")]
|
||||
if !ran {
|
||||
DROPPED.fetch_add(1, Ordering::Relaxed);
|
||||
#[cfg(feature = "diagnostics")]
|
||||
dropped();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl State {
|
||||
/// Indirect execution of a one-argument signature of `kind` (PC
|
||||
/// numbering: 0 draw, 1 indexed draw, 2 dispatch, 10 mesh dispatch) with
|
||||
/// records `stride` bytes apart at title address `arguments`, and the
|
||||
/// record count at `count` if the title gives one: the GPU reads them
|
||||
/// from the buffer's host copy, where earlier dispatches may have
|
||||
/// written them. False if it cannot run on the host.
|
||||
pub(crate) fn execute_indirect(
|
||||
&mut self,
|
||||
list: &HostList,
|
||||
(kind, stride, max): (u32, u32, u32),
|
||||
arguments: u64,
|
||||
count: Option<u64>,
|
||||
) -> bool {
|
||||
const DRAW: u32 = 0;
|
||||
const INDEXED: u32 = 1;
|
||||
const DISPATCH: u32 = 2;
|
||||
const MESH: u32 = 10;
|
||||
let len = u64::from(stride) * u64::from(max.max(1));
|
||||
let Some(args) = crate::shadow::find(arguments, len) else {
|
||||
return false;
|
||||
};
|
||||
let counter = match count {
|
||||
Some(at) => match crate::shadow::find(at, 4) {
|
||||
Some(s) => Some((s, at)),
|
||||
None => return false,
|
||||
},
|
||||
None => None,
|
||||
};
|
||||
let Some(signature) = matches!(kind, DRAW | INDEXED | DISPATCH | MESH)
|
||||
.then(|| host_signature(kind, stride))
|
||||
.flatten()
|
||||
else {
|
||||
return false;
|
||||
};
|
||||
args.refresh(list, arguments, len);
|
||||
if let Some((s, at)) = &counter {
|
||||
s.refresh(list, *at, 4);
|
||||
}
|
||||
// Bounded first: the clamp binds a compute pipeline of its own.
|
||||
if !crate::indirect::bound(list, &args.buffer, args.gpu(arguments), (kind, stride, max)) {
|
||||
return false;
|
||||
}
|
||||
self.host_pipeline = 0;
|
||||
self.host_roots[1] = 0;
|
||||
let ran = match kind {
|
||||
DRAW | INDEXED => self.topology != RECTANGLES && self.prepare(list, kind == INDEXED),
|
||||
MESH => self.prepare_for(list, false, true),
|
||||
DISPATCH => match crate::pipeline::host_pipeline(self.pipeline as This) {
|
||||
Some(p) if p.compute => {
|
||||
self.bind(list, p, true);
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
_ => false,
|
||||
};
|
||||
if !ran {
|
||||
crate::indirect::done(list, &args.buffer);
|
||||
return false;
|
||||
}
|
||||
#[cfg(feature = "diagnostics")]
|
||||
list.note_op(|| {
|
||||
self.op_text(format!("indirect kind {kind} max {max} at {arguments:#x}"), kind == DISPATCH)
|
||||
});
|
||||
// SAFETY: an open list with everything set; the buffers are host
|
||||
// copies the list keeps alive (refresh), the signature is cached.
|
||||
unsafe {
|
||||
list.list.ExecuteIndirect(
|
||||
&signature,
|
||||
max,
|
||||
&args.buffer,
|
||||
args.offset(arguments),
|
||||
counter.as_ref().map(|(s, _)| &s.buffer),
|
||||
counter.as_ref().map_or(0, |(s, at)| s.offset(*at)),
|
||||
)
|
||||
};
|
||||
crate::indirect::done(list, &args.buffer);
|
||||
if kind == DISPATCH {
|
||||
DISPATCHED.fetch_add(1, Ordering::Relaxed);
|
||||
} else {
|
||||
DRAWN.fetch_add(1, Ordering::Relaxed);
|
||||
}
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
/// The host command signature for one argument of `kind` with records
|
||||
/// `stride` bytes apart (no root arguments, so no root signature), made
|
||||
/// once.
|
||||
fn host_signature(kind: u32, stride: u32) -> Option<ID3D12CommandSignature> {
|
||||
static MADE: std::sync::Mutex<Vec<((u32, u32), ID3D12CommandSignature)>> =
|
||||
std::sync::Mutex::new(Vec::new());
|
||||
let mut made = MADE.lock().unwrap_or_else(|e| e.into_inner());
|
||||
if let Some((_, s)) = made.iter().find(|(k, _)| *k == (kind, stride)) {
|
||||
return Some(s.clone());
|
||||
}
|
||||
let argument = D3D12_INDIRECT_ARGUMENT_DESC {
|
||||
Type: D3D12_INDIRECT_ARGUMENT_TYPE(kind as i32),
|
||||
..Default::default()
|
||||
};
|
||||
let desc = D3D12_COMMAND_SIGNATURE_DESC {
|
||||
ByteStride: stride,
|
||||
NumArgumentDescs: 1,
|
||||
pArgumentDescs: &argument,
|
||||
NodeMask: 0,
|
||||
};
|
||||
let mut signature: Option<ID3D12CommandSignature> = None;
|
||||
// SAFETY: a description of one argument; no root arguments.
|
||||
let result = unsafe {
|
||||
crate::host::host()?.device.CreateCommandSignature(
|
||||
&desc,
|
||||
None::<&ID3D12RootSignature>,
|
||||
&mut signature,
|
||||
)
|
||||
};
|
||||
if let Err(e) = result {
|
||||
once!(error = %e, kind, stride, "host command signature refused");
|
||||
return None;
|
||||
}
|
||||
let signature = signature?;
|
||||
made.push(((kind, stride), signature.clone()));
|
||||
Some(signature)
|
||||
}
|
||||
|
||||
/// Gets what a shader reads or writes through a view ready: buffer data
|
||||
/// copied, textures moved to the state they need.
|
||||
fn readable(list: &HostList, u: &UsedResource, view: &View) {
|
||||
|
||||
Reference in new issue
Block a user