Skip to content
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

API for object labels #167

Open
kainino0x opened this issue Sep 29, 2022 · 1 comment
Open

API for object labels #167

kainino0x opened this issue Sep 29, 2022 · 1 comment
Labels
non-breaking Does not require a breaking change (that would block V1.0)

Comments

@kainino0x
Copy link
Collaborator

A proposal for the behavior of object labels has been accepted in the WebGPU group:
gpuweb/gpuweb#3263 (comment)

There are 2 key things here:

  • In cases where there are multiple wrappers for the same object (e.g. getBindGroupLayout, or internally-deduplicated objects), each wrapper maintains its own copy of the label.
  • How the label is used is implementation-defined, but the design enables implementations to keep track of all of the labels currently associated with an internal object (internally ReplaceLabel or AddLabel/RemoveLabel), so that we never have to mislead developers about what an object is. For example, if you getBindGroupLayout twice, set the labels to one and two, an error message might say something like ... isn't compatible with binding 0 of [BindGroupLayout "one|two"].

In webgpu.h, there are not guaranteed to be wrappers - e.g. createBindGroupLayout can return the exact same pointer value multiple times due to deduplication. This means when you SetLabel in a native implementation it might replace labels on bind group layouts that just happened to be identical. So, should we have a ReplaceLabel(old,new) or AddLabel(new)/RemoveLabel(old) API in webgpu.h instead? But there's a major problem here, I think - in both cases, we would also "leak" labels when you free an object ref, because we wouldn't know which label belonged to that ref, unless we require the label on free, which seems like a non-starter. (If we did, we could perfectly maintain the label list.)

I'd conclude that webgpu.h still needs a SetLabel API, despite the label fidelity problem. Some applications may want better fidelity. They could achieve this either by using an extension Replace/Add/Remove API (which e.g. Chromium would use), or maybe by enabling a special implementation mode that disables object deduplication, or adds an indirection layer to match the JS API (e.g. tracking labels in dawn wire)?

We also need to be able to implement webgpu.h on top of the JS API. SetLabel maps most nicely, since it simply overwrites the label of the wrapper.

Aside on how to implement Replace/Add/RemoveLabel on Emscripten

ReplaceLabel is interesting, because Emscripten can check (in debug builds) that the old label matches before overwriting the label, ensuring we always remove one label and add one label. AddLabel/RemoveLabel would need to be implemented as an additional layer on top of JS labels, though perhaps this is fine. Imagine a WASM application adds labels "one" and "two" and Dawn deduplicates it with an object with label "other": internally, the label could become e.g. one+two|other, if + were used by Emscripten and | by Dawn.

@kainino0x
Copy link
Collaborator Author

kainino0x commented Oct 12, 2023

webgpu.h meeting: Agreed we need to keep SetLabel (already have it). Any improvements can be prototyped in implementations, standardized post-v1.

Marking non-breaking.

@kainino0x kainino0x added the non-breaking Does not require a breaking change (that would block V1.0) label Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
non-breaking Does not require a breaking change (that would block V1.0)
Projects
None yet
Development

No branches or pull requests

1 participant