From 0f2e2d265f75048102eeb90024fa53d4e5309c9f Mon Sep 17 00:00:00 2001 From: raylitebull <287713799+raylitebull@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:24:35 +0100 Subject: [PATCH 1/2] UMA: support 8 and 16 heap-backed windows with multi-coherent pools and sparse GPU-view mirrors --- crates/xcl/src/gpu/dxil/kernel.rs | 3 +- crates/xcl/src/gpu/recomp/emit.rs | 5 +- crates/xcl/src/gpu/recomp/mod.rs | 8 + crates/xcl/src/gpu/recomp/runner.rs | 10 +- crates/xcl/src/gpu/uma.rs | 266 ++++++++++++++++++---- crates/xcl/src/hle/d3d12x/console_heap.rs | 27 ++- crates/xcl/src/hle/d3d12x/real.rs | 7 + crates/xcl/src/hle/kernelx.rs | 46 +++- 8 files changed, 308 insertions(+), 64 deletions(-) diff --git a/crates/xcl/src/gpu/dxil/kernel.rs b/crates/xcl/src/gpu/dxil/kernel.rs index d28a2ffcb..118a1d6ca 100644 --- a/crates/xcl/src/gpu/dxil/kernel.rs +++ b/crates/xcl/src/gpu/dxil/kernel.rs @@ -130,7 +130,8 @@ fn translate_entry(code: &[u8], o: KernelOptions, entry: Entry) -> Result (Vec, Option) { let heap = mem_windows & crate::gpu::recomp::HEAP_WINDOWS != 0; - let n = (mem_windows & !crate::gpu::recomp::HEAP_WINDOWS).clamp(1, 4); + let max = if heap { crate::gpu::uma::MAX_HEAP_WINDOWS as u32 } else { crate::gpu::uma::MAX_WINDOWS as u32 }; + let n = (mem_windows & !crate::gpu::recomp::HEAP_WINDOWS).clamp(1, max); if heap && n > 1 { let z = s.m.i32c(0); return (vec![RawUav { handle: z, binding: None }; n as usize], Some(coherent)); diff --git a/crates/xcl/src/gpu/recomp/emit.rs b/crates/xcl/src/gpu/recomp/emit.rs index 96966005b..3d13fd060 100644 --- a/crates/xcl/src/gpu/recomp/emit.rs +++ b/crates/xcl/src/gpu/recomp/emit.rs @@ -4243,10 +4243,11 @@ impl Em { // other groups wrote) relies on GLC / cache invalidation on the console: keep the flat // memory coherent across the GPU there; graphics keeps the cached (faster) view let coherent = if matches!(self.opt.mode, Mode::Compute(_)) { "globallycoherent " } else { "" }; - let windows = self.opt.mem_windows.clamp(1, 4); + let max_win = if self.opt.heap_windows { crate::gpu::uma::MAX_HEAP_WINDOWS as u32 } else { crate::gpu::uma::MAX_WINDOWS as u32 }; + let windows = self.opt.mem_windows.clamp(1, max_win); let _ = writeln!(h, "{coherent}RWByteAddressBuffer mem : register(u2);"); if windows > 1 { - for k in 1..windows { + for k in 1..windows.min(crate::gpu::uma::MAX_WINDOWS as u32) { let _ = writeln!(h, "{coherent}RWByteAddressBuffer mem{k} : register(u{});", 2 + k); } h.push_str("static uint xcl_w = 0u;\nstatic uint xcl_uma_base = 0u;\n"); diff --git a/crates/xcl/src/gpu/recomp/mod.rs b/crates/xcl/src/gpu/recomp/mod.rs index 1a1a8ba79..9efa71767 100644 --- a/crates/xcl/src/gpu/recomp/mod.rs +++ b/crates/xcl/src/gpu/recomp/mod.rs @@ -76,6 +76,11 @@ pub const MEM_HEAP_BASE: u32 = 0; /// Flag in a memory-windows count (`pso::mem_windows`, the translation caches' keys): /// `Options::heap_windows`. `translate` takes it out of `mem_windows`. pub const HEAP_WINDOWS: u32 = 0x100; + +pub(crate) fn valid_window_count(windows: usize, heap: bool) -> bool { + windows <= crate::gpu::uma::MAX_WINDOWS + || (heap && windows.is_power_of_two() && windows <= crate::gpu::uma::MAX_HEAP_WINDOWS) +} pub mod upper_lanes; use std::collections::{BTreeMap, BTreeSet}; @@ -1397,6 +1402,9 @@ pub fn translate(code: &[u8], opt: &Options) -> Result { } else { opt }; + if !valid_window_count(opt.mem_windows as usize, opt.heap_windows) { + return Err(format!("unsupported shader memory layout: {} windows (heap: {})", opt.mem_windows, opt.heap_windows)); + } let mut insts: Vec = Vec::new(); let mut off = 0usize; while off + 4 <= code.len() { diff --git a/crates/xcl/src/gpu/recomp/runner.rs b/crates/xcl/src/gpu/recomp/runner.rs index 7ddd3889b..5f08c01e4 100644 --- a/crates/xcl/src/gpu/recomp/runner.rs +++ b/crates/xcl/src/gpu/recomp/runner.rs @@ -1516,16 +1516,17 @@ fn run_in_region(dxil: &[u8], state: &KernelState, arena: &Arena) -> Result, Some(&raw_window_uav(mem_bytes)), h); diff --git a/crates/xcl/src/gpu/uma.rs b/crates/xcl/src/gpu/uma.rs index 82eac9e53..91c8c38fe 100644 --- a/crates/xcl/src/gpu/uma.rs +++ b/crates/xcl/src/gpu/uma.rs @@ -3,10 +3,11 @@ //! that D3D12 can open as heaps (`ID3D12Device3::OpenExistingHeapFromAddress`), so the GPU //! works on them directly. //! -//! A heap is smaller than 4 GiB, so the memory is up to 4 *windows*: window k is one region -//! at `base + k · 4 GiB` with `base` 16 GiB-aligned. The window of a console GPU address is -//! then `(address >> 32) & 3` and its low 32 bits are the offset in that window's heap – the -//! recompiler's `mem` (window 0), `mem1` … buffers. Allocations never straddle windows. +//! A heap is smaller than 4 GiB, so memory is split into windows at `base + k · 4 GiB`. +//! The aperture has 4 windows by default and can grow to 8 or 16 with heap-backed shaders +//! (`XCL_HEAP_WINDOWS=1` + `XCL_UMA_WINDOWS=8|16`). The base is aligned to the aperture size, +//! so shaders compute the window index from `(address >> 32) - (base >> 32)` and the byte +//! offset from the low 32 bits. Allocations never straddle windows. //! //! Measured on Windows 11 + RX 9070 (2026-11-20): the heap must cover a fully committed //! `VirtualAlloc` allocation (a reservation with partial commit is rejected); up to @@ -26,7 +27,64 @@ pub const GRAIN: usize = 0x1_0000; pub const MAX_SIZE: usize = (4096 << 20) - GRAIN; /// distance between windows pub const WINDOW: usize = 1 << 32; +/// Legacy layout and the number of memory UAVs in the ABI root signature. pub const MAX_WINDOWS: usize = 4; +/// Maximum number of windows addressable through the shared descriptor heap (`XCL_HEAP_WINDOWS=1`). +pub const MAX_HEAP_WINDOWS: usize = 16; + +/// Maximum number of committed coherent windows in an expanded runtime layout. +/// Always leaves at least 3 sparse VRAM windows (12 GiB). +fn max_coherent_windows(windows: usize) -> usize { + if windows > MAX_WINDOWS { + windows.saturating_sub(3).min(4).max(1) + } else { + 1 + } +} + +/// Maximum total committed coherent bytes for a runtime layout of `windows` windows. +fn max_coherent_bytes(windows: usize) -> usize { + max_coherent_windows(windows) * MAX_SIZE +} + +/// Split `total_coh` coherent bytes across `1..=max_coherent_windows(windows)` committed windows. +fn coherent_window_sizes(size: usize, coherent: usize, windows: usize) -> Vec { + let max_coh = max_coherent_windows(windows); + let total_coh = size + .min(coherent.max(RUNTIME_COMMITTED_CAP)) + .clamp(GRAIN, max_coh * MAX_SIZE); + let coh_wins = total_coh.div_ceil(MAX_SIZE).clamp(1, max_coh); + let mut coh_sizes = Vec::with_capacity(coh_wins); + let mut rem = total_coh; + for _ in 0..coh_wins { + let chunk = ((rem.min(MAX_SIZE) + GRAIN - 1) & !(GRAIN - 1)).clamp(GRAIN, MAX_SIZE); + coh_sizes.push(chunk); + rem = rem.saturating_sub(chunk); + } + coh_sizes +} + +/// Exclusive upper bound for candidate 4 GiB window slot indices. +/// Expanded apertures stay below the 40-bit console GPU VA limit (`1 TiB`). +fn slot_limit(windows: usize) -> usize { + if windows > MAX_WINDOWS { 1 << (40 - 32) } else { 512 } +} + +/// Requested runtime UMA window count (`XCL_UMA_WINDOWS=4|8|16`, default 4). +/// Layouts wider than 4 windows require `XCL_HEAP_WINDOWS=1`. +pub(crate) fn configured_runtime_windows() -> usize { + let Ok(val) = std::env::var("XCL_UMA_WINDOWS") else { return MAX_WINDOWS }; + let n = val.trim().parse::().unwrap_or(0); + if !matches!(n, MAX_WINDOWS | 8 | MAX_HEAP_WINDOWS) { + crate::xlog_warn!("UMA: XCL_UMA_WINDOWS={val:?} must be 4, 8, or 16 – using {MAX_WINDOWS}"); + return MAX_WINDOWS; + } + if n > MAX_WINDOWS && !crate::gpu::recomp::pso::heap_windows() { + crate::xlog_warn!("UMA: XCL_UMA_WINDOWS={n} requires XCL_HEAP_WINDOWS=1 – using {MAX_WINDOWS}"); + return MAX_WINDOWS; + } + n +} /// bytes of sparse window 0 only 32-bit descriptor heaps get (`Uma::desc_range`) const DESC_HEADROOM: usize = 512 << 20; @@ -42,7 +100,7 @@ enum WindowKind { pub struct Uma { base: usize, - kinds: [WindowKind; MAX_WINDOWS], + kinds: Vec, /// VirtualAlloc base pointers owned by this Uma (freed on Drop) win_allocs: Vec, inner: Mutex, @@ -167,9 +225,23 @@ impl Uma { /// `for_runtime` with a coherent window of up to `coherent` bytes (`coherent_hint`). pub fn for_runtime_with(size: usize, coherent: usize) -> Option { - let committed = ((size.min(coherent.max(RUNTIME_COMMITTED_CAP)) + GRAIN - 1) & !(GRAIN - 1)).clamp(GRAIN, MAX_SIZE); - let sparse_len = (MAX_WINDOWS - 1) * WINDOW; - for slot in (4usize..512).step_by(MAX_WINDOWS) { + Self::reserve_runtime(size, coherent, MAX_WINDOWS).or_else(|| Self::new(size)) + } + + /// `for_runtime_with` using `windows` total shader-visible windows: `windows - coh_wins` + /// sparse VRAM windows followed by `coh_wins` committed coherent windows sized to hold + /// `coherent` bytes (up to `max_coherent_windows(windows)`). + pub fn for_runtime_windows(size: usize, coherent: usize, windows: usize) -> Option { + let windows = if matches!(windows, MAX_WINDOWS | 8 | MAX_HEAP_WINDOWS) { windows } else { MAX_WINDOWS }; + Self::reserve_runtime(size, coherent, windows) + } + + fn reserve_runtime(size: usize, coherent: usize, windows: usize) -> Option { + let coh_sizes = coherent_window_sizes(size, coherent, windows); + let coh_wins = coh_sizes.len(); + let sparse_wins = windows - coh_wins; + let sparse_len = sparse_wins * WINDOW; + for slot in (windows..slot_limit(windows)).step_by(windows) { let base = slot << 32; let sp = unsafe { VirtualAlloc(base as *const std::ffi::c_void, sparse_len, MEM_RESERVE | MEM_WRITE_WATCH, PAGE_READWRITE) }; if sp as usize != base { @@ -178,23 +250,40 @@ impl Uma { } continue; } - let c_base = base + (MAX_WINDOWS - 1) * WINDOW; - let cp = unsafe { VirtualAlloc(c_base as *const std::ffi::c_void, committed, MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, PAGE_READWRITE) }; - if cp as usize != c_base { - if !cp.is_null() { - unsafe { VirtualFree(cp, 0, MEM_RELEASE) }; + let mut win_allocs = Vec::with_capacity(1 + coh_wins); + win_allocs.push(base); + let mut ok = true; + for (c, &c_size) in coh_sizes.iter().enumerate() { + let c_base = base + (sparse_wins + c) * WINDOW; + let cp = unsafe { VirtualAlloc(c_base as *const std::ffi::c_void, c_size, MEM_RESERVE | MEM_COMMIT | MEM_WRITE_WATCH, PAGE_READWRITE) }; + if cp as usize != c_base { + if !cp.is_null() { + unsafe { VirtualFree(cp, 0, MEM_RELEASE) }; + } + ok = false; + break; + } + win_allocs.push(c_base); + } + if !ok { + for p in win_allocs { + unsafe { VirtualFree(p as *mut std::ffi::c_void, 0, MEM_RELEASE) }; } - unsafe { VirtualFree(sp, 0, MEM_RELEASE) }; continue; } let mut inner = Inner::default(); - inner.free.insert((MAX_WINDOWS - 1) * WINDOW, committed); + let mut kinds = vec![WindowKind::Sparse; windows]; + for (c, &c_size) in coh_sizes.iter().enumerate() { + let k = sparse_wins + c; + inner.free.insert(k * WINDOW, c_size); + kinds[k] = WindowKind::Committed(c_size); + } let mut sparse_free: (BTreeMap, BTreeMap) = Default::default(); sparse_free.0.insert(base, sparse_len); let u = Uma { base, - kinds: [WindowKind::Sparse, WindowKind::Sparse, WindowKind::Sparse, WindowKind::Committed(committed)], - win_allocs: vec![base, c_base], + kinds, + win_allocs, inner: Mutex::new(inner), sparse_free: Mutex::new(sparse_free), pool: Mutex::new((0, 0, Vec::new())), @@ -202,22 +291,20 @@ impl Uma { u.reserve_pool(POOL); return Some(u); } - Uma::new(size) + None } /// The windows after the committed ones as one write-watched reservation (sparse windows). fn reserve_sparse_windows(&mut self) { let committed = self.windows(); - if committed >= MAX_WINDOWS { + if committed >= self.kinds.len() { return; } let start = self.base + committed * WINDOW; - let len = (MAX_WINDOWS - committed) * WINDOW; + let len = (self.kinds.len() - committed) * WINDOW; let p = unsafe { VirtualAlloc(start as *const std::ffi::c_void, len, MEM_RESERVE | MEM_WRITE_WATCH, PAGE_READWRITE) }; if p as usize == start { - for k in committed..MAX_WINDOWS { - self.kinds[k] = WindowKind::Sparse; - } + self.kinds[committed..].fill(WindowKind::Sparse); self.win_allocs.push(start); self.sparse_free.lock().unwrap().0.insert(start, len); } else if !p.is_null() { @@ -286,7 +373,7 @@ impl Uma { } let size = (size.max(1) + GRAIN - 1) & !(GRAIN - 1); let mut g = self.sparse_free.lock().unwrap(); - let end = self.base + MAX_WINDOWS * WINDOW; + let end = self.base + self.kinds.len() * WINDOW; let lo = self.title_sparse_start(); if let Some(at) = take_sparse_in(&mut g, (self.base + WINDOW).max(lo), end, size, GRAIN, false) { return Some(at); @@ -325,7 +412,7 @@ impl Uma { let size = size.max(1).checked_next_multiple_of(GRAIN)?; let align = align.max(GRAIN).checked_next_power_of_two()?; let mut g = self.sparse_free.lock().unwrap(); - let end = self.base + MAX_WINDOWS * WINDOW; + let end = self.base + self.kinds.len() * WINDOW; let lo = self.title_sparse_start(); let above_0 = (self.base + WINDOW).max(lo); if size <= WINDOW { @@ -375,8 +462,9 @@ impl Uma { /// `windows` committed windows of `size` bytes each. pub fn with_windows(windows: usize, size: usize) -> Option { let size = ((size + GRAIN - 1) & !(GRAIN - 1)).clamp(GRAIN, MAX_SIZE); - let windows = windows.clamp(1, MAX_WINDOWS); - for slot in (4usize..512).step_by(MAX_WINDOWS) { + let windows = windows.clamp(1, MAX_HEAP_WINDOWS); + let aperture = windows.next_power_of_two().max(MAX_WINDOWS); + for slot in (aperture..slot_limit(aperture)).step_by(aperture) { let base = slot << 32; let mut got = Vec::new(); for k in 0..windows { @@ -390,7 +478,7 @@ impl Uma { } if got.len() == windows { let mut inner = Inner::default(); - let mut kinds = [WindowKind::None; MAX_WINDOWS]; + let mut kinds = vec![WindowKind::None; aperture]; let mut win_allocs = Vec::with_capacity(windows + 1); for k in 0..windows { inner.free.insert(k * WINDOW, size); @@ -447,9 +535,9 @@ impl Uma { /// contiguous sparse windows belong to a single reservation, while each committed window /// is its own allocation. pub fn watch_regions(&self) -> Vec<(usize, usize)> { - let mut out: Vec<(usize, usize)> = Vec::with_capacity(MAX_WINDOWS); + let mut out: Vec<(usize, usize)> = Vec::with_capacity(self.kinds.len()); let mut k = 0; - while k < MAX_WINDOWS { + while k < self.kinds.len() { match self.kinds[k] { WindowKind::None => k += 1, WindowKind::Committed(s) => { @@ -459,7 +547,7 @@ impl Uma { WindowKind::Sparse => { let start = self.base + k * WINDOW; let mut len = 0usize; - while k < MAX_WINDOWS && matches!(self.kinds[k], WindowKind::Sparse) { + while k < self.kinds.len() && matches!(self.kinds[k], WindowKind::Sparse) { len += WINDOW; k += 1; } @@ -473,7 +561,7 @@ impl Uma { pub fn window_of(&self, p: usize) -> Option { let k = p.checked_sub(self.base)? / WINDOW; let (start, len) = self.window(k); - (k < MAX_WINDOWS && len > 0 && p - start < len).then_some(k) + (k < self.kinds.len() && len > 0 && p - start < len).then_some(k) } pub fn contains(&self, p: usize) -> bool { @@ -674,10 +762,11 @@ fn coherent_file() -> std::path::PathBuf { crate::state::data_dir().join("cache").join("uma_coherent.txt") } -/// Bytes the coherent window is made with. -pub fn coherent_hint() -> usize { +/// Bytes the coherent window(s) are made with for a runtime layout of `windows` windows. +pub fn coherent_hint_for(windows: usize) -> usize { + let cap = max_coherent_bytes(windows); if let Some(mb) = std::env::var("XCL_COHERENT_MB").ok().and_then(|v| v.parse::().ok()) { - return (mb << 20).clamp(GRAIN, MAX_SIZE); + return (mb << 20).clamp(GRAIN, cap); } let title = std::fs::read_to_string(coherent_file()).ok().and_then(|s| s.trim().parse::().ok()).unwrap_or(0); // only with the commit for all of it: the title's ~13 GB, video memory for its render targets @@ -692,7 +781,12 @@ pub fn coherent_hint() -> usize { ); return RUNTIME_COMMITTED_CAP; } - (title + RUNTIME_COMMITTED_CAP).min(MAX_SIZE) + (title + RUNTIME_COMMITTED_CAP).min(cap) +} + +/// Bytes the coherent window is made with (legacy 4-window cap). +pub fn coherent_hint() -> usize { + coherent_hint_for(MAX_WINDOWS) } /// Commit free before the title starts for its GPU heaps to go to the coherent window. @@ -719,31 +813,44 @@ pub fn note_coherent_need(bytes: usize) { let _ = std::fs::create_dir_all(d); } let _ = std::fs::write(&f, bytes.to_string()); - crate::xlog_info!("UMA: the title's graphics memory for the coherent window: {} MB (a window of up to {} MB from the next run)", bytes >> 20, (bytes + RUNTIME_COMMITTED_CAP).min(MAX_SIZE) >> 20); + let cap = max_coherent_bytes(configured_runtime_windows()); + crate::xlog_info!("UMA: the title's graphics memory for the coherent window: {} MB (up to {} MB from the next run)", bytes >> 20, (bytes + RUNTIME_COMMITTED_CAP).min(cap) >> 20); } } impl Uma { - /// The committed coherent window (None: none). + /// The first committed coherent window (None: none). pub fn committed_window(&self) -> Option { - (0..MAX_WINDOWS).find(|&k| self.is_committed_window(k)) + (0..self.kinds.len()).find(|&k| self.is_committed_window(k)) } } -/// The title's graphics memory (created on first use; `XCL_UMA_MB`, default 2048). +/// The title's graphics memory (created on first use; `XCL_UMA_MB`, default 2048; +/// `XCL_UMA_WINDOWS=4|8|16`, default 4, with 8/16 requiring `XCL_HEAP_WINDOWS=1`). pub fn get() -> Option<&'static Uma> { GLOBAL .get_or_init(|| { let mb = std::env::var("XCL_UMA_MB").ok().and_then(|v| v.parse::().ok()).unwrap_or(2048); - let coherent = coherent_hint(); - let u = Uma::for_runtime_with((mb << 20).max(coherent), coherent); + let req = configured_runtime_windows(); + let coherent = coherent_hint_for(req); + let u = if req > MAX_WINDOWS { + Uma::for_runtime_windows((mb << 20).max(coherent), coherent, req).or_else(|| { + crate::xlog_warn!("UMA: could not reserve {req} aligned windows below 1 TiB – falling back to {MAX_WINDOWS}"); + let fallback = coherent_hint_for(MAX_WINDOWS); + Uma::for_runtime_with((mb << 20).max(fallback), fallback) + }) + } else { + Uma::for_runtime_with((mb << 20).max(coherent), coherent) + }; match &u { Some(u) => { - let sparse_n = (0..MAX_WINDOWS).filter(|&k| u.is_sparse_window(k)).count(); + let sparse_n = (0..u.shader_windows()).filter(|&k| u.is_sparse_window(k)).count(); + let coh_n = u.windows(); crate::xlog_info!( - "UMA: {} sparse VRAM window(s) ({} GiB VA) + {} MB coherent window at {:#x}", + "UMA: {} sparse VRAM window(s) ({} GiB VA) + {} coherent window(s) ({} MB) at {:#x}", sparse_n, sparse_n * 4, + coh_n, u.size() >> 20, u.base() ); @@ -941,4 +1048,75 @@ mod tests { // Contiguous sparse windows 0..2 are reported as one OS watch region; window 3 as another. assert_eq!(u.watch_regions(), vec![(u.base(), 3 * WINDOW), (u.base() + 3 * WINDOW, 16 << 20)]); } + + #[test] + fn runtime_layout_supports_eight_and_sixteen_heap_windows() { + for windows in [8usize, MAX_HEAP_WINDOWS] { + let u = Uma::for_runtime_windows(16 << 20, RUNTIME_COMMITTED_CAP, windows).expect("expanded UMA aperture"); + let aperture = windows * WINDOW; + assert_eq!(u.base() % aperture, 0, "base must be {windows}*4 GiB aligned"); + assert!(u.base() + aperture <= (1usize << 40), "expanded aperture must fit below 40-bit VA limit"); + assert_eq!(u.shader_windows(), windows); + assert_eq!(u.windows(), 1); + for k in 0..windows - 1 { + assert!(u.is_sparse_window(k), "window {k} should be sparse"); + } + assert_eq!(u.committed_window(), Some(windows - 1)); + let c = u.alloc(0x2_0000, 0).unwrap() as usize; + assert_eq!(u.window_of(c), Some(windows - 1)); + assert!(u.free(c)); + // Reserve >12 GiB (larger than legacy 3 sparse windows) in windows 1+ while preserving window 0 headroom. + let big = (windows - 2) * WINDOW; + let r = u.sparse_reserve(big).expect("large title reservation in expanded sparse windows"); + assert_eq!(u.window_of(r), Some(1)); + let (d, ld) = u.sparse_alloc_in(0, GRAIN, GRAIN).expect("window 0 descriptor headroom intact"); + assert_eq!(u.window_of(d), Some(0)); + assert_eq!(u.sparse_release(d), Some(ld)); + assert_eq!(u.sparse_release(r), Some(big)); + assert_eq!(u.sparse_used(), 0); + assert_eq!( + u.watch_regions(), + vec![(u.base(), (windows - 1) * WINDOW), (u.base() + (windows - 1) * WINDOW, 16 << 20)] + ); + } + } + + #[test] + fn expanded_heap_window_shaders_translate_and_validate() { + use crate::gpu::dxil::kernel::{translate, KernelOptions}; + use crate::gpu::rdna2::encode; + use crate::gpu::recomp::{self, Options, HEAP_WINDOWS}; + let mut code = Vec::new(); + code.extend(encode("S_LOAD_DWORD", "ENC_SMEM", &[("SDATA", 4), ("SBASE", 0), ("OFFSET", 0), ("SOFFSET", 125)], None).unwrap()); + code.extend(encode("S_ENDPGM", "ENC_SOPP", &[], None).unwrap()); + for w in [8u32, MAX_HEAP_WINDOWS as u32] { + // HLSL path accepts 8/16 with heap_windows, rejects without. + assert!(recomp::translate(&code, &Options { mem_windows: w, heap_windows: false, ..Default::default() }).is_err()); + let t = recomp::translate(&code, &Options { mem_windows: w, heap_windows: true, ..Default::default() }).unwrap(); + assert!(t.hlsl.contains(&format!("xcl_w >= {w}u")), "HLSL must range-check against {w} windows"); + assert!(!t.hlsl.contains("mem4"), "root signature ABI stays at 4 root UAVs"); + // Direct DXIL path validates cleanly with 8/16 | HEAP_WINDOWS. + translate(&code, KernelOptions { wave64: true, split: false, mem_windows: w | HEAP_WINDOWS, sampler_base: 0 }).unwrap(); + } + } + + #[test] + fn expanded_runtime_layout_splits_large_coherent_heaps_across_multiple_windows() { + // Legacy 4-window layout stays capped at 1 coherent window (4095 MiB). + assert_eq!(coherent_window_sizes(6 << 30, 6 << 30, MAX_WINDOWS), vec![MAX_SIZE]); + // 8- and 16-window layouts split >4 GiB coherent heaps across multiple committed windows + // with exact remainder sizing (no wasted RAM commit) while preserving >=3 sparse windows. + let want = MAX_SIZE + (512 << 20); + for w in [8usize, MAX_HEAP_WINDOWS] { + assert_eq!(coherent_window_sizes(want, want, w), vec![MAX_SIZE, 512 << 20]); + assert_eq!(coherent_window_sizes(20 << 30, 20 << 30, w).len(), 4); + } + // Multi-window Uma::alloc seamlessly spills into the 2nd committed window. + let u = Uma::with_windows(2, 8 << 20).unwrap(); + let a = u.alloc(6 << 20, GRAIN).unwrap() as usize; + let b = u.alloc(6 << 20, GRAIN).unwrap() as usize; + assert_eq!(u.window_of(a), Some(0)); + assert_eq!(u.window_of(b), Some(1)); + assert!(u.free(a) && u.free(b)); + } } diff --git a/crates/xcl/src/hle/d3d12x/console_heap.rs b/crates/xcl/src/hle/d3d12x/console_heap.rs index 0aea5c0ee..cc374a57f 100644 --- a/crates/xcl/src/hle/d3d12x/console_heap.rs +++ b/crates/xcl/src/hle/d3d12x/console_heap.rs @@ -159,7 +159,7 @@ pub unsafe fn shared_heap(dev: &ID3D12Device) -> bool { heap, cap, // the memory windows' raw UAVs (`set_window_views`) come first - next: crate::gpu::recomp::MEM_HEAP_BASE + crate::gpu::uma::MAX_WINDOWS as u32, + next: crate::gpu::recomp::MEM_HEAP_BASE + crate::gpu::uma::MAX_HEAP_WINDOWS as u32, free: Vec::new(), }); } @@ -176,17 +176,19 @@ pub fn window_views_failed() -> bool { /// The memory windows' buffers `(resource, bytes)` as raw UAVs at `MEM_HEAP_BASE + k` of the /// shared heap, made now if need be (`Options::heap_windows`: shaders take window k from there). -/// A window without a buffer gets window 0's. False (and the shaders keep the switch): no -/// shared heap. +/// The legacy 4-window layout fills missing slots with window 0; wider layouts (8 / 16) require +/// every window buffer to be valid. pub unsafe fn set_window_views(dev: &ID3D12Device, windows: &[(usize, usize)]) -> bool { - let ok = !windows.is_empty() && windows[0].0 != 0 && shared_heap(dev) && { + let count = windows.len().max(crate::gpu::uma::MAX_WINDOWS); + let complete = count <= crate::gpu::uma::MAX_WINDOWS || windows.iter().all(|w| w.0 != 0); + let ok = count <= crate::gpu::uma::MAX_HEAP_WINDOWS && complete && windows.first().is_some_and(|w| w.0 != 0) && shared_heap(dev) && { let (device, cpu, inc) = { let g = GLOBAL.lock().unwrap(); let s = g.as_ref().unwrap(); (s.dev.clone(), s.cpu, s.inc) }; // The device may be adopted: its UAV hook re-enters descriptor bookkeeping. - for k in 0..crate::gpu::uma::MAX_WINDOWS { + for k in 0..count { let (raw, bytes) = windows.get(k).copied().filter(|w| w.0 != 0).unwrap_or(windows[0]); let raw = raw as *mut std::ffi::c_void; let Some(r) = ID3D12Resource::from_raw_borrowed(&raw) else { continue }; @@ -197,7 +199,7 @@ pub unsafe fn set_window_views(dev: &ID3D12Device, windows: &[(usize, usize)]) - }; if !ok { WINDOW_VIEWS_FAILED.store(true, std::sync::atomic::Ordering::Relaxed); - crate::xlog_warn!("memory windows: not in the shared descriptor heap – translated shaders switch over the windows' root UAVs"); + crate::xlog_warn!("memory windows: could not bind {count} window(s) in the shared descriptor heap"); } ok } @@ -579,10 +581,17 @@ mod tests { dev: dev.clone(), heap: ID3D12DescriptorHeap::from_raw(&mut heap as *mut _ as *mut c_void), cpu: 0x1000, gpu: 0x2000, inc: 32, cap: 1024, - next: crate::gpu::uma::MAX_WINDOWS as u32, free: Vec::new(), + next: crate::gpu::recomp::MEM_HEAP_BASE + crate::gpu::uma::MAX_HEAP_WINDOWS as u32, free: Vec::new(), }); - assert!(set_window_views(&dev, &[(&mut resource as *mut _ as usize, 0x10000)])); - assert_eq!(CALLS.load(Ordering::Relaxed), crate::gpu::uma::MAX_WINDOWS as u32); + let window = (&mut resource as *mut _ as usize, 0x10000); + assert!(set_window_views(&dev, &[window])); + assert_eq!(CALLS.swap(0, Ordering::Relaxed), crate::gpu::uma::MAX_WINDOWS as u32); + let mut windows = [window; crate::gpu::uma::MAX_HEAP_WINDOWS]; + assert!(set_window_views(&dev, &windows)); + assert_eq!(CALLS.swap(0, Ordering::Relaxed), windows.len() as u32); + windows[7] = (0, 0); + assert!(!set_window_views(&dev, &windows)); + assert_eq!(CALLS.load(Ordering::Relaxed), 0); assert!(UNLOCKED.load(Ordering::Relaxed), "device callback ran while GLOBAL was locked"); *GLOBAL.lock().unwrap() = None; } diff --git a/crates/xcl/src/hle/d3d12x/real.rs b/crates/xcl/src/hle/d3d12x/real.rs index 014dfa4d9..c9cdab7f5 100644 --- a/crates/xcl/src/hle/d3d12x/real.rs +++ b/crates/xcl/src/hle/d3d12x/real.rs @@ -3395,6 +3395,13 @@ fn with_switch_fallback(mut build: impl FnMut() -> R) -> R { if !HEAP_WINDOW_OOM.with(|o| o.replace(false)) { return r; } + if crate::gpu::uma::get().is_some_and(|u| u.shader_windows() > crate::gpu::uma::MAX_WINDOWS) { + static WARNED: std::sync::Once = std::sync::Once::new(); + WARNED.call_once(|| { + crate::xlog_warn!("D3D12.X: the driver refused an expanded-window pipeline; switch-form retry requires XCL_UMA_WINDOWS=4"); + }); + return r; + } let n = SWITCH_FORM_RETRIES.fetch_add(1, Ordering::Relaxed); if n < 5 || n % 100 == 0 { crate::xlog_warn!("D3D12.X: the driver ran out of memory on a pipeline with heap windows – building it in the switch form ({} so far)", n + 1); diff --git a/crates/xcl/src/hle/kernelx.rs b/crates/xcl/src/hle/kernelx.rs index 260788a30..437fa667a 100644 --- a/crates/xcl/src/hle/kernelx.rs +++ b/crates/xcl/src/hle/kernelx.rs @@ -184,6 +184,12 @@ pub mod mirrors { } static STATE: Mutex = Mutex::new(State { cpu: Vec::new(), gpu: BTreeMap::new() }); + /// Whether `(t, p)` is a CPU-inaccessible GPU-view alias reservation (`MEM_64K_PAGES` + /// reserve with `PAGE_GRAPHICS_NOACCESS | PAGE_NOACCESS`). + pub fn is_gpu_view_reservation(t: u32, p: u32) -> bool { + t & PAGES_64K == PAGES_64K && t & 0x1000 == 0 && p & GRAPHICS_NOACCESS != 0 && p & 0xFF == super::mem::PAGE_NOACCESS + } + /// A reservation of `size` bytes at `base` with allocation type `t` and protection `p`. pub fn reserved(base: usize, size: usize, t: u32, p: u32) { if t & PAGES_64K != PAGES_64K || t & 0x1000 != 0 { @@ -247,13 +253,17 @@ pub unsafe extern "system" fn VirtualAlloc(addr: *const c_void, size: usize, t: trace_mem("VirtualAlloc (sparse commit)", addr as usize, size, t as u64, p, q as usize); return q; } - // the title's own reservations of 64 KiB pages: in a sparse window, so the GPU sees them - if addr.is_null() && t & 0x2000 != 0 && t & MEM_64K_PAGES == MEM_64K_PAGES { + // the title's own reservations of 64 KiB pages: in a sparse window, so the GPU sees them. + // Skip CPU-inaccessible GPU-view mirror reservations (`PAGE_NOACCESS | PAGE_GRAPHICS_NOACCESS`): + // their pixels live in the paired CPU view (`mirrors::source`), so putting them in sparse VA + // wastes sparse address space and write-watch overhead while still needing mirror pairing. + if addr.is_null() && t & 0x2000 != 0 && t & MEM_64K_PAGES == MEM_64K_PAGES && !mirrors::is_gpu_view_reservation(t, p) { if let Some(q) = uma.and_then(|u| u.sparse_reserve(size)) { if t & 0x1000 != 0 && commit_sparse(q, size, p).is_null() { uma.map(|u| u.sparse_release(q)); return std::ptr::null_mut(); } + mirrors::reserved(q, size, t, p); trace_mem("VirtualAlloc (64K pages, sparse)", 0, size, t as u64, p, q); return q as *mut c_void; } @@ -276,7 +286,7 @@ pub unsafe extern "system" fn VirtualAlloc(addr: *const c_void, size: usize, t: return q as *mut c_void; } } - if addr.is_null() && t & MEM_GRAPHICS != 0 && t & 0x2000 != 0 { + if addr.is_null() && t & MEM_GRAPHICS != 0 && t & 0x2000 != 0 && !mirrors::is_gpu_view_reservation(t, p) { // on the console all graphics memory is GPU-visible, reserved address space too (titles // reserve a range, then commit or map pages and place resources in it): prefer the // sparse VRAM windows first so reservations consume zero system RAM until committed @@ -287,10 +297,12 @@ pub unsafe extern "system" fn VirtualAlloc(addr: *const c_void, size: usize, t: uma.and_then(|u| u.sparse_reserve(size)) }; if let Some(q) = reserved { + mirrors::reserved(q, size, t, p); trace_mem("VirtualAlloc (graphics reserve, sparse)", 0, size, t as u64, p, q); return q as *mut c_void; } if let Some(q) = uma.and_then(|u| u.reserve(size, 0x1_0000)) { + mirrors::reserved(q as usize, size, t, p); trace_mem("VirtualAlloc (graphics reserve, UMA)", 0, size, t as u64, p, q as usize); return q as *mut c_void; } @@ -316,7 +328,7 @@ pub unsafe extern "system" fn VirtualAlloc(addr: *const c_void, size: usize, t: // a pool of their own) const KEEP: usize = 96 << 20; let fits = u.size().saturating_sub(u.used()) >= size + KEEP; - if let Some(q) = u.committed_window().filter(|_| fits).and_then(|k| u.alloc_in(k, size, align)) { + if let Some(q) = fits.then(|| u.alloc(size, align)).flatten() { trace_mem("VirtualAlloc (graphics, coherent window)", 0, size, t as u64, p, q as usize); return q as *mut c_void; } @@ -433,6 +445,7 @@ pub unsafe extern "system" fn VirtualFree(addr: *mut c_void, size: usize, t: u32 } if release { u.sparse_release(a); + mirrors::released(a); } return 1; } @@ -3030,4 +3043,29 @@ mod tests { assert!(committed_page(base + 0x1000)); } } + + #[test] + fn sparse_64k_reservation_registers_gpu_view_mirror_and_releases_cleanly() { + unsafe { + // Reserve a 64 KiB-page CPU view (lands in sparse UMA when space is available) and + // pair it with a PAGE_NOACCESS | PAGE_GRAPHICS_NOACCESS GPU view of the same size. + let size = 4 << 20; + let cpu = VirtualAlloc(std::ptr::null(), size, mem::MEM_RESERVE | MEM_64K_PAGES, mem::PAGE_READWRITE); + assert!(!cpu.is_null()); + let gpu = VirtualAlloc(std::ptr::null(), size, mem::MEM_RESERVE | MEM_64K_PAGES, mem::PAGE_NOACCESS | 0x800); + assert!(!gpu.is_null()); + assert_eq!( + mirrors::source(gpu as usize + 0x2_0000), + Some(cpu as usize + 0x2_0000), + "GPU view must resolve to CPU view even when CPU view lives in sparse UMA" + ); + // GPU-view alias must not consume sparse UMA VA. + if let Some(u) = crate::gpu::uma::get() { + assert!(!u.is_sparse(gpu as usize), "CPU-inaccessible GPU view should stay outside sparse UMA"); + } + assert_eq!(VirtualFree(gpu, 0, mem::MEM_RELEASE), 1); + assert_eq!(mirrors::source(gpu as usize + 0x2_0000), None); + assert_eq!(VirtualFree(cpu, 0, mem::MEM_RELEASE), 1); + } + } } From 06308bc61a16a1cd4fb395f8e3704f3aba41b757 Mon Sep 17 00:00:00 2001 From: raylitebull <287713799+raylitebull@users.noreply.github.com> Date: Wed, 25 Nov 2026 00:07:42 +0100 Subject: [PATCH 2/2] UMA: cap runtime sparse windows at 3 (12 GiB) under 8/16-window layouts while keeping 5/13 coherent windows --- crates/xcl/src/gpu/uma.rs | 58 ++++++++++++++++------- crates/xcl/src/hle/d3d12x/console_heap.rs | 11 +++-- 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/crates/xcl/src/gpu/uma.rs b/crates/xcl/src/gpu/uma.rs index 91c8c38fe..aef6e08d6 100644 --- a/crates/xcl/src/gpu/uma.rs +++ b/crates/xcl/src/gpu/uma.rs @@ -32,11 +32,17 @@ pub const MAX_WINDOWS: usize = 4; /// Maximum number of windows addressable through the shared descriptor heap (`XCL_HEAP_WINDOWS=1`). pub const MAX_HEAP_WINDOWS: usize = 16; +/// Maximum sparse VRAM windows reserved in runtime layouts (3 × 4 GiB = 12 GiB VA). +/// Keeping sparse VA capped at 12 GiB prevents huge startup `MEM_64K_PAGES` title heaps from +/// being pulled into sparse VRAM (which causes multi-minute tile-mapping stalls and multi-GB +/// sparse pool bloat), while still giving expanded 8/16-window layouts extra coherent windows. +const MAX_RUNTIME_SPARSE_WINDOWS: usize = 3; + /// Maximum number of committed coherent windows in an expanded runtime layout. -/// Always leaves at least 3 sparse VRAM windows (12 GiB). +/// Always leaves 3 sparse VRAM windows (12 GiB): 1 coherent for 4-window, 5 for 8-window, 13 for 16-window. fn max_coherent_windows(windows: usize) -> usize { if windows > MAX_WINDOWS { - windows.saturating_sub(3).min(4).max(1) + windows.saturating_sub(MAX_RUNTIME_SPARSE_WINDOWS).max(1) } else { 1 } @@ -239,7 +245,7 @@ impl Uma { fn reserve_runtime(size: usize, coherent: usize, windows: usize) -> Option { let coh_sizes = coherent_window_sizes(size, coherent, windows); let coh_wins = coh_sizes.len(); - let sparse_wins = windows - coh_wins; + let sparse_wins = (windows - coh_wins).min(MAX_RUNTIME_SPARSE_WINDOWS); let sparse_len = sparse_wins * WINDOW; for slot in (windows..slot_limit(windows)).step_by(windows) { let base = slot << 32; @@ -272,7 +278,8 @@ impl Uma { continue; } let mut inner = Inner::default(); - let mut kinds = vec![WindowKind::Sparse; windows]; + let mut kinds = vec![WindowKind::None; windows]; + kinds[..sparse_wins].fill(WindowKind::Sparse); for (c, &c_size) in coh_sizes.iter().enumerate() { let k = sparse_wins + c; inner.free.insert(k * WINDOW, c_size); @@ -342,9 +349,15 @@ impl Uma { self.kinds.iter().any(|w| matches!(w, WindowKind::Sparse)) } - /// Windows translated shaders address (`mem`, `mem1` …): highest active window + 1. + /// Windows translated shaders address (`mem`, `mem1` …): full configured aperture for + /// sparse runtime layouts (keeping shader cache keys aligned with `XCL_UMA_WINDOWS=8|16` + /// even when trailing slots are unallocated), or highest active window + 1 otherwise. pub fn shader_windows(&self) -> usize { - self.kinds.iter().rposition(|w| !matches!(w, WindowKind::None)).map_or(0, |i| i + 1) + if self.has_sparse() { + self.kinds.len() + } else { + self.kinds.iter().rposition(|w| !matches!(w, WindowKind::None)).map_or(0, |i| i + 1) + } } /// Whether `p` is in a sparse window. @@ -1058,17 +1071,22 @@ mod tests { assert!(u.base() + aperture <= (1usize << 40), "expanded aperture must fit below 40-bit VA limit"); assert_eq!(u.shader_windows(), windows); assert_eq!(u.windows(), 1); - for k in 0..windows - 1 { + // Sparse VA stays capped at 3 windows (12 GiB) so huge startup heaps stay off sparse VRAM. + for k in 0..MAX_RUNTIME_SPARSE_WINDOWS { assert!(u.is_sparse_window(k), "window {k} should be sparse"); } - assert_eq!(u.committed_window(), Some(windows - 1)); + assert_eq!(u.committed_window(), Some(MAX_RUNTIME_SPARSE_WINDOWS)); + for k in (MAX_RUNTIME_SPARSE_WINDOWS + 1)..windows { + assert!(!u.is_sparse_window(k) && !u.is_committed_window(k), "unused trailing window {k} stays unreserved"); + } let c = u.alloc(0x2_0000, 0).unwrap() as usize; - assert_eq!(u.window_of(c), Some(windows - 1)); + assert_eq!(u.window_of(c), Some(MAX_RUNTIME_SPARSE_WINDOWS)); assert!(u.free(c)); - // Reserve >12 GiB (larger than legacy 3 sparse windows) in windows 1+ while preserving window 0 headroom. - let big = (windows - 2) * WINDOW; - let r = u.sparse_reserve(big).expect("large title reservation in expanded sparse windows"); + // Window 1..2 hold large reservations while preserving window 0 descriptor headroom; >12 GiB overflows cleanly. + let big = 2 * WINDOW; + let r = u.sparse_reserve(big).expect("8 GiB reservation in sparse windows 1..2"); assert_eq!(u.window_of(r), Some(1)); + assert!(u.sparse_reserve(4 * WINDOW).is_none(), "reservations beyond 12 GiB sparse cap must overflow to host RAM"); let (d, ld) = u.sparse_alloc_in(0, GRAIN, GRAIN).expect("window 0 descriptor headroom intact"); assert_eq!(u.window_of(d), Some(0)); assert_eq!(u.sparse_release(d), Some(ld)); @@ -1076,7 +1094,10 @@ mod tests { assert_eq!(u.sparse_used(), 0); assert_eq!( u.watch_regions(), - vec![(u.base(), (windows - 1) * WINDOW), (u.base() + (windows - 1) * WINDOW, 16 << 20)] + vec![ + (u.base(), MAX_RUNTIME_SPARSE_WINDOWS * WINDOW), + (u.base() + MAX_RUNTIME_SPARSE_WINDOWS * WINDOW, 16 << 20), + ] ); } } @@ -1104,13 +1125,18 @@ mod tests { fn expanded_runtime_layout_splits_large_coherent_heaps_across_multiple_windows() { // Legacy 4-window layout stays capped at 1 coherent window (4095 MiB). assert_eq!(coherent_window_sizes(6 << 30, 6 << 30, MAX_WINDOWS), vec![MAX_SIZE]); - // 8- and 16-window layouts split >4 GiB coherent heaps across multiple committed windows - // with exact remainder sizing (no wasted RAM commit) while preserving >=3 sparse windows. + // 8- and 16-window layouts split >4 GiB coherent heaps across up to 5 / 13 committed windows + // with exact remainder sizing while keeping sparse windows capped at 3 (12 GiB). let want = MAX_SIZE + (512 << 20); for w in [8usize, MAX_HEAP_WINDOWS] { assert_eq!(coherent_window_sizes(want, want, w), vec![MAX_SIZE, 512 << 20]); - assert_eq!(coherent_window_sizes(20 << 30, 20 << 30, w).len(), 4); + assert_eq!(coherent_window_sizes(5 * MAX_SIZE, 5 * MAX_SIZE, w).len(), 5); } + assert_eq!(coherent_window_sizes(20 << 30, 20 << 30, 8).len(), 5); + assert_eq!(coherent_window_sizes(20 << 30, 20 << 30, MAX_HEAP_WINDOWS).len(), 6); + assert_eq!(max_coherent_windows(MAX_WINDOWS), 1); + assert_eq!(max_coherent_windows(8), 5); + assert_eq!(max_coherent_windows(MAX_HEAP_WINDOWS), 13); // Multi-window Uma::alloc seamlessly spills into the 2nd committed window. let u = Uma::with_windows(2, 8 << 20).unwrap(); let a = u.alloc(6 << 20, GRAIN).unwrap() as usize; diff --git a/crates/xcl/src/hle/d3d12x/console_heap.rs b/crates/xcl/src/hle/d3d12x/console_heap.rs index cc374a57f..9e247c97d 100644 --- a/crates/xcl/src/hle/d3d12x/console_heap.rs +++ b/crates/xcl/src/hle/d3d12x/console_heap.rs @@ -176,11 +176,11 @@ pub fn window_views_failed() -> bool { /// The memory windows' buffers `(resource, bytes)` as raw UAVs at `MEM_HEAP_BASE + k` of the /// shared heap, made now if need be (`Options::heap_windows`: shaders take window k from there). -/// The legacy 4-window layout fills missing slots with window 0; wider layouts (8 / 16) require -/// every window buffer to be valid. +/// Active windows (`bytes > 0`) in wider layouts (8 / 16) must all have a valid buffer; unused +/// trailing slots (`(0, 0)`) safely alias window 0's buffer. pub unsafe fn set_window_views(dev: &ID3D12Device, windows: &[(usize, usize)]) -> bool { let count = windows.len().max(crate::gpu::uma::MAX_WINDOWS); - let complete = count <= crate::gpu::uma::MAX_WINDOWS || windows.iter().all(|w| w.0 != 0); + let complete = count <= crate::gpu::uma::MAX_WINDOWS || windows.iter().all(|&(raw, bytes)| raw != 0 || bytes == 0); let ok = count <= crate::gpu::uma::MAX_HEAP_WINDOWS && complete && windows.first().is_some_and(|w| w.0 != 0) && shared_heap(dev) && { let (device, cpu, inc) = { let g = GLOBAL.lock().unwrap(); @@ -589,7 +589,12 @@ mod tests { let mut windows = [window; crate::gpu::uma::MAX_HEAP_WINDOWS]; assert!(set_window_views(&dev, &windows)); assert_eq!(CALLS.swap(0, Ordering::Relaxed), windows.len() as u32); + // Unused trailing window `(0, 0)` safely aliases window 0; an active window that failed + // to open `(0, bytes > 0)` is rejected. windows[7] = (0, 0); + assert!(set_window_views(&dev, &windows)); + assert_eq!(CALLS.swap(0, Ordering::Relaxed), windows.len() as u32); + windows[7] = (0, 0x10000); assert!(!set_window_views(&dev, &windows)); assert_eq!(CALLS.load(Ordering::Relaxed), 0); assert!(UNLOCKED.load(Ordering::Relaxed), "device callback ran while GLOBAL was locked");