---
title: "reflect(): function in Reflection, TypeShade API reference"
description: "reflect, a function in Reflection. Recover a module's pipeline metadata from its IR."
url: https://typeshade.dev/api/reflect/
language: en
---

# `reflect()`

Function in Reflection

Recover a module's pipeline metadata from its IR.

`import { reflect } from 'typeshade'`

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

## Syntax

```ts
function reflect(m: ModuleDecl, opts?: ReflectOptions): Reflection
```

## Parameters

**`m` `ModuleDecl`**

the module to describe.

**`opts` optional `ReflectOptions`**

the emit facts that change what a host must bind, the fp64 flavour among them. Pass the same values the emit will get; a default here that disagrees with the emit describes a different program.

## Return value

`Reflection`

the target-neutral pipeline metadata described above.

## Description

Recover a module’s pipeline metadata from its IR. It is what a host reads to build bind groups, write uniform buffers, describe vertex state and check device features, without parsing a line of emitted source.

The result carries:

- `bindGroups`: every declared binding, sorted by group then binding, each with its name, address space, access mode, resource kind, owner, and the stages that reference it. It also includes the bindings the `f64` emulation adds on the author’s behalf, the `_fp64` guard texture among them (see [`ReflectOptions`](https://typeshade.dev/api/reflectoptions/)), because a host builds its bind group from this list and a binding missing here is a binding never bound.
- `uniforms` and `storage`: std140 and std430 struct layouts, per field offset, align and size plus the struct’s own size and alignment. This is where a byte offset comes from, so nothing counts them by hand.
- `vertex`: the vertex entry’s `@location` attributes with their offsets and the array stride. Attributes are tightly packed in declaration order, with no padding between them. The stride is the sum of their format sizes, as in `packModule()` and the manifest.
- `entries`: one signature per entry point, with its stage, its workgroup size for a compute entry, its input and output types, its structured location and builtin interface, and `portable` when the kernel declares that tier.
- `requiredFeatures`: every capability the emit needs, sorted and deduplicated. It covers the capabilities derived from the module’s shape (a storage binding, a compute entry, a multisampled texture load), the capabilities the module declared in `enables`, and the closure over implication, so a module declaring `float32Blend` also reports `floatRenderTarget`, since blending into a float target needs that target to be colour-renderable first. The ids are neutral, so translate them through [`hostFeaturesFor`](https://typeshade.dev/api/hostfeaturesfor/) for one target.
- `overrides`: each specialization constant’s name, type and default, the values a host pins through pipeline constants or a define header.
- `requires`: the host-provided globals the module references and does not declare.

A texture binding reports three more fields a host needs to create a matching view and layout. `textureDim` is `'2d'`, `'2d-ms'`, `'2d-array'`, `'cube'`, `'3d'`, `'1d'` or `'cube-array'`, and `textureElem` is the texel element, `f32`, `u32` or `i32`. Both axes are needed: WebGPU’s `sampleType` must be `'uint'` or `'sint'` for an integer texture, and WebGL2 must back one with an integer internal format. Getting that pairing wrong raises nothing on WebGL2, since a texture whose format disagrees with its sampler type is merely incomplete and reads zero. `sampleType` is the layout’s own word for it, `'depth'`, `'uint'`, `'sint'`, `'float'` or `'unfilterable-float'`: an `f32` texture is `'float'` when a call of an entry pairs it with a `sampler`, and `'unfilterable-float'` when the entries only load, measure or count it, which a 32-bit float format needs.

Reflection is read-only over the IR and never runs on the emit path. It takes a module and never a backend, which is why every id it reports is target-neutral.

[`wgslLayout`](https://typeshade.dev/api/wgsllayout/) is the same offset engine on its own, for a single struct with no module around it.

## Examples

### Example

```ts
import { reflect, hostFeaturesFor, wgslBackend } from 'typeshade'

const r = reflect(MODULE)
const device = await adapter.requestDevice({
  requiredFeatures: hostFeaturesFor(wgslBackend, r.requiredFeatures),
})
r.uniforms[0].fields // [{ name: 'mvp', offset: 0, size: 64, align: 16 }, …]
```

## In the guide

- [Language guide](https://typeshade.dev/guide/internals/)
- [Layouts and resources](https://typeshade.dev/guide/internals/layouts-and-resources/)
- [Emitting and reflection](https://typeshade.dev/guide/internals/emitting-and-reflection/)
- [The CPU oracle](https://typeshade.dev/guide/internals/the-cpu-oracle/)
- [Diagnostics](https://typeshade.dev/guide/internals/diagnostics/)
- [Conditional programs](https://typeshade.dev/guide/internals/conditional-programs/)
- [Capabilities & extensions](https://typeshade.dev/guide/internals/capabilities-extensions/)
- [fp64](https://typeshade.dev/guide/internals/fp64/)
- [Migrating a GLSL shader](https://typeshade.dev/guide/internals/migrating-a-glsl-shader/)

## See also

- [`ReflectOptions`](https://typeshade.dev/api/reflectoptions/)
- [`hostFeaturesFor`](https://typeshade.dev/api/hostfeaturesfor/)
- [`wgslLayout`](https://typeshade.dev/api/wgsllayout/)
- [`ModuleDecl`](https://typeshade.dev/api/moduledecl/)
- [`module`](https://typeshade.dev/api/module/)
- [`overrideConst`](https://typeshade.dev/api/overrideconst/)
- [`uniformStruct`](https://typeshade.dev/api/uniformstruct/)
- [`storageBuffer`](https://typeshade.dev/api/storagebuffer/)

## Source

[`src/core/reflect.ts`, line 171](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/reflect.ts#L171), at commit af54ddad5
