VICTORY_PRELUDE_UPLOADS=1: title textures uploaded on the list's prelude, decided at submission after the check (off)
Ported from Belobug/VIctory-Belobug-AMD 5d6bd84 ("Upload title textures in
submission prelude to fix frame-order & flickering"), where it is the only
way. A list records the upload of a title texture it samples only if the
staging buffer was changed when the list was recorded; the check at
submission may then find the memory changed and detile it, and only the
next list that samples the texture uploads that: a frame late when every
list of the frame was recorded before the check (a video's ring of buffers
shows an older picture, a texture streamed in its last one). A candidate of
the flicker at scene loads (analysis 6.12).
With the switch, `texture::upload_from` records nothing in the list: it
leaves a `PreludeUpload` (staging buffer, host copy, levels on demand) with
the list, and its `Step::Texture` as before, so the checks run where they
ran. At submission, after the list's steps, the staging buffers left pending
are refreshed (`Batch::refresh_textures`), and each texture whose host copy
was never uploaded or whose staging buffer was detiled since its last upload
is claimed (`claim_upload`; once per change, whichever lists of the
submission sample it) and copied on the list's prelude (`HostList::prelude`):
aliasing barrier for a pooled texture's first upload, to the copy
destination state and from there to the state the list starts with. What
the list's own upload did after the copy (a host copy grown, levels on
demand given memory, what the host copy holds) is done at the claim.
Kept as before: bakes (they record their copies whatever the check finds)
and movie planes. Left out of the port: the texture store's prefill (this
tree has none), the fork's refreshes before every copy and run step (here
`title_written` flushes the textures due already), the fork's change of
`Step::Texture`'s payload (the upload is held beside it instead, so the steps'
other readers, `card_steps` and `place`, are untouched), and its panel
change (unrelated).
Off by default (not behaviour-neutral: when textures are uploaded changes).
Tests (from the fork): a claim per change, in the same submission; a ring of
three buffers never shows an older picture.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
ee3fb5201a
commit
91df493ead
3 files changed
+272
-4
No files matched your search
@@ -2333,6 +2333,9 @@ struct Deferred {
|
||||
uploads: Vec<ID3D12Resource>,
|
||||
/// Standalone upload footprints kept through this list's fence (movie planes).
|
||||
plane_uploads: Vec<(Chunk, u64)>,
|
||||
/// Title textures whose upload the list's prelude records if the check at
|
||||
/// submission finds it due (`crate::texture::prelude_uploads`).
|
||||
prelude_uploads: Vec<crate::texture::PreludeUpload>,
|
||||
/// The bytes of `uploads` (counted in [`ALIVE`] while they are held).
|
||||
upload_bytes: u64,
|
||||
/// Host objects the list's commands name (pipelines, root signatures,
|
||||
@@ -5757,7 +5760,9 @@ impl Host {
|
||||
for list in runs {
|
||||
list.run_deferred(&mut batch, &air, |i| own.as_ref().is_some_and(|own| own.takes(list, i)));
|
||||
firsts.push(lists.len());
|
||||
if let Some(prelude) = list.prelude() {
|
||||
// (None unless `VICTORY_PRELUDE_UPLOADS=1`.)
|
||||
let uploads = list.prelude_uploads(&mut batch);
|
||||
if let Some(prelude) = list.prelude(&uploads) {
|
||||
lists.push(Some(prelude));
|
||||
}
|
||||
lists.push(list.list.cast().ok());
|
||||
@@ -6819,8 +6824,12 @@ impl HostList {
|
||||
/// its real state to the one the list starts with; the textures' real
|
||||
/// states become those the list ends with. For depth textures with a
|
||||
/// colour twin it first copies the side the list uses as it finds it
|
||||
/// from the other, if a list submitted earlier left it behind.
|
||||
fn prelude(&self) -> Option<ID3D12CommandList> {
|
||||
/// from the other, if a list submitted earlier left it behind. Title
|
||||
/// textures whose upload is decided at submission (`uploads`,
|
||||
/// `crate::texture::prelude_uploads`) are copied into their host copies
|
||||
/// here, right before the list runs (Belobug/VIctory-Belobug-AMD
|
||||
/// 5d6bd84).
|
||||
fn prelude(&self, uploads: &[(crate::texture::PreludeUpload, bool)]) -> Option<ID3D12CommandList> {
|
||||
const COPY_DEST: u32 = 0x400;
|
||||
const COPY_SOURCE: u32 = 0x800;
|
||||
let host_state = |state: u32| D3D12_RESOURCE_STATES(state as i32);
|
||||
@@ -6875,13 +6884,45 @@ impl HostList {
|
||||
}
|
||||
}
|
||||
}
|
||||
// The uploads decided at submission: each host copy to the copy
|
||||
// destination state, and from there to the state the list starts
|
||||
// with (back to its real state if the list does not use it).
|
||||
let mut aliasing = Vec::new();
|
||||
for (upload, first_upload) in uploads {
|
||||
let copy = &upload.copy;
|
||||
let key = std::sync::Arc::as_ptr(copy) as usize;
|
||||
// A texture cut from a block may lie where another did: what the
|
||||
// card holds of that one is done with before the first upload
|
||||
// into this one.
|
||||
if crate::pool::on() && *first_upload {
|
||||
aliasing.push(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),
|
||||
// SAFETY: a borrowed pointer the barrier never releases.
|
||||
pResourceAfter: unsafe { std::mem::transmute_copy(©.texture) },
|
||||
}),
|
||||
},
|
||||
});
|
||||
}
|
||||
let real = copying.get(&key).copied().unwrap_or_else(|| copy.state.load(Ordering::Relaxed));
|
||||
if real != COPY_DEST {
|
||||
to_copy.push(transition(©.texture, host_state(real), host_state(COPY_DEST)));
|
||||
if !states.contains_key(&key) {
|
||||
barriers.push(transition(©.texture, host_state(COPY_DEST), host_state(real)));
|
||||
}
|
||||
}
|
||||
copying.insert(key, COPY_DEST);
|
||||
}
|
||||
barriers.extend(states.iter().filter_map(|(key, (first, last, copy))| {
|
||||
let real = copy.state.swap(*last, Ordering::Relaxed);
|
||||
let real = copying.get(key).copied().unwrap_or(real);
|
||||
(real != *first)
|
||||
.then(|| transition(©.texture, host_state(real), host_state(*first)))
|
||||
}));
|
||||
if barriers.is_empty() && syncs.is_empty() {
|
||||
if barriers.is_empty() && syncs.is_empty() && uploads.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let Some((allocator, list)) = self
|
||||
@@ -6896,12 +6937,18 @@ impl HostList {
|
||||
let recorded = unsafe {
|
||||
allocator.Reset().and_then(|()| {
|
||||
list.Reset(allocator, None)?;
|
||||
if !aliasing.is_empty() {
|
||||
list.ResourceBarrier(&aliasing);
|
||||
}
|
||||
if !to_copy.is_empty() {
|
||||
list.ResourceBarrier(&to_copy);
|
||||
}
|
||||
for (depth, twin, colour) in &syncs {
|
||||
record_twin_copy(list, &depth.texture, twin, *colour);
|
||||
}
|
||||
for (upload, _) in uploads {
|
||||
upload.record(list);
|
||||
}
|
||||
if !barriers.is_empty() {
|
||||
list.ResourceBarrier(&barriers);
|
||||
}
|
||||
@@ -7476,6 +7523,32 @@ impl HostList {
|
||||
self.deferred().copies.push(Step::Texture(staging));
|
||||
}
|
||||
|
||||
/// [`HostList::defer_texture`] of a texture whose upload the list's
|
||||
/// prelude records if the check finds it due
|
||||
/// (`crate::texture::prelude_uploads`; [`HostList::prelude_uploads`]).
|
||||
pub(crate) fn defer_prelude_upload(&self, upload: crate::texture::PreludeUpload) {
|
||||
let mut deferred = self.deferred();
|
||||
deferred.copies.push(Step::Texture(upload.staging()));
|
||||
deferred.prelude_uploads.push(upload);
|
||||
}
|
||||
|
||||
/// At submission, after the list's steps: the textures whose upload its
|
||||
/// prelude records, each with whether it is the first upload into its
|
||||
/// host copy. Their staging buffers are refreshed first (those the
|
||||
/// submission's steps left pending). Ported from
|
||||
/// Belobug/VIctory-Belobug-AMD 5d6bd84.
|
||||
fn prelude_uploads(&self, batch: &mut Batch) -> Vec<(crate::texture::PreludeUpload, bool)> {
|
||||
let waiting = self.deferred().prelude_uploads.clone();
|
||||
if waiting.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
batch.refresh_textures();
|
||||
waiting
|
||||
.into_iter()
|
||||
.filter_map(|upload| upload.finish_refresh().map(|first| (upload, first)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A copy source owned exclusively by this list until reset after its
|
||||
/// last execution. A different list can prepare its movie plane concurrently.
|
||||
pub(crate) fn plane_upload(
|
||||
|
||||
Reference in new issue
Block a user