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
@@ -748,11 +748,19 @@ struct Resource {
|
||||
/// Textures also live on the host GPU (decision 0007); buffers do not
|
||||
/// yet.
|
||||
#[cfg(windows)]
|
||||
host: Option<windows::Win32::Graphics::Direct3D12::ID3D12Resource>,
|
||||
/// The state the host texture is in. The title's barriers name console
|
||||
/// states (looser than the host's), so we transition from this one.
|
||||
#[cfg(windows)]
|
||||
host_state: std::sync::atomic::AtomicU32,
|
||||
host: Option<std::sync::Arc<HostTexture>>,
|
||||
}
|
||||
|
||||
/// A title texture's host copy and the state it is in. The title's barriers
|
||||
/// name console states (looser than the host's), so we transition from this
|
||||
/// one. Lists that use the texture hold it until they are reset: the title
|
||||
/// may release a resource whose commands it recorded but not yet submitted
|
||||
/// (console memory outlives the object; a host texture must outlive the
|
||||
/// lists that name it).
|
||||
#[cfg(windows)]
|
||||
pub(crate) struct HostTexture {
|
||||
pub(crate) texture: windows::Win32::Graphics::Direct3D12::ID3D12Resource,
|
||||
pub(crate) state: std::sync::atomic::AtomicU32,
|
||||
}
|
||||
|
||||
/// Moves the host texture to `wanted` (a host texture state); the host
|
||||
@@ -760,21 +768,11 @@ struct Resource {
|
||||
#[cfg(windows)]
|
||||
pub(crate) fn host_transition(this: This, wanted: u32) -> Option<(*mut c_void, u32)> {
|
||||
use windows::core::Interface;
|
||||
let r = resource(this);
|
||||
let host = r.host.as_ref()?;
|
||||
let before = r
|
||||
.host_state
|
||||
let host = resource(this).host.as_ref()?;
|
||||
let before = host
|
||||
.state
|
||||
.swap(wanted, std::sync::atomic::Ordering::Relaxed);
|
||||
(before != wanted).then(|| (host.as_raw(), before))
|
||||
}
|
||||
|
||||
/// Sets the state the host texture is in after a submission; returns the
|
||||
/// one it was in.
|
||||
#[cfg(windows)]
|
||||
pub(crate) fn swap_host_state(this: This, state: u32) -> u32 {
|
||||
resource(this)
|
||||
.host_state
|
||||
.swap(state, std::sync::atomic::Ordering::Relaxed)
|
||||
(before != wanted).then(|| (host.texture.as_raw(), before))
|
||||
}
|
||||
|
||||
/// The host GPU's copy of a title resource, if it has one.
|
||||
@@ -785,7 +783,16 @@ pub(crate) fn host_resource<'a>(
|
||||
if this.is_null() {
|
||||
return None;
|
||||
}
|
||||
resource(this).host.as_ref()
|
||||
resource(this).host.as_deref().map(|h| &h.texture)
|
||||
}
|
||||
|
||||
/// A title texture's host copy, shared, for a list to hold.
|
||||
#[cfg(windows)]
|
||||
pub(crate) fn host_copy(this: This) -> Option<std::sync::Arc<HostTexture>> {
|
||||
if this.is_null() {
|
||||
return None;
|
||||
}
|
||||
resource(this).host.clone()
|
||||
}
|
||||
|
||||
/// A host texture like the title's: same description, in GPU memory,
|
||||
@@ -929,12 +936,13 @@ fn hand_out_resource(
|
||||
heap_flags,
|
||||
backing,
|
||||
#[cfg(windows)]
|
||||
host_state: host
|
||||
.as_ref()
|
||||
.map_or(0, |t| crate::host::legal_state(t, crate::host::texture_state(state)))
|
||||
.into(),
|
||||
#[cfg(windows)]
|
||||
host,
|
||||
host: host.map(|texture| {
|
||||
let state = crate::host::legal_state(&texture, crate::host::texture_state(state));
|
||||
std::sync::Arc::new(HostTexture {
|
||||
texture,
|
||||
state: state.into(),
|
||||
})
|
||||
}),
|
||||
});
|
||||
#[cfg(windows)]
|
||||
if desc.dimension == BUFFER {
|
||||
@@ -947,6 +955,24 @@ fn hand_out_resource(
|
||||
#[cfg(windows)]
|
||||
impl Drop for Resource {
|
||||
fn drop(&mut self) {
|
||||
#[cfg(feature = "diagnostics")]
|
||||
if self
|
||||
.host
|
||||
.as_ref()
|
||||
.is_some_and(|h| std::sync::Arc::strong_count(h) > 1)
|
||||
{
|
||||
// Before lists held their textures, this freed a texture that
|
||||
// lists not yet run still named (a GPU page fault).
|
||||
static OUTLIVED: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
|
||||
let n = OUTLIVED.fetch_add(1, std::sync::atomic::Ordering::Relaxed) + 1;
|
||||
if n.is_power_of_two() {
|
||||
tracing::info!(
|
||||
n,
|
||||
desc = ?self.desc,
|
||||
"a title texture was released while a list not yet reset names its host copy"
|
||||
);
|
||||
}
|
||||
}
|
||||
crate::texture::forget(std::ptr::from_ref::<Resource>(self) as usize);
|
||||
crate::descriptor::forget(std::ptr::from_ref::<Resource>(self) as usize);
|
||||
if self.desc.dimension == BUFFER {
|
||||
@@ -1705,6 +1731,8 @@ mod tests {
|
||||
let host_image = host_resource(image).unwrap();
|
||||
let back = host.new_list().unwrap();
|
||||
let (_, before) = host_transition(image, 0x800).unwrap();
|
||||
// The upload list holds the texture until it is reset.
|
||||
assert!(std::sync::Arc::strong_count(&host_copy(image).unwrap()) > 2);
|
||||
use windows::core::Interface;
|
||||
let out_to = Location {
|
||||
resource: readback.as_raw().cast_const().cast(),
|
||||
|
||||
Reference in new issue
Block a user