This commit is contained in:
Akko
2025-08-04 18:57:35 +02:00
parent 8cf6e78a79
commit 9495868c2e
5030 changed files with 518594 additions and 17609 deletions

View File

@@ -0,0 +1,165 @@
/// <reference types="@webgpu/types" />
import EventEmitter from 'eventemitter3';
import { BufferUsage } from './const';
import type { BindResource } from '../../gpu/shader/BindResource';
/** All the various typed arrays that exist in js */
export type TypedArray = Int8Array | Uint8Array | Int16Array | Uint16Array | Int32Array | Uint32Array | Uint8ClampedArray | Float32Array | Float64Array;
/** Options for creating a buffer */
export interface BufferOptions {
/**
* the data to initialize the buffer with, this can be a typed array,
* or a regular number array. If it is a number array, it will be converted to a Float32Array
*/
data?: TypedArray | number[];
/** the size of the buffer in bytes, if not supplied, it will be inferred from the data */
size?: number;
/** the usage of the buffer, see {@link rendering.BufferUsage} */
usage: number;
/** a label for the buffer, this is useful for debugging */
label?: string;
/**
* should the GPU buffer be shrunk when the data becomes smaller?
* changing this will cause the buffer to be destroyed and a new one created on the GPU
* this can be expensive, especially if the buffer is already big enough!
* setting this to false will prevent the buffer from being shrunk. This will yield better performance
* if you are constantly setting data that is changing size often.
* @default true
*/
shrinkToFit?: boolean;
}
export interface BufferDescriptor {
label?: string;
size: GPUSize64;
usage: BufferUsage;
mappedAtCreation?: boolean;
}
/**
* A wrapper for a WebGPU/WebGL Buffer.
* In PixiJS, the Buffer class is used to manage the data that is sent to the GPU rendering pipeline.
* It abstracts away the underlying GPU buffer and provides an interface for uploading typed arrays or other data to the GPU,
* They are used in the following places:
* <br><br>
* .1. {@link Geometry} as attribute data or index data for geometry
* <br>
* .2. {@link UniformGroup} as an underlying buffer for uniform data
* <br>
* .3. {@link BufferResource} as an underlying part of a buffer used directly by the GPU program
* <br>
*
* It is important to note that you must provide a usage type when creating a buffer. This is because
* the underlying GPU buffer needs to know how it will be used. For example, if you are creating a buffer
* to hold vertex data, you would use `BufferUsage.VERTEX`. This will tell the GPU that this buffer will be
* used as a vertex buffer. This is important because it will affect how you can use the buffer.
*
* Buffers are updated by calling the {@link Buffer.update} method. This immediately updates the buffer on the GPU.
* Be mindful of calling this more often than you need to. It is recommended to update buffers only when needed.
*
* In WebGPU, a GPU buffer cannot resized. This limitation is abstracted away, but know that resizing a buffer means
* creating a brand new one and destroying the old, so it is best to limit this if possible.
* @example
*
* const buffer = new Buffer({
* data: new Float32Array([1, 2, 3, 4]),
* usage: BufferUsage.VERTEX,
* });
* @memberof rendering
*/
export declare class Buffer extends EventEmitter<{
change: BindResource;
update: Buffer;
destroy: Buffer;
}> implements BindResource {
/**
* emits when the underlying buffer has changed shape (i.e. resized)
* letting the renderer know that it needs to discard the old buffer on the GPU and create a new one
* @event change
*/
/**
* emits when the underlying buffer data has been updated. letting the renderer know
* that it needs to update the buffer on the GPU
* @event update
*/
/**
* emits when the buffer is destroyed. letting the renderer know that it needs to destroy the buffer on the GPU
* @event destroy
*/
/** a unique id for this uniform group used through the renderer */
readonly uid: number;
/**
* a resource type, used to identify how to handle it when its in a bind group / shader resource
* @internal
* @ignore
*/
readonly _resourceType = "buffer";
/**
* the resource id used internally by the renderer to build bind group keys
* @internal
* @ignore
*/
_resourceId: number;
/**
* used internally to know if a uniform group was used in the last render pass
* @internal
* @ignore
*/
_touched: number;
/**
* a description of the buffer and how it should be set up on the GPU
* @internal
* @ignore
*/
readonly descriptor: BufferDescriptor;
/**
* @internal
* @ignore
*/
_updateID: number;
/**
* @internal
* @ignore
*/
_updateSize: number;
private _data;
/**
* should the GPU buffer be shrunk when the data becomes smaller?
* changing this will cause the buffer to be destroyed and a new one created on the GPU
* this can be expensive, especially if the buffer is already big enough!
* setting this to false will prevent the buffer from being shrunk. This will yield better performance
* if you are constantly setting data that is changing size often.
* @default true
*/
shrinkToFit: boolean;
/**
* Has the buffer been destroyed?
* @readonly
*/
destroyed: boolean;
/**
* Creates a new Buffer with the given options
* @param options - the options for the buffer
*/
constructor(options: BufferOptions);
/** the data in the buffer */
get data(): TypedArray;
set data(value: TypedArray);
/** whether the buffer is static or not */
get static(): boolean;
set static(value: boolean);
/**
* Sets the data in the buffer to the given value. This will immediately update the buffer on the GPU.
* If you only want to update a subset of the buffer, you can pass in the size of the data.
* @param value - the data to set
* @param size - the size of the data in bytes
* @param syncGPU - should the buffer be updated on the GPU immediately?
*/
setDataWithSize(value: TypedArray, size: number, syncGPU: boolean): void;
/**
* updates the buffer on the GPU to reflect the data in the buffer.
* By default it will update the entire buffer. If you only want to update a subset of the buffer,
* you can pass in the size of the buffer to update.
* @param sizeInBytes - the new size of the buffer in bytes
*/
update(sizeInBytes?: number): void;
/** Destroys the buffer */
destroy(): void;
}

View File

@@ -0,0 +1,156 @@
'use strict';
var EventEmitter = require('eventemitter3');
var uid = require('../../../../utils/data/uid.js');
var _const = require('./const.js');
"use strict";
class Buffer extends EventEmitter {
/**
* Creates a new Buffer with the given options
* @param options - the options for the buffer
*/
constructor(options) {
let { data, size } = options;
const { usage, label, shrinkToFit } = options;
super();
/**
* emits when the underlying buffer has changed shape (i.e. resized)
* letting the renderer know that it needs to discard the old buffer on the GPU and create a new one
* @event change
*/
/**
* emits when the underlying buffer data has been updated. letting the renderer know
* that it needs to update the buffer on the GPU
* @event update
*/
/**
* emits when the buffer is destroyed. letting the renderer know that it needs to destroy the buffer on the GPU
* @event destroy
*/
/** a unique id for this uniform group used through the renderer */
this.uid = uid.uid("buffer");
/**
* a resource type, used to identify how to handle it when its in a bind group / shader resource
* @internal
* @ignore
*/
this._resourceType = "buffer";
/**
* the resource id used internally by the renderer to build bind group keys
* @internal
* @ignore
*/
this._resourceId = uid.uid("resource");
/**
* used internally to know if a uniform group was used in the last render pass
* @internal
* @ignore
*/
this._touched = 0;
/**
* @internal
* @ignore
*/
this._updateID = 1;
/**
* should the GPU buffer be shrunk when the data becomes smaller?
* changing this will cause the buffer to be destroyed and a new one created on the GPU
* this can be expensive, especially if the buffer is already big enough!
* setting this to false will prevent the buffer from being shrunk. This will yield better performance
* if you are constantly setting data that is changing size often.
* @default true
*/
this.shrinkToFit = true;
/**
* Has the buffer been destroyed?
* @readonly
*/
this.destroyed = false;
if (data instanceof Array) {
data = new Float32Array(data);
}
this._data = data;
size = size ?? data?.byteLength;
const mappedAtCreation = !!data;
this.descriptor = {
size,
usage,
mappedAtCreation,
label
};
this.shrinkToFit = shrinkToFit ?? true;
}
/** the data in the buffer */
get data() {
return this._data;
}
set data(value) {
this.setDataWithSize(value, value.length, true);
}
/** whether the buffer is static or not */
get static() {
return !!(this.descriptor.usage & _const.BufferUsage.STATIC);
}
set static(value) {
if (value) {
this.descriptor.usage |= _const.BufferUsage.STATIC;
} else {
this.descriptor.usage &= ~_const.BufferUsage.STATIC;
}
}
/**
* Sets the data in the buffer to the given value. This will immediately update the buffer on the GPU.
* If you only want to update a subset of the buffer, you can pass in the size of the data.
* @param value - the data to set
* @param size - the size of the data in bytes
* @param syncGPU - should the buffer be updated on the GPU immediately?
*/
setDataWithSize(value, size, syncGPU) {
this._updateID++;
this._updateSize = size * value.BYTES_PER_ELEMENT;
if (this._data === value) {
if (syncGPU)
this.emit("update", this);
return;
}
const oldData = this._data;
this._data = value;
if (oldData.length !== value.length) {
if (!this.shrinkToFit && value.byteLength < oldData.byteLength) {
if (syncGPU)
this.emit("update", this);
} else {
this.descriptor.size = value.byteLength;
this._resourceId = uid.uid("resource");
this.emit("change", this);
}
return;
}
if (syncGPU)
this.emit("update", this);
}
/**
* updates the buffer on the GPU to reflect the data in the buffer.
* By default it will update the entire buffer. If you only want to update a subset of the buffer,
* you can pass in the size of the buffer to update.
* @param sizeInBytes - the new size of the buffer in bytes
*/
update(sizeInBytes) {
this._updateSize = sizeInBytes ?? this._updateSize;
this._updateID++;
this.emit("update", this);
}
/** Destroys the buffer */
destroy() {
this.destroyed = true;
this.emit("destroy", this);
this.emit("change", this);
this._data = null;
this.descriptor = null;
this.removeAllListeners();
}
}
exports.Buffer = Buffer;
//# sourceMappingURL=Buffer.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,154 @@
import EventEmitter from 'eventemitter3';
import { uid } from '../../../../utils/data/uid.mjs';
import { BufferUsage } from './const.mjs';
"use strict";
class Buffer extends EventEmitter {
/**
* Creates a new Buffer with the given options
* @param options - the options for the buffer
*/
constructor(options) {
let { data, size } = options;
const { usage, label, shrinkToFit } = options;
super();
/**
* emits when the underlying buffer has changed shape (i.e. resized)
* letting the renderer know that it needs to discard the old buffer on the GPU and create a new one
* @event change
*/
/**
* emits when the underlying buffer data has been updated. letting the renderer know
* that it needs to update the buffer on the GPU
* @event update
*/
/**
* emits when the buffer is destroyed. letting the renderer know that it needs to destroy the buffer on the GPU
* @event destroy
*/
/** a unique id for this uniform group used through the renderer */
this.uid = uid("buffer");
/**
* a resource type, used to identify how to handle it when its in a bind group / shader resource
* @internal
* @ignore
*/
this._resourceType = "buffer";
/**
* the resource id used internally by the renderer to build bind group keys
* @internal
* @ignore
*/
this._resourceId = uid("resource");
/**
* used internally to know if a uniform group was used in the last render pass
* @internal
* @ignore
*/
this._touched = 0;
/**
* @internal
* @ignore
*/
this._updateID = 1;
/**
* should the GPU buffer be shrunk when the data becomes smaller?
* changing this will cause the buffer to be destroyed and a new one created on the GPU
* this can be expensive, especially if the buffer is already big enough!
* setting this to false will prevent the buffer from being shrunk. This will yield better performance
* if you are constantly setting data that is changing size often.
* @default true
*/
this.shrinkToFit = true;
/**
* Has the buffer been destroyed?
* @readonly
*/
this.destroyed = false;
if (data instanceof Array) {
data = new Float32Array(data);
}
this._data = data;
size = size ?? data?.byteLength;
const mappedAtCreation = !!data;
this.descriptor = {
size,
usage,
mappedAtCreation,
label
};
this.shrinkToFit = shrinkToFit ?? true;
}
/** the data in the buffer */
get data() {
return this._data;
}
set data(value) {
this.setDataWithSize(value, value.length, true);
}
/** whether the buffer is static or not */
get static() {
return !!(this.descriptor.usage & BufferUsage.STATIC);
}
set static(value) {
if (value) {
this.descriptor.usage |= BufferUsage.STATIC;
} else {
this.descriptor.usage &= ~BufferUsage.STATIC;
}
}
/**
* Sets the data in the buffer to the given value. This will immediately update the buffer on the GPU.
* If you only want to update a subset of the buffer, you can pass in the size of the data.
* @param value - the data to set
* @param size - the size of the data in bytes
* @param syncGPU - should the buffer be updated on the GPU immediately?
*/
setDataWithSize(value, size, syncGPU) {
this._updateID++;
this._updateSize = size * value.BYTES_PER_ELEMENT;
if (this._data === value) {
if (syncGPU)
this.emit("update", this);
return;
}
const oldData = this._data;
this._data = value;
if (oldData.length !== value.length) {
if (!this.shrinkToFit && value.byteLength < oldData.byteLength) {
if (syncGPU)
this.emit("update", this);
} else {
this.descriptor.size = value.byteLength;
this._resourceId = uid("resource");
this.emit("change", this);
}
return;
}
if (syncGPU)
this.emit("update", this);
}
/**
* updates the buffer on the GPU to reflect the data in the buffer.
* By default it will update the entire buffer. If you only want to update a subset of the buffer,
* you can pass in the size of the buffer to update.
* @param sizeInBytes - the new size of the buffer in bytes
*/
update(sizeInBytes) {
this._updateSize = sizeInBytes ?? this._updateSize;
this._updateID++;
this.emit("update", this);
}
/** Destroys the buffer */
destroy() {
this.destroyed = true;
this.emit("destroy", this);
this.emit("change", this);
this._data = null;
this.descriptor = null;
this.removeAllListeners();
}
}
export { Buffer };
//# sourceMappingURL=Buffer.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,90 @@
import EventEmitter from 'eventemitter3';
import type { BindResource } from '../../gpu/shader/BindResource';
import type { Buffer } from './Buffer';
/**
* A resource that can be bound to a bind group and used in a shader.
* Whilst a buffer can be used as a resource, this class allows you to specify an offset and size of the buffer to use.
* This is useful if you have a large buffer and only part of it is used in a shader.
*
* This resource, will listen for changes on the underlying buffer and emit a itself if the buffer changes shape.
* @example
*
* const buffer = new Buffer({
* data: new Float32Array(1000),
* usage: BufferUsage.UNIFORM,
* });
* // Create a buffer resource that uses the first 100 bytes of a buffer
* const bufferResource = new BufferResource({
* buffer,
* offset: 0,
* size: 100,
* });
* @memberof rendering
*/
export declare class BufferResource extends EventEmitter<{
change: BindResource;
}> implements BindResource {
/**
* emits when the underlying buffer has changed shape (i.e. resized)
* letting the renderer know that it needs to discard the old buffer on the GPU and create a new one
* @event change
*/
/** a unique id for this uniform group used through the renderer */
readonly uid: number;
/**
* a resource type, used to identify how to handle it when its in a bind group / shader resource
* @internal
* @ignore
*/
readonly _resourceType = "bufferResource";
/**
* used internally to know if a uniform group was used in the last render pass
* @internal
* @ignore
*/
_touched: number;
/**
* the resource id used internally by the renderer to build bind group keys
* @internal
* @ignore
*/
_resourceId: number;
/** the underlying buffer that this resource is using */
buffer: Buffer;
/** the offset of the buffer this resource is using. If not provided, then it will use the offset of the buffer. */
readonly offset: number;
/** the size of the buffer this resource is using. If not provided, then it will use the size of the buffer. */
readonly size: number;
/**
* A cheeky hint to the GL renderer to let it know this is a BufferResource
* @internal
* @ignore
*/
readonly _bufferResource = true;
/**
* Has the Buffer resource been destroyed?
* @readonly
*/
destroyed: boolean;
/**
* Create a new Buffer Resource.
* @param options - The options for the buffer resource
* @param options.buffer - The underlying buffer that this resource is using
* @param options.offset - The offset of the buffer this resource is using.
* If not provided, then it will use the offset of the buffer.
* @param options.size - The size of the buffer this resource is using.
* If not provided, then it will use the size of the buffer.
*/
constructor({ buffer, offset, size }: {
buffer: Buffer;
offset?: number;
size?: number;
});
protected onBufferChange(): void;
/**
* Destroys this resource. Make sure the underlying buffer is not used anywhere else
* if you want to destroy it as well, or code will explode
* @param destroyBuffer - Should the underlying buffer be destroyed as well?
*/
destroy(destroyBuffer?: boolean): void;
}

View File

@@ -0,0 +1,80 @@
'use strict';
var EventEmitter = require('eventemitter3');
var uid = require('../../../../utils/data/uid.js');
"use strict";
class BufferResource extends EventEmitter {
/**
* Create a new Buffer Resource.
* @param options - The options for the buffer resource
* @param options.buffer - The underlying buffer that this resource is using
* @param options.offset - The offset of the buffer this resource is using.
* If not provided, then it will use the offset of the buffer.
* @param options.size - The size of the buffer this resource is using.
* If not provided, then it will use the size of the buffer.
*/
constructor({ buffer, offset, size }) {
super();
/**
* emits when the underlying buffer has changed shape (i.e. resized)
* letting the renderer know that it needs to discard the old buffer on the GPU and create a new one
* @event change
*/
/** a unique id for this uniform group used through the renderer */
this.uid = uid.uid("buffer");
/**
* a resource type, used to identify how to handle it when its in a bind group / shader resource
* @internal
* @ignore
*/
this._resourceType = "bufferResource";
/**
* used internally to know if a uniform group was used in the last render pass
* @internal
* @ignore
*/
this._touched = 0;
/**
* the resource id used internally by the renderer to build bind group keys
* @internal
* @ignore
*/
this._resourceId = uid.uid("resource");
/**
* A cheeky hint to the GL renderer to let it know this is a BufferResource
* @internal
* @ignore
*/
this._bufferResource = true;
/**
* Has the Buffer resource been destroyed?
* @readonly
*/
this.destroyed = false;
this.buffer = buffer;
this.offset = offset | 0;
this.size = size;
this.buffer.on("change", this.onBufferChange, this);
}
onBufferChange() {
this._resourceId = uid.uid("resource");
this.emit("change", this);
}
/**
* Destroys this resource. Make sure the underlying buffer is not used anywhere else
* if you want to destroy it as well, or code will explode
* @param destroyBuffer - Should the underlying buffer be destroyed as well?
*/
destroy(destroyBuffer = false) {
this.destroyed = true;
if (destroyBuffer) {
this.buffer.destroy();
}
this.emit("change", this);
this.buffer = null;
}
}
exports.BufferResource = BufferResource;
//# sourceMappingURL=BufferResource.js.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,78 @@
import EventEmitter from 'eventemitter3';
import { uid } from '../../../../utils/data/uid.mjs';
"use strict";
class BufferResource extends EventEmitter {
/**
* Create a new Buffer Resource.
* @param options - The options for the buffer resource
* @param options.buffer - The underlying buffer that this resource is using
* @param options.offset - The offset of the buffer this resource is using.
* If not provided, then it will use the offset of the buffer.
* @param options.size - The size of the buffer this resource is using.
* If not provided, then it will use the size of the buffer.
*/
constructor({ buffer, offset, size }) {
super();
/**
* emits when the underlying buffer has changed shape (i.e. resized)
* letting the renderer know that it needs to discard the old buffer on the GPU and create a new one
* @event change
*/
/** a unique id for this uniform group used through the renderer */
this.uid = uid("buffer");
/**
* a resource type, used to identify how to handle it when its in a bind group / shader resource
* @internal
* @ignore
*/
this._resourceType = "bufferResource";
/**
* used internally to know if a uniform group was used in the last render pass
* @internal
* @ignore
*/
this._touched = 0;
/**
* the resource id used internally by the renderer to build bind group keys
* @internal
* @ignore
*/
this._resourceId = uid("resource");
/**
* A cheeky hint to the GL renderer to let it know this is a BufferResource
* @internal
* @ignore
*/
this._bufferResource = true;
/**
* Has the Buffer resource been destroyed?
* @readonly
*/
this.destroyed = false;
this.buffer = buffer;
this.offset = offset | 0;
this.size = size;
this.buffer.on("change", this.onBufferChange, this);
}
onBufferChange() {
this._resourceId = uid("resource");
this.emit("change", this);
}
/**
* Destroys this resource. Make sure the underlying buffer is not used anywhere else
* if you want to destroy it as well, or code will explode
* @param destroyBuffer - Should the underlying buffer be destroyed as well?
*/
destroy(destroyBuffer = false) {
this.destroyed = true;
if (destroyBuffer) {
this.buffer.destroy();
}
this.emit("change", this);
this.buffer = null;
}
}
export { BufferResource };
//# sourceMappingURL=BufferResource.mjs.map

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,54 @@
/**
* Buffer usage flags. they can be combined using the bitwise OR operator
* eg : BufferUsage.VERTEX | BufferUsage.INDEX
* @memberof rendering
*/
export declare enum BufferUsage {
/**
* The buffer can be mapped for reading. (Example: calling mapAsync() with GPUMapMode.READ)
* May only be combined with COPY_DST.
*/
MAP_READ = 1,
/**
* The buffer can be mapped for writing. (Example: calling mapAsync() with GPUMapMode.WRITE)
* May only be combined with COPY_SRC.
*/
MAP_WRITE = 2,
/**
* The buffer can be used as the source of a copy operation.
* (Examples: as the source argument of a copyBufferToBuffer() or copyBufferToTexture() call.)
*/
COPY_SRC = 4,
/**
* The buffer can be used as the destination of a copy or write operation.
* (Examples: as the destination argument of a copyBufferToBuffer() or
* copyTextureToBuffer() call, or as the target of a writeBuffer() call.)
*/
COPY_DST = 8,
/** The buffer can be used as an index buffer. (Example: passed to setIndexBuffer().) */
INDEX = 16,
/** The buffer can be used as a vertex buffer. (Example: passed to setVertexBuffer().) */
VERTEX = 32,
/**
* The buffer can be used as a uniform buffer.
* (Example: as a bind group entry for a GPUBufferBindingLayout with a buffer.type of "uniform".)
*/
UNIFORM = 64,
/**
* The buffer can be used as a storage buffer.
* (Example: as a bind group entry for a GPUBufferBindingLayout with a buffer.type of "storage" or "read-only-storage".)
*/
STORAGE = 128,
/**
* The buffer can be used as to store indirect command arguments.
* (Examples: as the indirectBuffer argument of a drawIndirect() or dispatchWorkgroupsIndirect() call.)
*/
INDIRECT = 256,
/**
* The buffer can be used to capture query results.
* (Example: as the destination argument of a resolveQuerySet() call.)
*/
QUERY_RESOLVE = 512,
/** the buffer will not be updated frequently */
STATIC = 1024
}

View File

@@ -0,0 +1,20 @@
'use strict';
"use strict";
var BufferUsage = /* @__PURE__ */ ((BufferUsage2) => {
BufferUsage2[BufferUsage2["MAP_READ"] = 1] = "MAP_READ";
BufferUsage2[BufferUsage2["MAP_WRITE"] = 2] = "MAP_WRITE";
BufferUsage2[BufferUsage2["COPY_SRC"] = 4] = "COPY_SRC";
BufferUsage2[BufferUsage2["COPY_DST"] = 8] = "COPY_DST";
BufferUsage2[BufferUsage2["INDEX"] = 16] = "INDEX";
BufferUsage2[BufferUsage2["VERTEX"] = 32] = "VERTEX";
BufferUsage2[BufferUsage2["UNIFORM"] = 64] = "UNIFORM";
BufferUsage2[BufferUsage2["STORAGE"] = 128] = "STORAGE";
BufferUsage2[BufferUsage2["INDIRECT"] = 256] = "INDIRECT";
BufferUsage2[BufferUsage2["QUERY_RESOLVE"] = 512] = "QUERY_RESOLVE";
BufferUsage2[BufferUsage2["STATIC"] = 1024] = "STATIC";
return BufferUsage2;
})(BufferUsage || {});
exports.BufferUsage = BufferUsage;
//# sourceMappingURL=const.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"const.js","sources":["../../../../../src/rendering/renderers/shared/buffer/const.ts"],"sourcesContent":["/**\n * Buffer usage flags. they can be combined using the bitwise OR operator\n * eg : BufferUsage.VERTEX | BufferUsage.INDEX\n * @memberof rendering\n */\nexport enum BufferUsage\n// eslint-disable-next-line @typescript-eslint/indent\n{\n /**\n * The buffer can be mapped for reading. (Example: calling mapAsync() with GPUMapMode.READ)\n * May only be combined with COPY_DST.\n */\n MAP_READ = 0x0001,\n /**\n * The buffer can be mapped for writing. (Example: calling mapAsync() with GPUMapMode.WRITE)\n * May only be combined with COPY_SRC.\n */\n MAP_WRITE = 0x0002,\n /**\n * The buffer can be used as the source of a copy operation.\n * (Examples: as the source argument of a copyBufferToBuffer() or copyBufferToTexture() call.)\n */\n COPY_SRC = 0x0004,\n /**\n * The buffer can be used as the destination of a copy or write operation.\n * (Examples: as the destination argument of a copyBufferToBuffer() or\n * copyTextureToBuffer() call, or as the target of a writeBuffer() call.)\n */\n COPY_DST = 0x0008,\n /** The buffer can be used as an index buffer. (Example: passed to setIndexBuffer().) */\n INDEX = 0x0010,\n /** The buffer can be used as a vertex buffer. (Example: passed to setVertexBuffer().) */\n VERTEX = 0x0020,\n /**\n * The buffer can be used as a uniform buffer.\n * (Example: as a bind group entry for a GPUBufferBindingLayout with a buffer.type of \"uniform\".)\n */\n UNIFORM = 0x0040,\n /**\n * The buffer can be used as a storage buffer.\n * (Example: as a bind group entry for a GPUBufferBindingLayout with a buffer.type of \"storage\" or \"read-only-storage\".)\n */\n STORAGE = 0x0080,\n /**\n * The buffer can be used as to store indirect command arguments.\n * (Examples: as the indirectBuffer argument of a drawIndirect() or dispatchWorkgroupsIndirect() call.)\n */\n INDIRECT = 0x0100,\n /**\n * The buffer can be used to capture query results.\n * (Example: as the destination argument of a resolveQuerySet() call.)\n */\n QUERY_RESOLVE = 0x0200,\n /** the buffer will not be updated frequently */\n STATIC = 0x0400\n}\n"],"names":["BufferUsage"],"mappings":";;;AAKY,IAAA,WAAA,qBAAAA,YAAL,KAAA;AAOH,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,CAAX,CAAA,GAAA,UAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,eAAY,CAAZ,CAAA,GAAA,WAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,CAAX,CAAA,GAAA,UAAA,CAAA;AAMA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,CAAX,CAAA,GAAA,UAAA,CAAA;AAEA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,WAAQ,EAAR,CAAA,GAAA,OAAA,CAAA;AAEA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,YAAS,EAAT,CAAA,GAAA,QAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,aAAU,EAAV,CAAA,GAAA,SAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,aAAU,GAAV,CAAA,GAAA,SAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,GAAX,CAAA,GAAA,UAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,mBAAgB,GAAhB,CAAA,GAAA,eAAA,CAAA;AAEA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,YAAS,IAAT,CAAA,GAAA,QAAA,CAAA;AAjDQ,EAAAA,OAAAA,YAAAA,CAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;;;;"}

View File

@@ -0,0 +1,18 @@
"use strict";
var BufferUsage = /* @__PURE__ */ ((BufferUsage2) => {
BufferUsage2[BufferUsage2["MAP_READ"] = 1] = "MAP_READ";
BufferUsage2[BufferUsage2["MAP_WRITE"] = 2] = "MAP_WRITE";
BufferUsage2[BufferUsage2["COPY_SRC"] = 4] = "COPY_SRC";
BufferUsage2[BufferUsage2["COPY_DST"] = 8] = "COPY_DST";
BufferUsage2[BufferUsage2["INDEX"] = 16] = "INDEX";
BufferUsage2[BufferUsage2["VERTEX"] = 32] = "VERTEX";
BufferUsage2[BufferUsage2["UNIFORM"] = 64] = "UNIFORM";
BufferUsage2[BufferUsage2["STORAGE"] = 128] = "STORAGE";
BufferUsage2[BufferUsage2["INDIRECT"] = 256] = "INDIRECT";
BufferUsage2[BufferUsage2["QUERY_RESOLVE"] = 512] = "QUERY_RESOLVE";
BufferUsage2[BufferUsage2["STATIC"] = 1024] = "STATIC";
return BufferUsage2;
})(BufferUsage || {});
export { BufferUsage };
//# sourceMappingURL=const.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"const.mjs","sources":["../../../../../src/rendering/renderers/shared/buffer/const.ts"],"sourcesContent":["/**\n * Buffer usage flags. they can be combined using the bitwise OR operator\n * eg : BufferUsage.VERTEX | BufferUsage.INDEX\n * @memberof rendering\n */\nexport enum BufferUsage\n// eslint-disable-next-line @typescript-eslint/indent\n{\n /**\n * The buffer can be mapped for reading. (Example: calling mapAsync() with GPUMapMode.READ)\n * May only be combined with COPY_DST.\n */\n MAP_READ = 0x0001,\n /**\n * The buffer can be mapped for writing. (Example: calling mapAsync() with GPUMapMode.WRITE)\n * May only be combined with COPY_SRC.\n */\n MAP_WRITE = 0x0002,\n /**\n * The buffer can be used as the source of a copy operation.\n * (Examples: as the source argument of a copyBufferToBuffer() or copyBufferToTexture() call.)\n */\n COPY_SRC = 0x0004,\n /**\n * The buffer can be used as the destination of a copy or write operation.\n * (Examples: as the destination argument of a copyBufferToBuffer() or\n * copyTextureToBuffer() call, or as the target of a writeBuffer() call.)\n */\n COPY_DST = 0x0008,\n /** The buffer can be used as an index buffer. (Example: passed to setIndexBuffer().) */\n INDEX = 0x0010,\n /** The buffer can be used as a vertex buffer. (Example: passed to setVertexBuffer().) */\n VERTEX = 0x0020,\n /**\n * The buffer can be used as a uniform buffer.\n * (Example: as a bind group entry for a GPUBufferBindingLayout with a buffer.type of \"uniform\".)\n */\n UNIFORM = 0x0040,\n /**\n * The buffer can be used as a storage buffer.\n * (Example: as a bind group entry for a GPUBufferBindingLayout with a buffer.type of \"storage\" or \"read-only-storage\".)\n */\n STORAGE = 0x0080,\n /**\n * The buffer can be used as to store indirect command arguments.\n * (Examples: as the indirectBuffer argument of a drawIndirect() or dispatchWorkgroupsIndirect() call.)\n */\n INDIRECT = 0x0100,\n /**\n * The buffer can be used to capture query results.\n * (Example: as the destination argument of a resolveQuerySet() call.)\n */\n QUERY_RESOLVE = 0x0200,\n /** the buffer will not be updated frequently */\n STATIC = 0x0400\n}\n"],"names":["BufferUsage"],"mappings":";AAKY,IAAA,WAAA,qBAAAA,YAAL,KAAA;AAOH,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,CAAX,CAAA,GAAA,UAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,eAAY,CAAZ,CAAA,GAAA,WAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,CAAX,CAAA,GAAA,UAAA,CAAA;AAMA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,CAAX,CAAA,GAAA,UAAA,CAAA;AAEA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,WAAQ,EAAR,CAAA,GAAA,OAAA,CAAA;AAEA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,YAAS,EAAT,CAAA,GAAA,QAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,aAAU,EAAV,CAAA,GAAA,SAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,aAAU,GAAV,CAAA,GAAA,SAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,cAAW,GAAX,CAAA,GAAA,UAAA,CAAA;AAKA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,mBAAgB,GAAhB,CAAA,GAAA,eAAA,CAAA;AAEA,EAAAA,YAAAA,CAAAA,YAAAA,CAAA,YAAS,IAAT,CAAA,GAAA,QAAA,CAAA;AAjDQ,EAAAA,OAAAA,YAAAA,CAAAA;AAAA,CAAA,EAAA,WAAA,IAAA,EAAA;;;;"}

View File

@@ -0,0 +1,9 @@
/**
* Copies from one buffer to another.
* This is an optimised function that will use `Float64Array` window.
* This means it can copy twice as fast!
* @param sourceBuffer - the array buffer to copy from
* @param destinationBuffer - the array buffer to copy to
* @private
*/
export declare function fastCopy(sourceBuffer: ArrayBuffer, destinationBuffer: ArrayBuffer): void;

View File

@@ -0,0 +1,18 @@
'use strict';
"use strict";
function fastCopy(sourceBuffer, destinationBuffer) {
const lengthDouble = sourceBuffer.byteLength / 8 | 0;
const sourceFloat64View = new Float64Array(sourceBuffer, 0, lengthDouble);
const destinationFloat64View = new Float64Array(destinationBuffer, 0, lengthDouble);
destinationFloat64View.set(sourceFloat64View);
const remainingBytes = sourceBuffer.byteLength - lengthDouble * 8;
if (remainingBytes > 0) {
const sourceUint8View = new Uint8Array(sourceBuffer, lengthDouble * 8, remainingBytes);
const destinationUint8View = new Uint8Array(destinationBuffer, lengthDouble * 8, remainingBytes);
destinationUint8View.set(sourceUint8View);
}
}
exports.fastCopy = fastCopy;
//# sourceMappingURL=fastCopy.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"fastCopy.js","sources":["../../../../../../src/rendering/renderers/shared/buffer/utils/fastCopy.ts"],"sourcesContent":["/**\n * Copies from one buffer to another.\n * This is an optimised function that will use `Float64Array` window.\n * This means it can copy twice as fast!\n * @param sourceBuffer - the array buffer to copy from\n * @param destinationBuffer - the array buffer to copy to\n * @private\n */\nexport function fastCopy(sourceBuffer: ArrayBuffer, destinationBuffer: ArrayBuffer): void\n{\n const lengthDouble = (sourceBuffer.byteLength / 8) | 0;\n\n const sourceFloat64View = new Float64Array(sourceBuffer, 0, lengthDouble);\n const destinationFloat64View = new Float64Array(destinationBuffer, 0, lengthDouble);\n\n // Use set for faster copying\n destinationFloat64View.set(sourceFloat64View);\n\n // copying over the remaining bytes\n const remainingBytes = sourceBuffer.byteLength - (lengthDouble * 8);\n\n if (remainingBytes > 0)\n {\n const sourceUint8View = new Uint8Array(sourceBuffer, lengthDouble * 8, remainingBytes);\n const destinationUint8View = new Uint8Array(destinationBuffer, lengthDouble * 8, remainingBytes);\n\n // Direct copy for remaining bytes\n destinationUint8View.set(sourceUint8View);\n }\n}\n"],"names":[],"mappings":";;;AAQgB,SAAA,QAAA,CAAS,cAA2B,iBACpD,EAAA;AACI,EAAM,MAAA,YAAA,GAAgB,YAAa,CAAA,UAAA,GAAa,CAAK,GAAA,CAAA,CAAA;AAErD,EAAA,MAAM,iBAAoB,GAAA,IAAI,YAAa,CAAA,YAAA,EAAc,GAAG,YAAY,CAAA,CAAA;AACxE,EAAA,MAAM,sBAAyB,GAAA,IAAI,YAAa,CAAA,iBAAA,EAAmB,GAAG,YAAY,CAAA,CAAA;AAGlF,EAAA,sBAAA,CAAuB,IAAI,iBAAiB,CAAA,CAAA;AAG5C,EAAM,MAAA,cAAA,GAAiB,YAAa,CAAA,UAAA,GAAc,YAAe,GAAA,CAAA,CAAA;AAEjE,EAAA,IAAI,iBAAiB,CACrB,EAAA;AACI,IAAA,MAAM,kBAAkB,IAAI,UAAA,CAAW,YAAc,EAAA,YAAA,GAAe,GAAG,cAAc,CAAA,CAAA;AACrF,IAAA,MAAM,uBAAuB,IAAI,UAAA,CAAW,iBAAmB,EAAA,YAAA,GAAe,GAAG,cAAc,CAAA,CAAA;AAG/F,IAAA,oBAAA,CAAqB,IAAI,eAAe,CAAA,CAAA;AAAA,GAC5C;AACJ;;;;"}

View File

@@ -0,0 +1,16 @@
"use strict";
function fastCopy(sourceBuffer, destinationBuffer) {
const lengthDouble = sourceBuffer.byteLength / 8 | 0;
const sourceFloat64View = new Float64Array(sourceBuffer, 0, lengthDouble);
const destinationFloat64View = new Float64Array(destinationBuffer, 0, lengthDouble);
destinationFloat64View.set(sourceFloat64View);
const remainingBytes = sourceBuffer.byteLength - lengthDouble * 8;
if (remainingBytes > 0) {
const sourceUint8View = new Uint8Array(sourceBuffer, lengthDouble * 8, remainingBytes);
const destinationUint8View = new Uint8Array(destinationBuffer, lengthDouble * 8, remainingBytes);
destinationUint8View.set(sourceUint8View);
}
}
export { fastCopy };
//# sourceMappingURL=fastCopy.mjs.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"fastCopy.mjs","sources":["../../../../../../src/rendering/renderers/shared/buffer/utils/fastCopy.ts"],"sourcesContent":["/**\n * Copies from one buffer to another.\n * This is an optimised function that will use `Float64Array` window.\n * This means it can copy twice as fast!\n * @param sourceBuffer - the array buffer to copy from\n * @param destinationBuffer - the array buffer to copy to\n * @private\n */\nexport function fastCopy(sourceBuffer: ArrayBuffer, destinationBuffer: ArrayBuffer): void\n{\n const lengthDouble = (sourceBuffer.byteLength / 8) | 0;\n\n const sourceFloat64View = new Float64Array(sourceBuffer, 0, lengthDouble);\n const destinationFloat64View = new Float64Array(destinationBuffer, 0, lengthDouble);\n\n // Use set for faster copying\n destinationFloat64View.set(sourceFloat64View);\n\n // copying over the remaining bytes\n const remainingBytes = sourceBuffer.byteLength - (lengthDouble * 8);\n\n if (remainingBytes > 0)\n {\n const sourceUint8View = new Uint8Array(sourceBuffer, lengthDouble * 8, remainingBytes);\n const destinationUint8View = new Uint8Array(destinationBuffer, lengthDouble * 8, remainingBytes);\n\n // Direct copy for remaining bytes\n destinationUint8View.set(sourceUint8View);\n }\n}\n"],"names":[],"mappings":";AAQgB,SAAA,QAAA,CAAS,cAA2B,iBACpD,EAAA;AACI,EAAM,MAAA,YAAA,GAAgB,YAAa,CAAA,UAAA,GAAa,CAAK,GAAA,CAAA,CAAA;AAErD,EAAA,MAAM,iBAAoB,GAAA,IAAI,YAAa,CAAA,YAAA,EAAc,GAAG,YAAY,CAAA,CAAA;AACxE,EAAA,MAAM,sBAAyB,GAAA,IAAI,YAAa,CAAA,iBAAA,EAAmB,GAAG,YAAY,CAAA,CAAA;AAGlF,EAAA,sBAAA,CAAuB,IAAI,iBAAiB,CAAA,CAAA;AAG5C,EAAM,MAAA,cAAA,GAAiB,YAAa,CAAA,UAAA,GAAc,YAAe,GAAA,CAAA,CAAA;AAEjE,EAAA,IAAI,iBAAiB,CACrB,EAAA;AACI,IAAA,MAAM,kBAAkB,IAAI,UAAA,CAAW,YAAc,EAAA,YAAA,GAAe,GAAG,cAAc,CAAA,CAAA;AACrF,IAAA,MAAM,uBAAuB,IAAI,UAAA,CAAW,iBAAmB,EAAA,YAAA,GAAe,GAAG,cAAc,CAAA,CAAA;AAG/F,IAAA,oBAAA,CAAqB,IAAI,eAAe,CAAA,CAAA;AAAA,GAC5C;AACJ;;;;"}