/** * Pure static class implementing processing of WGSL shaders. It allocates fixed locations for * attributes, and handles conversion of uniforms to uniform buffers. */ export class WebgpuShaderProcessorWGSL { /** * Process the shader. * * @param {GraphicsDevice} device - The graphics device. * @param {object} shaderDefinition - The shader definition. * @param {Shader} shader - The shader. * @returns {object} - The processed shader data. */ static run(device: GraphicsDevice, shaderDefinition: object, shader: Shader): object; /** * Process a compute shader: reflect its simplified-syntax declarations (loose `uniform`s, * textures/samplers, storage buffers, storage textures) into a single bind group at * `reflectedGroupIndex`, leaving * any explicitly-bound (`@group/@binding`) declarations untouched. The loose uniforms are * collapsed into one generated uniform buffer (`ub_compute`) placed inside that same group. * * @param {GraphicsDevice} device - The graphics device. * @param {string} source - The fully-preprocessed compute shader source (includes/defines resolved). * @param {object} shaderDefinition - The shader definition. * @param {Shader} shader - The shader. * @param {number} reflectedGroupIndex - The bind group index the reflected resources are placed * in (0 when no caller format is supplied, otherwise 1). * @returns {object} - `{ cshader, computeBindGroupFormat, computeUniformBufferFormat }`. The * formats are null when there is nothing to reflect (strictly additive - behavior is then * identical to a fully hand-authored compute shader). */ static runCompute(device: GraphicsDevice, source: string, shaderDefinition: object, shader: Shader, reflectedGroupIndex: number): object; static extract(src: any): { src: any; attributes: string[]; varyings: string[]; uniforms: string[]; resources: string[]; }; /** * Process the lines with uniforms. The function receives the lines containing all numerical * uniforms. The function also receives the format of uniform buffers for view and material * level. All uniforms that match any of those are ignored, as those would be supplied by view / * material level buffers. All leftover uniforms create uniform buffer and bind group for the * mesh itself, containing uniforms that change on the level of the mesh. * * @param {GraphicsDevice} device - The graphics device. * @param {Array} uniforms - Lines containing uniforms. * @param {ShaderProcessorOptions} processingOptions - Uniform formats. * @param {Shader} shader - The shader definition. * @returns {object} - The uniform data. Returns a shader code block containing uniforms, to be * inserted into the shader, as well as generated uniform format structures for the mesh level. */ static processUniforms(device: GraphicsDevice, uniforms: Array, processingOptions: ShaderProcessorOptions, shader: Shader): object; /** * Source code references uniforms as `uniform.name`, but swap those to reference the actual uniform buffer * the uniform was assigned to, for example `ub_view.name`. * * @param {string} source - The source code. * @param {Array} uniforms - Lines containing uniforms. * @returns {string} - The source code with updated uniform references. */ static renameUniformAccess(source: string, uniforms: Array): string; static mergeResources(vertex: any, fragment: any, shader: any): any; /** * Converts parsed resource lines (textures, samplers, storage buffers, storage textures) into an * array of bind formats. Shared by the vertex/fragment path ({@link processResources}) and the * compute path ({@link runCompute}); only the shader-stage visibility differs. * * @param {Array} resources - The parsed resource lines. * @param {number} visibility - Shader stage visibility bit-flags for the created formats. * @param {Shader} shader - The shader (for error reporting). * @returns {Array} - The bind * formats, in declaration order (a texture with a sampler consumes the following sampler line). * @private */ private static buildResourceFormats; static processResources(device: any, resources: any, processingOptions: any, shader: any, visibility?: number, bindGroupIndex?: number): { code: string; meshBindGroupFormat: BindGroupFormat; }; /** * Generates a shader code for a uniform buffer, something like: * ``` * struct ub_view { matrix_viewProjection : mat4x4f } * @group(0) @binding(0) var ubView : ub_view; * ``` * * @param {UniformBufferFormat} ubFormat - Format of the uniform buffer. * @param {number} bindGroup - The bind group index. * @param {number} bindIndex - The bind index. * @param {string} [name] - The name used for the struct and uniform buffer variable * (`struct_ub_` / `ub_`). Defaults to the bind group name. The compute path passes * an explicit name as its reflected group index does not map to a meaningful bindGroupNames entry. * @returns {string} - The shader code for the uniform buffer. * @private */ private static getUniformShaderDeclaration; /** * Generates a shader code for a bind group, something like: * ``` * @group(0) @binding(0) var diffuseTexture: texture_2d; * @group(0) @binding(1) var diffuseTexture_sampler: sampler; // optional * ``` * @param {BindGroupFormat} format - The format of the bind group. * @param {number} bindGroup - The bind group index. * @returns {string} - The shader code for the bind group. */ static getTextureShaderDeclaration(format: BindGroupFormat, bindGroup: number): string; static processVaryings(varyingLines: any, varyingMap: any, isVertex: any, device: any, source?: string, entryInputName?: string): string; static generateFragmentOutputStruct(src: any, numRenderTargets: any): string; static floatAttributeToInt(type: any, signed: any): any; static processAttributes(attributeLines: any, shaderDefinitionAttributes: {}, attributesMap: any, processingOptions: any, shader: any, device: any, source?: string, entryInputName?: string): string; /** * Injects a call to _pcCopyInputs with the function's input parameter right after the opening * brace of a WGSL function marked with `@vertex` or `@fragment`. The regex is run inside this * function (not hoisted) so the brace position is always derived from the current `src` - any * earlier source-modifying step (e.g. `renameUniformAccess`) would invalidate a cached position. * * @param {string} src - The source string containing the WGSL code. * @param {Shader} shader - The shader. * @returns {string} - The modified source string. */ static copyInputs(src: string, shader: Shader): string; static cutOut(src: any, start: any, end: any, replacement: any): any; } import type { GraphicsDevice } from '../graphics-device.js'; import type { Shader } from '../shader.js'; declare class UniformLine { constructor(line: any, shader: any); /** * A name of the ub buffer which this uniform is assigned to. * * @type {string|null} */ ubName: string | null; arraySize: number; line: any; name: any; type: any; } import type { ShaderProcessorOptions } from '../shader-processor-options.js'; import { BindGroupFormat } from '../bind-group-format.js'; export {};