WebGPU error handling 1: Return error objects on errors.

Dawn used to return "nullptr" when an error happened while creating an
object. To match WebGPU we want to return valid pointers but to "error"
objects.

This commit implements WebGPU error handling for all "descriptorized"
objects and changes the nullptr error checks into "ValidateObject"
checks. This method is used both to check that the object isn't an
error, but also that all objects in a function call are from the same
device.

New validation is added to objects with methods (apart from Device) so
they check they aren't error objects.

A large number of ASSERTs were added to check that frontend objects
aren't accessed when they are errors, so that missing validation would
hit the asserts instead of crashing randomly.

The bind group validation tests were modified to test the behavior with
both nullptrs and error objects.

Future commits will change the CommandBufferBuilder to not be a builder
anymore but an "Encoder" instead with special-cased error handling. Then
once all objects are descriptorized, the notion of builders will be
removed from the code.

BUG=dawn:8

Change-Id: I8647712d5de3deb0e99e3bc58f34496f67710edd
Reviewed-on: https://dawn-review.googlesource.com/c/4360
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
35 files changed
tree: 7349ab2904e7f5496b19012a92cc852ed9403e4b
  1. build_overrides/
  2. examples/
  3. generator/
  4. infra/
  5. scripts/
  6. src/
  7. third_party/
  8. .clang-format
  9. .gitignore
  10. .gn
  11. AUTHORS
  12. BUILD.gn
  13. codereview.settings
  14. CONTRIBUTING.md
  15. dawn.json
  16. dawn_wire.json
  17. DEPS
  18. LICENSE
  19. OWNERS
  20. PRESUBMIT.py
  21. README.chromium
  22. README.md
README.md

Dawn, a WebGPU implementation

Dawn (formerly NXT) is an open-source and cross-platform implementation of the work-in-progress WebGPU standard. It exposes a C/C++ API that maps almost one-to-one to the WebGPU IDL and can be managed as part of a larger system such as a Web browser.

Dawn provides several WebGPU building blocks:

  • WebGPU C/C++ headers that applications and other building blocks use.
  • A “native” implementation of WebGPU using platforms' GPU APIs:
    • D3D12 on Windows 10
    • Metal on OSX (and eventually iOS)
    • Vulkan on Windows, Linux (eventually ChromeOS and Android too)
    • OpenGL as best effort where available
  • A client-server implementation of WebGPU for applications that are in a sandbox without access to native drivers

Directory structure

  • dawn.json: description of the API used to drive code generators.
  • examples: examples showing how Dawn is used.
  • generator: code generator for files produces from dawn.json
    • templates: Jinja2 templates for the generator
  • scripts: scripts to support things like continuous testing, build files, etc.
  • src:
    • common: helper code shared between core Dawn libraries and tests/samples
    • dawn_native: native implementation of WebGPU, one subfolder per backend
    • dawn_wire: client-server implementation of WebGPU
    • include: public headers for Dawn
    • tests: internal Dawn tests
      • end2end: WebGPU tests performing GPU operations
      • unittests: unittests and by extension tests not using the GPU
        • validation: WebGPU validation tests not using the GPU (frontend tests)
    • utils: helper code to use Dawn used by tests and samples
  • third_party: directory where dependencies live as well as their buildfiles.

Building Dawn

Dawn uses the Chromium build system and dependency management so you need to install depot_tools and add it to the PATH.

On Linux you need to have the pkg-config command:

# Install pkg-config on Ubuntu
sudo apt-get install pkg-config

Then get the source as follows:

# Clone the repo as "dawn"
git clone https://dawn.googlesource.com/dawn dawn && cd dawn

# Bootstrap the gclient configuration
cp scripts/standalone.gclient .gclient

# Fetch external dependencies and toolchains with gclient
gclient sync

Then generate build files using gn args out/Debug or gn args out/Release. A text editor will appear asking build options, the most common option is is_debug=true/false; otherwise gn args out/Release --list shows all the possible options.

Then use ninja -C out/Release to build dawn and for example ./out/Release/dawn_end2end_tests to run the tests.

Contributing

Please read and follow CONTRIBUTING.md. Dawn doesn‘t have a formal coding style yet, except what’s defined by our clang format style. Overall try to use the same style and convention as code around your change.

If you find issues with Dawn, please feel free to report them on the bug tracker. For other discussions, please post to Dawn's mailing list.

License

Please see LICENSE.

Disclaimer

This is not an officially supported Google product.