WebGPU

學海無涯,思境無維;數乃六藝,理之始也。
或有一得足矣 愚千慮

https://medium.com/@AlainGalvan/raw-webgpu-58522e638b17

Model







%0


Adapter

Adapter



Device

Device



Adapter->Device





Swap Chain

Swap Chain



Device->Swap Chain





Command Queue

Command Queue



Device->Command Queue





Command Encoder

Command Encoder



Device->Command Encoder





Pipelines

Pipelines



Device->Pipelines





GPUBuffer

GPUBuffer



Device->GPUBuffer





Bind Group

Bind Group



Device->Bind Group





Render Bundle Encoder

Render Bundle Encoder



Device->Render Bundle Encoder





GPUSampler

GPUSampler



Device->GPUSampler





GPUTexture

GPUTexture



Device->GPUTexture





Shader Module

Shader Module



Device->Shader Module





Query Set

Query Set



Device->Query Set





Surface

Surface



Swap Chain->Surface





Texture(View)

Texture(View)



Swap Chain->Texture(View)





Submit Command Buffer

Submit Command Buffer



Command Queue->Submit Command Buffer





Write Texture Buffer

Write Texture Buffer



Command Queue->Write Texture Buffer





Copy ImageBitmap to Texture

Copy ImageBitmap to Texture



Command Queue->Copy ImageBitmap to Texture





Render Pass

Render Pass



Command Encoder->Render Pass





Compute Pass

Compute Pass



Command Encoder->Compute Pass





Render Pipeline

Render Pipeline



Pipelines->Render Pipeline





Compute Pipeline

Compute Pipeline



Pipelines->Compute Pipeline





Vertex Buffer

Vertex Buffer



GPUBuffer->Vertex Buffer





Index Buffer

Index Buffer



GPUBuffer->Index Buffer





Uniform Buffer

Uniform Buffer



GPUBuffer->Uniform Buffer





Storage Buffer

Storage Buffer



GPUBuffer->Storage Buffer





Texture View

Texture View



GPUTexture->Texture View





Vertex Buffer->Render Pass





Index Buffer->Render Pass





Uniform Buffer->Render Pass





Command Buffer

Command Buffer



Render Pass->Command Buffer





Storage Buffer->Compute Pass





Compute Pass->Command Buffer





Render Pipeline->Render Pass





Compute Pipeline->Compute Pass





Command Buffer->Command Queue





GPU

  • requestAdapter()

request different adapter for different preference(ex: low-power)

Adapter

  • requestDevice()

Swap Chain

https://en.wikipedia.org/wiki/Swap_chain

A swap chain is a series of virtual framebuffers utilized by the graphics card and graphics API for frame rate stabilization and several other functions.

  • screen buffer
  • back buffer(s)

The swap chain usually exists in graphics memory, but it can exist in system memory as well. The non-utilization of a swap chain may result in stuttering rendering, but its existence and utilization are required by many graphics APIs.

A swap chain with two buffers is a double buffer.

  • Different present modes to prevent tearing on different devices.
  • frame buffer pixel formats
  • frame buffer size may change if window resizing.

Buffers

Create GPU Buffer

  • device.createBuffer()
  • buffer.getMappedRange() : get array buffer for CPU(js) from GPU.
  • buffer.unmap() : return the control back to GPU.
// Get a GPU buffer in a mapped state and an arrayBuffer for writing.
const gpuBuffer = device.createBuffer({
  mappedAtCreation: true,
  size: 4,
  usage: GPUBufferUsage.MAP_WRITE
});
const arrayBuffer = gpuBuffer.getMappedRange();

// Write bytes to buffer.
new Uint8Array(arrayBuffer).set([0, 1, 2, 3]);

// unmap the buffer from CPU, so GPU can use it now.
gpuBuffer.unmap();

Buffer Mapping

Get the mapping of the exist GPU buffer via buffer.mapAsyc(mode, offset, size).

An application can request to map a GPUBuffer so that they can access its content via ArrayBuffers that represent part of the GPUBuffer's allocations. Mapping a GPUBuffer is requested asynchronously with mapAsync() so that the user agent can ensure the GPU finished using the GPUBuffer before the application can access its content. Once the GPUBuffer is mapped the application can synchronously ask for access to ranges of its content with getMappedRange. A mapped GPUBuffer cannot be used by the GPU and must be unmapped using unmap before work using it can be submitted to the Queue timeline.

Babylon.js

babylon.js WebGPU

tags: WebGPU