textureNumLayers()
Function in Builtins
How many layers a 2D array texture has, as a u32.
import { textureNumLayers } from 'typeshade/core/ir'
This export returns an IR node. A "use typeshade" file calls the builtin itself: textureNumLayers()
The signature, the description and the examples come from the compiler's own source at commit af54ddad5.
Syntax
const textureNumLayers: ( tex: ReadonlyNode<TextureLoadArrayKey>,) => Node<"u32">Parameters
texReadonlyNode<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/core/ir'
const atlas = resource('atlas', texture2dArrayfT, { group: 0, binding: 1 })const layers = toF32(textureNumLayers(atlas.node))Targets
| Target | Support | Notes |
|---|---|---|
| WGSL (WebGPU) | Supported |
|
| GLSL ES 3.00 (WebGL2) | Supported |
|
| CPU oracle | Stub | The oracle has no texture memory and no neighbouring fragments. The call throws unless the module was compiled with |
In the guide
See also
Source
src/core/ir/node.ts, line 1967, at commit af54ddad5