---
title: "location(): function in Layout, TypeShade API reference"
description: "location, a function in Layout. Attribute a field or an entry-point parameter with @location(<n>), a slot the pipeline or the previous stage supplies…"
url: https://typeshade.dev/api/location/
language: en
---

# `location()`

Function in Layout

Attribute a field or an entry-point parameter with `@location(<n>)`, a slot the pipeline or the previous stage supplies, with an optional `@interpolate(<mode>)`.

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

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

## Syntax

```ts
const location: <T extends ShaderType>(
  n: number,
  type: T,
  interpolate?: string,
) => FieldSpec<T>
```

## Parameters

**`n` `number`**

the location slot.

**`type` `T extends ShaderType`**

the field’s type.

**`interpolate` optional `string`**

the interpolation mode, such as `'flat'` for an integer varying.

## Return value

`FieldSpec<T>`

a [`FieldSpec`](https://typeshade.dev/api/fieldspec/) for an `ioStruct` field map or an `fn` parameter record.

## Description

The same helper serves an [`ioStruct`](https://typeshade.dev/api/iostruct/) field map and an [`fn`](https://typeshade.dev/api/fn/) parameter record.

## Examples

### Example

```ts
const VsOut = ioStruct('VsOut', { pos: builtin('position', vec4fT), id: location(0, u32T, 'flat') })
```

## In the guide

- [Your first shader](https://typeshade.dev/guide/internals/your-first-shader/)
- [Functions and entry points](https://typeshade.dev/guide/internals/functions-and-entry-points/)
- [Layouts and resources](https://typeshade.dev/guide/internals/layouts-and-resources/)
- [Emitting and reflection](https://typeshade.dev/guide/internals/emitting-and-reflection/)
- [Diagnostics](https://typeshade.dev/guide/internals/diagnostics/)
- [fp64](https://typeshade.dev/guide/internals/fp64/)

## See also

- [`ioStruct`](https://typeshade.dev/api/iostruct/)
- [`fn`](https://typeshade.dev/api/fn/)
- [`FieldSpec`](https://typeshade.dev/api/fieldspec/)
- [`builtin`](https://typeshade.dev/api/builtin/)

## Source

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