Ticket 022 — drain pending SDF cache writes after the frame's main submit. Maps each staging buffer in one pass (single `device.poll(Wait)` covers all of them), unpads the row-aligned payload back to the tightly-packed on-disk layout, and writes to the cache. Best-effort throughout: a write failure is silently ignored — the next cold launch just rebakes.
(&mut self)
| 7308 | /// to the cache. Best-effort throughout: a write failure is |
| 7309 | /// silently ignored — the next cold launch just rebakes. |
| 7310 | pub fn flush_sdf_cache_writes(&mut self) { |
| 7311 | if self.sdf_cache_writes.is_empty() { return; } |
| 7312 | let entries = std::mem::take(&mut self.sdf_cache_writes); |
| 7313 | |
| 7314 | // Issue map_async on every buffer up front so a single poll |
| 7315 | // resolves all of them — much cheaper than serially polling |
| 7316 | // per buffer when 8 cold-launch bakes complete in one frame. |
| 7317 | for (_, buf) in &entries { |
| 7318 | let slice = buf.slice(..); |
| 7319 | slice.map_async(wgpu::MapMode::Read, |_| { /* polled below */ }); |
| 7320 | } |
| 7321 | let _ = self.device.poll(wgpu::PollType::Wait { submission_index: None, timeout: None }); |
| 7322 | |
| 7323 | let row_tight = (MESH_SDF_RES * 4) as usize; |
| 7324 | let row_padded = ((MESH_SDF_RES * 4 + 255) & !255) as usize; |
| 7325 | let res = MESH_SDF_RES as usize; |
| 7326 | |
| 7327 | for (hash, buf) in entries { |
| 7328 | let slice = buf.slice(..); |
| 7329 | let data = slice.get_mapped_range(); |
| 7330 | // Strip the wgpu-required row padding back to a tight |
| 7331 | // 32³ × 4-byte payload before storing. |
| 7332 | let mut tight = vec![0u8; res * res * row_tight]; |
| 7333 | for z in 0..res { |
| 7334 | for y in 0..res { |
| 7335 | let src_off = (z * res + y) * row_padded; |
| 7336 | let dst_off = (z * res + y) * row_tight; |
| 7337 | tight[dst_off..dst_off + row_tight] |
| 7338 | .copy_from_slice(&data[src_off..src_off + row_tight]); |
| 7339 | } |
| 7340 | } |
| 7341 | drop(data); |
| 7342 | buf.unmap(); |
| 7343 | let _ = crate::sdf_cache::store(hash, &tight); |
| 7344 | } |
| 7345 | } |
| 7346 | |
| 7347 | /// Ticket 013 V2 — re-light every populated card texel from the |
| 7348 | /// scene's directional sun + analytic sky. Runs once per frame |
no test coverage detected