---
title: "uniformStruct(): function in Layout, TypeShade API reference"
description: "uniformStruct, a function in Layout. Declare a uniform-buffer struct together with its binding, from one field map."
url: https://typeshade.dev/api/uniformstruct/
language: en
---

# `uniformStruct()`

Function in Layout

Declare a uniform-buffer struct together with its binding, from one field map.

`import { uniformStruct } from 'typeshade/core/ir'`

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

## Syntax

```ts
function uniformStruct<F extends Record<string, UniformFieldSpec>>(
  typeName: string,
  at: { group: number; binding: number; as: string },
  fields: F,
): UniformStruct<F>
```

## Parameters

**`typeName` `string`**

the emitted struct name.

**`at` `{ group: number; binding: number; as: string }`**

the `group` and `binding` slot, and `as`, the emitted variable name every field read is spelled through.

**`fields` `F extends Record<string, UniformFieldSpec>`**

the field map: a shader type, or an [`arrayOf`](https://typeshade.dev/api/arrayof/) array field.

## Return value

`UniformStruct<F>`

the [`UniformStruct`](https://typeshade.dev/api/uniformstruct-interface/) handle described above.

## Description

The struct, the binding and every field read then come from the same declaration, so a slot or a field type cannot drift between them.

The returned handle carries:

- `.struct` (also spelled `.decl`) for `module({ structs })` and `.binding` for `module({ bindings })`. Passing the handle in `uses` contributes both.
- `.field.<name>` for typed field access, which chains straight into the value surface: `U.field.raster_params.x`, `U.field.mvp.mul(v)`. A field declared with [`arrayOf`](https://typeshade.dev/api/arrayof/) exposes `.at(i)` instead. Uniforms are read-only, so `U.field.opacity.assign(...)` is a tsc error.
- `.node` for the raw binding access node, which is what a hand-built `member(...)` read needs and is rarely wanted otherwise.
- `.type` for the struct’s shader type.

Byte offsets are std140 and come from `reflect(m).uniforms`, so a host never counts them by hand.

## Examples

### Example

```ts
import { uniformStruct, mat4x4fT, vec4fT } from 'typeshade/core/ir'

const U = uniformStruct('Uniforms', { group: 0, binding: 0, as: 'u' }, {
  mvp: mat4x4fT,
  raster_params: vec4fT,
})

const opacity = U.field.raster_params.x
const m = module({ uses: [U], funcs: [vs, fs] })
```

## See also

- [`arrayOf`](https://typeshade.dev/api/arrayof/)
- [`UniformStruct`](https://typeshade.dev/api/uniformstruct-interface/)
- [`reflect`](https://typeshade.dev/api/reflect/)
- [`hostUniform`](https://typeshade.dev/api/hostuniform/)
- [`when`](https://typeshade.dev/api/when/)
- [`uniform`](https://typeshade.dev/api/uniform/)
- [`ioStruct`](https://typeshade.dev/api/iostruct/)

## Source

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