I have an ArrayBuffer which is mapped to GPU memory called copyBuffer:
const BUFFER_SIZE = 1000;
const stagingBuffer = device.createBuffer({
size: BUFFER_SIZE,
usage: GPUBufferUsage.MAP_READ | GPUBufferUsage.COPY_DST,
});
.
.
.
await stagingBuffer.mapAsync(GPUMapMode.READ, 0, BUFFER_SIZE);
const copyBuffer = stagingBuffer.getMappedRange(0, BUFFER_SIZE);
console.log(copyBuffer);
/* Output:
{
byteLength: 1000,
detached: false
...
[[Prototype]]: ArrayBuffer
}
*/
As you see detached
property of copyBuffer
is false which seems correct because I didn’t detach it from GPU memory.
Although when I detach it something odd (in my opinion) happens:
// continue
console.log(copyBuffer);
stagingBuffer.unmap(); // detach here
/* Output:
{
byteLength: 1000,
detached: true
...
[[Prototype]]: ArrayBuffer
}
*/
I added one line after console log and even though it is non-blocking (not async-await), console log shows something different – detached
is true!
Doesn’t console.log
finished before unmap()
execution?