Skip to content

Conversation

@kainino0x
Copy link
Contributor

@kainino0x kainino0x commented Mar 31, 2021

Realized I already had this sketched out on a local branch, should have pushed it up earlier.

This does not solve #1483 yet.

With bonus minor copyediting, because I can't help myself. Needs a bit more work later though.

Fixes #1154


Preview | Diff

@kainino0x kainino0x marked this pull request as draft March 31, 2021 00:42
@kainino0x
Copy link
Contributor Author

kainino0x commented Mar 31, 2021

oops, meant to open as draft (not done yet)

@kainino0x kainino0x force-pushed the copyToTexture branch 4 times, most recently from 9d8d43f to b439eeb Compare March 31, 2021 01:46
@kainino0x kainino0x requested review from Kangz, kvark and shaoboyan March 31, 2021 01:52
@kainino0x kainino0x marked this pull request as ready for review March 31, 2021 01:52
@kainino0x
Copy link
Contributor Author

Lots of open issues, but PTAL

Copy link
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.

LGTM, minus the naming

@kainino0x kainino0x changed the title copyToTexture for VideoElement and canvases copyExternalImageToTexture for VideoElement and canvases Apr 5, 2021
@kainino0x
Copy link
Contributor Author

Renamed to copyExternalImageToTexture to make this more specific.

Copy link
Member

@kenrussell kenrussell left a comment

Choose a reason for hiding this comment

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

Looks good to me! Will be good to move forward with this so that conformance tests and implementations can follow. A few small comments.

ImageBitmap, canvas, and VideoElement are all color-managed: they encode colors.
GPUTexture is not color-managed: it encodes raw numbers. Producing raw numbers requires knowing
the target encoding. Probably there should be a particular default value (e.g. the default profile
used by the browser for unmanaged content?), but eventually we'll want to add knobs.
Copy link
Member

Choose a reason for hiding this comment

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

Per recent updates to:
https://github.com/WICG/canvas-color-space/blob/main/CanvasColorSpaceProposal.md

specifically:
WICG/canvas-color-space#54

which was WebGL-specific, it might be possible to define this behavior for WebGPU from the colorSpace configured on the GPUSwapChain. Specifically:

  • The destination color space for uploads of HTMLCanvasElement and HTMLVideoElement is the colorSpace configured on the GPUSwapChain.
  • No conversion is performed for ImageBitmap, since those are intended to be configured properly at their creation time via ImageBitmapOptions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  • The destination color space for uploads of HTMLCanvasElement and HTMLVideoElement is the colorSpace configured on the GPUSwapChain.

Unfortunately we can't pick a default from the swap chain because there could be 0 or >1 swap chains for a GPUDevice.

Copy link
Member

Choose a reason for hiding this comment

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

I see.

In that case it seems to me that we might not need to have any controls in this copying path.

  • For HTMLVideoElement it's always desired to do the browser's default color space conversion.
  • For canvases and offscreen canvases, the source canvas's context provides enough control over the color space. The copy to a GPUTexture can be a passthrough with no color space conversion.
  • For ImageBitmap, the creation-time options provide the controls needed - and these are being enhanced in the CanvasColorSpaceProposal.

@kainino0x kainino0x changed the title copyExternalImageToTexture for VideoElement and canvases copyExternalImageToTexture for ~VideoElement and~ canvases Apr 20, 2021
@kainino0x kainino0x changed the title copyExternalImageToTexture for ~VideoElement and~ canvases copyExternalImageToTexture for ImageBitmap and canvases Apr 20, 2021
@kainino0x
Copy link
Contributor Author

Per the editors' discussion, I have removed the video overload from this PR. I've split it into the (dependent) PR #1647

- |copySize|.[=Extent3D/depthOrArrayLayers=] must be `1`.
- |destination|.{{GPUImageCopyTexture/texture}}.{{GPUTexture/[[textureUsage]]}}
must include both {{GPUTextureUsage/RENDER_ATTACHMENT}} and
{{GPUTextureUsage/COPY_DST}}.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note: We originally added RENDER_ATTACHMENT with video in mind, but I think it's still necessary without, because there is still a possible format conversion in this call (e.g. from rgba8unorm to rg16float, or from rgba16float to rgb10a2unorm).

@github-actions
Copy link
Contributor

Previews, as seen when this build job started (4d60238):
WebGPU | IDL
WGSL
Explainer

@github-actions
Copy link
Contributor

Previews, as seen when this build job started (0d16f1f):
WebGPU | IDL
WGSL
Explainer

@kainino0x kainino0x enabled auto-merge (squash) April 27, 2021 00:17
@github-actions
Copy link
Contributor

Previews, as seen when this build job started (d580abe):
WebGPU | IDL
WGSL
Explainer

@kainino0x kainino0x merged commit dcda8fe into gpuweb:main Apr 27, 2021
@kainino0x kainino0x deleted the copyToTexture branch April 27, 2021 00:18
@github-actions
Copy link
Contributor

Previews, as seen when this build job started (023b579):
WebGPU | IDL
WGSL
Explainer

@kainino0x
Copy link
Contributor Author

Editors meeting: decided to land this as it's the direction we agreed upon in the VF2F, and there are no surprises here, only details (like that it requires COPY_DST and RENDER_ATTACHMENT).

ben-clayton pushed a commit to ben-clayton/gpuweb that referenced this pull request Sep 6, 2022
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.

Proposal for importing Web platform images in WebGPU

5 participants