ReadBuffer
Asynchronously copies data from a device buffer to host memory.
Read time 2 minutesLast updated 8 days ago
Definition
- Type: Method
- Namespace: UnityEngine.LightTransport
- Assembly: UnityEngine.CoreModule
ReadBuffer<T>(BufferSlice<T>, NativeArray<T>)
Asynchronously copies data from a device buffer to host memory.
void ReadBuffer<T>(BufferSlice<T> src, NativeArray<T> dst) where T : struct
Parameters
The BufferSlice specifying the source data on the device.
The destination array in CPU memory. Must remain valid until the operation completes.
Remarks
Initiates an asynchronous transfer of data from device memory to host memory. The method returns immediately after enqueuing the operation. Use IDeviceContext.Flush() to ensure the operation begins executing, then use IDeviceContext.Wait or IDeviceContext.IsCompleted with the provided event to determine when the transfer is complete.
The destination NativeArray<T> must remain allocated and unchanged until the read operation completes, as indicated by the event.
Warning: EventID instances are single-use. Do not reuse an event that has been passed to this method.
Examples
// Read data from buffer with event trackingusing var outputData = new NativeArray<int>(1024, Allocator.Persistent);var readEvent = context.CreateEvent();context.ReadBuffer(bufferSlice, outputData, readEvent);// Start execution and wait for completioncontext.Flush();bool success = context.Wait(readEvent);Assert.IsTrue(success);context.DestroyEvent(readEvent);// outputData now contains the buffer contents
ReadBuffer<T>(BufferSlice<T>, NativeArray<T>, EventID)
Asynchronously copies data from a device buffer to host memory.
void ReadBuffer<T>(BufferSlice<T> src, NativeArray<T> dst, EventID id) where T : struct
Parameters
The BufferSlice specifying the source data on the device.
The destination array in CPU memory. Must remain valid until the operation completes.
Optional event ID to track completion of the read operation.
Remarks
Initiates an asynchronous transfer of data from device memory to host memory. The method returns immediately after enqueuing the operation. Use IDeviceContext.Flush() to ensure the operation begins executing, then use IDeviceContext.Wait or IDeviceContext.IsCompleted with the provided event to determine when the transfer is complete.
The destination NativeArray<T> must remain allocated and unchanged until the read operation completes, as indicated by the event.
Warning: EventID instances are single-use. Do not reuse an event that has been passed to this method.
Examples
// Read data from buffer with event trackingusing var outputData = new NativeArray<int>(1024, Allocator.Persistent);var readEvent = context.CreateEvent();context.ReadBuffer(bufferSlice, outputData, readEvent);// Start execution and wait for completioncontext.Flush();bool success = context.Wait(readEvent);Assert.IsTrue(success);context.DestroyEvent(readEvent);// outputData now contains the buffer contents