GlslEmitOptions
인터페이스, 출력 분류
The options accepted by emitGlslModule, emitGlslStages and emitGlslFragment: the shared EmitOptions plus three that exist only for GLSL ES 3.00, one for each thing the target lacks.
import type { GlslEmitOptions } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
interface GlslEmitOptions extends EmitOptions { emulateCompute?: boolean; overrideValues?: Readonly<Record<string, number | boolean>>; floatPrecision?: 'highp' | 'mediump';}설명
WebGL2 has no compute stage
(emulateCompute), no pipeline-time specialization constants (overrideValues) and no
implicit 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.
인스턴스 속성
emulateCompute선택 사항지원 중단booleanLower a gather-only
@computekernel to a fragment pass, aslowerComputeToFragmentdescribes. The host then runs the kernel as a fullscreen draw into anR32UItarget 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.overrideValues선택 사항Readonly<Record<string, number | boolean>>Pin
overridevalues 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#versionand precision lines, spelled as a GLSL literal (ausuffix foru32, a.0forf32). An override not named here keeps its#ifndefdefault.reflectlists the module’s overrides underoverrides; the WGSL equivalent iscreateRenderPipeline({ constants }).floatPrecision선택 사항'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.A mobile GPU pays real bandwidth and power for highp arithmetic and highp varyings where mediump suffices, and the precision qualifier is the only lever GLSL ES gives for it. The option is decided at emit time, never probed from the device, so a cache of emitted source must include it in its key; a key without it serves a mediump program to a highp request.
It spells the float line and nothing else.
precision highp int;stays highp, because the index math of the storage-to-data-texture lowering and the integer bit patterns it reads back need the full integer range, and theprecision highp <sampler type>;lines stay highp as well.It is a whole-stage default, so it covers positions and coordinates too. mediump is roughly fp16: about three decimal digits over a range of plus or minus 65504, far short of what a world-space position needs. f32 already runs out of precision once a value needs more than its seven digits, which is why the double-float emulation behind
f64Texists. Use'mediump'for fragment shaders whose output is a bounded, low-dynamic-range colour, and keep it away from any stage that computes a position, a value in world units or anf64value.Whether a device actually computes mediump at reduced precision is up to its driver; a software rasterizer that advertises 10-bit mediump commonly computes it at f32, so the numeric effect shows only on real mobile hardware.
관련 가이드
함께 보기
소스
src/core/backends/glsl.ts, 1846행, 커밋 c66579bf 기준