ConstDecl
이 페이지에서

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읽기 전용 string
type읽기 전용 ShaderType
wgslValue읽기 전용 number

Scalar value emitted by the WGSL/GLSL backends (the truncated shader constant). Used when valueExpr is absent; ignored otherwise.

cpuValue읽기 전용 number

Scalar value used by the CPU backend, at full double precision. Used when valueExpr is absent; ignored otherwise.

valueExpr선택 사항읽기 전용 Expr

Optional constant value as an IR literal expression, for example a vec4<f32>(…) colour, an array<vec4<f32>, N>(…) palette, or a struct literal. When present it replaces wgslValue and cpuValue on every backend: WGSL and GLSL emit it and the CPU backend evaluates it. It must be a constant-foldable literal expression (lit, construct, unop or binop over those, or a constref to an earlier constant); it may not read a binding, a parameter, or a runtime input. Ordinary f32 scalars keep using the wgslValue/cpuValue pair.

함께 보기

소스

src/core/ir/nodes.ts, 377행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고