Skip to content

WithBinding

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.

TArgs extends number[]

(…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.

TgpuGuardedComputePipeline<TArgs>

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 threads
fooPipeline.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 thread

packages/typegpu/src/core/root/rootTypes.ts:267


pipe(transform): WithBinding

(cfg) => Configurable

WithBinding

packages/typegpu/src/core/root/rootTypes.ts:293


with<T>(slot, value): WithBinding

T

TgpuSlot<T>

Eventual<T>

WithBinding

packages/typegpu/src/core/root/rootTypes.ts:279

with<T>(accessor, value): WithBinding

T extends WgslTexture<WgslTextureProps> | WgslStorageTexture<WgslStorageTextureProps>

TgpuAccessor<T>

TgpuTextureView<T> | Infer<T>

WithBinding

packages/typegpu/src/core/root/rootTypes.ts:280

with<T>(accessor, value): WithBinding

T extends AnyWgslData

TgpuAccessor<T>

TgpuFn<() => T> | TgpuBufferUsage<T, BindableBufferUsage> | TgpuBufferShorthand<T> | Infer<T>

WithBinding

packages/typegpu/src/core/root/rootTypes.ts:284


withCompute<ComputeIn>(entryFn): WithCompute

ComputeIn extends IORecord<AnyComputeBuiltin>

TgpuComputeFn<ComputeIn>

WithCompute

packages/typegpu/src/core/root/rootTypes.ts:218


withVertex<VertexIn, VertexOut>(entryFn, attribs): WithVertex<VertexOut>

VertexIn extends VertexInConstrained

VertexOut extends VertexOutConstrained

TgpuVertexFn<VertexIn, VertexOut>

LayoutToAllowedAttribs<OmitBuiltins<VertexIn>>

WithVertex<VertexOut>

packages/typegpu/src/core/root/rootTypes.ts:271