/** * @fileoverview GaussianWebGPUTrainer — GPU dispatch layer for the sovereign 3DGS training loop. * * Dispatches `splat-train-forward.wgsl` (alpha-blend forward rasterizer) and * `splat-train-backward.wgsl` (gradient accumulation via fixed-point atomic) to absorb the * O(N×pixels) hot path on the GPU. CPU handles: 3D→2D projection (`forward3D`), chain-rule * gradient backprop to 3D params (`backward3D`), and Adam optimizer. * * This closes the executor gap flagged by the 2026-06-20 /critic review: the WGSL kernels were * GPU-validated on an RTX 3060 (forward: max-abs 1.33e-5 vs CPU ref; backward: worst rel 2.1e-3) * but were not yet dispatched from a TypeScript caller. This module is that caller. * * Usage: * const trainer = new GaussianWebGPUTrainer(device); * await trainer.init(); * const result = await runGaussianTrainJobGPU(trainer, job, initial, views); * trainer.destroy(); * * Lifecycle: `init()` once, then `runGaussianTrainJobGPU()` any number of times * (buffers are lazily reallocated when N or (W,H) changes). Call `destroy()` when done. * * Honest scope (same as GaussianTrainRunner — inherited constraints): * - Fixed-cardinality by default (densification optional, same config surface). * - Flat diffuse RGB; no spherical harmonics. * - Per-pixel hit cap (MAX_HITS=256 in backward shader) — deep per-pixel overlap at large scale * needs the tiled-reduction follow-up. * - GPU readback is synchronous per-view (renderFrame → computeGradients → next view). * Pipelining across views is a follow-up optimisation. */ import { type Gaussian3D } from './GaussianTrainer3D'; import { type Gaussian2D, type Gaussian2DGrad } from './GaussianTrainer2D'; import type { GaussianTrainJobSpec, TrainView, TrainResult } from './GaussianTrainRunner'; /** * Pack Gaussian2D SoA → AoS Float32Array for GPU splat buffer upload. * The field order matches `struct Gauss { posx, posy, a, b, c, r, g, bl, op }` in the WGSL. * Note: `Gaussian2D.gr` (green) maps to the shader's `g` slot. */ export declare function packGauss2D(g2: Gaussian2D): Float32Array; /** * Convert fixed-point i32 gradient buffer → Gaussian2DGrad SoA. * Slot ordering matches the backward shader: posx(0), posy(1), a(2), b(3), c(4), r(5), g(6), bl(7), op(8). */ export declare function unpackGrad(raw: Int32Array, N: number): Gaussian2DGrad; /** * GPU dispatch layer for 3DGS training. Owns WebGPU pipelines and buffer sets. * Call `init()` before any dispatch, `destroy()` when done. */ export declare class GaussianWebGPUTrainer { private readonly dev; private fwdPipeline; private bwdPipeline; private allocN; private allocW; private allocH; private uniformBuf; private splatBuf; private imgBuf; private dLBuf; private gradBuf; private readbackImg; private readbackGrad; constructor(device: GPUDevice); /** Compile shader modules and create compute pipelines. Must be called once before dispatch. */ init(): Promise; private ensureBuffers; private writeUniforms; /** * Upload packed 2D gaussians → dispatch forward shader → read back composited image. * Returns Float32Array of length W*H*3 (row-major RGB, values in [0,1]). */ renderFrame(packed: Float32Array, N: number, W: number, H: number, bg?: readonly [number, number, number]): Promise; /** * Upload packed splats + dL/dimg → dispatch backward shader → read back gradient buffer. * Returns Gaussian2DGrad SoA (f64 arrays, converted from fixed-point i32). */ computeGradients(packed: Float32Array, N: number, W: number, H: number, dLimg: Float32Array, bg?: readonly [number, number, number]): Promise; private destroyBuffers; /** Release all GPU resources. Call when training is complete. */ destroy(): void; } /** * GPU-accelerated 3DGS training loop. Mirrors `runGaussianTrainJob` from GaussianTrainRunner.ts * but dispatches the O(N×pixels) forward+backward rasterization to the GPU. * * The training structure is identical (Adam + optional densification); only the rasterize and * gradient-accumulate steps move to the GPU — projection and optimizer remain on CPU. * * @param trainer An initialised GaussianWebGPUTrainer (call trainer.init() before this). * @param bg Background color for rendering (default black). * @param onProgress Called every iteration with (iterIndex, loss); omit to suppress. */ export declare function runGaussianTrainJobGPU(trainer: GaussianWebGPUTrainer, job: GaussianTrainJobSpec, initial: Gaussian3D, views: TrainView[], bg?: readonly [number, number, number], onProgress?: (iter: number, loss: number) => void): Promise; //# sourceMappingURL=GaussianWebGPUTrainer.d.ts.map