Skip to content

@tmrw-realityos/charm


@tmrw-realityos/charm / WebGPURenderContext

Class: WebGPURenderContext

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:32

Constructors

new WebGPURenderContext()

new WebGPURenderContext(device): WebGPURenderContext

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:86

Parameters

device

GPUDevice

Returns

WebGPURenderContext

Properties

alphaAddBlendDescriptor

alphaAddBlendDescriptor: GPUBlendState

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:81


alphaBlendDescriptor

alphaBlendDescriptor: GPUBlendState

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:76


backend

backend: WebGPUBackend

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:35


bindGroupCache

bindGroupCache: Map<number, GPUBindGroup>

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:43


bindGroupLayoutCache

bindGroupLayoutCache: Map<string, GPUBindGroupLayout>

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:44


bufferBindGroupsCache

bufferBindGroupsCache: WeakMap<GPUBuffer, GPUBindGroup[]>

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:63


buffersPendingUpdate

buffersPendingUpdate: WebGPUBuffer[] = []

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:66


computeCache

computeCache: Cache<GPUShaderModule>

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:56


computePipelineCache

computePipelineCache: Cache<GPUComputePipeline>

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:49


currentRenderBuffer?

optional currentRenderBuffer: GPUTexture

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:70


currentRenderPass?

optional currentRenderPass: GPURenderPassEncoder

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:69


defaultViewFormat

defaultViewFormat: GPUTextureFormat

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:38


device

device: GPUDevice

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:34


dynUniforms

dynUniforms: WebGPUDynamicUniforms

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:67


globalsUniformBuffer?

optional globalsUniformBuffer: WebGPUBuffer

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:72


mipmapGenerator

readonly mipmapGenerator: WebGPUMipmapGenerator

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:74


renderPipelineCache

renderPipelineCache: Cache<GPURenderPipeline>

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:47


renderPipelineDescriptorCache

renderPipelineDescriptorCache: Cache<GPURenderPipelineDescriptor>

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:51


samplerCache

samplerCache: Map<number, GPUSampler>

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:62


shaderCache

shaderCache: Cache<WebGPUShader>

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:55


textureBindGroupsCache

textureBindGroupsCache: WeakMap<GPUTexture, GPUBindGroup[]>

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:60


textureSampler

textureSampler: TextureSampler

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:61


texturesCache

texturesCache: Cache<WebGPUTexture>

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:59


current

static current: WebGPURenderContext

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:33

Accessors

renderPipelineDescriptorCacheValues

Get Signature

get renderPipelineDescriptorCacheValues(): GPURenderPipelineDescriptor[]

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:133

Returns

GPURenderPipelineDescriptor[]

Methods

addBufferToPending()

addBufferToPending(buffer): void

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:414

Used to avoid writing to the same buffer over a over when you just want to modify it once with the final data

Parameters

buffer

WebGPUBuffer

Returns

void


applyShaderToTexture()

applyShaderToTexture(encoder, input, destination, shader, data): void

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:396

Parameters

encoder

GPUCommandEncoder

input

GPUTexture

destination

GPUTexture

shader

WebGPUShader

data

ArrayBuffer

Returns

void


clearCache()

clearCache(): void

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:119

Returns

void


createSimpleBindGroup()

createSimpleBindGroup(layout, items, label): GPUBindGroup

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:311

Allows to create a bindgroup very easy (single string) and fast (cached descriptor). The layout could be an existing GPUBindGroupLayout or a string describing it, using syntax described in the function createSimpleBindGroupLayout.

Parameters

layout

string | GPUBindGroupLayout

items

(null | WebGPUBuffer | GPUBuffer | WebGPUTexture | GPUTextureView | GPUSampler | GPUBufferBinding)[]

label

string

Returns

GPUBindGroup


createSimpleBindGroupLayout()

createSimpleBindGroupLayout(types_key, label): GPUBindGroupLayout

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:215

Helper to build BindGroupLayout using a very simple interface: You must pass a string that contain a description of usage of every bindGroupItem in the right order, separated by commas. The properties of a single item are separated by '|' character: Example: "vs|uniform,fs|texture" means two items, one uniform for the vertex shader and one texture for the fragment shader.

Here is a list of all available keywords:

  • vs: used in a vertex shader
  • fs: used in a fragment shader
  • cs: used in a compute shader
  • uniform: used as uniform in a shader
  • read: read only buffer
  • store: storage buffer
  • texture: texture 2D
  • texture_multisampled: texture multisampled
  • texture_depth: depth texture
  • texture_depth_multisampled: depth texture multisampled
  • cube: texture Cubemap
  • sampler: texture sampler
  • dynamic: uniform buffer with dynamic offset All this keywords can be mixed to define all properties of every item. This string also applies as a hash for reusing bindgroup layouts. Use this method in conjunction with createSimpleBindGroup.

Parameters

types_key

string

label

string

Returns

GPUBindGroupLayout


createSimpleRenderPassDescriptor()

createSimpleRenderPassDescriptor(targetTexture): GPURenderPassDescriptor

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:363

An easy way to create a RenderPassDescriptor given a texture

Parameters

targetTexture

GPUTexture

Returns

GPURenderPassDescriptor


destroy()

destroy(): void

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:105

Returns

void


drawGeometryFromRenderable()

drawGeometryFromRenderable(renderable, renderPass, lastGeometryIndex): number

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:649

does the draw call once all is set

Parameters

renderable

RenderableDescriptor

renderPass

GPURenderPassEncoder

lastGeometryIndex

number = -1

Returns

number


getBufferBindGroup()

getBufferBindGroup(input, usage): GPUBindGroup

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:515

Asumes usage is for compute shader

Parameters

input

GPUBuffer

usage

number = eBindGroupUsage.fragment

Returns

GPUBindGroup


getPipeline()

getPipeline(material, shader, primitive, sampleCount, colorFormat, depthFormat?, colorFormat2?): GPURenderPipeline

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:540

Finds the right pipeline by generating a hash from the input

Parameters

material

Material

shader

WebGPUShader

primitive

WebGPUPrimitive

sampleCount

number

colorFormat

GPUTextureFormat

depthFormat?

"none" | GPUTextureFormat

colorFormat2?

GPUTextureFormat

Returns

GPURenderPipeline


getQuadBindGroup()

getQuadBindGroup(input): GPUBindGroup

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:383

Helper when you want to render a screen quad to apply some fx to a texture. It creates a BindGroup with the texture, sampler and generic uniform together.

Parameters

input

GPUTexture

Returns

GPUBindGroup


getSampler()

getSampler(textureSampler): GPUSampler

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:138

Creates a GPUSampler from a TextureSampler object, caching the result.

Parameters

textureSampler

TextureSampler

Returns

GPUSampler


getTexture()

getTexture(name, url?): WebGPUTexture

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:460

Retrieves a texture, and if doesnt exist, it tryes to load it.

Parameters

name

string

url?

string

Returns

WebGPUTexture


getTextureBindGroup()

getTextureBindGroup(input, usage, noSampler, format?): GPUBindGroup

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:482

Asumes usage is for fragment shader

Parameters

input

GPUTexture

usage

number = eBindGroupUsage.fragment

noSampler

boolean = false

format?

GPUTextureFormat

Returns

GPUBindGroup


getTextureSamplerDescriptor()

getTextureSamplerDescriptor(textureSampler): GPUSamplerDescriptor

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:152

Transforms a TextureSampler object into a GPUSamplerDescriptor object. It caches the result to go faster.

Parameters

textureSampler

TextureSampler

Returns

GPUSamplerDescriptor


loadTexture()

loadTexture(url, sRGB): WebGPUTexture

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:432

Parameters

url

string

sRGB

boolean = true

Returns

WebGPUTexture


registerTexture()

registerTexture(name, texture): void

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:468

Parameters

name

string

texture

WebGPUTexture

Returns

void


reset()

reset(): void

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:110

called to prepare for next frame, it sets up some offset to 0

Returns

void


setAsCurrent()

setAsCurrent(): void

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:115

Makes it the current one so it can be fetched from other places using WebGPURenderContext.current.

Returns

void


updatePendingBuffers()

updatePendingBuffers(): void

Defined in: packages/charm/src/graphics/WebGPU/WebGPURenderContext.ts:419

Called at the end of the framegraph

Returns

void