Skip to content

@tmrw-realityos/charm


@tmrw-realityos/charm / WebGPURenderContext

Class: WebGPURenderContext

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

Extends

  • TextureManager

Constructors

Constructor

new WebGPURenderContext(device): WebGPURenderContext

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

Parameters

device

GPUDevice

Returns

WebGPURenderContext

Overrides

TextureManager.constructor

Properties

alphaAddBlendDescriptor

alphaAddBlendDescriptor: GPUBlendState

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


alphaBlendDescriptor

alphaBlendDescriptor: GPUBlendState

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


backend

backend: WebGPUBackend

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


bindGroupCache

bindGroupCache: Map<number, GPUBindGroup>

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


bindGroupLayoutCache

bindGroupLayoutCache: Map<string, GPUBindGroupLayout>

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


bufferBindGroupsCache

bufferBindGroupsCache: WeakMap<GPUBuffer, GPUBindGroup[]>

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


buffersPendingUpdate

buffersPendingUpdate: WebGPUBuffer[] = []

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


computeCache

computeCache: Cache<GPUShaderModule>

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


computePipelineCache

computePipelineCache: Cache<GPUComputePipeline>

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


currentRenderBuffer?

optional currentRenderBuffer: GPUTexture

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


currentRenderPass?

optional currentRenderPass: GPURenderPassEncoder

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


defaultViewFormat

defaultViewFormat: GPUTextureFormat

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


device

device: GPUDevice

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


dynUniforms

dynUniforms: WebGPUDynamicUniforms

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


globalsUniformBuffer?

optional globalsUniformBuffer: WebGPUBuffer

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


mipmapGenerator

readonly mipmapGenerator: WebGPUMipmapGenerator

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


renderPipelineCache

renderPipelineCache: Cache<GPURenderPipeline>

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


renderPipelineDescriptorCache

renderPipelineDescriptorCache: Cache<GPURenderPipelineDescriptor>

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


samplerCache

samplerCache: Map<number, GPUSampler>

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


shaderCache

shaderCache: Cache<WebGPUShader>

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


textureBindGroupsCache

textureBindGroupsCache: WeakMap<GPUTexture, GPUBindGroup[]>

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


textureSampler

textureSampler: TextureSampler

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


texturesCache

texturesCache: Cache<WebGPUTexture>

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


current

static current: WebGPURenderContext

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

Accessors

renderPipelineDescriptorCacheValues

Get Signature

get renderPipelineDescriptorCacheValues(): GPURenderPipelineDescriptor[]

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

Returns

GPURenderPipelineDescriptor[]

Methods

addBufferToPending()

addBufferToPending(buffer): void

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

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:400

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:123

Returns

void


createSimpleBindGroup()

createSimpleBindGroup(layout, items, label): GPUBindGroup

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

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 | GPUBuffer | WebGPUBuffer | WebGPUTexture | GPUTextureView | GPUSampler | GPUBufferBinding)[]

label

string

Returns

GPUBindGroup


createSimpleBindGroupLayout()

createSimpleBindGroupLayout(types_key, label): GPUBindGroupLayout

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

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:367

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:108

Returns

void


destroyTexture()

destroyTexture(name): void

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

Destroy texture from GPU Memory

Parameters

name

string

Returns

void


drawGeometryFromRenderable()

drawGeometryFromRenderable(renderable, renderPass, lastGeometryIndex): number

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

does the draw call once all is set

Parameters

renderable

Renderable

renderPass

GPURenderPassEncoder

lastGeometryIndex

number = -1

Returns

number


generateMipmap()

generateMipmap(texture, encoder?): GPUTexture

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

Parameters

texture

GPUTexture

encoder?

GPUCommandEncoder

Returns

GPUTexture

Overrides

TextureManager.generateMipmap


getBufferBindGroup()

getBufferBindGroup(input, usage): GPUBindGroup

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

Asumes usage is for compute shader

Parameters

input

GPUBuffer

usage

number = eBindGroupUsage.fragment

Returns

GPUBindGroup


getPipeline()

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

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

Finds the right pipeline by generating a hash from the input

Parameters

material

Material

shader

WebGPUShader

primitive

WebGPUPrimitive

topology

eTopology

sampleCount

number

colorFormat

GPUTextureFormat

depthFormat?

GPUTextureFormat | "none"

colorFormat2?

GPUTextureFormat

Returns

GPURenderPipeline


getQuadBindGroup()

getQuadBindGroup(input): GPUBindGroup

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

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:142

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:464

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

Parameters

name

string

url?

string

Returns

WebGPUTexture

Overrides

TextureManager.getTexture


getTextureBindGroup()

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

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

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:156

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:436

Parameters

url

string

sRGB

boolean = true

Returns

WebGPUTexture


registerTexture()

registerTexture(name, texture): void

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

Register texture inside the texture cache to help others to use it

Parameters

name

string

texture

WebGPUTexture

Returns

void

Overrides

TextureManager.registerTexture


reset()

reset(): void

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

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:119

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:423

Called at the end of the framegraph

Returns

void