---
title: "lowerComputeToFragment(): function in Emit, TypeShade API"
description: "lowerComputeToFragment, a function in Emit. Rewrite a gather-only @compute module into a @fragment one that WebGL2 runs as a fullscreen draw into an R32UI…"
url: https://typeshade.dev/api/lowercomputetofragment/
language: en
---

# `lowerComputeToFragment()`

Function in Emit

Rewrite a gather-only `@compute` module into a `@fragment` one that WebGL2 runs as a fullscreen draw into an R32UI target, one texel per invocation.

`import { lowerComputeToFragment } from 'typeshade'`

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

## Syntax

```ts
function lowerComputeToFragment(m: ModuleDecl): ModuleDecl
```

## Parameters

**`m` `ModuleDecl`**

a module with one `@compute` entry.

## Return value

`ModuleDecl`

the rewritten module, with a `@fragment` entry and no `read_write` binding.

## Exceptions

**`@link UnsupportedFeatureError`**

([`SD0030`](https://typeshade.dev/reference/errors/sd0030/)) when the module has no `@compute` entry, no `global_invocation_id` parameter, no `read_write` storage binding or no `uniform` binding, and when the kernel is not gather-only: a write at an index other than `gid.x`, more than one write to the output, or a use of `global_invocation_id` other than `.x`.

**`@link TypeShadeError`**

[`SD0111`](https://typeshade.dev/reference/errors/sd0111/) instead of the above when the entry is declared `portable`: the portable-kernel check then reports every violation with its remedy at once, the same report both backends give.

## Description

The rewrite:

- turns the `@compute` entry into a `@fragment` entry and drops its workgroup size;
- removes the `@builtin(global_invocation_id)` parameter and adds a `@builtin(position)` one, so `gid.x` becomes `u32(floor(position.x)) + u32(floor(position.y)) * width`, where `width` is the `.y` component of the module’s first `uniform` binding;
- turns the single `out[gid.x] = e` write to the `read_write` storage binding into `return e`, typed `u32` at `@location(0)`, and removes that binding;
- turns an expression-less `return;` (the bounds guard) into `discard;`.

Read-only storage bindings are left in place; a full emit goes on to rewrite them as data textures, so a module this function returns is not yet ready to emit on its own.

## Source

[`src/core/backends/glsl/compute-lowering.ts`, line 39](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/backends/glsl/compute-lowering.ts#L39), at commit af54ddad5
