UNPKG

typegpu

Version:

A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.

59 lines (58 loc) 3.31 kB
import type { PrimitiveOffsetInfo } from '../../data/offsetUtils.ts'; import type { AnyWgslData } from '../../data/wgslTypes.ts'; import { $internal } from '../../shared/symbols.ts'; import type { TgpuBindGroup, TgpuBindGroupLayout, TgpuLayoutEntry } from '../../tgpuBindGroupLayout.ts'; import type { IndirectFlag, TgpuBuffer } from '../buffer/buffer.ts'; import { ComputeDrawState } from '../pipeline/drawState.ts'; import type { TgpuComputePipeline } from '../pipeline/computePipeline.ts'; import type { ExperimentalTgpuRoot } from '../root/rootTypes.ts'; import { type TgpuPassTimestampWrites } from './attachments.ts'; import type { TgpuCommandEncoder } from './commandEncoder.ts'; /** * The TypeGPU equivalent of {@link GPUComputePassDescriptor}. * Query sets accept TypeGPU query sets next to raw {@link GPUQuerySet}s. */ export interface TgpuComputePassDescriptor { label?: string | undefined; timestampWrites?: TgpuPassTimestampWrites | undefined; } export interface ComputePassInternals { readonly rawPass: GPUComputePassEncoder; readonly state: ComputeDrawState; /** Undefined for raw pass encoders the caller owns */ readonly owner: TgpuCommandEncoder | undefined; appliedVersion: number | undefined; } /** * A compute pass recording into a {@link TgpuCommandEncoder}. * * Dispatch either by binding TypeGPU pipelines to it * (`pipeline.with(pass).dispatchWorkgroups(...)`), or proxy-style via * `pass.setPipeline(pipeline)` followed by `pass.dispatchWorkgroups(...)`. * * Call `end()` when done recording. */ export interface TgpuComputePass { readonly [$internal]: ComputePassInternals; readonly resourceType: 'compute-pass'; /** Sets the current {@link TgpuComputePipeline} for subsequent dispatches */ setPipeline(pipeline: TgpuComputePipeline): void; /** Associates a bind group with the layout it was created from */ setBindGroup(bindGroup: TgpuBindGroup): void; /** Associates a bind group with the given layout */ setBindGroup<Entries extends Record<string, TgpuLayoutEntry | null>>(bindGroupLayout: TgpuBindGroupLayout<Entries>, bindGroup: TgpuBindGroup<Entries> | GPUBindGroup): void; dispatchWorkgroups(x: number, y?: number, z?: number): void; /** * Dispatches compute workgroups using parameters read from a buffer. * The buffer must contain 3 consecutive u32 values (x, y, z workgroup counts). * To get the correct offset within complex data structures, use `d.memoryLayoutOf(...)`. * * @param indirectBuffer - Buffer marked with 'indirect' usage containing dispatch parameters or raw GPUBuffer * @param start - PrimitiveOffsetInfo pointing to the first dispatch parameter. If not provided, starts at offset 0. To obtain safe offsets, use `d.memoryLayoutOf(...)`. */ dispatchWorkgroupsIndirect<T extends AnyWgslData>(indirectBuffer: (TgpuBuffer<T> & IndirectFlag) | GPUBuffer, start?: PrimitiveOffsetInfo | number): void; /** Completes the recording of this compute pass */ end(): void; } export declare function INTERNAL_beginComputePass(encoder: TgpuCommandEncoder, descriptor?: TgpuComputePassDescriptor): TgpuComputePass; export declare function INTERNAL_adoptComputePass(root: ExperimentalTgpuRoot, rawPass: GPUComputePassEncoder): TgpuComputePass;