-
Notifications
You must be signed in to change notification settings - Fork 353
Add GPU.[[adapters_active]] #1477
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This internal slot has no enforced ("must") behavior, but is intended to
enhance compatibility between different WebGPU implementations/hardware
and push developers toward an optimal path.
|
I got some concerns here after initial look. It prevents UA to do what it wants in some cases. For example, when an adapter is added, maybe the UA choice would otherwise be keep the previously acquired adapters alive and well. But following this logic would make the UA to fail the device creation. |
|
Editors meeting: had a long conversation about this and we're still thinking on it. |
|
Revised based on discussion in editing meeting. |
|
The general idea looks good but I have a slight concern about the composability of things in asynchronous scenarios. Consider the following code: let currentDevice = null;
async function asyncReinit() {
const adapter = await gpu.requestAdapter();
currentDevice = adapter.requestDevice();
initWithDevice(device);
}
resetButton.onclick = () => {
asyncReinit();
currentDevice.destroy();
}This code look like it should properly destroy the device and reinitialize it, and that the order of This might be slightly worse in pages using multiple WebGPU components that don't know about each other. The timing of things could lead to hard to reproduce issues where devices fail creation. This issue isn't a huge blocker but it would be nice to fix it if it's not too hard. |
FWIW, a previous draft of my rework had a GPUAdapterProvider and put the [[active]] state on that. Each applet on a page would create its own GPUAdapterProvider once at startup (providing its adapter options there) and receive adaptersadded/adapterschanged events on it. |
I've fixed the PR so it actually ever sets I think the design is actually reasonably robust to this. If this does happen flakily, an already-lost device is returned, and the application should recover from that in the normal way by trying again. |
|
Ok, I think that's a little window for conflicts so it's probably fine. You previously had a proposal for making |
| [[#adapter-selection]] and the criteria in |options|. | ||
|
|
||
| 1. |promise| [=resolves=] with a new {{GPUAdapter}} encapsulating |adapter|. | ||
| 1. Set `navigator.gpu.`{{GPU/[[adapters_active]]}} to `true`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, so if the user wants to ignore this logic entirely, they'd just
- hold onto
GPUAdapterafter a device is lost - call
requestAdapterwithout bothering to check the result - use the old
GPUAdapterlike nothing happened
Isn't the intent here to prevent this behavior? It looks to me that some users may do just this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, they could do this, but it would be harder to do that accidentally.
We could be much more strict and just make new GPUAdapter objects, but we'd lose expando properties and break equality comparisons.
|
Editors discussed this more, and I think we are going to make requestAdapter(s) return new GPUAdapter object(s) every time, as this is the most forward-compatible. Instead of In the future we can consider allowing requestAdapter(s) to return the same GPUAdapter object(s) multiple times, which would allow applications to do equality comparisons or hang expando properties off of them. This would be a nearly-non-breaking change, less risky than going the other way. Alternatively we can start guaranteeing that the |
Goal
Make
requestDevice()behave more similarly across scenarios, so developers don't accidentally use it unportably. Do this by making "less extreme" scenarios (likedevice.destroy()) look the same as "more extreme" scenarios (like eGPU unplug or TDR). This prevents developers from accidentally writing code that works in less extreme cases but fails in more extreme cases.Solution
Adds a global internal
GPU.[[adapters_active]]flag. If it's false, no adapter can create a device.It is gets set to
falsein scenarios described in the PR.Preview | Diff