Skip to content

Add clear support for integer format color attachments - #9143

Merged
mvaligursky merged 2 commits into
mainfrom
mv-int-clear
Jul 31, 2026
Merged

Add clear support for integer format color attachments#9143
mvaligursky merged 2 commits into
mainfrom
mv-int-clear

Conversation

@mvaligursky

Copy link
Copy Markdown
Contributor

Allows render passes to clear integer format color attachments. Previously this was not supported - on WebGL, gl.clear has undefined results on integer buffers, which is also the reason the Picker encodes ids into an RGBA8 texture instead of using a uint32 format. For integer formats, the components of the clear color are the raw integer values.

Changes:

  • On WebGL, integer format color attachments are cleared using clearBufferiv / clearBufferuiv, matching the format class of each attachment. A single integer attachment uses this path as well, as it cannot be cleared by gl.clear.
  • On WebGPU, which supports this natively, a debug-time validation was added, reporting an engine error when the clear color components of an integer attachment are not integers (or are negative for unsigned formats), instead of a WebGPU validation failure.

Examples:

  • The hidden test/independent-blending example gained an indicator panel - an R32U render target is cleared to a marker value by a clear-only render pass, and the panel samples it, showing green when it contains the expected value.

Part of #5356. This also unblocks migrating the Picker to a uint32 format, which additionally needs uint fragment outputs for the pick shader variants.

@github-actions

github-actions Bot commented Jul 30, 2026

Copy link
Copy Markdown

Build size report

This PR changes the size of the minified bundles.

Bundle Minified Gzip Brotli
playcanvas.min.js 2357.2 KB (+1.9 KB, +0.08%) 605.1 KB (+0.2 KB, +0.04%) 469.8 KB (+0.1 KB, +0.02%)
playcanvas.min.mjs 2354.6 KB (+1.9 KB, +0.08%) 604.2 KB (+0.3 KB, +0.05%) 469.3 KB (+0.0 KB, +0.00%)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Enables render-pass clears for integer-format color attachments across WebGL and WebGPU, aligning behavior with backend capabilities and adding an example-based verification path.

Changes:

  • WebGL: clears integer color attachments using gl.clearBufferiv / gl.clearBufferuiv per attachment (and for single integer attachments too).
  • WebGPU: adds debug-time validation to prevent non-integer (and negative-for-unsigned) clear values from triggering WebGPU validation errors.
  • Example: extends test/independent-blending with an R32U clear-and-sample indicator panel.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/platform/graphics/webgpu/webgpu-render-target.js Adds debug-only clear-value validation for integer-format attachments on WebGPU render passes.
src/platform/graphics/webgl/webgl-graphics-device.js Routes integer attachment clears through the appropriate clearBuffer* API, including single-attachment integer RTs.
examples/src/examples/test/independent-blending.example.mjs Adds an R32U render target clear + indicator panel to verify integer clear support.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/platform/graphics/webgl/webgl-graphics-device.js
@mvaligursky mvaligursky added the area: graphics Graphics related issue label Jul 31, 2026
@mvaligursky
mvaligursky merged commit e2788a9 into main Jul 31, 2026
10 checks passed
@mvaligursky
mvaligursky deleted the mv-int-clear branch July 31, 2026 09:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: graphics Graphics related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants