Skip to content

copyExternalImageToTexture: add validation, make validation async - #1737

Merged
kainino0x merged 10 commits into
gpuweb:mainfrom
kainino0x:copy-validation-async
Jul 26, 2021
Merged

kainino0x merged 10 commits into
gpuweb:mainfrom
kainino0x:copy-validation-async

Conversation

@kainino0x

@kainino0x kainino0x commented May 17, 2021 •

Copy link
Copy Markdown
Contributor

@kainino0x
kainino0x requested review from kvark, shaoboyan and toji May 17, 2021 23:24
Comment thread spec/index.bs Resolved
@kainino0x kainino0x changed the title Make copyExternalImageToTexture destination validation async Make copyExternalImageToTexture destination validation async, remove float formats for now May 18, 2021
Comment thread spec/index.bs Outdated
Issue: The above list was written just for ImageBitmap.
Re-evaluate it for canvas (and video).
(It's probably still fine, though `rgb10a2unorm` is a bit of an outlier.)
1. If |sourceImage| is an {{ImageBitmap}} and

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.

Is there the same validation requirements for OffscreenCanvas?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, OffscreenCanvas should be detachable as well but it doesn't seem to be detachable in the same way as a "platform object". I found this which I guess we can simply call into:
https://html.spec.whatwg.org/multipage/canvas.html#check-the-usability-of-the-image-argument
(and if that's missing checks for detachedness, that should be fixed upstream)

Notably, using that algorithm means that using zero-sized HTMLCanvasElement/OffscreenCanvas becomes an error (even if the copy size is zero). I guess we should adopt that since it's consistent with other usages.

If image has either a horizontal dimension or a vertical dimension equal to zero, then throw an "InvalidStateError" DOMException.

@kainino0x kainino0x changed the title Make copyExternalImageToTexture destination validation async, remove float formats for now copyExternalImageToTexture: add validation, make validation async, remove float formats for now May 18, 2021
@kainino0x
kainino0x force-pushed the copy-validation-async branch from e518964 to a10785c Compare May 18, 2021 03:12
Comment thread spec/index.bs Resolved
Comment thread spec/index.bs
- |source|.|origin|.[=Origin3D/y=] + |copySize|.[=Extent3D/height=]
must be ≤ the height of |sourceImage|.
- |source|.|origin|.[=Origin3D/z=] + |copySize|.[=Extent3D/depthOrArrayLayers=]
must be ≤ 1.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's the rational for allowing a depth of 0? That's a departure from the validation logic this is replacing. Also, this implicitly prevents copying to texture array layers other than the 0th layer, which I'm not sure is intended?

Seems like the desired logic may be something along the lines of simply:

- |copySize|.[=Extent3D/depthOrArrayLayers=] must be 1;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This only prevents copying from layers other than the 0th (the source image is 2d so always has only one layer).

This behavior is more consistent with copyTextureToTexture: it validates the same as a copy from a 2d texture with one layer.

Comment thread spec/index.bs Outdated
1. Let |sourceImage| be |source|.{{GPUImageCopyExternalImage/source}}
1. Run [=Check the usability of the image argument=](|sourceImage|).
If it throws an exception, stop.
If it does not return `good`, throw an {{InvalidStateException}} and stop.

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.

I'm not sure this will cover the case below:
During the CopyExternalImageToTexture/ImportToTexture call, it might possible we hit some browser internal error which cause the externalImage content is invalid.
If not, then I think we need to define a behaviour on this case.
Fail silently is one option. (Not good, but webgl and canvas impl in chromium works like this)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Honestly I don't know what we are supposed to do here. Ideally specs shouldn't need to say what to do if some unspecified problem occurred inside the browser. Hopefully those unspecified problems fall into the following buckets:

  • Resource was lost due to gpu process loss. In this case the device is lost, too so it doesn't matter.
  • Resource is in an "invalid" state because it hasn't been initialized or is in some other state that means, per-spec, it would be a blank image. In those cases we make sure the implementation copies from a blank image.

shaoboyan added a commit to shaoboyan/cts that referenced this pull request May 27, 2021
Update copyImageBitmapToTexture validation rules based on the new
CL (gpuweb/gpuweb#1737)
Comment thread spec/index.bs Resolved
kainino0x pushed a commit to gpuweb/cts that referenced this pull request Jun 1, 2021
* Update validation tests of copyImageBitmapToTexture

Update copyImageBitmapToTexture validation rules based on the new
CL (gpuweb/gpuweb#1737)

* Remove float texture format support for operation tests

* Clean up kValidTextureFormatsForCopyIB2T

* `as readonly string[]`
@kainino0x
kainino0x force-pushed the copy-validation-async branch from 8f94225 to 34b571c Compare July 19, 2021 23:15
@kainino0x kainino0x changed the title copyExternalImageToTexture: add validation, make validation async, remove float formats for now copyExternalImageToTexture: add validation, make validation async Jul 19, 2021
@kainino0x

Copy link
Copy Markdown
Contributor Author

Fixed the function call thing, and refreshed the PR to resolve merge conflicts.

@kainino0x
kainino0x merged commit 95ed421 into gpuweb:main Jul 26, 2021
@kainino0x
kainino0x deleted the copy-validation-async branch July 26, 2021 21:06
github-actions Bot added a commit that referenced this pull request Jul 26, 2021
)

SHA: 95ed421
Reason: push, by @kainino0x

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions Bot added a commit that referenced this pull request Jul 26, 2021
)

SHA: 95ed421
Reason: push, by @kainino0x

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
github-actions Bot added a commit that referenced this pull request Jul 26, 2021
)

SHA: 95ed421
Reason: push, by @kainino0x

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

5 participants