UNPKG

typegpu

Version:

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

31 lines (30 loc) 1.4 kB
import type { BaseData } from './wgslTypes.ts'; import type { Infer } from '../shared/repr.ts'; export declare function createOffsetProxy<T extends BaseData>(schema: T, baseOffset?: number): unknown; /** * Interface containing information about the offset and the available contiguous after a selected primitive. */ export interface PrimitiveOffsetInfo { /** The byte offset of the primitive within the buffer. */ offset: number; /** The number of contiguous bytes available from the offset. */ contiguous: number; } /** * A function that retrieves offset and information for a specific primitive within a data schema. * Example usage: * ```ts * const Boid = d.struct({ * position: d.vec3f, * velocity: d.vec3f, * }); * const memLayout = d.memoryLayoutOf(Boid, (b) => b.velocity.y); * console.log(memLayout.offset); // Byte offset of velocity.y within Boid (here 20 bytes) * console.log(memLayout.contiguous); // Contiguous bytes available from that offset (here 8 bytes) * ``` * * @param schema - The data schema to analyze. * @param accessor - Optional function that accesses a specific element within the schema. If omitted, uses the root offset (0). * @returns An object containing the offset and contiguous byte information. */ export declare function memoryLayoutOf<T extends BaseData>(schema: T, accessor?: (proxy: Infer<T>) => unknown): PrimitiveOffsetInfo;