---
title: "resource(): function in Layout, TypeShade API reference"
description: "resource, a function in Layout. Declare a bound resource that is not a struct: a texture or a sampler."
url: https://typeshade.dev/api/resource/
language: en
---

# `resource()`

Function in Layout

Declare a bound resource that is not a struct: a texture or a sampler.

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

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

## Syntax

```ts
function resource<T extends ShaderType>(
  name: string,
  type: T,
  at: { group: number; binding: number; space?: AddressSpace },
): Resource<T>
```

## Parameters

**`name` `string`**

the emitted binding name, which is also the name a host binds by.

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

the resource’s type, such as `texture2dfT`, `texture2dArrayfT` or `samplerT`.

**`at` `{ group: number; binding: number; space?: AddressSpace }`**

the `group` and `binding` slot, and optionally the address `space`.

## Return value

`Resource<T>`

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

## Description

The binding declaration and the access node come from this one call.

`.node` keeps the specific key of the type you passed: `Node<'texture_2d<f32>'>`, `Node<'sampler'>`, `Node<'texture_2d_array<u32>'>`. That is what makes the texture calls type-checked at the authoring line: [`textureSample`](https://typeshade.dev/api/texturesample/) takes a sampled 2D texture and a sampler in that order, so swapping them is a tsc error, an integer texture is rejected where filtering has no meaning, and an array texture requires its layer argument.

`.binding` goes in `module({ bindings })`, or pass the handle in `uses`. The address space defaults to `'uniform'`, the texture and sampler convention.

## Examples

### Example

```ts
import { resource, textureSample, texture2dfT, samplerT } from 'typeshade/core/ir'

const tex = resource('tex', texture2dfT, { group: 0, binding: 1 })
const smp = resource('tex_sampler', samplerT, { group: 0, binding: 2 })
const c = textureSample(tex.node, smp.node, uv)
```

## See also

- [`textureSample`](https://typeshade.dev/api/texturesample/)
- [`Resource`](https://typeshade.dev/api/resource-interface/)
- [`textureLoad`](https://typeshade.dev/api/textureload/)
- [`storageBuffer`](https://typeshade.dev/api/storagebuffer/)
- [`array`](https://typeshade.dev/api/array/)

## Source

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