Merge pull request #961 from ludovic111/fix/readback-alignment

🤖 Agent: merged after verify passed. GPU readbacks (occlusion results, GPU timer) no longer assume the mapping's alignment; fixes the Vega 11 launch crash in #953.
This commit is contained in:
Ludovic Marie
2026-10-19 04:47:48 +02:00
committed by GitHub
2 changed files with 6 additions and 3 deletions
+4 -2
View File
@@ -273,7 +273,9 @@ impl Cull {
}
let mapped = r.buffer.slice(..r.slots.len() as u64 * 4);
if let Ok(data) = mapped.get_mapped_range() {
let results: &[u32] = bytemuck::cast_slice(&data);
// The mapping isn't guaranteed to be 4-byte aligned (a Vega 11
// on Windows panicked in cast_slice), so copy the words out.
let results: Vec<u32> = bytemuck::pod_collect_to_vec(&data);
let (mut hidden, mut indices) = (0, 0u64);
for (&result, &n) in results.iter().zip(&r.indices) {
if result != r.stamp {
@@ -283,7 +285,7 @@ impl Cull {
}
let share = indices as f32 / r.total.max(1) as f32;
self.hidden = ([hidden, results.len()], share);
for (&slot, &result) in r.slots.iter().zip(results) {
for (&slot, &result) in r.slots.iter().zip(&results) {
let slot = slot as usize;
if slot >= self.seen.len() {
self.seen.resize(slot + 1, false);
+2 -1
View File
@@ -147,7 +147,8 @@ impl GpuTimer {
continue;
}
if let Ok(data) = slot.buffer.slice(..).get_mapped_range() {
let stamps: &[u64] = bytemuck::cast_slice(&data);
// Read unaligned: the mapping isn't guaranteed to be 8-byte aligned.
let stamps: [u64; 2] = bytemuck::pod_read_unaligned(&data[..16]);
let ticks = stamps[1].saturating_sub(stamps[0]);
out.push((ticks as f64 * f64::from(self.period_ns) / 1e6) as f32);
}