VICTORY_POOL_SMALL=0: pooled textures at 64 KiB multiples (off); diagnostics: a pooled texture read past its piece is said
Ported from Belobug/VIctory-Belobug-AMD c278f0d. That fork places pooled textures of 64 KiB and less at 64 KiB multiples by default (4 KiB multiples only with VICTORY_POOL_SMALL=1): its two device losses with the pool on the night of 2026-11-25 faulted in 256x256 block-compressed textures with 7 levels placed at a 4 KiB multiple that is no 64 KiB one, whose descriptor base lay 0xa000 into the piece and whose first level ended 0x2000 past it, read by the card the moment the slot was made. Not proven to be the cause. Here the switch keeps its name and meaning, with our default: unset or 1, 4 KiB multiples where the host allows it, as before; VICTORY_POOL_SMALL=0, 64 KiB multiples (at most 60 KiB more card memory per small texture). Also an A/B switch in diag builds (VICTORY_AB). Diag builds with the address book say loudly when a pooled texture's first level lies past the end of its piece (`where_the_card_reads`, `book::address`), and where the first levels of the first 40 lie. The fork's test of a placed texture's reference to its heap is left out (a measurement of the host; the fork weakened it in 4cd2d13). Off by default: changes where pooled textures lie and how much card memory they take. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
13dca45ac6
commit
185bc4cc84
2 files changed
+112
-2
No files matched your search
@@ -242,6 +242,17 @@ fn viewable(format: i32) -> Option<i32> {
|
||||
})
|
||||
}
|
||||
|
||||
/// The address of `texture` as its descriptor has it (its first level's),
|
||||
/// if the book is kept.
|
||||
pub(crate) fn address(texture: &ID3D12Resource) -> Option<u64> {
|
||||
if !on() {
|
||||
return None;
|
||||
}
|
||||
// SAFETY: a live resource.
|
||||
let desc = unsafe { texture.GetDesc() };
|
||||
texture_address(texture, &desc)
|
||||
}
|
||||
|
||||
/// The address of a texture: the base its descriptor has.
|
||||
fn texture_address(texture: &ID3D12Resource, desc: &D3D12_RESOURCE_DESC) -> Option<u64> {
|
||||
struct Slot(ID3D12DescriptorHeap, usize);
|
||||
|
||||
@@ -459,6 +459,103 @@ unsafe extern "system" fn release(this: *mut c_void) -> u32 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Whether textures of 64 KiB and less are placed at multiples of 4 KiB in
|
||||
/// their block, where the host allows it (as before; `VICTORY_POOL_SMALL=0`:
|
||||
/// at multiples of 64 KiB, as every other texture).
|
||||
///
|
||||
/// Ported from Belobug/VIctory-Belobug-AMD c278f0d, where 64 KiB multiples
|
||||
/// are the default: the two device losses of the night of 2026-11-25 with
|
||||
/// the pool in that fork's report (runs steps-ab2 and start-3) faulted in
|
||||
/// the same kind of texture: 256x256, block-compressed, 7 levels, placed at
|
||||
/// a 4 KiB multiple that is no 64 KiB one (offsets 0x406000 and 0x3fe6000 of
|
||||
/// their blocks), never used before, read by the card the moment its slot
|
||||
/// was made; the descriptor's base of both lies 0xa000 into the piece, on a
|
||||
/// 64 KiB multiple, and its first level of 32 KiB from there ends 0x2000
|
||||
/// past the piece. Why the card faulted there is not proven; textures at
|
||||
/// 64 KiB multiples have none of that, for some memory (at most 60 KiB a
|
||||
/// small texture).
|
||||
fn small_placement() -> bool {
|
||||
#[cfg(feature = "diagnostics")]
|
||||
if let Some(on) = crate::ab::pick("VICTORY_POOL_SMALL") {
|
||||
return on;
|
||||
}
|
||||
static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
|
||||
*ON.get_or_init(|| std::env::var_os("VICTORY_POOL_SMALL").is_none_or(|v| v != "0"))
|
||||
}
|
||||
|
||||
/// Diagnostics: whether the card reads a pooled texture inside the piece it
|
||||
/// was placed in. A block's address is taken as the lowest of its textures'
|
||||
/// descriptor bases less their pieces' starts (a texture's first level may
|
||||
/// lie past its piece's start, never before it); a texture whose first level
|
||||
/// the card would read from past its piece's end is said loudly. (Ported
|
||||
/// from Belobug/VIctory-Belobug-AMD c278f0d.)
|
||||
#[cfg(feature = "diagnostics")]
|
||||
fn where_the_card_reads(heap: &ID3D12Heap, texture: &ID3D12Resource, piece: Piece) {
|
||||
static BLOCKS: Mutex<Vec<(usize, u64)>> = Mutex::new(Vec::new());
|
||||
static SAID: AtomicU64 = AtomicU64::new(0);
|
||||
let Some(base) = crate::book::address(texture) else { return };
|
||||
let Some(seen) = base.checked_sub(piece.start) else { return };
|
||||
let raw = heap.as_raw() as usize;
|
||||
let block = {
|
||||
let mut blocks = BLOCKS.lock().unwrap_or_else(|e| e.into_inner());
|
||||
match blocks.iter_mut().find(|b| b.0 == raw) {
|
||||
Some(b) => {
|
||||
b.1 = b.1.min(seen);
|
||||
b.1
|
||||
}
|
||||
None => {
|
||||
if blocks.len() >= 4096 {
|
||||
blocks.remove(0);
|
||||
}
|
||||
blocks.push((raw, seen));
|
||||
seen
|
||||
}
|
||||
}
|
||||
};
|
||||
let into = base - block - piece.start;
|
||||
// SAFETY: a live texture.
|
||||
let desc = unsafe { texture.GetDesc() };
|
||||
// The first level's bytes, as a copy would have them.
|
||||
let mut level = 0u64;
|
||||
if let Some(host) = crate::host::made_host() {
|
||||
// SAFETY: plain query of a valid description.
|
||||
unsafe { host.device.GetCopyableFootprints(&desc, 0, 1, 0, None, None, None, Some(&raw mut level)) };
|
||||
}
|
||||
if into + level > piece.len {
|
||||
let n = SAID.fetch_add(1, Ordering::Relaxed) + 1;
|
||||
if n <= 50 || n.is_power_of_two() {
|
||||
tracing::error!(
|
||||
times = n,
|
||||
base = format_args!("{base:#x}"),
|
||||
piece_start = format_args!("{:#x}", piece.start),
|
||||
piece_len = format_args!("{:#x}", piece.len),
|
||||
into = format_args!("{into:#x}"),
|
||||
first_level_bytes = format_args!("{level:#x}"),
|
||||
width = desc.Width,
|
||||
height = desc.Height,
|
||||
levels = desc.MipLevels,
|
||||
format = desc.Format.0,
|
||||
"POOL: the card reads a pooled texture's first level past the end of the piece it was placed in"
|
||||
);
|
||||
}
|
||||
}
|
||||
// Every placement offset and where the first level lies, a few of them.
|
||||
static SHOWN: AtomicU64 = AtomicU64::new(0);
|
||||
if into > 0 && SHOWN.fetch_add(1, Ordering::Relaxed) < 40 {
|
||||
tracing::info!(
|
||||
into = format_args!("{into:#x}"),
|
||||
piece_start = format_args!("{:#x}", piece.start),
|
||||
piece_len = format_args!("{:#x}", piece.len),
|
||||
width = desc.Width,
|
||||
height = desc.Height,
|
||||
levels = desc.MipLevels,
|
||||
format = desc.Format.0,
|
||||
alignment = desc.Alignment,
|
||||
"pool: a texture's first level lies past its piece's start"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Textures made in the last second ([`fresh`]), and when.
|
||||
static RECENT: Mutex<VecDeque<(usize, u64)>> = Mutex::new(VecDeque::new());
|
||||
|
||||
@@ -508,10 +605,11 @@ pub(crate) unsafe fn texture(
|
||||
return None;
|
||||
}
|
||||
// Small textures lie at multiples of 4 KiB where the host allows it
|
||||
// (the top mip is 64 KiB at most): 64 KiB each otherwise.
|
||||
// (the top mip is 64 KiB at most) and [`small_placement`] says so: 64 KiB
|
||||
// each otherwise.
|
||||
// SAFETY: the caller's description.
|
||||
let mut d = unsafe { *desc };
|
||||
d.Alignment = u64::from(D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT);
|
||||
d.Alignment = if small_placement() { u64::from(D3D12_SMALL_RESOURCE_PLACEMENT_ALIGNMENT) } else { 0 };
|
||||
// SAFETY: plain queries.
|
||||
let mut info = unsafe { device.GetResourceAllocationInfo(0, &[d]) };
|
||||
if info.SizeInBytes == u64::MAX || info.Alignment != d.Alignment {
|
||||
@@ -555,6 +653,7 @@ pub(crate) unsafe fn texture(
|
||||
#[cfg(feature = "diagnostics")]
|
||||
{
|
||||
crate::book::made(&made, || "a texture in a block".into());
|
||||
where_the_card_reads(&heap, &made, piece);
|
||||
crate::book::block(&heap, &made, piece.start, BLOCK);
|
||||
crate::book::note(made.as_raw() as usize, || {
|
||||
let block = lock(&TEXTURES).blocks.get(piece.block).and_then(Option::as_ref).map(|b| (b.made, b.since));
|
||||
|
||||
Reference in new issue
Block a user