---
title: "fwidth(): IR builder function in typeshade/core/ir"
description: "fwidth, an IR builder function in typeshade/core/ir. fwidth(x): abs(dpdx(x)) + abs(dpdy(x)), the screen-space derivative magnitude, component-wise."
url: https://typeshade.dev/api/fwidth/
language: en
---

# `fwidth()`

Function in Builtins

`fwidth(x)`: abs(`dpdx(x)`) + abs(`dpdy(x)`), the screen-space derivative magnitude, component-wise.

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

This export returns an IR node. A `"use typeshade"` file calls the builtin itself: [`fwidth()`](https://typeshade.dev/reference/functions/fwidth/)

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

## Syntax

```ts
const fwidth: <K extends FloatKey>(x: ReadonlyNode<K>) => Node<K>
```

## Parameters

**`x` `ReadonlyNode<K>`**

## Return value

`Node<K>`

## Exceptions

**[`SD0109`](https://typeshade.dev/reference/errors/sd0109/)**

It exists only on the GPU and only in a fragment shader; the fragment-only-builtin lint rule, which runs at every emit, reports SD0109 when it appears in a vertex or compute stage.

## Description

`fwidth(x)`: `abs(dpdx(x)) + abs(dpdy(x))`, the screen-space derivative magnitude, component-wise. It exists only on the GPU (the CPU evaluation returns 0) and only in a fragment shader; the `fragment-only-builtin` lint rule, which runs at every emit, reports [`SD0109`](https://typeshade.dev/reference/errors/sd0109/) when it appears in a vertex or compute stage. In those stages compute the quantity on the host and pass it in.

## Targets

| Target | Support | Notes |
| --- | --- | --- |
| WGSL (WebGPU) | Supported | `fwidth(x)`. |
| GLSL ES 3.00 (WebGL2) | Supported | `fwidth(x)`. |
| 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

- [Values and mutation](https://typeshade.dev/guide/internals/values-and-mutation/)
- [Layouts and resources](https://typeshade.dev/guide/internals/layouts-and-resources/)
- [The CPU oracle](https://typeshade.dev/guide/internals/the-cpu-oracle/)

## See also

- [`fwidth()`](https://typeshade.dev/reference/functions/fwidth/)

## Source

[`src/core/ir/node.ts`, line 1974](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/node.ts#L1974), at commit af54ddad5
