blob: a7d154a7e65817411a734b09df2903a7d2763e5a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
import { memcpy, TypedArrayBufferView } from '../../common/util/util.js';
import { align } from './math.js';
/**
* Creates a buffer with the contents of some TypedArray.
* The buffer size will always be aligned to 4 as we set mappedAtCreation === true when creating the
* buffer.
*/
export function makeBufferWithContents(
device: GPUDevice,
dataArray: TypedArrayBufferView,
usage: GPUBufferUsageFlags
): GPUBuffer {
const buffer = device.createBuffer({
mappedAtCreation: true,
size: align(dataArray.byteLength, 4),
usage,
});
memcpy({ src: dataArray }, { dst: buffer.getMappedRange() });
buffer.unmap();
return buffer;
}
|