Skip to content

Define intrinsic size / natural dimensions of WebGPU canvases - #2300

Closed
kainino0x wants to merge 2 commits into
gpuweb:mainfrom
kainino0x:intrinsic-size
Closed

kainino0x wants to merge 2 commits into
gpuweb:mainfrom
kainino0x:intrinsic-size

Conversation

@kainino0x

@kainino0x kainino0x commented Nov 13, 2021 •

Copy link
Copy Markdown
Contributor

This is in draft

...while I figure out whether having differing intrinsic size and natural dimensions as defined here makes sense.

This slightly refactors the state of GPUCanvasContext and makes a bunch
of small editorial changes in related areas.

Note the changes in GPUCanvasContext.configure which move all of the
error handling back to the content timeline (instead of the device
timeline). This is because it was previously attempted to early-return
from the device timeline and expected it to terminate the content
timeline steps, which isn't possible.


Preview | Diff

This slightly refactors the state of GPUCanvasContext and makes a bunch
of small editorial changes in related areas.

Note the changes in GPUCanvasContext.configure which move all of the
error handling back to the content timeline (instead of the device
timeline). This is because it was previously attempted to early-return
from the device timeline and expected it to terminate the content
timeline steps, which isn't possible.
@github-actions

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
Contributor

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

Comment thread spec/index.bs
{{GPUCanvasContext}} has the following internal slots:

<dl dfn-type=attribute dfn-for="GPUCanvasContext">
: <dfn>\[[validConfiguration]]</dfn> of type boolean, initially `false`.

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.

The validConfiguration flag was tracked separately from the configuration itself because at the time we did the refactor to fold the swap chain into the context I recall us making the decision that as long as configure() had been called (and a device had been supplied) you would always get a texture out of getCurrentTexture(), even if it was an invalid one. That normalizes this with how createTexture() works, where something like an invalid size would give back an invalid texture in both cases.

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.

I see, I had forgotten this. Given that getCurrentTexture() can still throw exceptions (if the context entirely unconfigured), I'm not sure how helpful this is?

It would especially make sense for getCurrentTexture() to throw if configure() also threw, see [1]. Seems to me to be consistent we should either:

  1. Have configure() unconditionally set the configuration even if it doesn't make sense, and validate asynchronously. If configured incorrectly, return invalid textures from getCurrentTexture().
  2. Have configure() validate synchronously and on failure either:
    a. Leave the old configuration in place (if any) so getCurrentTexture() keeps working as it did.
    b. Leave the canvas unconfigured so getCurrentTexture() now throws.

Right now the spec is in an "impossible" in-between state where I think it requires a content-gpu-content round-trip unless the configuration state could somehow move to the gpu process (I don't think it can).

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.

Have configure() unconditionally set the configuration even if it doesn't make sense, and validate asynchronously. If configured incorrectly, return invalid textures from getCurrentTexture().

I suppose since device is a required member of GPUCanvasConfiguration this makes sense. The IDL validation will throw if they don't provide a device, so it satisfies the logic of "if configure() threw getCurrentTexture() will throw. For everything else we'll be guaranteed to have a device, even if it's a destroyed/invalid one, so we can raise validation errors and create invalid textures.

Comment thread spec/index.bs
1. Generate a {{GPUValidationError}} in the current scope of |device| with an appropriate error message.
1. Return.

Issue: Just throw an exception instead?

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.

[1]

Comment thread spec/index.bs
{{GPUCanvasContext}} has the following internal slots:

<dl dfn-type=attribute dfn-for="GPUCanvasContext">
: <dfn>\[[validConfiguration]]</dfn> of type boolean, initially `false`.

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.

I see, I had forgotten this. Given that getCurrentTexture() can still throw exceptions (if the context entirely unconfigured), I'm not sure how helpful this is?

It would especially make sense for getCurrentTexture() to throw if configure() also threw, see [1]. Seems to me to be consistent we should either:

  1. Have configure() unconditionally set the configuration even if it doesn't make sense, and validate asynchronously. If configured incorrectly, return invalid textures from getCurrentTexture().
  2. Have configure() validate synchronously and on failure either:
    a. Leave the old configuration in place (if any) so getCurrentTexture() keeps working as it did.
    b. Leave the canvas unconfigured so getCurrentTexture() now throws.

Right now the spec is in an "impossible" in-between state where I think it requires a content-gpu-content round-trip unless the configuration state could somehow move to the gpu process (I don't think it can).

@kainino0x

Copy link
Copy Markdown
Contributor Author

Obsoleted by #2416 which sidesteps complexities here by having the current texture always match the canvas size.

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.

2 participants