GlslEmitOptions
On this page

GlslEmitOptions

Interface in Emit

The options accepted by emitGlslModule, emitGlslStages and emitGlslFragment: the shared EmitOptions plus three that exist only for GLSL ES 3.00.

import type { GlslEmitOptions } from 'typeshade'

The signature, the description and the examples come from the compiler's own source at commit af54ddad5.

Syntax

interface GlslEmitOptions extends EmitOptions {
emulateCompute?: boolean;
overrideValues?: Readonly<Record<string, number | boolean>>;
floatPrecision?: 'highp' | 'mediump';
}

Description

WebGL2 has no compute stage (emulateCompute) or pipeline-time specialization constants (overrideValues). Fragment shaders have no default float precision (floatPrecision). All three are decided when the source is emitted, never probed from the device, so emitted source can be cached under a key derived from the options. Omitting them all leaves the emitted bytes unchanged.

Instance properties

emulateComputeoptionaldeprecated boolean

Lower a gather-only @compute kernel to a fragment pass, as lowerComputeToFragment describes. The host then runs the kernel as a fullscreen draw into an R32UI target instead of a compute dispatch, which is why this is opt-in where the storage lowering is automatic: it changes what the host has to do. Implies the data-texture lowering for the read-only storage bindings that remain.

overrideValuesoptional Readonly<Record<string, number | boolean>>

Pin override values for this emit. GLSL ES 3.00 has no pipeline-time specialization constants, so each specialization is its own emit: every override named here becomes a hard #define NAME <value> after the #version and precision lines, spelled as a GLSL literal (a u suffix for u32, a .0 for f32). An override not named here keeps its #ifndef default. reflect lists the module’s overrides under overrides; the WGSL equivalent is createRenderPipeline({ constants }).

floatPrecisionoptional 'highp' | 'mediump'

The default float precision qualifier for the emitted stage, the precision <p> float; line. 'highp' is the default and leaves the emitted bytes unchanged. It applies to floating-point declarations without an explicit precision qualifier; explicit qualifiers and the expression precision rules still apply.

GLSL ES 3.00 predeclares highp float precision in vertex shaders. Fragment shaders have no default float precision. This option sets an explicit default in either stage. It is decided at emit time, never probed from the device, so a cache of emitted source must include it in its key.

It spells the float line and nothing else. precision highp int; and the precision highp <sampler type>; lines stay highp. Index math and integer bit patterns in the storage-to-data-texture lowering need the full integer range.

Mediump specifies minimum range and precision requirements, not an IEEE 754 binary16 format. An implementation may use higher precision, including f32. Unqualified positions, coordinates and intermediate variables can be affected; a bounded final colour alone does not establish that the calculations meet their error budget. Keep highp for calculations that require its range or precision, including the f32 components of the emulation behind f64T.

Measure numeric errors and performance on the target implementations. Reduced precision can improve performance or power use on some devices; this option guarantees neither. Numeric differences are not restricted to mobile hardware.

In the guide

See also

Source

src/core/backends/glsl/options.ts, line 10, at commit af54ddad5

Edit this page Report a problem