---
title: "compute: attribute in the TypeShade language reference"
description: "compute, an attribute in the TypeShade language reference. Marks a compute-stage entry point with its workgroup size, one to three extents…"
url: https://typeshade.dev/reference/attributes/compute/
language: en
---

# `@compute`

Attribute

Marks a compute-stage entry point with its workgroup size, one to three extents, on the function declaration: `@compute([64]) export function main(…) { … }`.

`@compute([x, y?, z?])` makes the function it marks a compute entry point and gives its workgroup size, one to three extents.

## Compare examples

Compare three invocations of one dispatch. Each reads its own `global_invocation_id` and writes its own element.

**Example program**`declare const out: storage<array<u32>, "read_write">; @compute([64]) export function main(gid: builtin<"global_invocation_id">): void { out[gid.x] = gid.x; }`

**Example 1`gid.x = 0`**

**Result**

`workgroup 0, lane 0`

**Example 2`gid.x = 63`**

**Result**

`workgroup 0, lane 63`

**Example 3`gid.x = 64`**

**Result**

`workgroup 1, lane 0`

The examples are calculation models and do not run GPU work. The reference below gives the syntax of the attribute. 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 for general GPU work over buffers and textures, outside any draw.

## Inputs and limits

The size is the argument of the attribute, and a bare `@compute` takes 64. The host chooses how many workgroups a dispatch runs; the size says how many invocations each one holds.

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 attributes

- [`@workgroup_size`](https://typeshade.dev/reference/attributes/workgroup_size/)
- [`@vertex`](https://typeshade.dev/reference/attributes/vertex/)
- [`@fragment`](https://typeshade.dev/reference/attributes/fragment/)

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

## Syntax

```ts
declare function compute(workgroupSize: readonly number[]): (target: Function, context?: unknown) => void
declare function compute(target: Function, context?: unknown): void
```

## Parameters

- `workgroupSize` `readonly number[]`

It is also written on its own, with no arguments.

The declaration also names what the TypeScript decorator runtime hands a decorator, `target` and `context`. A call passes neither.

## Description

A bare `@compute` takes 64.

## Examples

- [`path/double-array/double-array.shade.ts`](https://typeshade.dev/guide/examples/double-array/)
- [`path/image-blur/image-blur.shade.ts`](https://typeshade.dev/guide/examples/image-blur/)
- [`path/parallel-sum/parallel-sum.shade.ts`](https://typeshade.dev/guide/examples/parallel-sum/)
- [`path/histogram/histogram.shade.ts`](https://typeshade.dev/guide/examples/histogram/)
- [`gallery/array-length/array-length.shade.ts`](https://typeshade.dev/guide/examples/array-length/)
- [`gallery/atomic-histogram/atomic-histogram.shade.ts`](https://typeshade.dev/guide/examples/atomic-histogram/)
- [`gallery/compute-reduction-twin/compute-reduction-twin.shade.ts`](https://typeshade.dev/guide/examples/compute-reduction-twin/)
- [`gallery/compute-sync/compute-sync.shade.ts`](https://typeshade.dev/guide/examples/compute-sync/)
- [`gallery/gpu-console/gpu-console.shade.ts`](https://typeshade.dev/guide/examples/gpu-console/)
- [`gallery/particle-step/particle-step.shade.ts`](https://typeshade.dev/guide/examples/particle-step/)
- [`gallery/storage-texture/storage-texture.shade.ts`](https://typeshade.dev/guide/examples/storage-texture/)
- [`gallery/subgroup-reduce/subgroup-reduce.shade.ts`](https://typeshade.dev/guide/examples/subgroup-reduce/)
- [`gallery/workgroup-override/workgroup-override.shade.ts`](https://typeshade.dev/guide/examples/workgroup-override/)
- [`gallery/workgroup-reduce/workgroup-reduce.shade.ts`](https://typeshade.dev/guide/examples/workgroup-reduce/)
- [`gallery/workgroup-scratch/workgroup-scratch.shade.ts`](https://typeshade.dev/guide/examples/workgroup-scratch/)
- [`gallery/workgroup-tile-2d/workgroup-tile-2d.shade.ts`](https://typeshade.dev/guide/examples/workgroup-tile-2d/)

## See also

- [Attributes](https://typeshade.dev/reference/attributes/)
