Appearance
@tmrw-realityos/charm • Docs
@tmrw-realityos/charm / WebGPUDynamicUniforms
Class: WebGPUDynamicUniforms
This class helps handle sending small chunks of data as uniforms to shaders. Instead of creating a buffer for every one of them, you can use this one with some offset.
Usage
To send small blocks of data (< 256bytes) to a shader you can use the storeInGenericBuffer:
typescript
//store inside a global shared buffer
const offset = dynUniforms.store(mydata.buffer);
//during rendering call this method to bind the global uniforms bindgroup
dynUniforms.bindBufferOffset( renderpass, bind_group_index, offset );
To mark a variable that will use this buffer, you must assign a name that contains the word DYNAMIC like: uniforms_DYNAMIC.
Keep in mind that this buffer must be uploaded to the GPU before the rendering calls are sent to the command buffer. This is already done in the FrameGraph execute method, but if you are not using the frame graph you must call manually to:
typescript
dynUniforms.updateBuffer();
You can find dynUniforms inside renderContext as context.dynUniforms
Constructors
new WebGPUDynamicUniforms()
new WebGPUDynamicUniforms(
device
):WebGPUDynamicUniforms
Parameters
• device: GPUDevice
Returns
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:52
Properties
buffer
buffer:
WebGPUBuffer
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:39
CSReadBindGroup
CSReadBindGroup:
GPUBindGroup
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:50
CSStoreBindGroup
CSStoreBindGroup:
GPUBindGroup
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:49
currentOffset
currentOffset:
number
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:40
data
data:
Uint8Array
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:38
device
device:
GPUDevice
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:36
FSBindGroup
FSBindGroup:
GPUBindGroup
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:47
stagingBuffer
stagingBuffer:
WebGPUBuffer
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:43
stagingData
stagingData:
Uint8Array
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:42
stagingOffset
stagingOffset:
number
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:44
VSBindGroup
VSBindGroup:
GPUBindGroup
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:46
VSFSBindGroup
VSFSBindGroup:
GPUBindGroup
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:48
Methods
bindBuffer()
bindBuffer(
renderPass
,index
,data
,usage
):void
Allows to pass small chunk of memory to shader, it is required that the variable has the DYNAMIC word in the name, like uniforms_DYNAMIC. To know more how to use, check the intro.
Parameters
• renderPass: GPURenderPassEncoder
• index: number
• data: ArrayBuffer
• usage: ShaderUsage
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:199
bindBufferOffset()
bindBufferOffset(
renderPass
,index
,offset
,usage
):void
Parameters
• renderPass: GPURenderPassEncoder
• index: number
• offset: number
• usage: ShaderUsage
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:181
bindReadOnlyStorageBufferOffset()
bindReadOnlyStorageBufferOffset(
passEncoder
,index
,offset
):void
Parameters
• passEncoder: GPUComputePassEncoder
• index: number
• offset: number
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:256
bindStorageBufferOffset()
bindStorageBufferOffset(
passEncoder
,index
,offset
):void
Parameters
• passEncoder: GPUComputePassEncoder
• index: number
• offset: number
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:248
destroy()
destroy():
void
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:147
isFull()
isFull():
boolean
Returns
boolean
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:264
readBuffer()
readBuffer(
syncStagingbuffer
,offset
?,size
?):Promise
<Uint8Array
>
Readback from the generic buffer. The generic stagingbuffer must be unmapped prior to calling this method.
Parameters
• syncStagingbuffer: boolean
= true
Copy genericBuffer to genericStagingbuffer. Set to false if the staging buffer is already synchronized.
• offset?: number
Byte offset to read from
• size?: number
Byte size to read
Returns
Promise
<Uint8Array
>
Readback data
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:218
reset()
reset():
void
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:152
store()
store(
data
):number
Use this function when you want to send a small chunk of data to your shader during rendering for uniforms. Instead of creating a buffer, it will store your data in a global buffer, and return an offset that you can use to bind it later.
Parameters
• data: ArrayBuffer
Data to store in. Bytelength must be a multiple of four and less than 256.
Returns
number
Offset in the generic buffer needed for binding in bindBufferOffset
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:162
updateBuffer()
updateBuffer():
void
Returns
void
Defined in
packages/charm/src/graphics/WebGPU/WebGPUDynamicUniforms.ts:177