hostUniform
이 페이지에서

hostUniform()

함수, 레이아웃 분류

Declare a host-owned uniform: one scalar, vector or matrix value the host supplies, spelled the way the host's target spells it.

import { hostUniform } from 'typeshade'

시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.

구문

function hostUniform<T extends ShaderType>(
name: string,
type: T,
at: { group: number; binding: number },
opts?: { precision?: 'highp' | 'mediump' | 'lowp' },
): Resource<T>

매개변수

name string

the uniform’s name, as the host spells it.

type T extends ShaderType

its shader type: a scalar, vector or matrix.

at { group: number; binding: number }

the WGSL group and binding slot. GLSL does not use it, and it is still required because the same declaration has to work on both targets.

opts선택 사항 { precision?: 'highp' | 'mediump' | 'lowp' }

precision, a GLSL-only qualifier for this declaration.

반환값

Resource<T>

the Resource handle, .binding and .node.

예외

SD0016

SD0016 when type is a struct or an array.

설명

On WGSL this is an ordinary @group(N) @binding(M) var<uniform> declaration. The one difference from resource is that reflect marks it owner: 'host', which tells a consumer that the host’s bind-group layout is the authority and it must not allocate one itself.

On GLSL ES 3.00 it emits a loose uniform <type> <name>; in the default block, which is what a GLSL host prelude provides, where a module-owned uniform gets a std140 block. The declaration is a real binding, so reflect describes it and minify() keeps it consistent with the module’s reads.

Scalars, vectors and matrices only. A host-owned struct is hostBlock, which makes the same choice one level up: it can flatten to exactly these loose declarations, or stay a std140 block. When the host’s prelude already declares the symbol and the module must not declare it again, use externVar, which emits nothing.

예제

예제

import { hostUniform, vec2fT } from 'typeshade'
const viewport = hostUniform('u_viewport_px', vec2fT, { group: 0, binding: 1 }, {
precision: 'highp', // GLSL only; ignored on WGSL
})

관련 가이드

함께 보기

소스

src/core/sot.ts, 899행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고