mapBuffer method

  1. @override
Future<MappedBuffer> mapBuffer(
  1. StorageBuffer buffer,
  2. MapMode mode, {
  3. int offsetInBytes = 0,
  4. int? sizeInBytes,
})
override

Maps sizeInBytes bytes (to the end by default) of buffer from offsetInBytes into host memory, once every pass submitted before this call is done with it — DeviceFeature.mappedBuffers.

The staging-buffer path, both ways: MapMode.read on a BufferUsage.hostReadable buffer that a transfer pass copied results into, MapMode.write on a BufferUsage.hostWritable one the host fills and a transfer pass copies onward. See MappedBuffer for how long the bytes are valid. readBuffer is this, copied out and unmapped, for a whole buffer.

Implementation

@override
Future<MappedBuffer> mapBuffer(
  StorageBuffer buffer,
  MapMode mode, {
  int offsetInBytes = 0,
  int? sizeInBytes,
}) async {
  features.require(DeviceFeature.mappedBuffers, backend: _name);
  final size = sizeInBytes ?? buffer.lengthInBytes - offsetInBytes;
  calls.add(
    RecordedCall(
      'mapBuffer',
      arguments: (
        mode: mode,
        offsetInBytes: offsetInBytes,
        sizeInBytes: size,
      ),
    ),
  );
  return FakeMapping(ByteData(size));
}