Move Adapter toggles from PhysicalDevice to Adapter

Bug: dawn:1774
Change-Id: I25a4040af929b5dc49ad481f85a067e427b97424
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/132267
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Stephen White <senorblanco@chromium.org>
Commit-Queue: Austin Eng <enga@chromium.org>
This commit is contained in:
Austin Eng 2023-05-11 17:10:28 +00:00 committed by Dawn LUCI CQ
parent 4d6f048af0
commit 096ce5936a
38 changed files with 348 additions and 389 deletions

View File

@ -14,56 +14,178 @@
#include "dawn/native/Adapter.h"
#include <memory>
#include <utility>
#include "dawn/native/ChainUtils_autogen.h"
#include "dawn/native/Device.h"
#include "dawn/native/Instance.h"
#include "dawn/native/PhysicalDevice.h"
namespace dawn::native {
AdapterBase::AdapterBase(const Ref<PhysicalDeviceBase>& physicalDevice, FeatureLevel featureLevel)
: mPhysicalDevice(std::move(physicalDevice)), mFeatureLevel(featureLevel) {
ASSERT(physicalDevice->SupportsFeatureLevel(featureLevel));
AdapterBase::AdapterBase(Ref<PhysicalDeviceBase> physicalDevice, FeatureLevel featureLevel)
: AdapterBase(physicalDevice,
featureLevel,
TogglesState(ToggleStage::Adapter)
.InheritFrom(physicalDevice->GetInstance()->GetTogglesState())) {}
AdapterBase::AdapterBase(Ref<PhysicalDeviceBase> physicalDevice,
FeatureLevel featureLevel,
const TogglesState& adapterToggles)
: mPhysicalDevice(std::move(physicalDevice)),
mFeatureLevel(featureLevel),
mTogglesState(adapterToggles) {
ASSERT(mPhysicalDevice->SupportsFeatureLevel(featureLevel));
ASSERT(mTogglesState.GetStage() == ToggleStage::Adapter);
}
AdapterBase::~AdapterBase() = default;
void AdapterBase::SetUseTieredLimits(bool useTieredLimits) {
mUseTieredLimits = useTieredLimits;
}
PhysicalDeviceBase* AdapterBase::GetPhysicalDevice() {
return mPhysicalDevice.Get();
}
InstanceBase* AdapterBase::APIGetInstance() const {
return mPhysicalDevice->APIGetInstance();
InstanceBase* instance = mPhysicalDevice->GetInstance();
ASSERT(instance != nullptr);
instance->APIReference();
return instance;
}
bool AdapterBase::APIGetLimits(SupportedLimits* limits) const {
return mPhysicalDevice->APIGetLimits(limits);
ASSERT(limits != nullptr);
if (limits->nextInChain != nullptr) {
return false;
}
if (mUseTieredLimits) {
limits->limits = ApplyLimitTiers(mPhysicalDevice->GetLimits().v1);
} else {
limits->limits = mPhysicalDevice->GetLimits().v1;
}
return true;
}
void AdapterBase::APIGetProperties(AdapterProperties* properties) const {
mPhysicalDevice->APIGetProperties(properties);
ASSERT(properties != nullptr);
MaybeError result = ValidateSingleSType(properties->nextInChain,
wgpu::SType::DawnAdapterPropertiesPowerPreference);
if (result.IsError()) {
mPhysicalDevice->GetInstance()->ConsumedError(result.AcquireError());
return;
}
DawnAdapterPropertiesPowerPreference* powerPreferenceDesc = nullptr;
FindInChain(properties->nextInChain, &powerPreferenceDesc);
if (powerPreferenceDesc != nullptr) {
powerPreferenceDesc->powerPreference = wgpu::PowerPreference::Undefined;
}
properties->vendorID = mPhysicalDevice->GetVendorId();
properties->vendorName = mPhysicalDevice->GetVendorName().c_str();
properties->architecture = mPhysicalDevice->GetArchitectureName().c_str();
properties->deviceID = mPhysicalDevice->GetDeviceId();
properties->name = mPhysicalDevice->GetName().c_str();
properties->driverDescription = mPhysicalDevice->GetDriverDescription().c_str();
properties->adapterType = mPhysicalDevice->GetAdapterType();
properties->backendType = mPhysicalDevice->GetBackendType();
properties->compatibilityMode = mFeatureLevel == FeatureLevel::Compatibility;
}
bool AdapterBase::APIHasFeature(wgpu::FeatureName feature) const {
return mPhysicalDevice->APIHasFeature(feature);
return mPhysicalDevice->HasFeature(feature);
}
size_t AdapterBase::APIEnumerateFeatures(wgpu::FeatureName* features) const {
return mPhysicalDevice->APIEnumerateFeatures(features);
return mPhysicalDevice->EnumerateFeatures(features);
}
DeviceBase* AdapterBase::APICreateDevice(const DeviceDescriptor* descriptor) {
return mPhysicalDevice->CreateDevice(this, descriptor);
constexpr DeviceDescriptor kDefaultDesc = {};
if (descriptor == nullptr) {
descriptor = &kDefaultDesc;
}
auto result = CreateDevice(descriptor);
if (result.IsError()) {
mPhysicalDevice->GetInstance()->ConsumedError(result.AcquireError());
return nullptr;
}
return result.AcquireSuccess().Detach();
}
ResultOrError<Ref<DeviceBase>> AdapterBase::CreateDevice(const DeviceDescriptor* descriptor) {
ASSERT(descriptor != nullptr);
// Create device toggles state from required toggles descriptor and inherited adapter toggles
// state.
const DawnTogglesDescriptor* deviceTogglesDesc = nullptr;
FindInChain(descriptor->nextInChain, &deviceTogglesDesc);
// Create device toggles state.
TogglesState deviceToggles =
TogglesState::CreateFromTogglesDescriptor(deviceTogglesDesc, ToggleStage::Device);
deviceToggles.InheritFrom(mTogglesState);
// Default toggles for all backend
deviceToggles.Default(Toggle::LazyClearResourceOnFirstUse, true);
// Backend-specific forced and default device toggles
mPhysicalDevice->SetupBackendDeviceToggles(&deviceToggles);
// Validate all required features are supported by the adapter and suitable under given toggles.
// Note that certain toggles in device toggles state may be overriden by user and different from
// the adapter toggles state.
// TODO(dawn:1495): After implementing adapter toggles, decide whether we should validate
// supported features using adapter toggles or device toggles.
for (uint32_t i = 0; i < descriptor->requiredFeaturesCount; ++i) {
wgpu::FeatureName feature = descriptor->requiredFeatures[i];
DAWN_TRY(mPhysicalDevice->ValidateFeatureSupportedWithToggles(feature, deviceToggles));
}
if (descriptor->requiredLimits != nullptr) {
SupportedLimits supportedLimits;
bool success = APIGetLimits(&supportedLimits);
ASSERT(success);
DAWN_TRY_CONTEXT(ValidateLimits(supportedLimits.limits, descriptor->requiredLimits->limits),
"validating required limits");
DAWN_INVALID_IF(descriptor->requiredLimits->nextInChain != nullptr,
"nextInChain is not nullptr.");
}
return mPhysicalDevice->CreateDevice(this, descriptor, deviceToggles);
}
void AdapterBase::APIRequestDevice(const DeviceDescriptor* descriptor,
WGPURequestDeviceCallback callback,
void* userdata) {
return mPhysicalDevice->RequestDevice(this, descriptor, callback, userdata);
constexpr DeviceDescriptor kDefaultDescriptor = {};
if (descriptor == nullptr) {
descriptor = &kDefaultDescriptor;
}
auto result = CreateDevice(descriptor);
if (result.IsError()) {
std::unique_ptr<ErrorData> errorData = result.AcquireError();
// TODO(crbug.com/dawn/1122): Call callbacks only on wgpuInstanceProcessEvents
callback(WGPURequestDeviceStatus_Error, nullptr, errorData->GetFormattedMessage().c_str(),
userdata);
return;
}
Ref<DeviceBase> device = result.AcquireSuccess();
WGPURequestDeviceStatus status =
device == nullptr ? WGPURequestDeviceStatus_Unknown : WGPURequestDeviceStatus_Success;
// TODO(crbug.com/dawn/1122): Call callbacks only on wgpuInstanceProcessEvents
callback(status, ToAPI(device.Detach()), nullptr, userdata);
}
const TogglesState& AdapterBase::GetTogglesState() const {
return mPhysicalDevice->GetTogglesState();
return mTogglesState;
}
bool AdapterBase::AllowUnsafeAPIs() const {

View File

@ -29,7 +29,10 @@ struct SupportedLimits;
class AdapterBase : public RefCounted {
public:
AdapterBase(const Ref<PhysicalDeviceBase>& physicalDevice, FeatureLevel featureLevel);
AdapterBase(Ref<PhysicalDeviceBase> physicalDevice, FeatureLevel featureLevel);
AdapterBase(Ref<PhysicalDeviceBase> physicalDevice,
FeatureLevel featureLevel,
const TogglesState& adapterToggles);
~AdapterBase() override;
// WebGPU API
@ -42,6 +45,9 @@ class AdapterBase : public RefCounted {
WGPURequestDeviceCallback callback,
void* userdata);
DeviceBase* APICreateDevice(const DeviceDescriptor* descriptor = nullptr);
ResultOrError<Ref<DeviceBase>> CreateDevice(const DeviceDescriptor* descriptor);
void SetUseTieredLimits(bool useTieredLimits);
// Return the underlying PhysicalDevice.
PhysicalDeviceBase* GetPhysicalDevice();
@ -59,6 +65,9 @@ class AdapterBase : public RefCounted {
private:
Ref<PhysicalDeviceBase> mPhysicalDevice;
FeatureLevel mFeatureLevel;
bool mUseTieredLimits = false;
// Adapter toggles state, currently only inherited from instance toggles state.
TogglesState mTogglesState;
};
} // namespace dawn::native

View File

@ -29,8 +29,7 @@ InstanceBase* BackendConnection::GetInstance() const {
}
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> BackendConnection::DiscoverAdapters(
const AdapterDiscoveryOptionsBase* options,
const TogglesState& adapterToggles) {
const AdapterDiscoveryOptionsBase* options) {
return DAWN_VALIDATION_ERROR("DiscoverAdapters not implemented for this backend.");
}

View File

@ -36,13 +36,11 @@ class BackendConnection {
// 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(
const TogglesState& adapterToggles) = 0;
virtual std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() = 0;
// Returns new adapters created with the backend-specific options.
virtual ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
const AdapterDiscoveryOptionsBase* options,
const TogglesState& adapterToggles);
const AdapterDiscoveryOptionsBase* options);
private:
InstanceBase* mInstance = nullptr;

View File

@ -89,11 +89,11 @@ std::vector<const char*> Adapter::GetSupportedFeatures() const {
}
bool Adapter::GetLimits(WGPUSupportedLimits* limits) const {
return mImpl->GetPhysicalDevice()->GetLimits(FromAPI(limits));
return mImpl->APIGetLimits(FromAPI(limits));
}
void Adapter::SetUseTieredLimits(bool useTieredLimits) {
mImpl->GetPhysicalDevice()->SetUseTieredLimits(useTieredLimits);
mImpl->SetUseTieredLimits(useTieredLimits);
}
bool Adapter::SupportsExternalImages() const {

View File

@ -157,7 +157,7 @@ void InstanceBase::WillDropLastExternalRef() {
// In order to break this cycle and prevent leaks, when the application drops the last external
// ref and WillDropLastExternalRef is called, the instance clears out any member refs to
// adapters that hold back-refs to the instance - thus breaking any reference cycles.
mAdapters.clear();
mPhysicalDevices.clear();
}
// TODO(crbug.com/dawn/832): make the platform an initialization parameter of the instance.
@ -251,24 +251,27 @@ ResultOrError<Ref<AdapterBase>> InstanceBase::RequestAdapterInternal(
std::optional<size_t> cpuAdapterIndex;
std::optional<size_t> unknownAdapterIndex;
for (size_t i = 0; i < mAdapters.size(); ++i) {
AdapterProperties properties;
mAdapters[i]->APIGetProperties(&properties);
bool isCompatibility = mAdapters[i]->GetFeatureLevel() == FeatureLevel::Compatibility;
if (options->compatibilityMode != isCompatibility) {
Ref<PhysicalDeviceBase> selectedPhysicalDevice;
FeatureLevel featureLevel =
options->compatibilityMode ? FeatureLevel::Compatibility : FeatureLevel::Core;
for (size_t i = 0; i < mPhysicalDevices.size(); ++i) {
if (!mPhysicalDevices[i]->SupportsFeatureLevel(featureLevel)) {
continue;
}
if (options->forceFallbackAdapter) {
if (!gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID)) {
if (!gpu_info::IsGoogleSwiftshader(mPhysicalDevices[i]->GetVendorId(),
mPhysicalDevices[i]->GetDeviceId())) {
continue;
}
return mAdapters[i];
selectedPhysicalDevice = mPhysicalDevices[i];
break;
}
if (properties.adapterType == preferredType) {
return mAdapters[i];
if (mPhysicalDevices[i]->GetAdapterType() == preferredType) {
selectedPhysicalDevice = mPhysicalDevices[i];
break;
}
switch (properties.adapterType) {
switch (mPhysicalDevices[i]->GetAdapterType()) {
case wgpu::AdapterType::DiscreteGPU:
discreteGPUAdapterIndex = i;
break;
@ -285,20 +288,30 @@ ResultOrError<Ref<AdapterBase>> InstanceBase::RequestAdapterInternal(
}
// For now, we always prefer the discrete GPU
if (discreteGPUAdapterIndex) {
return mAdapters[*discreteGPUAdapterIndex];
}
if (integratedGPUAdapterIndex) {
return mAdapters[*integratedGPUAdapterIndex];
}
if (cpuAdapterIndex) {
return mAdapters[*cpuAdapterIndex];
}
if (unknownAdapterIndex) {
return mAdapters[*unknownAdapterIndex];
if (selectedPhysicalDevice == nullptr) {
if (discreteGPUAdapterIndex) {
selectedPhysicalDevice = mPhysicalDevices[*discreteGPUAdapterIndex];
} else if (integratedGPUAdapterIndex) {
selectedPhysicalDevice = mPhysicalDevices[*integratedGPUAdapterIndex];
} else if (cpuAdapterIndex) {
selectedPhysicalDevice = mPhysicalDevices[*cpuAdapterIndex];
} else if (unknownAdapterIndex) {
selectedPhysicalDevice = mPhysicalDevices[*unknownAdapterIndex];
}
}
return Ref<AdapterBase>(nullptr);
if (selectedPhysicalDevice == nullptr) {
return Ref<AdapterBase>(nullptr);
}
// Set up toggles state for default adapters, currently adapter don't have a toggles
// descriptor so just inherit from instance toggles.
// TODO(dawn:1495): Handle the adapter toggles descriptor after implemented.
TogglesState adapterToggles = TogglesState(ToggleStage::Adapter);
adapterToggles.InheritFrom(mToggles);
return AcquireRef(
new AdapterBase(std::move(selectedPhysicalDevice), featureLevel, adapterToggles));
}
void InstanceBase::DiscoverDefaultAdapters() {
@ -312,24 +325,12 @@ void InstanceBase::DiscoverDefaultAdapters() {
// Query and merge all default adapters for all backends
for (std::unique_ptr<BackendConnection>& backend : mBackends) {
// Set up toggles state for default adapters, currently adapter don't have a toggles
// descriptor so just inherit from instance toggles.
// TODO(dawn:1495): Handle the adapter toggles descriptor after implemented.
TogglesState adapterToggles = TogglesState(ToggleStage::Adapter);
adapterToggles.InheritFrom(mToggles);
std::vector<Ref<PhysicalDeviceBase>> physicalDevices =
backend->DiscoverDefaultAdapters(adapterToggles);
std::vector<Ref<PhysicalDeviceBase>> physicalDevices = backend->DiscoverDefaultAdapters();
for (Ref<PhysicalDeviceBase>& physicalDevice : physicalDevices) {
ASSERT(physicalDevice->GetBackendType() == backend->GetType());
ASSERT(physicalDevice->GetInstance() == this);
for (auto featureLevel : {FeatureLevel::Compatibility, FeatureLevel::Core}) {
if (physicalDevice->SupportsFeatureLevel(featureLevel)) {
mAdapters.push_back(
AcquireRef(new AdapterBase(std::move(physicalDevice), featureLevel)));
}
}
mPhysicalDevices.push_back(std::move(physicalDevice));
}
}
@ -366,8 +367,23 @@ const FeatureInfo* InstanceBase::GetFeatureInfo(wgpu::FeatureName feature) {
return mFeaturesInfo.GetFeatureInfo(feature);
}
const std::vector<Ref<AdapterBase>>& InstanceBase::GetAdapters() const {
return mAdapters;
std::vector<Ref<AdapterBase>> InstanceBase::GetAdapters() const {
// Set up toggles state for default adapters, currently adapter don't have a toggles
// descriptor so just inherit from instance toggles.
// TODO(dawn:1495): Handle the adapter toggles descriptor after implemented.
TogglesState adapterToggles = TogglesState(ToggleStage::Adapter);
adapterToggles.InheritFrom(mToggles);
std::vector<Ref<AdapterBase>> adapters;
for (const auto& physicalDevice : mPhysicalDevices) {
for (FeatureLevel featureLevel : {FeatureLevel::Compatibility, FeatureLevel::Core}) {
if (physicalDevice->SupportsFeatureLevel(featureLevel)) {
adapters.push_back(
AcquireRef(new AdapterBase(physicalDevice, featureLevel, adapterToggles)));
}
}
}
return adapters;
}
void InstanceBase::EnsureBackendConnection(wgpu::BackendType backendType) {
@ -451,24 +467,13 @@ MaybeError InstanceBase::DiscoverAdaptersInternal(const AdapterDiscoveryOptionsB
}
foundBackend = true;
// Set up toggles state for default adapters, currently adapter don't have a toggles
// descriptor so just inherit from instance toggles.
// TODO(dawn:1495): Handle the adapter toggles descriptor after implemented.
TogglesState adapterToggles = TogglesState(ToggleStage::Adapter);
adapterToggles.InheritFrom(mToggles);
std::vector<Ref<PhysicalDeviceBase>> newPhysicalDevices;
DAWN_TRY_ASSIGN(newPhysicalDevices, backend->DiscoverAdapters(options, adapterToggles));
DAWN_TRY_ASSIGN(newPhysicalDevices, backend->DiscoverAdapters(options));
for (Ref<PhysicalDeviceBase>& physicalDevice : newPhysicalDevices) {
ASSERT(physicalDevice->GetBackendType() == backend->GetType());
ASSERT(physicalDevice->GetInstance() == this);
for (auto featureLevel : {FeatureLevel::Compatibility, FeatureLevel::Core}) {
if (physicalDevice->SupportsFeatureLevel(featureLevel)) {
mAdapters.push_back(
AcquireRef(new AdapterBase(std::move(physicalDevice), featureLevel)));
}
}
mPhysicalDevices.push_back(std::move(physicalDevice));
}
}

View File

@ -61,7 +61,7 @@ class InstanceBase final : public RefCountedWithExternalCount {
void DiscoverDefaultAdapters();
bool DiscoverAdapters(const AdapterDiscoveryOptionsBase* options);
const std::vector<Ref<AdapterBase>>& GetAdapters() const;
std::vector<Ref<AdapterBase>> GetAdapters() const;
// Used to handle error that happen up to device creation.
bool ConsumedError(MaybeError maybeError);
@ -157,7 +157,7 @@ class InstanceBase final : public RefCountedWithExternalCount {
BlobCache mPassthroughBlobCache;
std::vector<std::unique_ptr<BackendConnection>> mBackends;
std::vector<Ref<AdapterBase>> mAdapters;
std::vector<Ref<PhysicalDeviceBase>> mPhysicalDevices;
TogglesState mToggles;

View File

@ -21,18 +21,13 @@
#include "dawn/common/GPUInfo.h"
#include "dawn/common/Log.h"
#include "dawn/native/ChainUtils_autogen.h"
#include "dawn/native/Device.h"
#include "dawn/native/Instance.h"
#include "dawn/native/ValidationUtils_autogen.h"
namespace dawn::native {
PhysicalDeviceBase::PhysicalDeviceBase(InstanceBase* instance,
wgpu::BackendType backend,
const TogglesState& adapterToggles)
: mInstance(instance), mBackend(backend), mTogglesState(adapterToggles) {
ASSERT(adapterToggles.GetStage() == ToggleStage::Adapter);
}
PhysicalDeviceBase::PhysicalDeviceBase(InstanceBase* instance, wgpu::BackendType backend)
: mInstance(instance), mBackend(backend) {}
PhysicalDeviceBase::~PhysicalDeviceBase() = default;
@ -56,87 +51,18 @@ MaybeError PhysicalDeviceBase::Initialize() {
return {};
}
InstanceBase* PhysicalDeviceBase::APIGetInstance() const {
auto instance = GetInstance();
ASSERT(instance != nullptr);
instance->APIReference();
return instance;
}
bool PhysicalDeviceBase::APIGetLimits(SupportedLimits* limits) const {
return GetLimits(limits);
}
void PhysicalDeviceBase::APIGetProperties(AdapterProperties* properties) const {
MaybeError result = ValidateSingleSType(properties->nextInChain,
wgpu::SType::DawnAdapterPropertiesPowerPreference);
if (result.IsError()) {
mInstance->ConsumedError(result.AcquireError());
return;
}
DawnAdapterPropertiesPowerPreference* powerPreferenceDesc = nullptr;
FindInChain(properties->nextInChain, &powerPreferenceDesc);
if (powerPreferenceDesc != nullptr) {
powerPreferenceDesc->powerPreference = wgpu::PowerPreference::Undefined;
}
properties->vendorID = mVendorId;
properties->vendorName = mVendorName.c_str();
properties->architecture = mArchitectureName.c_str();
properties->deviceID = mDeviceId;
properties->name = mName.c_str();
properties->driverDescription = mDriverDescription.c_str();
properties->adapterType = mAdapterType;
properties->backendType = mBackend;
}
bool PhysicalDeviceBase::APIHasFeature(wgpu::FeatureName feature) const {
bool PhysicalDeviceBase::HasFeature(wgpu::FeatureName feature) const {
return mSupportedFeatures.IsEnabled(feature);
}
size_t PhysicalDeviceBase::APIEnumerateFeatures(wgpu::FeatureName* features) const {
size_t PhysicalDeviceBase::EnumerateFeatures(wgpu::FeatureName* features) const {
return mSupportedFeatures.EnumerateFeatures(features);
}
DeviceBase* PhysicalDeviceBase::CreateDevice(AdapterBase* adapter,
const DeviceDescriptor* descriptor) {
DeviceDescriptor defaultDesc = {};
if (descriptor == nullptr) {
descriptor = &defaultDesc;
}
auto result = CreateDeviceInternal(adapter, descriptor);
if (result.IsError()) {
mInstance->ConsumedError(result.AcquireError());
return nullptr;
}
return result.AcquireSuccess().Detach();
}
void PhysicalDeviceBase::RequestDevice(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
WGPURequestDeviceCallback callback,
void* userdata) {
static constexpr DeviceDescriptor kDefaultDescriptor = {};
if (descriptor == nullptr) {
descriptor = &kDefaultDescriptor;
}
auto result = CreateDeviceInternal(adapter, descriptor);
if (result.IsError()) {
std::unique_ptr<ErrorData> errorData = result.AcquireError();
// TODO(crbug.com/dawn/1122): Call callbacks only on wgpuInstanceProcessEvents
callback(WGPURequestDeviceStatus_Error, nullptr, errorData->GetFormattedMessage().c_str(),
userdata);
return;
}
Ref<DeviceBase> device = result.AcquireSuccess();
WGPURequestDeviceStatus status =
device == nullptr ? WGPURequestDeviceStatus_Unknown : WGPURequestDeviceStatus_Success;
// TODO(crbug.com/dawn/1122): Call callbacks only on wgpuInstanceProcessEvents
callback(status, ToAPI(device.Detach()), nullptr, userdata);
ResultOrError<Ref<DeviceBase>> PhysicalDeviceBase::CreateDevice(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles) {
return CreateDeviceImpl(adapter, descriptor, deviceToggles);
}
void PhysicalDeviceBase::InitializeVendorArchitectureImpl() {
@ -152,10 +78,30 @@ uint32_t PhysicalDeviceBase::GetDeviceId() const {
return mDeviceId;
}
const std::string& PhysicalDeviceBase::GetVendorName() const {
return mVendorName;
}
const std::string& PhysicalDeviceBase::GetArchitectureName() const {
return mArchitectureName;
}
const std::string& PhysicalDeviceBase::GetName() const {
return mName;
}
const gpu_info::DriverVersion& PhysicalDeviceBase::GetDriverVersion() const {
return mDriverVersion;
}
const std::string& PhysicalDeviceBase::GetDriverDescription() const {
return mDriverDescription;
}
wgpu::AdapterType PhysicalDeviceBase::GetAdapterType() const {
return mAdapterType;
}
wgpu::BackendType PhysicalDeviceBase::GetBackendType() const {
return mBackend;
}
@ -178,21 +124,8 @@ bool PhysicalDeviceBase::SupportsAllRequiredFeatures(
return true;
}
bool PhysicalDeviceBase::GetLimits(SupportedLimits* limits) const {
ASSERT(limits != nullptr);
if (limits->nextInChain != nullptr) {
return false;
}
if (mUseTieredLimits) {
limits->limits = ApplyLimitTiers(mLimits.v1);
} else {
limits->limits = mLimits.v1;
}
return true;
}
const TogglesState& PhysicalDeviceBase::GetTogglesState() const {
return mTogglesState;
const CombinedLimits& PhysicalDeviceBase::GetLimits() const {
return mLimits;
}
void PhysicalDeviceBase::EnableFeature(Feature feature) {
@ -227,51 +160,6 @@ void PhysicalDeviceBase::SetSupportedFeaturesForTesting(
}
}
ResultOrError<Ref<DeviceBase>> PhysicalDeviceBase::CreateDeviceInternal(
AdapterBase* adapter,
const DeviceDescriptor* descriptor) {
ASSERT(descriptor != nullptr);
// Create device toggles state from required toggles descriptor and inherited adapter toggles
// state.
const DawnTogglesDescriptor* deviceTogglesDesc = nullptr;
FindInChain(descriptor->nextInChain, &deviceTogglesDesc);
// Create device toggles state.
TogglesState deviceToggles =
TogglesState::CreateFromTogglesDescriptor(deviceTogglesDesc, ToggleStage::Device);
deviceToggles.InheritFrom(mTogglesState);
// Default toggles for all backend
deviceToggles.Default(Toggle::LazyClearResourceOnFirstUse, true);
// Backend-specific forced and default device toggles
SetupBackendDeviceToggles(&deviceToggles);
// Validate all required features are supported by the adapter and suitable under given toggles.
// Note that certain toggles in device toggles state may be overriden by user and different from
// the adapter toggles state.
// TODO(dawn:1495): After implementing adapter toggles, decide whether we should validate
// supported features using adapter toggles or device toggles.
for (uint32_t i = 0; i < descriptor->requiredFeaturesCount; ++i) {
wgpu::FeatureName feature = descriptor->requiredFeatures[i];
DAWN_TRY(ValidateFeatureSupportedWithToggles(feature, deviceToggles));
}
if (descriptor->requiredLimits != nullptr) {
DAWN_TRY_CONTEXT(ValidateLimits(mUseTieredLimits ? ApplyLimitTiers(mLimits.v1) : mLimits.v1,
descriptor->requiredLimits->limits),
"validating required limits");
DAWN_INVALID_IF(descriptor->requiredLimits->nextInChain != nullptr,
"nextInChain is not nullptr.");
}
return CreateDeviceImpl(adapter, descriptor, deviceToggles);
}
void PhysicalDeviceBase::SetUseTieredLimits(bool useTieredLimits) {
mUseTieredLimits = useTieredLimits;
}
void PhysicalDeviceBase::ResetInternalDeviceForTesting() {
mInstance->ConsumedError(ResetInternalDeviceForTestingImpl());
}

View File

@ -37,28 +37,26 @@ enum class FeatureLevel { Compatibility, Core };
class PhysicalDeviceBase : public RefCounted {
public:
PhysicalDeviceBase(InstanceBase* instance,
wgpu::BackendType backend,
const TogglesState& adapterToggles);
PhysicalDeviceBase(InstanceBase* instance, wgpu::BackendType backend);
~PhysicalDeviceBase() override;
MaybeError Initialize();
// 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 RequestDevice(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
WGPURequestDeviceCallback callback,
void* userdata);
DeviceBase* CreateDevice(AdapterBase* adapter, const DeviceDescriptor* descriptor = nullptr);
bool HasFeature(wgpu::FeatureName feature) const;
size_t EnumerateFeatures(wgpu::FeatureName* features) const;
ResultOrError<Ref<DeviceBase>> CreateDevice(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles);
uint32_t GetVendorId() const;
uint32_t GetDeviceId() const;
const std::string& GetVendorName() const;
const std::string& GetArchitectureName() const;
const std::string& GetName() const;
const gpu_info::DriverVersion& GetDriverVersion() const;
const std::string& GetDriverDescription() const;
wgpu::AdapterType GetAdapterType() const;
wgpu::BackendType GetBackendType() const;
// This method differs from APIGetInstance() in that it won't increase the ref count of the
@ -71,17 +69,21 @@ class PhysicalDeviceBase : public RefCounted {
bool SupportsAllRequiredFeatures(
const ityp::span<size_t, const wgpu::FeatureName>& features) const;
bool GetLimits(SupportedLimits* limits) const;
void SetUseTieredLimits(bool useTieredLimits);
// Get the actual toggles state of the adapter.
const TogglesState& GetTogglesState() const;
const CombinedLimits& GetLimits() const;
virtual bool SupportsExternalImages() const = 0;
virtual bool SupportsFeatureLevel(FeatureLevel featureLevel) const = 0;
// Backend-specific force-setting and defaulting device toggles
virtual void SetupBackendDeviceToggles(TogglesState* deviceToggles) const = 0;
// Check if a feature os supported by this adapter AND suitable with given toggles.
// TODO(dawn:1495): After implementing adapter toggles, remove this and use adapter toggles
// instead of device toggles to validate supported features.
MaybeError ValidateFeatureSupportedWithToggles(wgpu::FeatureName feature,
const TogglesState& toggles) const;
protected:
uint32_t mVendorId = 0xFFFFFFFF;
std::string mVendorName;
@ -94,18 +96,10 @@ class PhysicalDeviceBase : public RefCounted {
// Mark a feature as enabled in mSupportedFeatures.
void EnableFeature(Feature feature);
// Check if a feature os supported by this adapter AND suitable with given toggles.
// TODO(dawn:1495): After implementing adapter toggles, remove this and use adapter toggles
// instead of device toggles to validate supported features.
MaybeError ValidateFeatureSupportedWithToggles(wgpu::FeatureName feature,
const TogglesState& toggles) const;
// Used for the tests that intend to use an adapter without all features enabled.
void SetSupportedFeaturesForTesting(const std::vector<wgpu::FeatureName>& requiredFeatures);
private:
// Backend-specific force-setting and defaulting device toggles
virtual void SetupBackendDeviceToggles(TogglesState* deviceToggles) const = 0;
virtual ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(AdapterBase* adapter,
const DeviceDescriptor* descriptor,
const TogglesState& deviceToggles) = 0;
@ -124,23 +118,16 @@ class PhysicalDeviceBase : public RefCounted {
wgpu::FeatureName feature,
const TogglesState& toggles) const = 0;
ResultOrError<Ref<DeviceBase>> CreateDeviceInternal(AdapterBase* adapter,
const DeviceDescriptor* descriptor);
virtual MaybeError ResetInternalDeviceForTestingImpl();
Ref<InstanceBase> mInstance;
wgpu::BackendType mBackend;
// Adapter toggles state, currently only inherited from instance toggles state.
TogglesState mTogglesState;
// Features set that CAN be supported by devices of this adapter. Some features in this set may
// be guarded by toggles, and creating a device with these features required may result in a
// validation error if proper toggles are not enabled/disabled.
FeaturesSet mSupportedFeatures;
CombinedLimits mLimits;
bool mUseTieredLimits = false;
};
} // namespace dawn::native

View File

@ -238,19 +238,17 @@ const PlatformFunctions* Backend::GetFunctions() const {
return mFunctions.get();
}
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
const TogglesState& adapterToggles) {
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
AdapterDiscoveryOptions options(ToAPI(GetType()), nullptr);
std::vector<Ref<PhysicalDeviceBase>> adapters;
if (GetInstance()->ConsumedError(DiscoverAdapters(&options, adapterToggles), &adapters)) {
if (GetInstance()->ConsumedError(DiscoverAdapters(&options), &adapters)) {
return {};
}
return adapters;
}
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
const AdapterDiscoveryOptionsBase* optionsBase,
const TogglesState& adapterToggles) {
const AdapterDiscoveryOptionsBase* optionsBase) {
ASSERT(optionsBase->backendType == ToAPI(GetType()));
const AdapterDiscoveryOptions* options =
static_cast<const AdapterDiscoveryOptions*>(optionsBase);
@ -259,8 +257,7 @@ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
if (options->dxgiAdapter != nullptr) {
// |dxgiAdapter| was provided. Discover just that adapter.
Ref<PhysicalDeviceBase> adapter;
DAWN_TRY_ASSIGN(adapter,
CreatePhysicalDeviceFromIDXGIAdapter(options->dxgiAdapter, adapterToggles));
DAWN_TRY_ASSIGN(adapter, CreatePhysicalDeviceFromIDXGIAdapter(options->dxgiAdapter));
adapters.push_back(std::move(adapter));
return std::move(adapters);
}
@ -274,8 +271,8 @@ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
ASSERT(dxgiAdapter != nullptr);
Ref<PhysicalDeviceBase> adapter;
if (GetInstance()->ConsumedError(
CreatePhysicalDeviceFromIDXGIAdapter(dxgiAdapter, adapterToggles), &adapter)) {
if (GetInstance()->ConsumedError(CreatePhysicalDeviceFromIDXGIAdapter(dxgiAdapter),
&adapter)) {
continue;
}

View File

@ -75,16 +75,13 @@ class Backend : public BackendConnection {
const PlatformFunctions* GetFunctions() const;
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters(
const TogglesState& adapterToggles) override;
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
const AdapterDiscoveryOptionsBase* optionsBase,
const TogglesState& adapterToggles) override;
const AdapterDiscoveryOptionsBase* optionsBase) override;
protected:
virtual ResultOrError<Ref<PhysicalDeviceBase>> CreatePhysicalDeviceFromIDXGIAdapter(
ComPtr<IDXGIAdapter> dxgiAdapter,
const TogglesState& adapterToggles) = 0;
ComPtr<IDXGIAdapter> dxgiAdapter) = 0;
private:
// Acquiring DXC version information and store the result in mDxcVersionInfo. This function

View File

@ -24,9 +24,8 @@ namespace dawn::native::d3d {
PhysicalDevice::PhysicalDevice(Backend* backend,
ComPtr<IDXGIAdapter3> hardwareAdapter,
wgpu::BackendType backendType,
const TogglesState& adapterToggles)
: PhysicalDeviceBase(backend->GetInstance(), backendType, adapterToggles),
wgpu::BackendType backendType)
: PhysicalDeviceBase(backend->GetInstance(), backendType),
mHardwareAdapter(std::move(hardwareAdapter)),
mBackend(backend) {}

View File

@ -27,8 +27,7 @@ class PhysicalDevice : public PhysicalDeviceBase {
public:
PhysicalDevice(Backend* backend,
ComPtr<IDXGIAdapter3> hardwareAdapter,
wgpu::BackendType backendType,
const TogglesState& adapterToggles);
wgpu::BackendType backendType);
~PhysicalDevice() override;
IDXGIAdapter3* GetHardwareAdapter() const;

View File

@ -42,12 +42,11 @@ const PlatformFunctions* Backend::GetFunctions() const {
}
ResultOrError<Ref<PhysicalDeviceBase>> Backend::CreatePhysicalDeviceFromIDXGIAdapter(
ComPtr<IDXGIAdapter> dxgiAdapter,
const TogglesState& adapterToggles) {
ComPtr<IDXGIAdapter> dxgiAdapter) {
ComPtr<IDXGIAdapter3> dxgiAdapter3;
DAWN_TRY(CheckHRESULT(dxgiAdapter.As(&dxgiAdapter3), "DXGIAdapter retrieval"));
Ref<PhysicalDevice> physicalDevice =
AcquireRef(new PhysicalDevice(this, std::move(dxgiAdapter3), adapterToggles));
AcquireRef(new PhysicalDevice(this, std::move(dxgiAdapter3)));
DAWN_TRY(physicalDevice->Initialize());
return {std::move(physicalDevice)};

View File

@ -32,8 +32,7 @@ class Backend : public d3d::Backend {
protected:
ResultOrError<Ref<PhysicalDeviceBase>> CreatePhysicalDeviceFromIDXGIAdapter(
ComPtr<IDXGIAdapter> dxgiAdapter,
const TogglesState& adapterToggles) override;
ComPtr<IDXGIAdapter> dxgiAdapter) override;
private:
using Base = d3d::Backend;

View File

@ -61,10 +61,8 @@ MaybeError InitializeDebugLayerFilters(ComPtr<ID3D11Device> d3d11Device) {
} // namespace
PhysicalDevice::PhysicalDevice(Backend* backend,
ComPtr<IDXGIAdapter3> hardwareAdapter,
const TogglesState& adapterToggles)
: Base(backend, std::move(hardwareAdapter), wgpu::BackendType::D3D11, adapterToggles) {}
PhysicalDevice::PhysicalDevice(Backend* backend, ComPtr<IDXGIAdapter3> hardwareAdapter)
: Base(backend, std::move(hardwareAdapter), wgpu::BackendType::D3D11) {}
PhysicalDevice::~PhysicalDevice() = default;

View File

@ -26,9 +26,7 @@ class Backend;
class PhysicalDevice : public d3d::PhysicalDevice {
public:
PhysicalDevice(Backend* backend,
ComPtr<IDXGIAdapter3> hardwareAdapter,
const TogglesState& adapterToggles);
PhysicalDevice(Backend* backend, ComPtr<IDXGIAdapter3> hardwareAdapter);
~PhysicalDevice() override;
// PhysicalDeviceBase Implementation

View File

@ -64,12 +64,11 @@ const PlatformFunctions* Backend::GetFunctions() const {
}
ResultOrError<Ref<PhysicalDeviceBase>> Backend::CreatePhysicalDeviceFromIDXGIAdapter(
ComPtr<IDXGIAdapter> dxgiAdapter,
const TogglesState& adapterToggles) {
ComPtr<IDXGIAdapter> dxgiAdapter) {
ComPtr<IDXGIAdapter3> dxgiAdapter3;
DAWN_TRY(CheckHRESULT(dxgiAdapter.As(&dxgiAdapter3), "DXGIAdapter retrieval"));
Ref<PhysicalDevice> physicalDevice =
AcquireRef(new PhysicalDevice(this, std::move(dxgiAdapter3), adapterToggles));
AcquireRef(new PhysicalDevice(this, std::move(dxgiAdapter3)));
DAWN_TRY(physicalDevice->Initialize());
return {std::move(physicalDevice)};

View File

@ -36,8 +36,7 @@ class Backend final : public d3d::Backend {
protected:
ResultOrError<Ref<PhysicalDeviceBase>> CreatePhysicalDeviceFromIDXGIAdapter(
ComPtr<IDXGIAdapter> dxgiAdapter,
const TogglesState& adapterToggles) override;
ComPtr<IDXGIAdapter> dxgiAdapter) override;
private:
using Base = d3d::Backend;

View File

@ -29,10 +29,8 @@
namespace dawn::native::d3d12 {
PhysicalDevice::PhysicalDevice(Backend* backend,
ComPtr<IDXGIAdapter3> hardwareAdapter,
const TogglesState& adapterToggles)
: Base(backend, std::move(hardwareAdapter), wgpu::BackendType::D3D12, adapterToggles) {}
PhysicalDevice::PhysicalDevice(Backend* backend, ComPtr<IDXGIAdapter3> hardwareAdapter)
: Base(backend, std::move(hardwareAdapter), wgpu::BackendType::D3D12) {}
PhysicalDevice::~PhysicalDevice() {
CleanUpDebugLayerFilters();

View File

@ -27,9 +27,7 @@ class Backend;
class PhysicalDevice : public d3d::PhysicalDevice {
public:
PhysicalDevice(Backend* backend,
ComPtr<IDXGIAdapter3> hardwareAdapter,
const TogglesState& adapterToggles);
PhysicalDevice(Backend* backend, ComPtr<IDXGIAdapter3> hardwareAdapter);
~PhysicalDevice() override;
// PhysicalDeviceBase Implementation

View File

@ -26,11 +26,9 @@ class Backend : public BackendConnection {
explicit Backend(InstanceBase* instance);
~Backend() override;
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters(
const TogglesState& adapterToggles) override;
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
const AdapterDiscoveryOptionsBase* optionsBase,
const TogglesState& adapterToggles) override;
const AdapterDiscoveryOptionsBase* optionsBase) override;
};
} // namespace dawn::native::metal

View File

@ -255,11 +255,8 @@ DAWN_NOINLINE bool IsGPUCounterSupported(id<MTLDevice> device,
class PhysicalDevice : public PhysicalDeviceBase {
public:
PhysicalDevice(InstanceBase* instance,
id<MTLDevice> device,
const TogglesState& requiredAdapterToggle)
: PhysicalDeviceBase(instance, wgpu::BackendType::Metal, requiredAdapterToggle),
mDevice(device) {
PhysicalDevice(InstanceBase* instance, id<MTLDevice> device)
: PhysicalDeviceBase(instance, wgpu::BackendType::Metal), mDevice(device) {
mName = std::string([[*mDevice name] UTF8String]);
PCIIDs ids;
@ -811,10 +808,9 @@ Backend::Backend(InstanceBase* instance) : BackendConnection(instance, wgpu::Bac
Backend::~Backend() = default;
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
const TogglesState& adapterToggles) {
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
AdapterDiscoveryOptions options;
auto result = DiscoverAdapters(&options, adapterToggles);
auto result = DiscoverAdapters(&options);
if (result.IsError()) {
GetInstance()->ConsumedError(result.AcquireError());
return {};
@ -823,8 +819,7 @@ std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
}
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
const AdapterDiscoveryOptionsBase* optionsBase,
const TogglesState& adapterToggles) {
const AdapterDiscoveryOptionsBase* optionsBase) {
ASSERT(optionsBase->backendType == WGPUBackendType_Metal);
std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
@ -832,8 +827,7 @@ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
NSRef<NSArray<id<MTLDevice>>> devices = AcquireNSRef(MTLCopyAllDevices());
for (id<MTLDevice> device in devices.Get()) {
Ref<PhysicalDevice> physicalDevice =
AcquireRef(new PhysicalDevice(GetInstance(), device, adapterToggles));
Ref<PhysicalDevice> physicalDevice = AcquireRef(new PhysicalDevice(GetInstance(), device));
if (!GetInstance()->ConsumedError(physicalDevice->Initialize())) {
physicalDevices.push_back(std::move(physicalDevice));
}
@ -842,8 +836,8 @@ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
// iOS only has a single device so MTLCopyAllDevices doesn't exist there.
#if defined(DAWN_PLATFORM_IOS)
Ref<PhysicalDevice> physicalDevice = AcquireRef(
new PhysicalDevice(GetInstance(), MTLCreateSystemDefaultDevice(), adapterToggles));
Ref<PhysicalDevice> physicalDevice =
AcquireRef(new PhysicalDevice(GetInstance(), MTLCreateSystemDefaultDevice()));
if (!GetInstance()->ConsumedError(physicalDevice->Initialize())) {
physicalDevices.push_back(std::move(physicalDevice));
}

View File

@ -32,11 +32,7 @@ namespace dawn::native::null {
// Connect()
PhysicalDevice::PhysicalDevice(InstanceBase* instance)
: PhysicalDevice(instance,
TogglesState(ToggleStage::Adapter).InheritFrom(instance->GetTogglesState())) {}
PhysicalDevice::PhysicalDevice(InstanceBase* instance, const TogglesState& adapterToggles)
: PhysicalDeviceBase(instance, wgpu::BackendType::Null, adapterToggles) {
: PhysicalDeviceBase(instance, wgpu::BackendType::Null) {
mVendorId = 0;
mDeviceId = 0;
mName = "Null backend";
@ -90,13 +86,11 @@ class Backend : public BackendConnection {
explicit Backend(InstanceBase* instance)
: BackendConnection(instance, wgpu::BackendType::Null) {}
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters(
const TogglesState& adapterToggles) override {
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() 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;
Ref<PhysicalDevice> physicalDevice =
AcquireRef(new PhysicalDevice(GetInstance(), adapterToggles));
Ref<PhysicalDevice> physicalDevice = AcquireRef(new PhysicalDevice(GetInstance()));
physicalDevices.push_back(std::move(physicalDevice));
return physicalDevices;
}

View File

@ -175,7 +175,6 @@ class PhysicalDevice : public PhysicalDeviceBase {
// Create null adapter without providing toggles state for testing, only inherit instance's
// toggles state
explicit PhysicalDevice(InstanceBase* instance);
PhysicalDevice(InstanceBase* instance, const TogglesState& adapterToggles);
~PhysicalDevice() override;
// PhysicalDeviceBase Implementation

View File

@ -33,8 +33,7 @@ namespace dawn::native::opengl {
Backend::Backend(InstanceBase* instance, wgpu::BackendType backendType)
: BackendConnection(instance, backendType) {}
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
const TogglesState& adapterToggles) {
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
std::vector<Ref<PhysicalDeviceBase>> adapters;
#if DAWN_PLATFORM_IS(WINDOWS)
const char* eglLib = "libEGL.dll";
@ -70,7 +69,7 @@ std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
context->MakeCurrent();
auto result = DiscoverAdapters(&options, adapterToggles);
auto result = DiscoverAdapters(&options);
if (result.IsError()) {
GetInstance()->ConsumedError(result.AcquireError());
@ -85,8 +84,7 @@ std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
}
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
const AdapterDiscoveryOptionsBase* optionsBase,
const TogglesState& adapterToggles) {
const AdapterDiscoveryOptionsBase* optionsBase) {
// TODO(cwallez@chromium.org): For now only create a single OpenGL adapter because don't
// know how to handle MakeCurrent.
DAWN_INVALID_IF(mCreatedAdapter, "The OpenGL backend can only create a single adapter.");
@ -98,7 +96,7 @@ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
DAWN_INVALID_IF(options->getProc == nullptr, "AdapterDiscoveryOptions::getProc must be set");
Ref<PhysicalDevice> adapter = AcquireRef(new PhysicalDevice(
GetInstance(), static_cast<wgpu::BackendType>(optionsBase->backendType), adapterToggles));
GetInstance(), static_cast<wgpu::BackendType>(optionsBase->backendType)));
DAWN_TRY(adapter->InitializeGLFunctions(options->getProc));
DAWN_TRY(adapter->Initialize());

View File

@ -26,11 +26,9 @@ class Backend : public BackendConnection {
public:
Backend(InstanceBase* instance, wgpu::BackendType backendType);
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters(
const TogglesState& adapterToggles) override;
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
const AdapterDiscoveryOptionsBase* option,
const TogglesState& adapterToggless) override;
const AdapterDiscoveryOptionsBase* option) override;
private:
bool mCreatedAdapter = false;

View File

@ -53,10 +53,8 @@ uint32_t GetVendorIdFromVendors(const char* vendor) {
} // anonymous namespace
PhysicalDevice::PhysicalDevice(InstanceBase* instance,
wgpu::BackendType backendType,
const TogglesState& adapterToggle)
: PhysicalDeviceBase(instance, backendType, adapterToggle) {}
PhysicalDevice::PhysicalDevice(InstanceBase* instance, wgpu::BackendType backendType)
: PhysicalDeviceBase(instance, backendType) {}
MaybeError PhysicalDevice::InitializeGLFunctions(void* (*getProc)(const char*)) {
// Use getProc to populate the dispatch table

View File

@ -23,9 +23,7 @@ namespace dawn::native::opengl {
class PhysicalDevice : public PhysicalDeviceBase {
public:
PhysicalDevice(InstanceBase* instance,
wgpu::BackendType backendType,
const TogglesState& adapterToggle);
PhysicalDevice(InstanceBase* instance, wgpu::BackendType backendType);
MaybeError InitializeGLFunctions(void* (*getProc)(const char*));

View File

@ -457,10 +457,9 @@ Backend::Backend(InstanceBase* instance) : BackendConnection(instance, wgpu::Bac
Backend::~Backend() = default;
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
const TogglesState& adapterToggles) {
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
AdapterDiscoveryOptions options;
auto result = DiscoverAdapters(&options, adapterToggles);
auto result = DiscoverAdapters(&options);
if (result.IsError()) {
GetInstance()->ConsumedError(result.AcquireError());
return {};
@ -469,8 +468,7 @@ std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
}
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
const AdapterDiscoveryOptionsBase* optionsBase,
const TogglesState& adapterToggles) {
const AdapterDiscoveryOptionsBase* optionsBase) {
ASSERT(optionsBase->backendType == WGPUBackendType_Vulkan);
const AdapterDiscoveryOptions* options =
@ -499,8 +497,8 @@ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
const std::vector<VkPhysicalDevice>& vkPhysicalDevices =
mVulkanInstances[icd]->GetVkPhysicalDevices();
for (uint32_t i = 0; i < vkPhysicalDevices.size(); ++i) {
Ref<PhysicalDevice> physicalDevice = AcquireRef(new PhysicalDevice(
instance, mVulkanInstances[icd].Get(), vkPhysicalDevices[i], adapterToggles));
Ref<PhysicalDevice> physicalDevice = AcquireRef(
new PhysicalDevice(instance, mVulkanInstances[icd].Get(), vkPhysicalDevices[i]));
if (instance->ConsumedError(physicalDevice->Initialize())) {
continue;
}

View File

@ -91,11 +91,9 @@ class Backend : public BackendConnection {
MaybeError Initialize();
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters(
const TogglesState& adapterToggles) override;
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
const AdapterDiscoveryOptionsBase* optionsBase,
const TogglesState& adapterToggles) override;
const AdapterDiscoveryOptionsBase* optionsBase) override;
private:
ityp::array<ICD, Ref<VulkanInstance>, 2> mVulkanInstances = {};

View File

@ -58,9 +58,8 @@ gpu_info::DriverVersion DecodeVulkanDriverVersion(uint32_t vendorID, uint32_t ve
PhysicalDevice::PhysicalDevice(InstanceBase* instance,
VulkanInstance* vulkanInstance,
VkPhysicalDevice physicalDevice,
const TogglesState& adapterToggles)
: PhysicalDeviceBase(instance, wgpu::BackendType::Vulkan, adapterToggles),
VkPhysicalDevice physicalDevice)
: PhysicalDeviceBase(instance, wgpu::BackendType::Vulkan),
mVkPhysicalDevice(physicalDevice),
mVulkanInstance(vulkanInstance) {}

View File

@ -29,8 +29,7 @@ class PhysicalDevice : public PhysicalDeviceBase {
public:
PhysicalDevice(InstanceBase* instance,
VulkanInstance* vulkanInstance,
VkPhysicalDevice physicalDevice,
const TogglesState& adapterToggles);
VkPhysicalDevice physicalDevice);
~PhysicalDevice() override;
// PhysicalDeviceBase Implementation

View File

@ -25,10 +25,12 @@
namespace {
std::unique_ptr<dawn::native::Instance> nativeInstance = nullptr;
WGPUAdapter nullBackendAdapter = nullptr;
wgpu::Adapter nullBackendAdapter = nullptr;
} // namespace
void SetupNullBackend(const benchmark::State& state) {
dawnProcSetProcs(&dawn::native::GetProcs());
if (!nativeInstance) {
nativeInstance = std::make_unique<dawn::native::Instance>();
nativeInstance->DiscoverDefaultAdapters();
@ -39,7 +41,7 @@ void SetupNullBackend(const benchmark::State& state) {
wgpu::AdapterProperties properties;
a.GetProperties(&properties);
if (properties.backendType == wgpu::BackendType::Null) {
nullBackendAdapter = a.Get();
nullBackendAdapter = wgpu::Adapter(a.Get());
}
}
}
@ -47,19 +49,16 @@ void SetupNullBackend(const benchmark::State& state) {
}
wgpu::Device CreateNullDevice(const wgpu::DeviceDescriptor& desc) {
dawnProcSetProcs(&dawn::native::GetProcs());
wgpu::Device device;
wgpu::Adapter(nullBackendAdapter)
.RequestDevice(
&desc,
[](WGPURequestDeviceStatus status, WGPUDevice cDevice, char const* message,
void* userdata) {
ASSERT(status == WGPURequestDeviceStatus_Success);
*reinterpret_cast<wgpu::Device*>(userdata) = wgpu::Device::Acquire(cDevice);
},
&device);
nullBackendAdapter.RequestDevice(
&desc,
[](WGPURequestDeviceStatus status, WGPUDevice cDevice, char const* message,
void* userdata) {
ASSERT(status == WGPURequestDeviceStatus_Success);
*reinterpret_cast<wgpu::Device*>(userdata) = wgpu::Device::Acquire(cDevice);
},
&device);
while (!device) {
wgpuInstanceProcessEvents(nativeInstance->Get());
}

View File

@ -263,13 +263,11 @@ class AdapterCreationTest : public ::testing::Test {
if (properties.compatibilityMode) {
continue;
}
swiftShaderAvailable =
swiftShaderAvailable ||
swiftShaderAvailable |=
gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID);
discreteGPUAvailable = discreteGPUAvailable ||
properties.adapterType == wgpu::AdapterType::DiscreteGPU;
integratedGPUAvailable = integratedGPUAvailable ||
properties.adapterType == wgpu::AdapterType::IntegratedGPU;
discreteGPUAvailable |= properties.adapterType == wgpu::AdapterType::DiscreteGPU;
integratedGPUAvailable |=
properties.adapterType == wgpu::AdapterType::IntegratedGPU;
}
}
@ -322,7 +320,7 @@ TEST_F(AdapterCreationTest, NullGivesDefaultAdapter) {
instance.RequestAdapter(nullptr, cb.Callback(), cb.MakeUserdata(this + 1));
wgpu::Adapter adapter2 = wgpu::Adapter::Acquire(cAdapter);
EXPECT_EQ(adapter.Get(), adapter2.Get());
EXPECT_EQ(adapter2 != nullptr, anyAdapterAvailable);
}
// Test that requesting the fallback adapter returns SwiftShader.

View File

@ -26,18 +26,19 @@ class FeatureTests : public testing::Test {
: testing::Test(),
mInstanceBase(dawn::native::InstanceBase::Create()),
mPhysicalDevice(mInstanceBase.Get()),
mUnsafePhysicalDeviceDisallow(
mInstanceBase.Get(),
mUnsafePhysicalDeviceDisallow(mInstanceBase.Get()),
mUnsafePhysicalDevice(mInstanceBase.Get()),
mAdapterBase(&mPhysicalDevice, dawn::native::FeatureLevel::Core),
mUnsafeAdapterBaseDisallow(
&mUnsafePhysicalDeviceDisallow,
dawn::native::FeatureLevel::Core,
dawn::native::TogglesState(dawn::native::ToggleStage::Adapter)
.SetForTesting(dawn::native::Toggle::DisallowUnsafeAPIs, false, false)),
mUnsafePhysicalDevice(
mInstanceBase.Get(),
mUnsafeAdapterBase(
&mUnsafePhysicalDevice,
dawn::native::FeatureLevel::Core,
dawn::native::TogglesState(dawn::native::ToggleStage::Adapter)
.SetForTesting(dawn::native::Toggle::AllowUnsafeAPIs, true, true)),
mAdapterBase(&mPhysicalDevice, dawn::native::FeatureLevel::Core),
mUnsafeAdapterBaseDisallow(&mUnsafePhysicalDeviceDisallow,
dawn::native::FeatureLevel::Core),
mUnsafeAdapterBase(&mUnsafePhysicalDevice, dawn::native::FeatureLevel::Core) {}
.SetForTesting(dawn::native::Toggle::AllowUnsafeAPIs, true, true)) {}
std::vector<wgpu::FeatureName> GetAllFeatureNames() {
std::vector<wgpu::FeatureName> allFeatureNames(kTotalFeaturesCount);
@ -149,7 +150,7 @@ TEST_F(FeatureTests, RequireAndGetEnabledFeatures) {
// AllowUnsafeAPIs or disables DisallowUnsafeApis, otherwise expect validation error.
if (featuresInfo.GetFeatureInfo(featureName)->featureState ==
dawn::native::FeatureInfo::FeatureState::Experimental) {
ASSERT_EQ(nullptr, deviceBase);
ASSERT_EQ(nullptr, deviceBase) << i;
} else {
// Requiring stable features should succeed.
ASSERT_NE(nullptr, deviceBase);

View File

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

View File

@ -260,6 +260,8 @@ TEST_F(DeviceCreationTest, CreateDeviceRequiringExperimentalFeatures) {
// Test creating device on the adapter with AllowUnsafeApis toggle enabled would succeed.
{
deviceDescriptor.nextInChain = nullptr;
wgpu::Device device = unsafeAdapter.CreateDevice(&deviceDescriptor);
EXPECT_NE(device, nullptr);