typegpu
Version:
A thin layer between JS and WebGPU/WGSL that improves development experience and allows for faster iteration.
112 lines (111 loc) • 4.89 kB
TypeScript
import { type TgpuQuerySet } from '../querySet/querySet.ts';
import type { v3u, Vec3u } from '../../data/wgslTypes.ts';
import { $getNameForward, $internal, $soul } from '../../shared/symbols.ts';
import type { TgpuBindGroup } from '../../tgpuBindGroupLayout.ts';
import type { LogGeneratorOptions } from '../../tgsl/consoleLog/types.ts';
import type { WgslGeneratorClass } from '../../tgsl/shaderGenerator.ts';
import { type TgpuUniform } from '../buffer/bufferBinding.ts';
import { type TgpuComputePipeline } from '../pipeline/computePipeline.ts';
import type { ExperimentalTgpuRoot, TgpuGuardedComputePipeline, TgpuGuardedComputePipelineSoul, TgpuRootSoul, TgpuRoot } from './rootTypes.ts';
import type { RestoreContext } from '../../serial/types.ts';
export declare class TgpuGuardedComputePipelineImpl<TArgs extends number[]> implements TgpuGuardedComputePipeline<TArgs> {
#private;
readonly resourceType = "guarded-compute-pipeline";
readonly [$soul]: TgpuGuardedComputePipelineSoul;
constructor(root: ExperimentalTgpuRoot, pipeline: TgpuComputePipeline, sizeUniform: TgpuUniform<Vec3u>, workgroupSize: v3u);
with(bindGroup: TgpuBindGroup): TgpuGuardedComputePipeline<TArgs>;
withPerformanceCallback(callback: (start: bigint, end: bigint) => void | Promise<void>): TgpuGuardedComputePipeline<TArgs>;
withTimestampWrites(options: {
querySet: TgpuQuerySet<'timestamp'> | GPUQuerySet;
beginningOfPassWriteIndex?: number;
endOfPassWriteIndex?: number;
}): TgpuGuardedComputePipeline<TArgs>;
dispatchThreads(...threads: TArgs): void;
initAsync(): Promise<void>;
initSync(): void;
get pipeline(): TgpuComputePipeline;
get sizeUniform(): TgpuUniform<Vec3u>;
[$internal]: boolean;
get [$getNameForward](): TgpuComputePipeline;
$name(label: string): this;
}
export declare function INTERNAL_restoreRoot(soul: TgpuRootSoul, ctx: RestoreContext): TgpuRoot;
export declare function INTERNAL_restoreGuardedComputePipeline(soul: TgpuGuardedComputePipelineSoul, ctx: RestoreContext): TgpuGuardedComputePipeline;
/**
* Options passed into {@link init}.
*/
export type InitOptions = {
adapter?: GPURequestAdapterOptions | undefined;
device?: (GPUDeviceDescriptor & {
optionalFeatures?: Iterable<GPUFeatureName>;
}) | undefined;
/** @default 'strict' */
unstable_names?: 'random' | 'strict' | undefined;
/**
* If set to true, rooted resolves will be stripped of all excessive spaces.
* Rooted resolves include pipelines and all their transitive dependencies,
* but not, for example, `tgpu.resolve([MyStruct])`,
* as there may be multiple roots with different settings in one program.
*
* @default false
*/
unstable_minify?: boolean;
/**
* A custom shader code generator, used when resolving TypeGPU functions.
* If not provided, the default WGSL generator will be used.
*/
unstable_shaderGeneratorClass?: WgslGeneratorClass | undefined;
unstable_logOptions?: LogGeneratorOptions;
};
/**
* Options passed into {@link initFromDevice}.
*/
export type InitFromDeviceOptions = {
device: GPUDevice;
/** @default 'strict' */
unstable_names?: 'random' | 'strict' | undefined;
/**
* If set to true, rooted resolves will be stripped of all excessive spaces.
* Rooted resolves include pipelines and all their transitive dependencies,
* but not, for example, `tgpu.resolve([MyStruct])`,
* as there may be multiple roots with different settings in one program.
*
* @default false
*/
unstable_minify?: boolean;
/**
* A custom shader code generator, used when resolving TypeGPU functions.
* If not provided, the default WGSL generator will be used.
*/
unstable_shaderGeneratorClass?: WgslGeneratorClass | undefined;
unstable_logOptions?: LogGeneratorOptions;
};
/**
* Requests a new GPU device and creates a root around it.
* If a specific device should be used instead, use @see initFromDevice.
*
* @example
* When given no options, the function will ask the browser for a suitable GPU device.
* ```ts
* const root = await tgpu.init();
* ```
*
* @example
* If there are specific options that should be used when requesting a device, you can pass those in.
* ```ts
* const adapterOptions: GPURequestAdapterOptions = ...;
* const deviceDescriptor: GPUDeviceDescriptor = ...;
* const root = await tgpu.init({ adapter: adapterOptions, device: deviceDescriptor });
* ```
*/
export declare function init(options?: InitOptions): Promise<TgpuRoot>;
/**
* Creates a root from the given device, instead of requesting it like @see init.
*
* @example
* ```ts
* const device: GPUDevice = ...;
* const root = tgpu.initFromDevice({ device });
* ```
*/
export declare function initFromDevice(options: InitFromDeviceOptions): TgpuRoot;