import type { BundleCommand, Command, ComputeCommand, ComputePassDescriptor, ComputePipeline, RenderCommand, RenderPassDescriptor, RenderPipeline, } from "./types.js"; /** * Type a plain command object. An identity function — no GPU work, no copy — * existing purely so plain JS gets autocomplete and type checking on the * command shape (TypeScript users can use `satisfies RenderCommand` instead). * * The returned object is the same reference: mutating uniforms or pipeline * state between submits keeps working, with the usual caveat that shader * sources on the pipeline are treated as immutable. * * ```js * const drawCmd = gpu.defineCommand({ * pass: { clearValue: [0.2, 0.2, 0.2, 1], depthClearValue: 1 }, * pipeline: { * shader, * depthWriteEnabled: true, * }, * attributes: { position: positions }, * indices, * uniforms: { projection, view, model }, * }); * ``` */ export function defineCommand(cmd: RenderCommand): RenderCommand; export function defineCommand(cmd: ComputeCommand): ComputeCommand; export function defineCommand(cmd: BundleCommand): BundleCommand; export function defineCommand(cmd: Command): Command { return cmd; } /** * Type a standalone pass descriptor — render or compute pass options — * (identity function, see {@link defineCommand}). Note that sharing a pass * object between commands does not merge their render passes: each submit with * a `pass` opens its own (re-clearing if a clear value is set) — to draw * several commands into one pass, use the pass scope form `gpu.submit(ctx, { * pass }, () => ...)`. */ export function definePass(pass: RenderPassDescriptor): RenderPassDescriptor; export function definePass(pass: ComputePassDescriptor): ComputePassDescriptor; export function definePass( pass: RenderPassDescriptor | ComputePassDescriptor, ): RenderPassDescriptor | ComputePassDescriptor { return pass; } /** * Type a standalone pipeline description (identity function, see * {@link defineCommand}). Sharing one pipeline object between commands is * encouraged: reflection, bind group layouts and GPU pipeline variants are * cached per pipeline object, so shared objects mean one cache entry — commands * drawn with the same targets and vertex layout reuse a single * GPURenderPipeline. Shader sources on the object are treated as immutable. */ export function definePipeline(pipeline: RenderPipeline): RenderPipeline; export function definePipeline(pipeline: ComputePipeline): ComputePipeline; export function definePipeline( pipeline: RenderPipeline | ComputePipeline, ): RenderPipeline | ComputePipeline { return pipeline; }