---
title: "hostUniform(): function in Layout, TypeShade API reference"
description: "hostUniform, a function in Layout. Declare a host-owned uniform: one scalar, vector or matrix value the host supplies…"
url: https://typeshade.dev/api/hostuniform/
language: en
---

# `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/core/ir'`

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

## Syntax

```ts
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.

**`opts` optional `{ precision?: 'highp' | 'mediump' | 'lowp' }`**

`precision`, a GLSL-only qualifier for this declaration.

## Return value

`Resource<T>`

the [`Resource`](https://typeshade.dev/api/resource-interface/) handle, `.binding` and `.node`.

## Exceptions

**[`SD0016`](https://typeshade.dev/reference/errors/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`](https://typeshade.dev/api/resource/) is that [`reflect`](https://typeshade.dev/api/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`](https://typeshade.dev/api/reflect/) describes it and `minify()` keeps it consistent with the module’s reads.

Scalars, vectors and matrices only. A host-owned struct is [`hostBlock`](https://typeshade.dev/api/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`](https://typeshade.dev/api/externvar/), which emits nothing.

## Examples

### Example

```ts
import { hostUniform, vec2fT } from 'typeshade/core/ir'

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

## In the guide

- [Migrating a GLSL shader](https://typeshade.dev/guide/internals/migrating-a-glsl-shader/)

## See also

- [`resource`](https://typeshade.dev/api/resource/)
- [`reflect`](https://typeshade.dev/api/reflect/)
- [`hostBlock`](https://typeshade.dev/api/hostblock/)
- [`externVar`](https://typeshade.dev/api/externvar/)
- [`Resource`](https://typeshade.dev/api/resource-interface/)
- [`uniformStruct`](https://typeshade.dev/api/uniformstruct/)

## Source

[`src/core/sot.ts`, line 906](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/sot.ts#L906), at commit af54ddad5
