@@ -336,19 +336,41 @@ fn map_buffer(
336
336
337
337
let mapped = unsafe { std:: slice:: from_raw_parts_mut ( mapping. ptr . as_ptr ( ) , size as usize ) } ;
338
338
339
- for uninitialized in buffer
340
- . initialization_status
341
- . write ( )
342
- . drain ( offset.. ( size + offset ) )
339
+ // We can't call flush_mapped_ranges in this case, so we can't drain the uninitialized ranges either
340
+ if !mapping . is_coherent
341
+ && kind == HostMap :: Read
342
+ && !buffer . usage . contains ( wgt :: BufferUsages :: MAP_WRITE )
343
343
{
344
- // The mapping's pointer is already offset, however we track the
345
- // uninitialized range relative to the buffer's start.
346
- let fill_range =
347
- ( uninitialized. start - offset) as usize ..( uninitialized. end - offset) as usize ;
348
- mapped[ fill_range] . fill ( 0 ) ;
349
-
350
- if !mapping. is_coherent && kind == HostMap :: Read {
351
- unsafe { raw. flush_mapped_ranges ( raw_buffer, & [ uninitialized] ) } ;
344
+ for uninitialized in buffer
345
+ . initialization_status
346
+ . write ( )
347
+ . uninitialized ( offset..( size + offset) )
348
+ {
349
+ // The mapping's pointer is already offset, however we track the
350
+ // uninitialized range relative to the buffer's start.
351
+ let fill_range =
352
+ ( uninitialized. start - offset) as usize ..( uninitialized. end - offset) as usize ;
353
+ mapped[ fill_range] . fill ( 0 ) ;
354
+ }
355
+ } else {
356
+ for uninitialized in buffer
357
+ . initialization_status
358
+ . write ( )
359
+ . drain ( offset..( size + offset) )
360
+ {
361
+ // The mapping's pointer is already offset, however we track the
362
+ // uninitialized range relative to the buffer's start.
363
+ let fill_range =
364
+ ( uninitialized. start - offset) as usize ..( uninitialized. end - offset) as usize ;
365
+ mapped[ fill_range] . fill ( 0 ) ;
366
+
367
+ // NOTE: This is only possible when MAPPABLE_PRIMARY_BUFFERS is enabled.
368
+ if !mapping. is_coherent
369
+ && kind == HostMap :: Read
370
+ && buffer. usage . contains ( wgt:: BufferUsages :: MAP_WRITE )
371
+ {
372
+ unsafe { raw. flush_mapped_ranges ( raw_buffer, & [ uninitialized] ) } ;
373
+ }
352
374
}
353
375
}
354
376
0 commit comments