I have a uniform buffer that is created like this:
const temp = new Float32Array([0, 0, 0, 0, 0, 0, 0, 0]);
const positionBuffer = device.createBuffer({
size: temp.byteLength,
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_SRC,
mappedAtCreation: true,
});
const positionArray = new Float32Array(positionBuffer.getMappedRange());
positionArray.set(temp);
positionBuffer.unmap();
When I want to update the position uniform, I try to run positionBuffer.mapAsync(GPUMapMode.WRITE)
but it fails with the following warning:
The buffer usages (BufferUsage::(CopySrc|Uniform)) do not contain BufferUsage::MapWrite.
But when I then add the MAP_WRITE
flag I get a different warning:
Buffer usages (BufferUsage::(MapWrite|CopyDst|Index)) is invalid. If a buffer usage contains BufferUsage::MapWrite the only other allowed usage is BufferUsage::CopySrc.
I obviously need the uniform flag and probably the copy_dst flag (or maybe not?). I would assume that it would be better to map the buffer and directly write to GPU memory rather than any other way, so how would I achieve this?