---
title: "wgslLayout(): function in Reflection, TypeShade API"
description: "wgslLayout, a function in Reflection. Compute the byte layout of one struct under a LayoutKind: each field's offset, alignment and size…"
url: https://typeshade.dev/api/wgsllayout/
language: en
---

# `wgslLayout()`

Function in Reflection

Compute the byte layout of one struct under a LayoutKind: each field's offset, alignment and size, plus the struct's total size and alignment.

`import { wgslLayout } from 'typeshade'`

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

## Syntax

```ts
function wgslLayout(
  struct: StructDecl,
  layout: LayoutKind,
  structs: ReadonlyMap<string, StructDecl> = new Map(),
): StructLayout
```

## Parameters

**`struct` `StructDecl`**

the struct to lay out.

**`layout` `LayoutKind`**

`'std140'` for a uniform buffer, `'std430'` for a storage buffer.

**`structs` optional `ReadonlyMap<string, StructDecl>`**

the structs a nested struct-typed field may refer to, by name. Defaults to a map holding only `struct` itself.

## Return value

`StructLayout`

the [`StructLayout`](https://typeshade.dev/api/structlayout/).

## Exceptions

**`Error`**

if a field’s type has no byte layout (a texture or a sampler), if a nested struct is not in `structs`, or if a `mat2` field is laid out under `'std140'` (see [`LayoutKind`](https://typeshade.dev/api/layoutkind/)).

## Description

Under `'std140'` the struct’s and every nested array’s base alignment rounds up to 16; under `'std430'` natural alignment applies.

## Examples

### Example

```ts
import { wgslLayout } from 'typeshade'
import { vec3fT, f32T } from 'typeshade/core/ir'

const light = { name: 'Light', fields: [{ name: 'pos', type: vec3fT }, { name: 'radius', type: f32T }] }
wgslLayout(light, 'std140')
// { name: 'Light', size: 16, align: 16, fields: [
//   { name: 'pos', type: 'vec3<f32>', offset: 0, align: 16, size: 12 },
//   { name: 'radius', type: 'f32', offset: 12, align: 4, size: 4 } ] }
```

## In the guide

- [Emitting and reflection](https://typeshade.dev/guide/internals/emitting-and-reflection/)

## See also

- [`LayoutKind`](https://typeshade.dev/api/layoutkind/)
- [`StructLayout`](https://typeshade.dev/api/structlayout/)
- [`reflect`](https://typeshade.dev/api/reflect/)

## Source

[`src/core/reflect/layout.ts`, line 211](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/reflect/layout.ts#L211), at commit af54ddad5
