---
title: "textureNumSamples: shader function examples and input limits"
description: "Multisampling stores several coverage samples in each texel. This query returns that sample count."
url: https://typeshade.dev/reference/functions/textureNumSamples/
language: en
---

# `textureNumSamples`

Function

Multisampling stores several coverage samples in each texel. This query returns that sample count.

## Compare examples

Textures can have different width and height but return the same sample count.

**Example 1`texture_multisampled_2d: 8 × 8; samples = 4`**

**Result**

`4`

**Example 2`texture_multisampled_2d: 64 × 32; samples = 4`**

**Result**

`4`

**Example 3`texture_depth_multisampled_2d: 8 × 8; samples = 4`**

**Result**

`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 it when resolving a multisampled image by reading its individual samples.

## Inputs and limits

This query requires a multisampled texture. Sample indices start at zero. The compiler has no GLSL ES multisample form.

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/)

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

Returns the number of samples per texel of a `texture_multisampled_2d` or a `texture_depth_multisampled_2d` as a `u32`.

## Syntax

```ts
declare function textureNumSamples<E extends TextureElem = f32>(
  tex: texture_multisampled_2d<E> | texture_depth_multisampled_2d,
): 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`

## Parameters

- `tex` `texture_multisampled_2d<E> | texture_depth_multisampled_2d`

## Return value

`u32`

## Description

A single-sample texture is refused. Compiles to `textureNumSamples` on WGSL; its GLSL lowering is not supported yet ([Rule 10.5](https://typeshade.dev/reference/rules/10-5/)), so a module using it emits WGSL alone.

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**

`textureNumSamples(a)`

**GLSL ES 3.00**

`textureNumSamples` is not supported yet on the WebGL2 tier (Rule 10.5)

## Examples

- [`gallery/msaa-resolve/msaa-resolve.shade.ts`](https://typeshade.dev/guide/examples/msaa-resolve/)

## See also

- [Functions](https://typeshade.dev/reference/functions/)
- [Builtin table](https://typeshade.dev/guide/language/builtins/#textures)
