[dawn][native] Store ExternalTexture in BGL BindingInfo

Store both internal bindings and external bindings in the BGL. This is
the new comment at the top of the class that explains the newly added
APIBindingIndex as well.

<copypaste>
BindGroupLayout stores the information passed in the BindGroupLayoutDescriptor
but processes it in various ways to make it more efficient to use internally
and to add internal bindings used to implement WebGPU feature that don't exist
in backend APIs.

Storing information in hashmap<BindingNumber, T> would be inefficient because
these numbers may be sparse. Instead the are compacted into vectors, and
reordered using |BindingTypeOrder| to make it efficient to iterate over all the
bindings of a same kind. Indexind the packed bindings is done with
|BindingIndex| or |APIBindingIndex| (see below for the explanation).

In other cases bindings need to be expanded because a single BGLEntry can
match multiple BGEntries when bindingArraySize > 1. To make handling more
regular, a fake BGLEntry is created for each array element such that most code
doesn't need to be aware of bindingArraySize.

We also need to have private bindings that cannot be set by the users: dynamic
binding array or ExternalTextures add additional bindings for their inner
workings which are private to Dawn. Conversely ExternalTexture is a pure
frontend object and doesn't exist in backends, so dawn::native must mostly be
unaware about it. This is where |BindingIndex| and |APIBindingIndex| are
different:

 - |APIBindingIndex| are user-facing bindings and cannot be used to access
 private bindings. It is used in code for BindGroup validation and opertations
 and when reflecting/validating WGSL bind points.
 - |BindingIndex| are Dawn-facing bindings where ExternalTexture shouldn't be
 accessed and instead can be used to access internal bindings.

Internally both |APIBindingIndex| and |BindingIndex| are used to access the
same vector, but the types are used to force uses of different BindGroupLayout
accessors that ASSERT the invariant above.
</copypaste>

ShaderModule in every backend is modified to iterate over the BGL's
BindingInfo using the BindingMap. Previously they iterated over the list
of bindings in the EntryPointMetadata. Iterating over the BGL's entries
allow using the new ExternalTextureBindingInfo that points at the
BindingIndex of its plane0/1/metadata, but requires converting from
APIBindingIndex to BindingIndex. (in future CLs the GenerateBindings can
be factored between all the backends)

The OpenGL ShaderModule is modified further to use a BindingIndex
instead of a BindingNumber in the CombinedSamplerPair.

A few additional cleanups will be done in follow-up CLs:
 - The external texture expansion map will be removed.
 - BGL::GetBindingIndex(BindingNumber) will be removed.

Bug: 42240282
Change-Id: I745d6dcaa1368be2656e09525e77edd0a34709bb
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/262196
Commit-Queue: Geoff Lang <geofflang@chromium.org>
Reviewed-by: Geoff Lang <geofflang@chromium.org>
Auto-Submit: Corentin Wallez <cwallez@chromium.org>
14 files changed
tree: 488771f3f6a060a6761d2adcdcda63aacea8ff59
  1. .github/
  2. .vscode/
  3. build_overrides/
  4. docs/
  5. generator/
  6. include/
  7. infra/
  8. scripts/
  9. src/
  10. test/
  11. third_party/
  12. tools/
  13. webgpu-cts/
  14. .bazelrc
  15. .clang-format
  16. .clang-format-ignore
  17. .clang-tidy
  18. .git-blame-ignore-revs
  19. .gitattributes
  20. .gitignore
  21. .gitmodules
  22. .gn
  23. .style.yapf
  24. .vpython3
  25. AUTHORS
  26. BUILD.bazel
  27. BUILD.gn
  28. CMakeLists.txt
  29. CMakeSettings.json
  30. CODE_OF_CONDUCT.md
  31. codereview.settings
  32. CONTRIBUTING.md
  33. CPPLINT.cfg
  34. DEPS
  35. DIR_METADATA
  36. go.mod
  37. go.sum
  38. go_presubmit_support.py
  39. LICENSE
  40. OWNERS
  41. PRESUBMIT.py
  42. README.chromium
  43. README.md
  44. unsafe_buffers_paths.txt
  45. WATCHLISTS
  46. WORKSPACE.bazel
README.md

Build Status Matrix Space

Dawn, a WebGPU implementation

Dawn is an open-source and cross-platform implementation of the WebGPU standard. More precisely it implements webgpu.h that is a one-to-one mapping with the WebGPU IDL. Dawn is meant to be integrated as part of a larger system and is the underlying implementation of WebGPU in Chromium.

Dawn provides several WebGPU building blocks:

  • WebGPU C/C++ headers that applications and other building blocks use.
    • The webgpu.h version that Dawn implements.
    • A C++ wrapper for the webgpu.h.
  • A “native” implementation of WebGPU using platforms' GPU APIs: D3D12, Metal, Vulkan and OpenGL. See per API support for more details.
  • A client-server implementation of WebGPU for applications that are in a sandbox without access to native drivers
  • Tint is a compiler for the WebGPU Shader Language (WGSL) that can be used in standalone to convert shaders from and to WGSL.

Helpful links:

Documentation table of content

Developer documentation:

User documentation: (TODO, figure out what overlaps with the webgpu.h docs)

License

BSD 3-Clause License, please see LICENSE.

Disclaimer

This is not an officially supported Google product.