Merge upstream & update dependencies

This commit is contained in:
2023-05-27 11:38:11 -04:00
37232 changed files with 1278304 additions and 430258 deletions

View File

@@ -0,0 +1,41 @@
// Copyright 2023 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef INCLUDE_DAWN_NATIVE_D3D11BACKEND_H_
#define INCLUDE_DAWN_NATIVE_D3D11BACKEND_H_
#include <d3d11_1.h>
#include <windows.h>
#include <wrl/client.h>
#include <memory>
#include "dawn/native/D3DBackend.h"
namespace dawn::native::d3d11 {
struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions
: public d3d::PhysicalDeviceDiscoveryOptions {
PhysicalDeviceDiscoveryOptions();
explicit PhysicalDeviceDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
};
// TODO(dawn:1774): Deprecated.
using AdapterDiscoveryOptions = PhysicalDeviceDiscoveryOptions;
DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D11Device> GetD3D11Device(WGPUDevice device);
} // namespace dawn::native::d3d11
#endif // INCLUDE_DAWN_NATIVE_D3D11BACKEND_H_

View File

@@ -20,25 +20,14 @@
#include <windows.h>
#include <wrl/client.h>
#include <memory>
#include "dawn/dawn_wsi.h"
#include "dawn/native/DawnNative.h"
#include "dawn/native/D3DBackend.h"
struct ID3D12Device;
struct ID3D12Resource;
namespace dawn::native::d3d12 {
class D3D11on12ResourceCache;
class Device;
class ExternalImageDXGIImpl;
DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<ID3D12Device> GetD3D12Device(WGPUDevice device);
DAWN_NATIVE_EXPORT DawnSwapChainImplementation CreateNativeSwapChainImpl(WGPUDevice device,
HWND window);
DAWN_NATIVE_EXPORT WGPUTextureFormat
GetNativeSwapChainPreferredFormat(const DawnSwapChainImplementation* swapChain);
enum MemorySegment {
Local,
@@ -49,80 +38,14 @@ DAWN_NATIVE_EXPORT uint64_t SetExternalMemoryReservation(WGPUDevice device,
uint64_t requestedReservationSize,
MemorySegment memorySegment);
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorDXGISharedHandle : ExternalImageDescriptor {
public:
ExternalImageDescriptorDXGISharedHandle();
// Note: SharedHandle must be a handle to a texture object.
// TODO(dawn:576): Remove after changing Chromium code to set textureSharedHandle.
HANDLE sharedHandle = nullptr;
HANDLE textureSharedHandle = nullptr;
// Optional shared handle to a D3D11/12 fence which can be used to synchronize using wait/signal
// values specified in the access descriptor below. If null, the texture will be assumed to have
// an associated DXGI keyed mutex which will be used with a fixed key of 0 for synchronization.
HANDLE fenceSharedHandle = nullptr;
struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions
: public d3d::PhysicalDeviceDiscoveryOptions {
PhysicalDeviceDiscoveryOptions();
explicit PhysicalDeviceDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
};
// Keyed mutex acquire/release uses a fixed key of 0 to match Chromium behavior.
constexpr UINT64 kDXGIKeyedMutexAcquireReleaseKey = 0;
struct DAWN_NATIVE_EXPORT ExternalImageAccessDescriptorDXGISharedHandle
: ExternalImageAccessDescriptor {
public:
// Value used for fence wait. A value of 0 is valid, but essentially a no-op since the fence
// lifetime starts with the 0 value signaled. A value of UINT64_MAX is ignored since it's also
// used by the D3D runtime to indicate that the device was removed.
uint64_t fenceWaitValue = 0;
// Value to signal the fence with after the texture is destroyed. A value of 0 means the fence
// will not be signaled.
uint64_t fenceSignalValue = 0;
// Whether the texture is for a WebGPU swap chain.
bool isSwapChainTexture = false;
};
// TODO(dawn:576): Remove after changing Chromium code to use the new struct name.
struct DAWN_NATIVE_EXPORT ExternalImageAccessDescriptorDXGIKeyedMutex
: ExternalImageAccessDescriptorDXGISharedHandle {
public:
// TODO(chromium:1241533): Remove deprecated keyed mutex params after removing associated
// code from Chromium - we use a fixed key of 0 for acquire and release everywhere now.
uint64_t acquireMutexKey;
uint64_t releaseMutexKey;
};
class DAWN_NATIVE_EXPORT ExternalImageDXGI {
public:
~ExternalImageDXGI();
static std::unique_ptr<ExternalImageDXGI> Create(
WGPUDevice device,
const ExternalImageDescriptorDXGISharedHandle* descriptor);
// Returns true if the external image resources are still valid, otherwise ProduceTexture() is
// guaranteed to fail e.g. after device destruction.
bool IsValid() const;
// TODO(sunnyps): |device| is ignored - remove after Chromium migrates to single parameter call.
WGPUTexture ProduceTexture(WGPUDevice device,
const ExternalImageAccessDescriptorDXGISharedHandle* descriptor);
WGPUTexture ProduceTexture(const ExternalImageAccessDescriptorDXGISharedHandle* descriptor);
private:
explicit ExternalImageDXGI(std::unique_ptr<ExternalImageDXGIImpl> impl);
std::unique_ptr<ExternalImageDXGIImpl> mImpl;
};
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
AdapterDiscoveryOptions();
explicit AdapterDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter;
};
// TODO(dawn:1774): Deprecated.
using AdapterDiscoveryOptions = PhysicalDeviceDiscoveryOptions;
} // namespace dawn::native::d3d12

View File

@@ -0,0 +1,101 @@
// Copyright 2023 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef INCLUDE_DAWN_NATIVE_D3DBACKEND_H_
#define INCLUDE_DAWN_NATIVE_D3DBACKEND_H_
#include <dxgi1_4.h>
#include <windows.h>
#include <wrl/client.h>
#include <memory>
#include <vector>
#include "dawn/native/DawnNative.h"
namespace dawn::native::d3d {
class ExternalImageDXGIImpl;
DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<IDXGIAdapter> GetDXGIAdapter(WGPUAdapter adapter);
struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions
: public PhysicalDeviceDiscoveryOptionsBase {
PhysicalDeviceDiscoveryOptions(WGPUBackendType type,
Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter;
};
// TODO(dawn:1774): Deprecated.
using AdapterDiscoveryOptions = PhysicalDeviceDiscoveryOptions;
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorDXGISharedHandle : ExternalImageDescriptor {
public:
ExternalImageDescriptorDXGISharedHandle();
// Note: SharedHandle must be a handle to a texture object.
HANDLE sharedHandle = nullptr;
};
struct DAWN_NATIVE_EXPORT ExternalImageDXGIFenceDescriptor {
// Shared handle for the fence. This never passes ownership to the callee (when used as an input
// parameter) or to the caller (when used as a return value or output parameter).
HANDLE fenceHandle = nullptr;
// The value that was previously signaled on this fence and should be waited on.
uint64_t fenceValue = 0;
};
struct DAWN_NATIVE_EXPORT ExternalImageDXGIBeginAccessDescriptor {
bool isInitialized = false; // Whether the texture is initialized on import
WGPUTextureUsageFlags usage = WGPUTextureUsage_None;
// A list of fences to wait on before accessing the texture.
std::vector<ExternalImageDXGIFenceDescriptor> waitFences;
// Whether the texture is for a WebGPU swap chain.
bool isSwapChainTexture = false;
};
class DAWN_NATIVE_EXPORT ExternalImageDXGI {
public:
~ExternalImageDXGI();
static std::unique_ptr<ExternalImageDXGI> Create(
WGPUDevice device,
const ExternalImageDescriptorDXGISharedHandle* descriptor);
// Returns true if the external image resources are still valid, otherwise BeginAccess() is
// guaranteed to fail e.g. after device destruction.
bool IsValid() const;
// Creates WGPUTexture wrapping the DXGI shared handle. The provided wait fences will be
// synchronized before using the texture in any command lists. Empty fences (nullptr handle) are
// ignored for convenience (EndAccess can return such fences).
WGPUTexture BeginAccess(const ExternalImageDXGIBeginAccessDescriptor* descriptor);
// Returns the signalFence that the client must wait on for correct synchronization. Can return
// an empty fence (nullptr handle) if the texture wasn't accessed by Dawn.
// Note that merely calling Destroy() on the WGPUTexture does not ensure synchronization.
void EndAccess(WGPUTexture texture, ExternalImageDXGIFenceDescriptor* signalFence);
private:
explicit ExternalImageDXGI(std::unique_ptr<ExternalImageDXGIImpl> impl);
std::unique_ptr<ExternalImageDXGIImpl> mImpl;
};
} // namespace dawn::native::d3d
#endif // INCLUDE_DAWN_NATIVE_D3DBACKEND_H_

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;
@@ -36,18 +37,9 @@ namespace dawn::native {
class InstanceBase;
class AdapterBase;
// An optional parameter of Adapter::CreateDevice() to send additional information when creating
// a Device. For example, we can use it to enable a workaround, optimization or feature.
struct DAWN_NATIVE_EXPORT DawnDeviceDescriptor {
DawnDeviceDescriptor();
~DawnDeviceDescriptor();
std::vector<const char*> requiredFeatures;
std::vector<const char*> forceEnabledToggles;
std::vector<const char*> forceDisabledToggles;
const WGPURequiredLimits* requiredLimits = nullptr;
};
// Each toggle is assigned with a TogglesStage, indicating the validation and earliest usage
// time of the toggle.
enum class ToggleStage { Instance, Adapter, Device };
// A struct to record the information of a toggle. A toggle is a code path in Dawn device that
// can be manually configured to run or not outside Dawn, including workarounds, special
@@ -56,12 +48,21 @@ struct ToggleInfo {
const char* name;
const char* description;
const char* url;
ToggleStage stage;
};
// A struct to record the information of a feature. A feature is a GPU feature that is not
// required to be supported by all Dawn backends and can only be used when it is enabled on the
// creation of device.
using FeatureInfo = ToggleInfo;
struct FeatureInfo {
const char* name;
const char* description;
const char* url;
// The enum of feature state, could be stable or experimental. Using an experimental feature
// requires the AllowUnsafeAPIs toggle to be enabled.
enum class FeatureState { Stable = 0, Experimental };
FeatureState featureState;
};
// An adapter is an object that represent on possibility of creating devices in the system.
// Most of the time it will represent a combination of a physical GPU and an API. Not that the
@@ -97,13 +98,9 @@ class DAWN_NATIVE_EXPORT Adapter {
explicit operator bool() const;
// Create a device on this adapter. On an error, nullptr is returned.
WGPUDevice CreateDevice(const DawnDeviceDescriptor* deviceDescriptor);
WGPUDevice CreateDevice(const wgpu::DeviceDescriptor* deviceDescriptor);
WGPUDevice CreateDevice(const WGPUDeviceDescriptor* deviceDescriptor = nullptr);
void RequestDevice(const DawnDeviceDescriptor* descriptor,
WGPURequestDeviceCallback callback,
void* userdata);
void RequestDevice(const wgpu::DeviceDescriptor* descriptor,
WGPURequestDeviceCallback callback,
void* userdata);
@@ -121,17 +118,35 @@ class DAWN_NATIVE_EXPORT Adapter {
AdapterBase* mImpl = nullptr;
};
// Base class for options passed to Instance::DiscoverAdapters.
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptionsBase {
// Base class for options passed to Instance::DiscoverPhysicalDevices.
struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptionsBase {
public:
const WGPUBackendType backendType;
protected:
explicit AdapterDiscoveryOptionsBase(WGPUBackendType type);
explicit PhysicalDeviceDiscoveryOptionsBase(WGPUBackendType type);
};
// Deprecated, use PhysicalDeviceDiscoveryOptionsBase instead.
// TODO(dawn:1774): Remove this.
using AdapterDiscoveryOptionsBase = PhysicalDeviceDiscoveryOptionsBase;
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).
//
@@ -145,15 +160,20 @@ class DAWN_NATIVE_EXPORT Instance {
Instance(const Instance& other) = delete;
Instance& operator=(const Instance& other) = delete;
// Gather all adapters in the system that can be accessed with no special options. These
// adapters will later be returned by GetAdapters.
void DiscoverDefaultAdapters();
// Gather all physical devices in the system that can be accessed with no special options.
void DiscoverDefaultPhysicalDevices();
// Adds adapters that can be discovered with the options provided (like a getProcAddress).
// The backend is chosen based on the type of the options used. Returns true on success.
// Adds physical devices that can be discovered with the options provided (like a
// getProcAddress). The backend is chosen based on the type of the options used. Returns true on
// success.
bool DiscoverPhysicalDevices(const PhysicalDeviceDiscoveryOptionsBase* options);
// Deprecated, use DiscoverDefaultPhysicalDevices and DiscoverPhysicalDevices instead.
// TODO(Dawn:1774): Remove these.
void DiscoverDefaultAdapters();
bool DiscoverAdapters(const AdapterDiscoveryOptionsBase* options);
// Returns all the adapters that the instance knows about.
// Returns a vector of adapters, one for each physical device the instance knows about.
std::vector<Adapter> GetAdapters() const;
const ToggleInfo* GetToggleInfo(const char* toggleName);
@@ -166,8 +186,8 @@ class DAWN_NATIVE_EXPORT Instance {
// Enable debug capture on Dawn startup
void EnableBeginCaptureOnStartup(bool beginCaptureOnStartup);
// TODO(dawn:1374) Deprecate this once it is passed via the descriptor.
void SetPlatform(dawn::platform::Platform* platform);
// Enable / disable the adapter blocklist.
void EnableAdapterBlocklist(bool enable);
uint64_t GetDeviceCountForTesting() const;
@@ -207,6 +227,8 @@ DAWN_NATIVE_EXPORT std::vector<const char*> GetProcMapNamesForTesting();
DAWN_NATIVE_EXPORT bool DeviceTick(WGPUDevice device);
DAWN_NATIVE_EXPORT bool InstanceProcessEvents(WGPUInstance instance);
// ErrorInjector functions used for testing only. Defined in dawn_native/ErrorInjector.cpp
DAWN_NATIVE_EXPORT void EnableErrorInjector();
DAWN_NATIVE_EXPORT void DisableErrorInjector();
@@ -221,6 +243,7 @@ enum ExternalImageType {
IOSurface,
DXGISharedHandle,
EGLImage,
AHardwareBuffer,
};
// Common properties of external images
@@ -237,12 +260,6 @@ struct DAWN_NATIVE_EXPORT ExternalImageDescriptor {
ExternalImageType mType;
};
struct DAWN_NATIVE_EXPORT ExternalImageAccessDescriptor {
public:
bool isInitialized = false; // Whether the texture is initialized on import
WGPUTextureUsageFlags usage = WGPUTextureUsage_None;
};
struct DAWN_NATIVE_EXPORT ExternalImageExportInfo {
public:
bool isInitialized = false; // Whether the texture is initialized after export
@@ -266,6 +283,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;

View File

@@ -15,7 +15,8 @@
#ifndef INCLUDE_DAWN_NATIVE_METALBACKEND_H_
#define INCLUDE_DAWN_NATIVE_METALBACKEND_H_
#include "dawn/dawn_wsi.h"
#include <vector>
#include "dawn/native/DawnNative.h"
// The specifics of the Metal backend expose types in function signatures that might not be
@@ -34,23 +35,52 @@ typedef __IOSurface* IOSurfaceRef;
namespace dawn::native::metal {
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
AdapterDiscoveryOptions();
struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions
: public PhysicalDeviceDiscoveryOptionsBase {
PhysicalDeviceDiscoveryOptions();
};
// TODO(dawn:1774): Deprecated.
using AdapterDiscoveryOptions = PhysicalDeviceDiscoveryOptions;
struct DAWN_NATIVE_EXPORT ExternalImageMTLSharedEventDescriptor {
// Shared event handle `id<MTLSharedEvent>`.
// This never passes ownership to the callee (when used as an input
// parameter) or to the caller (when used as a return value or output parameter).
#ifdef __OBJC__
id<MTLSharedEvent> sharedEvent = nil;
static_assert(sizeof(id<MTLSharedEvent>) == sizeof(void*));
static_assert(alignof(id<MTLSharedEvent>) == alignof(void*));
#else
void* sharedEvent = nullptr;
#endif
// The value that was previously signaled on this event and should be waited on.
uint64_t signaledValue = 0;
};
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorIOSurface : ExternalImageDescriptor {
public:
ExternalImageDescriptorIOSurface();
~ExternalImageDescriptorIOSurface();
IOSurfaceRef ioSurface;
// This has been deprecated.
uint32_t plane;
// A list of events to wait on before accessing the texture.
std::vector<ExternalImageMTLSharedEventDescriptor> waitEvents;
};
struct DAWN_NATIVE_EXPORT ExternalImageIOSurfaceEndAccessDescriptor
: ExternalImageMTLSharedEventDescriptor {
bool isInitialized;
};
DAWN_NATIVE_EXPORT WGPUTexture WrapIOSurface(WGPUDevice device,
const ExternalImageDescriptorIOSurface* descriptor);
DAWN_NATIVE_EXPORT void IOSurfaceEndAccess(WGPUTexture texture,
ExternalImageIOSurfaceEndAccessDescriptor* descriptor);
// When making Metal interop with other APIs, we need to be careful that QueueSubmit doesn't
// mean that the operations will be visible to other APIs/Metal devices right away. macOS
// does have a global queue of graphics operations, but the command buffers are inserted there

View File

@@ -15,11 +15,12 @@
#ifndef INCLUDE_DAWN_NATIVE_NULLBACKEND_H_
#define INCLUDE_DAWN_NATIVE_NULLBACKEND_H_
#include "dawn/dawn_wsi.h"
#include "dawn/native/DawnNative.h"
namespace dawn::native::null {
DAWN_NATIVE_EXPORT DawnSwapChainImplementation CreateNativeSwapChainImpl();
// Nothing for now \o/
} // namespace dawn::native::null
#endif // INCLUDE_DAWN_NATIVE_NULLBACKEND_H_

View File

@@ -17,13 +17,13 @@
typedef void* EGLImage;
#include "dawn/dawn_wsi.h"
#include "dawn/native/DawnNative.h"
namespace dawn::native::opengl {
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
explicit AdapterDiscoveryOptions(WGPUBackendType type);
struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions
: public PhysicalDeviceDiscoveryOptionsBase {
explicit PhysicalDeviceDiscoveryOptions(WGPUBackendType type);
void* (*getProc)(const char*);
// Context
@@ -32,18 +32,14 @@ struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptio
void* userData;
};
// TODO(dawn:1774): Deprecated.
using AdapterDiscoveryOptions = PhysicalDeviceDiscoveryOptions;
// TODO(crbug.com/dawn/810): This struct can be removed once Chrome is no longer using it.
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptionsES : public AdapterDiscoveryOptions {
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptionsES : public PhysicalDeviceDiscoveryOptions {
AdapterDiscoveryOptionsES();
};
using PresentCallback = void (*)(void*);
DAWN_NATIVE_EXPORT DawnSwapChainImplementation CreateNativeSwapChainImpl(WGPUDevice device,
PresentCallback present,
void* presentUserdata);
DAWN_NATIVE_EXPORT WGPUTextureFormat
GetNativeSwapChainPreferredFormat(const DawnSwapChainImplementation* swapChain);
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorEGLImage : ExternalImageDescriptor {
public:
ExternalImageDescriptorEGLImage();

View File

@@ -20,7 +20,6 @@
#include <array>
#include <vector>
#include "dawn/dawn_wsi.h"
#include "dawn/native/DawnNative.h"
namespace dawn::native::vulkan {
@@ -29,17 +28,23 @@ DAWN_NATIVE_EXPORT VkInstance GetInstance(WGPUDevice device);
DAWN_NATIVE_EXPORT PFN_vkVoidFunction GetInstanceProcAddr(WGPUDevice device, const char* pName);
DAWN_NATIVE_EXPORT DawnSwapChainImplementation CreateNativeSwapChainImpl(WGPUDevice device,
::VkSurfaceKHR surface);
DAWN_NATIVE_EXPORT WGPUTextureFormat
GetNativeSwapChainPreferredFormat(const DawnSwapChainImplementation* swapChain);
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
AdapterDiscoveryOptions();
struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions
: public PhysicalDeviceDiscoveryOptionsBase {
PhysicalDeviceDiscoveryOptions();
bool forceSwiftShader = false;
};
// TODO(dawn:1774): Deprecated.
using AdapterDiscoveryOptions = PhysicalDeviceDiscoveryOptions;
enum class NeedsDedicatedAllocation {
Yes,
No,
// Use Vulkan reflection to detect whether a dedicated allocation is needed.
Detect,
};
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorVk : ExternalImageDescriptor {
public:
// The following members may be ignored if |ExternalImageDescriptor::isInitialized| is false
@@ -54,6 +59,11 @@ struct DAWN_NATIVE_EXPORT ExternalImageDescriptorVk : ExternalImageDescriptor {
VkImageLayout releasedOldLayout = VK_IMAGE_LAYOUT_GENERAL;
VkImageLayout releasedNewLayout = VK_IMAGE_LAYOUT_GENERAL;
// Try to detect the need to use a dedicated allocation for imported images by default but let
// the application override this as drivers have bugs and forget to require a dedicated
// allocation.
NeedsDedicatedAllocation dedicatedAllocation = NeedsDedicatedAllocation::Detect;
protected:
using ExternalImageDescriptor::ExternalImageDescriptor;
};
@@ -126,6 +136,26 @@ struct DAWN_NATIVE_EXPORT ExternalImageExportInfoDmaBuf : ExternalImageExportInf
ExternalImageExportInfoDmaBuf();
};
#ifdef __ANDROID__
// Descriptor for AHardwareBuffer image import
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorAHardwareBuffer : ExternalImageDescriptorVk {
public:
ExternalImageDescriptorAHardwareBuffer();
struct AHardwareBuffer* handle; // The AHardwareBuffer which contains the memory of the image
std::vector<int> waitFDs; // File descriptors of semaphores which will be waited on
protected:
using ExternalImageDescriptorVk::ExternalImageDescriptorVk;
};
struct DAWN_NATIVE_EXPORT ExternalImageExportInfoAHardwareBuffer : ExternalImageExportInfoFD {
ExternalImageExportInfoAHardwareBuffer();
};
#endif // __ANDROID__
#endif // __linux__
// Imports external memory into a Vulkan image. Internally, this uses external memory /
@@ -142,6 +172,8 @@ DAWN_NATIVE_EXPORT WGPUTexture WrapVulkanImage(WGPUDevice device,
DAWN_NATIVE_EXPORT bool ExportVulkanImage(WGPUTexture texture,
VkImageLayout desiredLayout,
ExternalImageExportInfoVk* info);
// |ExportVulkanImage| with default desiredLayout of VK_IMAGE_LAYOUT_UNDEFINED.
DAWN_NATIVE_EXPORT bool ExportVulkanImage(WGPUTexture texture, ExternalImageExportInfoVk* info);
} // namespace dawn::native::vulkan