Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webgl: Support colorMask in RenderPass #2046

Merged
merged 3 commits into from
Mar 21, 2024
Merged

webgl: Support colorMask in RenderPass #2046

merged 3 commits into from
Mar 21, 2024

Conversation

felixpalmer
Copy link
Collaborator

For visgl/deck.gl#8636

When a WebGLRenderPass is created it immediately does a clear(). deck.gl was previously setting a colorMask using withParametersWebGL, but now with this removed there is no way to set the colorMask before the clear operation. Doing it in Pass.getLayerParameters() is too late, as by then the clear operation has happened

Background

Change List

  • Support colorMask in RenderPass

@@ -180,6 +180,9 @@ export type RenderPassParameters = {
blendConstant?: number[]; // GPUColor
/** Stencil operation "replace" sets the value to stencilReference */
stencilReference?: number; // GPUStencilValue

/** Sets mask for channels (RGBA) to render/clear **/
colorMask?: boolean[];
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: if we require exactly four channel masks, lets make that explicit —

Suggested change
colorMask?: boolean[];
colorMask?: [boolean, boolean, boolean, boolean];

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Discussing with @Pessimistress we need to think of a way to make this WebGPU compatible. It may make more sense to pass writeMask instead

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hm, there's also the RenderPipeline parameter, colorMask, which is a bit mask:

/** Bitmask controlling which channels are are written to when drawing to this color target. defaulting to 0xF */
colorMask?: number;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, I missed that! I still think it's worth moving to RenderPassParameters

@Pessimistress
Copy link
Collaborator

Defer to @ibgreen - is the WebGPU name writeMask preferred?

Copy link
Collaborator

@ibgreen ibgreen left a comment

Choose a reason for hiding this comment

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

FWIW

I believe clear colors in WebGPU are set per target (attachment) not as part of the props.

For now, I don't think I exposed that full API.

Why can't we set it before we call gl.clear?

@Pessimistress
Copy link
Collaborator

Why can't we set it before we call gl.clear?

We are trying to avoid using setParametersWebGL.

@felixpalmer
Copy link
Collaborator Author

OK, so it seems this change is OK, but we should change it to be a bitmask to align with the WebGPU API before merging

@felixpalmer felixpalmer merged commit 79fd850 into master Mar 21, 2024
2 checks passed
@felixpalmer felixpalmer deleted the felix/color-mask branch March 21, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants