ConstDecl
인터페이스, IR 분류
A ModuleDecl.consts entry: a module-scope constant.
import type { ConstDecl } from 'typeshade'
시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.
구문
interface ConstDecl { readonly name: string; readonly type: ShaderType; readonly wgslValue: number; readonly cpuValue: number; readonly valueExpr?: Expr;}설명
For a scalar, write a plain
object literal with one value per precision, for example
{ name: 'PI', type: f32T, wgslValue: 3.14159265, cpuValue: Math.PI }: the WGSL and
GLSL backends emit wgslValue, and the CPU backend, which runs the module in double
precision, uses cpuValue. For a vector, array or struct constant use
constExpr, which fills valueExpr instead. When both forms are present,
valueExpr wins.
인스턴스 속성
name읽기 전용stringtype읽기 전용ShaderTypewgslValue읽기 전용numberScalar value emitted by the WGSL/GLSL backends (the truncated shader constant). Used when
valueExpris absent; ignored otherwise.cpuValue읽기 전용numberScalar value used by the CPU backend, at full double precision. Used when
valueExpris absent; ignored otherwise.valueExpr선택 사항읽기 전용ExprOptional constant value as an IR literal expression, for example a
vec4<f32>(…)colour, anarray<vec4<f32>, N>(…)palette, or a struct literal. When present it replaceswgslValueandcpuValueon every backend: WGSL and GLSL emit it and the CPU backend evaluates it. It must be a constant-foldable literal expression (lit,construct,unoporbinopover those, or aconstrefto an earlier constant); it may not read a binding, a parameter, or a runtime input. Ordinaryf32scalars keep using thewgslValue/cpuValuepair.
함께 보기
소스
src/core/ir/nodes.ts, 377행, 커밋 c66579bf 기준