Turn AdapterBase into a wrapper class.

Change AdapterBase from an alias to PhysicalDeviceBase to a thin
wrapper class holding a ref to a PhysicalDeviceBase. This way,
mutiple AdapterBases can point at the same PhysicalDeviceBase.

For now, InstanceBase wraps all PhysicalDeviceBases discovered by a
backend in a single AdapterBase. In the future, this relationship will
become many-to-one.

Since Devices now maintain a ref on the AdapterBase wrapper (in order to
query toggles, etc), PhysicalDeviceBase::CreateDeviceImpl() now takes
the AdapterBase as an argument, so that the PhysicalDeviceBase knows
which AdapterBase to vend a Device for.

Note that the Toggles also still remain on the PhysicalDeviceBase, to
be moved up to the AdapterBase in a future change.

Bug: dawn:1774
Change-Id: Idef5d24fbd66d8552959230e246e453abddcc736
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/131001
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Stephen White <senorblanco@chromium.org>
This commit is contained in:
Stephen White 2023-05-03 01:29:44 +00:00 committed by Dawn LUCI CQ
parent 5eb3619d3e
commit fed6b6b35b
39 changed files with 225 additions and 102 deletions

View File

@ -34,7 +34,8 @@ struct DeviceDescriptor;
namespace dawn::native { namespace dawn::native {
class InstanceBase; class InstanceBase;
class PhysicalDeviceBase; class AdapterBase;
// An optional parameter of Adapter::CreateDevice() to send additional information when creating // 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. // a Device. For example, we can use it to enable a workaround, optimization or feature.
struct DAWN_NATIVE_EXPORT DawnDeviceDescriptor { struct DAWN_NATIVE_EXPORT DawnDeviceDescriptor {
@ -84,10 +85,8 @@ struct FeatureInfo {
class DAWN_NATIVE_EXPORT Adapter { class DAWN_NATIVE_EXPORT Adapter {
public: public:
Adapter(); Adapter();
// TODO(dawn:1774): all references to PhysicalDeviceBase in this class will go back to
// using AdapterBase once the latter becomes a real class again.
// NOLINTNEXTLINE(runtime/explicit) // NOLINTNEXTLINE(runtime/explicit)
Adapter(PhysicalDeviceBase* impl); Adapter(AdapterBase* impl);
~Adapter(); ~Adapter();
Adapter(const Adapter& other); Adapter(const Adapter& other);
@ -132,7 +131,7 @@ class DAWN_NATIVE_EXPORT Adapter {
void ResetInternalDeviceForTesting(); void ResetInternalDeviceForTesting();
private: private:
PhysicalDeviceBase* mImpl = nullptr; AdapterBase* mImpl = nullptr;
}; };
// Base class for options passed to Instance::DiscoverAdapters. // Base class for options passed to Instance::DiscoverAdapters.

View File

@ -0,0 +1,66 @@
// Copyright 2023 The Dawn Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#include "dawn/native/Adapter.h"
#include <utility>
#include "dawn/native/PhysicalDevice.h"
namespace dawn::native {
AdapterBase::AdapterBase(const Ref<PhysicalDeviceBase>& physicalDevice)
: mPhysicalDevice(std::move(physicalDevice)) {}
AdapterBase::~AdapterBase() = default;
PhysicalDeviceBase* AdapterBase::GetPhysicalDevice() {
return mPhysicalDevice.Get();
}
InstanceBase* AdapterBase::APIGetInstance() const {
return mPhysicalDevice->APIGetInstance();
}
bool AdapterBase::APIGetLimits(SupportedLimits* limits) const {
return mPhysicalDevice->APIGetLimits(limits);
}
void AdapterBase::APIGetProperties(AdapterProperties* properties) const {
mPhysicalDevice->APIGetProperties(properties);
}
bool AdapterBase::APIHasFeature(wgpu::FeatureName feature) const {
return mPhysicalDevice->APIHasFeature(feature);
}
size_t AdapterBase::APIEnumerateFeatures(wgpu::FeatureName* features) const {
return mPhysicalDevice->APIEnumerateFeatures(features);
}
DeviceBase* AdapterBase::APICreateDevice(const DeviceDescriptor* descriptor) {
return mPhysicalDevice->CreateDevice(this, descriptor);
}
void AdapterBase::APIRequestDevice(const DeviceDescriptor* descriptor,
WGPURequestDeviceCallback callback,
void* userdata) {
return mPhysicalDevice->RequestDevice(this, descriptor, callback, userdata);
}
const TogglesState& AdapterBase::GetTogglesState() const {
return mPhysicalDevice->GetTogglesState();
}
} // namespace dawn::native

View File

@ -15,12 +15,43 @@
#ifndef SRC_DAWN_NATIVE_ADAPTER_H_ #ifndef SRC_DAWN_NATIVE_ADAPTER_H_
#define SRC_DAWN_NATIVE_ADAPTER_H_ #define SRC_DAWN_NATIVE_ADAPTER_H_
#include "dawn/native/PhysicalDevice.h" #include "dawn/native/DawnNative.h"
#include "dawn/common/RefCounted.h"
#include "dawn/native/dawn_platform.h"
namespace dawn::native { namespace dawn::native {
using AdapterBase = PhysicalDeviceBase; class DeviceBase;
class TogglesState;
struct SupportedLimits;
} class AdapterBase : public RefCounted {
public:
explicit AdapterBase(const Ref<PhysicalDeviceBase>& physicalDevice);
~AdapterBase() override;
// WebGPU API
InstanceBase* APIGetInstance() const;
bool APIGetLimits(SupportedLimits* limits) const;
void APIGetProperties(AdapterProperties* properties) const;
bool APIHasFeature(wgpu::FeatureName feature) const;
size_t APIEnumerateFeatures(wgpu::FeatureName* features) const;
void APIRequestDevice(const DeviceDescriptor* descriptor,
WGPURequestDeviceCallback callback,
void* userdata);
DeviceBase* APICreateDevice(const DeviceDescriptor* descriptor = nullptr);
// Return the underlying PhysicalDevice.
PhysicalDeviceBase* GetPhysicalDevice();
// Get the actual toggles state of the adapter.
const TogglesState& GetTogglesState() const;
private:
Ref<PhysicalDeviceBase> mPhysicalDevice;
};
} // namespace dawn::native
#endif // SRC_DAWN_NATIVE_ADAPTER_H_ #endif // SRC_DAWN_NATIVE_ADAPTER_H_

View File

@ -184,6 +184,7 @@ source_set("sources") {
sources = get_target_outputs(":utils_gen") sources = get_target_outputs(":utils_gen")
sources += [ sources += [
"Adapter.cpp",
"Adapter.h", "Adapter.h",
"ApplyClearColorValueWithDrawHelper.cpp", "ApplyClearColorValueWithDrawHelper.cpp",
"ApplyClearColorValueWithDrawHelper.h", "ApplyClearColorValueWithDrawHelper.h",

View File

@ -31,6 +31,7 @@ target_sources(dawn_native PRIVATE
"${DAWN_INCLUDE_DIR}/dawn/native/dawn_native_export.h" "${DAWN_INCLUDE_DIR}/dawn/native/dawn_native_export.h"
${DAWN_NATIVE_UTILS_GEN_SOURCES} ${DAWN_NATIVE_UTILS_GEN_SOURCES}
"Adapter.h" "Adapter.h"
"Adapter.cpp"
"ApplyClearColorValueWithDrawHelper.cpp" "ApplyClearColorValueWithDrawHelper.cpp"
"ApplyClearColorValueWithDrawHelper.h" "ApplyClearColorValueWithDrawHelper.h"
"AsyncTask.cpp" "AsyncTask.cpp"

View File

@ -79,7 +79,7 @@ MaybeError ValidateTimestampQuery(const DeviceBase* device,
DAWN_INVALID_IF(!device->HasFeature(requiredFeature), DAWN_INVALID_IF(!device->HasFeature(requiredFeature),
"Timestamp queries used without the %s feature enabled.", "Timestamp queries used without the %s feature enabled.",
device->GetAdapter() device->GetPhysicalDevice()
->GetInstance() ->GetInstance()
->GetFeatureInfo(FeatureEnumToAPIFeature(requiredFeature)) ->GetFeatureInfo(FeatureEnumToAPIFeature(requiredFeature))
->name); ->name);

View File

@ -81,7 +81,7 @@ DawnDeviceDescriptor::~DawnDeviceDescriptor() = default;
Adapter::Adapter() = default; Adapter::Adapter() = default;
Adapter::Adapter(PhysicalDeviceBase* impl) : mImpl(impl) { Adapter::Adapter(AdapterBase* impl) : mImpl(impl) {
if (mImpl != nullptr) { if (mImpl != nullptr) {
mImpl->Reference(); mImpl->Reference();
} }
@ -122,20 +122,20 @@ WGPUAdapter Adapter::Get() const {
} }
std::vector<const char*> Adapter::GetSupportedFeatures() const { std::vector<const char*> Adapter::GetSupportedFeatures() const {
FeaturesSet supportedFeaturesSet = mImpl->GetSupportedFeatures(); FeaturesSet supportedFeaturesSet = mImpl->GetPhysicalDevice()->GetSupportedFeatures();
return supportedFeaturesSet.GetEnabledFeatureNames(); return supportedFeaturesSet.GetEnabledFeatureNames();
} }
bool Adapter::GetLimits(WGPUSupportedLimits* limits) const { bool Adapter::GetLimits(WGPUSupportedLimits* limits) const {
return mImpl->GetLimits(FromAPI(limits)); return mImpl->GetPhysicalDevice()->GetLimits(FromAPI(limits));
} }
void Adapter::SetUseTieredLimits(bool useTieredLimits) { void Adapter::SetUseTieredLimits(bool useTieredLimits) {
mImpl->SetUseTieredLimits(useTieredLimits); mImpl->GetPhysicalDevice()->SetUseTieredLimits(useTieredLimits);
} }
bool Adapter::SupportsExternalImages() const { bool Adapter::SupportsExternalImages() const {
return mImpl->SupportsExternalImages(); return mImpl->GetPhysicalDevice()->SupportsExternalImages();
} }
Adapter::operator bool() const { Adapter::operator bool() const {
@ -177,7 +177,7 @@ void Adapter::RequestDevice(const WGPUDeviceDescriptor* descriptor,
} }
void Adapter::ResetInternalDeviceForTesting() { void Adapter::ResetInternalDeviceForTesting() {
mImpl->ResetInternalDeviceForTesting(); mImpl->GetPhysicalDevice()->ResetInternalDeviceForTesting();
} }
// AdapterDiscoverOptionsBase // AdapterDiscoverOptionsBase
@ -210,7 +210,7 @@ bool Instance::DiscoverAdapters(const AdapterDiscoveryOptionsBase* options) {
std::vector<Adapter> Instance::GetAdapters() const { std::vector<Adapter> Instance::GetAdapters() const {
// Adapters are owned by mImpl so it is safe to return non RAII pointers to them // Adapters are owned by mImpl so it is safe to return non RAII pointers to them
std::vector<Adapter> adapters; std::vector<Adapter> adapters;
for (const Ref<PhysicalDeviceBase>& adapter : mImpl->GetAdapters()) { for (const Ref<AdapterBase>& adapter : mImpl->GetAdapters()) {
adapters.push_back(Adapter(adapter.Get())); adapters.push_back(Adapter(adapter.Get()));
} }
return adapters; return adapters;

View File

@ -286,7 +286,7 @@ MaybeError DeviceBase::Initialize(Ref<QueueBase> defaultQueue) {
// mAdapter is not set for mock test devices. // mAdapter is not set for mock test devices.
// TODO(crbug.com/dawn/1702): using a mock adapter could avoid the null checking. // TODO(crbug.com/dawn/1702): using a mock adapter could avoid the null checking.
if (mAdapter != nullptr) { if (mAdapter != nullptr) {
mAdapter->GetInstance()->AddDevice(this); mAdapter->GetPhysicalDevice()->GetInstance()->AddDevice(this);
} }
return {}; return {};
@ -344,11 +344,12 @@ void DeviceBase::WillDropLastExternalRef() {
// mAdapter is not set for mock test devices. // mAdapter is not set for mock test devices.
// TODO(crbug.com/dawn/1702): using a mock adapter could avoid the null checking. // TODO(crbug.com/dawn/1702): using a mock adapter could avoid the null checking.
if (mAdapter != nullptr) { if (mAdapter != nullptr) {
mAdapter->GetInstance()->RemoveDevice(this); mAdapter->GetPhysicalDevice()->GetInstance()->RemoveDevice(this);
// Once last external ref dropped, all callbacks should be forwarded to Instance's callback // Once last external ref dropped, all callbacks should be forwarded to Instance's callback
// queue instead. // queue instead.
mCallbackTaskManager = mAdapter->GetInstance()->GetCallbackTaskManager(); mCallbackTaskManager =
mAdapter->GetPhysicalDevice()->GetInstance()->GetCallbackTaskManager();
} }
} }
@ -659,9 +660,10 @@ BlobCache* DeviceBase::GetBlobCache() {
// TODO(crbug.com/dawn/1481): Shader caching currently has a dependency on the WGSL writer to // TODO(crbug.com/dawn/1481): Shader caching currently has a dependency on the WGSL writer to
// generate cache keys. We can lift the dependency once we also cache frontend parsing, // generate cache keys. We can lift the dependency once we also cache frontend parsing,
// transformations, and reflection. // transformations, and reflection.
return mAdapter->GetInstance()->GetBlobCache(!IsToggleEnabled(Toggle::DisableBlobCache)); return mAdapter->GetPhysicalDevice()->GetInstance()->GetBlobCache(
!IsToggleEnabled(Toggle::DisableBlobCache));
#else #else
return mAdapter->GetInstance()->GetBlobCache(false); return mAdapter->GetPhysicalDevice()->GetInstance()->GetBlobCache(false);
#endif #endif
} }
@ -720,12 +722,11 @@ AdapterBase* DeviceBase::GetAdapter() const {
} }
PhysicalDeviceBase* DeviceBase::GetPhysicalDevice() const { PhysicalDeviceBase* DeviceBase::GetPhysicalDevice() const {
return mAdapter return mAdapter->GetPhysicalDevice();
.Get(); // TODO(dawn:1774): This will retrieve the PhysicalDevice from the AdapterBase.
} }
dawn::platform::Platform* DeviceBase::GetPlatform() const { dawn::platform::Platform* DeviceBase::GetPlatform() const {
return GetAdapter()->GetInstance()->GetPlatform(); return GetPhysicalDevice()->GetInstance()->GetPlatform();
} }
ExecutionSerial DeviceBase::GetCompletedCommandSerial() const { ExecutionSerial DeviceBase::GetCompletedCommandSerial() const {
@ -1346,7 +1347,7 @@ MaybeError DeviceBase::Tick() {
return {}; return {};
} }
PhysicalDeviceBase* DeviceBase::APIGetAdapter() { AdapterBase* DeviceBase::APIGetAdapter() {
mAdapter->Reference(); mAdapter->Reference();
return mAdapter.Get(); return mAdapter.Get();
} }
@ -1373,7 +1374,7 @@ ExternalTextureBase* DeviceBase::APICreateExternalTexture(
void DeviceBase::ApplyFeatures(const DeviceDescriptor* deviceDescriptor) { void DeviceBase::ApplyFeatures(const DeviceDescriptor* deviceDescriptor) {
ASSERT(deviceDescriptor); ASSERT(deviceDescriptor);
ASSERT(GetAdapter()->SupportsAllRequiredFeatures( ASSERT(GetPhysicalDevice()->SupportsAllRequiredFeatures(
{deviceDescriptor->requiredFeatures, deviceDescriptor->requiredFeaturesCount})); {deviceDescriptor->requiredFeatures, deviceDescriptor->requiredFeaturesCount}));
for (uint32_t i = 0; i < deviceDescriptor->requiredFeaturesCount; ++i) { for (uint32_t i = 0; i < deviceDescriptor->requiredFeaturesCount; ++i) {

View File

@ -24,6 +24,7 @@ namespace dawn::native {
enum class ObjectType : uint32_t; enum class ObjectType : uint32_t;
class AdapterBase;
class BindGroupBase; class BindGroupBase;
class BindGroupLayoutBase; class BindGroupLayoutBase;
class BufferBase; class BufferBase;
@ -51,8 +52,6 @@ class SwapChainBase;
class TextureBase; class TextureBase;
class TextureViewBase; class TextureViewBase;
using AdapterBase = PhysicalDeviceBase;
class DeviceBase; class DeviceBase;
template <typename T> template <typename T>

View File

@ -313,13 +313,13 @@ void InstanceBase::DiscoverDefaultAdapters() {
TogglesState adapterToggles = TogglesState(ToggleStage::Adapter); TogglesState adapterToggles = TogglesState(ToggleStage::Adapter);
adapterToggles.InheritFrom(mToggles); adapterToggles.InheritFrom(mToggles);
std::vector<Ref<AdapterBase>> backendAdapters = std::vector<Ref<PhysicalDeviceBase>> physicalDevices =
backend->DiscoverDefaultAdapters(adapterToggles); backend->DiscoverDefaultAdapters(adapterToggles);
for (Ref<AdapterBase>& adapter : backendAdapters) { for (Ref<PhysicalDeviceBase>& physicalDevice : physicalDevices) {
ASSERT(adapter->GetBackendType() == backend->GetType()); ASSERT(physicalDevice->GetBackendType() == backend->GetType());
ASSERT(adapter->GetInstance() == this); ASSERT(physicalDevice->GetInstance() == this);
mAdapters.push_back(std::move(adapter)); mAdapters.push_back(AcquireRef(new AdapterBase(std::move(physicalDevice))));
} }
} }
@ -447,13 +447,13 @@ MaybeError InstanceBase::DiscoverAdaptersInternal(const AdapterDiscoveryOptionsB
TogglesState adapterToggles = TogglesState(ToggleStage::Adapter); TogglesState adapterToggles = TogglesState(ToggleStage::Adapter);
adapterToggles.InheritFrom(mToggles); adapterToggles.InheritFrom(mToggles);
std::vector<Ref<AdapterBase>> newAdapters; std::vector<Ref<PhysicalDeviceBase>> newPhysicalDevices;
DAWN_TRY_ASSIGN(newAdapters, backend->DiscoverAdapters(options, adapterToggles)); DAWN_TRY_ASSIGN(newPhysicalDevices, backend->DiscoverAdapters(options, adapterToggles));
for (Ref<AdapterBase>& adapter : newAdapters) { for (Ref<PhysicalDeviceBase>& physicalDevice : newPhysicalDevices) {
ASSERT(adapter->GetBackendType() == backend->GetType()); ASSERT(physicalDevice->GetBackendType() == backend->GetType());
ASSERT(adapter->GetInstance() == this); ASSERT(physicalDevice->GetInstance() == this);
mAdapters.push_back(std::move(adapter)); mAdapters.push_back(AcquireRef(new AdapterBase(std::move(physicalDevice))));
} }
} }

View File

@ -127,12 +127,13 @@ size_t PhysicalDeviceBase::APIEnumerateFeatures(wgpu::FeatureName* features) con
return mSupportedFeatures.EnumerateFeatures(features); return mSupportedFeatures.EnumerateFeatures(features);
} }
DeviceBase* PhysicalDeviceBase::APICreateDevice(const DeviceDescriptor* descriptor) { DeviceBase* PhysicalDeviceBase::CreateDevice(AdapterBase* adapter,
const DeviceDescriptor* descriptor) {
DeviceDescriptor defaultDesc = {}; DeviceDescriptor defaultDesc = {};
if (descriptor == nullptr) { if (descriptor == nullptr) {
descriptor = &defaultDesc; descriptor = &defaultDesc;
} }
auto result = CreateDeviceInternal(descriptor); auto result = CreateDeviceInternal(adapter, descriptor);
if (result.IsError()) { if (result.IsError()) {
mInstance->ConsumedError(result.AcquireError()); mInstance->ConsumedError(result.AcquireError());
return nullptr; return nullptr;
@ -140,14 +141,15 @@ DeviceBase* PhysicalDeviceBase::APICreateDevice(const DeviceDescriptor* descript
return result.AcquireSuccess().Detach(); return result.AcquireSuccess().Detach();
} }
void PhysicalDeviceBase::APIRequestDevice(const DeviceDescriptor* descriptor, void PhysicalDeviceBase::RequestDevice(AdapterBase* adapter,
WGPURequestDeviceCallback callback, const DeviceDescriptor* descriptor,
void* userdata) { WGPURequestDeviceCallback callback,
void* userdata) {
static constexpr DeviceDescriptor kDefaultDescriptor = {}; static constexpr DeviceDescriptor kDefaultDescriptor = {};
if (descriptor == nullptr) { if (descriptor == nullptr) {
descriptor = &kDefaultDescriptor; descriptor = &kDefaultDescriptor;
} }
auto result = CreateDeviceInternal(descriptor); auto result = CreateDeviceInternal(adapter, descriptor);
if (result.IsError()) { if (result.IsError()) {
std::unique_ptr<ErrorData> errorData = result.AcquireError(); std::unique_ptr<ErrorData> errorData = result.AcquireError();
@ -253,6 +255,7 @@ void PhysicalDeviceBase::SetSupportedFeaturesForTesting(
} }
ResultOrError<Ref<DeviceBase>> PhysicalDeviceBase::CreateDeviceInternal( ResultOrError<Ref<DeviceBase>> PhysicalDeviceBase::CreateDeviceInternal(
AdapterBase* adapter,
const DeviceDescriptor* descriptor) { const DeviceDescriptor* descriptor) {
ASSERT(descriptor != nullptr); ASSERT(descriptor != nullptr);
@ -289,7 +292,7 @@ ResultOrError<Ref<DeviceBase>> PhysicalDeviceBase::CreateDeviceInternal(
DAWN_INVALID_IF(descriptor->requiredLimits->nextInChain != nullptr, DAWN_INVALID_IF(descriptor->requiredLimits->nextInChain != nullptr,
"nextInChain is not nullptr."); "nextInChain is not nullptr.");
} }
return CreateDeviceImpl(descriptor, deviceToggles); return CreateDeviceImpl(adapter, descriptor, deviceToggles);
} }
void PhysicalDeviceBase::SetUseTieredLimits(bool useTieredLimits) { void PhysicalDeviceBase::SetUseTieredLimits(bool useTieredLimits) {

View File

@ -48,10 +48,11 @@ class PhysicalDeviceBase : public RefCounted {
void APIGetProperties(AdapterProperties* properties) const; void APIGetProperties(AdapterProperties* properties) const;
bool APIHasFeature(wgpu::FeatureName feature) const; bool APIHasFeature(wgpu::FeatureName feature) const;
size_t APIEnumerateFeatures(wgpu::FeatureName* features) const; size_t APIEnumerateFeatures(wgpu::FeatureName* features) const;
void APIRequestDevice(const DeviceDescriptor* descriptor, void RequestDevice(AdapterBase* adapter,
WGPURequestDeviceCallback callback, const DeviceDescriptor* descriptor,
void* userdata); WGPURequestDeviceCallback callback,
DeviceBase* APICreateDevice(const DeviceDescriptor* descriptor = nullptr); void* userdata);
DeviceBase* CreateDevice(AdapterBase* adapter, const DeviceDescriptor* descriptor = nullptr);
uint32_t GetVendorId() const; uint32_t GetVendorId() const;
uint32_t GetDeviceId() const; uint32_t GetDeviceId() const;
@ -101,7 +102,8 @@ class PhysicalDeviceBase : public RefCounted {
// Backend-specific force-setting and defaulting device toggles // Backend-specific force-setting and defaulting device toggles
virtual void SetupBackendDeviceToggles(TogglesState* deviceToggles) const = 0; virtual void SetupBackendDeviceToggles(TogglesState* deviceToggles) const = 0;
virtual ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(const DeviceDescriptor* descriptor, virtual ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles) = 0; const TogglesState& deviceToggles) = 0;
virtual MaybeError InitializeImpl() = 0; virtual MaybeError InitializeImpl() = 0;
@ -118,7 +120,8 @@ class PhysicalDeviceBase : public RefCounted {
wgpu::FeatureName feature, wgpu::FeatureName feature,
const TogglesState& toggles) const = 0; const TogglesState& toggles) const = 0;
ResultOrError<Ref<DeviceBase>> CreateDeviceInternal(const DeviceDescriptor* descriptor); ResultOrError<Ref<DeviceBase>> CreateDeviceInternal(AdapterBase* adapter,
const DeviceDescriptor* descriptor);
virtual MaybeError ResetInternalDeviceForTestingImpl(); virtual MaybeError ResetInternalDeviceForTestingImpl();
Ref<InstanceBase> mInstance; Ref<InstanceBase> mInstance;

View File

@ -233,7 +233,7 @@ bool SwapChainBase::IsAttached() const {
} }
wgpu::BackendType SwapChainBase::GetBackendType() const { wgpu::BackendType SwapChainBase::GetBackendType() const {
return GetDevice()->GetAdapter()->GetBackendType(); return GetDevice()->GetPhysicalDevice()->GetBackendType();
} }
MaybeError SwapChainBase::ValidatePresent() const { MaybeError SwapChainBase::ValidatePresent() const {

View File

@ -199,9 +199,10 @@ void PhysicalDevice::SetupBackendDeviceToggles(TogglesState* deviceToggles) cons
deviceToggles->Default(Toggle::ApplyClearBigIntegerColorValueWithDraw, true); deviceToggles->Default(Toggle::ApplyClearBigIntegerColorValueWithDraw, true);
} }
ResultOrError<Ref<DeviceBase>> PhysicalDevice::CreateDeviceImpl(const DeviceDescriptor* descriptor, ResultOrError<Ref<DeviceBase>> PhysicalDevice::CreateDeviceImpl(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles) { const TogglesState& deviceToggles) {
return Device::Create(this, descriptor, deviceToggles); return Device::Create(adapter, descriptor, deviceToggles);
} }
// Resets the backend device and creates a new one. If any D3D11 objects belonging to the // Resets the backend device and creates a new one. If any D3D11 objects belonging to the

View File

@ -42,7 +42,8 @@ class PhysicalDevice : public d3d::PhysicalDevice {
void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override; void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override;
ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(const DeviceDescriptor* descriptor, ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles) override; const TogglesState& deviceToggles) override;
MaybeError ResetInternalDeviceForTestingImpl() override; MaybeError ResetInternalDeviceForTestingImpl() override;

View File

@ -579,9 +579,10 @@ void PhysicalDevice::SetupBackendDeviceToggles(TogglesState* deviceToggles) cons
} }
} }
ResultOrError<Ref<DeviceBase>> PhysicalDevice::CreateDeviceImpl(const DeviceDescriptor* descriptor, ResultOrError<Ref<DeviceBase>> PhysicalDevice::CreateDeviceImpl(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles) { const TogglesState& deviceToggles) {
return Device::Create(this, descriptor, deviceToggles); return Device::Create(adapter, descriptor, deviceToggles);
} }
// Resets the backend device and creates a new one. If any D3D12 objects belonging to the // Resets the backend device and creates a new one. If any D3D12 objects belonging to the

View File

@ -44,7 +44,8 @@ class PhysicalDevice : public d3d::PhysicalDevice {
void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override; void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override;
ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(const DeviceDescriptor* descriptor, ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles) override; const TogglesState& deviceToggles) override;
MaybeError ResetInternalDeviceForTestingImpl() override; MaybeError ResetInternalDeviceForTestingImpl() override;

View File

@ -115,7 +115,7 @@ void ResidencyManager::UpdateVideoMemoryInfo() {
void ResidencyManager::UpdateMemorySegmentInfo(MemorySegmentInfo* segmentInfo) { void ResidencyManager::UpdateMemorySegmentInfo(MemorySegmentInfo* segmentInfo) {
DXGI_QUERY_VIDEO_MEMORY_INFO queryVideoMemoryInfo; DXGI_QUERY_VIDEO_MEMORY_INFO queryVideoMemoryInfo;
ToBackend(mDevice->GetAdapter()) ToBackend(mDevice->GetPhysicalDevice())
->GetHardwareAdapter() ->GetHardwareAdapter()
->QueryVideoMemoryInfo(0, segmentInfo->dxgiSegment, &queryVideoMemoryInfo); ->QueryVideoMemoryInfo(0, segmentInfo->dxgiSegment, &queryVideoMemoryInfo);

View File

@ -89,10 +89,10 @@ ResultOrError<d3d::CompiledShader> ShaderModule::Compile(
if (device->IsToggleEnabled(Toggle::UseDXC)) { if (device->IsToggleEnabled(Toggle::UseDXC)) {
// If UseDXC toggle are not forced to be disable, DXC should have been validated to be // If UseDXC toggle are not forced to be disable, DXC should have been validated to be
// available. // available.
ASSERT(ToBackend(device->GetAdapter())->GetBackend()->IsDXCAvailable()); ASSERT(ToBackend(device->GetPhysicalDevice())->GetBackend()->IsDXCAvailable());
// We can get the DXC version information since IsDXCAvailable() is true. // We can get the DXC version information since IsDXCAvailable() is true.
d3d::DxcVersionInfo dxcVersionInfo = d3d::DxcVersionInfo dxcVersionInfo =
ToBackend(device->GetAdapter())->GetBackend()->GetDxcVersion(); ToBackend(device->GetPhysicalDevice())->GetBackend()->GetDxcVersion();
req.bytecode.compiler = d3d::Compiler::DXC; req.bytecode.compiler = d3d::Compiler::DXC;
req.bytecode.dxcLibrary = device->GetDxcLibrary().Get(); req.bytecode.dxcLibrary = device->GetDxcLibrary().Get();

View File

@ -293,9 +293,10 @@ class PhysicalDevice : public PhysicalDeviceBase {
} }
private: private:
ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(const DeviceDescriptor* descriptor, ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles) override { const TogglesState& deviceToggles) override {
return Device::Create(this, mDevice, descriptor, deviceToggles); return Device::Create(adapter, mDevice, descriptor, deviceToggles);
} }
void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override { void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override {

View File

@ -86,14 +86,14 @@ bool ComputePipeline::RequiresStorageBufferLength() const {
void ComputePipeline::InitializeAsync(Ref<ComputePipelineBase> computePipeline, void ComputePipeline::InitializeAsync(Ref<ComputePipelineBase> computePipeline,
WGPUCreateComputePipelineAsyncCallback callback, WGPUCreateComputePipelineAsyncCallback callback,
void* userdata) { void* userdata) {
AdapterBase* adapter = computePipeline->GetDevice()->GetAdapter(); PhysicalDeviceBase* physicalDevice = computePipeline->GetDevice()->GetPhysicalDevice();
std::unique_ptr<CreateComputePipelineAsyncTask> asyncTask = std::unique_ptr<CreateComputePipelineAsyncTask> asyncTask =
std::make_unique<CreateComputePipelineAsyncTask>(std::move(computePipeline), callback, std::make_unique<CreateComputePipelineAsyncTask>(std::move(computePipeline), callback,
userdata); userdata);
// Workaround a crash where the validation layers on AMD crash with partition alloc. // Workaround a crash where the validation layers on AMD crash with partition alloc.
// See crbug.com/dawn/1200. // See crbug.com/dawn/1200.
if (adapter->GetInstance()->IsBackendValidationEnabled() && if (physicalDevice->GetInstance()->IsBackendValidationEnabled() &&
gpu_info::IsAMD(adapter->GetVendorId())) { gpu_info::IsAMD(physicalDevice->GetVendorId())) {
asyncTask->Run(); asyncTask->Run();
return; return;
} }

View File

@ -16,6 +16,7 @@
#include "dawn/common/GPUInfo.h" #include "dawn/common/GPUInfo.h"
#include "dawn/common/Platform.h" #include "dawn/common/Platform.h"
#include "dawn/native/Adapter.h"
#include "dawn/native/BackendConnection.h" #include "dawn/native/BackendConnection.h"
#include "dawn/native/BindGroupLayout.h" #include "dawn/native/BindGroupLayout.h"
#include "dawn/native/Commands.h" #include "dawn/native/Commands.h"
@ -155,7 +156,7 @@ MaybeError Device::Initialize(const DeviceDescriptor* descriptor) {
if (mIsTimestampQueryEnabled && !IsToggleEnabled(Toggle::DisableTimestampQueryConversion)) { if (mIsTimestampQueryEnabled && !IsToggleEnabled(Toggle::DisableTimestampQueryConversion)) {
// Make a best guess of timestamp period based on device vendor info, and converge it to // Make a best guess of timestamp period based on device vendor info, and converge it to
// an accurate value by the following calculations. // an accurate value by the following calculations.
mTimestampPeriod = gpu_info::IsIntel(GetAdapter()->GetVendorId()) ? 83.333f : 1.0f; mTimestampPeriod = gpu_info::IsIntel(GetPhysicalDevice()->GetVendorId()) ? 83.333f : 1.0f;
// Initialize kalman filter parameters // Initialize kalman filter parameters
mKalmanInfo = std::make_unique<KalmanInfo>(); mKalmanInfo = std::make_unique<KalmanInfo>();

View File

@ -513,14 +513,14 @@ NSRef<MTLVertexDescriptor> RenderPipeline::MakeVertexDesc() const {
void RenderPipeline::InitializeAsync(Ref<RenderPipelineBase> renderPipeline, void RenderPipeline::InitializeAsync(Ref<RenderPipelineBase> renderPipeline,
WGPUCreateRenderPipelineAsyncCallback callback, WGPUCreateRenderPipelineAsyncCallback callback,
void* userdata) { void* userdata) {
AdapterBase* adapter = renderPipeline->GetDevice()->GetAdapter(); PhysicalDeviceBase* physicalDevice = renderPipeline->GetDevice()->GetPhysicalDevice();
std::unique_ptr<CreateRenderPipelineAsyncTask> asyncTask = std::unique_ptr<CreateRenderPipelineAsyncTask> asyncTask =
std::make_unique<CreateRenderPipelineAsyncTask>(std::move(renderPipeline), callback, std::make_unique<CreateRenderPipelineAsyncTask>(std::move(renderPipeline), callback,
userdata); userdata);
// Workaround a crash where the validation layers on AMD crash with partition alloc. // Workaround a crash where the validation layers on AMD crash with partition alloc.
// See crbug.com/dawn/1200. // See crbug.com/dawn/1200.
if (adapter->GetInstance()->IsBackendValidationEnabled() && if (physicalDevice->GetInstance()->IsBackendValidationEnabled() &&
gpu_info::IsAMD(adapter->GetVendorId())) { gpu_info::IsAMD(physicalDevice->GetVendorId())) {
asyncTask->Run(); asyncTask->Run();
return; return;
} }

View File

@ -69,9 +69,10 @@ MaybeError PhysicalDevice::InitializeSupportedLimitsImpl(CombinedLimits* limits)
void PhysicalDevice::SetupBackendDeviceToggles(TogglesState* deviceToggles) const {} void PhysicalDevice::SetupBackendDeviceToggles(TogglesState* deviceToggles) const {}
ResultOrError<Ref<DeviceBase>> PhysicalDevice::CreateDeviceImpl(const DeviceDescriptor* descriptor, ResultOrError<Ref<DeviceBase>> PhysicalDevice::CreateDeviceImpl(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles) { const TogglesState& deviceToggles) {
return Device::Create(this, descriptor, deviceToggles); return Device::Create(adapter, descriptor, deviceToggles);
} }
MaybeError PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl( MaybeError PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl(

View File

@ -193,7 +193,8 @@ class PhysicalDevice : public PhysicalDeviceBase {
const TogglesState& toggles) const override; const TogglesState& toggles) const override;
void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override; void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override;
ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(const DeviceDescriptor* descriptor, ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles) override; const TogglesState& deviceToggles) override;
}; };

View File

@ -137,7 +137,7 @@ MaybeError Device::Initialize(const DeviceDescriptor* descriptor) {
// extensions // extensions
bool hasDebugOutput = gl.IsAtLeastGL(4, 3) || gl.IsAtLeastGLES(3, 2); bool hasDebugOutput = gl.IsAtLeastGL(4, 3) || gl.IsAtLeastGLES(3, 2);
if (GetAdapter()->GetInstance()->IsBackendValidationEnabled() && hasDebugOutput) { if (GetPhysicalDevice()->GetInstance()->IsBackendValidationEnabled() && hasDebugOutput) {
gl.Enable(GL_DEBUG_OUTPUT); gl.Enable(GL_DEBUG_OUTPUT);
gl.Enable(GL_DEBUG_OUTPUT_SYNCHRONOUS); gl.Enable(GL_DEBUG_OUTPUT_SYNCHRONOUS);

View File

@ -38,13 +38,13 @@ class Texture;
class TextureView; class TextureView;
struct OpenGLBackendTraits { struct OpenGLBackendTraits {
using PhysicalDeviceType = PhysicalDevice;
using BindGroupType = BindGroup; using BindGroupType = BindGroup;
using BindGroupLayoutType = BindGroupLayout; using BindGroupLayoutType = BindGroupLayout;
using BufferType = Buffer; using BufferType = Buffer;
using CommandBufferType = CommandBuffer; using CommandBufferType = CommandBuffer;
using ComputePipelineType = ComputePipeline; using ComputePipelineType = ComputePipeline;
using DeviceType = Device; using DeviceType = Device;
using PhysicalDeviceType = PhysicalDevice;
using PipelineLayoutType = PipelineLayout; using PipelineLayoutType = PipelineLayout;
using QuerySetType = QuerySet; using QuerySetType = QuerySet;
using QueueType = Queue; using QueueType = Queue;

View File

@ -217,13 +217,14 @@ void PhysicalDevice::SetupBackendDeviceToggles(TogglesState* deviceToggles) cons
gl.GetVersion().IsES()); gl.GetVersion().IsES());
} }
ResultOrError<Ref<DeviceBase>> PhysicalDevice::CreateDeviceImpl(const DeviceDescriptor* descriptor, ResultOrError<Ref<DeviceBase>> PhysicalDevice::CreateDeviceImpl(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles) { const TogglesState& deviceToggles) {
EGLenum api = EGLenum api =
GetBackendType() == wgpu::BackendType::OpenGL ? EGL_OPENGL_API : EGL_OPENGL_ES_API; GetBackendType() == wgpu::BackendType::OpenGL ? EGL_OPENGL_API : EGL_OPENGL_ES_API;
std::unique_ptr<Device::Context> context; std::unique_ptr<Device::Context> context;
DAWN_TRY_ASSIGN(context, ContextEGL::Create(mEGLFunctions, api)); DAWN_TRY_ASSIGN(context, ContextEGL::Create(mEGLFunctions, api));
return Device::Create(this, descriptor, mFunctions, std::move(context), deviceToggles); return Device::Create(adapter, descriptor, mFunctions, std::move(context), deviceToggles);
} }
MaybeError PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl( MaybeError PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl(

View File

@ -43,7 +43,8 @@ class PhysicalDevice : public PhysicalDeviceBase {
const TogglesState& toggles) const override; const TogglesState& toggles) const override;
void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override; void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override;
ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(const DeviceDescriptor* descriptor, ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles) override; const TogglesState& deviceToggles) override;
OpenGLFunctions mFunctions; OpenGLFunctions mFunctions;

View File

@ -504,9 +504,10 @@ void PhysicalDevice::SetupBackendDeviceToggles(TogglesState* deviceToggles) cons
deviceToggles->Default(Toggle::UsePlaceholderFragmentInVertexOnlyPipeline, true); deviceToggles->Default(Toggle::UsePlaceholderFragmentInVertexOnlyPipeline, true);
} }
ResultOrError<Ref<DeviceBase>> PhysicalDevice::CreateDeviceImpl(const DeviceDescriptor* descriptor, ResultOrError<Ref<DeviceBase>> PhysicalDevice::CreateDeviceImpl(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles) { const TogglesState& deviceToggles) {
return Device::Create(this, descriptor, deviceToggles); return Device::Create(adapter, descriptor, deviceToggles);
} }
MaybeError PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl( MaybeError PhysicalDevice::ValidateFeatureSupportedWithTogglesImpl(

View File

@ -54,7 +54,8 @@ class PhysicalDevice : public PhysicalDeviceBase {
const TogglesState& toggles) const override; const TogglesState& toggles) const override;
void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override; void SetupBackendDeviceToggles(TogglesState* deviceToggles) const override;
ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(const DeviceDescriptor* descriptor, ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles) override; const TogglesState& deviceToggles) override;
VkPhysicalDevice mVkPhysicalDevice; VkPhysicalDevice mVkPhysicalDevice;

View File

@ -621,7 +621,8 @@ bool IsSampleCountSupported(const dawn::native::vulkan::Device* device,
const VkImageCreateInfo& imageCreateInfo) { const VkImageCreateInfo& imageCreateInfo) {
ASSERT(device); ASSERT(device);
VkPhysicalDevice vkPhysicalDevice = ToBackend(device->GetAdapter())->GetVkPhysicalDevice(); VkPhysicalDevice vkPhysicalDevice =
ToBackend(device->GetPhysicalDevice())->GetVkPhysicalDevice();
VkImageFormatProperties properties; VkImageFormatProperties properties;
if (device->fn.GetPhysicalDeviceImageFormatProperties( if (device->fn.GetPhysicalDeviceImageFormatProperties(
vkPhysicalDevice, imageCreateInfo.format, imageCreateInfo.imageType, vkPhysicalDevice, imageCreateInfo.format, imageCreateInfo.imageType,

View File

@ -153,7 +153,8 @@ class ServiceImplementationDmaBuf : public ServiceImplementation {
static_cast<const ExternalImageDescriptorDmaBuf*>(descriptor); static_cast<const ExternalImageDescriptorDmaBuf*>(descriptor);
// Verify plane count for the modifier. // Verify plane count for the modifier.
VkPhysicalDevice vkPhysicalDevice = ToBackend(mDevice->GetAdapter())->GetVkPhysicalDevice(); VkPhysicalDevice vkPhysicalDevice =
ToBackend(mDevice->GetPhysicalDevice())->GetVkPhysicalDevice();
uint32_t planeCount = 0; uint32_t planeCount = 0;
if (mDevice->ConsumedError(GetModifierPlaneCount(mDevice->fn, vkPhysicalDevice, format, if (mDevice->ConsumedError(GetModifierPlaneCount(mDevice->fn, vkPhysicalDevice, format,
dmaBufDescriptor->drmModifier), dmaBufDescriptor->drmModifier),
@ -303,7 +304,8 @@ class ServiceImplementationDmaBuf : public ServiceImplementation {
const ExternalImageDescriptorDmaBuf* dmaBufDescriptor = const ExternalImageDescriptorDmaBuf* dmaBufDescriptor =
static_cast<const ExternalImageDescriptorDmaBuf*>(descriptor); static_cast<const ExternalImageDescriptorDmaBuf*>(descriptor);
VkPhysicalDevice vkPhysicalDevice = ToBackend(mDevice->GetAdapter())->GetVkPhysicalDevice(); VkPhysicalDevice vkPhysicalDevice =
ToBackend(mDevice->GetPhysicalDevice())->GetVkPhysicalDevice();
VkDevice device = mDevice->GetVkDevice(); VkDevice device = mDevice->GetVkDevice();
uint32_t planeCount; uint32_t planeCount;

View File

@ -29,7 +29,7 @@ class ServiceImplementationZirconHandle : public ServiceImplementation {
explicit ServiceImplementationZirconHandle(Device* device) explicit ServiceImplementationZirconHandle(Device* device)
: ServiceImplementation(device), : ServiceImplementation(device),
mSupported(CheckSupport(device->GetDeviceInfo(), mSupported(CheckSupport(device->GetDeviceInfo(),
ToBackend(device->GetAdapter())->GetVkPhysicalDevice(), ToBackend(device->GetPhysicalDevice())->GetVkPhysicalDevice(),
device->fn)) {} device->fn)) {}
~ServiceImplementationZirconHandle() override = default; ~ServiceImplementationZirconHandle() override = default;

View File

@ -25,11 +25,13 @@ class FeatureTests : public testing::Test {
FeatureTests() FeatureTests()
: testing::Test(), : testing::Test(),
mInstanceBase(dawn::native::InstanceBase::Create()), mInstanceBase(dawn::native::InstanceBase::Create()),
mAdapterBase(mInstanceBase.Get()), mPhysicalDevice(mInstanceBase.Get()),
mUnsafeAdapterBase( mUnsafePhysicalDevice(
mInstanceBase.Get(), mInstanceBase.Get(),
dawn::native::TogglesState(dawn::native::ToggleStage::Adapter) dawn::native::TogglesState(dawn::native::ToggleStage::Adapter)
.SetForTesting(dawn::native::Toggle::DisallowUnsafeAPIs, false, false)) {} .SetForTesting(dawn::native::Toggle::DisallowUnsafeAPIs, false, false)),
mAdapterBase(&mPhysicalDevice),
mUnsafeAdapterBase(&mUnsafePhysicalDevice) {}
std::vector<wgpu::FeatureName> GetAllFeatureNames() { std::vector<wgpu::FeatureName> GetAllFeatureNames() {
std::vector<wgpu::FeatureName> allFeatureNames(kTotalFeaturesCount); std::vector<wgpu::FeatureName> allFeatureNames(kTotalFeaturesCount);
@ -45,11 +47,13 @@ class FeatureTests : public testing::Test {
protected: protected:
// By default DisallowUnsafeAPIs is enabled in this instance. // By default DisallowUnsafeAPIs is enabled in this instance.
Ref<dawn::native::InstanceBase> mInstanceBase; Ref<dawn::native::InstanceBase> mInstanceBase;
dawn::native::null::PhysicalDevice mPhysicalDevice;
dawn::native::null::PhysicalDevice mUnsafePhysicalDevice;
// The adapter that inherit toggles states from the instance, also have DisallowUnsafeAPIs // The adapter that inherit toggles states from the instance, also have DisallowUnsafeAPIs
// enabled. // enabled.
dawn::native::null::PhysicalDevice mAdapterBase; dawn::native::AdapterBase mAdapterBase;
// The adapter that override DisallowUnsafeAPIs to disabled in toggles state. // The adapter that override DisallowUnsafeAPIs to disabled in toggles state.
dawn::native::null::PhysicalDevice mUnsafeAdapterBase; dawn::native::AdapterBase mUnsafeAdapterBase;
}; };
// Test the creation of a device will fail if the requested feature is not supported on the // Test the creation of a device will fail if the requested feature is not supported on the
@ -64,7 +68,7 @@ TEST_F(FeatureTests, AdapterWithRequiredFeatureDisabled) {
// Test that the adapter with unsafe apis disallowed validate features as expected. // Test that the adapter with unsafe apis disallowed validate features as expected.
{ {
mAdapterBase.SetSupportedFeaturesForTesting(featureNamesWithoutOne); mPhysicalDevice.SetSupportedFeaturesForTesting(featureNamesWithoutOne);
dawn::native::Adapter adapterWithoutFeature(&mAdapterBase); dawn::native::Adapter adapterWithoutFeature(&mAdapterBase);
wgpu::DeviceDescriptor deviceDescriptor; wgpu::DeviceDescriptor deviceDescriptor;
@ -79,7 +83,7 @@ TEST_F(FeatureTests, AdapterWithRequiredFeatureDisabled) {
// Test that the adapter with unsafe apis allowed validate features as expected. // Test that the adapter with unsafe apis allowed validate features as expected.
{ {
mUnsafeAdapterBase.SetSupportedFeaturesForTesting(featureNamesWithoutOne); mUnsafePhysicalDevice.SetSupportedFeaturesForTesting(featureNamesWithoutOne);
dawn::native::Adapter adapterWithoutFeature(&mUnsafeAdapterBase); dawn::native::Adapter adapterWithoutFeature(&mUnsafeAdapterBase);
wgpu::DeviceDescriptor deviceDescriptor; wgpu::DeviceDescriptor deviceDescriptor;

View File

@ -56,13 +56,13 @@ class GetProcAddressTests : public testing::TestWithParam<DawnFlavor> {
GetProcAddressTests() GetProcAddressTests()
: testing::TestWithParam<DawnFlavor>(), : testing::TestWithParam<DawnFlavor>(),
mNativeInstance(dawn::native::InstanceBase::Create()), mNativeInstance(dawn::native::InstanceBase::Create()),
mNativeAdapter(mNativeInstance.Get()) {} mAdapterBase(AcquireRef(new dawn::native::null::PhysicalDevice(mNativeInstance.Get()))) {}
void SetUp() override { void SetUp() override {
switch (GetParam()) { switch (GetParam()) {
case DawnFlavor::Native: { case DawnFlavor::Native: {
mDevice = wgpu::Device::Acquire( mDevice = wgpu::Device::Acquire(
reinterpret_cast<WGPUDevice>(mNativeAdapter.APICreateDevice())); reinterpret_cast<WGPUDevice>(mAdapterBase.APICreateDevice()));
mProcs = dawn::native::GetProcs(); mProcs = dawn::native::GetProcs();
break; break;
} }
@ -94,7 +94,7 @@ class GetProcAddressTests : public testing::TestWithParam<DawnFlavor> {
protected: protected:
Ref<dawn::native::InstanceBase> mNativeInstance; Ref<dawn::native::InstanceBase> mNativeInstance;
dawn::native::null::PhysicalDevice mNativeAdapter; dawn::native::AdapterBase mAdapterBase;
std::unique_ptr<utils::TerribleCommandBuffer> mC2sBuf; std::unique_ptr<utils::TerribleCommandBuffer> mC2sBuf;
std::unique_ptr<dawn::wire::WireClient> mWireClient; std::unique_ptr<dawn::wire::WireClient> mWireClient;

View File

@ -27,12 +27,12 @@ class PerThreadProcTests : public testing::Test {
public: public:
PerThreadProcTests() PerThreadProcTests()
: mNativeInstance(dawn::native::InstanceBase::Create()), : mNativeInstance(dawn::native::InstanceBase::Create()),
mNativeAdapter(mNativeInstance.Get()) {} mAdapterBase(AcquireRef(new dawn::native::null::PhysicalDevice(mNativeInstance.Get()))) {}
~PerThreadProcTests() override = default; ~PerThreadProcTests() override = default;
protected: protected:
Ref<dawn::native::InstanceBase> mNativeInstance; Ref<dawn::native::InstanceBase> mNativeInstance;
dawn::native::null::PhysicalDevice mNativeAdapter; dawn::native::AdapterBase mAdapterBase;
}; };
// Test that procs can be set per thread. This test overrides deviceCreateBuffer with a placeholder // Test that procs can be set per thread. This test overrides deviceCreateBuffer with a placeholder
@ -57,10 +57,10 @@ TEST_F(PerThreadProcTests, DispatchesPerThread) {
// Note: Acquire doesn't call reference or release. // Note: Acquire doesn't call reference or release.
wgpu::Device deviceA = wgpu::Device deviceA =
wgpu::Device::Acquire(reinterpret_cast<WGPUDevice>(mNativeAdapter.APICreateDevice())); wgpu::Device::Acquire(reinterpret_cast<WGPUDevice>(mAdapterBase.APICreateDevice()));
wgpu::Device deviceB = wgpu::Device deviceB =
wgpu::Device::Acquire(reinterpret_cast<WGPUDevice>(mNativeAdapter.APICreateDevice())); wgpu::Device::Acquire(reinterpret_cast<WGPUDevice>(mAdapterBase.APICreateDevice()));
std::thread threadA([&]() { std::thread threadA([&]() {
DawnProcTable procs = dawn::native::GetProcs(); DawnProcTable procs = dawn::native::GetProcs();

View File

@ -135,7 +135,7 @@ TEST_F(InstanceToggleTest, InstanceTogglesInheritToAdapterAndDevice) {
// Get the adapter created by instance with default toggles. // Get the adapter created by instance with default toggles.
dawn::native::AdapterBase* nullAdapter = nullptr; dawn::native::AdapterBase* nullAdapter = nullptr;
for (auto& adapter : instance->GetAdapters()) { for (auto& adapter : instance->GetAdapters()) {
if (adapter->GetBackendType() == wgpu::BackendType::Null) { if (adapter->GetPhysicalDevice()->GetBackendType() == wgpu::BackendType::Null) {
nullAdapter = adapter.Get(); nullAdapter = adapter.Get();
break; break;
} }

View File

@ -15,8 +15,8 @@
#include <utility> #include <utility>
#include "dawn/common/Math.h" #include "dawn/common/Math.h"
#include "dawn/native/Adapter.h"
#include "dawn/native/vulkan/DeviceVk.h" #include "dawn/native/vulkan/DeviceVk.h"
#include "dawn/native/vulkan/PhysicalDeviceVk.h"
#include "dawn/tests/DawnTest.h" #include "dawn/tests/DawnTest.h"
#include "dawn/tests/white_box/VulkanImageWrappingTests.h" #include "dawn/tests/white_box/VulkanImageWrappingTests.h"
#include "dawn/utils/ComboRenderPipelineDescriptor.h" #include "dawn/utils/ComboRenderPipelineDescriptor.h"