-
Notifications
You must be signed in to change notification settings - Fork 212
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
chore(core) new device props api #2100
Conversation
Signed-off-by: Chris Gervang <chris@gervang.com>
Signed-off-by: Chris Gervang <chris@gervang.com>
modules/core/src/adapter/device.ts
Outdated
}; | ||
|
||
export type WebGPUDeviceProps = _DeviceProps & { | ||
/** Request a Device with the highest limits supported by platform. WebGPU: devices can be created with minimal limits. */ | ||
requestMaxLimits?: boolean; |
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.
This is intended to be WebGPU only? It isn't used by WebGL
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.
Not quite convinced that this is worth the extra complexity in term of types etc, compared to just adding two WebGL/WebGPU columns to the DeviceProps docs table.
Also seems to limit the ability to specify WebGL/WebGPU options when using best-available
(though I assume that is fixable).
@@ -128,11 +128,13 @@ export class WebGLDevice extends Device { | |||
|
|||
this.handle = createBrowserContext(this.canvasContext.canvas, { | |||
...props, | |||
onContextLost: (event: Event) => | |||
onContextLost: (event: Event) => { |
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.
What are these changes? Some editor auto correct?
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.
This calls the users onContextLost, if provided
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.
This calls the users onContextLost, if provided
I see. Adding a one line bug fix in to a bigger API change is a bit risky, can slip through the review, and can get lost if API change is not approved...
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.
Happy to split this out. I didn't mean to put anything risky in here. The reason I included this is get clarity on the intended API. It's unclear to me what the intent is.
If users shouldn't be able to provide onContextLost
by design, then the API types need to be adjusted a bit. If we can agree the user should be able to provide onContextLost
, then this is a bug and I'll pull that into another PR.
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.
Now that you shine a light on it, I think we should completely drop support for onContextLost
. Such callback code tends to be surprisingly messy to keep working across devices and it doesn't add value.
We don't talk about contexts anymore, just devices. and we have the replacement in the WebGPU style promise API: device.lost
App can register its onContextLost callback with device.lost.then(onContextLost)
.
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.
I agree. device.lost
sounds better since it the same API for both devices, making this redundant.
Is there a device equivalent for onContextRestore
as well?
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.
No, context restore is not supported by luma.gl v9.
The problems is that properly handling context restore in non-trivial apps is very tricky, since all resources are lost and have to be recreated, and the data that was used to create buffers and textures may not have been saved.
\Showing a message asking the user to just refresh the page is usually best way out.
WebGPU doesn't support restore.
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.
Should the onContextRestore code in the WebGL device be removed then?
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. I would vote for that. It is not impossible for an app to register the callback even if luma.gl API doesn't support it, they will just need to get the context and add an event handler themselves.
The vision here makes sense to me, that one day we’ll be able to use The complex typing reflects a complex API; I think these types should be as helpful to users as possible. It defeats the purpose if users need to constantly refer to the documentation just to know which properties they can use, especially when they are explicitly using WebGL or WebGPU. I think the goal should be to provide clarity and reduce the cognitive load, and I'm open simpler implementations if they exist. |
In loaders.gl we have options sub-objects for each loader, the same model could work here: luma.createDevice({
// common options
webgl: {
// webgl specific options,
},
webgpu: {
// webgpu specific options
}
}; It would be slightly breaking but make it very clear what is going on. |
Signed-off-by: Chris Gervang <chris@gervang.com>
Signed-off-by: Chris Gervang <chris@gervang.com>
OK I have made another pass on this. Decided to go with some technically breaking changes to clean up the API, shouldn't lead to any subtle issues.
|
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.
Nice progress! Left a few comments. I'm wondering if we should warn when features that are only WebGL or only WebGPU are used on an incompatible device, like "debug"? When the lib does nothing I can foresee that being a long debugging session to learn what exactly is and isn't supported, specifically for any potentially ambiguous top-level device props. What do you think?
|
Have a few test failures, plan to merge when they are sorted. |
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.
I like the new names, and the docstrings are very helpful! Thanks for pushing this forward.
| `_requestMaxLimits?: boolean` | `true` | Ensures that the Device exposes the highest `DeviceLimits` supported by platform (WebGPU). | | ||
| `_initializeFeatures?: boolean` | `true` | Initialize all `DeviceFeatures` on startup. 🧪 | | ||
| `_disabledFeatures?: Record<DeviceFeature, boolean>` | `{ 'compilation-status-async-webgl': true }` | Disable specific `DeviceFeatures`. 🧪 | | ||
| `_factoryDestroyPolicy?: string` | `'unused'` | `'unused' \| 'never'` Never destroy cached shaders and pipelines. 🧪 | |
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.
Why might someone use this?
It is a tradeoff between reuse/speed and memory. I added it to unblock things until we find the right balance.
| `depth24unorm-stencil8` | Removed | `depth24plus-stencil8` | The `TextureFormat` was removed from the WebGPU spec | | ||
| `rgb8unorm-unsized` | Removed | `rgb8unorm` | No longer support unsized WebGL1 `TextureFormat` | | ||
| `rgba8unorm-unsized` | Removed | `rgb8aunorm` | No longer support unsized WebGL1 `TextureFormat` | | ||
| Updated API | Status | Replacement | Comment | |
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.
Might be good to document the renamed device props and removal of "break" before merging
Great review, you are really paying attention to this! Agree with all your proposals. Would you mind applying your changes? Landing this PR has become a pretty big effort, so teamwork is appreciated. |
@chrisgervang This is passing CI after lots of iterations. Will land and we can take your suggestions in a follow up PR. |
For visgl/deck.gl#8945
Background
DeviceProps
API Changes:For both devices,
For webgl,
onContextLost
. Usedevice.lost
instead.onContextRestore
. Luma 9 doesn't support restoring context.For WebGPU,
Taking a stab at documenting device props per device and type hinting CreateDeviceProps. Feel free to make corrections or clarifications around the intent behind some of these props, when I was unsure I went off of how the current implementation is written (even though knowing it may be incomplete)
I think deck should use
CreateDeviceProps
, so I've exported that as well.Change List