---
title: "textureDimensions / textureSize: shader function guide"
description: "Texture dimensions describe the extent of an image, not its colour. Use them to turn texel offsets into normalized coordinate offsets."
url: https://typeshade.dev/reference/functions/textureDimensions/
language: en
---

# `textureDimensions`

Function

Texture dimensions describe the extent of an image, not its colour.

**Related names in other languages**

These related operations can differ in arguments, support, and semantics. The foreign names are not accepted TypeShade aliases. Check the target forms and restrictions.

- GLSL: `textureSize`

[Targets](https://typeshade.dev/reference/functions/textureDimensions/#targets)

## Compare examples

Each component of the returned vector gives the texel count along one axis. A cube's face count is not part of that size vector.

**Example 1`texture_2d: 8 × 4`**

**Result**

`vec2u(8, 4)`

**Example 2`texture_3d: 8 × 4 × 2`**

**Result**

`vec3u(8, 4, 2)`

**Example 3`texture_cube: 4 × 4 × 6`**

**Result**

`vec2u(4, 4)`

The examples are calculation models and do not run GPU work. The reference below gives the complete call signatures. Decimal results are rounded for display. The stated assumptions determine each example; actual shader results follow the target precision and execution rules.

## When to use it

Use them to turn texel offsets into normalized coordinate offsets.

## Inputs and limits

Array layer counts and sample counts are separate queries. A cube query returns the size of one face.

For shader input rules and precision, consult [WGSL](https://www.w3.org/TR/WGSL/) and [GLSL ES 3.00](https://registry.khronos.org/OpenGL/specs/es/3.0/GLSL_ES_Specification_3.00.pdf).

## Related functions

- [`textureSample`](https://typeshade.dev/reference/functions/textureSample/)
- [`textureLoad`](https://typeshade.dev/reference/functions/textureLoad/)
- [`textureSampleLevel`](https://typeshade.dev/reference/functions/textureSampleLevel/)
- [`textureSampleBias`](https://typeshade.dev/reference/functions/textureSampleBias/)
- [`textureSampleGrad`](https://typeshade.dev/reference/functions/textureSampleGrad/)

**WGSL**

`textureDimensions(a)`

**GLSL ES 3.00**

`uvec2(textureSize(a, 0))`

The signature, the sentence and any message are the compiler's own text at commit af54ddad5.

Returns the size of the texture's base mip level: width and height as a `vec2u`, width, height and depth as a `vec3u` on a `texture_3d`, or the width alone as a `u32` on a `texture_1d`.

## Syntax

```ts
declare function textureDimensions<E extends TextureElem = f32>(
  tex: texture_2d<E> | texture_2d_array<E>,
  level?: number,
): vec2u
declare function textureDimensions<E extends TextureElem = f32>(
  tex: texture_cube<E> | texture_cube_array<E>,
  level?: number,
): vec2u
declare function textureDimensions<E extends TextureElem = f32>(
  tex: texture_3d<E>,
  level?: number,
): vec3u
declare function textureDimensions<E extends TextureElem = f32>(tex: texture_1d<E>, level?: number): u32
declare function textureDimensions<E extends TextureElem = f32>(tex: texture_multisampled_2d<E>): vec2u
declare function textureDimensions(
  tex:
    | texture_depth_2d
    | texture_depth_2d_array
    | texture_depth_cube
    | texture_depth_cube_array
    | texture_depth_multisampled_2d,
  level?: number,
): vec2u
declare function textureDimensions<F extends StorageFormat, A extends StorageAccess>(
  tex: texture_storage_2d<F, A> | texture_storage_2d_array<F, A>,
): vec2u
```

A `number` in a parameter or a return position is the scalar slot. The ambient file declares a GPU scalar as a branded number whose brand is optional, so a literal and any branded scalar both fill it.

`type f32 = number & { readonly [f32Tag]?: true }`

A `number` you write as a type is inferred from its uses, and `f32`, `i32` and `u32` fix a width; [the TypeScript constructs page](https://typeshade.dev/guide/language/from-typescript/) carries that row with the compiler's emit.

A signature may name a type the ambient file declares for its own use. These are those declarations.

**`TextureElem`**

`type TextureElem = f32 | i32 | u32`

**`StorageFormat`**

`type StorageFormat = 'rgba8unorm' | 'rgba8snorm' | 'rgba8uint' | 'rgba8sint' | 'rgba16uint' | 'rgba16sint' | 'rgba16float' | 'r32uint' | 'r32sint' | 'r32float' | 'rg32uint' | 'rg32sint' | 'rg32float' | 'rgba32uint' | 'rgba32sint' | 'rgba32float' | 'bgra8unorm'`

**`StorageAccess`**

`type StorageAccess = 'write' | 'read' | 'read_write'`

## Parameters

- `tex` `texture_2d<E> | texture_2d_array<E>``texture_cube<E> | texture_cube_array<E>``texture_3d<E>``texture_1d<E>``texture_multisampled_2d<E>``| texture_depth_2d | texture_depth_2d_array | texture_depth_cube | texture_depth_cube_array | texture_depth_multisampled_2d``texture_storage_2d<F, A> | texture_storage_2d_array<F, A>`
- `level` optional `number`

## Return value

`vec2u``vec3u``u32`

## Description

On a cube texture it is the size of one face.

The CPU oracle has no texture memory and no neighbouring fragments. The call throws unless the module was compiled with `{ gpuStubs: true }`, which returns a placeholder.

## Targets

**WGSL**

`textureDimensions(a)`

**GLSL ES 3.00**

`uvec2(textureSize(a, 0))`

## Examples

- [`gallery/cube-array-gather/cube-array-gather.shade.ts`](https://typeshade.dev/guide/examples/cube-array-gather/)
- [`gallery/cube-env/cube-env.shade.ts`](https://typeshade.dev/guide/examples/cube-env/)
- [`gallery/msaa-resolve/msaa-resolve.shade.ts`](https://typeshade.dev/guide/examples/msaa-resolve/)
- [`gallery/shadow-compare/shadow-compare.shade.ts`](https://typeshade.dev/guide/examples/shadow-compare/)
- [`gallery/storage-texture/storage-texture.shade.ts`](https://typeshade.dev/guide/examples/storage-texture/)
- [`gallery/textured-quad/textured-quad.shade.ts`](https://typeshade.dev/guide/examples/textured-quad/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [Builtin table](https://typeshade.dev/guide/language/builtins/#textures)
- [`textureDimensions()` in `typeshade/core/ir`](https://typeshade.dev/api/texturedimensions/)
