The first copy into a texture the title fills goes over zeros
VICTORY_COPY_OVER_TITLE=title: over what title memory holds; =0: over whatever the block of the pool held. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
a0678ad1fa
commit
2c165e09cd
2 files changed
+61
-7
No files matched your search
@@ -1024,19 +1024,33 @@ extern "system" fn copy_texture_region(
|
||||
// source above too).
|
||||
list.twin_use(dst.resource, false, true);
|
||||
// The first copy into a texture of the title's: what it does not
|
||||
// write is what title memory holds, as on the console. (The host
|
||||
// write is zeros, as in a texture that was an allocation of its own
|
||||
// (`VICTORY_COPY_OVER_TITLE=title`: what title memory holds, which
|
||||
// may be another texture's: specks on the waitress's forehead were
|
||||
// left in run n04). (The host
|
||||
// copy is cut from a block and held whatever lay there, and no
|
||||
// upload is made once a copy wrote it: the atlas the title copies
|
||||
// its baked decorations into, a 2048x2048 BC3 texture of which a
|
||||
// bake writes 256x256 at most, was drawn over a character's face
|
||||
// with other textures' bytes wherever nothing was baked, runs n01 and
|
||||
// textures-1.)
|
||||
static OVER: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
if *OVER.get_or_init(|| std::env::var_os("VICTORY_COPY_OVER_TITLE").is_none_or(|v| v != "0"))
|
||||
&& crate::texture::title_written(to)
|
||||
&& !crate::texture::host_wrote(dst.resource as usize)
|
||||
{
|
||||
crate::texture::upload(list, dst.resource, to);
|
||||
static OVER: std::sync::OnceLock<u8> = std::sync::OnceLock::new();
|
||||
let over = *OVER.get_or_init(|| match std::env::var("VICTORY_COPY_OVER_TITLE").as_deref() {
|
||||
Ok("0") => 0,
|
||||
Ok("title") => 1,
|
||||
_ => 2,
|
||||
});
|
||||
if over != 0 && crate::texture::title_written(to) && !crate::texture::host_wrote(dst.resource as usize) {
|
||||
// One a list uploaded, or a draw sampled, holds the title's.
|
||||
if over == 2 && !list.used(dst.resource as usize) && !crate::texture::is_staged(dst.resource) {
|
||||
if let Some(host) = crate::host::host() {
|
||||
ensure_state(list, dst.resource, COPY_DEST);
|
||||
let _ = list.first_use(dst.resource as usize);
|
||||
crate::texture::zeros(list, host, to);
|
||||
}
|
||||
} else {
|
||||
crate::texture::upload(list, dst.resource, to);
|
||||
}
|
||||
// (Done before the title's copy writes over it.)
|
||||
if list.used(dst.resource as usize) {
|
||||
ensure_state(list, dst.resource, COPY_SOURCE);
|
||||
|
||||
@@ -937,6 +937,46 @@ impl Drop for Claimed {
|
||||
}
|
||||
}
|
||||
|
||||
/// Records copies of zeros into every subresource of `texture`, which is in
|
||||
/// the copy destination state.
|
||||
pub(crate) fn zeros(list: &HostList, host: &crate::host::Host, texture: &ID3D12Resource) {
|
||||
// SAFETY: a live resource.
|
||||
let d = unsafe { texture.GetDesc() };
|
||||
let layers = if d.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D { 1 } else { u32::from(d.DepthOrArraySize) };
|
||||
let count = u32::from(d.MipLevels) * layers;
|
||||
let mut footprints = vec![D3D12_PLACED_SUBRESOURCE_FOOTPRINT::default(); count as usize];
|
||||
let mut bytes = 0u64;
|
||||
// SAFETY: outputs for `count` subresources.
|
||||
unsafe {
|
||||
host.device
|
||||
.GetCopyableFootprints(&d, 0, count, 0, Some(footprints.as_mut_ptr()), None, None, Some(&mut bytes));
|
||||
}
|
||||
if bytes == 0 || bytes == u64::MAX {
|
||||
return;
|
||||
}
|
||||
let Some((buffer, data)) = list.upload(host, bytes) else {
|
||||
return;
|
||||
};
|
||||
// SAFETY: a mapped buffer of `bytes` bytes, just made.
|
||||
unsafe { std::ptr::write_bytes(data, 0, bytes as usize) };
|
||||
for (i, footprint) in footprints.iter().enumerate() {
|
||||
let to = D3D12_TEXTURE_COPY_LOCATION {
|
||||
// SAFETY: a borrowed pointer the location never releases.
|
||||
pResource: unsafe { std::mem::transmute_copy(texture) },
|
||||
Type: D3D12_TEXTURE_COPY_TYPE_SUBRESOURCE_INDEX,
|
||||
Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { SubresourceIndex: i as u32 },
|
||||
};
|
||||
let from = D3D12_TEXTURE_COPY_LOCATION {
|
||||
// SAFETY: as above; the list holds the buffer until it is reset.
|
||||
pResource: unsafe { std::mem::transmute_copy(&buffer) },
|
||||
Type: D3D12_TEXTURE_COPY_TYPE_PLACED_FOOTPRINT,
|
||||
Anonymous: D3D12_TEXTURE_COPY_LOCATION_0 { PlacedFootprint: *footprint },
|
||||
};
|
||||
// SAFETY: an open list; both locations name live resources.
|
||||
unsafe { list.list.CopyTextureRegion(&to, 0, 0, 0, &from, None) };
|
||||
}
|
||||
}
|
||||
|
||||
/// Levels on demand (`crate::tiles`): the card itself is about to write
|
||||
/// title texture `resource` in `list` (a copy or a resolve into level
|
||||
/// `level`, or into every level). If its host copy `texture` was made
|
||||
|
||||
Reference in new issue
Block a user