Merge fork main c96b4f2

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
localandClaude Opus 5.5 committed 2026-11-24 19:56:57 -06:00
commit d9a31188be
8 files changed
+755 -74

No files matched your search

+62 -3
View File
@@ -487,9 +487,65 @@ static HOST_WRITTEN: Mutex<Option<std::collections::HashSet<usize>>> = Mutex::ne
/// A host copy or resolve writes `resource`.
pub(crate) fn host_written(resource: This) {
let mut set = HOST_WRITTEN.lock().unwrap_or_else(|e| e.into_inner());
set.get_or_insert_with(Default::default)
.insert(resource as usize);
let new = {
let mut set = HOST_WRITTEN.lock().unwrap_or_else(|e| e.into_inner());
set.get_or_insert_with(Default::default).insert(resource as usize)
};
// Diagnostics (run 177): where its title memory is, for placed views
// the title reads that memory through ([`placed_in_host_written`]).
if new && let Some((at, desc)) = crate::resource::texture_memory(resource) {
// SAFETY: 56 bytes in the description's layout.
let words = unsafe { std::ptr::from_ref(&desc).cast::<[u32; 14]>().read_unaligned() };
let bytes = crate::resource::placed_bytes(&words).unwrap_or(0);
if !at.is_null() && bytes > 0 {
HOST_WRITTEN_AT
.lock()
.unwrap_or_else(|e| e.into_inner())
.insert(at as u64, (bytes, words[4], words[6], words[7], words[8], resource as usize));
}
}
}
/// The title memory of textures the host copied into, by address: bytes
/// and description words 4, 6, 7 and 8 (width, height, layers and levels,
/// format).
static HOST_WRITTEN_AT: Mutex<std::collections::BTreeMap<u64, (u64, u32, u32, u32, u32, usize)>> =
Mutex::new(std::collections::BTreeMap::new());
/// A texture the title placed at `address` (description words `desc`) was
/// made: says so once if it lies in the memory of a texture the host
/// copied into ([`host_written`]). Its own host copy is filled from title
/// memory, which the copy never reached: the copied texels are on the
/// card in the other texture, where no shader that reads this view finds
/// them.
pub(crate) fn placed_in_host_written(address: u64, desc: &[u32; 14]) {
let hit = {
let map = HOST_WRITTEN_AT.lock().unwrap_or_else(|e| e.into_inner());
map.range(..=address)
.next_back()
.filter(|(at, d)| address < **at + d.0)
.map(|(at, d)| (*at, *d))
};
if let Some((at, (bytes, width, height, layers_levels, format, _))) = hit {
static SAID: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
if SAID.fetch_add(1, std::sync::atomic::Ordering::Relaxed) < 200 {
tracing::warn!(
view_address = format_args!("{address:#x}"),
view_offset = address - at,
view_width = desc[4],
view_height = desc[6],
view_layers_levels = format_args!("{:#x}", desc[7]),
view_format = desc[8],
copied_address = format_args!("{at:#x}"),
copied_bytes = bytes,
copied_width = width,
copied_height = height,
copied_layers_levels = format_args!("{layers_levels:#x}"),
copied_format = format,
"HERO LEAD: a placed texture view lies in the memory of a texture the host copied into: it is filled from title memory, which the copy never reached"
);
}
}
}
/// Whether the host GPU wrote `resource` by a copy or resolve
@@ -513,6 +569,9 @@ pub(crate) fn forget(resource: usize) {
if let Some(set) = set.as_mut() {
set.remove(&resource);
}
// Its memory may be given to other textures now (run 177: most of the
// "HERO LEAD" lines were views in memory a released texture had held).
HOST_WRITTEN_AT.lock().unwrap_or_else(|e| e.into_inner()).retain(|_, d| d.5 != resource);
let mut through = THROUGH.lock().unwrap_or_else(|e| e.into_inner());
if let Some(through) = through.as_mut() {
through.remove(&resource);