Skip to content

Experiment with using canvas.getContext() for configuration - #2593

Closed
toji wants to merge 4 commits into
mainfrom
canvas-configure
Closed

toji wants to merge 4 commits into
mainfrom
canvas-configure

Conversation

@toji

@toji toji commented Feb 10, 2022 •

Copy link
Copy Markdown
Member

Not intended for merge!

This builds off of the commits and discussion in #2416 to help understand what it would mean to switch to using canvas.getContext() as the context configuration mechanism. (Initially proposed in #2416 (comment))

The biggest quirks that I found while drafting this:

  • getPreferredFormat needs to move, and GPUAdapter is about the only logical place. This means you're getting the preferred format against a HTMLCanvasElement and not a context, which means we'd need to determine what should happen if, say, you pass a canvas which already has a 2d context, etc.
  • "IDL" errors need to be manually validated due to the getContext() overload.
  • Not sure what the ideal behavior is for a scenario where you've already configured the context, then call getContext() again with an invalid configuration. (ie: no device or format). Return the previously valid context without change? Return null? Return the previously valid context but unconfigure? Always return a context and let errors surface in getCurrentTexture()?
  • unconfigure() feels a little out of place now, though I think the functionality is still needed.

💥 Error: 500 Internal Server Error 💥

PR Preview failed to build. (Last tried on Feb 11, 2022, 7:29 PM UTC).

More

PR Preview relies on a number of web services to run. There seems to be an issue with the following one:

🚨 CSS Spec Preprocessor - CSS Spec Preprocessor is the web service used to build Bikeshed specs.

🔗 Related URL

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator at 
 [no address given] to inform them of the time this error occurred,
 and the actions you performed just before this error.</p>
<p>More information about this error may be available
in the server error log.</p>
<hr>
<address>Apache/2.4.10 (Debian) Server at api.csswg.org Port 443</address>
</body></html>

If you don't have enough information above to solve the error by yourself (or to understand to which web service the error is related to, if any), please file an issue.

@annevk

annevk commented Feb 11, 2022

Copy link
Copy Markdown
Contributor

You cannot throw for an invalid configuration?

@toji

toji commented Feb 11, 2022

Copy link
Copy Markdown
Member Author

We can (and I've updated the PR to do so), but there's some subtlety here that means that we may want to accept a configuration that seems "invalid" otherwise. For example, we have the unconfigure() method to break a context's association with a GPUDevice, but it may be better to handle that same functionality by calling canvas.getContext('webgpu', null);

If we want to communicate errors at the time of this call then throwing an error is almost certainly the right approach, it's just a question of whether or not we actually want to do that in some or all cases.

Comment thread spec/index.bs
readonly attribute (HTMLCanvasElement or OffscreenCanvas) canvas;

undefined configure(GPUCanvasConfiguration configuration);
undefined unconfigure();

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.

do we still need this? I guess it's a distant relative to buffer.destroy.
Without a configure method it seems strange though. Maybe it should be called destroy?

@toji

toji commented Feb 11, 2022

Copy link
Copy Markdown
Member Author

I agree that it feels strange to have an explicit unconfigure() without an associated configure(). A name change would probably help, though destroy() sounds as if we'd be discarding the context, which we're not. It just breaks the association with the GPUDevice so the device can be GCed.

Viable paths I see for this:

  • Rename unconfigure() to something more logical in isolation. (dropDevice(), invalidate(), reset()?)
  • Drop unconfigure() in favor of calling getContext('webgpu', null); (or, implicitly, getContext('webgpu');)
  • Drop the ability to unconfigure entirely, and have it only weakly hold a reference to the device. We've decided against that in the past, though.

@toji

toji commented Mar 17, 2022

Copy link
Copy Markdown
Member Author

After talking with @junov about canvas integration this morning, I don't believe we're going to pursue this direction any longer. Closing, and we'll update #2416 with additional context soon.

@toji toji closed this Mar 17, 2022
@toji
toji deleted the canvas-configure branch March 17, 2022 16:32
@annevk

annevk commented Mar 17, 2022

Copy link
Copy Markdown
Contributor

Stating it as a foregone conclusion seems a little weird. Looking forward to the context.

@kainino0x

Copy link
Copy Markdown
Contributor

It's not a conclusion, since we'll track conclusions on the issue and the issue is still open; more that toji's tentative proposal in this PR is retracted by toji.

@kainino0x

Copy link
Copy Markdown
Contributor

Er, well, I guess we don't have a real issue open. But I guess #2416 is the one we're using to track it (it's attached to the project tracker).

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.

4 participants