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

Does compositingAlphaMode affect using the canvas as an image source? #1847

Closed
kainino0x opened this issue Jun 16, 2021 · 10 comments · Fixed by #2905
Closed

Does compositingAlphaMode affect using the canvas as an image source? #1847

kainino0x opened this issue Jun 16, 2021 · 10 comments · Fixed by #2905
Projects
Milestone

Comments

@kainino0x
Copy link
Contributor

kainino0x commented Jun 16, 2021

In #1839 we spec the behavior of reading from WebGPU canvases from other APIs, but we need to clarify whether compositingAlphaMode affects those.

  1. If compositingAlphaMode is "opaque" does that mean e.g. drawImage reads opaque values?
  2. If we add compositingAlphaMode "unpremultiplied" would that mean e.g. texImage2D sees it as an unpremultiplied source?

My initial feeling is that the answers to both should be yes. In that case we should also probably rename compositingAlphaMode to something like canvasAlphaMode.

@kainino0x kainino0x changed the title Does compositingAlphaMode affect Does compositingAlphaMode affect using the canvas as an image source? Jun 16, 2021
@kainino0x
Copy link
Contributor Author

Actually I'm not sure which makes more sense.

  1. Reading opaque values seems unnecessary, and may cause complications for implementations which only do premultiply/unpremultiply conversions now, and not "opaquification" conversions.
  2. I think the answer to this would need to be yes, though it only matters if we actually add that mode (which we are hoping not to do). Still, the possibility may warrant changing this from compositingAlphaMode to canvasOutputAlphaMode or something.

@kainino0x kainino0x added this to the MVP milestone Jun 22, 2021
@kainino0x kainino0x added this to Needs Discussion in Main Jun 22, 2021
@kainino0x
Copy link
Contributor Author

Or two separate flags, compositeAsOpaque (which doesn't affect using it as an image source) and alphaPremultiplied (which affects both compositing and using it as an image source).

@kainino0x
Copy link
Contributor Author

Another side note: recent additions to the spec mean that webgpu canvases can't be both composited and used as image sources at the same time. So on macOS, where we have to clear the alpha channel to get the "opaque" compositing behavior, we do have the opportunity to do so without affecting drawImage et al.)

@kainino0x
Copy link
Contributor Author

kainino0x commented Aug 9, 2021

Meeting update: This should be blocked on #1988

@kainino0x kainino0x added the tacit resolution candidate Editors may be able to resolve and move to tacit resolution queue label Jan 13, 2022
@Kangz
Copy link
Contributor

Kangz commented Mar 21, 2022

#1988 is post-V1. What is the tacit resolution candidate for this?

@kainino0x
Copy link
Contributor Author

kainino0x commented Mar 21, 2022

We don't have a proposal yet, I just put that label to indicate that editors should discuss and look for a solution we can propose. Specifically, I want to attempt to unblock this on #1988, just define the behavior and keep the API open for future improvements.

@kainino0x
Copy link
Contributor Author

More specifically, the spec actually says you can't use already-composited results as an image source:

and we need to make sure that's OK because I'm pretty sure it resolves this issue.

@kainino0x
Copy link
Contributor Author

If we add a way to read back the "display buffer" (presented image), then compositingAlphaMode would need to affect the result of that readback (on all platforms for consistency) because some platforms have to clear the alpha channel to 1.0 for presentation.
#2743 (comment)

@shaoboyan
Copy link
Contributor

I think we have conclusion in this issue that we don't apply compositingAlphaMode to the drawing buffer content. Can we close this issue?

@kainino0x
Copy link
Contributor Author

It's not concluded yet because I need to make a proposal for #2743. I think the solution there is going to necessitate compositingAlphaMode affecting drawImage/toDataURL/etc.

kainino0x added a commit to kainino0x/gpuweb that referenced this issue May 17, 2022
Changes compositingAlphaMode to just alphaMode, because it now affects
the canvas as an image source (drawImage/toDataURL/etc.) as well as
compositing.

Fixes gpuweb#2743
Fixes gpuweb#1847
Fixes a leftover bit from gpuweb#2373 (placeholder canvases)
kainino0x added a commit to kainino0x/gpuweb that referenced this issue May 17, 2022
Changes compositingAlphaMode to just alphaMode, because it now affects
the canvas as an image source (drawImage/toDataURL/etc.) as well as
compositing.

Fixes gpuweb#2743
Fixes gpuweb#1847
Fixes a leftover bit from gpuweb#2373 (placeholder canvases)
kainino0x added a commit to kainino0x/gpuweb that referenced this issue May 18, 2022
Changes compositingAlphaMode to just alphaMode, because it now affects
the canvas as an image source (drawImage/toDataURL/etc.) as well as
compositing.

Fixes gpuweb#2743
Fixes gpuweb#1847
Fixes a leftover bit from gpuweb#2373 (placeholder canvases)
kainino0x added a commit to kainino0x/gpuweb that referenced this issue May 18, 2022
This allows drawImage/toDataURL/etc. to see the canvas contents
presented in the previous frame, as long as getCurrentTexture (or
configure/unconfigure) hasn't been called yet this frame.

alphaMode (née compositingAlphaMode) now affects using the canvas as an
image source (drawImage/etc.) as well as compositing, so that the
observed contents don't change on a frame boundary.

As a weird aside (necessary to fully define the image source behavior),
defines super-luminant values as being in the extended color space (i.e.
once un-premultiplied). This definition emerges naturally, but it's also
weird.

Fixes gpuweb#2743
Fixes gpuweb#1847
Fixes a leftover bit from gpuweb#2373 (placeholder canvases)
kainino0x added a commit that referenced this issue May 26, 2022
* Allow reading back from canvases after present

This allows drawImage/toDataURL/etc. to see the canvas contents
presented in the previous frame, as long as getCurrentTexture (or
configure/unconfigure) hasn't been called yet this frame.

alphaMode (née compositingAlphaMode) now affects using the canvas as an
image source (drawImage/etc.) as well as compositing, so that the
observed contents don't change on a frame boundary.

As a weird aside (necessary to fully define the image source behavior),
defines super-luminant values as being in the extended color space (i.e.
once un-premultiplied). This definition emerges naturally, but it's also
weird.

Fixes #2743
Fixes #1847
Fixes a leftover bit from #2373 (placeholder canvases)

* nit

* Remove the "cancel present" behavior of destroy()

This fixes several problems:
- Unnecessary complexity in how currentTexture logic works.
- Errors in the previous commit, where this was just not fully handled.
- Using the "destroyed" state on the content process (minor issue).

* nits

* nit
@kainino0x kainino0x removed the tacit resolution candidate Editors may be able to resolve and move to tacit resolution queue label Jun 13, 2022
jdarpinian pushed a commit to jdarpinian/gpuweb that referenced this issue Aug 12, 2022
* Allow reading back from canvases after present

This allows drawImage/toDataURL/etc. to see the canvas contents
presented in the previous frame, as long as getCurrentTexture (or
configure/unconfigure) hasn't been called yet this frame.

alphaMode (née compositingAlphaMode) now affects using the canvas as an
image source (drawImage/etc.) as well as compositing, so that the
observed contents don't change on a frame boundary.

As a weird aside (necessary to fully define the image source behavior),
defines super-luminant values as being in the extended color space (i.e.
once un-premultiplied). This definition emerges naturally, but it's also
weird.

Fixes gpuweb#2743
Fixes gpuweb#1847
Fixes a leftover bit from gpuweb#2373 (placeholder canvases)

* nit

* Remove the "cancel present" behavior of destroy()

This fixes several problems:
- Unnecessary complexity in how currentTexture logic works.
- Errors in the previous commit, where this was just not fully handled.
- Using the "destroyed" state on the content process (minor issue).

* nits

* nit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Main
Needs Discussion
Development

Successfully merging a pull request may close this issue.

3 participants