---
title: "overrideConst(): function in Authoring, TypeShade API"
description: "overrideConst, a function in Authoring. Declare a pipeline specialization constant: one value that is fixed when a pipeline is created…"
url: https://typeshade.dev/api/overrideconst/
language: en
---

# `overrideConst()`

Function in Authoring

Declare a pipeline specialization constant: one value that is fixed when a pipeline is created, later than module build and earlier than the draw.

`import { overrideConst } from 'typeshade/core/ir'`

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

## Syntax

```ts
function overrideConst<T extends ShaderType>(
  name: string,
  type: T,
  defaultValue: number | boolean,
): OverrideHandle<KeyOf<T>>
```

## Parameters

**`name` `string`**

the override’s name, as the host spells it in `constants` or in a define.

**`type` `T extends ShaderType`**

the scalar shader type of the value.

**`defaultValue` `number | boolean`**

the value used when the host pins nothing.

## Return value

`OverrideHandle<KeyOf<T>>`

an [`OverrideHandle`](https://typeshade.dev/api/overridehandle/): `.node` reads the value, `.decl` goes into `module({ overrides })`.

## Exceptions

**[`SD0014`](https://typeshade.dev/reference/errors/sd0014/)**

[`SD0014`](https://typeshade.dev/reference/errors/sd0014/) when `type` is not a scalar.

## Description

WGSL emits a module-scope `override name: type = default;`, and the host pins it through pipeline constants, `createRenderPipeline({ constants: { name } })`. GLSL ES 3.00 has no driver-side equivalent, so a specialized variant is a re-emit: pass `emitGlslModule(m, stage, { overrideValues })` and the backend writes a generated `#define NAME <value>` placed after the `#version` line, which is where GLSL will accept it. An override the caller does not name keeps its default. The values a host passes on either target come from `reflect(m).overrides`, which reports each name, type and default.

The read stays opaque to the optimizer, so a branch guarded by `q.node` survives every DSL pass and the driver eliminates it per variant. That is the ubershader mechanism: one module, one emit, N specialized pipelines.

WGSL allows scalar overrides only, so `type` must be `bool`, `i32`, `u32` or `f32`.

## Examples

### Example

```ts
import { reflect } from 'typeshade'
import { overrideConst, module, u32T } from 'typeshade/core/ir'

const quality = overrideConst('QUALITY', u32T, 1)
const m = module({ overrides: [quality.decl], funcs: [fs] })
reflect(m).overrides // [{ name: 'QUALITY', type: u32T, default: 1 }]
```

## See also

- [`OverrideHandle`](https://typeshade.dev/api/overridehandle/)
- [`reflect`](https://typeshade.dev/api/reflect/)
- [`variantFamily`](https://typeshade.dev/api/variantfamily/)
- [`when`](https://typeshade.dev/api/when/)

## Source

[`src/core/ir/builder.ts`, line 1235](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/builder.ts#L1235), at commit af54ddad5
