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

Allow out-of-standard-gamut colors with float canvases #4526

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

kainino0x
Copy link
Contributor

@kainino0x kainino0x commented Mar 19, 2024

The spec previously said that it was undefined behavior to display "out-of-gamut premultiplied RGBA values" (R/G/B > A).

But that definition overlooked some cases. We intended to allow using an rgba16float srgb canvas to display wider-than-srgb colors, but such colors would according to the current definition be "out-of-gamut premultiplied RGBA values" (regardless of whether they're opaque like [1.04, 0, 0, 1] or transparent like [0.52, 0, 0, 0.5]).

This replaces that concept with "out-of-range premultiplied RGBA values", which is when the unpremultiplied equivalent of the color can't be represented in the format used for the color (e.g. premul [0.52, 0, 0, 0.5] in rgba8unorm). I've written it this way because I think it will be valid for #4108 as well if we ever get that [EDIT: fixed link to point to correct issue]. The idea is that as long as the implementation doesn't use any intermediate format that's worse than the canvas format (in either range or precision), the color will be preserved.

@kainino0x
Copy link
Contributor Author

@ccameron-chromium does this seem right?

Copy link
Contributor

github-actions bot commented Mar 19, 2024

Previews, as seen when this build job started (7cf11da):
WebGPU webgpu.idl | Explainer | Correspondence Reference
WGSL grammar.js | wgsl.lalr.txt

@kainino0x

This comment was marked as outdated.

@kainino0x kainino0x changed the title Allow out-of-gamut premultiplied values with float canvases Allow out-of-standard-gamut colors with float canvases Mar 19, 2024
@kainino0x kainino0x force-pushed the out-of-gamut-sometimes-valid branch from e8ba5f4 to e7c33a8 Compare March 19, 2024 21:09
@kainino0x kainino0x force-pushed the out-of-gamut-sometimes-valid branch from e7c33a8 to d706a20 Compare March 19, 2024 22:03
<!-- POSTV1(#4108): add example for XR formats, which *probably* handle this -->
</table>

Visible results may be undefined because the value could be lost at different steps of display:
Copy link
Contributor Author

@kainino0x kainino0x Mar 19, 2024

Choose a reason for hiding this comment

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

I wanted to write out an example of the actual blending math, but that ends up demonstrating a completely different problem, which is that you get very different results doing nonlinear blending in display color space (e.g. in display-p3), vs in srgb.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it gets complicated.

@kainino0x
Copy link
Contributor Author

kainino0x commented Mar 19, 2024

Copy link
Contributor

@ccameron-chromium ccameron-chromium left a comment

Choose a reason for hiding this comment

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

This behavior seems fine. I'm a bit surprised that we're not allowing this even for rgba16float canvases (since I think that's pretty safe, and we are allowing such canvases to go out of gamut).

<!-- POSTV1(#4108): add example for XR formats, which *probably* handle this -->
</table>

Visible results may be undefined because the value could be lost at different steps of display:
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, it gets complicated.

regardless of the canvas's {{GPUCanvasConfiguration/format}}.

However, when a ({{GPUCanvasAlphaMode/"premultiplied"}}) canvas containing such a value is
displayed *on screen*, the visible result for the entire canvas is undefined.
Copy link
Contributor

Choose a reason for hiding this comment

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

Checking that I understand.

Consider a canvas that is premultiplied, rgba16float, srgb being displayed on a P3 monitor.

If the value [0.52, 0, 0, 0.5] is written to the canvas, and the canvas is displayed, then the result is undefined even though it's within the gamut of the display, because of various machinations that might happen throughout the display pipeline.

This seems reasonable to me. Would the idea be to make this valid when in extended mode?

@kainino0x kainino0x added the needs-cts-issue This change requires tests (or would need tests if accepted), but may not have a CTS issue filed yet label Apr 27, 2024
@kainino0x kainino0x added the api WebGPU API label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api WebGPU API needs-cts-issue This change requires tests (or would need tests if accepted), but may not have a CTS issue filed yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants