textureNumLayers
On this page

textureNumLayers()

Function in Builtins

How many layers a 2D array texture has, as a u32.

import { textureNumLayers } from 'typeshade'

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

Syntax

const textureNumLayers: (
tex: ReadonlyNode<TextureLoadArrayKey>,
) => Node<"u32">

Parameters

tex ReadonlyNode<TextureLoadArrayKey>

the array-texture binding to measure.

Return value

Node<'u32'>

the layer count.

Description

textureDimensions reports the width and height only, vec2<u32>, for an array texture as much as for a plain one, so the layer count is this separate query. Wrap the result in toF32 for float arithmetic.

It accepts an array key only: a plain 2D or multisampled texture has no layer count, and passing one is a tsc error. An integer array texture is accepted, since the count is a property of the view and not of the texel element.

The targets spell it differently, which is why it carries its own id instead of overloading textureDimensions. WGSL has the dedicated textureNumLayers(t). GLSL ES 3.00 has no such function and reads the third component of textureSize(t, 0), exactly the component the uvec2() constructor behind textureDimensions drops. The lod argument is required there, and the layer count does not vary with lod, so 0 is always right.

The CPU evaluation (compileModule) has no way to query a texture and returns a placeholder under its gpuStubs option.

Examples

Example

import { resource, textureNumLayers, toF32, texture2dArrayfT } from 'typeshade'
const atlas = resource('atlas', texture2dArrayfT, { group: 0, binding: 1 })
const layers = toF32(textureNumLayers(atlas.node))

Targets

TargetSupportNotes
WGSL (WebGPU) Supported

textureNumLayers(tex).

GLSL ES 3.00 (WebGL2) Supported

uint(textureSize(tex, 0).z).

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

See also

Source

src/core/ir/node.ts, line 2231, at commit 26de7be8

Edit this page Report a problem