(
from: GPUPointer,
fromOffset: number,
to: Pointer,
nbytes: number
)
| 1000 | } |
| 1001 | |
| 1002 | private deviceCopyFromGPU( |
| 1003 | from: GPUPointer, |
| 1004 | fromOffset: number, |
| 1005 | to: Pointer, |
| 1006 | nbytes: number |
| 1007 | ): void { |
| 1008 | // Flush batched compute passes before the readback copy. |
| 1009 | this.flushCommands(); |
| 1010 | const gpuTemp = this.getOrCreateReadStagingBuffer(nbytes); |
| 1011 | |
| 1012 | const copyEncoder = this.device.createCommandEncoder(); |
| 1013 | copyEncoder.copyBufferToBuffer( |
| 1014 | this.gpuBufferFromPtr(from), |
| 1015 | fromOffset, |
| 1016 | gpuTemp, |
| 1017 | 0, |
| 1018 | nbytes |
| 1019 | ); |
| 1020 | const copyCommands = copyEncoder.finish(); |
| 1021 | this.device.queue.submit([copyCommands]); |
| 1022 | |
| 1023 | const readPromise = gpuTemp.mapAsync(GPUMapMode.READ).then(() => { |
| 1024 | const data = gpuTemp.getMappedRange(0, nbytes); |
| 1025 | this.memory.storeRawBytes(to, new Uint8Array(data)); |
| 1026 | this.recycleReadStagingBuffer(gpuTemp); |
| 1027 | }); |
| 1028 | // Chain with any existing pending read so sync() awaits all of them. |
| 1029 | this.pendingGPUToCPUCopy = this.pendingGPUToCPUCopy |
| 1030 | ? this.pendingGPUToCPUCopy.then(() => readPromise) |
| 1031 | : readPromise; |
| 1032 | } |
| 1033 | |
| 1034 | private deviceCopyWithinGPU( |
| 1035 | from: GPUPointer, |
no test coverage detected