Skip to content

Commit

Permalink
Make copyImageBitmapToTexture a GPUQueue operation. (gpuweb#488)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kangz authored Nov 11, 2019
1 parent 53bf767 commit e597343
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
10 changes: 6 additions & 4 deletions design/ImageBitmapToTexture.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ dictionary GPUImageBitmapCopyView {
GPUOrigin2D origin;
};
partial interface GPUCommandEncoder {
partial interface GPUQueue {
void copyImageBitmapToTexture(
GPUImageBitmapCopyView source,
GPUTextureCopyView destination,
Expand All @@ -15,14 +15,16 @@ partial interface GPUCommandEncoder {
};
```

`copyImageBitmapToTexture` encodes a copy from a source sub-rectangle of an `ImageBitmap` into a destination sub-resource of a `GPUTexture`.
When the command buffer is submitted, the `ImageBitmap` must not be detached.
If it is, a validation error is generated.
`copyImageBitmapToTexture` submits a copy from a source sub-rectangle of an `ImageBitmap` into a destination sub-resource of a `GPUTexture`.
The `ImageBitmap` must not be detached, if it is, a validation error is generated.

## Alternatives Considered

* Creating a `GPUTexture` directly from an `ImageBitmap`, attempting to avoid copies, is impractical because it requires the GPUTexture's format to match the internal representation of the `ImageBitmap`, which is not exposed to the Web platform.
Additionally, `ImageBitmap`s may be GPU- or CPU-backed, and wrapping a CPU-backed `ImageBitmap` is a significant meta-operation that requires an additional copy to be submitted.
* Having `copyImageBitmapToTexture` on `GPUCommandEncoder`: this makes implementations much more complicated because they can't know when the copy will be effectively submitted.
It also allows having multiple `copyImageBitmapToTexture` at different sports in the `GPUCommandEncoder` which would require splicing the encoder and keeping track of all the chunks.
Realistically, copying `ImageBitmap`s will be during loading to copy from `<img>` elements, or at most a couple times per frame for example to copy a camera frame, so an immediate copy is fine.

## Issues

Expand Down
16 changes: 8 additions & 8 deletions spec/index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -1596,11 +1596,6 @@ interface GPUCommandEncoder {
GPUTextureCopyView destination,
GPUExtent3D copySize);

void copyImageBitmapToTexture(
GPUImageBitmapCopyView source,
GPUTextureCopyView destination,
GPUExtent3D copySize);

void pushDebugGroup(DOMString groupLabel);
void popDebugGroup();
void insertDebugMarker(DOMString markerLabel);
Expand All @@ -1610,9 +1605,6 @@ interface GPUCommandEncoder {
GPUCommandEncoder includes GPUObjectBase;
</script>

* {{GPUCommandEncoder/copyImageBitmapToTexture()}}:
* For now, `copySize.z` must be `1`.

### Creation ### {#command-encoder-creation}

<script type=idl>
Expand Down Expand Up @@ -1854,10 +1846,18 @@ interface GPUQueue {

GPUFence createFence(optional GPUFenceDescriptor descriptor = {});
void signal(GPUFence fence, unsigned long long signalValue);

void copyImageBitmapToTexture(
GPUImageBitmapCopyView source,
GPUTextureCopyView destination,
GPUExtent3D copySize);
};
GPUQueue includes GPUObjectBase;
</script>

- {{GPUQueue/copyImageBitmapToTexture()}}:
- For now, `copySize.z` must be `1`.

{{GPUQueue/submit(commandBuffers)}} does nothing and produces an error if any of the following is true:

- Any {{GPUBuffer}} referenced in any element of `commandBuffers` isn't in the `"unmapped"` [=buffer state=].
Expand Down

0 comments on commit e597343

Please sign in to comment.