textureNumLayers
On this page

textureNumLayers

Function

A texture array contains independently addressable image layers. This query returns their count.

Compare examples

The result is the array layer count. For a cube array, it counts cubes, not individual faces.

Example 1texture_2d_array: layers = 1
Result
1
Example 2texture_2d_array: layers = 4
Result
4
Example 3texture_cube_array: cubes = 3
Result
3

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 it to bound a layer selector or iterate over an image array.

Inputs and limits

The texture must be an array texture. The highest valid layer index is one less than the count.

For shader input rules and precision, consult WGSL and GLSL ES 3.00.

WGSL
textureNumLayers(a)
GLSL ES 3.00
uint(textureSize(a, 0).z)

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

Returns the number of layers of a texture_2d_array or a texture_cube_array as a u32.

Syntax

declare function textureNumLayers<E extends TextureElem = f32>(tex: texture_cube_array<E>): u32
declare function textureNumLayers(tex: texture_depth_cube_array): u32
declare function textureNumLayers(tex: texture_depth_2d_array): u32
declare function textureNumLayers<E extends TextureElem = f32>(tex: texture_2d_array<E>): u32
declare function textureNumLayers<F extends StorageFormat, A extends StorageAccess>(
tex: texture_storage_2d_array<F, A>,
): u32

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

Return value

u32

Description

A texture with no layers is refused.

Targets

WGSL
textureNumLayers(a)
GLSL ES 3.00
uint(textureSize(a, 0).z)

Examples

See also

Edit this page Report a problem