Skip to content

Add GPUSwapChainAlphaMode = opaque/premultiplied#1474

Merged
kvark merged 4 commits intogpuweb:mainfrom
kdashg:swapchain-blend
Apr 16, 2021
Merged

Add GPUSwapChainAlphaMode = opaque/premultiplied#1474
kvark merged 4 commits intogpuweb:mainfrom
kdashg:swapchain-blend

Conversation

@kdashg
Copy link
Copy Markdown
Contributor

@kdashg kdashg commented Feb 26, 2021

Closes #1425.


Preview | Diff

@kdashg
Copy link
Copy Markdown
Contributor Author

kdashg commented Feb 26, 2021

These aren't necessarily as efficiently implementable everywhere as we would like today, but I think this might be the API we would want to offer eventually. It can be efficiently supported on some platforms, at least. I think @kvark was taking a census on this?

@kdashg
Copy link
Copy Markdown
Contributor Author

kdashg commented Feb 26, 2021

Worth noting is that Windows has an API for this:
https://docs.microsoft.com/en-us/windows/win32/api/dxgi1_2/ne-dxgi1_2-dxgi_alpha_mode

Apple does not, and expects premultiplied rgba. You can specify isOpaque:true iff you can promise your content is fully opaque already. (that is, all a values are 1.0)

Copy link
Copy Markdown
Contributor

@kvark kvark left a comment

Choose a reason for hiding this comment

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

I like the general direction!
I started a table for investigating this but need more help finishing it up.

</thead>
<tr>
<td>{{GPUSwapChainAlphaMode/opaque}}
<td>Paint RGB as opaque and ignore alpha values.
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.

We need to figure out how to describe or implement it consistently. If on one platform we have to clear alpha to 1 at the end of the pass, and on others we don't then an application that reads back the swapchain will see the difference.

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.

We (kvark/jdashg/I) discussed this and agreed that it wouldn't be possible to do this on a pass. It has to occur after user code loses access to the texture (after the end of the frame), so it would have to be a separate pass.

@kdashg
Copy link
Copy Markdown
Contributor Author

kdashg commented Mar 1, 2021

There are some concerns that nonPremultiplied is not worth implementing just yet, at least not with the same priority as premultiplied and opaque.

Add note that `opaque` may incur some overhead.
@kdashg
Copy link
Copy Markdown
Contributor Author

kdashg commented Mar 22, 2021

@kenrussell @RafaelCintron @litherum PTAL

@github-actions
Copy link
Copy Markdown
Contributor

Previews, as seen at the time of posting this comment:
WebGPU | IDL
WGSL
4697d0f

Copy link
Copy Markdown
Contributor

@kainino0x kainino0x left a comment

Choose a reason for hiding this comment

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

This API surface LGTM [for the current proposal], but I left a comment on #1425 (comment)

spec/index.bs Outdated
required GPUDevice device;
required GPUTextureFormat format;
GPUTextureUsageFlags usage = 0x10; // GPUTextureUsage.RENDER_ATTACHMENT
GPUSwapChainAlphaMode alphaMode = "opaque";
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.

nit: should we call this a "composition mode" or something since it doesn't affect alpha as seen on the WebGPU side?

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.

@jdashg please rename this to GPUCompositeAlphaMode before landing

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.

And rename the dictionary member to compositeAlphaMode (or something along those lines) as well.

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.

Updated to GPUCanvasCompositingAlphaMode and compositingAlphaMode. Decided not to use "composite" because in this position it looks like we're using it as an adjective.

@Kangz
Copy link
Copy Markdown
Contributor

Kangz commented Apr 9, 2021

Are any changes needed before we land this?

@kenrussell
Copy link
Copy Markdown
Member

Are any changes needed before we land this?

The description needs to be revised during commit, but aside from that the PR looks fine to me.

@kvark kvark changed the title Add GPUSwapChainAlphaMode = opaque/premultiplied/non-premultiplied. Add GPUSwapChainAlphaMode = opaque/premultiplied Apr 12, 2021
@kvark kvark merged commit c2bf7a9 into gpuweb:main Apr 16, 2021
ben-clayton pushed a commit to ben-clayton/gpuweb that referenced this pull request Sep 6, 2022
…gpuweb#1474)

* Change importExternalTexture,destroy to importExternalTexutre,expired

The lifecycle of GPUExternalTexture changes from single js microtask to
align with video frame from imported HTMLVideoElement.
GPUExternalTexture.expired should changes from false to true when latest
video frame from HTMLVideoElement is updated.

fixed:gpuweb#1473

* Address comments
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.

Can WebGPU canvas alpha be configured?

5 participants