diff --git a/README.md b/README.md index 4010879d7c..ead407d881 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,14 @@ loads the world and shows it: slowly, and with rendering defects. Tested on one machine: Windows 11, AMD RX 6700 XT. +NVIDIA GPUs cap shader-visible view heaps at 10^6 slots, and the world uses +more (slot 1,236,191 and up). On such a GPU, shaders clamp indices below the +cap instead of faulting the device, and a slot past the kept ones reads an +empty or unrelated view (until 2026-11-25 the run ended +with "device removed", DXGI_ERROR_INVALID_CALL). Expect missing or wrong +objects. The shader cache is kept per heap size, so run `translate --cache` +again after switching GPUs. + > **Warning.** Entering the world on a real GPU has hung it in earlier > builds, and Windows then resets the display driver (every monitor goes > black for a moment). The latest runs did not, but it is not ruled out; a diff --git a/crates/victory-gpu/src/descriptor/host.rs b/crates/victory-gpu/src/descriptor/host.rs index 8b1867ad8d..2ddb218fb6 100644 --- a/crates/victory-gpu/src/descriptor/host.rs +++ b/crates/victory-gpu/src/descriptor/host.rs @@ -50,7 +50,8 @@ pub(crate) struct HostHeap { /// view there, `VIEW_MARK_NONE` for none. Mapped at the address kept /// beside it. marks: Option<(ID3D12Resource, usize)>, - /// Per title slot, the title address of the buffer view it holds, as a + /// Per slot (`indexed_slots`), the title address of the buffer view it + /// holds (0 past the title's slots), as a /// buffer descriptor's dwords 0 and 1 (shaders reading a descriptor's /// address as data, `crate::memory`): the buffer, its mapping and host /// address, made on first use. @@ -83,8 +84,9 @@ pub(crate) fn near_heaps(va: u64) -> String { } /// The host's limit for shader-visible view heaps on resource binding -/// tiers 1 and 2; tier 3 hardware may take more. -const PORTABLE_VIEWS: u32 = 1_000_000; +/// tiers 1 and 2; tier 3 hardware may take more. Translated shaders clamp +/// to it where the host takes no heap of `HEAP_VIEWS` (`host::create`). +pub(crate) const PORTABLE_VIEWS: u32 = 1_000_000; /// Slots past the title's in a view heap, for tables a draw needs made /// afresh (constant buffers copied per draw). A list holds the slots it @@ -93,9 +95,18 @@ const PORTABLE_VIEWS: u32 = 1_000_000; /// each a device removal shortly after; #59). const DYNAMIC: u32 = 1 << 18; +/// Entries in a per-slot table translated shaders read as a root view +/// (strides, marks, view addresses): every index they can compute. A root +/// view has no bounds, and they clamp indices below `heap_views`, at most +/// `HEAP_VIEWS`, which may pass the title's `count` (a capped heap keeps +/// fewer). A read past the table read past its buffer, and hung NVIDIA. +fn indexed_slots(count: u32) -> u32 { + count.max(victory_shader::emit::HEAP_VIEWS) +} + /// The dynamic slots of a heap whose host would not take [`DYNAMIC`] more /// (a capped heap, NVIDIA): the title's slots keep their room first. -const MIN_DYNAMIC: u32 = 1 << 16; +const MIN_DYNAMIC: u32 = victory_shader::emit::CAPPED_DYNAMIC; impl HostHeap { pub(crate) fn new(sampler: bool, count: u32) -> Option { @@ -121,12 +132,12 @@ impl HostHeap { // heap, and dynamic ones): shaders read the table as a root view, // which has no bounds, at indices clamped below `HEAP_VIEWS`. let strides = (!sampler) - .then(|| host.upload_buffer(u64::from(count.max(victory_shader::emit::HEAP_VIEWS)) * 4)) + .then(|| host.upload_buffer(u64::from(indexed_slots(count)) * 4)) .flatten() .map(|(buffer, data)| (buffer, data as usize)); let marks = (!sampler) .then(|| { - let bytes = u64::from(count.max(victory_shader::emit::HEAP_VIEWS)) * 8; + let bytes = u64::from(indexed_slots(count)) * 8; let (buffer, data) = host.upload_buffer(bytes)?; crate::host::name(&buffer, || "view marks".into()); // Every slot unmarked (all ones) until a view is made there. @@ -137,9 +148,15 @@ impl HostHeap { .flatten(); // The larger dynamic range only where the host takes it on top of // every title slot; else the smaller one, and the cap after that. - // Translated shaders clamp their indices below `HEAP_VIEWS` or + // Translated shaders clamp their indices below `heap_views` or // `HEAP_SAMPLERS`: slots up to there exist and stay null. - let (views, samplers) = (victory_shader::emit::HEAP_VIEWS, victory_shader::emit::HEAP_SAMPLERS); + // Each view heap also has room past the dynamic slots for the null + // buffer views (the 3 slots below `views`, `null_buffer_view`). + let (views, samplers) = (victory_shader::emit::heap_views(), victory_shader::emit::HEAP_SAMPLERS); + // A capped host: shaders clamp below `views`, so the heap is exactly + // that, its last slots null (a larger one would put title views + // where shaders expect null ones). + let fits = |extra: u32| views == victory_shader::emit::HEAP_VIEWS || count + extra + 3 <= views; let (heap, count, extra) = if sampler { match make(count.max(samplers)) { Ok(heap) => (heap, count, 0), @@ -148,18 +165,24 @@ impl HostHeap { return None; } } - } else if let Ok(heap) = make((count + DYNAMIC).max(views)) { + } else if fits(DYNAMIC) && let Ok(heap) = make((count + DYNAMIC + 3).max(views)) { (heap, count, DYNAMIC) + } else if fits(MIN_DYNAMIC) && let Ok(heap) = make((count + MIN_DYNAMIC + 3).max(views)) { + (heap, count, MIN_DYNAMIC) } else { - // shortcut: a host that caps its heaps below `HEAP_VIEWS` (NVIDIA) - // faults on an index past them, as before the clamp. - match make(count + MIN_DYNAMIC) { - Ok(heap) => (heap, count, MIN_DYNAMIC), - Err(e) if count + MIN_DYNAMIC > PORTABLE_VIEWS => { - // shortcut: descriptors past the host's limit are left - // out; a title that reaches them needs remapping. - tracing::warn!(error = %e, count, "host view heap capped at {PORTABLE_VIEWS}"); - (make(PORTABLE_VIEWS).ok()?, PORTABLE_VIEWS - MIN_DYNAMIC, MIN_DYNAMIC) + // shortcut: title slots past the host's cap (NVIDIA) are left + // out. The dynamic slots, then the null buffer views, take the + // heap's last slots. Shaders read a title index past the kept + // ones from the null last slot (`title_views`), not a dynamic + // slot's view (another draw's, a hang on NVIDIA). A title that + // draws with them needs remapping. + // `title_views()` where the host is capped; uncapped, the title + // still keeps room for the dynamic and null slots. + let title = views - MIN_DYNAMIC - 3; + match make(views) { + Ok(heap) => { + tracing::warn!(count, kept = title, "host view heap capped at {views}"); + (heap, count.min(title), MIN_DYNAMIC) } Err(e) => { tracing::warn!(error = %e, count, sampler, "no host descriptor heap"); @@ -196,7 +219,7 @@ impl HostHeap { kept: Mutex::new(vec![None; (count + extra) as usize]), next: Mutex::new((0, vec![false; extra as usize])), pairs: Mutex::new((count + extra, Vec::new())), - pairs_end: match victory_shader::emit::NULL_BUFFER_VIEW { + pairs_end: match victory_shader::emit::null_buffer_view() { null if !sampler && null > count + extra && null < total => null - 1, _ => total, }, @@ -220,7 +243,7 @@ impl HostHeap { // What shaders read instead of a slot without a buffer view where // they take one at a computed index (`victory_shader::emit`, "Buffer // views at computed heap indices"): a null raw SRV, and UAV below it. - let null = victory_shader::emit::NULL_BUFFER_VIEW; + let null = victory_shader::emit::null_buffer_view(); if !sampler && null > count + extra && null < total { h.raw_view_at(null, None, 0, 0, false); h.raw_view_at(null - 1, None, 0, 0, true); @@ -541,7 +564,7 @@ impl HostHeap { /// on first use from the slots made so far. pub(crate) fn view_addresses(&self) -> Option { let made = self.addresses.get_or_init(|| { - let (buffer, data) = host()?.upload_buffer(u64::from(self.count) * 8)?; + let (buffer, data) = host()?.upload_buffer(u64::from(indexed_slots(self.count)) * 8)?; crate::host::name(&buffer, || "view addresses".into()); let data = data as usize; let made = self.made.lock().unwrap_or_else(|e| e.into_inner()); @@ -752,40 +775,47 @@ fn uav_desc(words: &[u32; 10]) -> D3D12_UNORDERED_ACCESS_VIEW_DESC { /// The byte stride of a buffer view (its element size, at least 1), 0 for /// other views: what the view-stride table holds for it. fn view_stride(view: &View) -> u32 { + // Nonzero: shaders taking views at computed indices read the null buffer + // view where the table holds 0 (`victory_shader::emit`). + buffer_element(view).map_or(0, |(element, _)| element.max(1) as u32) +} + +/// A buffer view's element size and structure stride. +fn buffer_element(view: &View) -> Option<(u64, u32)> { let (unordered, words): (bool, &[u32; 10]) = match view { // Read as raw buffers (`make`). - View::Constant(..) => return 4, + View::Constant(..) => return Some((4, 0)), View::Shader(_, Some(desc)) => (false, desc), View::Unordered(_, _, Some(desc)) => (true, desc), View::Placed(unordered, resource, desc) if resource[0] == 1 => { match desc[..10].try_into() { Ok(words) => (*unordered, words), - Err(_) => return 0, + Err(_) => return None, } } - _ => return 0, + _ => return None, }; // The view dimension: buffer (1) for shader and unordered views alike. if words[1] != 1 { - return 0; + return None; } - let element = if unordered { + Some(if unordered { let desc = uav_desc(words); // SAFETY: a buffer view's union member. let buffer = unsafe { desc.Anonymous.Buffer }; - if buffer.StructureByteStride > 0 { + let element = if buffer.StructureByteStride > 0 { u64::from(buffer.StructureByteStride) } else if buffer.Flags.0 & D3D12_BUFFER_UAV_FLAG_RAW.0 != 0 { 4 } else { crate::resource::element(desc.Format.0 as u32).map_or(0, |(bytes, _)| bytes) - } + }; + (element, buffer.StructureByteStride) } else { - element_size(&srv_desc(words)) - }; - // Nonzero: shaders taking views at computed indices read the null buffer - // view where the table holds 0 (`victory_shader::emit`). - element.max(1) as u32 + let desc = srv_desc(words); + // SAFETY: a buffer view's union member. + (element_size(&desc), unsafe { desc.Anonymous.Buffer }.StructureByteStride) + }) } /// A buffer view of title memory at `address` on its host copy: the first @@ -849,7 +879,8 @@ pub(crate) fn buffer_range(view: &View) -> Option<(u64, u64)> { /// reads, [`crate::shadow::for_view`]) and the view's title range. pub(crate) fn view_copy(view: &View) -> Option<(std::sync::Arc, u64, u64)> { let (address, len) = buffer_range(view)?; - let (shadow, _) = crate::shadow::for_view(address, len, u64::from(view_stride(view)))?; + let (element, stride) = buffer_element(view)?; + let (shadow, _) = crate::shadow::for_view(address, len, copy_align(element, stride))?; Some((shadow, address, len)) } @@ -895,8 +926,9 @@ fn buffer_srv( } // The copy its own bytes are in, its first element counted from there. let start = address + buffer.FirstElement * element; + let align = copy_align(element, buffer.StructureByteStride); let Some((shadow, own)) = - crate::shadow::for_view(start, u64::from(buffer.NumElements) * element, element) + crate::shadow::for_view(start, u64::from(buffer.NumElements) * element, align) else { #[cfg(feature = "diagnostics")] if REFUSED.fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 200 { @@ -914,6 +946,12 @@ fn buffer_srv( once!(first, count, element, "buffer view empty or past its host copy"); return None; } + if let Some((first, count)) = as_raw(first, count, buffer.StructureByteStride) { + (buffer.FirstElement, buffer.NumElements) = (first, count); + buffer.StructureByteStride = 0; + buffer.Flags |= D3D12_BUFFER_SRV_FLAG_RAW; + desc.Format = DXGI_FORMAT_R32_TYPELESS; + } let host = host()?; // SAFETY: a live buffer and a slot of our heap. unsafe { @@ -923,6 +961,30 @@ fn buffer_srv( Some(Some((shadow.buffer.clone(), own.then_some(shadow)))) } +/// A structured view's range as a raw view's (4-byte words): translated +/// shaders read every structured buffer through a raw handle at byte +/// `index * stride + offset` (the stride may only be known at run time, from +/// the view-stride table), and some drivers (NVIDIA) read a structured view +/// through a raw handle wrongly. +fn as_raw(first: u64, count: u32, stride: u32) -> Option<(u64, u32)> { + (stride > 0 && stride.is_multiple_of(4)).then(|| { + let words = u64::from(stride / 4); + // The host's most elements in a buffer view (as `raw_view_at`). + (first * words, (u64::from(count) * words).min(1 << 27) as u32) + }) +} + +/// Where in its host copy a view of `element`-byte elements must start: on +/// an element, and a structured view (made raw, [`as_raw`]) also on 16 bytes +/// (`D3D12_RAW_UAV_SRV_BYTE_ALIGNMENT`). +fn copy_align(element: u64, stride: u32) -> u64 { + if as_raw(0, 0, stride).is_some() { + element << (4 - element.trailing_zeros().min(4)) + } else { + element + } +} + /// Whether `count` elements of `element` bytes from element `first` lie in /// `buffer`. The console takes a view that is empty or runs past its /// memory; the host removes the device for one. @@ -960,7 +1022,8 @@ fn buffer_uav( return None; } let start = address + buffer.FirstElement * element; - let (shadow, own) = crate::shadow::for_view(start, u64::from(buffer.NumElements) * element, element)?; + let align = copy_align(element, buffer.StructureByteStride); + let (shadow, own) = crate::shadow::for_view(start, u64::from(buffer.NumElements) * element, align)?; // SAFETY: a live buffer. let flags = unsafe { shadow.buffer.GetDesc() }.Flags; if flags.0 & D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS.0 == 0 { @@ -974,6 +1037,12 @@ fn buffer_uav( once!(first, count, element, "unordered buffer view empty or past its host copy"); return None; } + if let Some((first, count)) = as_raw(first, count, buffer.StructureByteStride) { + (buffer.FirstElement, buffer.NumElements) = (first, count); + buffer.StructureByteStride = 0; + buffer.Flags |= D3D12_BUFFER_UAV_FLAG_RAW; + desc.Format = DXGI_FORMAT_R32_TYPELESS; + } let host = host()?; // SAFETY: a live buffer and a slot of our heap. unsafe { @@ -1039,15 +1108,15 @@ fn fits(texture: &ID3D12Resource, castable: &[u32], mut format: Option<&mut DXGI } let view = format.as_ref().map_or(0, |f| f.0 as u32); if view == 0 { - return !typeless; + return !typeless && (!unordered || stores(own, own)); } let cast = castable.contains(&view); if family(view) != family(own) && !cast { once!(view, own, "view format of another family"); return false; } - if cast && family(view) != family(own) && unordered && !typed_store(view) { - once!(view, own, "an unordered view in a format the host cannot store"); + // The format the view gets (below): the title's, or the texture's own. + if unordered && !stores(if typeless || cast { view } else { own }, own) { return false; } if let Some(format) = format @@ -1073,6 +1142,17 @@ fn default_view(resource: crate::object::This) -> bool { other.is_none() } +/// Whether the host makes typed unordered views of `format` on a texture of +/// `own`: an optional feature for some formats (16-bit packed ones such as +/// B5G5R5A1 on NVIDIA), whose view without it removes the device. +fn stores(format: u32, own: u32) -> bool { + let ok = typed_store(format); + if !ok { + once!(format, own, "an unordered view in a format the host cannot store"); + } + ok +} + /// Whether the host stores to typed unordered views of `format`. fn typed_store(format: u32) -> bool { static KNOWN: Mutex> = Mutex::new(Vec::new()); @@ -1095,6 +1175,7 @@ fn typed_store(format: u32) -> bool { } .is_ok() && support.Support1.0 & D3D12_FORMAT_SUPPORT1_TYPED_UNORDERED_ACCESS_VIEW.0 != 0 + && support.Support2.0 & D3D12_FORMAT_SUPPORT2_UAV_TYPED_STORE.0 != 0 }); known.push((format, ok)); ok @@ -1428,6 +1509,18 @@ fn null_view(at: D3D12_CPU_DESCRIPTOR_HANDLE) { mod tests { use super::*; + /// f607780aa8e502d0 read the view addresses at a table index past a + /// capped heap's title slots: past the buffer (DEVICE_HUNG, GTX 1660). + #[test] + fn per_slot_tables_cover_every_index_a_shader_reads() { + use victory_shader::emit::HEAP_VIEWS; + // GTX 1660: heap capped at 10^6, 934461 title slots kept. + for (count, views) in [(934_461, 1_000_000), (1_245_184, HEAP_VIEWS), (10, HEAP_VIEWS)] { + assert!(indexed_slots(count) >= views, "{count} {views}"); + assert!(indexed_slots(count) >= count); + } + } + /// The world's 16-byte view of 0 elements removed the device. #[test] fn empty_and_overlong_buffer_views_are_refused() { @@ -1438,6 +1531,19 @@ mod tests { assert!(!within(64, u64::MAX, 1, 16)); } + /// Structured views become raw ones in words, at most the host's 2^27 + /// elements; other views stay as they are. + #[test] + fn structured_views_become_raw_within_the_element_limit() { + assert_eq!(as_raw(3, 10, 16), Some((12, 40))); + assert_eq!(as_raw(0, 1 << 24, 64), Some((0, 1 << 27))); + assert_eq!(as_raw(0, 10, 0), None); + assert_eq!(as_raw(0, 10, 6), None); + assert_eq!(copy_align(4, 4), 16); + assert_eq!(copy_align(24, 24), 48); + assert_eq!(copy_align(4, 0), 4); + } + /// A null texture UAV keeps the title's dimension (3D for the world's /// wind field), and is 2D when the title names none. #[test] @@ -1480,10 +1586,10 @@ mod tests { return; // no host GPU }; // Every index a translated shader can reach exists (clamped below - // `HEAP_VIEWS`, `HEAP_SAMPLERS`). + // `heap_views`, `HEAP_SAMPLERS`). // SAFETY: plain queries of live heaps. unsafe { - assert!(heap.heap.GetDesc().NumDescriptors >= victory_shader::emit::HEAP_VIEWS); + assert!(heap.heap.GetDesc().NumDescriptors >= victory_shader::emit::heap_views()); let samplers = HostHeap::new(true, 128).unwrap(); assert!(samplers.heap.GetDesc().NumDescriptors >= victory_shader::emit::HEAP_SAMPLERS); } diff --git a/crates/victory-gpu/src/draw.rs b/crates/victory-gpu/src/draw.rs index 3172caf810..6eda3e24ff 100644 --- a/crates/victory-gpu/src/draw.rs +++ b/crates/victory-gpu/src/draw.rs @@ -2465,7 +2465,10 @@ void main(uint3 id : SV_DispatchThreadID) { // SAFETY: a live buffer. unsafe { made.GetDesc() }.Width }; - assert_eq!(width(start + 456), 1 << 16, "on an element: the buffer's copy"); + // Host views of structured buffers are raw: on an element 16 bytes + // in (912), the buffer's copy; on one that is not (456), its own. + assert_eq!(width(start + 912), 1 << 16, "on an element: the buffer's copy"); + assert_eq!(width(start + 456), (4 * 456u64).next_multiple_of(256), "off 16 bytes: its own bytes"); assert_eq!(width(start + 100), (4 * 456u64).next_multiple_of(256), "off: its own bytes"); let (copy, address, len) = crate::descriptor::host::view_copy(&view(start + 100)).unwrap(); assert_eq!((copy.range(), address, len), ((start + 100, 4 * 456), start + 100, 4 * 456)); diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs index 09314c377c..158b0e0a04 100644 --- a/crates/victory-gpu/src/host.rs +++ b/crates/victory-gpu/src/host.rs @@ -223,6 +223,24 @@ fn create() -> windows::core::Result { let cpu_view_size = device.GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV); tracing::info!("host D3D12 device ready"); + // A host whose shader-visible view heaps stop below `HEAP_VIEWS` + // (NVIDIA): translated shaders clamp their heap indices below its + // cap instead, so a title slot past it reads null, not a fault. + let views = victory_shader::emit::HEAP_VIEWS; + if let Err(e) = device.CreateDescriptorHeap::( + &D3D12_DESCRIPTOR_HEAP_DESC { + Type: D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, + NumDescriptors: views, + Flags: D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, + NodeMask: 0, + }, + ) { + let cap = crate::descriptor::host::PORTABLE_VIEWS; + tracing::warn!(error = %e, views, cap, "host view heaps capped: shaders read slots past the cap as null"); + if !victory_shader::emit::set_heap_views(cap) { + tracing::error!(cap, "view-heap cap set after shaders read it"); + } + } // The console fuses its multiply-adds (`v_fma_f32`, `v_fmac_f32`, // `v_fma_mix*`); the lowering's DXIL `FMad` is fused only where the // host chooses (the RX 6700 XT does, WARP does not). diff --git a/crates/victory-gpu/src/pipeline/library.rs b/crates/victory-gpu/src/pipeline/library.rs index 9946221283..d9a923bac3 100644 --- a/crates/victory-gpu/src/pipeline/library.rs +++ b/crates/victory-gpu/src/pipeline/library.rs @@ -183,6 +183,7 @@ fn open(device: &ID3D12Device1, blob: Vec) -> Option { /// host descriptions). fn tag(blob: &[u8]) -> String { let limit = victory_shader::emit::loop_limit().to_le_bytes(); + let views = victory_shader::emit::heap_views().to_le_bytes(); let translator = victory_shader::SOURCE_HASH.as_bytes(); let mut h = blake3::Hasher::new(); for part in [ @@ -190,6 +191,7 @@ fn tag(blob: &[u8]) -> String { translator, include_bytes!("../shader_cache.rs"), &limit, + &views, include_bytes!("host.rs"), include_bytes!("library.rs"), ] { diff --git a/crates/victory-gpu/src/shader_cache.rs b/crates/victory-gpu/src/shader_cache.rs index 04af536ec7..5a86fafc4d 100644 --- a/crates/victory-gpu/src/shader_cache.rs +++ b/crates/victory-gpu/src/shader_cache.rs @@ -30,6 +30,8 @@ static MISSES: AtomicU64 = AtomicU64::new(0); /// Keeps translated shaders in a folder of `dir` from now on: the folder /// of this translator, `None` if it cannot be opened. pub fn use_shader_cache(dir: PathBuf) -> Option { + // The folder's key holds the host's heap cap, set as the host is made. + crate::host::host(); let dir = dir.join(&blake3::Hash::from(*build()).to_hex()[..16]); match Cache::open(&dir) { Ok(cache) => { @@ -53,7 +55,8 @@ pub fn counts() -> (u64, u64) { /// (`victory_shader::SOURCE_HASH`: its sources, manifest, the lock file and /// the compiler), the entry's encoding (this file's text) and the /// translation settings (the loop limit, which a diagnostics build can -/// change at run time). +/// change at run time; the view-heap slots shaders index, smaller on a host +/// that caps its heaps). fn build() -> &'static [u8; 32] { static BUILD: OnceLock<[u8; 32]> = OnceLock::new(); BUILD.get_or_init(|| { @@ -64,24 +67,27 @@ fn build() -> &'static [u8; 32] { "VICTORY_SHADER_LOOP_LIMIT: translated loops stop sooner" ); } - key(victory_shader::SOURCE_HASH, ENCODING, limit) + key(victory_shader::SOURCE_HASH, ENCODING, limit, victory_shader::emit::heap_views()) }) } /// This file, whose `encode` and `decode` define the entries. const ENCODING: &[u8] = include_bytes!("shader_cache.rs"); -fn key(translator: &str, encoding: &[u8], limit: u32) -> [u8; 32] { +fn key(translator: &str, encoding: &[u8], limit: u32, views: u32) -> [u8; 32] { let mut h = blake3::Hasher::new(); h.update(translator.as_bytes()); h.update(blake3::hash(encoding).as_bytes()); h.update(&limit.to_le_bytes()); + h.update(&views.to_le_bytes()); *h.finalize().as_bytes() } /// The translation of a console shader container, from the cache when /// there is one, and whether it came from there. pub fn host_shader(container: &[u8]) -> (Result, bool) { + // The host's heap cap is a translation setting, set as it is made. + crate::host::host(); // Writes through views mark their pages: copy-backs compare only those // (`crate::shadow::copy_back_marks`). let options = victory_shader::emit::Options { view_marks: true }; @@ -431,21 +437,23 @@ mod tests { } /// The key's parts: a change to any of them (the translator's sources, - /// this file's encoding, the loop limit) makes another key, so no entry + /// this file's encoding, the loop limit, the heap size) makes another key, so no entry /// written before it is read. #[test] fn the_key_covers_translator_encoding_and_settings() { - let k = key("0123456789abcdef", b"encoding", 1 << 20); - assert_eq!(k, key("0123456789abcdef", b"encoding", 1 << 20)); - assert_ne!(k, key("0123456789abcdee", b"encoding", 1 << 20)); - assert_ne!(k, key("0123456789abcdef", b"encoding.", 1 << 20)); - assert_ne!(k, key("0123456789abcdef", b"encoding", 1 << 19)); + let k = key("0123456789abcdef", b"encoding", 1 << 20, 1 << 21); + assert_eq!(k, key("0123456789abcdef", b"encoding", 1 << 20, 1 << 21)); + assert_ne!(k, key("0123456789abcdee", b"encoding", 1 << 20, 1 << 21)); + assert_ne!(k, key("0123456789abcdef", b"encoding.", 1 << 20, 1 << 21)); + assert_ne!(k, key("0123456789abcdef", b"encoding", 1 << 19, 1 << 21)); + assert_ne!(k, key("0123456789abcdef", b"encoding", 1 << 20, 1_000_000)); assert_eq!( *build(), key( victory_shader::SOURCE_HASH, ENCODING, - victory_shader::emit::loop_limit() + victory_shader::emit::loop_limit(), + victory_shader::emit::heap_views() ) ); // The encoding part is this file as built. diff --git a/crates/victory-shader/src/emit/host.rs b/crates/victory-shader/src/emit/host.rs index 76f2455004..b9d8c535d8 100644 --- a/crates/victory-shader/src/emit/host.rs +++ b/crates/victory-shader/src/emit/host.rs @@ -129,6 +129,23 @@ impl Host { } } + /// Whether the device takes a shader-visible view heap of + /// [`super::HEAP_VIEWS`] slots, as [`View::NullBuffers`] needs (NVIDIA + /// stops at 10^6). + pub fn takes_full_view_heap(&self) -> bool { + // SAFETY: a plain heap creation on a live device. + unsafe { + self.device + .CreateDescriptorHeap::(&D3D12_DESCRIPTOR_HEAP_DESC { + Type: D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV, + NumDescriptors: super::HEAP_VIEWS, + Flags: D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE, + ..Default::default() + }) + .is_ok() + } + } + /// The root signature translated shaders expect: user data per stage /// at `b0`, immediate samplers per stage at `s`, heaps directly /// indexed. @@ -1642,11 +1659,13 @@ impl Host { 0, D3D12_BUFFER_SRV_FLAG_NONE, ), + // Raw, as the runtime makes a structured view + // (its stride is in the view-stride table). Stride::Structured(s) => ( - DXGI_FORMAT_UNKNOWN, - data.len() * 4 / s as usize, - s, - D3D12_BUFFER_SRV_FLAG_NONE, + DXGI_FORMAT_R32_TYPELESS, + data.len() * 4 / s as usize * s as usize / 4, + 0, + D3D12_BUFFER_SRV_FLAG_RAW, ), Stride::Format(f, bytes) => ( f, diff --git a/crates/victory-shader/src/emit/lower.rs b/crates/victory-shader/src/emit/lower.rs index caab7ead5c..504ccaab9e 100644 --- a/crates/victory-shader/src/emit/lower.rs +++ b/crates/victory-shader/src/emit/lower.rs @@ -4067,6 +4067,8 @@ impl<'a> Lower<'a> { || un.contains("atomic") || used.is_some_and(|u| u.kind == ResourceType::Uav); let u = if uav { 0x1000 } else { 0 }; + // The bytes of a record, for a buffer counted in records. + let mut per = 0; let (props, image) = match &ui.fields { Fields::Image { dim, .. } => { let kind = match dim { @@ -4086,7 +4088,9 @@ impl<'a> Lower<'a> { { (10 | u, 0x409) } else if *idxen && format.is_none() && stride >= 4 && stride.is_multiple_of(4) { - (12 | u, stride) + // Host buffer views are raw: bytes, counted in records below. + per = stride; + (11 | u, 0) } else { (11 | u, 0) }; @@ -4105,7 +4109,10 @@ impl<'a> Lower<'a> { } let props = match used.stride { 0 | 1 => (11 | u, 0), - s if s.is_multiple_of(4) => (12 | u, s), + s if s.is_multiple_of(4) => { + per = s; + (11 | u, 0) + } _ => return Err("a scalar-loaded buffer of odd stride read as data"), }; (props, None) @@ -4162,6 +4169,11 @@ impl<'a> Lower<'a> { let d3 = self.s.m.bin(c, Bin::Or, base, last); vec![(1, d1), (2, d2), (3, d3), (4, depth)] } + None if per > 0 => { + let per = self.s.m.i32(per); + let bytes = field(self, 0); + vec![(2, self.s.m.bin(c, Bin::UDiv, bytes, per))] + } None => vec![(2, field(self, 0))], }; for k in 0..count { @@ -5032,12 +5044,13 @@ impl<'a> Lower<'a> { /// buffer one (a wild address: the texture's address shifted 8 bits /// down) and faulted the device. fn buffer_guard(&mut self, src: &Source, index: V, sampler: bool, props: (u32, u32)) -> V { + let index = self.title_guard(src, index, sampler); // Typed, raw and structured buffers (DXIL resource kinds 10-12). if sampler || !(10..=12).contains(&(props.0 & 0xFF)) || !self.is_heap_direct(src) { return index; } let c = self.cur; - let last = self.s.m.i32(super::HEAP_VIEWS - 1); + let last = self.s.m.i32(super::heap_views() - 1); let over = self.s.m.cmp(c, pred::IUGT, index, last); let index = self.s.m.select(c, over, last, index); let four = self.s.m.i32(4); @@ -5050,22 +5063,51 @@ impl<'a> Lower<'a> { let zero = self.s.m.i32(0); let none = self.s.m.cmp(c, pred::EQ, stride, zero); // The null unordered access view sits just below the null SRV. - let null = super::NULL_BUFFER_VIEW - u32::from(props.0 & 0x1000 != 0); + let null = super::null_buffer_view() - u32::from(props.0 & 0x1000 != 0); let null = self.s.m.i32(null); self.s.m.select(c, none, null, index) } - /// Whether a descriptor comes from the resource heap itself (root type - /// 5, not a table) on some path. - fn is_heap_direct(&self, src: &Source) -> bool { - src.leaves().iter().any(|l| match l { + /// `index`, or the heap's last slot (null) where a capped host heap + /// keeps no title slot there (module notes, "Heap indices"): for a + /// view taken from the resource heap itself on every path, an index at + /// or past [`super::title_views`] would read a dynamic slot, another + /// draw's view, perhaps of another kind (a GPU hang on NVIDIA, with no + /// page fault). Tables hold dynamic slots' indices and are left alone. + fn title_guard(&mut self, src: &Source, index: V, sampler: bool) -> V { + let title = super::title_views(); + if sampler || title == super::heap_views() || !self.all_heap_direct(src) { + return index; + } + let c = self.cur; + let first = self.s.m.i32(title); + let past = self.s.m.cmp(c, pred::IUGE, index, first); + let null = self.s.m.i32(super::heap_views() - 1); + self.s.m.select(c, past, null, index) + } + + /// Whether a descriptor comes from the resource heap itself on every + /// path. + fn all_heap_direct(&self, src: &Source) -> bool { + let leaves = src.leaves(); + !leaves.is_empty() && leaves.iter().all(|l| self.leaf_heap_direct(l)) + } + + fn leaf_heap_direct(&self, l: &Source) -> bool { + match l { Source::Loaded { load, .. } | Source::Fetched { load, .. } => self .scalar .get(load) .and_then(|a| self.x.native.layout.get(a.param)) .is_some_and(|p| p.root == RootType::ResourceHeap), _ => false, - }) + } + } + + /// Whether a descriptor comes from the resource heap itself (root type + /// 5, not a table) on some path. + fn is_heap_direct(&self, src: &Source) -> bool { + src.leaves().iter().any(|l| self.leaf_heap_direct(l)) } /// The heap index of a descriptor that may differ between lanes, @@ -8812,11 +8854,11 @@ impl<'a> Lower<'a> { if stride < 4 || !stride.is_multiple_of(4) { return Err("a structured buffer of unknown stride"); } - let h = self.handle(site, src, false, (12 | u, stride))?; + let h = self.handle(site, src, false, (11 | u, 0))?; let s = self.s.m.i32(stride); let row = self.s.m.bin(self.cur, Bin::Mul, index, s); let byte = self.s.m.bin(self.cur, Bin::Add, row, off); - (h, [index, off, iu], byte) + (h, [byte, iu, iu], byte) } None => { let (h, off) = self.raw_view(site, src, off, 4, (11 | u, 0), true, guard)?; @@ -8946,11 +8988,12 @@ impl<'a> Lower<'a> { if stride < 4 || !stride.is_multiple_of(4) { return Err("a structured buffer of unknown stride"); } - args.push(self.handle(site, src, false, (12 | u, stride))?); - args.extend([index, off]); + args.push(self.handle(site, src, false, (11 | u, 0))?); let s = self.s.m.i32(stride); let row = self.s.m.bin(self.cur, Bin::Mul, index, s); - (byte, bytes) = (self.s.m.bin(self.cur, Bin::Add, row, off), 4 * count); + byte = self.s.m.bin(self.cur, Bin::Add, row, off); + args.extend([byte, iu]); + bytes = 4 * count; } None => { let n = 4 * count; @@ -9054,14 +9097,17 @@ impl<'a> Lower<'a> { if stride < 4 || !stride.is_multiple_of(4) { return Err("a structured buffer of unknown stride"); } - let h = self.handle(site, src, false, (12 | u, stride))?; + let h = self.handle(site, src, false, (11 | u, 0))?; + let s = self.s.m.i32(stride); + let row = self.s.m.bin(c, Bin::Mul, index, s); + let byte = self.s.m.bin(c, Bin::Add, row, off); self.s.op( c, "rawBufferLoad.f32", Attr::ReadOnly, self.s.t.res_ret, 139, - &[h, index, off, mask, align], + &[h, byte, iu, mask, align], ) } None => { diff --git a/crates/victory-shader/src/emit/mod.rs b/crates/victory-shader/src/emit/mod.rs index 4e1fb2f92c..de6418e9cc 100644 --- a/crates/victory-shader/src/emit/mod.rs +++ b/crates/victory-shader/src/emit/mod.rs @@ -82,17 +82,19 @@ //! * **Rectangle lists** ([`rectangle_gs`]): a geometry shader made from a //! vertex shader's outputs completes each rectangle with its fourth //! corner `v0 + v2 - v1`, as the console's hardware does. -//! * **Heap indices** (added 2026-11-24) are clamped to [`HEAP_VIEWS`] − 1 +//! * **Heap indices** (added 2026-11-24) are clamped to [`heap_views`] − 1 //! (samplers [`HEAP_SAMPLERS`] − 1): the host's heaps have at least that //! many slots, those past its own null, so an index past the heap (data //! still wrong; the console would read whatever memory follows its heap) -//! reads nothing instead of faulting the device. +//! reads nothing instead of faulting the device. [`heap_views`] is +//! [`HEAP_VIEWS`], or the host's cap where its heaps stop below that +//! (NVIDIA, 10^6; 2026-11-25): title slots past the cap then read null. //! * **Buffer views at computed heap indices** (added 2026-11-24): a //! buffer read through a descriptor the shader takes from the resource //! heap itself first looks up the view-stride table (root SRV //! `t`[`VIEW_STRIDES`], which then covers every index below -//! [`HEAP_VIEWS`], dynamic slots too); where it holds 0 (no buffer view -//! there) the shader reads heap index [`NULL_BUFFER_VIEW`] instead (for +//! [`heap_views`], dynamic slots too); where it holds 0 (no buffer view +//! there) the shader reads heap index [`null_buffer_view`] instead (for //! unordered access the index below), which the host keeps a null raw //! buffer SRV (UAV). The index comes from data, and a texture descriptor //! read as a buffer one is a wild address (the texture's shifted 8 bits @@ -246,6 +248,50 @@ pub fn loop_limit() -> u32 { }) } +static HEAP_LIMIT: std::sync::OnceLock = std::sync::OnceLock::new(); + +/// The view-heap slots translated shaders index: heap indices are clamped +/// below this, and the null buffer views sit at its last slots +/// ([`null_buffer_view`]). [`HEAP_VIEWS`] unless the host set a smaller one +/// ([`set_heap_views`]) before the first translation. The value is part of +/// the translation, so the shader cache must key on it (`victory-gpu`'s +/// does). +pub fn heap_views() -> u32 { + *HEAP_LIMIT.get_or_init(|| HEAP_VIEWS) +} + +/// Sets [`heap_views`] for a host whose shader-visible view heaps stop +/// below [`HEAP_VIEWS`] (NVIDIA: 10^6), so an index past them reads a null +/// slot instead of faulting the device. Has no effect once read or set: +/// whether [`heap_views`] is now `views` (capped at [`HEAP_VIEWS`]). +pub fn set_heap_views(views: u32) -> bool { + let views = views.min(HEAP_VIEWS); + let _ = HEAP_LIMIT.set(views); + heap_views() == views +} + +/// The dynamic slots of a host view heap capped below [`HEAP_VIEWS`]: they +/// and the three null slots ([`null_buffer_view`]) follow the title's. +pub const CAPPED_DYNAMIC: u32 = 1 << 16; + +/// The title view slots a host heap keeps: [`heap_views`], or where the +/// host capped it below [`HEAP_VIEWS`], those before the +/// [`CAPPED_DYNAMIC`] dynamic slots and the null ones. Translated shaders +/// read a title index past them from the null last slot. +pub fn title_views() -> u32 { + capped_title(heap_views()) +} + +fn capped_title(views: u32) -> u32 { + if views < HEAP_VIEWS { views - CAPPED_DYNAMIC - 3 } else { views } +} + +/// The heap index of the host's null raw buffer SRV (the null raw UAV at +/// the index below): [`heap_views`] - 2. [`NULL_BUFFER_VIEW`] by default. +pub fn null_buffer_view() -> u32 { + heap_views() - 2 +} + /// `VICTORY_SHADER_LOOP_LIMIT`'s value; the default when it is unset, /// unreadable or 0. Pure, for testing. fn parse_loop_limit(value: Option<&str>) -> u32 { @@ -619,6 +665,16 @@ mod tests { use super::lower::LOOP_LIMIT; use super::parse_loop_limit; + /// A capped heap (NVIDIA, 10^6 views) keeps 934461 title slots: its + /// last 2^16 + 3 are the dynamic and null ones, which a title index + /// must not reach. An uncapped heap keeps every slot below it. + #[test] + fn a_capped_heap_keeps_title_slots_below_its_dynamic_ones() { + assert_eq!(super::capped_title(1_000_000), 934_461); + assert_eq!(super::capped_title(1_000_000) + super::CAPPED_DYNAMIC + 3, 1_000_000); + assert_eq!(super::capped_title(super::HEAP_VIEWS), super::HEAP_VIEWS); + } + #[test] fn the_loop_limit_switch_parses_or_falls_back() { assert_eq!(parse_loop_limit(None), LOOP_LIMIT); diff --git a/crates/victory-shader/src/emit/shader.rs b/crates/victory-shader/src/emit/shader.rs index e68e2627c9..70e143ec7b 100644 --- a/crates/victory-shader/src/emit/shader.rs +++ b/crates/victory-shader/src/emit/shader.rs @@ -520,7 +520,7 @@ impl Shader { self.nonuniform_handles += u32::from(nonuniform); // An index past the host's heap faults the device (a console shader // reads whatever memory follows its heap): the last slot instead. - let last = self.m.i32(if sampler { HEAP_SAMPLERS } else { HEAP_VIEWS } - 1); + let last = self.m.i32(if sampler { HEAP_SAMPLERS } else { super::heap_views() } - 1); let over = self.m.cmp(block, pred::IUGT, index, last); let index = self.m.select(block, over, last, index); let (s, n) = (self.m.bool(sampler), self.m.bool(nonuniform)); diff --git a/crates/victory-shader/src/emit/stride_tests.rs b/crates/victory-shader/src/emit/stride_tests.rs index fc160f5f98..7331cc845f 100644 --- a/crates/victory-shader/src/emit/stride_tests.rs +++ b/crates/victory-shader/src/emit/stride_tests.rs @@ -325,6 +325,10 @@ fn a_heap_buffer_read_where_no_buffer_view_is_reads_zeros() { eprintln!("no SM 6.6 {label} device; skipped"); continue; }; + if !host.takes_full_view_heap() { + eprintln!("{label} view heaps stop below HEAP_VIEWS; skipped"); + continue; + } let (root, pso) = host .compute_pipeline(&shader) .unwrap_or_else(|e| panic!("{label}: compute_pipeline failed: {e}")); diff --git a/docs/gpu-hang-investigation.md b/docs/gpu-hang-investigation.md new file mode 100644 index 0000000000..7d8b2d05ce --- /dev/null +++ b/docs/gpu-hang-investigation.md @@ -0,0 +1,118 @@ +# GPU hang in the world (DEVICE_HUNG), Series X and Series S + +Status: **fixed** (GTX 1660 Super). Last updated 2026-11-25. + +Branch fix/nvidia-heap-clamp (PR #2185). Fixed and committed there: the NVIDIA +INVALID_CALL removals (heap clamp 4d91d9d/8d5eaaa, raw structured views 16580cd, +unstorable texture UAVs a81ee21, review fixes 852b207), and this DEVICE_HUNG. + +## Cause and fix +The 1660 caps the view heap at 10^6 (`host view heap capped at 1000000 count=1245184 +kept=934461`). The per-slot view-addresses table (`HostHeap::view_addresses`, +crates/victory-gpu/src/descriptor/host.rs) was sized for `count` = 934461 slots. +Translated shaders read it through a root SRV, which has no bounds checks, at a heap +index clamped only below `heap_views` (10^6). That index can reach 999999, so a read +can land up to ~524 KB past the buffer. On NVIDIA that hung f607 with no DRED page fault. + +The strides and marks tables were already sized `count.max(HEAP_VIEWS)`. All three now +use `indexed_slots(count)`. Test: `per_slot_tables_cover_every_index_a_shader_reads`. + +Verified with the diag build plus DRED. No run after the fix had a device removal. +Every unfixed run hung between frames 1340 and 1603. +- Series X (vaddr1): no removal. At frame 1699 the run ended in a title crash: seven + int3s (0x80000003 at victory-image+0x5149aec), then WER. +- Series X (final1, the build after the review fixes): no removal. At frame 1797 it + ended with exit 139: an AV executing unmapped memory inside the NVIDIA driver + (nvwgf2umx.dll), called from victory.exe through D3D12Core. The log line before it + was `slow host submission ms=1684`, followed by mesh pipeline creation. +- Series S (vaddrS): no removal through frame 1929, when the 480 s run timed out. It + logged one first-chance AV in nvwgf2umx.dll+0x122db1c (read 0x0); the title + survived it. + +## New crashes past the old hang point (triaged: not reproduced, no emulator fault found) +Neither crash repeats, and neither points at emulator code. + +**Driver AV at frame 1797 (final1).** The stack runs from `pipeline::library::pipeline` +(the `create()` call, library.rs) through D3D12Core into nvwgf2umx.dll, on a pipeline +worker making a mesh pipeline. +- It executed 0x77fc4bd42980. nvwgf2umx.dll was mapped at 0x7ffc4bb70000 that boot + (same boot as the run). 0x7ffc4bd42980 is nvwgf2umx+0x1d2980. +- The bad target differs from that valid driver address in exactly one bit (bit 43). + A single flipped bit in a code pointer is the mark of a memory or CPU error, not of a + bad pipeline description. No WHEA event was logged, which non-ECC RAM would not + report anyway. +- Making every one of the title's 28164 pack pipelines offline (`translate --cache + --pipelines`) did not crash. The first pass stalled with 3 jobs for over 4 minutes + until its timeout. A rerun made the remaining 1098 jobs, those 3 included, in 40 s. + So the stall did not repeat. +- Suggested check on this host: a memory test, and stock CPU/RAM settings if any + overclock or curve offset is set. + +**Title int3 at frame 1699 (vaddr1).** victory-image+0x5149aec is the fatal trap of a +lock-free pool allocator. It fires when the free list is empty (head index 0x1fffe) or +the pool has no storage. The function picks one of two pools by a type byte: +| pool (title global) | entry | capacity | +|---|---|---| +| 0x14a9ec938 | 0xe0 bytes | 22500 | +| 0x14abbe2e8 | 0x110 bytes | 27500 | + +Pool header: +0x0 storage, +0x8 entry size, +0xc capacity, +0x10 live count, +0x20 free +head, +0x28 links. A run polled both pools every 2 s (pool1, Series X, 480 s). It +reached frame 1928 with no crash. Pool A peaked at 9714 live entries and pool B +at 4901. Both rose and fell with the scene and leveled off at the end, with no +growth trend and under 45% of capacity. A leak that the emulator causes would show as +steady growth. Exhausting the pool from there in one frame is unlikely; a corrupted +head index (see the bit flip above) would also hit this trap. + +**Title AV at frame 6942 (manual run, open).** A long manual run (the title's crash +report says `Xbox Series X`) faulted at victory-image+0x7b61a7, reading 0x8. The +code is `mov (%rdi),%r15; call *0x8(%r15)`: a virtual call on the object at +0x6ca4e1220, whose first qword (its vtable) is 0. The object was freed, zeroed or +never set up. This is a different site from the two crashes above, and no flipped bit +shows in the registers. One crash so far does not tell a title bug from the emulator +writing over title memory. The next step is to find what writes zeros there. + +Runs past the old hang point: vaddr1 (int3, 1699), final1 (AV, 1797), vaddrS (none, +1929), pool1 (none, 1928), finalS (none, 1937, Series S, 400 s, clean HEAD), manual +(AV, 6942). + +## Series S +- The old exit-139 segfault does not reproduce (`run --console series-s`). +- Before the fix it stopped at frame ~1515 with the same DEVICE_HUNG as Series X. + It is the same bug, not a Series S-only one. +- After the fix: no removal through frame 1929, when the 480 s run timed out. + +## The hang (before the fix) +- 0x887A0006 between frames ~1340 and ~1603. +- DRED: the hung command is `indirect kind 2 max 1 [compute f607780aa8e502d0]` + (args at title 0xd9358fe80). +- Skipping only f607780aa8e502d0: no removal through frame 1699. + Skipping 741447eb077ae6d3 (the voxel grid writer) also avoids it. +- f607 is a BVH traversal (emulated image_bvh64_intersect_ray, LDS short stack, two + loops each capped at 0xffff by the shader). + +## Leads ruled out +1. **Loop count.** With VICTORY_SHADER_LOOP_LIMIT=16 it still hung on the same command + at frame 1341. +2. **Group count.** With every indirect dispatch clamped to one group it still hung at + frame 1467. No DRED page fault was reported. +3. **Uncounted loops.** f607's only back edges both carry the per-lane counter. There is + no `s_barrier`. +4. **Wave-op or atomic spin.** waveReadLaneFirst appears only outside the loops. LDS uses + only store and atomicrmw xchg. +5. **Dirty-bitmap atomics.** Skipping the memory-dirty OR still hung (frame 1455). +6. **LDS out of range.** The groupshared array is 512 dwords and every address is masked + with `and 2044`. +7. **BVH node data.** Zeroing every node dword still hung on the same command (frame 1463). +8. **Title indices reaching dynamic slots.** `title_guard` (emit/lower.rs) sends a title + index at or past `title_views()` to the null last slot. It still hung at frame 1603, + so this was not the cause. It is kept as a correctness fix: such an index read + another draw's view, perhaps of another kind. + +## Open, not addressed +- `heap_handle` clamps an index to the last slot, which holds a Texture2D null SRV. + A buffer or UAV handle clamped there is a type mismatch. No hang has been seen from it. +- Review follow-up: on a capped host the heap is now exactly `heap_views()` slots unless + the title plus its dynamic and null slots fit under it. A larger heap would put title + views at the null slots shaders clamp to. The uncapped fallback keeps + `views - MIN_DYNAMIC - 3` title slots again.