diff --git a/crates/victory-gpu/src/replay/edit.rs b/crates/victory-gpu/src/replay/edit.rs index e4f1f98..33b3cac 100644 --- a/crates/victory-gpu/src/replay/edit.rs +++ b/crates/victory-gpu/src/replay/edit.rs @@ -57,7 +57,7 @@ pub fn no_uav_barriers(cmds: Vec) -> (Vec, u32) { /// resources. pub fn barriers_only(cmds: Vec) -> Vec { cmds.into_iter() - .filter(|c| matches!(c, Cmd::Barriers { .. })) + .filter(Cmd::is_barrier) .collect() } @@ -87,7 +87,10 @@ pub fn merge_barriers(cmds: Vec) -> (Vec, u32) { } } c => { - if c.works() || matches!(c, Cmd::BeginQuery { .. } | Cmd::EndQuery { .. }) { + if c.works() + || c.is_barrier() + || matches!(c, Cmd::BeginQuery { .. } | Cmd::EndQuery { .. }) + { open = None; } out.push(c); @@ -670,6 +673,13 @@ mod tests { go() ] ); + let with_global_sync = vec![ + barriers(&[moved(1, 0, 8)]), + Cmd::GlobalSync {}, + barriers(&[moved(1, 8, 64)]), + ]; + assert_eq!(merge_barriers(with_global_sync.clone()), (with_global_sync.clone(), 0)); + assert_eq!(barriers_only(with_global_sync.clone()), with_global_sync); // Parts of a resource are not mixed up. let part = |sub, before, after| Barrier::Transition { flags: 0, diff --git a/crates/victory-gpu/src/replay/play.rs b/crates/victory-gpu/src/replay/play.rs index 93b2352..0f93400 100644 --- a/crates/victory-gpu/src/replay/play.rs +++ b/crates/victory-gpu/src/replay/play.rs @@ -631,15 +631,25 @@ impl Player { *at = Instant::now(); }; let mut at = Instant::now(); - player.make_resources(options.buffers, &options.only_buffers)?; + player.make_resources(options.buffers, &options.only_buffers).context("creating replay resources")?; step("resources", &mut at); - player.make_pipelines(options.shaders.as_deref())?; + player.make_pipelines(options.shaders.as_deref()).context("creating replay pipelines")?; step("pipelines", &mut at); - player.make_descriptors()?; + player.make_descriptors().context("creating replay descriptor heaps")?; step("descriptors", &mut at); - player.load_contents()?; + if let Err(error) = player.load_contents() { + if let Some(queue) = &player.info { + for message in debug_messages(queue) { + tracing::error!("{message}"); + } + } + if options.breadcrumbs { + log_replay_breadcrumbs(&player.device); + } + return Err(error).context("loading the frame's initial contents"); + } step("contents", &mut at); - player.make_masters(options.buffers, options.restore)?; + player.make_masters(options.buffers, options.restore).context("preparing replay restore copies")?; step("copies to restore from", &mut at); let steps: Vec = steps .iter() @@ -756,8 +766,16 @@ impl Player { _ => gpu::to_props(p), } }; - // Flags a replay has no use for: sharing, display, not zeroed. - const DROP: i32 = 0x1 | 0x8 | 0x20 | 0x1000; + // The title makes its non-resident allocations resident separately. + // Replay does not record residency calls and needs them from its first copy. + const DROP: i32 = 0x1 | 0x8 | 0x20 | D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT.0 + | D3D12_HEAP_FLAG_CREATE_NOT_ZEROED.0; + let nonresident = |flags: i32| flags & D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT.0 != 0; + let heaps = self.frame.heaps.iter().filter(|h| nonresident(h.flags)).count(); + let resources = self.frame.resources.iter().filter(|r| { + matches!(r.place, Place::Committed { flags, .. } if nonresident(flags)) + }).count(); + tracing::debug!(heaps, resources, "recreating non-resident allocations as resident"); let used_by_buffers_only: HashSet = { let mut textures = HashSet::new(); for r in &self.frame.resources { @@ -1317,8 +1335,8 @@ impl Player { "{full} versions of descriptor heaps had no room: earlier lists see later views" )); } - // Render target and depth views. - let mut views: [HashSet; 2] = Default::default(); + // CPU-only views for render targets, depth, and UAV clears. + let mut views: [HashSet; 3] = Default::default(); for c in self.commands.iter().flatten() { match c { Cmd::Targets { colors, depth } => { @@ -1327,6 +1345,7 @@ impl Player { } Cmd::ClearTarget { view, .. } => _ = views[0].insert(*view), Cmd::ClearDepth { view, .. } => _ = views[1].insert(*view), + Cmd::ClearUavFloat { view, .. } => _ = views[2].insert(*view), _ => {} } } @@ -1337,6 +1356,7 @@ impl Player { let kind = [ D3D12_DESCRIPTOR_HEAP_TYPE_RTV, D3D12_DESCRIPTOR_HEAP_TYPE_DSV, + D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, ][i]; let d = D3D12_DESCRIPTOR_HEAP_DESC { Type: kind, @@ -1370,7 +1390,7 @@ impl Player { None }; self.device.CreateRenderTargetView(res, d, at); - } else { + } else if i == 1 { let d = s .desc .as_ptr() @@ -1389,6 +1409,8 @@ impl Player { None }; self.device.CreateDepthStencilView(res, d, at); + } else { + self.view(s, at, false); } self.targets.insert(*s, at); at.ptr += step; @@ -1439,7 +1461,8 @@ impl Player { } for (n, batch) in batches.iter().enumerate() { let k = n % stagings.len(); - self.worker.wait(stagings[k].2)?; + self.worker.wait(stagings[k].2) + .with_context(|| format!("waiting to reuse staging for upload batch {n}"))?; let map = stagings[k].1; let next = AtomicUsize::new(0); let failed: std::sync::Mutex> = std::sync::Mutex::default(); @@ -1586,7 +1609,7 @@ impl Player { } } } - })?; + }).context("uploading the recorded resource contents")?; // To the states of the frame's start. let mut back = Vec::new(); for r in &self.frame.resources { @@ -1602,7 +1625,7 @@ impl Player { // SAFETY: an open list; live resources. unsafe { list.ResourceBarrier(all) }; } - })?; + }).context("restoring initial resource states after upload")?; if missing > 0 { self.note(format!( "contents of {missing} parts of resources that could not be made are left out" @@ -1656,7 +1679,7 @@ impl Player { unsafe { list.CopyBufferRegion(&o.res, d.at, staging, *at, *len) }; } } - })?; + }).context("uploading initial CPU writes")?; // The later ones wait in a buffer of their own. let mut later: Vec<((u64, Delta), u64, u64)> = Vec::new(); let mut total = 0u64; @@ -1681,7 +1704,7 @@ impl Player { // SAFETY: an open list; live buffers. unsafe { list.CopyBufferRegion(&buffer, *to, staging, *at, *len) }; } - })?; + }).context("uploading later CPU writes")?; } Ok(()) } @@ -1720,6 +1743,7 @@ impl Player { } Cmd::Indirect { args, count, .. } => named.extend([*args, *count]), Cmd::ResolveQuery { dst, .. } => _ = named.insert(*dst), + Cmd::ClearUavFloat { view, .. } => _ = named.insert(view.res), _ => {} } } @@ -1789,6 +1813,7 @@ impl Player { Cmd::CopyBuffer { dst, .. } | Cmd::CopyResource { dst, .. } | Cmd::ResolveQuery { dst, .. } => _ = written.insert(*dst), + Cmd::ClearUavFloat { view, .. } => _ = written.insert(view.res), Cmd::CopyTexture { dst: Loc::Sub { res, .. } | Loc::Placed { res, .. }, .. @@ -2289,7 +2314,7 @@ impl Player { .map(|c| { 2 + if o.detailed { c.iter() - .filter(|c| c.works() || matches!(c, Cmd::Barriers { .. })) + .filter(|c| c.works() || c.is_barrier()) .count() } else { 0 @@ -2574,12 +2599,12 @@ impl Player { // SAFETY: an open list. unsafe { self.wait_for_all(list) }; } - let timed = c.works() || matches!(c, Cmd::Barriers { .. }); + let timed = c.works() || c.is_barrier(); if timed && let Some((heap, next)) = &mut stamp { // SAFETY: as above. unsafe { list.EndQuery(*heap, D3D12_QUERY_TYPE_TIMESTAMP, **next) }; let category = match c { - Cmd::Barriers { .. } => "barriers", + Cmd::Barriers { .. } | Cmd::GlobalSync {} => "barriers", Cmd::Dispatch { .. } if clamps.contains(&bound) => "argument clamps (ours)", Cmd::Dispatch { .. } if compares.contains(&bound) => { "hash and compare passes (ours)" @@ -2593,7 +2618,7 @@ impl Player { Cmd::Draw { .. } | Cmd::DrawIndexed { .. } | Cmd::DispatchMesh { .. } => { "draws" } - Cmd::ClearDepth { .. } | Cmd::ClearTarget { .. } | Cmd::Discard { .. } => { + Cmd::ClearDepth { .. } | Cmd::ClearTarget { .. } | Cmd::ClearUavFloat { .. } | Cmd::Discard { .. } => { "clears" } Cmd::Resolve { .. } | Cmd::ResolveRegion { .. } => "resolves", @@ -2806,6 +2831,7 @@ impl Player { all.iter().filter_map(|b| self.barrier(b)).collect(); barriers(l, &all); } + Cmd::GlobalSync {} => self.wait_for_all(l), Cmd::Heaps { heaps } => { let all: Vec> = heaps .iter() @@ -2943,6 +2969,18 @@ impl Player { l.ClearRenderTargetView(view(v), color, rects); } } + Cmd::ClearUavFloat { heap, index, view: v, color, rects } => { + if let Some((versions, step)) = self.descriptors.get(heap) + && let Some(version) = versions.get(version) + && let (Some(resource), Some(cpu)) = (res(v.res), self.targets.get(v)) + { + let gpu = D3D12_GPU_DESCRIPTOR_HANDLE { + ptr: version.gpu + u64::from(*index) * step, + }; + let rects: Vec = rects.iter().map(|r| to_rect(*r)).collect(); + l.ClearUnorderedAccessViewFloat(gpu, *cpu, resource, color, &rects); + } + } Cmd::Discard { res: id, rects, @@ -3160,10 +3198,10 @@ impl Player { /// One run of the frame, noted in the report; its timestamps. fn once(&mut self, o: &Options, (built, report): &mut (Sends, Report)) -> Result> { - self.restore(o.restore)?; + self.restore(o.restore).context("restoring the recorded frame")?; self.fresh = false; - let stamps = self.send(built, o)?; - if let Some((db, _, hash, _)) = self.picture_now()? { + let stamps = self.send(built, o).context("executing recorded command lists")?; + if let Some((db, _, hash, _)) = self.picture_now().context("reading the replayed picture")? { report.pictures.push((db, hash)); } let ms = |a: u32, b: u32| { @@ -3545,6 +3583,30 @@ fn make_device(frame: &Frame, debug: bool, breadcrumbs: bool) -> Result<(ID3D12D } } +fn log_replay_breadcrumbs(device: &ID3D12Device) { + let Ok(dred) = device.cast::() else { return }; + // SAFETY: DRED's arrays and linked nodes live as long as the device. + unsafe { + if let Ok(fault) = dred.GetPageFaultAllocationOutput1() + && fault.PageFaultVA != 0 + { + tracing::error!(va = format_args!("{:#x}", fault.PageFaultVA), "replay GPU page fault"); + } + if let Ok(crumbs) = dred.GetAutoBreadcrumbsOutput() { + let mut node = crumbs.pHeadAutoBreadcrumbNode; + for _ in 0..32 { + let Some(crumb) = node.as_ref() else { break }; + let done = crumb.pLastBreadcrumbValue.as_ref().copied().unwrap_or(0); + if done < crumb.BreadcrumbCount && !crumb.pCommandHistory.is_null() { + let op = *crumb.pCommandHistory.add(done as usize); + tracing::error!(done, total = crumb.BreadcrumbCount, op = op.0, "incomplete replay command list"); + } + node = crumb.pNext; + } + } + } +} + /// The debug layer's errors: how many of each kind, and its first text. fn debug_messages(q: &ID3D12InfoQueue) -> Vec { let mut seen: BTreeMap = BTreeMap::new(); diff --git a/crates/victory-gpu/src/replay/play/diverge.rs b/crates/victory-gpu/src/replay/play/diverge.rs index de9da17..8655b1b 100644 --- a/crates/victory-gpu/src/replay/play/diverge.rs +++ b/crates/victory-gpu/src/replay/play/diverge.rs @@ -487,10 +487,8 @@ impl Player { .iter() .filter(|c| { !c.works() - && !matches!( - c, - Cmd::Barriers { .. } | Cmd::BeginQuery { .. } | Cmd::EndQuery { .. } - ) + && !c.is_barrier() + && !matches!(c, Cmd::BeginQuery { .. } | Cmd::EndQuery { .. }) }) .cloned() .collect(); diff --git a/crates/victory-gpu/src/replay/play/look.rs b/crates/victory-gpu/src/replay/play/look.rs index 62df3bc..77a3714 100644 --- a/crates/victory-gpu/src/replay/play/look.rs +++ b/crates/victory-gpu/src/replay/play/look.rs @@ -174,7 +174,9 @@ pub fn flow( | Cmd::CopyResource { .. } | Cmd::Resolve { .. } | Cmd::ClearDepth { .. } - | Cmd::ClearTarget { .. } => line(&format!("{here}:{n} {c:?}")), + | Cmd::ClearTarget { .. } + | Cmd::ClearUavFloat { .. } + | Cmd::GlobalSync {} => line(&format!("{here}:{n} {c:?}")), c if c.runs_shaders() && (compute || draws) => { let name = pipelines.get(&pso).map_or("", |p| p.name.as_str()); line(&format!("{here}:{n} {c:?} pso {pso} {name}")); diff --git a/crates/victory-gpu/src/replay/record.rs b/crates/victory-gpu/src/replay/record.rs index 70a1fa4..a3be7cc 100644 --- a/crates/victory-gpu/src/replay/record.rs +++ b/crates/victory-gpu/src/replay/record.rs @@ -1076,6 +1076,8 @@ fn list_table(t: &mut [usize; hook::SLOTS]) { ID3D12GraphicsCommandList_Vtbl.SetPipelineState = set_pipeline ); set!(t, ID3D12GraphicsCommandList_Vtbl.ResourceBarrier = barrier); + set!(t, ID3D12GraphicsCommandList7_Vtbl.Barrier = enhanced_barrier); + set!(t, ID3D12GraphicsCommandList_Vtbl.ClearUnorderedAccessViewFloat = clear_uav_float); set!( t, ID3D12GraphicsCommandList_Vtbl.SetDescriptorHeaps = set_heaps @@ -1190,7 +1192,6 @@ fn list_rest(t: &mut [usize; hook::SLOTS]) -> &'static [(usize, &'static str)] { ID3D12GraphicsCommandList_Vtbl.ExecuteBundle, ID3D12GraphicsCommandList_Vtbl.SOSetTargets, ID3D12GraphicsCommandList_Vtbl.ClearUnorderedAccessViewUint, - ID3D12GraphicsCommandList_Vtbl.ClearUnorderedAccessViewFloat, ID3D12GraphicsCommandList_Vtbl.SetPredication, ID3D12GraphicsCommandList1_Vtbl.AtomicCopyBufferUINT, ID3D12GraphicsCommandList1_Vtbl.AtomicCopyBufferUINT64, @@ -1208,7 +1209,6 @@ fn list_rest(t: &mut [usize; hook::SLOTS]) -> &'static [(usize, &'static str)] { ID3D12GraphicsCommandList4_Vtbl.DispatchRays, ID3D12GraphicsCommandList5_Vtbl.RSSetShadingRate, ID3D12GraphicsCommandList5_Vtbl.RSSetShadingRateImage, - ID3D12GraphicsCommandList7_Vtbl.Barrier, ID3D12GraphicsCommandList8_Vtbl.OMSetFrontAndBackStencilRef, ID3D12GraphicsCommandList9_Vtbl.RSSetDepthBias, ID3D12GraphicsCommandList9_Vtbl.IASetIndexBufferStripCutValue, @@ -2317,6 +2317,32 @@ unsafe extern "system" fn barrier(this: Ptr, n: u32, all: *const D3D12_RESOURCE_ } } +unsafe extern "system" fn enhanced_barrier(this: Ptr, n: u32, groups: *const D3D12_BARRIER_GROUP) { + // SAFETY: the original call owns these arrays for the duration of the hook. + unsafe { + own!(this, ID3D12GraphicsCommandList7_Vtbl.Barrier)(this, n, groups); + if n == 0 { + return; + } + // This is the full-queue synchronization emitted by host::place. + let first = &*groups; + if n == 1 && first.Type == D3D12_BARRIER_TYPE_GLOBAL && first.NumBarriers == 1 { + let barrier = &*first.Anonymous.pGlobalBarriers; + if barrier.SyncBefore == D3D12_BARRIER_SYNC_ALL + && barrier.SyncAfter == D3D12_BARRIER_SYNC_ALL + && barrier.AccessBefore == D3D12_BARRIER_ACCESS_COMMON + && barrier.AccessAfter == D3D12_BARRIER_ACCESS_COMMON + { + note(this, |_| Cmd::GlobalSync {}); + return; + } + } + if let Some((r, _)) = of(this) { + r.problem("unsupported enhanced Barrier call is not recorded"); + } + } +} + unsafe extern "system" fn set_heaps(this: Ptr, n: u32, all: *const Ptr) { // SAFETY: as above. unsafe { @@ -2612,6 +2638,44 @@ unsafe extern "system" fn clear_target( } } +unsafe extern "system" fn clear_uav_float( + this: Ptr, + gpu: D3D12_GPU_DESCRIPTOR_HANDLE, + cpu: D3D12_CPU_DESCRIPTOR_HANDLE, + res: Ptr, + color: *const f32, + n: u32, + all: *const RECT, +) { + // SAFETY: the original call's pointers live through this hook. + unsafe { + own!(this, ID3D12GraphicsCommandList_Vtbl.ClearUnorderedAccessViewFloat)( + this, gpu, cpu, res, color, n, all, + ); + if let Some((r, state)) = of(this) + && r.armed.load(Ordering::Relaxed) + { + let gpu_slot = read(&r.descriptors).gpu(gpu.ptr).map(|(h, i)| (h.id, i)); + let view = r.view(cpu.ptr); + if let Some((heap, index)) = gpu_slot + && view.kind == slot::UAV + && view.res != NONE + && view.res == r.resource(res) + { + state.push(&Cmd::ClearUavFloat { + heap, + index, + view, + color: color.cast::<[f32; 4]>().read(), + rects: rects(n, all), + }); + } else { + r.problem("a floating-point UAV clear has an untracked resource or descriptor"); + } + } + } +} + unsafe extern "system" fn discard(this: Ptr, res: Ptr, region: *const D3D12_DISCARD_REGION) { // SAFETY: as above. unsafe { diff --git a/crates/victory-gpu/src/replay/wire.rs b/crates/victory-gpu/src/replay/wire.rs index a5623c2..f3b3ac7 100644 --- a/crates/victory-gpu/src/replay/wire.rs +++ b/crates/victory-gpu/src/replay/wire.rs @@ -373,12 +373,14 @@ wire_enum! { 31 Indirect { signature: u32, most: u32, args: u32, at: u64, count: u32, count_at: u64 }, 32 WriteImmediate { all: Vec<(Va, u32, i32)> }, 33 DepthBounds { min: f32, max: f32 }, + 34 GlobalSync {}, + 35 ClearUavFloat { heap: u32, index: u32, view: Slot, color: [f32; 4], rects: Vec<[i32; 4]> }, } } /// The highest kind number of [`Cmd`]. #[cfg(test)] -const LAST_CMD: u8 = 33; +const LAST_CMD: u8 = 35; impl Cmd { /// The commands of a list's bytes. @@ -403,12 +405,17 @@ impl Cmd { | Cmd::ResolveRegion { .. } | Cmd::ClearDepth { .. } | Cmd::ClearTarget { .. } + | Cmd::ClearUavFloat { .. } | Cmd::Discard { .. } | Cmd::ResolveQuery { .. } | Cmd::WriteImmediate { .. } ) } + pub fn is_barrier(&self) -> bool { + matches!(self, Cmd::Barriers { .. } | Cmd::GlobalSync {}) + } + /// Whether it runs the pipeline bound. pub fn runs_shaders(&self) -> bool { matches!( @@ -779,7 +786,7 @@ pub(crate) mod tests { }, Cmd::Discard { res: 1, - rects, + rects: rects.clone(), subs: Some([0, 2]), }, Cmd::BeginQuery { @@ -815,6 +822,14 @@ pub(crate) mod tests { min: 0.25, max: 0.75, }, + Cmd::GlobalSync {}, + Cmd::ClearUavFloat { + heap: 10, + index: 7, + view: view(), + color: [0.0, 1.0, 0.5, -0.25], + rects, + }, ] } diff --git a/crates/victory-gpu/tests/replay.rs b/crates/victory-gpu/tests/replay.rs index 9f80bc9..5817e93 100644 --- a/crates/victory-gpu/tests/replay.rs +++ b/crates/victory-gpu/tests/replay.rs @@ -26,6 +26,20 @@ use windows::core::{Interface, PCSTR, s, w}; const SIZE: u32 = 128; +fn enhanced_barriers(device: &ID3D12Device) -> bool { + let mut options = D3D12_FEATURE_DATA_D3D12_OPTIONS12::default(); + // SAFETY: a feature structure of the expected size. + unsafe { + device.CheckFeatureSupport( + D3D12_FEATURE_D3D12_OPTIONS12, + (&raw mut options).cast(), + size_of_val(&options) as u32, + ) + } + .is_ok() + && options.EnhancedBarriersSupported.as_bool() +} + const DRAW: &str = r#" #define RS "RootConstants(num32BitConstants=2, b0), CBV(b1), DescriptorTable(SRV(t0, numDescriptors=unbounded)), DescriptorTable(Sampler(s0))" cbuffer Pick : register(b0) { uint pick; uint pad; }; @@ -718,10 +732,13 @@ impl Scene { ..Default::default() }, Alignment: 0, - Flags: D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES, + Flags: D3D12_HEAP_FLAG_ALLOW_ONLY_NON_RT_DS_TEXTURES + | D3D12_HEAP_FLAG_CREATE_NOT_RESIDENT, }; device.CreateHeap(&desc, &mut memory).unwrap(); let memory = memory.unwrap(); + let pageable: ID3D12Pageable = memory.cast().unwrap(); + device.MakeResident(&[Some(pageable)]).unwrap(); let placed = || { let mut made: Option = None; let d = texture_desc(16, rgba, D3D12_RESOURCE_FLAG_NONE); @@ -1319,6 +1336,22 @@ impl Scene { ); l.ClearRenderTargetView(rtv, &[0.1 * n as f32, 0.2, 0.3, 1.0], None); l.ClearDepthStencilView(dsv, D3D12_CLEAR_FLAG_DEPTH, 1.0, 0, None); + if enhanced_barriers(&self.device) { + let list: ID3D12GraphicsCommandList7 = l.cast().unwrap(); + let global = 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: &global, + }, + }]); + } self.arguments(&l, COMMON); self.targets(&l); self.quad(&l, 4000, 0, 0); @@ -1384,6 +1417,36 @@ impl Scene { let second = l; let l = self.open(2); l.SetDescriptorHeaps(&[Some(self.views.clone())]); + let clear_heap: ID3D12DescriptorHeap = self.device.CreateDescriptorHeap( + &D3D12_DESCRIPTOR_HEAP_DESC { + Type: D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, + NumDescriptors: 1, + ..Default::default() + }, + ).unwrap(); + let clear_cpu = clear_heap.GetCPUDescriptorHandleForHeapStart(); + let clear_slot = 3999; + let clear_gpu = D3D12_GPU_DESCRIPTOR_HANDLE { + ptr: self.views.GetGPUDescriptorHandleForHeapStart().ptr + + clear_slot as u64 * self.step as u64, + }; + let clear_view = D3D12_UNORDERED_ACCESS_VIEW_DESC { + Format: DXGI_FORMAT_R32_FLOAT, + ViewDimension: D3D12_UAV_DIMENSION_BUFFER, + Anonymous: D3D12_UNORDERED_ACCESS_VIEW_DESC_0 { + Buffer: D3D12_BUFFER_UAV { + NumElements: 256, + ..Default::default() + }, + }, + }; + for at in [clear_cpu, self.cpu(clear_slot)] { + self.device.CreateUnorderedAccessView( + &self.sum, None::<&ID3D12Resource>, Some(&clear_view), at, + ); + } + l.ClearUnorderedAccessViewFloat(clear_gpu, clear_cpu, &self.sum, &[1.0; 4], &[]); + l.ResourceBarrier(&[uav_barrier()]); l.SetComputeRootSignature(&self.add.root); l.SetPipelineState(&self.add.pso); l.SetComputeRootShaderResourceView(0, self.shared.0.GetGPUVirtualAddress()); @@ -1706,6 +1769,15 @@ fn a_frame_is_recorded_and_replayed() { "{}", std::fs::read_to_string(folder.join("notes.txt")).unwrap() ); + let (mut syncs, mut clears) = (0, 0); + play::listing(&folder, (0, u32::MAX), &mut |line| { + syncs += usize::from(line.contains("GlobalSync")); + clears += usize::from(line.contains("ClearUavFloat")); + }).unwrap(); + assert_eq!(clears, 1, "one floating-point UAV clear captured"); + if enhanced_barriers(&device) { + assert_eq!(syncs, 1, "one global synchronization call captured"); + } let plain = Options { loops: 3, @@ -1741,7 +1813,7 @@ fn a_frame_is_recorded_and_replayed() { ); } assert_eq!(count("dispatches"), 6); - assert_eq!(count("clears"), 2); + assert_eq!(count("clears"), 3); assert!( report .shaders