(
from: Pointer,
to: GPUPointer,
toOffset: number,
nbytes: number
)
| 936 | } |
| 937 | |
| 938 | private deviceCopyToGPU( |
| 939 | from: Pointer, |
| 940 | to: GPUPointer, |
| 941 | toOffset: number, |
| 942 | nbytes: number |
| 943 | ): void { |
| 944 | // Flush batched compute passes before writing to a GPU buffer, |
| 945 | // otherwise the write may be reordered before pending dispatches |
| 946 | // that read from the same buffer. |
| 947 | this.flushCommands(); |
| 948 | let rawBytes = this.memory.loadRawBytes(from, nbytes); |
| 949 | if (rawBytes.length % 4 !== 0) { |
| 950 | // writeBuffer requires length to be multiples of 4, so we pad here |
| 951 | const toPad = 4 - rawBytes.length % 4; |
| 952 | const padded = new Uint8Array(rawBytes.length + toPad); |
| 953 | padded.set(rawBytes); |
| 954 | rawBytes = padded; |
| 955 | nbytes = nbytes + toPad; |
| 956 | } |
| 957 | this.device.queue.writeBuffer( |
| 958 | this.gpuBufferFromPtr(to), |
| 959 | toOffset, |
| 960 | rawBytes as GPUAllowSharedBufferSource, |
| 961 | 0, |
| 962 | nbytes |
| 963 | ); |
| 964 | } |
| 965 | |
| 966 | /** |
| 967 | * Get a MAP_READ staging buffer from the pool, or create one if none fits. |
no test coverage detected