I try to code a simple paint example with webgpu , so , in every mousemove , arrayData.length is changing. I keep an array storage all points(vec2 array) , I create new GPUBuffer with this points array in every frame,because I want to change the gpuBuffer.size whitch is readonly.
At last I get an Error : RangeError: Failed to execute 'createBuffer' on 'GPUDevice': createBuffer failed, size is too large for the implementation when mappedAtCreation == true
const data = new Float32Array( [ 0.3, 0.3, 0.4, 0.4 ] );
async function frame () {
const commandEncoder = device.createCommandEncoder();
... ...
const vertexBuffer = device.createBuffer( {
size: data.byteLength,
usage: GPUBufferUsage.VERTEX,
mappedAtCreation: true
} );
//@ts-ignore
const dst = new data.constructor( vertexBuffer.getMappedRange() );
dst.set( data );
vertexBuffer.unmap();
const passEncoder = commandEncoder.beginRenderPass( renderPassDescriptor );
passEncoder.setPipeline( pipeline );
passEncoder.setVertexBuffer( 0, vertexBuffer );
passEncoder.draw( data.length / 2 );
passEncoder.end();
device.queue.submit( [ commandEncoder.finish() ] );
// I try to destory the buffer after finish , it is no useful
vertexBuffer.destroy();
requestAnimationFrame( frame );
}
I want to update the vertexBuffer in mosemove(in every frame), at present, i create new GPUBuffer , it doesn't seem to work