hostUniform
On this page

hostUniform()

Function in Layout

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'

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

Syntax

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

Parameters

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.

optsoptional { precision?: 'highp' | 'mediump' | 'lowp' }

precision, a GLSL-only qualifier for this declaration.

Return value

Resource<T>

the Resource handle, .binding and .node.

Exceptions

SD0016

SD0016 when type is a struct or an array.

Description

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.

Examples

Example

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

In the guide

See also

Source

src/core/sot.ts, line 899, at commit 26de7be8

Edit this page Report a problem