mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-09 21:47:47 +00:00
tint->dawn: Move src/dawn_native -> src/dawn/native
Bug: dawn:1275 Change-Id: Ic60a00107a015bc677ff929c492f1085ffc38482 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/79083 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Ben Clayton <bclayton@chromium.org>
This commit is contained in:
committed by
Dawn LUCI CQ
parent
b2c4d7a244
commit
818001d32e
111
src/include/dawn/native/D3D12Backend.h
Normal file
111
src/include/dawn/native/D3D12Backend.h
Normal file
@@ -0,0 +1,111 @@
|
||||
// Copyright 2018 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 DAWNNATIVE_D3D12BACKEND_H_
|
||||
#define DAWNNATIVE_D3D12BACKEND_H_
|
||||
|
||||
#include <dawn/dawn_wsi.h>
|
||||
#include <dawn/native/DawnNative.h>
|
||||
|
||||
#include <DXGI1_4.h>
|
||||
#include <d3d12.h>
|
||||
#include <windows.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct ID3D12Device;
|
||||
struct ID3D12Resource;
|
||||
|
||||
namespace dawn::native::d3d12 {
|
||||
|
||||
class D3D11on12ResourceCache;
|
||||
|
||||
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,
|
||||
NonLocal,
|
||||
};
|
||||
|
||||
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.
|
||||
HANDLE sharedHandle;
|
||||
};
|
||||
|
||||
// Keyed mutex acquire/release uses a fixed key of 0 to match Chromium behavior.
|
||||
constexpr UINT64 kDXGIKeyedMutexAcquireReleaseKey = 0;
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageAccessDescriptorDXGIKeyedMutex
|
||||
: ExternalImageAccessDescriptor {
|
||||
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;
|
||||
bool isSwapChainTexture = false;
|
||||
};
|
||||
|
||||
class DAWN_NATIVE_EXPORT ExternalImageDXGI {
|
||||
public:
|
||||
~ExternalImageDXGI();
|
||||
|
||||
// Note: SharedHandle must be a handle to a texture object.
|
||||
static std::unique_ptr<ExternalImageDXGI> Create(
|
||||
WGPUDevice device,
|
||||
const ExternalImageDescriptorDXGISharedHandle* descriptor);
|
||||
|
||||
WGPUTexture ProduceTexture(WGPUDevice device,
|
||||
const ExternalImageAccessDescriptorDXGIKeyedMutex* descriptor);
|
||||
|
||||
private:
|
||||
ExternalImageDXGI(Microsoft::WRL::ComPtr<ID3D12Resource> d3d12Resource,
|
||||
const WGPUTextureDescriptor* descriptor);
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D12Resource> mD3D12Resource;
|
||||
|
||||
// Contents of WGPUTextureDescriptor are stored individually since the descriptor
|
||||
// could outlive this image.
|
||||
WGPUTextureUsageFlags mUsage;
|
||||
WGPUTextureUsageFlags mUsageInternal = WGPUTextureUsage_None;
|
||||
WGPUTextureDimension mDimension;
|
||||
WGPUExtent3D mSize;
|
||||
WGPUTextureFormat mFormat;
|
||||
uint32_t mMipLevelCount;
|
||||
uint32_t mSampleCount;
|
||||
|
||||
std::unique_ptr<D3D11on12ResourceCache> mD3D11on12ResourceCache;
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
|
||||
AdapterDiscoveryOptions();
|
||||
AdapterDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
|
||||
|
||||
Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter;
|
||||
};
|
||||
|
||||
} // namespace dawn::native::d3d12
|
||||
|
||||
#endif // DAWNNATIVE_D3D12BACKEND_H_
|
||||
261
src/include/dawn/native/DawnNative.h
Normal file
261
src/include/dawn/native/DawnNative.h
Normal file
@@ -0,0 +1,261 @@
|
||||
// Copyright 2018 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 DAWNNATIVE_DAWNNATIVE_H_
|
||||
#define DAWNNATIVE_DAWNNATIVE_H_
|
||||
|
||||
#include <dawn/dawn_proc_table.h>
|
||||
#include <dawn/native/dawn_native_export.h>
|
||||
#include <dawn/webgpu.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace dawn::platform {
|
||||
class Platform;
|
||||
} // namespace dawn::platform
|
||||
|
||||
namespace wgpu {
|
||||
struct AdapterProperties;
|
||||
struct DeviceDescriptor;
|
||||
} // namespace wgpu
|
||||
|
||||
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 {
|
||||
std::vector<const char*> requiredFeatures;
|
||||
std::vector<const char*> forceEnabledToggles;
|
||||
std::vector<const char*> forceDisabledToggles;
|
||||
|
||||
const WGPURequiredLimits* requiredLimits = nullptr;
|
||||
};
|
||||
|
||||
// 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
|
||||
// features and optimizations.
|
||||
struct ToggleInfo {
|
||||
const char* name;
|
||||
const char* description;
|
||||
const char* url;
|
||||
};
|
||||
|
||||
// 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;
|
||||
|
||||
// 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
|
||||
// same GPU can be represented by multiple adapters but on different APIs.
|
||||
//
|
||||
// The underlying Dawn adapter is owned by the Dawn instance so this class is not RAII but just
|
||||
// a reference to an underlying adapter.
|
||||
class DAWN_NATIVE_EXPORT Adapter {
|
||||
public:
|
||||
Adapter();
|
||||
Adapter(AdapterBase* impl);
|
||||
~Adapter();
|
||||
|
||||
Adapter(const Adapter& other);
|
||||
Adapter& operator=(const Adapter& other);
|
||||
|
||||
// Essentially webgpu.h's wgpuAdapterGetProperties while we don't have WGPUAdapter in
|
||||
// dawn.json
|
||||
void GetProperties(wgpu::AdapterProperties* properties) const;
|
||||
void GetProperties(WGPUAdapterProperties* properties) const;
|
||||
|
||||
std::vector<const char*> GetSupportedExtensions() const;
|
||||
std::vector<const char*> GetSupportedFeatures() const;
|
||||
WGPUDeviceProperties GetAdapterProperties() const;
|
||||
bool GetLimits(WGPUSupportedLimits* limits) const;
|
||||
|
||||
void SetUseTieredLimits(bool useTieredLimits);
|
||||
|
||||
// Check that the Adapter is able to support importing external images. This is necessary
|
||||
// to implement the swapchain and interop APIs in Chromium.
|
||||
bool SupportsExternalImages() const;
|
||||
|
||||
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);
|
||||
void RequestDevice(const WGPUDeviceDescriptor* descriptor,
|
||||
WGPURequestDeviceCallback callback,
|
||||
void* userdata);
|
||||
|
||||
// Returns the underlying WGPUAdapter object.
|
||||
WGPUAdapter Get() const;
|
||||
|
||||
// Reset the backend device object for testing purposes.
|
||||
void ResetInternalDeviceForTesting();
|
||||
|
||||
private:
|
||||
AdapterBase* mImpl = nullptr;
|
||||
};
|
||||
|
||||
// Base class for options passed to Instance::DiscoverAdapters.
|
||||
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptionsBase {
|
||||
public:
|
||||
const WGPUBackendType backendType;
|
||||
|
||||
protected:
|
||||
AdapterDiscoveryOptionsBase(WGPUBackendType type);
|
||||
};
|
||||
|
||||
enum BackendValidationLevel { Full, Partial, Disabled };
|
||||
|
||||
// Represents a connection to dawn_native and is used for dependency injection, discovering
|
||||
// system adapters and injecting custom adapters (like a Swiftshader Vulkan adapter).
|
||||
//
|
||||
// This is an RAII class for Dawn instances and also controls the lifetime of all adapters
|
||||
// for this instance.
|
||||
class DAWN_NATIVE_EXPORT Instance {
|
||||
public:
|
||||
explicit Instance(const WGPUInstanceDescriptor* desc = nullptr);
|
||||
~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();
|
||||
|
||||
// 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.
|
||||
bool DiscoverAdapters(const AdapterDiscoveryOptionsBase* options);
|
||||
|
||||
// Returns all the adapters that the instance knows about.
|
||||
std::vector<Adapter> GetAdapters() const;
|
||||
|
||||
const ToggleInfo* GetToggleInfo(const char* toggleName);
|
||||
const FeatureInfo* GetFeatureInfo(WGPUFeatureName feature);
|
||||
|
||||
// Enables backend validation layers
|
||||
void EnableBackendValidation(bool enableBackendValidation);
|
||||
void SetBackendValidationLevel(BackendValidationLevel validationLevel);
|
||||
|
||||
// Enable debug capture on Dawn startup
|
||||
void EnableBeginCaptureOnStartup(bool beginCaptureOnStartup);
|
||||
|
||||
void SetPlatform(dawn::platform::Platform* platform);
|
||||
|
||||
// Returns the underlying WGPUInstance object.
|
||||
WGPUInstance Get() const;
|
||||
|
||||
private:
|
||||
InstanceBase* mImpl = nullptr;
|
||||
};
|
||||
|
||||
// Backend-agnostic API for dawn_native
|
||||
DAWN_NATIVE_EXPORT const DawnProcTable& GetProcs();
|
||||
|
||||
// Query the names of all the toggles that are enabled in device
|
||||
DAWN_NATIVE_EXPORT std::vector<const char*> GetTogglesUsed(WGPUDevice device);
|
||||
|
||||
// Backdoor to get the number of lazy clears for testing
|
||||
DAWN_NATIVE_EXPORT size_t GetLazyClearCountForTesting(WGPUDevice device);
|
||||
|
||||
// Backdoor to get the number of deprecation warnings for testing
|
||||
DAWN_NATIVE_EXPORT size_t GetDeprecationWarningCountForTesting(WGPUDevice device);
|
||||
|
||||
// Query if texture has been initialized
|
||||
DAWN_NATIVE_EXPORT bool IsTextureSubresourceInitialized(
|
||||
WGPUTexture texture,
|
||||
uint32_t baseMipLevel,
|
||||
uint32_t levelCount,
|
||||
uint32_t baseArrayLayer,
|
||||
uint32_t layerCount,
|
||||
WGPUTextureAspect aspect = WGPUTextureAspect_All);
|
||||
|
||||
// Backdoor to get the order of the ProcMap for testing
|
||||
DAWN_NATIVE_EXPORT std::vector<const char*> GetProcMapNamesForTesting();
|
||||
|
||||
DAWN_NATIVE_EXPORT bool DeviceTick(WGPUDevice device);
|
||||
|
||||
// ErrorInjector functions used for testing only. Defined in dawn_native/ErrorInjector.cpp
|
||||
DAWN_NATIVE_EXPORT void EnableErrorInjector();
|
||||
DAWN_NATIVE_EXPORT void DisableErrorInjector();
|
||||
DAWN_NATIVE_EXPORT void ClearErrorInjector();
|
||||
DAWN_NATIVE_EXPORT uint64_t AcquireErrorInjectorCallCount();
|
||||
DAWN_NATIVE_EXPORT void InjectErrorAt(uint64_t index);
|
||||
|
||||
// The different types of external images
|
||||
enum ExternalImageType {
|
||||
OpaqueFD,
|
||||
DmaBuf,
|
||||
IOSurface,
|
||||
DXGISharedHandle,
|
||||
EGLImage,
|
||||
};
|
||||
|
||||
// Common properties of external images
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageDescriptor {
|
||||
public:
|
||||
const WGPUTextureDescriptor* cTextureDescriptor; // Must match image creation params
|
||||
bool isInitialized; // Whether the texture is initialized on import
|
||||
ExternalImageType GetType() const;
|
||||
|
||||
protected:
|
||||
ExternalImageDescriptor(ExternalImageType type);
|
||||
|
||||
private:
|
||||
ExternalImageType mType;
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageAccessDescriptor {
|
||||
public:
|
||||
bool isInitialized; // Whether the texture is initialized on import
|
||||
WGPUTextureUsageFlags usage;
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageExportInfo {
|
||||
public:
|
||||
bool isInitialized; // Whether the texture is initialized after export
|
||||
ExternalImageType GetType() const;
|
||||
|
||||
protected:
|
||||
ExternalImageExportInfo(ExternalImageType type);
|
||||
|
||||
private:
|
||||
ExternalImageType mType;
|
||||
};
|
||||
|
||||
DAWN_NATIVE_EXPORT const char* GetObjectLabelForTesting(void* objectHandle);
|
||||
|
||||
DAWN_NATIVE_EXPORT uint64_t GetAllocatedSizeForTesting(WGPUBuffer buffer);
|
||||
|
||||
DAWN_NATIVE_EXPORT bool BindGroupLayoutBindingsEqualForTesting(WGPUBindGroupLayout a,
|
||||
WGPUBindGroupLayout b);
|
||||
|
||||
} // namespace dawn::native
|
||||
|
||||
// TODO(dawn:824): Remove once the deprecation period is passed.
|
||||
namespace dawn_native = dawn::native;
|
||||
|
||||
#endif // DAWNNATIVE_DAWNNATIVE_H_
|
||||
71
src/include/dawn/native/MetalBackend.h
Normal file
71
src/include/dawn/native/MetalBackend.h
Normal file
@@ -0,0 +1,71 @@
|
||||
// Copyright 2018 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 DAWNNATIVE_METALBACKEND_H_
|
||||
#define DAWNNATIVE_METALBACKEND_H_
|
||||
|
||||
#include <dawn/dawn_wsi.h>
|
||||
#include <dawn/native/DawnNative.h>
|
||||
|
||||
// The specifics of the Metal backend expose types in function signatures that might not be
|
||||
// available in dependent's minimum supported SDK version. Suppress all availability errors using
|
||||
// clang's pragmas. Dependents using the types without guarded availability will still get errors
|
||||
// when using the types.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunguarded-availability"
|
||||
|
||||
struct __IOSurface;
|
||||
typedef __IOSurface* IOSurfaceRef;
|
||||
|
||||
#ifdef __OBJC__
|
||||
# import <Metal/Metal.h>
|
||||
#endif //__OBJC__
|
||||
|
||||
namespace dawn::native::metal {
|
||||
|
||||
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
|
||||
AdapterDiscoveryOptions();
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorIOSurface : ExternalImageDescriptor {
|
||||
public:
|
||||
ExternalImageDescriptorIOSurface();
|
||||
|
||||
IOSurfaceRef ioSurface;
|
||||
uint32_t plane;
|
||||
};
|
||||
|
||||
DAWN_NATIVE_EXPORT WGPUTexture
|
||||
WrapIOSurface(WGPUDevice device, const ExternalImageDescriptorIOSurface* 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
|
||||
// when they are "scheduled". Submitting other operations before the command buffer is
|
||||
// scheduled could lead to races in who gets scheduled first and incorrect rendering.
|
||||
DAWN_NATIVE_EXPORT void WaitForCommandsToBeScheduled(WGPUDevice device);
|
||||
|
||||
} // namespace dawn::native::metal
|
||||
|
||||
#ifdef __OBJC__
|
||||
namespace dawn::native::metal {
|
||||
|
||||
DAWN_NATIVE_EXPORT id<MTLDevice> GetMetalDevice(WGPUDevice device);
|
||||
|
||||
} // namespace dawn::native::metal
|
||||
#endif // __OBJC__
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
#endif // DAWNNATIVE_METALBACKEND_H_
|
||||
25
src/include/dawn/native/NullBackend.h
Normal file
25
src/include/dawn/native/NullBackend.h
Normal file
@@ -0,0 +1,25 @@
|
||||
// Copyright 2018 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 DAWNNATIVE_NULLBACKEND_H_
|
||||
#define DAWNNATIVE_NULLBACKEND_H_
|
||||
|
||||
#include <dawn/dawn_wsi.h>
|
||||
#include <dawn/native/DawnNative.h>
|
||||
|
||||
namespace dawn::native::null {
|
||||
DAWN_NATIVE_EXPORT DawnSwapChainImplementation CreateNativeSwapChainImpl();
|
||||
} // namespace dawn::native::null
|
||||
|
||||
#endif // DAWNNATIVE_NULLBACKEND_H_
|
||||
55
src/include/dawn/native/OpenGLBackend.h
Normal file
55
src/include/dawn/native/OpenGLBackend.h
Normal file
@@ -0,0 +1,55 @@
|
||||
// Copyright 2018 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 DAWNNATIVE_OPENGLBACKEND_H_
|
||||
#define DAWNNATIVE_OPENGLBACKEND_H_
|
||||
|
||||
typedef void* EGLImage;
|
||||
|
||||
#include <dawn/dawn_wsi.h>
|
||||
#include <dawn/native/DawnNative.h>
|
||||
|
||||
namespace dawn::native::opengl {
|
||||
|
||||
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
|
||||
AdapterDiscoveryOptions();
|
||||
|
||||
void* (*getProc)(const char*);
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptionsES : public AdapterDiscoveryOptionsBase {
|
||||
AdapterDiscoveryOptionsES();
|
||||
|
||||
void* (*getProc)(const char*);
|
||||
};
|
||||
|
||||
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();
|
||||
|
||||
::EGLImage image;
|
||||
};
|
||||
|
||||
DAWN_NATIVE_EXPORT WGPUTexture
|
||||
WrapExternalEGLImage(WGPUDevice device, const ExternalImageDescriptorEGLImage* descriptor);
|
||||
|
||||
} // namespace dawn::native::opengl
|
||||
|
||||
#endif // DAWNNATIVE_OPENGLBACKEND_H_
|
||||
140
src/include/dawn/native/VulkanBackend.h
Normal file
140
src/include/dawn/native/VulkanBackend.h
Normal file
@@ -0,0 +1,140 @@
|
||||
// Copyright 2018 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 DAWNNATIVE_VULKANBACKEND_H_
|
||||
#define DAWNNATIVE_VULKANBACKEND_H_
|
||||
|
||||
#include <dawn/dawn_wsi.h>
|
||||
#include <dawn/native/DawnNative.h>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace dawn::native::vulkan {
|
||||
|
||||
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();
|
||||
|
||||
bool forceSwiftShader = false;
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorVk : ExternalImageDescriptor {
|
||||
public:
|
||||
// The following members may be ignored if |ExternalImageDescriptor::isInitialized| is false
|
||||
// since the import does not need to preserve texture contents.
|
||||
|
||||
// See https://www.khronos.org/registry/vulkan/specs/1.1/html/chap7.html. The acquire
|
||||
// operation old/new layouts must match exactly the layouts in the release operation. So
|
||||
// we may need to issue two barriers releasedOldLayout -> releasedNewLayout ->
|
||||
// cTextureDescriptor.usage if the new layout is not compatible with the desired usage.
|
||||
// The first barrier is the queue transfer, the second is the layout transition to our
|
||||
// desired usage.
|
||||
VkImageLayout releasedOldLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
VkImageLayout releasedNewLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
|
||||
protected:
|
||||
using ExternalImageDescriptor::ExternalImageDescriptor;
|
||||
};
|
||||
|
||||
struct ExternalImageExportInfoVk : ExternalImageExportInfo {
|
||||
public:
|
||||
// See comments in |ExternalImageDescriptorVk|
|
||||
// Contains the old/new layouts used in the queue release operation.
|
||||
VkImageLayout releasedOldLayout;
|
||||
VkImageLayout releasedNewLayout;
|
||||
|
||||
protected:
|
||||
using ExternalImageExportInfo::ExternalImageExportInfo;
|
||||
};
|
||||
|
||||
// Can't use DAWN_PLATFORM_LINUX since header included in both Dawn and Chrome
|
||||
#ifdef __linux__
|
||||
|
||||
// Common properties of external images represented by FDs. On successful import the file
|
||||
// descriptor's ownership is transferred to the Dawn implementation and they shouldn't be
|
||||
// used outside of Dawn again. TODO(enga): Also transfer ownership in the error case so the
|
||||
// caller can assume the FD is always consumed.
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorFD : ExternalImageDescriptorVk {
|
||||
public:
|
||||
int memoryFD; // A file descriptor from an export of the memory of the image
|
||||
std::vector<int> waitFDs; // File descriptors of semaphores which will be waited on
|
||||
|
||||
protected:
|
||||
using ExternalImageDescriptorVk::ExternalImageDescriptorVk;
|
||||
};
|
||||
|
||||
// Descriptor for opaque file descriptor image import
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorOpaqueFD : ExternalImageDescriptorFD {
|
||||
ExternalImageDescriptorOpaqueFD();
|
||||
|
||||
VkDeviceSize allocationSize; // Must match VkMemoryAllocateInfo from image creation
|
||||
uint32_t memoryTypeIndex; // Must match VkMemoryAllocateInfo from image creation
|
||||
};
|
||||
|
||||
// Descriptor for dma-buf file descriptor image import
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorDmaBuf : ExternalImageDescriptorFD {
|
||||
ExternalImageDescriptorDmaBuf();
|
||||
|
||||
uint32_t stride; // Stride of the buffer in bytes
|
||||
uint64_t drmModifier; // DRM modifier of the buffer
|
||||
};
|
||||
|
||||
// Info struct that is written to in |ExportVulkanImage|.
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageExportInfoFD : ExternalImageExportInfoVk {
|
||||
public:
|
||||
// Contains the exported semaphore handles.
|
||||
std::vector<int> semaphoreHandles;
|
||||
|
||||
protected:
|
||||
using ExternalImageExportInfoVk::ExternalImageExportInfoVk;
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageExportInfoOpaqueFD : ExternalImageExportInfoFD {
|
||||
ExternalImageExportInfoOpaqueFD();
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageExportInfoDmaBuf : ExternalImageExportInfoFD {
|
||||
ExternalImageExportInfoDmaBuf();
|
||||
};
|
||||
|
||||
#endif // __linux__
|
||||
|
||||
// Imports external memory into a Vulkan image. Internally, this uses external memory /
|
||||
// semaphore extensions to import the image and wait on the provided synchronizaton
|
||||
// primitives before the texture can be used.
|
||||
// On failure, returns a nullptr.
|
||||
DAWN_NATIVE_EXPORT WGPUTexture WrapVulkanImage(WGPUDevice device,
|
||||
const ExternalImageDescriptorVk* descriptor);
|
||||
|
||||
// Exports external memory from a Vulkan image. This must be called on wrapped textures
|
||||
// before they are destroyed. It writes the semaphore to wait on and the old/new image
|
||||
// layouts to |info|. Pass VK_IMAGE_LAYOUT_UNDEFINED as |desiredLayout| if you don't want to
|
||||
// perform a layout transition.
|
||||
DAWN_NATIVE_EXPORT bool ExportVulkanImage(WGPUTexture texture,
|
||||
VkImageLayout desiredLayout,
|
||||
ExternalImageExportInfoVk* info);
|
||||
|
||||
} // namespace dawn::native::vulkan
|
||||
|
||||
#endif // DAWNNATIVE_VULKANBACKEND_H_
|
||||
36
src/include/dawn/native/dawn_native_export.h
Normal file
36
src/include/dawn/native/dawn_native_export.h
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright 2018 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 DAWNNATIVE_EXPORT_H_
|
||||
#define DAWNNATIVE_EXPORT_H_
|
||||
|
||||
#if defined(DAWN_NATIVE_SHARED_LIBRARY)
|
||||
# if defined(_WIN32)
|
||||
# if defined(DAWN_NATIVE_IMPLEMENTATION)
|
||||
# define DAWN_NATIVE_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define DAWN_NATIVE_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
# else // defined(_WIN32)
|
||||
# if defined(DAWN_NATIVE_IMPLEMENTATION)
|
||||
# define DAWN_NATIVE_EXPORT __attribute__((visibility("default")))
|
||||
# else
|
||||
# define DAWN_NATIVE_EXPORT
|
||||
# endif
|
||||
# endif // defined(_WIN32)
|
||||
#else // defined(DAWN_NATIVE_SHARED_LIBRARY)
|
||||
# define DAWN_NATIVE_EXPORT
|
||||
#endif // defined(DAWN_NATIVE_SHARED_LIBRARY)
|
||||
|
||||
#endif // DAWNNATIVE_EXPORT_H_
|
||||
@@ -1,111 +1 @@
|
||||
// Copyright 2018 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 DAWNNATIVE_D3D12BACKEND_H_
|
||||
#define DAWNNATIVE_D3D12BACKEND_H_
|
||||
|
||||
#include <dawn/dawn_wsi.h>
|
||||
#include <dawn_native/DawnNative.h>
|
||||
|
||||
#include <DXGI1_4.h>
|
||||
#include <d3d12.h>
|
||||
#include <windows.h>
|
||||
#include <wrl/client.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
struct ID3D12Device;
|
||||
struct ID3D12Resource;
|
||||
|
||||
namespace dawn::native::d3d12 {
|
||||
|
||||
class D3D11on12ResourceCache;
|
||||
|
||||
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,
|
||||
NonLocal,
|
||||
};
|
||||
|
||||
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.
|
||||
HANDLE sharedHandle;
|
||||
};
|
||||
|
||||
// Keyed mutex acquire/release uses a fixed key of 0 to match Chromium behavior.
|
||||
constexpr UINT64 kDXGIKeyedMutexAcquireReleaseKey = 0;
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageAccessDescriptorDXGIKeyedMutex
|
||||
: ExternalImageAccessDescriptor {
|
||||
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;
|
||||
bool isSwapChainTexture = false;
|
||||
};
|
||||
|
||||
class DAWN_NATIVE_EXPORT ExternalImageDXGI {
|
||||
public:
|
||||
~ExternalImageDXGI();
|
||||
|
||||
// Note: SharedHandle must be a handle to a texture object.
|
||||
static std::unique_ptr<ExternalImageDXGI> Create(
|
||||
WGPUDevice device,
|
||||
const ExternalImageDescriptorDXGISharedHandle* descriptor);
|
||||
|
||||
WGPUTexture ProduceTexture(WGPUDevice device,
|
||||
const ExternalImageAccessDescriptorDXGIKeyedMutex* descriptor);
|
||||
|
||||
private:
|
||||
ExternalImageDXGI(Microsoft::WRL::ComPtr<ID3D12Resource> d3d12Resource,
|
||||
const WGPUTextureDescriptor* descriptor);
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D12Resource> mD3D12Resource;
|
||||
|
||||
// Contents of WGPUTextureDescriptor are stored individually since the descriptor
|
||||
// could outlive this image.
|
||||
WGPUTextureUsageFlags mUsage;
|
||||
WGPUTextureUsageFlags mUsageInternal = WGPUTextureUsage_None;
|
||||
WGPUTextureDimension mDimension;
|
||||
WGPUExtent3D mSize;
|
||||
WGPUTextureFormat mFormat;
|
||||
uint32_t mMipLevelCount;
|
||||
uint32_t mSampleCount;
|
||||
|
||||
std::unique_ptr<D3D11on12ResourceCache> mD3D11on12ResourceCache;
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
|
||||
AdapterDiscoveryOptions();
|
||||
AdapterDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
|
||||
|
||||
Microsoft::WRL::ComPtr<IDXGIAdapter> dxgiAdapter;
|
||||
};
|
||||
|
||||
} // namespace dawn::native::d3d12
|
||||
|
||||
#endif // DAWNNATIVE_D3D12BACKEND_H_
|
||||
#include <dawn/native/D3D12Backend.h>
|
||||
|
||||
@@ -1,261 +1 @@
|
||||
// Copyright 2018 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 DAWNNATIVE_DAWNNATIVE_H_
|
||||
#define DAWNNATIVE_DAWNNATIVE_H_
|
||||
|
||||
#include <dawn/dawn_proc_table.h>
|
||||
#include <dawn/webgpu.h>
|
||||
#include <dawn_native/dawn_native_export.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace dawn::platform {
|
||||
class Platform;
|
||||
} // namespace dawn::platform
|
||||
|
||||
namespace wgpu {
|
||||
struct AdapterProperties;
|
||||
struct DeviceDescriptor;
|
||||
}
|
||||
|
||||
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 {
|
||||
std::vector<const char*> requiredFeatures;
|
||||
std::vector<const char*> forceEnabledToggles;
|
||||
std::vector<const char*> forceDisabledToggles;
|
||||
|
||||
const WGPURequiredLimits* requiredLimits = nullptr;
|
||||
};
|
||||
|
||||
// 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
|
||||
// features and optimizations.
|
||||
struct ToggleInfo {
|
||||
const char* name;
|
||||
const char* description;
|
||||
const char* url;
|
||||
};
|
||||
|
||||
// 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;
|
||||
|
||||
// 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
|
||||
// same GPU can be represented by multiple adapters but on different APIs.
|
||||
//
|
||||
// The underlying Dawn adapter is owned by the Dawn instance so this class is not RAII but just
|
||||
// a reference to an underlying adapter.
|
||||
class DAWN_NATIVE_EXPORT Adapter {
|
||||
public:
|
||||
Adapter();
|
||||
Adapter(AdapterBase* impl);
|
||||
~Adapter();
|
||||
|
||||
Adapter(const Adapter& other);
|
||||
Adapter& operator=(const Adapter& other);
|
||||
|
||||
// Essentially webgpu.h's wgpuAdapterGetProperties while we don't have WGPUAdapter in
|
||||
// dawn.json
|
||||
void GetProperties(wgpu::AdapterProperties* properties) const;
|
||||
void GetProperties(WGPUAdapterProperties* properties) const;
|
||||
|
||||
std::vector<const char*> GetSupportedExtensions() const;
|
||||
std::vector<const char*> GetSupportedFeatures() const;
|
||||
WGPUDeviceProperties GetAdapterProperties() const;
|
||||
bool GetLimits(WGPUSupportedLimits* limits) const;
|
||||
|
||||
void SetUseTieredLimits(bool useTieredLimits);
|
||||
|
||||
// Check that the Adapter is able to support importing external images. This is necessary
|
||||
// to implement the swapchain and interop APIs in Chromium.
|
||||
bool SupportsExternalImages() const;
|
||||
|
||||
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);
|
||||
void RequestDevice(const WGPUDeviceDescriptor* descriptor,
|
||||
WGPURequestDeviceCallback callback,
|
||||
void* userdata);
|
||||
|
||||
// Returns the underlying WGPUAdapter object.
|
||||
WGPUAdapter Get() const;
|
||||
|
||||
// Reset the backend device object for testing purposes.
|
||||
void ResetInternalDeviceForTesting();
|
||||
|
||||
private:
|
||||
AdapterBase* mImpl = nullptr;
|
||||
};
|
||||
|
||||
// Base class for options passed to Instance::DiscoverAdapters.
|
||||
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptionsBase {
|
||||
public:
|
||||
const WGPUBackendType backendType;
|
||||
|
||||
protected:
|
||||
AdapterDiscoveryOptionsBase(WGPUBackendType type);
|
||||
};
|
||||
|
||||
enum BackendValidationLevel { Full, Partial, Disabled };
|
||||
|
||||
// Represents a connection to dawn_native and is used for dependency injection, discovering
|
||||
// system adapters and injecting custom adapters (like a Swiftshader Vulkan adapter).
|
||||
//
|
||||
// This is an RAII class for Dawn instances and also controls the lifetime of all adapters
|
||||
// for this instance.
|
||||
class DAWN_NATIVE_EXPORT Instance {
|
||||
public:
|
||||
explicit Instance(const WGPUInstanceDescriptor* desc = nullptr);
|
||||
~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();
|
||||
|
||||
// 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.
|
||||
bool DiscoverAdapters(const AdapterDiscoveryOptionsBase* options);
|
||||
|
||||
// Returns all the adapters that the instance knows about.
|
||||
std::vector<Adapter> GetAdapters() const;
|
||||
|
||||
const ToggleInfo* GetToggleInfo(const char* toggleName);
|
||||
const FeatureInfo* GetFeatureInfo(WGPUFeatureName feature);
|
||||
|
||||
// Enables backend validation layers
|
||||
void EnableBackendValidation(bool enableBackendValidation);
|
||||
void SetBackendValidationLevel(BackendValidationLevel validationLevel);
|
||||
|
||||
// Enable debug capture on Dawn startup
|
||||
void EnableBeginCaptureOnStartup(bool beginCaptureOnStartup);
|
||||
|
||||
void SetPlatform(dawn::platform::Platform* platform);
|
||||
|
||||
// Returns the underlying WGPUInstance object.
|
||||
WGPUInstance Get() const;
|
||||
|
||||
private:
|
||||
InstanceBase* mImpl = nullptr;
|
||||
};
|
||||
|
||||
// Backend-agnostic API for dawn_native
|
||||
DAWN_NATIVE_EXPORT const DawnProcTable& GetProcs();
|
||||
|
||||
// Query the names of all the toggles that are enabled in device
|
||||
DAWN_NATIVE_EXPORT std::vector<const char*> GetTogglesUsed(WGPUDevice device);
|
||||
|
||||
// Backdoor to get the number of lazy clears for testing
|
||||
DAWN_NATIVE_EXPORT size_t GetLazyClearCountForTesting(WGPUDevice device);
|
||||
|
||||
// Backdoor to get the number of deprecation warnings for testing
|
||||
DAWN_NATIVE_EXPORT size_t GetDeprecationWarningCountForTesting(WGPUDevice device);
|
||||
|
||||
// Query if texture has been initialized
|
||||
DAWN_NATIVE_EXPORT bool IsTextureSubresourceInitialized(
|
||||
WGPUTexture texture,
|
||||
uint32_t baseMipLevel,
|
||||
uint32_t levelCount,
|
||||
uint32_t baseArrayLayer,
|
||||
uint32_t layerCount,
|
||||
WGPUTextureAspect aspect = WGPUTextureAspect_All);
|
||||
|
||||
// Backdoor to get the order of the ProcMap for testing
|
||||
DAWN_NATIVE_EXPORT std::vector<const char*> GetProcMapNamesForTesting();
|
||||
|
||||
DAWN_NATIVE_EXPORT bool DeviceTick(WGPUDevice device);
|
||||
|
||||
// ErrorInjector functions used for testing only. Defined in dawn_native/ErrorInjector.cpp
|
||||
DAWN_NATIVE_EXPORT void EnableErrorInjector();
|
||||
DAWN_NATIVE_EXPORT void DisableErrorInjector();
|
||||
DAWN_NATIVE_EXPORT void ClearErrorInjector();
|
||||
DAWN_NATIVE_EXPORT uint64_t AcquireErrorInjectorCallCount();
|
||||
DAWN_NATIVE_EXPORT void InjectErrorAt(uint64_t index);
|
||||
|
||||
// The different types of external images
|
||||
enum ExternalImageType {
|
||||
OpaqueFD,
|
||||
DmaBuf,
|
||||
IOSurface,
|
||||
DXGISharedHandle,
|
||||
EGLImage,
|
||||
};
|
||||
|
||||
// Common properties of external images
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageDescriptor {
|
||||
public:
|
||||
const WGPUTextureDescriptor* cTextureDescriptor; // Must match image creation params
|
||||
bool isInitialized; // Whether the texture is initialized on import
|
||||
ExternalImageType GetType() const;
|
||||
|
||||
protected:
|
||||
ExternalImageDescriptor(ExternalImageType type);
|
||||
|
||||
private:
|
||||
ExternalImageType mType;
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageAccessDescriptor {
|
||||
public:
|
||||
bool isInitialized; // Whether the texture is initialized on import
|
||||
WGPUTextureUsageFlags usage;
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageExportInfo {
|
||||
public:
|
||||
bool isInitialized; // Whether the texture is initialized after export
|
||||
ExternalImageType GetType() const;
|
||||
|
||||
protected:
|
||||
ExternalImageExportInfo(ExternalImageType type);
|
||||
|
||||
private:
|
||||
ExternalImageType mType;
|
||||
};
|
||||
|
||||
DAWN_NATIVE_EXPORT const char* GetObjectLabelForTesting(void* objectHandle);
|
||||
|
||||
DAWN_NATIVE_EXPORT uint64_t GetAllocatedSizeForTesting(WGPUBuffer buffer);
|
||||
|
||||
DAWN_NATIVE_EXPORT bool BindGroupLayoutBindingsEqualForTesting(WGPUBindGroupLayout a,
|
||||
WGPUBindGroupLayout b);
|
||||
|
||||
} // namespace dawn::native
|
||||
|
||||
// TODO(dawn:824): Remove once the deprecation period is passed.
|
||||
namespace dawn_native = dawn::native;
|
||||
|
||||
#endif // DAWNNATIVE_DAWNNATIVE_H_
|
||||
#include <dawn/native/DawnNative.h>
|
||||
|
||||
@@ -1,71 +1 @@
|
||||
// Copyright 2018 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 DAWNNATIVE_METALBACKEND_H_
|
||||
#define DAWNNATIVE_METALBACKEND_H_
|
||||
|
||||
#include <dawn/dawn_wsi.h>
|
||||
#include <dawn_native/DawnNative.h>
|
||||
|
||||
// The specifics of the Metal backend expose types in function signatures that might not be
|
||||
// available in dependent's minimum supported SDK version. Suppress all availability errors using
|
||||
// clang's pragmas. Dependents using the types without guarded availability will still get errors
|
||||
// when using the types.
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wunguarded-availability"
|
||||
|
||||
struct __IOSurface;
|
||||
typedef __IOSurface* IOSurfaceRef;
|
||||
|
||||
#ifdef __OBJC__
|
||||
# import <Metal/Metal.h>
|
||||
#endif //__OBJC__
|
||||
|
||||
namespace dawn::native::metal {
|
||||
|
||||
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
|
||||
AdapterDiscoveryOptions();
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorIOSurface : ExternalImageDescriptor {
|
||||
public:
|
||||
ExternalImageDescriptorIOSurface();
|
||||
|
||||
IOSurfaceRef ioSurface;
|
||||
uint32_t plane;
|
||||
};
|
||||
|
||||
DAWN_NATIVE_EXPORT WGPUTexture
|
||||
WrapIOSurface(WGPUDevice device, const ExternalImageDescriptorIOSurface* 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
|
||||
// when they are "scheduled". Submitting other operations before the command buffer is
|
||||
// scheduled could lead to races in who gets scheduled first and incorrect rendering.
|
||||
DAWN_NATIVE_EXPORT void WaitForCommandsToBeScheduled(WGPUDevice device);
|
||||
|
||||
} // namespace dawn::native::metal
|
||||
|
||||
#ifdef __OBJC__
|
||||
namespace dawn::native::metal {
|
||||
|
||||
DAWN_NATIVE_EXPORT id<MTLDevice> GetMetalDevice(WGPUDevice device);
|
||||
|
||||
} // namespace dawn::native::metal
|
||||
#endif // __OBJC__
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
#endif // DAWNNATIVE_METALBACKEND_H_
|
||||
#include <dawn/native/MetalBackend.h>
|
||||
|
||||
@@ -1,25 +1 @@
|
||||
// Copyright 2018 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 DAWNNATIVE_NULLBACKEND_H_
|
||||
#define DAWNNATIVE_NULLBACKEND_H_
|
||||
|
||||
#include <dawn/dawn_wsi.h>
|
||||
#include <dawn_native/DawnNative.h>
|
||||
|
||||
namespace dawn::native::null {
|
||||
DAWN_NATIVE_EXPORT DawnSwapChainImplementation CreateNativeSwapChainImpl();
|
||||
} // namespace dawn::native::null
|
||||
|
||||
#endif // DAWNNATIVE_NULLBACKEND_H_
|
||||
#include <dawn/native/NullBackend.h>
|
||||
|
||||
@@ -1,55 +1 @@
|
||||
// Copyright 2018 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 DAWNNATIVE_OPENGLBACKEND_H_
|
||||
#define DAWNNATIVE_OPENGLBACKEND_H_
|
||||
|
||||
typedef void* EGLImage;
|
||||
|
||||
#include <dawn/dawn_wsi.h>
|
||||
#include <dawn_native/DawnNative.h>
|
||||
|
||||
namespace dawn::native::opengl {
|
||||
|
||||
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
|
||||
AdapterDiscoveryOptions();
|
||||
|
||||
void* (*getProc)(const char*);
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptionsES : public AdapterDiscoveryOptionsBase {
|
||||
AdapterDiscoveryOptionsES();
|
||||
|
||||
void* (*getProc)(const char*);
|
||||
};
|
||||
|
||||
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();
|
||||
|
||||
::EGLImage image;
|
||||
};
|
||||
|
||||
DAWN_NATIVE_EXPORT WGPUTexture
|
||||
WrapExternalEGLImage(WGPUDevice device, const ExternalImageDescriptorEGLImage* descriptor);
|
||||
|
||||
} // namespace dawn::native::opengl
|
||||
|
||||
#endif // DAWNNATIVE_OPENGLBACKEND_H_
|
||||
#include <dawn/native/OpenGLBackend.h>
|
||||
|
||||
@@ -1,140 +1 @@
|
||||
// Copyright 2018 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 DAWNNATIVE_VULKANBACKEND_H_
|
||||
#define DAWNNATIVE_VULKANBACKEND_H_
|
||||
|
||||
#include <dawn/dawn_wsi.h>
|
||||
#include <dawn_native/DawnNative.h>
|
||||
|
||||
#include <vulkan/vulkan.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace dawn::native::vulkan {
|
||||
|
||||
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();
|
||||
|
||||
bool forceSwiftShader = false;
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorVk : ExternalImageDescriptor {
|
||||
public:
|
||||
// The following members may be ignored if |ExternalImageDescriptor::isInitialized| is false
|
||||
// since the import does not need to preserve texture contents.
|
||||
|
||||
// See https://www.khronos.org/registry/vulkan/specs/1.1/html/chap7.html. The acquire
|
||||
// operation old/new layouts must match exactly the layouts in the release operation. So
|
||||
// we may need to issue two barriers releasedOldLayout -> releasedNewLayout ->
|
||||
// cTextureDescriptor.usage if the new layout is not compatible with the desired usage.
|
||||
// The first barrier is the queue transfer, the second is the layout transition to our
|
||||
// desired usage.
|
||||
VkImageLayout releasedOldLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
VkImageLayout releasedNewLayout = VK_IMAGE_LAYOUT_GENERAL;
|
||||
|
||||
protected:
|
||||
using ExternalImageDescriptor::ExternalImageDescriptor;
|
||||
};
|
||||
|
||||
struct ExternalImageExportInfoVk : ExternalImageExportInfo {
|
||||
public:
|
||||
// See comments in |ExternalImageDescriptorVk|
|
||||
// Contains the old/new layouts used in the queue release operation.
|
||||
VkImageLayout releasedOldLayout;
|
||||
VkImageLayout releasedNewLayout;
|
||||
|
||||
protected:
|
||||
using ExternalImageExportInfo::ExternalImageExportInfo;
|
||||
};
|
||||
|
||||
// Can't use DAWN_PLATFORM_LINUX since header included in both Dawn and Chrome
|
||||
#ifdef __linux__
|
||||
|
||||
// Common properties of external images represented by FDs. On successful import the file
|
||||
// descriptor's ownership is transferred to the Dawn implementation and they shouldn't be
|
||||
// used outside of Dawn again. TODO(enga): Also transfer ownership in the error case so the
|
||||
// caller can assume the FD is always consumed.
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorFD : ExternalImageDescriptorVk {
|
||||
public:
|
||||
int memoryFD; // A file descriptor from an export of the memory of the image
|
||||
std::vector<int> waitFDs; // File descriptors of semaphores which will be waited on
|
||||
|
||||
protected:
|
||||
using ExternalImageDescriptorVk::ExternalImageDescriptorVk;
|
||||
};
|
||||
|
||||
// Descriptor for opaque file descriptor image import
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorOpaqueFD : ExternalImageDescriptorFD {
|
||||
ExternalImageDescriptorOpaqueFD();
|
||||
|
||||
VkDeviceSize allocationSize; // Must match VkMemoryAllocateInfo from image creation
|
||||
uint32_t memoryTypeIndex; // Must match VkMemoryAllocateInfo from image creation
|
||||
};
|
||||
|
||||
// Descriptor for dma-buf file descriptor image import
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageDescriptorDmaBuf : ExternalImageDescriptorFD {
|
||||
ExternalImageDescriptorDmaBuf();
|
||||
|
||||
uint32_t stride; // Stride of the buffer in bytes
|
||||
uint64_t drmModifier; // DRM modifier of the buffer
|
||||
};
|
||||
|
||||
// Info struct that is written to in |ExportVulkanImage|.
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageExportInfoFD : ExternalImageExportInfoVk {
|
||||
public:
|
||||
// Contains the exported semaphore handles.
|
||||
std::vector<int> semaphoreHandles;
|
||||
|
||||
protected:
|
||||
using ExternalImageExportInfoVk::ExternalImageExportInfoVk;
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageExportInfoOpaqueFD : ExternalImageExportInfoFD {
|
||||
ExternalImageExportInfoOpaqueFD();
|
||||
};
|
||||
|
||||
struct DAWN_NATIVE_EXPORT ExternalImageExportInfoDmaBuf : ExternalImageExportInfoFD {
|
||||
ExternalImageExportInfoDmaBuf();
|
||||
};
|
||||
|
||||
#endif // __linux__
|
||||
|
||||
// Imports external memory into a Vulkan image. Internally, this uses external memory /
|
||||
// semaphore extensions to import the image and wait on the provided synchronizaton
|
||||
// primitives before the texture can be used.
|
||||
// On failure, returns a nullptr.
|
||||
DAWN_NATIVE_EXPORT WGPUTexture WrapVulkanImage(WGPUDevice device,
|
||||
const ExternalImageDescriptorVk* descriptor);
|
||||
|
||||
// Exports external memory from a Vulkan image. This must be called on wrapped textures
|
||||
// before they are destroyed. It writes the semaphore to wait on and the old/new image
|
||||
// layouts to |info|. Pass VK_IMAGE_LAYOUT_UNDEFINED as |desiredLayout| if you don't want to
|
||||
// perform a layout transition.
|
||||
DAWN_NATIVE_EXPORT bool ExportVulkanImage(WGPUTexture texture,
|
||||
VkImageLayout desiredLayout,
|
||||
ExternalImageExportInfoVk* info);
|
||||
|
||||
} // namespace dawn::native::vulkan
|
||||
|
||||
#endif // DAWNNATIVE_VULKANBACKEND_H_
|
||||
#include <dawn/native/VulkanBackend.h>
|
||||
|
||||
@@ -1,36 +1 @@
|
||||
// Copyright 2018 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 DAWNNATIVE_EXPORT_H_
|
||||
#define DAWNNATIVE_EXPORT_H_
|
||||
|
||||
#if defined(DAWN_NATIVE_SHARED_LIBRARY)
|
||||
# if defined(_WIN32)
|
||||
# if defined(DAWN_NATIVE_IMPLEMENTATION)
|
||||
# define DAWN_NATIVE_EXPORT __declspec(dllexport)
|
||||
# else
|
||||
# define DAWN_NATIVE_EXPORT __declspec(dllimport)
|
||||
# endif
|
||||
# else // defined(_WIN32)
|
||||
# if defined(DAWN_NATIVE_IMPLEMENTATION)
|
||||
# define DAWN_NATIVE_EXPORT __attribute__((visibility("default")))
|
||||
# else
|
||||
# define DAWN_NATIVE_EXPORT
|
||||
# endif
|
||||
# endif // defined(_WIN32)
|
||||
#else // defined(DAWN_NATIVE_SHARED_LIBRARY)
|
||||
# define DAWN_NATIVE_EXPORT
|
||||
#endif // defined(DAWN_NATIVE_SHARED_LIBRARY)
|
||||
|
||||
#endif // DAWNNATIVE_EXPORT_H_
|
||||
#include <dawn/native/dawn_native_export.h>
|
||||
|
||||
Reference in New Issue
Block a user