Updates DawnInstanceDescriptor to pass in the Platform.

Notes:
- Separates ChainedStruct to be reusable without cpp header. (Also
  updates native structs to directly use it.)
- Manually implements the descriptor in DawnNative.
- Reworks ChainUtils with mapping from struct to STypes.
- Updates the tests to use either SetPlatformForTesting which is still
  required because DawnTest uses a "global" instance for all tests and
  some tests require setting (and cleaning up) a test specific platform.

Bug: dawn:1374
Change-Id: I078c78f22c5137030cf3cf0e8358fe4373ee9c6c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132268
Reviewed-by: Austin Eng <enga@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
Loko Kung
2023-05-16 04:50:32 +00:00
committed by Dawn LUCI CQ
parent f9f9f829e3
commit 14ed533565
15 changed files with 157 additions and 75 deletions

View File

@@ -21,6 +21,7 @@
#include "dawn/dawn_proc_table.h"
#include "dawn/native/dawn_native_export.h"
#include "dawn/webgpu.h"
#include "dawn/webgpu_cpp_chained_struct.h"
namespace dawn::platform {
class Platform;
@@ -128,6 +129,20 @@ struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptionsBase {
enum BackendValidationLevel { Full, Partial, Disabled };
// Can be chained in InstanceDescriptor
struct DAWN_NATIVE_EXPORT DawnInstanceDescriptor : wgpu::ChainedStruct {
DawnInstanceDescriptor();
static constexpr size_t kFirstMemberAlignment =
wgpu::detail::ConstexprMax(alignof(wgpu::ChainedStruct), alignof(uint32_t));
alignas(kFirstMemberAlignment) uint32_t additionalRuntimeSearchPathsCount = 0;
const char* const* additionalRuntimeSearchPaths;
dawn::platform::Platform* platform = nullptr;
// Equality operators, mostly for testing. Note that this tests
// strict pointer-pointer equality if the struct contains member pointers.
bool operator==(const DawnInstanceDescriptor& rhs) const;
};
// Represents a connection to dawn_native and is used for dependency injection, discovering
// system adapters and injecting custom adapters (like a Swiftshader Vulkan adapter).
//
@@ -262,6 +277,12 @@ DAWN_NATIVE_EXPORT bool BindGroupLayoutBindingsEqualForTesting(WGPUBindGroupLayo
} // namespace dawn::native
// Alias the DawnInstanceDescriptor up to wgpu.
// TODO(dawn:1374) Remove this aliasing once the usages are updated.
namespace wgpu {
using dawn::native::DawnInstanceDescriptor;
} // namespace wgpu
// TODO(dawn:824): Remove once the deprecation period is passed.
namespace dawn_native = dawn::native;