> Development branch documentation · commit 327c05c78d2f528e4f4a679fcc7a77d9aa161f48
> Package versions: @zenfg/webgpu 0.1.0, @zenfg/snapshot 0.1.0, @zenfg/inspector 0.1.0, zenfg 0.1.0, zenfg-snapshot 0.1.0
> Source: https://github.com/uinosoft/zenfg/blob/327c05c78d2f528e4f4a679fcc7a77d9aa161f48/packages/webgpu/src/frameGraph.ts#L247

[ZenFG TypeScript API](/zenfg/docs/api/index.md) / [webgpu](/zenfg/docs/api/webgpu/index.md) / [root](/zenfg/docs/api/webgpu/root/index.md) / FrameGraph

# Class: FrameGraph

Defined in: [packages/webgpu/src/frameGraph.ts:247](https://github.com/uinosoft/zenfg/blob/327c05c78d2f528e4f4a679fcc7a77d9aa161f48/packages/webgpu/src/frameGraph.ts#L247)

**`Beta`**

Long-lived device-bound runtime shared by independent recordings and compiled
frames. It owns only the transient pool and GPU profiler.

## Remarks

A `FrameGraph` may create many independent single-use recorders, but
only one compiled frame may execute at a time. Imported textures and buffers
always remain caller-owned. Call [FrameGraph.destroy](#destroy) before releasing
the device-bound runtime.

## Example

```ts
import { FrameGraph } from '@zenfg/webgpu';

const graph = new FrameGraph(device);
const frame = graph.beginFrame();
const buffer = frame.createBuffer({ label: 'scratch', size: 256 });
frame.clearBuffer({ operations: [{ target: buffer }], sideEffect: true });
frame.compile().execute();
graph.destroy();
```

## Constructors

### Constructor

> **new FrameGraph**(`device`): `FrameGraph`

Defined in: [packages/webgpu/src/frameGraph.ts:251](https://github.com/uinosoft/zenfg/blob/327c05c78d2f528e4f4a679fcc7a77d9aa161f48/packages/webgpu/src/frameGraph.ts#L251)

**`Beta`**

Creates a CPU-only runtime bound permanently to `device`.

#### Parameters

##### device

`GPUDevice`

#### Returns

`FrameGraph`

## Methods

### beginFrame()

> **beginFrame**(): [`FrameGraphRecorder`](/zenfg/docs/api/webgpu/root/interfaces/FrameGraphRecorder.md)

Defined in: [packages/webgpu/src/frameGraph.ts:266](https://github.com/uinosoft/zenfg/blob/327c05c78d2f528e4f4a679fcc7a77d9aa161f48/packages/webgpu/src/frameGraph.ts#L266)

**`Beta`**

Starts an independent single-use recording.

#### Returns

[`FrameGraphRecorder`](/zenfg/docs/api/webgpu/root/interfaces/FrameGraphRecorder.md)

#### Throws

If this runtime has been destroyed.

***

### clearResourcePool()

> **clearResourcePool**(): `void`

Defined in: [packages/webgpu/src/frameGraph.ts:287](https://github.com/uinosoft/zenfg/blob/327c05c78d2f528e4f4a679fcc7a77d9aa161f48/packages/webgpu/src/frameGraph.ts#L287)

**`Beta`**

Destroys resources retained for reuse while preserving historical counters.

#### Returns

`void`

#### Throws

If this runtime has been destroyed or a compiled frame is currently
executing.

***

### destroy()

> **destroy**(): `void`

Defined in: [packages/webgpu/src/frameGraph.ts:300](https://github.com/uinosoft/zenfg/blob/327c05c78d2f528e4f4a679fcc7a77d9aa161f48/packages/webgpu/src/frameGraph.ts#L300)

**`Beta`**

Permanently releases runtime-owned resources and invalidates outstanding
recorders and compiled frames. Imported resources remain caller-owned.
Repeated calls after successful destruction are no-ops.

#### Returns

`void`

#### Throws

If a compiled frame is currently executing.

***

### getResourcePoolStats()

> **getResourcePoolStats**(): [`FrameGraphResourcePoolStats`](/zenfg/docs/api/webgpu/root/type-aliases/FrameGraphResourcePoolStats.md)

Defined in: [packages/webgpu/src/frameGraph.ts:276](https://github.com/uinosoft/zenfg/blob/327c05c78d2f528e4f4a679fcc7a77d9aa161f48/packages/webgpu/src/frameGraph.ts#L276)

**`Beta`**

Returns aggregate transient-pool counters and retained-byte estimates.

#### Returns

[`FrameGraphResourcePoolStats`](/zenfg/docs/api/webgpu/root/type-aliases/FrameGraphResourcePoolStats.md)

#### Throws

If this runtime has been destroyed.
