---
title: "textureLoad(): IR builder function in typeshade/core/ir"
description: "textureLoad, an IR builder function in typeshade/core/ir. Load one texel from a 2D texture at integer coordinates, returning vec4<f32>…"
url: https://typeshade.dev/api/textureload/
language: en
---

# `textureLoad()`

Function in Builtins

Load one texel from a 2D texture at integer coordinates, returning `vec4<f32>`, `vec4<u32>` or `vec4<i32>` to match the texture's element.

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

This export returns an IR node. A `"use typeshade"` file calls the builtin itself: [`textureLoad()`](https://typeshade.dev/reference/functions/textureLoad/)

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

## Syntax

```ts
function textureLoad<K extends TextureLoad2dKey>(
  tex: ReadonlyNode<K>,
  coord: NodeLike,
  level: NodeLike,
): Node<TexelKey<K>>;
function textureLoad<K extends TextureLoadArrayKey>(
  tex: ReadonlyNode<K>,
  coord: NodeLike,
  layer: ReadonlyNode<'i32' | 'u32'> | number,
  level: NodeLike,
): Node<TexelKey<K>>;
```

## Parameters

**`tex` `ReadonlyNode<K>`**

**`coord` `NodeLike`**

**`level` `NodeLike`**

## Return value

`Node<TexelKey<K>>`

## Exceptions

**[`SD0015`](https://typeshade.dev/reference/errors/sd0015/)**

A JS number level lifts to a `u32` literal, so 0 emits a valid integer level on both targets, and a fractional level throws SD0015.

## Description

WGSL requires the mip level argument; pass `0` for the base level. A JS number level lifts to a `u32` literal, so `0` emits a valid integer level on both targets, and a fractional level throws [`SD0015`](https://typeshade.dev/reference/errors/sd0015/). The coordinate is usually a `vec2<i32>`; any vector or scalar node is accepted here and the GPU compiler checks it. The CPU evaluation returns a placeholder under its `gpuStubs` option.

For an integer texture this is the read to use: integer texels cannot be filtered, so [`textureSample`](https://typeshade.dev/api/texturesample/) and [`textureSampleLevel`](https://typeshade.dev/api/texturesamplelevel/) reject those keys at `tsc`.

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Supported | `textureLoad(tex, coord, level)`. |
| GLSL ES 3.00 (WebGL2) | Supported | `texelFetch(tex, coord, int(level))`. |
| CPU oracle | Stub | The oracle has no texture memory and no neighbouring fragments. The call throws unless the module was compiled with `{ gpuStubs: true }`, which returns a placeholder. |

## In the guide

- [Layouts and resources](https://typeshade.dev/guide/internals/layouts-and-resources/)
- [The CPU oracle](https://typeshade.dev/guide/internals/the-cpu-oracle/)

## See also

- [`textureLoad()`](https://typeshade.dev/reference/functions/textureLoad/)
- [`textureSample`](https://typeshade.dev/api/texturesample/)
- [`textureSampleLevel`](https://typeshade.dev/api/texturesamplelevel/)
- [`resource`](https://typeshade.dev/api/resource/)

## Source

[`src/core/ir/node.ts`, line 1882](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/node.ts#L1882), at commit af54ddad5
