TgpuRoot
Extends
Section titled “Extends”Unwrapper.WithBinding
Properties
Section titled “Properties”[$internal]
Section titled “[$internal]”[$internal]:
object
logOptions
Section titled “logOptions”logOptions:
LogGeneratorOptions
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:719
~unstable
Section titled “~unstable”~unstable:
Pick<ExperimentalTgpuRoot,"with"|"withCompute"|"createGuardedComputePipeline"|"withVertex"|"pipe"|"beginRenderPass"|"createComparisonSampler"|"createSampler"|"createTexture"|"flush"|"nameRegistrySetting"|"shaderGenerator">
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:905
device
Section titled “device”
readonlydevice:GPUDevice
The GPU device associated with this root.
Overrides
Section titled “Overrides”Unwrapper.device
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:726
Accessors
Section titled “Accessors”enabledFeatures
Section titled “enabledFeatures”Get Signature
Section titled “Get Signature”get enabledFeatures():
ReadonlySet<GPUFeatureName>
Retrieves a read-only list of all enabled features of the GPU device.
Returns
Section titled “Returns”ReadonlySet<GPUFeatureName>
A set of strings representing the enabled features.
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:896
Methods
Section titled “Methods”configureContext()
Section titled “configureContext()”configureContext(
options):GPUCanvasContext
Creates and configures context for the provided canvas.
Automatically sets the format to navigator.gpu.getPreferredCanvasFormat() if not provided.
Parameters
Section titled “Parameters”options
Section titled “options”ConfigureContextOptions
Returns
Section titled “Returns”GPUCanvasContext
Throws
Section titled “Throws”An error if no context could be obtained
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:733
createBindGroup()
Section titled “createBindGroup()”createBindGroup<
Entries>(layout,entries):TgpuBindGroup<Entries>
Creates a group of resources that can be bound to a shader based on a specified layout.
Type Parameters
Section titled “Type Parameters”• Entries extends Record<string, null | TgpuLayoutEntry> = Record<string, null | TgpuLayoutEntry>
Parameters
Section titled “Parameters”layout
Section titled “layout”TgpuBindGroupLayout<Entries>
Layout describing the bind group to be created.
entries
Section titled “entries”ExtractBindGroupInputFromLayout<Entries>
A record with values being the resources populating the bind group and keys being their associated names, matching the layout keys.
Returns
Section titled “Returns”TgpuBindGroup<Entries>
Remarks
Section titled “Remarks”Typed wrapper around a GPUBindGroup.
Example
Section titled “Example”const fooLayout = tgpu.bindGroupLayout({ foo: { uniform: d.vec3f }, bar: { texture: 'float' },});
const fooBuffer = ...;const barTexture = ...;
const fooBindGroup = root.createBindGroup(fooLayout, { foo: fooBuffer, bar: barTexture,});Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:885
createBuffer()
Section titled “createBuffer()”Call Signature
Section titled “Call Signature”createBuffer<
TData>(typeSchema,initial?):TgpuBuffer<TData>
Allocates memory on the GPU, allows passing data between host and shader.
Type Parameters
Section titled “Type Parameters”• TData extends AnyData
Parameters
Section titled “Parameters”typeSchema
Section titled “typeSchema”ValidateBufferSchema<TData>
The type of data that this buffer will hold.
initial?
Section titled “initial?”Infer<NoInfer<TData>>
The initial value of the buffer. (optional)
Returns
Section titled “Returns”TgpuBuffer<TData>
Remarks
Section titled “Remarks”Typed wrapper around a GPUBuffer.
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:744
Call Signature
Section titled “Call Signature”createBuffer<
TData>(typeSchema,gpuBuffer):TgpuBuffer<TData>
Allocates memory on the GPU, allows passing data between host and shader.
Type Parameters
Section titled “Type Parameters”• TData extends AnyData
Parameters
Section titled “Parameters”typeSchema
Section titled “typeSchema”ValidateBufferSchema<TData>
The type of data that this buffer will hold.
gpuBuffer
Section titled “gpuBuffer”GPUBuffer
A vanilla WebGPU buffer.
Returns
Section titled “Returns”TgpuBuffer<TData>
Remarks
Section titled “Remarks”Typed wrapper around a GPUBuffer.
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:759
createComputePipeline()
Section titled “createComputePipeline()”createComputePipeline<
ComputeIn>(descriptor):TgpuComputePipeline
Type Parameters
Section titled “Type Parameters”• ComputeIn extends IORecord<AnyComputeBuiltin>
Parameters
Section titled “Parameters”descriptor
Section titled “descriptor”Descriptor<ComputeIn>
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”WithBinding.createComputePipeline
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:253
createGuardedComputePipeline()
Section titled “createGuardedComputePipeline()”createGuardedComputePipeline<
TArgs>(callback):TgpuGuardedComputePipeline<TArgs>
Creates a compute pipeline that executes the given callback in an exact number of threads.
This is different from withCompute(...).createPipeline() in that it does a bounds check on the
thread id, where as regular pipelines do not and work in units of workgroups.
Type Parameters
Section titled “Type Parameters”• TArgs extends number[]
Parameters
Section titled “Parameters”callback
Section titled “callback”(…args) => void
A function converted to WGSL and executed on the GPU. It can accept up to 3 parameters (x, y, z) which correspond to the global invocation ID of the executing thread.
Returns
Section titled “Returns”TgpuGuardedComputePipeline<TArgs>
Examples
Section titled “Examples”If no parameters are provided, the callback will be executed once, in a single thread.
const fooPipeline = root .createGuardedComputePipeline(() => { 'use gpu'; console.log('Hello, GPU!'); });
fooPipeline.dispatchThreads();// [GPU] Hello, GPU!One parameter means n-threads will be executed in parallel.
const fooPipeline = root .createGuardedComputePipeline((x) => { 'use gpu'; if (x % 16 === 0) { // Logging every 16th thread console.log('I am the', x, 'thread'); } });
// executing 512 threadsfooPipeline.dispatchThreads(512);// [GPU] I am the 256 thread// [GPU] I am the 272 thread// ... (30 hidden logs)// [GPU] I am the 16 thread// [GPU] I am the 240 threadInherited from
Section titled “Inherited from”WithBinding.createGuardedComputePipeline
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:417
createMutable()
Section titled “createMutable()”Call Signature
Section titled “Call Signature”createMutable<
TData>(typeSchema,initial?):TgpuMutable<TData>
Allocates memory on the GPU, allows passing data between host and shader. Can be mutated in-place on the GPU. For a general-purpose buffer, use TgpuRoot.createBuffer.
Type Parameters
Section titled “Type Parameters”• TData extends AnyWgslData
Parameters
Section titled “Parameters”typeSchema
Section titled “typeSchema”ValidateStorageSchema<TData>
The type of data that this buffer will hold.
initial?
Section titled “initial?”Infer<NoInfer<TData>>
The initial value of the buffer. (optional)
Returns
Section titled “Returns”TgpuMutable<TData>
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:799
Call Signature
Section titled “Call Signature”createMutable<
TData>(typeSchema,gpuBuffer):TgpuMutable<TData>
Allocates memory on the GPU, allows passing data between host and shader. Can be mutated in-place on the GPU. For a general-purpose buffer, use TgpuRoot.createBuffer.
Type Parameters
Section titled “Type Parameters”• TData extends AnyWgslData
Parameters
Section titled “Parameters”typeSchema
Section titled “typeSchema”ValidateStorageSchema<TData>
The type of data that this buffer will hold.
gpuBuffer
Section titled “gpuBuffer”GPUBuffer
A vanilla WebGPU buffer.
Returns
Section titled “Returns”TgpuMutable<TData>
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:813
createQuerySet()
Section titled “createQuerySet()”createQuerySet<
T>(type,count,rawQuerySet?):TgpuQuerySet<T>
Creates a query set for collecting timestamps or occlusion queries.
Type Parameters
Section titled “Type Parameters”• T extends GPUQueryType
Parameters
Section titled “Parameters”T
The type of queries to collect (‘occlusion’ or ‘timestamp’).
number
The number of queries in the set.
rawQuerySet?
Section titled “rawQuerySet?”GPUQuerySet
An optional pre-existing GPUQuerySet to use instead of creating a new one.
Returns
Section titled “Returns”TgpuQuerySet<T>
Remarks
Section titled “Remarks”Typed wrapper around a GPUQuerySet.
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:855
createReadonly()
Section titled “createReadonly()”Call Signature
Section titled “Call Signature”createReadonly<
TData>(typeSchema,initial?):TgpuReadonly<TData>
Allocates memory on the GPU, allows passing data between host and shader. Read-only on the GPU, optimized for large data. For a general-purpose buffer, use TgpuRoot.createBuffer.
Type Parameters
Section titled “Type Parameters”• TData extends AnyWgslData
Parameters
Section titled “Parameters”typeSchema
Section titled “typeSchema”ValidateStorageSchema<TData>
The type of data that this buffer will hold.
initial?
Section titled “initial?”Infer<NoInfer<TData>>
The initial value of the buffer. (optional)
Returns
Section titled “Returns”TgpuReadonly<TData>
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:826
Call Signature
Section titled “Call Signature”createReadonly<
TData>(typeSchema,gpuBuffer):TgpuReadonly<TData>
Allocates memory on the GPU, allows passing data between host and shader. Read-only on the GPU, optimized for large data. For a general-purpose buffer, use TgpuRoot.createBuffer.
Type Parameters
Section titled “Type Parameters”• TData extends AnyWgslData
Parameters
Section titled “Parameters”typeSchema
Section titled “typeSchema”ValidateStorageSchema<TData>
The type of data that this buffer will hold.
gpuBuffer
Section titled “gpuBuffer”GPUBuffer
A vanilla WebGPU buffer.
Returns
Section titled “Returns”TgpuReadonly<TData>
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:840
createRenderPipeline()
Section titled “createRenderPipeline()”Call Signature
Section titled “Call Signature”createRenderPipeline<
TVertexIn,TAttribs,TVertexOut,TFragmentOut>(descriptor):TgpuRenderPipeline<NormalizeOutput<TFragmentOut>>
Type Parameters
Section titled “Type Parameters”• TVertexIn extends In = Record<string, any>
• TAttribs extends object = LayoutToAllowedAttribs<TVertexIn>
• TVertexOut = unknown
• TFragmentOut = unknown
Parameters
Section titled “Parameters”descriptor
Section titled “descriptor”DescriptorBase & object
Returns
Section titled “Returns”TgpuRenderPipeline<NormalizeOutput<TFragmentOut>>
Inherited from
Section titled “Inherited from”WithBinding.createRenderPipeline
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:257
Call Signature
Section titled “Call Signature”createRenderPipeline<
TVertexIn,TAttribs,TVertexOut>(descriptor):TgpuRenderPipeline<Void>
Type Parameters
Section titled “Type Parameters”• TVertexIn extends In = Record<string, any>
• TAttribs extends object = LayoutToAllowedAttribs<TVertexIn>
• TVertexOut extends Out = Out
Parameters
Section titled “Parameters”descriptor
Section titled “descriptor”DescriptorBase & object
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”WithBinding.createRenderPipeline
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:286
Call Signature
Section titled “Call Signature”createRenderPipeline<
TVertexIn,TAttribs,TVertexOut,TFragmentOut>(descriptor):TgpuRenderPipeline<Void> |TgpuRenderPipeline<NormalizeOutput<TFragmentOut>>
Type Parameters
Section titled “Type Parameters”• TVertexIn extends In = Record<string, any>
• TAttribs extends object = LayoutToAllowedAttribs<TVertexIn>
• TVertexOut extends Out = Out
• TFragmentOut = unknown
Parameters
Section titled “Parameters”descriptor
Section titled “descriptor”DescriptorBase & {attribs: TAttribs;fragment: TgpuFragmentFn<VertexOutToVarying<OmitBuiltins<TVertexOut>> & Record<string, AnyFragmentInputBuiltin>, Assume<TFragmentOut, Out>> | (input) => AutoFragmentOut<Assume<TFragmentOut, v4f | AnyAutoCustoms>>;targets: FragmentOutToTargets<NoInfer<TFragmentOut>>;vertex: TgpuVertexFn<TVertexIn, Assume<TVertexOut, Out>> | (input) => AutoVertexOut<Assume<TVertexOut, AnyAutoCustoms>>; } | {attribs: TAttribs;fragment: TgpuFragmentFn<VertexOutToVarying<OmitBuiltins<TVertexOut>> & Record<string, AnyFragmentInputBuiltin>, Record<string, never>> | (input) => undefined;targets: undefined;vertex: TgpuVertexFn<TVertexIn, Assume<TVertexOut, Out>> | (input) => AutoVertexOut<Assume<TVertexOut, AnyAutoCustoms>>; }
Returns
Section titled “Returns”TgpuRenderPipeline<Void> | TgpuRenderPipeline<NormalizeOutput<TFragmentOut>>
Inherited from
Section titled “Inherited from”WithBinding.createRenderPipeline
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:315
createUniform()
Section titled “createUniform()”Call Signature
Section titled “Call Signature”createUniform<
TData>(typeSchema,initial?):TgpuUniform<TData>
Allocates memory on the GPU, allows passing data between host and shader. Read-only on the GPU, optimized for small data. For a general-purpose buffer, use TgpuRoot.createBuffer.
Type Parameters
Section titled “Type Parameters”• TData extends AnyWgslData
Parameters
Section titled “Parameters”typeSchema
Section titled “typeSchema”ValidateUniformSchema<TData>
The type of data that this buffer will hold.
initial?
Section titled “initial?”Infer<NoInfer<TData>>
The initial value of the buffer. (optional)
Returns
Section titled “Returns”TgpuUniform<TData>
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:772
Call Signature
Section titled “Call Signature”createUniform<
TData>(typeSchema,gpuBuffer):TgpuUniform<TData>
Allocates memory on the GPU, allows passing data between host and shader. Read-only on the GPU, optimized for small data. For a general-purpose buffer, use TgpuRoot.createBuffer.
Type Parameters
Section titled “Type Parameters”• TData extends AnyWgslData
Parameters
Section titled “Parameters”typeSchema
Section titled “typeSchema”ValidateUniformSchema<TData>
The type of data that this buffer will hold.
gpuBuffer
Section titled “gpuBuffer”GPUBuffer
A vanilla WebGPU buffer.
Returns
Section titled “Returns”TgpuUniform<TData>
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:786
destroy()
Section titled “destroy()”destroy():
void
Destroys all underlying resources (i.e. buffers…) created through this root object.
If the object is created via tgpu.init instead of tgpu.initFromDevice,
then the inner GPU device is destroyed as well.
Returns
Section titled “Returns”void
Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:903
pipe()
Section titled “pipe()”pipe(
transform):WithBinding
Parameters
Section titled “Parameters”transform
Section titled “transform”(cfg) => Configurable
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:429
unwrap()
Section titled “unwrap()”Call Signature
Section titled “Call Signature”unwrap(
resource):GPUComputePipeline
Parameters
Section titled “Parameters”resource
Section titled “resource”Returns
Section titled “Returns”GPUComputePipeline
Inherited from
Section titled “Inherited from”Unwrapper.unwrap
Defined in
Section titled “Defined in”packages/typegpu/src/unwrapper.ts:13
Call Signature
Section titled “Call Signature”unwrap(
resource):GPURenderPipeline
Parameters
Section titled “Parameters”resource
Section titled “resource”Returns
Section titled “Returns”GPURenderPipeline
Inherited from
Section titled “Inherited from”Unwrapper.unwrap
Defined in
Section titled “Defined in”packages/typegpu/src/unwrapper.ts:14
Call Signature
Section titled “Call Signature”unwrap(
resource):GPUBindGroupLayout
Parameters
Section titled “Parameters”resource
Section titled “resource”Returns
Section titled “Returns”GPUBindGroupLayout
Inherited from
Section titled “Inherited from”Unwrapper.unwrap
Defined in
Section titled “Defined in”packages/typegpu/src/unwrapper.ts:15
Call Signature
Section titled “Call Signature”unwrap(
resource):GPUBindGroup
Parameters
Section titled “Parameters”resource
Section titled “resource”Returns
Section titled “Returns”GPUBindGroup
Inherited from
Section titled “Inherited from”Unwrapper.unwrap
Defined in
Section titled “Defined in”packages/typegpu/src/unwrapper.ts:16
Call Signature
Section titled “Call Signature”unwrap(
resource):GPUBuffer
Parameters
Section titled “Parameters”resource
Section titled “resource”Returns
Section titled “Returns”GPUBuffer
Inherited from
Section titled “Inherited from”Unwrapper.unwrap
Defined in
Section titled “Defined in”packages/typegpu/src/unwrapper.ts:17
Call Signature
Section titled “Call Signature”unwrap(
resource):GPUTextureView
Parameters
Section titled “Parameters”resource
Section titled “resource”Returns
Section titled “Returns”GPUTextureView
Inherited from
Section titled “Inherited from”Unwrapper.unwrap
Defined in
Section titled “Defined in”packages/typegpu/src/unwrapper.ts:18
Call Signature
Section titled “Call Signature”unwrap(
resource):GPUVertexBufferLayout
Parameters
Section titled “Parameters”resource
Section titled “resource”Returns
Section titled “Returns”GPUVertexBufferLayout
Inherited from
Section titled “Inherited from”Unwrapper.unwrap
Defined in
Section titled “Defined in”packages/typegpu/src/unwrapper.ts:19
Call Signature
Section titled “Call Signature”unwrap(
resource):GPUSampler
Parameters
Section titled “Parameters”resource
Section titled “resource”Returns
Section titled “Returns”GPUSampler
Inherited from
Section titled “Inherited from”Unwrapper.unwrap
Defined in
Section titled “Defined in”packages/typegpu/src/unwrapper.ts:20
Call Signature
Section titled “Call Signature”unwrap(
resource):GPUSampler
Parameters
Section titled “Parameters”resource
Section titled “resource”Returns
Section titled “Returns”GPUSampler
Inherited from
Section titled “Inherited from”Unwrapper.unwrap
Defined in
Section titled “Defined in”packages/typegpu/src/unwrapper.ts:21
Call Signature
Section titled “Call Signature”unwrap(
resource):GPUQuerySet
Parameters
Section titled “Parameters”resource
Section titled “resource”TgpuQuerySet<GPUQueryType>
Returns
Section titled “Returns”GPUQuerySet
Inherited from
Section titled “Inherited from”Unwrapper.unwrap
Defined in
Section titled “Defined in”packages/typegpu/src/unwrapper.ts:22
Call Signature
Section titled “Call Signature”unwrap(
resource):GPUTexture
Parameters
Section titled “Parameters”resource
Section titled “resource”Returns
Section titled “Returns”GPUTexture
Inherited from
Section titled “Inherited from”Unwrapper.unwrap
Defined in
Section titled “Defined in”packages/typegpu/src/unwrapper.ts:23
with()
Section titled “with()”Call Signature
Section titled “Call Signature”with<
T>(slot,value):WithBinding
Type Parameters
Section titled “Type Parameters”• T
Parameters
Section titled “Parameters”TgpuSlot<T>
Eventual<T>
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:197
Call Signature
Section titled “Call Signature”with<
T>(accessor,value):WithBinding
Type Parameters
Section titled “Type Parameters”• T extends BaseData
Parameters
Section titled “Parameters”accessor
Section titled “accessor”TgpuAccessor<T>
In<NoInfer<T>>
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:198
Call Signature
Section titled “Call Signature”with<
T>(accessor,value):WithBinding
Type Parameters
Section titled “Type Parameters”• T extends BaseData
Parameters
Section titled “Parameters”accessor
Section titled “accessor”In<NoInfer<T>>
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:199
withCompute()
Section titled “withCompute()”withCompute<
ComputeIn>(entryFn):WithCompute
Type Parameters
Section titled “Type Parameters”• ComputeIn extends IORecord<AnyComputeBuiltin>
Parameters
Section titled “Parameters”entryFn
Section titled “entryFn”TgpuComputeFn<ComputeIn>
Returns
Section titled “Returns”Inherited from
Section titled “Inherited from”Defined in
Section titled “Defined in”packages/typegpu/src/core/root/rootTypes.ts:249
withVertex()
Section titled “withVertex()”withVertex<
VertexIn,VertexOut>(entryFn, …args):WithVertex<VertexOut>
Type Parameters
Section titled “Type Parameters”• VertexIn extends In
• VertexOut extends Out
Parameters
Section titled “Parameters”entryFn
Section titled “entryFn”TgpuVertexFn<VertexIn, VertexOut>
…OptionalArgs<LayoutToAllowedAttribs<OmitBuiltins<VertexIn>>>
Returns
Section titled “Returns”WithVertex<VertexOut>