# Class: GpuEncoderSystem

**`Advanced`**

The system that handles encoding commands for the GPU.

## Implements

- [`System`](rendering.System.html.md)

## Constructors

### Constructor

> **new GpuEncoderSystem**(`renderer`): `GpuEncoderSystem`

#### Parameters

##### renderer

[`WebGPURenderer`](rendering.WebGPURenderer.html.md)

#### Returns

`GpuEncoderSystem`

## Properties

### commandEncoder

> **commandEncoder**: [`GPUCommandEncoder`](https://developer.mozilla.org/docs/Web/API/GPUCommandEncoder)

***

### commandFinished

> **commandFinished**: [`Promise`](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise)\<`void`\>

***

### renderPassEncoder

> **renderPassEncoder**: [`GPURenderPassEncoder`](https://developer.mozilla.org/docs/Web/API/GPURenderPassEncoder) \| [`GPURenderBundleEncoder`](https://developer.mozilla.org/docs/Web/API/GPURenderBundleEncoder)

The active command target that draws and state are recorded into. This is the live render
pass during normal rendering, or a [GPURenderBundleEncoder](https://developer.mozilla.org/docs/Web/API/GPURenderBundleEncoder) while a render bundle is
being recorded (see [beginBundle](#beginbundle)). Both encoders expose the same render/bind command
API the encoder relies on (`GPURenderCommandsMixin` + `GPUBindingCommandsMixin`),
so callers write to it without caring which one is active. Pass-level commands (viewport,
stencil, executeBundles, end) are not part of that shared API and go through the private pass encoder.

## Methods

### beginBundle()

> **beginBundle**(`label?`): `void`

Begins recording a render bundle. While recording, all draw commands are captured into a
[GPURenderBundleEncoder](https://developer.mozilla.org/docs/Web/API/GPURenderBundleEncoder) instead of the active render pass. The current render pass
encoder is saved and restored when [endBundle](#endbundle) is called.

Render bundles allow pre-recording of draw commands that can be replayed multiple times
via [executeBundle](#executebundle), reducing CPU overhead for repeated draw sequences.

#### Parameters

##### label?

`string`

Optional debug label. Names the bundle in GPU captures and in the WebGPU
validation errors it can raise when replayed, instead of `(unlabeled)`.

#### Returns

`void`

#### Throws

If a render bundle is already being recorded.

***

### beginRenderPass()

> **beginRenderPass**(`gpuRenderTarget`): `void`

#### Parameters

##### gpuRenderTarget

`GpuRenderTarget`

#### Returns

`void`

***

### destroy()

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

Generic destroy methods to be overridden by the subclass

#### Returns

`void`

#### Implementation of

[`System`](rendering.System.html.md).[`destroy`](rendering.System.html#destroy)

***

### draw()

> **draw**(`options`): `void`

#### Parameters

##### options

###### baseVertex?

`number`

###### firstInstance?

`number`

###### geometry

[`Geometry`](rendering.Geometry.html.md)

###### instanceCount?

`number`

###### shader

[`Shader`](rendering.Shader.html.md)

###### size?

`number`

###### skipSync?

`boolean`

###### start?

`number`

###### state?

[`State`](rendering.State.html.md)

###### topology?

[`Topology`](rendering.Topology.html.md)

#### Returns

`void`

***

### drawIndirect()

> **drawIndirect**(`options`): `void`

Sets up the pipeline, geometry, and bind groups then issues an indirect draw call.
Uses `drawIndexedIndirect` when the geometry has an index buffer, otherwise `drawIndirect`.
Draw parameters (vertex count, instance count, etc.) are read from the indirect buffer on the GPU.

#### Parameters

##### options

The draw options.

###### geometry

[`Geometry`](rendering.Geometry.html.md)

The geometry to draw.

###### indirectBuffer

[`GPUBuffer`](https://developer.mozilla.org/docs/Web/API/GPUBuffer)

The GPU buffer containing the indirect draw parameters.

###### indirectOffset

`number`

Byte offset into the indirect buffer.

###### shader

[`Shader`](rendering.Shader.html.md)

The shader to use.

###### skipSync?

`boolean`

If true, skips syncing uniform groups to their GPU buffers.

###### state?

[`State`](rendering.State.html.md)

Optional render state (blending, depth, etc.).

###### topology?

[`Topology`](rendering.Topology.html.md)

Optional primitive topology override.

#### Returns

`void`

***

### endBundle()

> **endBundle**(): [`RenderBundle`](rendering.RenderBundle.html.md)

Finishes recording the current render bundle and restores the previous render pass encoder.

#### Returns

[`RenderBundle`](rendering.RenderBundle.html.md)

The recorded [RenderBundle](rendering.RenderBundle.html.md), ready to be executed via [executeBundle](#executebundle) and
stamped with the pipeline state it baked so [isBundleValid](#isbundlevalid) can vet it on later frames.

***

### endRenderPass()

> **endRenderPass**(): `void`

#### Returns

`void`

***

### executeBundle()

> **executeBundle**(`bundle`): `void`

Replays previously recorded render bundles on the current render pass.
The bound state cache is cleared since a bundle may set its own pipeline, bind groups, and buffers.

Pass a whole run of bundles rather than calling this once per bundle: WebGPU resets the pass
state after every call, so N calls cost N cache clears and N trips through the binding layer
for exactly the same result.

Every bundle must have been recorded against a matching render target — check with
[isBundleValid](#isbundlevalid) first and re-record if it says no, as Pixi cannot rebuild your draw
commands for you.

#### Parameters

##### bundle

The render bundle to execute, or a run of them to execute in one call.

[`RenderBundle`](rendering.RenderBundle.html.md) | [`RenderBundle`](rendering.RenderBundle.html.md)[]

#### Returns

`void`

***

### finishRenderPass()

> **finishRenderPass**(): `void`

#### Returns

`void`

***

### isBundleValid()

> **isBundleValid**(`bundle`): `boolean`

Checks whether a recorded bundle can still be replayed against the render target that is
bound now.

A bundle permanently bakes the attachment state it was recorded with — color format(s),
color target count, depth/stencil format, sample count — and WebGPU rejects the entire
command buffer if any of it differs at execute time. It also bakes the front-face winding of
its pipelines, which WebGPU does *not* validate: once the target's [RenderTarget.flipY](rendering.RenderTarget.html#flipy)
parity changes, replaying silently renders geometry inside out.

Ask before replaying rather than after: only the caller owns the draw commands, so only the
caller can re-record. A missing bundle reports `false`, so `!isBundleValid(bundles[i])` reads
correctly on the first frame, before anything has been recorded.

#### Parameters

##### bundle

[`RenderBundle`](rendering.RenderBundle.html.md)

The bundle to check, as returned by [endBundle](#endbundle).

#### Returns

`boolean`

`true` if the bundle is safe to execute right now, `false` if it must be re-recorded.

***

### postrender()

> **postrender**(): `void`

#### Returns

`void`

***

### renderStart()

> **renderStart**(): `void`

#### Returns

`void`

***

### resetBindGroup()

> **resetBindGroup**(`index`): `void`

#### Parameters

##### index

`number`

#### Returns

`void`

***

### setBindGroup()

> **setBindGroup**(`index`, `bindGroup`, `program`): `void`

#### Parameters

##### index

`number`

##### bindGroup

[`BindGroup`](rendering.BindGroup.html.md)

##### program

[`GpuProgram`](rendering.GpuProgram.html.md)

#### Returns

`void`

***

### setGeometry()

> **setGeometry**(`geometry`, `program`): `void`

#### Parameters

##### geometry

[`Geometry`](rendering.Geometry.html.md)

##### program

[`GpuProgram`](rendering.GpuProgram.html.md)

#### Returns

`void`

***

### setPipeline()

> **setPipeline**(`pipeline`): `void`

#### Parameters

##### pipeline

[`GPURenderPipeline`](https://developer.mozilla.org/docs/Web/API/GPURenderPipeline)

#### Returns

`void`

***

### setPipelineFromGeometryProgramAndState()

> **setPipelineFromGeometryProgramAndState**(`geometry`, `program`, `state`, `topology?`, `overrides?`): `void`

#### Parameters

##### geometry

[`Geometry`](rendering.Geometry.html.md)

##### program

[`GpuProgram`](rendering.GpuProgram.html.md)

##### state

`any`

##### topology?

[`Topology`](rendering.Topology.html.md)

##### overrides?

[`ShaderOverrides`](rendering.ShaderOverrides.html.md)

#### Returns

`void`

***

### setStencilReference()

> **setStencilReference**(`stencilReference`): `void`

Sets the stencil reference value for subsequent draws. This is a pass-level command, so it
always targets the real render pass — not a bundle encoder, which cannot set stencil state.

#### Parameters

##### stencilReference

`number`

The stencil reference value to use.

#### Returns

`void`

***

### setViewport()

> **setViewport**(`viewport`): `void`

#### Parameters

##### viewport

[`Rectangle`](maths.Rectangle.html.md)

#### Returns

`void`
