Class GPUBuffer
- Namespace
- CSharpToJavaScript.APIs.JS
- Assembly
- CSharpToJavaScript.dll
The GPUBuffer interface of the {{domxref("WebGPU API", "WebGPU API", "", "nocode")}} represents a block of memory that can be used to store raw data to use in GPU operations.
[Value("GPUBuffer")]
public class GPUBuffer
- Inheritance
-
GPUBuffer
- Inherited Members
Remarks
A GPUBuffer object instance is created using the CreateBuffer(GPUBufferDescriptor) method.
-The WebGPU API
Constructors
GPUBuffer()
public GPUBuffer()
Properties
MapState
The mapState read-only property of the
GPUBuffer interface represents the mapped state of the GPUBuffer.
[Value("mapState")]
public GPUBufferMapState MapState { get; }
Property Value
- GPUBufferMapState
An enumerated value. Possible values are:
Remarks
Size
The size read-only property of the
GPUBuffer interface represents the length of the GPUBuffer's memory allocation, in bytes.
[Value("size")]
public ulong Size { get; }
Property Value
- ulong
A number.
Remarks
size is set via the size property in the descriptor object passed into the originating CreateBuffer(GPUBufferDescriptor) call.
-The WebGPU API
Usage
The usage read-only property of the
GPUBuffer interface contains the {{glossary("bitwise flags")}} representing the allowed usages of the GPUBuffer.
[Value("usage")]
public ulong Usage { get; }
Property Value
- ulong
The bitwise flags representing the original usages set when the
GPUBufferwas first created. The returned number is the sum of decimal values representing the different flags, as seen in the table below.Bitwise flag Usage description Hex equiv. Decimal equiv. GPUBufferUsage.COPY_SRCThe buffer can be used as the source of a copy operation, for example the source argument of a CopyBufferToBuffer(GPUBuffer, ulong, GPUBuffer, ulong, ulong) call. 0x0004 4 GPUBufferUsage.COPY_DSTThe buffer can be used as the destination of a copy/write operation, for example the destination argument of a CopyTextureToBuffer(GPUTexelCopyTextureInfo, GPUTexelCopyBufferInfo, Union222) call. 0x0008 8 GPUBufferUsage.INDEXThe buffer can be used as an index buffer, for example as the bufferargument passed to GPURenderPassEncoder.SetIndexBuffer.0x0010 16 GPUBufferUsage.INDIRECTThe buffer can be used to store indirect command arguments, for example as the indirectBufferargument of a GPURenderPassEncoder.DrawIndirect or DispatchWorkgroupsIndirect(GPUBuffer, ulong) call.0x0100 256 GPUBufferUsage.MAP_READThe buffer can be mapped for reading, for example when calling MapAsync(ulong, ulong, ulong) with a modeofGPUMapMode.READ. This flag may only be combined withGPUBufferUsage.COPY_DST.0x0001 1 GPUBufferUsage.MAP_WRITEThe buffer can be mapped for writing, for example when calling MapAsync(ulong, ulong, ulong) with a modeofGPUMapMode.WRITE. This flag may only be combined withGPUBufferUsage.COPY_SRC.0x0002 2 GPUBufferUsage.QUERY_RESOLVEThe buffer can be used to capture query results, for example as the destination argument of a ResolveQuerySet(GPUQuerySet, ulong, ulong, GPUBuffer, ulong) call. 0x0200 512 GPUBufferUsage.STORAGEThe buffer can be used as a storage buffer, for example as a resource in a bind group entry when creating a GPUBindGroup (via CreateBindGroup(GPUBindGroupDescriptor)), which adheres to a GPUBindGroupLayout entry with a buffer binding layout typeof"storage"or"read-only-storage".0x0080 128 GPUBufferUsage.UNIFORMThe buffer can be used as a uniform buffer, for example as a resource in a bind group entry when creating a GPUBindGroup (via CreateBindGroup(GPUBindGroupDescriptor)), which adheres to a GPUBindGroupLayout entry with a buffer binding layout typeof"uniform".0x0040 64 GPUBufferUsage.VERTEXThe buffer can be used as a vertex buffer, for example as the bufferargument passed to GPURenderPassEncoder.SetVertexBuffer.0x0020 32
Remarks
usage is set via the usage property in the descriptor object passed into the originating CreateBuffer(GPUBufferDescriptor) call.
-The WebGPU API
Methods
Destroy()
The destroy() method of the
GPUBuffer interface destroys the GPUBuffer.
[Value("destroy")]
public GlobalObject.Undefined Destroy()
Returns
Remarks
GetMappedRange(ulong, ulong)
The getMappedRange() method of the
GPUBuffer interface returns an {{jsxref("ArrayBuffer")}} containing the mapped contents of the GPUBuffer in the specified range.
[Value("getMappedRange")]
public ArrayBuffer GetMappedRange(ulong offset = 0, ulong size = 0)
Parameters
Returns
Remarks
This can only happen once the GPUBuffer has been successfully mapped with MapAsync(ulong, ulong, ulong) (this can be checked via MapState). While the GPUBuffer is mapped it cannot be used in any GPU commands.
When you have finished working with the GPUBuffer values, call Unmap() to unmap it, making it accessible to the GPU again. A TypeError is thrown if an attempt is made to detach the {{jsxref("ArrayBuffer")}} in any way other than via Unmap(), such as by calling {{jsxref("ArrayBuffer/transfer", "transfer()")}}.
-The WebGPU API
MapAsync(ulong, ulong, ulong)
The mapAsync() method of the
GPUBuffer interface maps the specified range of the GPUBuffer. It returns a Promise that resolves when the GPUBuffer's content is ready to be accessed. While the GPUBuffer is mapped it cannot be used in any GPU commands.
[Value("mapAsync")]
public Task<GlobalObject.Undefined> MapAsync(ulong mode, ulong offset = 0, ulong size = 0)
Parameters
Returns
- Task<GlobalObject.Undefined>
A Promise that resolves to GlobalObject.Undefined when the
GPUBuffer's content is ready to be accessed.
Remarks
Once the buffer is successfully mapped (which can be checked via MapState), calls to GetMappedRange(ulong, ulong) will return an {{jsxref("ArrayBuffer")}} containing the GPUBuffer's current values, to be read and updated by JavaScript as required.
When you have finished working with the GPUBuffer values, call Unmap() to unmap it, making it accessible to the GPU again.
-The WebGPU API
Unmap()
The unmap() method of the
GPUBuffer interface unmaps the mapped range of the GPUBuffer, making its contents available for use by the GPU again after it has previously been mapped with MapAsync(ulong, ulong, ulong) (the GPU cannot access a mapped GPUBuffer).
[Value("unmap")]
public GlobalObject.Undefined Unmap()
Returns
Remarks
When unmap() is called, any {{jsxref("ArrayBuffer")}}s created via GetMappedRange(ulong, ulong) are detached.
-The WebGPU API