VIctory's 88 commits fitted in; clzero loops end as the console's do
The fork's emulation of a clzero loop zeroed from the start to the end and left rax at the end: the instruction zeroes whole lines and the test comes after it (VIctory's own test of it failed here). The title's descriptor heaps are held shared while their slots are written (VIctory 628b95d held them alone, for every thread that writes descriptors). Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
0618f88ebe
commit
329df7aef4
6 files changed
+56
-116
No files matched your search
@@ -126,14 +126,17 @@ const SHADER_VISIBLE: u32 = 1;
|
||||
/// Shader-visible heaps by address range, for mirroring descriptor writes:
|
||||
/// start, end, heap.
|
||||
#[cfg(windows)]
|
||||
static SHADER_HEAPS: std::sync::Mutex<Vec<(u64, u64, usize)>> = std::sync::Mutex::new(Vec::new());
|
||||
///
|
||||
/// Held shared while a heap found here is used (by every thread that writes
|
||||
/// descriptors, and by [`sync_heaps`]), alone only where heaps come and go.
|
||||
static SHADER_HEAPS: std::sync::RwLock<Vec<(u64, u64, usize)>> = std::sync::RwLock::new(Vec::new());
|
||||
|
||||
/// Makes the host descriptor for what the title wrote at `handle`, if it
|
||||
/// is in a shader-visible heap. Keeps `SHADER_HEAPS` locked for the duration
|
||||
/// so `Heap::drop` cannot free the heap concurrently.
|
||||
#[cfg(windows)]
|
||||
fn mirror(handle: u64) {
|
||||
let heaps = SHADER_HEAPS.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let heaps = SHADER_HEAPS.read().unwrap_or_else(|e| e.into_inner());
|
||||
let Some(&(_, _, at)) = heaps
|
||||
.iter()
|
||||
.find(|&&(start, end, _)| (start..end).contains(&handle))
|
||||
@@ -177,7 +180,7 @@ pub(crate) fn sync_heaps() {
|
||||
let started = std::time::Instant::now();
|
||||
let (mut pages, mut looked, mut mirrored) = (0u64, 0u64, 0u64);
|
||||
let mut page_bytes: Vec<u8> = Vec::new();
|
||||
let heaps = SHADER_HEAPS.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let heaps = SHADER_HEAPS.read().unwrap_or_else(|e| e.into_inner());
|
||||
for &(start, end, at) in heaps.iter() {
|
||||
// SAFETY: registered heaps are live (removed when dropped).
|
||||
let heap = unsafe { &*(at as *const Heap) };
|
||||
@@ -275,7 +278,7 @@ fn changed_slots(
|
||||
/// `heap`, if that heap still exists.
|
||||
#[cfg(windows)]
|
||||
pub(crate) fn release_dynamic(heap: usize, first: u32, n: u32) {
|
||||
let heaps = SHADER_HEAPS.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let heaps = SHADER_HEAPS.read().unwrap_or_else(|e| e.into_inner());
|
||||
if heaps.iter().any(|&(_, _, h)| h == heap)
|
||||
// SAFETY: registered heaps are live (removed when dropped).
|
||||
&& let Some(Some(host)) = unsafe { &*(heap as *const Heap) }.host.get()
|
||||
@@ -289,7 +292,7 @@ pub(crate) fn release_dynamic(heap: usize, first: u32, n: u32) {
|
||||
/// bytes at `gpu`.
|
||||
#[cfg(windows)]
|
||||
pub(crate) fn constant_slot(heap: usize, index: u32, gpu: u64, size: u32) {
|
||||
let heaps = SHADER_HEAPS.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let heaps = SHADER_HEAPS.read().unwrap_or_else(|e| e.into_inner());
|
||||
if heaps.iter().any(|&(_, _, h)| h == heap)
|
||||
// SAFETY: registered heaps are live (removed when dropped).
|
||||
&& let Some(Some(host)) = unsafe { &*(heap as *const Heap) }.host.get()
|
||||
@@ -302,7 +305,7 @@ pub(crate) fn constant_slot(heap: usize, index: u32, gpu: u64, size: u32) {
|
||||
impl Drop for Heap {
|
||||
fn drop(&mut self) {
|
||||
let at = std::ptr::from_ref::<Heap>(self) as usize;
|
||||
let mut heaps = SHADER_HEAPS.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut heaps = SHADER_HEAPS.write().unwrap_or_else(|e| e.into_inner());
|
||||
heaps.retain(|&(_, _, h)| h != at);
|
||||
}
|
||||
}
|
||||
@@ -819,7 +822,14 @@ pub(crate) fn make_waiting() {
|
||||
// texture without a host copy must go on waiting).
|
||||
// (Looked up first: the handle is read only while its heap is
|
||||
// there.)
|
||||
let Some((heap, index)) = shader_slot(handle) else {
|
||||
// (The heap stays while the lock is held: `mirror`.)
|
||||
let heaps = SHADER_HEAPS.read().unwrap_or_else(|e| e.into_inner());
|
||||
let Some(&(_, _, at)) = heaps.iter().find(|&&(start, end, _)| (start..end).contains(&handle)) else {
|
||||
continue;
|
||||
};
|
||||
// SAFETY: a registered heap, live while the lock is held.
|
||||
let heap = unsafe { &*(at as *const Heap) };
|
||||
let Some(index) = heap.index(handle) else {
|
||||
continue;
|
||||
};
|
||||
let same = match view(handle) {
|
||||
@@ -1113,7 +1123,7 @@ pub(crate) extern "system" fn create_heap(
|
||||
#[cfg(windows)]
|
||||
if visible {
|
||||
let at = std::ptr::from_ref::<Heap>(&heap) as usize;
|
||||
let mut heaps = SHADER_HEAPS.lock().unwrap_or_else(|e| e.into_inner());
|
||||
let mut heaps = SHADER_HEAPS.write().unwrap_or_else(|e| e.into_inner());
|
||||
heaps.push((start, start + size, at));
|
||||
}
|
||||
#[cfg(not(windows))]
|
||||
|
||||
Reference in new issue
Block a user