From 142141cdf26db698cb720d926996352eff453ee5 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Mon, 8 Aug 2022 17:42:41 +0000 Subject: [PATCH] Do simplifications assuming macOS 10.11 is the min version supported. Bug: dawn:1397 Change-Id: I42a588b2a30e12eb7b6889a8954311b632547c58 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/90243 Commit-Queue: Corentin Wallez Reviewed-by: Austin Eng Kokoro: Kokoro --- README.chromium | 54 +++++++++++++++++++++++++++++ docs/support.md | 54 +++++++++++++++++++++++++++++ src/dawn/native/metal/BackendMTL.mm | 53 ++++++++-------------------- src/dawn/utils/GLFWUtils_metal.mm | 28 +++++++-------- 4 files changed, 135 insertions(+), 54 deletions(-) create mode 100644 docs/support.md diff --git a/README.chromium b/README.chromium index e14cc8b843..15f5c6f276 100644 --- a/README.chromium +++ b/README.chromium @@ -1,4 +1,58 @@ Name: Dawn +![Dawn's logo: a sun rising behind a stylized mountain inspired by the WebGPU logo. The text "Dawn" is written below it.](docs/imgs/dawn_logo.png "Dawn's logo") + +# Dawn, a WebGPU implementation + +Dawn is an open-source and cross-platform implementation of the work-in-progress [WebGPU](https://webgpu.dev) standard. +More precisely it implements [`webgpu.h`](https://github.com/webgpu-native/webgpu-headers/blob/main/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](docs/support.md) 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: + + - [Dawn bug tracker](https://bugs.chromium.org/p/dawn/issues/entry) if you find issues with Dawn. + - [Tint bug tracker](https://bugs.chromium.org/p/tint/issues/entry) if you find issues with Tint. + - [Dawn's mailing list](https://groups.google.com/forum/#!members/dawn-graphics) for other discussions related to Dawn. + - [Dawn's source code](https://dawn.googlesource.com/dawn) + - [Dawn's Matrix chatroom](https://matrix.to/#/#webgpu-dawn:matrix.org) for live discussion around contributing or using Dawn. + - [WebGPU's Matrix chatroom](https://matrix.to/#/#WebGPU:matrix.org) + - [Tint mirror](https://dawn.googlesource.com/tint) for standalone usage. + +## Documentation table of content + +Developer documentation: + + - [Dawn overview](docs/dawn/overview.md) + - [Building](docs/building.md) + - [Contributing](CONTRIBUTING.md) + - [Code of Conduct](CODE_OF_CONDUCT.md) + - [Testing Dawn](docs/dawn/testing.md) + - [Debugging Dawn](docs/dawn/debugging.md) + - [Dawn's infrastructure](docs/dawn/infra.md) + - [Dawn errors](docs/dawn/errors.md) + - [Tint experimental extensions](docs/tint/experimental_extensions.md) + + +User documentation: (TODO, figure out what overlaps with the webgpu.h docs) + +## Status + +(TODO) + +## License + +Apache 2.0 Public License, please see [LICENSE](/LICENSE). + +## Disclaimer + +This is not an officially supported Google product. Short Name: dawn URL: https://dawn.googlesource.com/dawn License: Apache 2.0 diff --git a/docs/support.md b/docs/support.md new file mode 100644 index 0000000000..c4e38bff53 --- /dev/null +++ b/docs/support.md @@ -0,0 +1,54 @@ +# Platform and API support for Dawn/Tint + +## Khronos's Vulkan + +Vulkan is supported with minimal features, limits and extensions being required (what's required has been measured to be wildly available). +Vulkan is the preferred target API on platforms that don't have other "modern" GPU APIs. +Vulkan is supported as best effort on other platforms (e.g. Windows and macOS). + +**Required version**: Vulkan 1.0 is supported with some required extensions (`VK_KHR_maintenance1`), or Vulkan 1.1 and above without extensions. + +**Required features**: `depthBiasClamp`, `fragmentStoresAndAtomics`, `fullDrawIndexUint32`, `imageCubeArray`, `independentBlend`, `sampleRateShading`, and either `textureCompressionBC` or both of `textureCompressionETC` and `textureCompressionASTC_LDR`. + +**Required limites**: they are too detailed to describe here, but in general should be wildly supported. +See the [WebGPU limits](https://gpuweb.github.io/gpuweb/#limits) that mostly correspond to Vulkan limits. + +**Operating system support**: + + - Linux: Supported. + - ChromeOS: Supported. + - Android: Work in progress. + - Fuchsia: Work in progress. + +## Microsoft's D3D12 + +D3D12 is supported with feature level 11.1, or feature level 11.0 with Resource Binding Tier 2. +This is the vast majority of D3D12 devices. +Supported shader models are 5.1 and above. It is the preferred target API when available. + +**Windows flavor support**: + + - Win32: Supported. + - UWP: Supported, best effort. + - Xbox: Not supported, contributions welcome. + +## Apple's Metal + +Metal is supported and is the preferred target API when available. + +**Apple OS support:** + + - macOS: supported. + - iOS: supported, best effort. + - tvOS/ipadOS/...: Not supported, contributions welcome. + +## Khronos's OpenGL family + +Support for OpenGL is in progress with the aim to make OpenGL ES 3.1 (with extensions and limits) supported through EGL. +Other flavors of OpenGL (desktop OpenGL) or binding APIs (GLX, WGL, EAGL, CGL) are supported as best effort with contributions welcome. + + +## Microsoft's D3D12 + +Dawn doesn't have a D3D11 backend at the moment, but D3D11 support can be achieved with the OpenGL ES backend through ANGLE's OpenGL ES to D3D11 translation. +There might be a D3D11 backend in the future. diff --git a/src/dawn/native/metal/BackendMTL.mm b/src/dawn/native/metal/BackendMTL.mm index ee480a6673..fdd27bf223 100644 --- a/src/dawn/native/metal/BackendMTL.mm +++ b/src/dawn/native/metal/BackendMTL.mm @@ -158,22 +158,14 @@ MaybeError GetDevicePCIInfo(id device, PCIIDs* ids) { return GetVendorIdFromVendors(device, ids); } -bool IsMetalSupported() { - // Metal was first introduced in macOS 10.11 - // WebGPU is targeted at macOS 10.12+ - // TODO(dawn:1181): Dawn native should allow non-conformant WebGPU on macOS 10.11 - return IsMacOSVersionAtLeast(10, 12); -} #elif DAWN_PLATFORM_IS(IOS) + MaybeError GetDevicePCIInfo(id device, PCIIDs* ids) { DAWN_UNUSED(device); *ids = PCIIDs{0, 0}; return {}; } -bool IsMetalSupported() { - return true; -} #else #error "Unsupported Apple platform." #endif @@ -467,10 +459,8 @@ class Adapter : public AdapterBase { return MTLGPUFamily::Mac2; } } - if (@available(macOS 10.11, *)) { - if ([*mDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v1]) { - return MTLGPUFamily::Mac1; - } + if ([*mDevice supportsFeatureSet:MTLFeatureSet_macOS_GPUFamily1_v1]) { + return MTLGPUFamily::Mac1; } #elif TARGET_OS_IOS if (@available(iOS 10.11, *)) { @@ -658,43 +648,30 @@ ResultOrError>> Backend::DiscoverAdapters( ASSERT(optionsBase->backendType == WGPUBackendType_Metal); std::vector> adapters; - BOOL supportedVersion = NO; #if DAWN_PLATFORM_IS(MACOS) - if (@available(macOS 10.11, *)) { - supportedVersion = YES; + NSRef>> devices = AcquireNSRef(MTLCopyAllDevices()); - NSRef>> devices = AcquireNSRef(MTLCopyAllDevices()); - - for (id device in devices.Get()) { - Ref adapter = AcquireRef(new Adapter(GetInstance(), device)); - if (!GetInstance()->ConsumedError(adapter->Initialize())) { - adapters.push_back(std::move(adapter)); - } - } - } -#endif - -#if DAWN_PLATFORM_IS(IOS) - if (@available(iOS 8.0, *)) { - supportedVersion = YES; - // iOS only has a single device so MTLCopyAllDevices doesn't exist there. - Ref adapter = - AcquireRef(new Adapter(GetInstance(), MTLCreateSystemDefaultDevice())); + for (id device in devices.Get()) { + Ref adapter = AcquireRef(new Adapter(GetInstance(), device)); if (!GetInstance()->ConsumedError(adapter->Initialize())) { adapters.push_back(std::move(adapter)); } } #endif - if (!supportedVersion) { - UNREACHABLE(); + + // iOS only has a single device so MTLCopyAllDevices doesn't exist there. +#if defined(DAWN_PLATFORM_IOS) + Ref adapter = + AcquireRef(new Adapter(GetInstance(), MTLCreateSystemDefaultDevice())); + if (!GetInstance()->ConsumedError(adapter->Initialize())) { + adapters.push_back(std::move(adapter)); } +#endif + return adapters; } BackendConnection* Connect(InstanceBase* instance) { - if (!IsMetalSupported()) { - return nullptr; - } return new Backend(instance); } diff --git a/src/dawn/utils/GLFWUtils_metal.mm b/src/dawn/utils/GLFWUtils_metal.mm index d07eecaf0b..3bb39e0e02 100644 --- a/src/dawn/utils/GLFWUtils_metal.mm +++ b/src/dawn/utils/GLFWUtils_metal.mm @@ -29,25 +29,21 @@ namespace utils { std::unique_ptr SetupWindowAndGetSurfaceDescriptorCocoa(GLFWwindow* window) { - if (@available(macOS 10.11, *)) { - NSWindow* nsWindow = glfwGetCocoaWindow(window); - NSView* view = [nsWindow contentView]; + NSWindow* nsWindow = glfwGetCocoaWindow(window); + NSView* view = [nsWindow contentView]; - // Create a CAMetalLayer that covers the whole window that will be passed to - // CreateSurface. - [view setWantsLayer:YES]; - [view setLayer:[CAMetalLayer layer]]; + // Create a CAMetalLayer that covers the whole window that will be passed to + // CreateSurface. + [view setWantsLayer:YES]; + [view setLayer:[CAMetalLayer layer]]; - // Use retina if the window was created with retina support. - [[view layer] setContentsScale:[nsWindow backingScaleFactor]]; + // Use retina if the window was created with retina support. + [[view layer] setContentsScale:[nsWindow backingScaleFactor]]; - std::unique_ptr desc = - std::make_unique(); - desc->layer = [view layer]; - return std::move(desc); - } - - return nullptr; + std::unique_ptr desc = + std::make_unique(); + desc->layer = [view layer]; + return std::move(desc); } } // namespace utils