Dawn: Deprecate DiscoverAdapters with DiscoverPhysicalDevices
This CL deprecate Discover[Default]Adapters and replace them with Discover[Default]PhysicalDevices. This help clearify the behavior of discovering physical devices and requesting / getting adapters, and prepare for adding adapter toggles in GetAdapters. Related end-to-end tests AdapterDiscoveryTests are split into PhysicalDeviceDiscoveryTests and AdapterCreationTests as well. Bug: dawn:1774, dawn:1495 Change-Id: Iac3d9da3022e5eb3c6dd6b3e3b2224f523792289 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/133968 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Kokoro: Kokoro <noreply+kokoro@google.com> Commit-Queue: Zhaoming Jiang <zhaoming.jiang@intel.com> Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
parent
dd7b314105
commit
6663a97b74
|
@ -25,11 +25,15 @@
|
|||
|
||||
namespace dawn::native::d3d11 {
|
||||
|
||||
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public d3d::AdapterDiscoveryOptions {
|
||||
AdapterDiscoveryOptions();
|
||||
explicit AdapterDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
|
||||
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
|
||||
|
|
|
@ -38,11 +38,15 @@ DAWN_NATIVE_EXPORT uint64_t SetExternalMemoryReservation(WGPUDevice device,
|
|||
uint64_t requestedReservationSize,
|
||||
MemorySegment memorySegment);
|
||||
|
||||
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public d3d::AdapterDiscoveryOptions {
|
||||
AdapterDiscoveryOptions();
|
||||
explicit AdapterDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
|
||||
struct DAWN_NATIVE_EXPORT PhysicalDeviceDiscoveryOptions
|
||||
: public d3d::PhysicalDeviceDiscoveryOptions {
|
||||
PhysicalDeviceDiscoveryOptions();
|
||||
explicit PhysicalDeviceDiscoveryOptions(Microsoft::WRL::ComPtr<IDXGIAdapter> adapter);
|
||||
};
|
||||
|
||||
// TODO(dawn:1774): Deprecated.
|
||||
using AdapterDiscoveryOptions = PhysicalDeviceDiscoveryOptions;
|
||||
|
||||
} // namespace dawn::native::d3d12
|
||||
|
||||
#endif // INCLUDE_DAWN_NATIVE_D3D12BACKEND_H_
|
||||
|
|
|
@ -30,11 +30,16 @@ class ExternalImageDXGIImpl;
|
|||
|
||||
DAWN_NATIVE_EXPORT Microsoft::WRL::ComPtr<IDXGIAdapter> GetDXGIAdapter(WGPUAdapter adapter);
|
||||
|
||||
struct DAWN_NATIVE_EXPORT AdapterDiscoveryOptions : public AdapterDiscoveryOptionsBase {
|
||||
AdapterDiscoveryOptions(WGPUBackendType type, Microsoft::WRL::ComPtr<IDXGIAdapter> 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();
|
||||
|
|
|
@ -118,15 +118,19 @@ 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
|
||||
|
@ -156,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);
|
||||
|
|
|
@ -35,10 +35,14 @@ 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
|
||||
|
|
|
@ -21,14 +21,18 @@ typedef void* EGLImage;
|
|||
|
||||
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*);
|
||||
};
|
||||
|
||||
// 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();
|
||||
};
|
||||
|
||||
|
|
|
@ -28,12 +28,16 @@ DAWN_NATIVE_EXPORT VkInstance GetInstance(WGPUDevice device);
|
|||
|
||||
DAWN_NATIVE_EXPORT PFN_vkVoidFunction GetInstanceProcAddr(WGPUDevice device, const char* pName);
|
||||
|
||||
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,
|
||||
|
|
|
@ -70,7 +70,7 @@ int DawnWireServerFuzzer::Initialize(int* argc, char*** argv) {
|
|||
sVulkanLoader.Open(dawn::GetExecutableDirectory().value_or("") + "vulkan-1.dll");
|
||||
#endif
|
||||
|
||||
sInstance->DiscoverDefaultAdapters();
|
||||
sInstance->DiscoverDefaultPhysicalDevices();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -28,9 +28,9 @@ InstanceBase* BackendConnection::GetInstance() const {
|
|||
return mInstance;
|
||||
}
|
||||
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> BackendConnection::DiscoverAdapters(
|
||||
const AdapterDiscoveryOptionsBase* options) {
|
||||
return DAWN_VALIDATION_ERROR("DiscoverAdapters not implemented for this backend.");
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> BackendConnection::DiscoverPhysicalDevices(
|
||||
const PhysicalDeviceDiscoveryOptionsBase* options) {
|
||||
return DAWN_VALIDATION_ERROR("DiscoverPhysicalDevices not implemented for this backend.");
|
||||
}
|
||||
|
||||
} // namespace dawn::native
|
||||
|
|
|
@ -34,13 +34,13 @@ class BackendConnection {
|
|||
wgpu::BackendType GetType() const;
|
||||
InstanceBase* GetInstance() const;
|
||||
|
||||
// Returns all the adapters for the system that can be created by the backend, without extra
|
||||
// options (such as debug adapters, custom driver libraries, etc.)
|
||||
virtual std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() = 0;
|
||||
// Returns all the physical devices for the system that can be created by the backend, without
|
||||
// extra options (such as debug adapters, custom driver libraries, etc.)
|
||||
virtual std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultPhysicalDevices() = 0;
|
||||
|
||||
// Returns new adapters created with the backend-specific options.
|
||||
virtual ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
||||
const AdapterDiscoveryOptionsBase* options);
|
||||
// Returns new physical devices created with the backend-specific options.
|
||||
virtual ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverPhysicalDevices(
|
||||
const PhysicalDeviceDiscoveryOptionsBase* options);
|
||||
|
||||
private:
|
||||
InstanceBase* mInstance = nullptr;
|
||||
|
|
|
@ -132,7 +132,7 @@ void Adapter::ResetInternalDeviceForTesting() {
|
|||
|
||||
// AdapterDiscoverOptionsBase
|
||||
|
||||
AdapterDiscoveryOptionsBase::AdapterDiscoveryOptionsBase(WGPUBackendType type)
|
||||
PhysicalDeviceDiscoveryOptionsBase::PhysicalDeviceDiscoveryOptionsBase(WGPUBackendType type)
|
||||
: backendType(type) {}
|
||||
|
||||
// DawnInstanceDescriptor
|
||||
|
@ -162,12 +162,22 @@ Instance::~Instance() {
|
|||
}
|
||||
}
|
||||
|
||||
void Instance::DiscoverDefaultAdapters() {
|
||||
mImpl->DiscoverDefaultAdapters();
|
||||
void Instance::DiscoverDefaultPhysicalDevices() {
|
||||
mImpl->DiscoverDefaultPhysicalDevices();
|
||||
}
|
||||
|
||||
bool Instance::DiscoverPhysicalDevices(const PhysicalDeviceDiscoveryOptionsBase* options) {
|
||||
return mImpl->DiscoverPhysicalDevices(options);
|
||||
}
|
||||
|
||||
// Deprecated.
|
||||
void Instance::DiscoverDefaultAdapters() {
|
||||
mImpl->DiscoverDefaultPhysicalDevices();
|
||||
}
|
||||
|
||||
// Deprecated.
|
||||
bool Instance::DiscoverAdapters(const AdapterDiscoveryOptionsBase* options) {
|
||||
return mImpl->DiscoverAdapters(options);
|
||||
return mImpl->DiscoverPhysicalDevices(options);
|
||||
}
|
||||
|
||||
std::vector<Adapter> Instance::GetAdapters() const {
|
||||
|
|
|
@ -217,10 +217,10 @@ ResultOrError<Ref<AdapterBase>> InstanceBase::RequestAdapterInternal(
|
|||
if (options->forceFallbackAdapter) {
|
||||
#if defined(DAWN_ENABLE_BACKEND_VULKAN)
|
||||
if (GetEnabledBackends()[wgpu::BackendType::Vulkan]) {
|
||||
dawn_native::vulkan::AdapterDiscoveryOptions vulkanOptions;
|
||||
dawn_native::vulkan::PhysicalDeviceDiscoveryOptions vulkanOptions;
|
||||
vulkanOptions.forceSwiftShader = true;
|
||||
|
||||
MaybeError result = DiscoverAdaptersInternal(&vulkanOptions);
|
||||
MaybeError result = DiscoverPhysicalDevicesInternal(&vulkanOptions);
|
||||
if (result.IsError()) {
|
||||
dawn::WarningLog() << absl::StrFormat(
|
||||
"Skipping Vulkan Swiftshader adapter because initialization failed: %s",
|
||||
|
@ -232,7 +232,7 @@ ResultOrError<Ref<AdapterBase>> InstanceBase::RequestAdapterInternal(
|
|||
return Ref<AdapterBase>(nullptr);
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_VULKAN)
|
||||
} else {
|
||||
DiscoverDefaultAdapters();
|
||||
DiscoverDefaultPhysicalDevices();
|
||||
}
|
||||
|
||||
wgpu::AdapterType preferredType;
|
||||
|
@ -314,7 +314,7 @@ ResultOrError<Ref<AdapterBase>> InstanceBase::RequestAdapterInternal(
|
|||
new AdapterBase(std::move(selectedPhysicalDevice), featureLevel, adapterToggles));
|
||||
}
|
||||
|
||||
void InstanceBase::DiscoverDefaultAdapters() {
|
||||
void InstanceBase::DiscoverDefaultPhysicalDevices() {
|
||||
for (wgpu::BackendType b : IterateBitSet(GetEnabledBackends())) {
|
||||
EnsureBackendConnection(b);
|
||||
}
|
||||
|
@ -325,7 +325,8 @@ void InstanceBase::DiscoverDefaultAdapters() {
|
|||
|
||||
// Query and merge all default adapters for all backends
|
||||
for (std::unique_ptr<BackendConnection>& backend : mBackends) {
|
||||
std::vector<Ref<PhysicalDeviceBase>> physicalDevices = backend->DiscoverDefaultAdapters();
|
||||
std::vector<Ref<PhysicalDeviceBase>> physicalDevices =
|
||||
backend->DiscoverDefaultPhysicalDevices();
|
||||
|
||||
for (Ref<PhysicalDeviceBase>& physicalDevice : physicalDevices) {
|
||||
ASSERT(physicalDevice->GetBackendType() == backend->GetType());
|
||||
|
@ -338,8 +339,8 @@ void InstanceBase::DiscoverDefaultAdapters() {
|
|||
}
|
||||
|
||||
// This is just a wrapper around the real logic that uses Error.h error handling.
|
||||
bool InstanceBase::DiscoverAdapters(const AdapterDiscoveryOptionsBase* options) {
|
||||
MaybeError result = DiscoverAdaptersInternal(options);
|
||||
bool InstanceBase::DiscoverPhysicalDevices(const PhysicalDeviceDiscoveryOptionsBase* options) {
|
||||
MaybeError result = DiscoverPhysicalDevicesInternal(options);
|
||||
|
||||
if (result.IsError()) {
|
||||
dawn::WarningLog() << absl::StrFormat(
|
||||
|
@ -450,7 +451,8 @@ void InstanceBase::EnsureBackendConnection(wgpu::BackendType backendType) {
|
|||
mBackendsConnected.set(backendType);
|
||||
}
|
||||
|
||||
MaybeError InstanceBase::DiscoverAdaptersInternal(const AdapterDiscoveryOptionsBase* options) {
|
||||
MaybeError InstanceBase::DiscoverPhysicalDevicesInternal(
|
||||
const PhysicalDeviceDiscoveryOptionsBase* options) {
|
||||
wgpu::BackendType backendType = static_cast<wgpu::BackendType>(options->backendType);
|
||||
DAWN_TRY(ValidateBackendType(backendType));
|
||||
|
||||
|
@ -468,7 +470,7 @@ MaybeError InstanceBase::DiscoverAdaptersInternal(const AdapterDiscoveryOptionsB
|
|||
foundBackend = true;
|
||||
|
||||
std::vector<Ref<PhysicalDeviceBase>> newPhysicalDevices;
|
||||
DAWN_TRY_ASSIGN(newPhysicalDevices, backend->DiscoverAdapters(options));
|
||||
DAWN_TRY_ASSIGN(newPhysicalDevices, backend->DiscoverPhysicalDevices(options));
|
||||
|
||||
for (Ref<PhysicalDeviceBase>& physicalDevice : newPhysicalDevices) {
|
||||
ASSERT(physicalDevice->GetBackendType() == backend->GetType());
|
||||
|
|
|
@ -58,9 +58,10 @@ class InstanceBase final : public RefCountedWithExternalCount {
|
|||
WGPURequestAdapterCallback callback,
|
||||
void* userdata);
|
||||
|
||||
void DiscoverDefaultAdapters();
|
||||
bool DiscoverAdapters(const AdapterDiscoveryOptionsBase* options);
|
||||
void DiscoverDefaultPhysicalDevices();
|
||||
bool DiscoverPhysicalDevices(const PhysicalDeviceDiscoveryOptionsBase* options);
|
||||
|
||||
// Return adapters created on every known physical device.
|
||||
std::vector<Ref<AdapterBase>> GetAdapters() const;
|
||||
|
||||
// Used to handle error that happen up to device creation.
|
||||
|
@ -134,7 +135,7 @@ class InstanceBase final : public RefCountedWithExternalCount {
|
|||
// Lazily creates connections to all backends that have been compiled.
|
||||
void EnsureBackendConnection(wgpu::BackendType backendType);
|
||||
|
||||
MaybeError DiscoverAdaptersInternal(const AdapterDiscoveryOptionsBase* options);
|
||||
MaybeError DiscoverPhysicalDevicesInternal(const PhysicalDeviceDiscoveryOptionsBase* options);
|
||||
|
||||
ResultOrError<Ref<AdapterBase>> RequestAdapterInternal(const RequestAdapterOptions* options);
|
||||
|
||||
|
|
|
@ -238,35 +238,35 @@ const PlatformFunctions* Backend::GetFunctions() const {
|
|||
return mFunctions.get();
|
||||
}
|
||||
|
||||
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
|
||||
AdapterDiscoveryOptions options(ToAPI(GetType()), nullptr);
|
||||
std::vector<Ref<PhysicalDeviceBase>> adapters;
|
||||
if (GetInstance()->ConsumedError(DiscoverAdapters(&options), &adapters)) {
|
||||
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultPhysicalDevices() {
|
||||
PhysicalDeviceDiscoveryOptions options(ToAPI(GetType()), nullptr);
|
||||
std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
|
||||
if (GetInstance()->ConsumedError(DiscoverPhysicalDevices(&options), &physicalDevices)) {
|
||||
return {};
|
||||
}
|
||||
return adapters;
|
||||
return physicalDevices;
|
||||
}
|
||||
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
||||
const AdapterDiscoveryOptionsBase* optionsBase) {
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverPhysicalDevices(
|
||||
const PhysicalDeviceDiscoveryOptionsBase* optionsBase) {
|
||||
ASSERT(optionsBase->backendType == ToAPI(GetType()));
|
||||
const AdapterDiscoveryOptions* options =
|
||||
static_cast<const AdapterDiscoveryOptions*>(optionsBase);
|
||||
const PhysicalDeviceDiscoveryOptions* options =
|
||||
static_cast<const PhysicalDeviceDiscoveryOptions*>(optionsBase);
|
||||
|
||||
std::vector<Ref<PhysicalDeviceBase>> adapters;
|
||||
std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
|
||||
if (options->dxgiAdapter != nullptr) {
|
||||
// |dxgiAdapter| was provided. Discover just that adapter.
|
||||
Ref<PhysicalDeviceBase> adapter;
|
||||
DAWN_TRY_ASSIGN(adapter, CreatePhysicalDeviceFromIDXGIAdapter(options->dxgiAdapter));
|
||||
adapters.push_back(std::move(adapter));
|
||||
return std::move(adapters);
|
||||
physicalDevices.push_back(std::move(adapter));
|
||||
return std::move(physicalDevices);
|
||||
}
|
||||
|
||||
// Enumerate and discover all available adapters.
|
||||
// Enumerate and discover all available physicalDevices.
|
||||
for (uint32_t adapterIndex = 0;; ++adapterIndex) {
|
||||
ComPtr<IDXGIAdapter1> dxgiAdapter = nullptr;
|
||||
if (GetFactory()->EnumAdapters1(adapterIndex, &dxgiAdapter) == DXGI_ERROR_NOT_FOUND) {
|
||||
break; // No more adapters to enumerate.
|
||||
break; // No more physicalDevices to enumerate.
|
||||
}
|
||||
|
||||
ASSERT(dxgiAdapter != nullptr);
|
||||
|
@ -276,10 +276,10 @@ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
|||
continue;
|
||||
}
|
||||
|
||||
adapters.push_back(std::move(adapter));
|
||||
physicalDevices.push_back(std::move(adapter));
|
||||
}
|
||||
|
||||
return adapters;
|
||||
return physicalDevices;
|
||||
}
|
||||
|
||||
} // namespace dawn::native::d3d
|
||||
|
|
|
@ -75,9 +75,9 @@ class Backend : public BackendConnection {
|
|||
|
||||
const PlatformFunctions* GetFunctions() const;
|
||||
|
||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
||||
const AdapterDiscoveryOptionsBase* optionsBase) override;
|
||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultPhysicalDevices() override;
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverPhysicalDevices(
|
||||
const PhysicalDeviceDiscoveryOptionsBase* optionsBase) override;
|
||||
|
||||
protected:
|
||||
virtual ResultOrError<Ref<PhysicalDeviceBase>> CreatePhysicalDeviceFromIDXGIAdapter(
|
||||
|
|
|
@ -33,9 +33,10 @@ Microsoft::WRL::ComPtr<IDXGIAdapter> GetDXGIAdapter(WGPUAdapter adapter) {
|
|||
return ToBackend(FromAPI(adapter)->GetPhysicalDevice())->GetHardwareAdapter();
|
||||
}
|
||||
|
||||
AdapterDiscoveryOptions::AdapterDiscoveryOptions(WGPUBackendType type,
|
||||
Microsoft::WRL::ComPtr<IDXGIAdapter> adapter)
|
||||
: AdapterDiscoveryOptionsBase(type), dxgiAdapter(std::move(adapter)) {}
|
||||
PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions(
|
||||
WGPUBackendType type,
|
||||
Microsoft::WRL::ComPtr<IDXGIAdapter> adapter)
|
||||
: PhysicalDeviceDiscoveryOptionsBase(type), dxgiAdapter(std::move(adapter)) {}
|
||||
|
||||
ExternalImageDescriptorDXGISharedHandle::ExternalImageDescriptorDXGISharedHandle()
|
||||
: ExternalImageDescriptor(ExternalImageType::DXGISharedHandle) {}
|
||||
|
|
|
@ -25,10 +25,11 @@
|
|||
|
||||
namespace dawn::native::d3d11 {
|
||||
|
||||
AdapterDiscoveryOptions::AdapterDiscoveryOptions() : AdapterDiscoveryOptions(nullptr) {}
|
||||
PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions()
|
||||
: PhysicalDeviceDiscoveryOptions(nullptr) {}
|
||||
|
||||
AdapterDiscoveryOptions::AdapterDiscoveryOptions(ComPtr<IDXGIAdapter> adapter)
|
||||
: d3d::AdapterDiscoveryOptions(WGPUBackendType_D3D11, std::move(adapter)) {}
|
||||
PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions(ComPtr<IDXGIAdapter> adapter)
|
||||
: d3d::PhysicalDeviceDiscoveryOptions(WGPUBackendType_D3D11, std::move(adapter)) {}
|
||||
|
||||
Microsoft::WRL::ComPtr<ID3D11Device> GetD3D11Device(WGPUDevice device) {
|
||||
return ToBackend(FromAPI(device))->GetD3D11Device();
|
||||
|
|
|
@ -39,9 +39,10 @@ uint64_t SetExternalMemoryReservation(WGPUDevice device,
|
|||
memorySegment, requestedReservationSize);
|
||||
}
|
||||
|
||||
AdapterDiscoveryOptions::AdapterDiscoveryOptions() : AdapterDiscoveryOptions(nullptr) {}
|
||||
PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions()
|
||||
: PhysicalDeviceDiscoveryOptions(nullptr) {}
|
||||
|
||||
AdapterDiscoveryOptions::AdapterDiscoveryOptions(ComPtr<IDXGIAdapter> adapter)
|
||||
: d3d::AdapterDiscoveryOptions(WGPUBackendType_D3D12, std::move(adapter)) {}
|
||||
PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions(ComPtr<IDXGIAdapter> adapter)
|
||||
: d3d::PhysicalDeviceDiscoveryOptions(WGPUBackendType_D3D12, std::move(adapter)) {}
|
||||
|
||||
} // namespace dawn::native::d3d12
|
||||
|
|
|
@ -26,9 +26,9 @@ class Backend : public BackendConnection {
|
|||
explicit Backend(InstanceBase* instance);
|
||||
~Backend() override;
|
||||
|
||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
||||
const AdapterDiscoveryOptionsBase* optionsBase) override;
|
||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultPhysicalDevices() override;
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverPhysicalDevices(
|
||||
const PhysicalDeviceDiscoveryOptionsBase* optionsBase) override;
|
||||
};
|
||||
|
||||
} // namespace dawn::native::metal
|
||||
|
|
|
@ -819,9 +819,9 @@ Backend::Backend(InstanceBase* instance) : BackendConnection(instance, wgpu::Bac
|
|||
|
||||
Backend::~Backend() = default;
|
||||
|
||||
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
|
||||
AdapterDiscoveryOptions options;
|
||||
auto result = DiscoverAdapters(&options);
|
||||
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultPhysicalDevices() {
|
||||
PhysicalDeviceDiscoveryOptions options;
|
||||
auto result = DiscoverPhysicalDevices(&options);
|
||||
if (result.IsError()) {
|
||||
GetInstance()->ConsumedError(result.AcquireError());
|
||||
return {};
|
||||
|
@ -829,8 +829,8 @@ std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
|
|||
return result.AcquireSuccess();
|
||||
}
|
||||
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
||||
const AdapterDiscoveryOptionsBase* optionsBase) {
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverPhysicalDevices(
|
||||
const PhysicalDeviceDiscoveryOptionsBase* optionsBase) {
|
||||
ASSERT(optionsBase->backendType == WGPUBackendType_Metal);
|
||||
|
||||
std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
|
||||
|
|
|
@ -23,8 +23,8 @@
|
|||
|
||||
namespace dawn::native::metal {
|
||||
|
||||
AdapterDiscoveryOptions::AdapterDiscoveryOptions()
|
||||
: AdapterDiscoveryOptionsBase(WGPUBackendType_Metal) {}
|
||||
PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions()
|
||||
: PhysicalDeviceDiscoveryOptionsBase(WGPUBackendType_Metal) {}
|
||||
|
||||
ExternalImageDescriptorIOSurface::ExternalImageDescriptorIOSurface()
|
||||
: ExternalImageDescriptor(ExternalImageType::IOSurface) {}
|
||||
|
|
|
@ -86,7 +86,7 @@ class Backend : public BackendConnection {
|
|||
explicit Backend(InstanceBase* instance)
|
||||
: BackendConnection(instance, wgpu::BackendType::Null) {}
|
||||
|
||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override {
|
||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultPhysicalDevices() override {
|
||||
// There is always a single Null adapter because it is purely CPU based and doesn't
|
||||
// depend on the system.
|
||||
std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
|
||||
|
|
|
@ -33,8 +33,8 @@ namespace dawn::native::opengl {
|
|||
Backend::Backend(InstanceBase* instance, wgpu::BackendType backendType)
|
||||
: BackendConnection(instance, backendType) {}
|
||||
|
||||
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
|
||||
std::vector<Ref<PhysicalDeviceBase>> adapters;
|
||||
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultPhysicalDevices() {
|
||||
std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
|
||||
#if DAWN_PLATFORM_IS(WINDOWS)
|
||||
const char* eglLib = "libEGL.dll";
|
||||
#elif DAWN_PLATFORM_IS(MACOS)
|
||||
|
@ -46,7 +46,7 @@ std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
|
|||
return {};
|
||||
}
|
||||
|
||||
AdapterDiscoveryOptions options(ToAPI(GetType()));
|
||||
PhysicalDeviceDiscoveryOptions options(ToAPI(GetType()));
|
||||
options.getProc =
|
||||
reinterpret_cast<void* (*)(const char*)>(mLibEGL.GetProc("eglGetProcAddress"));
|
||||
if (!options.getProc) {
|
||||
|
@ -69,39 +69,41 @@ std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
|
|||
|
||||
context->MakeCurrent();
|
||||
|
||||
auto result = DiscoverAdapters(&options);
|
||||
auto result = DiscoverPhysicalDevices(&options);
|
||||
|
||||
if (result.IsError()) {
|
||||
GetInstance()->ConsumedError(result.AcquireError());
|
||||
} else {
|
||||
auto value = result.AcquireSuccess();
|
||||
adapters.insert(adapters.end(), value.begin(), value.end());
|
||||
physicalDevices.insert(physicalDevices.end(), value.begin(), value.end());
|
||||
}
|
||||
|
||||
egl.MakeCurrent(prevDisplay, prevDrawSurface, prevReadSurface, prevContext);
|
||||
|
||||
return adapters;
|
||||
return physicalDevices;
|
||||
}
|
||||
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
||||
const AdapterDiscoveryOptionsBase* optionsBase) {
|
||||
// TODO(cwallez@chromium.org): For now only create a single OpenGL adapter because don't
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverPhysicalDevices(
|
||||
const PhysicalDeviceDiscoveryOptionsBase* optionsBase) {
|
||||
// TODO(cwallez@chromium.org): For now only create a single OpenGL physicalDevice because don't
|
||||
// know how to handle MakeCurrent.
|
||||
DAWN_INVALID_IF(mCreatedAdapter, "The OpenGL backend can only create a single adapter.");
|
||||
DAWN_INVALID_IF(mCreatedPhysicalDevice,
|
||||
"The OpenGL backend can only create a single physicalDevice.");
|
||||
|
||||
ASSERT(static_cast<wgpu::BackendType>(optionsBase->backendType) == GetType());
|
||||
const AdapterDiscoveryOptions* options =
|
||||
static_cast<const AdapterDiscoveryOptions*>(optionsBase);
|
||||
const PhysicalDeviceDiscoveryOptions* options =
|
||||
static_cast<const PhysicalDeviceDiscoveryOptions*>(optionsBase);
|
||||
|
||||
DAWN_INVALID_IF(options->getProc == nullptr, "AdapterDiscoveryOptions::getProc must be set");
|
||||
DAWN_INVALID_IF(options->getProc == nullptr,
|
||||
"PhysicalDeviceDiscoveryOptions::getProc must be set");
|
||||
|
||||
Ref<PhysicalDevice> adapter = AcquireRef(new PhysicalDevice(
|
||||
Ref<PhysicalDevice> physicalDevice = AcquireRef(new PhysicalDevice(
|
||||
GetInstance(), static_cast<wgpu::BackendType>(optionsBase->backendType)));
|
||||
DAWN_TRY(adapter->InitializeGLFunctions(options->getProc));
|
||||
DAWN_TRY(adapter->Initialize());
|
||||
DAWN_TRY(physicalDevice->InitializeGLFunctions(options->getProc));
|
||||
DAWN_TRY(physicalDevice->Initialize());
|
||||
|
||||
mCreatedAdapter = true;
|
||||
std::vector<Ref<PhysicalDeviceBase>> adapters{std::move(adapter)};
|
||||
mCreatedPhysicalDevice = true;
|
||||
std::vector<Ref<PhysicalDeviceBase>> adapters{std::move(physicalDevice)};
|
||||
return std::move(adapters);
|
||||
}
|
||||
|
||||
|
|
|
@ -26,12 +26,12 @@ class Backend : public BackendConnection {
|
|||
public:
|
||||
Backend(InstanceBase* instance, wgpu::BackendType backendType);
|
||||
|
||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
||||
const AdapterDiscoveryOptionsBase* option) override;
|
||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultPhysicalDevices() override;
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverPhysicalDevices(
|
||||
const PhysicalDeviceDiscoveryOptionsBase* option) override;
|
||||
|
||||
private:
|
||||
bool mCreatedAdapter = false;
|
||||
bool mCreatedPhysicalDevice = false;
|
||||
DynamicLib mLibEGL;
|
||||
};
|
||||
|
||||
|
|
|
@ -21,11 +21,11 @@
|
|||
|
||||
namespace dawn::native::opengl {
|
||||
|
||||
AdapterDiscoveryOptions::AdapterDiscoveryOptions(WGPUBackendType type)
|
||||
: AdapterDiscoveryOptionsBase(type) {}
|
||||
PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions(WGPUBackendType type)
|
||||
: PhysicalDeviceDiscoveryOptionsBase(type) {}
|
||||
|
||||
AdapterDiscoveryOptionsES::AdapterDiscoveryOptionsES()
|
||||
: AdapterDiscoveryOptions(WGPUBackendType_OpenGLES) {}
|
||||
: PhysicalDeviceDiscoveryOptions(WGPUBackendType_OpenGLES) {}
|
||||
|
||||
ExternalImageDescriptorEGLImage::ExternalImageDescriptorEGLImage()
|
||||
: ExternalImageDescriptor(ExternalImageType::EGLImage) {}
|
||||
|
|
|
@ -457,9 +457,9 @@ Backend::Backend(InstanceBase* instance) : BackendConnection(instance, wgpu::Bac
|
|||
|
||||
Backend::~Backend() = default;
|
||||
|
||||
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
|
||||
AdapterDiscoveryOptions options;
|
||||
auto result = DiscoverAdapters(&options);
|
||||
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultPhysicalDevices() {
|
||||
PhysicalDeviceDiscoveryOptions options;
|
||||
auto result = DiscoverPhysicalDevices(&options);
|
||||
if (result.IsError()) {
|
||||
GetInstance()->ConsumedError(result.AcquireError());
|
||||
return {};
|
||||
|
@ -467,12 +467,12 @@ std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
|
|||
return result.AcquireSuccess();
|
||||
}
|
||||
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
||||
const AdapterDiscoveryOptionsBase* optionsBase) {
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverPhysicalDevices(
|
||||
const PhysicalDeviceDiscoveryOptionsBase* optionsBase) {
|
||||
ASSERT(optionsBase->backendType == WGPUBackendType_Vulkan);
|
||||
|
||||
const AdapterDiscoveryOptions* options =
|
||||
static_cast<const AdapterDiscoveryOptions*>(optionsBase);
|
||||
const PhysicalDeviceDiscoveryOptions* options =
|
||||
static_cast<const PhysicalDeviceDiscoveryOptions*>(optionsBase);
|
||||
|
||||
std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
|
||||
|
||||
|
|
|
@ -91,9 +91,9 @@ class Backend : public BackendConnection {
|
|||
|
||||
MaybeError Initialize();
|
||||
|
||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
||||
const AdapterDiscoveryOptionsBase* optionsBase) override;
|
||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultPhysicalDevices() override;
|
||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverPhysicalDevices(
|
||||
const PhysicalDeviceDiscoveryOptionsBase* optionsBase) override;
|
||||
|
||||
private:
|
||||
ityp::array<ICD, Ref<VulkanInstance>, 2> mVulkanInstances = {};
|
||||
|
|
|
@ -36,8 +36,8 @@ DAWN_NATIVE_EXPORT PFN_vkVoidFunction GetInstanceProcAddr(WGPUDevice device, con
|
|||
return (*backendDevice->fn.GetInstanceProcAddr)(backendDevice->GetVkInstance(), pName);
|
||||
}
|
||||
|
||||
AdapterDiscoveryOptions::AdapterDiscoveryOptions()
|
||||
: AdapterDiscoveryOptionsBase(WGPUBackendType_Vulkan) {}
|
||||
PhysicalDeviceDiscoveryOptions::PhysicalDeviceDiscoveryOptions()
|
||||
: PhysicalDeviceDiscoveryOptionsBase(WGPUBackendType_Vulkan) {}
|
||||
|
||||
#if DAWN_PLATFORM_IS(LINUX)
|
||||
ExternalImageDescriptorOpaqueFD::ExternalImageDescriptorOpaqueFD()
|
||||
|
|
|
@ -272,7 +272,7 @@ int main(int argc, const char* argv[]) {
|
|||
dawnProcSetProcs(&procs);
|
||||
|
||||
instance = std::make_unique<dawn::native::Instance>();
|
||||
instance->DiscoverDefaultAdapters();
|
||||
instance->DiscoverDefaultPhysicalDevices();
|
||||
|
||||
std::vector<dawn::native::Adapter> adapters = instance->GetAdapters();
|
||||
dawn::native::Adapter chosenAdapter;
|
||||
|
|
|
@ -128,7 +128,7 @@ wgpu::Device CreateCppDawnDevice() {
|
|||
}
|
||||
|
||||
instance = std::make_unique<dawn::native::Instance>();
|
||||
instance->DiscoverDefaultAdapters();
|
||||
instance->DiscoverDefaultPhysicalDevices();
|
||||
|
||||
// Get an adapter for the backend to use, and create the device.
|
||||
dawn::native::Adapter backendAdapter;
|
||||
|
|
|
@ -485,7 +485,7 @@ source_set("end2end_tests_sources") {
|
|||
]
|
||||
|
||||
sources = [
|
||||
"end2end/AdapterDiscoveryTests.cpp",
|
||||
"end2end/AdapterCreationTests.cpp",
|
||||
"end2end/BasicTests.cpp",
|
||||
"end2end/BindGroupTests.cpp",
|
||||
"end2end/BufferTests.cpp",
|
||||
|
@ -536,6 +536,7 @@ source_set("end2end_tests_sources") {
|
|||
"end2end/NonzeroTextureCreationTests.cpp",
|
||||
"end2end/ObjectCachingTests.cpp",
|
||||
"end2end/OpArrayLengthTests.cpp",
|
||||
"end2end/PhysicalDeviceDiscoveryTests.cpp",
|
||||
"end2end/PipelineCachingTests.cpp",
|
||||
"end2end/PipelineLayoutTests.cpp",
|
||||
"end2end/PrimitiveStateTests.cpp",
|
||||
|
|
|
@ -64,7 +64,7 @@ void DawnNativeTest::SetUp() {
|
|||
instance = std::make_unique<dawn::native::Instance>(
|
||||
reinterpret_cast<const WGPUInstanceDescriptor*>(&instanceDesc));
|
||||
instance->EnableAdapterBlocklist(false);
|
||||
instance->DiscoverDefaultAdapters();
|
||||
instance->DiscoverDefaultPhysicalDevices();
|
||||
|
||||
std::vector<dawn::native::Adapter> adapters = instance->GetAdapters();
|
||||
|
||||
|
|
|
@ -416,7 +416,7 @@ std::unique_ptr<dawn::native::Instance> DawnTestEnvironment::CreateInstanceAndDi
|
|||
}
|
||||
#endif // DAWN_ENABLE_BACKEND_OPENGLES
|
||||
|
||||
instance->DiscoverDefaultAdapters();
|
||||
instance->DiscoverDefaultPhysicalDevices();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ void SetupNullBackend(const benchmark::State& state) {
|
|||
|
||||
if (!nativeInstance) {
|
||||
nativeInstance = std::make_unique<dawn::native::Instance>();
|
||||
nativeInstance->DiscoverDefaultAdapters();
|
||||
nativeInstance->DiscoverDefaultPhysicalDevices();
|
||||
}
|
||||
|
||||
if (!nullBackendAdapter) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
// Copyright 2021 The Dawn Authors
|
||||
// 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.
|
||||
|
@ -16,36 +16,11 @@
|
|||
#include <utility>
|
||||
|
||||
#include "dawn/common/GPUInfo.h"
|
||||
#include "dawn/common/Log.h"
|
||||
#include "dawn/common/Platform.h"
|
||||
#include "dawn/common/SystemUtils.h"
|
||||
#include "dawn/dawn_proc.h"
|
||||
#include "dawn/native/DawnNative.h"
|
||||
#include "dawn/tests/MockCallback.h"
|
||||
#include "dawn/webgpu_cpp.h"
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_VULKAN)
|
||||
#include "dawn/native/VulkanBackend.h"
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_VULKAN)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_D3D11)
|
||||
#include "dawn/native/D3D11Backend.h"
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_D3D11)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_D3D12)
|
||||
#include "dawn/native/D3D12Backend.h"
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_D3D12)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_METAL)
|
||||
#include "dawn/native/MetalBackend.h"
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_METAL)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_DESKTOP_GL) || defined(DAWN_ENABLE_BACKEND_OPENGLES)
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "dawn/native/OpenGLBackend.h"
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_DESKTOP_GL) || defined(DAWN_ENABLE_BACKEND_OPENGLES)
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
namespace dawn {
|
||||
namespace {
|
||||
|
@ -54,209 +29,15 @@ using testing::_;
|
|||
using testing::MockCallback;
|
||||
using testing::SaveArg;
|
||||
|
||||
class AdapterDiscoveryTests : public ::testing::Test {};
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_VULKAN)
|
||||
// Test only discovering the SwiftShader adapter
|
||||
TEST(AdapterDiscoveryTests, OnlySwiftShader) {
|
||||
native::Instance instance;
|
||||
|
||||
native::vulkan::AdapterDiscoveryOptions options;
|
||||
options.forceSwiftShader = true;
|
||||
instance.DiscoverAdapters(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
EXPECT_LE(adapters.size(), 2u); // 0 or 2 SwiftShader adapters.
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::Vulkan);
|
||||
EXPECT_EQ(properties.adapterType, wgpu::AdapterType::CPU);
|
||||
EXPECT_TRUE(gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID));
|
||||
}
|
||||
}
|
||||
|
||||
// Test discovering only Vulkan adapters
|
||||
TEST(AdapterDiscoveryTests, OnlyVulkan) {
|
||||
native::Instance instance;
|
||||
|
||||
native::vulkan::AdapterDiscoveryOptions options;
|
||||
instance.DiscoverAdapters(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::Vulkan);
|
||||
}
|
||||
}
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_VULKAN)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_D3D11)
|
||||
// Test discovering only D3D11 adapters
|
||||
TEST(AdapterDiscoveryTests, OnlyD3D11) {
|
||||
native::Instance instance;
|
||||
|
||||
native::d3d11::AdapterDiscoveryOptions options;
|
||||
instance.DiscoverAdapters(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D11);
|
||||
}
|
||||
}
|
||||
|
||||
// Test discovering a D3D11 adapter from a prexisting DXGI adapter
|
||||
TEST(AdapterDiscoveryTests, MatchingDXGIAdapterD3D11) {
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
ComPtr<IDXGIFactory4> dxgiFactory;
|
||||
HRESULT hr = ::CreateDXGIFactory2(0, IID_PPV_ARGS(&dxgiFactory));
|
||||
ASSERT_EQ(hr, S_OK);
|
||||
|
||||
for (uint32_t adapterIndex = 0;; ++adapterIndex) {
|
||||
ComPtr<IDXGIAdapter1> dxgiAdapter = nullptr;
|
||||
if (dxgiFactory->EnumAdapters1(adapterIndex, &dxgiAdapter) == DXGI_ERROR_NOT_FOUND) {
|
||||
break; // No more adapters to enumerate.
|
||||
}
|
||||
|
||||
native::Instance instance;
|
||||
|
||||
native::d3d11::AdapterDiscoveryOptions options;
|
||||
options.dxgiAdapter = std::move(dxgiAdapter);
|
||||
instance.DiscoverAdapters(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D11);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_D3D11)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_D3D12)
|
||||
// Test discovering only D3D12 adapters
|
||||
TEST(AdapterDiscoveryTests, OnlyD3D12) {
|
||||
native::Instance instance;
|
||||
|
||||
native::d3d12::AdapterDiscoveryOptions options;
|
||||
instance.DiscoverAdapters(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D12);
|
||||
}
|
||||
}
|
||||
|
||||
// Test discovering a D3D12 adapter from a prexisting DXGI adapter
|
||||
TEST(AdapterDiscoveryTests, MatchingDXGIAdapterD3D12) {
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
ComPtr<IDXGIFactory4> dxgiFactory;
|
||||
HRESULT hr = ::CreateDXGIFactory2(0, IID_PPV_ARGS(&dxgiFactory));
|
||||
ASSERT_EQ(hr, S_OK);
|
||||
|
||||
for (uint32_t adapterIndex = 0;; ++adapterIndex) {
|
||||
ComPtr<IDXGIAdapter1> dxgiAdapter = nullptr;
|
||||
if (dxgiFactory->EnumAdapters1(adapterIndex, &dxgiAdapter) == DXGI_ERROR_NOT_FOUND) {
|
||||
break; // No more adapters to enumerate.
|
||||
}
|
||||
|
||||
native::Instance instance;
|
||||
|
||||
native::d3d12::AdapterDiscoveryOptions options;
|
||||
options.dxgiAdapter = std::move(dxgiAdapter);
|
||||
instance.DiscoverAdapters(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D12);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_D3D12)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_METAL)
|
||||
// Test discovering only Metal adapters
|
||||
TEST(AdapterDiscoveryTests, OnlyMetal) {
|
||||
native::Instance instance;
|
||||
|
||||
native::metal::AdapterDiscoveryOptions options;
|
||||
instance.DiscoverAdapters(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::Metal);
|
||||
}
|
||||
}
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_METAL)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_METAL) && defined(DAWN_ENABLE_BACKEND_VULKAN)
|
||||
// Test discovering the Metal backend, then the Vulkan backend
|
||||
// does not duplicate adapters.
|
||||
TEST(AdapterDiscoveryTests, OneBackendThenTheOther) {
|
||||
native::Instance instance;
|
||||
uint32_t metalAdapterCount = 0;
|
||||
{
|
||||
native::metal::AdapterDiscoveryOptions options;
|
||||
instance.DiscoverAdapters(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
metalAdapterCount = adapters.size();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
ASSERT_EQ(properties.backendType, wgpu::BackendType::Metal);
|
||||
}
|
||||
}
|
||||
{
|
||||
native::vulkan::AdapterDiscoveryOptions options;
|
||||
instance.DiscoverAdapters(&options);
|
||||
|
||||
uint32_t metalAdapterCount2 = 0;
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_TRUE(properties.backendType == wgpu::BackendType::Metal ||
|
||||
properties.backendType == wgpu::BackendType::Vulkan);
|
||||
if (properties.backendType == wgpu::BackendType::Metal) {
|
||||
metalAdapterCount2++;
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(metalAdapterCount, metalAdapterCount2);
|
||||
}
|
||||
}
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_VULKAN) && defined(DAWN_ENABLE_BACKEND_METAL)
|
||||
|
||||
class AdapterCreationTest : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
dawnProcSetProcs(&dawn_native::GetProcs());
|
||||
dawnProcSetProcs(&native::GetProcs());
|
||||
|
||||
{
|
||||
auto nativeInstance = std::make_unique<dawn_native::Instance>();
|
||||
nativeInstance->DiscoverDefaultAdapters();
|
||||
for (dawn_native::Adapter& nativeAdapter : nativeInstance->GetAdapters()) {
|
||||
auto nativeInstance = std::make_unique<native::Instance>();
|
||||
nativeInstance->DiscoverDefaultPhysicalDevices();
|
||||
for (native::Adapter& nativeAdapter : nativeInstance->GetAdapters()) {
|
||||
anyAdapterAvailable = true;
|
||||
|
||||
wgpu::AdapterProperties properties;
|
|
@ -78,7 +78,7 @@ TEST_F(DeviceInitializationTest, DeviceOutlivesInstance) {
|
|||
{
|
||||
auto instance = std::make_unique<native::Instance>();
|
||||
instance->EnableAdapterBlocklist(false);
|
||||
instance->DiscoverDefaultAdapters();
|
||||
instance->DiscoverDefaultPhysicalDevices();
|
||||
for (const native::Adapter& adapter : instance->GetAdapters()) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
@ -96,7 +96,7 @@ TEST_F(DeviceInitializationTest, DeviceOutlivesInstance) {
|
|||
|
||||
auto instance = std::make_unique<native::Instance>();
|
||||
instance->EnableAdapterBlocklist(false);
|
||||
instance->DiscoverDefaultAdapters();
|
||||
instance->DiscoverDefaultPhysicalDevices();
|
||||
for (native::Adapter& adapter : instance->GetAdapters()) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
@ -127,7 +127,7 @@ TEST_F(DeviceInitializationTest, AdapterOutlivesInstance) {
|
|||
{
|
||||
auto instance = std::make_unique<native::Instance>();
|
||||
instance->EnableAdapterBlocklist(false);
|
||||
instance->DiscoverDefaultAdapters();
|
||||
instance->DiscoverDefaultPhysicalDevices();
|
||||
for (const native::Adapter& adapter : instance->GetAdapters()) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
@ -152,7 +152,7 @@ TEST_F(DeviceInitializationTest, AdapterOutlivesInstance) {
|
|||
// It will only be valid as long as the instance is alive.
|
||||
WGPUInstance unsafeInstancePtr = instance->Get();
|
||||
|
||||
instance->DiscoverDefaultAdapters();
|
||||
instance->DiscoverDefaultPhysicalDevices();
|
||||
for (native::Adapter& nativeAdapter : instance->GetAdapters()) {
|
||||
wgpu::AdapterProperties properties;
|
||||
nativeAdapter.GetProperties(&properties);
|
||||
|
|
|
@ -0,0 +1,243 @@
|
|||
// Copyright 2021 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.
|
||||
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "dawn/common/GPUInfo.h"
|
||||
#include "dawn/native/DawnNative.h"
|
||||
#include "dawn/webgpu_cpp.h"
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_VULKAN)
|
||||
#include "dawn/native/VulkanBackend.h"
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_VULKAN)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_D3D11)
|
||||
#include "dawn/native/D3D11Backend.h"
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_D3D11)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_D3D12)
|
||||
#include "dawn/native/D3D12Backend.h"
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_D3D12)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_METAL)
|
||||
#include "dawn/native/MetalBackend.h"
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_METAL)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_DESKTOP_GL) || defined(DAWN_ENABLE_BACKEND_OPENGLES)
|
||||
#include "GLFW/glfw3.h"
|
||||
#include "dawn/native/OpenGLBackend.h"
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_DESKTOP_GL) || defined(DAWN_ENABLE_BACKEND_OPENGLES)
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
namespace dawn {
|
||||
namespace {
|
||||
|
||||
class PhysicalDeviceDiscoveryTests : public ::testing::Test {};
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_VULKAN)
|
||||
// Test only discovering the SwiftShader physical devices
|
||||
TEST(PhysicalDeviceDiscoveryTests, OnlySwiftShader) {
|
||||
native::Instance instance;
|
||||
|
||||
native::vulkan::PhysicalDeviceDiscoveryOptions options;
|
||||
options.forceSwiftShader = true;
|
||||
instance.DiscoverPhysicalDevices(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
EXPECT_LE(adapters.size(), 2u); // 0 or 2 SwiftShader adapters.
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::Vulkan);
|
||||
EXPECT_EQ(properties.adapterType, wgpu::AdapterType::CPU);
|
||||
EXPECT_TRUE(gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID));
|
||||
}
|
||||
}
|
||||
|
||||
// Test discovering only Vulkan physical devices
|
||||
TEST(PhysicalDeviceDiscoveryTests, OnlyVulkan) {
|
||||
native::Instance instance;
|
||||
|
||||
native::vulkan::PhysicalDeviceDiscoveryOptions options;
|
||||
instance.DiscoverPhysicalDevices(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::Vulkan);
|
||||
}
|
||||
}
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_VULKAN)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_D3D11)
|
||||
// Test discovering only D3D11 physical devices
|
||||
TEST(PhysicalDeviceDiscoveryTests, OnlyD3D11) {
|
||||
native::Instance instance;
|
||||
|
||||
native::d3d11::PhysicalDeviceDiscoveryOptions options;
|
||||
instance.DiscoverPhysicalDevices(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D11);
|
||||
}
|
||||
}
|
||||
|
||||
// Test discovering a D3D11 physical device from a prexisting DXGI adapter
|
||||
TEST(PhysicalDeviceDiscoveryTests, MatchingDXGIAdapterD3D11) {
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
ComPtr<IDXGIFactory4> dxgiFactory;
|
||||
HRESULT hr = ::CreateDXGIFactory2(0, IID_PPV_ARGS(&dxgiFactory));
|
||||
ASSERT_EQ(hr, S_OK);
|
||||
|
||||
for (uint32_t adapterIndex = 0;; ++adapterIndex) {
|
||||
ComPtr<IDXGIAdapter1> dxgiAdapter = nullptr;
|
||||
if (dxgiFactory->EnumAdapters1(adapterIndex, &dxgiAdapter) == DXGI_ERROR_NOT_FOUND) {
|
||||
break; // No more adapters to enumerate.
|
||||
}
|
||||
|
||||
native::Instance instance;
|
||||
|
||||
native::d3d11::PhysicalDeviceDiscoveryOptions options;
|
||||
options.dxgiAdapter = std::move(dxgiAdapter);
|
||||
instance.DiscoverPhysicalDevices(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D11);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_D3D11)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_D3D12)
|
||||
// Test discovering only D3D12 physical devices
|
||||
TEST(PhysicalDeviceDiscoveryTests, OnlyD3D12) {
|
||||
native::Instance instance;
|
||||
|
||||
native::d3d12::PhysicalDeviceDiscoveryOptions options;
|
||||
instance.DiscoverPhysicalDevices(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D12);
|
||||
}
|
||||
}
|
||||
|
||||
// Test discovering a D3D12 physical device from a prexisting DXGI adapter
|
||||
TEST(PhysicalDeviceDiscoveryTests, MatchingDXGIAdapterD3D12) {
|
||||
using Microsoft::WRL::ComPtr;
|
||||
|
||||
ComPtr<IDXGIFactory4> dxgiFactory;
|
||||
HRESULT hr = ::CreateDXGIFactory2(0, IID_PPV_ARGS(&dxgiFactory));
|
||||
ASSERT_EQ(hr, S_OK);
|
||||
|
||||
for (uint32_t adapterIndex = 0;; ++adapterIndex) {
|
||||
ComPtr<IDXGIAdapter1> dxgiAdapter = nullptr;
|
||||
if (dxgiFactory->EnumAdapters1(adapterIndex, &dxgiAdapter) == DXGI_ERROR_NOT_FOUND) {
|
||||
break; // No more adapters to enumerate.
|
||||
}
|
||||
|
||||
native::Instance instance;
|
||||
|
||||
native::d3d12::PhysicalDeviceDiscoveryOptions options;
|
||||
options.dxgiAdapter = std::move(dxgiAdapter);
|
||||
instance.DiscoverPhysicalDevices(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::D3D12);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_D3D12)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_METAL)
|
||||
// Test discovering only Metal physical devices
|
||||
TEST(PhysicalDeviceDiscoveryTests, OnlyMetal) {
|
||||
native::Instance instance;
|
||||
|
||||
native::metal::PhysicalDeviceDiscoveryOptions options;
|
||||
instance.DiscoverPhysicalDevices(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_EQ(properties.backendType, wgpu::BackendType::Metal);
|
||||
}
|
||||
}
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_METAL)
|
||||
|
||||
#if defined(DAWN_ENABLE_BACKEND_METAL) && defined(DAWN_ENABLE_BACKEND_VULKAN)
|
||||
// Test discovering the Metal backend, then the Vulkan backend
|
||||
// does not duplicate physical devices.
|
||||
TEST(PhysicalDeviceDiscoveryTests, OneBackendThenTheOther) {
|
||||
native::Instance instance;
|
||||
uint32_t metalAdapterCount = 0;
|
||||
{
|
||||
native::metal::PhysicalDeviceDiscoveryOptions options;
|
||||
instance.DiscoverPhysicalDevices(&options);
|
||||
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
metalAdapterCount = adapters.size();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
ASSERT_EQ(properties.backendType, wgpu::BackendType::Metal);
|
||||
}
|
||||
}
|
||||
{
|
||||
native::vulkan::PhysicalDeviceDiscoveryOptions options;
|
||||
instance.DiscoverPhysicalDevices(&options);
|
||||
|
||||
uint32_t metalAdapterCount2 = 0;
|
||||
const auto& adapters = instance.GetAdapters();
|
||||
for (const auto& adapter : adapters) {
|
||||
wgpu::AdapterProperties properties;
|
||||
adapter.GetProperties(&properties);
|
||||
|
||||
EXPECT_TRUE(properties.backendType == wgpu::BackendType::Metal ||
|
||||
properties.backendType == wgpu::BackendType::Vulkan);
|
||||
if (properties.backendType == wgpu::BackendType::Metal) {
|
||||
metalAdapterCount2++;
|
||||
}
|
||||
}
|
||||
EXPECT_EQ(metalAdapterCount, metalAdapterCount2);
|
||||
}
|
||||
}
|
||||
#endif // defined(DAWN_ENABLE_BACKEND_VULKAN) && defined(DAWN_ENABLE_BACKEND_METAL)
|
||||
|
||||
} // anonymous namespace
|
||||
} // namespace dawn
|
|
@ -170,10 +170,10 @@ TEST_F(InstanceToggleTest, InstanceTogglesInheritToAdapterAndDevice) {
|
|||
native::InstanceBase* instance = native::FromAPI(nativeInstance->Get());
|
||||
const native::TogglesState& instanceTogglesState = instance->GetTogglesState();
|
||||
|
||||
// Discover adapters with default toggles.
|
||||
instance->DiscoverDefaultAdapters();
|
||||
// Discover physical devices.
|
||||
instance->DiscoverDefaultPhysicalDevices();
|
||||
|
||||
// Get the adapter created by instance with default toggles.
|
||||
// Get the adapters created by instance with default toggles.
|
||||
Ref<native::AdapterBase> nullAdapter;
|
||||
for (auto& adapter : instance->GetAdapters()) {
|
||||
if (adapter->GetPhysicalDevice()->GetBackendType() == wgpu::BackendType::Null) {
|
||||
|
|
|
@ -43,7 +43,7 @@ class DeviceCreationTest : public testing::Test {
|
|||
// Create an instance with default toggles and create an adapter from it.
|
||||
WGPUInstanceDescriptor safeInstanceDesc = {};
|
||||
instance = std::make_unique<dawn::native::Instance>(&safeInstanceDesc);
|
||||
instance->DiscoverDefaultAdapters();
|
||||
instance->DiscoverDefaultPhysicalDevices();
|
||||
for (dawn::native::Adapter& nativeAdapter : instance->GetAdapters()) {
|
||||
wgpu::AdapterProperties properties;
|
||||
nativeAdapter.GetProperties(&properties);
|
||||
|
@ -67,7 +67,7 @@ class DeviceCreationTest : public testing::Test {
|
|||
unsafeInstanceDesc.nextInChain = &unsafeInstanceTogglesDesc.chain;
|
||||
|
||||
unsafeInstanceDisallow = std::make_unique<dawn::native::Instance>(&unsafeInstanceDesc);
|
||||
unsafeInstanceDisallow->DiscoverDefaultAdapters();
|
||||
unsafeInstanceDisallow->DiscoverDefaultPhysicalDevices();
|
||||
for (dawn::native::Adapter& nativeAdapter : unsafeInstanceDisallow->GetAdapters()) {
|
||||
wgpu::AdapterProperties properties;
|
||||
nativeAdapter.GetProperties(&properties);
|
||||
|
@ -90,7 +90,7 @@ class DeviceCreationTest : public testing::Test {
|
|||
unsafeInstanceDesc.nextInChain = &unsafeInstanceTogglesDesc.chain;
|
||||
|
||||
unsafeInstance = std::make_unique<dawn::native::Instance>(&unsafeInstanceDesc);
|
||||
unsafeInstance->DiscoverDefaultAdapters();
|
||||
unsafeInstance->DiscoverDefaultPhysicalDevices();
|
||||
for (dawn::native::Adapter& nativeAdapter : unsafeInstance->GetAdapters()) {
|
||||
wgpu::AdapterProperties properties;
|
||||
nativeAdapter.GetProperties(&properties);
|
||||
|
|
|
@ -145,7 +145,7 @@ void ValidationTest::SetUp() {
|
|||
|
||||
mDawnInstance = std::make_unique<dawn::native::Instance>(&instanceDesc);
|
||||
|
||||
mDawnInstance->DiscoverDefaultAdapters();
|
||||
mDawnInstance->DiscoverDefaultPhysicalDevices();
|
||||
mInstance = mWireHelper->RegisterInstance(mDawnInstance->Get());
|
||||
|
||||
std::string traceName =
|
||||
|
|
Loading…
Reference in New Issue