overrideConst()
함수, 작성 분류
Declare a pipeline specialization constant: one value that is fixed when a pipeline is created, later than module build and earlier than the draw.
import { overrideConst } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
function overrideConst<T extends ShaderType>( name: string, type: T, defaultValue: number | boolean,): OverrideHandle<KeyOf<T>>매개변수
namestringthe override’s name, as the host spells it in
constantsor in a define.typeT extends ShaderTypethe scalar shader type of the value.
defaultValuenumber | booleanthe value used when the host pins nothing.
반환값
OverrideHandle<KeyOf<T>>
an OverrideHandle: .node reads the value, .decl goes into
module({ overrides }).
예외
설명
WGSL emits a module-scope override name: type = default;, and the host pins it through
pipeline constants, createRenderPipeline({ constants: { name } }). GLSL ES 3.00 has no
driver-side equivalent, so a specialized variant is a re-emit: pass
emitGlslModule(m, stage, { overrideValues }) and the backend writes a generated
#define NAME <value> placed after the #version line, which is where GLSL will accept
it. An override the caller does not name keeps its default. The values a host passes on
either target come from reflect(m).overrides, which reports each name, type and default.
The read stays opaque to the optimizer, so a branch guarded by q.node survives every DSL
pass and the driver eliminates it per variant. That is the ubershader mechanism: one
module, one emit, N specialized pipelines.
WGSL allows scalar overrides only, so type must be bool, i32, u32 or f32.
예제
예제
import { overrideConst, module, reflect, u32T } from 'typeshade'
const quality = overrideConst('QUALITY', u32T, 1)const m = module({ overrides: [quality.decl], funcs: [fs] })reflect(m).overrides // [{ name: 'QUALITY', type: u32T, default: 1 }]관련 가이드
함께 보기
소스
src/core/ir/builder.ts, 1501행, 커밋 c66579bf 기준