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:
parent
4d6f048af0
commit
096ce5936a
|
@ -14,56 +14,178 @@
|
||||||
|
|
||||||
#include "dawn/native/Adapter.h"
|
#include "dawn/native/Adapter.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
|
#include "dawn/native/ChainUtils_autogen.h"
|
||||||
|
#include "dawn/native/Device.h"
|
||||||
|
#include "dawn/native/Instance.h"
|
||||||
#include "dawn/native/PhysicalDevice.h"
|
#include "dawn/native/PhysicalDevice.h"
|
||||||
|
|
||||||
namespace dawn::native {
|
namespace dawn::native {
|
||||||
|
|
||||||
AdapterBase::AdapterBase(const Ref<PhysicalDeviceBase>& physicalDevice, FeatureLevel featureLevel)
|
AdapterBase::AdapterBase(Ref<PhysicalDeviceBase> physicalDevice, FeatureLevel featureLevel)
|
||||||
: mPhysicalDevice(std::move(physicalDevice)), mFeatureLevel(featureLevel) {
|
: AdapterBase(physicalDevice,
|
||||||
ASSERT(physicalDevice->SupportsFeatureLevel(featureLevel));
|
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;
|
AdapterBase::~AdapterBase() = default;
|
||||||
|
|
||||||
|
void AdapterBase::SetUseTieredLimits(bool useTieredLimits) {
|
||||||
|
mUseTieredLimits = useTieredLimits;
|
||||||
|
}
|
||||||
|
|
||||||
PhysicalDeviceBase* AdapterBase::GetPhysicalDevice() {
|
PhysicalDeviceBase* AdapterBase::GetPhysicalDevice() {
|
||||||
return mPhysicalDevice.Get();
|
return mPhysicalDevice.Get();
|
||||||
}
|
}
|
||||||
|
|
||||||
InstanceBase* AdapterBase::APIGetInstance() const {
|
InstanceBase* AdapterBase::APIGetInstance() const {
|
||||||
return mPhysicalDevice->APIGetInstance();
|
InstanceBase* instance = mPhysicalDevice->GetInstance();
|
||||||
|
ASSERT(instance != nullptr);
|
||||||
|
instance->APIReference();
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AdapterBase::APIGetLimits(SupportedLimits* limits) const {
|
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 {
|
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;
|
properties->compatibilityMode = mFeatureLevel == FeatureLevel::Compatibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AdapterBase::APIHasFeature(wgpu::FeatureName feature) const {
|
bool AdapterBase::APIHasFeature(wgpu::FeatureName feature) const {
|
||||||
return mPhysicalDevice->APIHasFeature(feature);
|
return mPhysicalDevice->HasFeature(feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t AdapterBase::APIEnumerateFeatures(wgpu::FeatureName* features) const {
|
size_t AdapterBase::APIEnumerateFeatures(wgpu::FeatureName* features) const {
|
||||||
return mPhysicalDevice->APIEnumerateFeatures(features);
|
return mPhysicalDevice->EnumerateFeatures(features);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceBase* AdapterBase::APICreateDevice(const DeviceDescriptor* descriptor) {
|
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,
|
void AdapterBase::APIRequestDevice(const DeviceDescriptor* descriptor,
|
||||||
WGPURequestDeviceCallback callback,
|
WGPURequestDeviceCallback callback,
|
||||||
void* userdata) {
|
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 {
|
const TogglesState& AdapterBase::GetTogglesState() const {
|
||||||
return mPhysicalDevice->GetTogglesState();
|
return mTogglesState;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AdapterBase::AllowUnsafeAPIs() const {
|
bool AdapterBase::AllowUnsafeAPIs() const {
|
||||||
|
|
|
@ -29,7 +29,10 @@ struct SupportedLimits;
|
||||||
|
|
||||||
class AdapterBase : public RefCounted {
|
class AdapterBase : public RefCounted {
|
||||||
public:
|
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;
|
~AdapterBase() override;
|
||||||
|
|
||||||
// WebGPU API
|
// WebGPU API
|
||||||
|
@ -42,6 +45,9 @@ class AdapterBase : public RefCounted {
|
||||||
WGPURequestDeviceCallback callback,
|
WGPURequestDeviceCallback callback,
|
||||||
void* userdata);
|
void* userdata);
|
||||||
DeviceBase* APICreateDevice(const DeviceDescriptor* descriptor = nullptr);
|
DeviceBase* APICreateDevice(const DeviceDescriptor* descriptor = nullptr);
|
||||||
|
ResultOrError<Ref<DeviceBase>> CreateDevice(const DeviceDescriptor* descriptor);
|
||||||
|
|
||||||
|
void SetUseTieredLimits(bool useTieredLimits);
|
||||||
|
|
||||||
// Return the underlying PhysicalDevice.
|
// Return the underlying PhysicalDevice.
|
||||||
PhysicalDeviceBase* GetPhysicalDevice();
|
PhysicalDeviceBase* GetPhysicalDevice();
|
||||||
|
@ -59,6 +65,9 @@ class AdapterBase : public RefCounted {
|
||||||
private:
|
private:
|
||||||
Ref<PhysicalDeviceBase> mPhysicalDevice;
|
Ref<PhysicalDeviceBase> mPhysicalDevice;
|
||||||
FeatureLevel mFeatureLevel;
|
FeatureLevel mFeatureLevel;
|
||||||
|
bool mUseTieredLimits = false;
|
||||||
|
// Adapter toggles state, currently only inherited from instance toggles state.
|
||||||
|
TogglesState mTogglesState;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dawn::native
|
} // namespace dawn::native
|
||||||
|
|
|
@ -29,8 +29,7 @@ InstanceBase* BackendConnection::GetInstance() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> BackendConnection::DiscoverAdapters(
|
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> BackendConnection::DiscoverAdapters(
|
||||||
const AdapterDiscoveryOptionsBase* options,
|
const AdapterDiscoveryOptionsBase* options) {
|
||||||
const TogglesState& adapterToggles) {
|
|
||||||
return DAWN_VALIDATION_ERROR("DiscoverAdapters not implemented for this backend.");
|
return DAWN_VALIDATION_ERROR("DiscoverAdapters not implemented for this backend.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -36,13 +36,11 @@ class BackendConnection {
|
||||||
|
|
||||||
// Returns all the adapters for the system that can be created by the backend, without extra
|
// 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.)
|
// options (such as debug adapters, custom driver libraries, etc.)
|
||||||
virtual std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters(
|
virtual std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() = 0;
|
||||||
const TogglesState& adapterToggles) = 0;
|
|
||||||
|
|
||||||
// Returns new adapters created with the backend-specific options.
|
// Returns new adapters created with the backend-specific options.
|
||||||
virtual ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
virtual ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
||||||
const AdapterDiscoveryOptionsBase* options,
|
const AdapterDiscoveryOptionsBase* options);
|
||||||
const TogglesState& adapterToggles);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
InstanceBase* mInstance = nullptr;
|
InstanceBase* mInstance = nullptr;
|
||||||
|
|
|
@ -89,11 +89,11 @@ std::vector<const char*> Adapter::GetSupportedFeatures() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Adapter::GetLimits(WGPUSupportedLimits* limits) const {
|
bool Adapter::GetLimits(WGPUSupportedLimits* limits) const {
|
||||||
return mImpl->GetPhysicalDevice()->GetLimits(FromAPI(limits));
|
return mImpl->APIGetLimits(FromAPI(limits));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Adapter::SetUseTieredLimits(bool useTieredLimits) {
|
void Adapter::SetUseTieredLimits(bool useTieredLimits) {
|
||||||
mImpl->GetPhysicalDevice()->SetUseTieredLimits(useTieredLimits);
|
mImpl->SetUseTieredLimits(useTieredLimits);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Adapter::SupportsExternalImages() const {
|
bool Adapter::SupportsExternalImages() const {
|
||||||
|
|
|
@ -157,7 +157,7 @@ void InstanceBase::WillDropLastExternalRef() {
|
||||||
// In order to break this cycle and prevent leaks, when the application drops the last external
|
// 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
|
// 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.
|
// 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.
|
// 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> cpuAdapterIndex;
|
||||||
std::optional<size_t> unknownAdapterIndex;
|
std::optional<size_t> unknownAdapterIndex;
|
||||||
|
|
||||||
for (size_t i = 0; i < mAdapters.size(); ++i) {
|
Ref<PhysicalDeviceBase> selectedPhysicalDevice;
|
||||||
AdapterProperties properties;
|
FeatureLevel featureLevel =
|
||||||
mAdapters[i]->APIGetProperties(&properties);
|
options->compatibilityMode ? FeatureLevel::Compatibility : FeatureLevel::Core;
|
||||||
|
for (size_t i = 0; i < mPhysicalDevices.size(); ++i) {
|
||||||
bool isCompatibility = mAdapters[i]->GetFeatureLevel() == FeatureLevel::Compatibility;
|
if (!mPhysicalDevices[i]->SupportsFeatureLevel(featureLevel)) {
|
||||||
if (options->compatibilityMode != isCompatibility) {
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options->forceFallbackAdapter) {
|
if (options->forceFallbackAdapter) {
|
||||||
if (!gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID)) {
|
if (!gpu_info::IsGoogleSwiftshader(mPhysicalDevices[i]->GetVendorId(),
|
||||||
|
mPhysicalDevices[i]->GetDeviceId())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return mAdapters[i];
|
selectedPhysicalDevice = mPhysicalDevices[i];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (properties.adapterType == preferredType) {
|
if (mPhysicalDevices[i]->GetAdapterType() == preferredType) {
|
||||||
return mAdapters[i];
|
selectedPhysicalDevice = mPhysicalDevices[i];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
switch (properties.adapterType) {
|
switch (mPhysicalDevices[i]->GetAdapterType()) {
|
||||||
case wgpu::AdapterType::DiscreteGPU:
|
case wgpu::AdapterType::DiscreteGPU:
|
||||||
discreteGPUAdapterIndex = i;
|
discreteGPUAdapterIndex = i;
|
||||||
break;
|
break;
|
||||||
|
@ -285,20 +288,30 @@ ResultOrError<Ref<AdapterBase>> InstanceBase::RequestAdapterInternal(
|
||||||
}
|
}
|
||||||
|
|
||||||
// For now, we always prefer the discrete GPU
|
// For now, we always prefer the discrete GPU
|
||||||
if (discreteGPUAdapterIndex) {
|
if (selectedPhysicalDevice == nullptr) {
|
||||||
return mAdapters[*discreteGPUAdapterIndex];
|
if (discreteGPUAdapterIndex) {
|
||||||
}
|
selectedPhysicalDevice = mPhysicalDevices[*discreteGPUAdapterIndex];
|
||||||
if (integratedGPUAdapterIndex) {
|
} else if (integratedGPUAdapterIndex) {
|
||||||
return mAdapters[*integratedGPUAdapterIndex];
|
selectedPhysicalDevice = mPhysicalDevices[*integratedGPUAdapterIndex];
|
||||||
}
|
} else if (cpuAdapterIndex) {
|
||||||
if (cpuAdapterIndex) {
|
selectedPhysicalDevice = mPhysicalDevices[*cpuAdapterIndex];
|
||||||
return mAdapters[*cpuAdapterIndex];
|
} else if (unknownAdapterIndex) {
|
||||||
}
|
selectedPhysicalDevice = mPhysicalDevices[*unknownAdapterIndex];
|
||||||
if (unknownAdapterIndex) {
|
}
|
||||||
return mAdapters[*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() {
|
void InstanceBase::DiscoverDefaultAdapters() {
|
||||||
|
@ -312,24 +325,12 @@ void InstanceBase::DiscoverDefaultAdapters() {
|
||||||
|
|
||||||
// Query and merge all default adapters for all backends
|
// Query and merge all default adapters for all backends
|
||||||
for (std::unique_ptr<BackendConnection>& backend : mBackends) {
|
for (std::unique_ptr<BackendConnection>& backend : mBackends) {
|
||||||
// Set up toggles state for default adapters, currently adapter don't have a toggles
|
std::vector<Ref<PhysicalDeviceBase>> physicalDevices = backend->DiscoverDefaultAdapters();
|
||||||
// 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);
|
|
||||||
|
|
||||||
for (Ref<PhysicalDeviceBase>& physicalDevice : physicalDevices) {
|
for (Ref<PhysicalDeviceBase>& physicalDevice : physicalDevices) {
|
||||||
ASSERT(physicalDevice->GetBackendType() == backend->GetType());
|
ASSERT(physicalDevice->GetBackendType() == backend->GetType());
|
||||||
ASSERT(physicalDevice->GetInstance() == this);
|
ASSERT(physicalDevice->GetInstance() == this);
|
||||||
for (auto featureLevel : {FeatureLevel::Compatibility, FeatureLevel::Core}) {
|
mPhysicalDevices.push_back(std::move(physicalDevice));
|
||||||
if (physicalDevice->SupportsFeatureLevel(featureLevel)) {
|
|
||||||
mAdapters.push_back(
|
|
||||||
AcquireRef(new AdapterBase(std::move(physicalDevice), featureLevel)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -366,8 +367,23 @@ const FeatureInfo* InstanceBase::GetFeatureInfo(wgpu::FeatureName feature) {
|
||||||
return mFeaturesInfo.GetFeatureInfo(feature);
|
return mFeaturesInfo.GetFeatureInfo(feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::vector<Ref<AdapterBase>>& InstanceBase::GetAdapters() const {
|
std::vector<Ref<AdapterBase>> InstanceBase::GetAdapters() const {
|
||||||
return mAdapters;
|
// 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) {
|
void InstanceBase::EnsureBackendConnection(wgpu::BackendType backendType) {
|
||||||
|
@ -451,24 +467,13 @@ MaybeError InstanceBase::DiscoverAdaptersInternal(const AdapterDiscoveryOptionsB
|
||||||
}
|
}
|
||||||
foundBackend = true;
|
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;
|
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) {
|
for (Ref<PhysicalDeviceBase>& physicalDevice : newPhysicalDevices) {
|
||||||
ASSERT(physicalDevice->GetBackendType() == backend->GetType());
|
ASSERT(physicalDevice->GetBackendType() == backend->GetType());
|
||||||
ASSERT(physicalDevice->GetInstance() == this);
|
ASSERT(physicalDevice->GetInstance() == this);
|
||||||
for (auto featureLevel : {FeatureLevel::Compatibility, FeatureLevel::Core}) {
|
mPhysicalDevices.push_back(std::move(physicalDevice));
|
||||||
if (physicalDevice->SupportsFeatureLevel(featureLevel)) {
|
|
||||||
mAdapters.push_back(
|
|
||||||
AcquireRef(new AdapterBase(std::move(physicalDevice), featureLevel)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -61,7 +61,7 @@ class InstanceBase final : public RefCountedWithExternalCount {
|
||||||
void DiscoverDefaultAdapters();
|
void DiscoverDefaultAdapters();
|
||||||
bool DiscoverAdapters(const AdapterDiscoveryOptionsBase* options);
|
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.
|
// Used to handle error that happen up to device creation.
|
||||||
bool ConsumedError(MaybeError maybeError);
|
bool ConsumedError(MaybeError maybeError);
|
||||||
|
@ -157,7 +157,7 @@ class InstanceBase final : public RefCountedWithExternalCount {
|
||||||
BlobCache mPassthroughBlobCache;
|
BlobCache mPassthroughBlobCache;
|
||||||
|
|
||||||
std::vector<std::unique_ptr<BackendConnection>> mBackends;
|
std::vector<std::unique_ptr<BackendConnection>> mBackends;
|
||||||
std::vector<Ref<AdapterBase>> mAdapters;
|
std::vector<Ref<PhysicalDeviceBase>> mPhysicalDevices;
|
||||||
|
|
||||||
TogglesState mToggles;
|
TogglesState mToggles;
|
||||||
|
|
||||||
|
|
|
@ -21,18 +21,13 @@
|
||||||
#include "dawn/common/GPUInfo.h"
|
#include "dawn/common/GPUInfo.h"
|
||||||
#include "dawn/common/Log.h"
|
#include "dawn/common/Log.h"
|
||||||
#include "dawn/native/ChainUtils_autogen.h"
|
#include "dawn/native/ChainUtils_autogen.h"
|
||||||
#include "dawn/native/Device.h"
|
|
||||||
#include "dawn/native/Instance.h"
|
#include "dawn/native/Instance.h"
|
||||||
#include "dawn/native/ValidationUtils_autogen.h"
|
#include "dawn/native/ValidationUtils_autogen.h"
|
||||||
|
|
||||||
namespace dawn::native {
|
namespace dawn::native {
|
||||||
|
|
||||||
PhysicalDeviceBase::PhysicalDeviceBase(InstanceBase* instance,
|
PhysicalDeviceBase::PhysicalDeviceBase(InstanceBase* instance, wgpu::BackendType backend)
|
||||||
wgpu::BackendType backend,
|
: mInstance(instance), mBackend(backend) {}
|
||||||
const TogglesState& adapterToggles)
|
|
||||||
: mInstance(instance), mBackend(backend), mTogglesState(adapterToggles) {
|
|
||||||
ASSERT(adapterToggles.GetStage() == ToggleStage::Adapter);
|
|
||||||
}
|
|
||||||
|
|
||||||
PhysicalDeviceBase::~PhysicalDeviceBase() = default;
|
PhysicalDeviceBase::~PhysicalDeviceBase() = default;
|
||||||
|
|
||||||
|
@ -56,87 +51,18 @@ MaybeError PhysicalDeviceBase::Initialize() {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
InstanceBase* PhysicalDeviceBase::APIGetInstance() const {
|
bool PhysicalDeviceBase::HasFeature(wgpu::FeatureName feature) 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 {
|
|
||||||
return mSupportedFeatures.IsEnabled(feature);
|
return mSupportedFeatures.IsEnabled(feature);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t PhysicalDeviceBase::APIEnumerateFeatures(wgpu::FeatureName* features) const {
|
size_t PhysicalDeviceBase::EnumerateFeatures(wgpu::FeatureName* features) const {
|
||||||
return mSupportedFeatures.EnumerateFeatures(features);
|
return mSupportedFeatures.EnumerateFeatures(features);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeviceBase* PhysicalDeviceBase::CreateDevice(AdapterBase* adapter,
|
ResultOrError<Ref<DeviceBase>> PhysicalDeviceBase::CreateDevice(AdapterBase* adapter,
|
||||||
const DeviceDescriptor* descriptor) {
|
const DeviceDescriptor* descriptor,
|
||||||
DeviceDescriptor defaultDesc = {};
|
const TogglesState& deviceToggles) {
|
||||||
if (descriptor == nullptr) {
|
return CreateDeviceImpl(adapter, descriptor, deviceToggles);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicalDeviceBase::InitializeVendorArchitectureImpl() {
|
void PhysicalDeviceBase::InitializeVendorArchitectureImpl() {
|
||||||
|
@ -152,10 +78,30 @@ uint32_t PhysicalDeviceBase::GetDeviceId() const {
|
||||||
return mDeviceId;
|
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 {
|
const gpu_info::DriverVersion& PhysicalDeviceBase::GetDriverVersion() const {
|
||||||
return mDriverVersion;
|
return mDriverVersion;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::string& PhysicalDeviceBase::GetDriverDescription() const {
|
||||||
|
return mDriverDescription;
|
||||||
|
}
|
||||||
|
|
||||||
|
wgpu::AdapterType PhysicalDeviceBase::GetAdapterType() const {
|
||||||
|
return mAdapterType;
|
||||||
|
}
|
||||||
|
|
||||||
wgpu::BackendType PhysicalDeviceBase::GetBackendType() const {
|
wgpu::BackendType PhysicalDeviceBase::GetBackendType() const {
|
||||||
return mBackend;
|
return mBackend;
|
||||||
}
|
}
|
||||||
|
@ -178,21 +124,8 @@ bool PhysicalDeviceBase::SupportsAllRequiredFeatures(
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhysicalDeviceBase::GetLimits(SupportedLimits* limits) const {
|
const CombinedLimits& PhysicalDeviceBase::GetLimits() const {
|
||||||
ASSERT(limits != nullptr);
|
return mLimits;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicalDeviceBase::EnableFeature(Feature feature) {
|
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() {
|
void PhysicalDeviceBase::ResetInternalDeviceForTesting() {
|
||||||
mInstance->ConsumedError(ResetInternalDeviceForTestingImpl());
|
mInstance->ConsumedError(ResetInternalDeviceForTestingImpl());
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,28 +37,26 @@ enum class FeatureLevel { Compatibility, Core };
|
||||||
|
|
||||||
class PhysicalDeviceBase : public RefCounted {
|
class PhysicalDeviceBase : public RefCounted {
|
||||||
public:
|
public:
|
||||||
PhysicalDeviceBase(InstanceBase* instance,
|
PhysicalDeviceBase(InstanceBase* instance, wgpu::BackendType backend);
|
||||||
wgpu::BackendType backend,
|
|
||||||
const TogglesState& adapterToggles);
|
|
||||||
~PhysicalDeviceBase() override;
|
~PhysicalDeviceBase() override;
|
||||||
|
|
||||||
MaybeError Initialize();
|
MaybeError Initialize();
|
||||||
|
|
||||||
// WebGPU API
|
bool HasFeature(wgpu::FeatureName feature) const;
|
||||||
InstanceBase* APIGetInstance() const;
|
size_t EnumerateFeatures(wgpu::FeatureName* features) const;
|
||||||
bool APIGetLimits(SupportedLimits* limits) const;
|
|
||||||
void APIGetProperties(AdapterProperties* properties) const;
|
ResultOrError<Ref<DeviceBase>> CreateDevice(AdapterBase* adapter,
|
||||||
bool APIHasFeature(wgpu::FeatureName feature) const;
|
const DeviceDescriptor* descriptor,
|
||||||
size_t APIEnumerateFeatures(wgpu::FeatureName* features) const;
|
const TogglesState& deviceToggles);
|
||||||
void RequestDevice(AdapterBase* adapter,
|
|
||||||
const DeviceDescriptor* descriptor,
|
|
||||||
WGPURequestDeviceCallback callback,
|
|
||||||
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;
|
||||||
|
const std::string& GetVendorName() const;
|
||||||
|
const std::string& GetArchitectureName() const;
|
||||||
|
const std::string& GetName() const;
|
||||||
const gpu_info::DriverVersion& GetDriverVersion() const;
|
const gpu_info::DriverVersion& GetDriverVersion() const;
|
||||||
|
const std::string& GetDriverDescription() const;
|
||||||
|
wgpu::AdapterType GetAdapterType() const;
|
||||||
wgpu::BackendType GetBackendType() const;
|
wgpu::BackendType GetBackendType() const;
|
||||||
|
|
||||||
// This method differs from APIGetInstance() in that it won't increase the ref count of the
|
// 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(
|
bool SupportsAllRequiredFeatures(
|
||||||
const ityp::span<size_t, const wgpu::FeatureName>& features) const;
|
const ityp::span<size_t, const wgpu::FeatureName>& features) const;
|
||||||
|
|
||||||
bool GetLimits(SupportedLimits* limits) const;
|
const CombinedLimits& GetLimits() const;
|
||||||
|
|
||||||
void SetUseTieredLimits(bool useTieredLimits);
|
|
||||||
|
|
||||||
// Get the actual toggles state of the adapter.
|
|
||||||
const TogglesState& GetTogglesState() const;
|
|
||||||
|
|
||||||
virtual bool SupportsExternalImages() const = 0;
|
virtual bool SupportsExternalImages() const = 0;
|
||||||
|
|
||||||
virtual bool SupportsFeatureLevel(FeatureLevel featureLevel) 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:
|
protected:
|
||||||
uint32_t mVendorId = 0xFFFFFFFF;
|
uint32_t mVendorId = 0xFFFFFFFF;
|
||||||
std::string mVendorName;
|
std::string mVendorName;
|
||||||
|
@ -94,18 +96,10 @@ class PhysicalDeviceBase : public RefCounted {
|
||||||
|
|
||||||
// Mark a feature as enabled in mSupportedFeatures.
|
// Mark a feature as enabled in mSupportedFeatures.
|
||||||
void EnableFeature(Feature feature);
|
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.
|
// Used for the tests that intend to use an adapter without all features enabled.
|
||||||
void SetSupportedFeaturesForTesting(const std::vector<wgpu::FeatureName>& requiredFeatures);
|
void SetSupportedFeaturesForTesting(const std::vector<wgpu::FeatureName>& requiredFeatures);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Backend-specific force-setting and defaulting device toggles
|
|
||||||
virtual void SetupBackendDeviceToggles(TogglesState* deviceToggles) const = 0;
|
|
||||||
|
|
||||||
virtual ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(AdapterBase* adapter,
|
virtual ResultOrError<Ref<DeviceBase>> CreateDeviceImpl(AdapterBase* adapter,
|
||||||
const DeviceDescriptor* descriptor,
|
const DeviceDescriptor* descriptor,
|
||||||
const TogglesState& deviceToggles) = 0;
|
const TogglesState& deviceToggles) = 0;
|
||||||
|
@ -124,23 +118,16 @@ class PhysicalDeviceBase : public RefCounted {
|
||||||
wgpu::FeatureName feature,
|
wgpu::FeatureName feature,
|
||||||
const TogglesState& toggles) const = 0;
|
const TogglesState& toggles) const = 0;
|
||||||
|
|
||||||
ResultOrError<Ref<DeviceBase>> CreateDeviceInternal(AdapterBase* adapter,
|
|
||||||
const DeviceDescriptor* descriptor);
|
|
||||||
|
|
||||||
virtual MaybeError ResetInternalDeviceForTestingImpl();
|
virtual MaybeError ResetInternalDeviceForTestingImpl();
|
||||||
Ref<InstanceBase> mInstance;
|
Ref<InstanceBase> mInstance;
|
||||||
wgpu::BackendType mBackend;
|
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
|
// 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
|
// 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.
|
// validation error if proper toggles are not enabled/disabled.
|
||||||
FeaturesSet mSupportedFeatures;
|
FeaturesSet mSupportedFeatures;
|
||||||
|
|
||||||
CombinedLimits mLimits;
|
CombinedLimits mLimits;
|
||||||
bool mUseTieredLimits = false;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dawn::native
|
} // namespace dawn::native
|
||||||
|
|
|
@ -238,19 +238,17 @@ const PlatformFunctions* Backend::GetFunctions() const {
|
||||||
return mFunctions.get();
|
return mFunctions.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
|
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
|
||||||
const TogglesState& adapterToggles) {
|
|
||||||
AdapterDiscoveryOptions options(ToAPI(GetType()), nullptr);
|
AdapterDiscoveryOptions options(ToAPI(GetType()), nullptr);
|
||||||
std::vector<Ref<PhysicalDeviceBase>> adapters;
|
std::vector<Ref<PhysicalDeviceBase>> adapters;
|
||||||
if (GetInstance()->ConsumedError(DiscoverAdapters(&options, adapterToggles), &adapters)) {
|
if (GetInstance()->ConsumedError(DiscoverAdapters(&options), &adapters)) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
return adapters;
|
return adapters;
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
||||||
const AdapterDiscoveryOptionsBase* optionsBase,
|
const AdapterDiscoveryOptionsBase* optionsBase) {
|
||||||
const TogglesState& adapterToggles) {
|
|
||||||
ASSERT(optionsBase->backendType == ToAPI(GetType()));
|
ASSERT(optionsBase->backendType == ToAPI(GetType()));
|
||||||
const AdapterDiscoveryOptions* options =
|
const AdapterDiscoveryOptions* options =
|
||||||
static_cast<const AdapterDiscoveryOptions*>(optionsBase);
|
static_cast<const AdapterDiscoveryOptions*>(optionsBase);
|
||||||
|
@ -259,8 +257,7 @@ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
||||||
if (options->dxgiAdapter != nullptr) {
|
if (options->dxgiAdapter != nullptr) {
|
||||||
// |dxgiAdapter| was provided. Discover just that adapter.
|
// |dxgiAdapter| was provided. Discover just that adapter.
|
||||||
Ref<PhysicalDeviceBase> adapter;
|
Ref<PhysicalDeviceBase> adapter;
|
||||||
DAWN_TRY_ASSIGN(adapter,
|
DAWN_TRY_ASSIGN(adapter, CreatePhysicalDeviceFromIDXGIAdapter(options->dxgiAdapter));
|
||||||
CreatePhysicalDeviceFromIDXGIAdapter(options->dxgiAdapter, adapterToggles));
|
|
||||||
adapters.push_back(std::move(adapter));
|
adapters.push_back(std::move(adapter));
|
||||||
return std::move(adapters);
|
return std::move(adapters);
|
||||||
}
|
}
|
||||||
|
@ -274,8 +271,8 @@ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
||||||
|
|
||||||
ASSERT(dxgiAdapter != nullptr);
|
ASSERT(dxgiAdapter != nullptr);
|
||||||
Ref<PhysicalDeviceBase> adapter;
|
Ref<PhysicalDeviceBase> adapter;
|
||||||
if (GetInstance()->ConsumedError(
|
if (GetInstance()->ConsumedError(CreatePhysicalDeviceFromIDXGIAdapter(dxgiAdapter),
|
||||||
CreatePhysicalDeviceFromIDXGIAdapter(dxgiAdapter, adapterToggles), &adapter)) {
|
&adapter)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,16 +75,13 @@ class Backend : public BackendConnection {
|
||||||
|
|
||||||
const PlatformFunctions* GetFunctions() const;
|
const PlatformFunctions* GetFunctions() const;
|
||||||
|
|
||||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters(
|
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
|
||||||
const TogglesState& adapterToggles) override;
|
|
||||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
||||||
const AdapterDiscoveryOptionsBase* optionsBase,
|
const AdapterDiscoveryOptionsBase* optionsBase) override;
|
||||||
const TogglesState& adapterToggles) override;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ResultOrError<Ref<PhysicalDeviceBase>> CreatePhysicalDeviceFromIDXGIAdapter(
|
virtual ResultOrError<Ref<PhysicalDeviceBase>> CreatePhysicalDeviceFromIDXGIAdapter(
|
||||||
ComPtr<IDXGIAdapter> dxgiAdapter,
|
ComPtr<IDXGIAdapter> dxgiAdapter) = 0;
|
||||||
const TogglesState& adapterToggles) = 0;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Acquiring DXC version information and store the result in mDxcVersionInfo. This function
|
// Acquiring DXC version information and store the result in mDxcVersionInfo. This function
|
||||||
|
|
|
@ -24,9 +24,8 @@ namespace dawn::native::d3d {
|
||||||
|
|
||||||
PhysicalDevice::PhysicalDevice(Backend* backend,
|
PhysicalDevice::PhysicalDevice(Backend* backend,
|
||||||
ComPtr<IDXGIAdapter3> hardwareAdapter,
|
ComPtr<IDXGIAdapter3> hardwareAdapter,
|
||||||
wgpu::BackendType backendType,
|
wgpu::BackendType backendType)
|
||||||
const TogglesState& adapterToggles)
|
: PhysicalDeviceBase(backend->GetInstance(), backendType),
|
||||||
: PhysicalDeviceBase(backend->GetInstance(), backendType, adapterToggles),
|
|
||||||
mHardwareAdapter(std::move(hardwareAdapter)),
|
mHardwareAdapter(std::move(hardwareAdapter)),
|
||||||
mBackend(backend) {}
|
mBackend(backend) {}
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,7 @@ class PhysicalDevice : public PhysicalDeviceBase {
|
||||||
public:
|
public:
|
||||||
PhysicalDevice(Backend* backend,
|
PhysicalDevice(Backend* backend,
|
||||||
ComPtr<IDXGIAdapter3> hardwareAdapter,
|
ComPtr<IDXGIAdapter3> hardwareAdapter,
|
||||||
wgpu::BackendType backendType,
|
wgpu::BackendType backendType);
|
||||||
const TogglesState& adapterToggles);
|
|
||||||
~PhysicalDevice() override;
|
~PhysicalDevice() override;
|
||||||
|
|
||||||
IDXGIAdapter3* GetHardwareAdapter() const;
|
IDXGIAdapter3* GetHardwareAdapter() const;
|
||||||
|
|
|
@ -42,12 +42,11 @@ const PlatformFunctions* Backend::GetFunctions() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<Ref<PhysicalDeviceBase>> Backend::CreatePhysicalDeviceFromIDXGIAdapter(
|
ResultOrError<Ref<PhysicalDeviceBase>> Backend::CreatePhysicalDeviceFromIDXGIAdapter(
|
||||||
ComPtr<IDXGIAdapter> dxgiAdapter,
|
ComPtr<IDXGIAdapter> dxgiAdapter) {
|
||||||
const TogglesState& adapterToggles) {
|
|
||||||
ComPtr<IDXGIAdapter3> dxgiAdapter3;
|
ComPtr<IDXGIAdapter3> dxgiAdapter3;
|
||||||
DAWN_TRY(CheckHRESULT(dxgiAdapter.As(&dxgiAdapter3), "DXGIAdapter retrieval"));
|
DAWN_TRY(CheckHRESULT(dxgiAdapter.As(&dxgiAdapter3), "DXGIAdapter retrieval"));
|
||||||
Ref<PhysicalDevice> physicalDevice =
|
Ref<PhysicalDevice> physicalDevice =
|
||||||
AcquireRef(new PhysicalDevice(this, std::move(dxgiAdapter3), adapterToggles));
|
AcquireRef(new PhysicalDevice(this, std::move(dxgiAdapter3)));
|
||||||
DAWN_TRY(physicalDevice->Initialize());
|
DAWN_TRY(physicalDevice->Initialize());
|
||||||
|
|
||||||
return {std::move(physicalDevice)};
|
return {std::move(physicalDevice)};
|
||||||
|
|
|
@ -32,8 +32,7 @@ class Backend : public d3d::Backend {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ResultOrError<Ref<PhysicalDeviceBase>> CreatePhysicalDeviceFromIDXGIAdapter(
|
ResultOrError<Ref<PhysicalDeviceBase>> CreatePhysicalDeviceFromIDXGIAdapter(
|
||||||
ComPtr<IDXGIAdapter> dxgiAdapter,
|
ComPtr<IDXGIAdapter> dxgiAdapter) override;
|
||||||
const TogglesState& adapterToggles) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using Base = d3d::Backend;
|
using Base = d3d::Backend;
|
||||||
|
|
|
@ -61,10 +61,8 @@ MaybeError InitializeDebugLayerFilters(ComPtr<ID3D11Device> d3d11Device) {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
PhysicalDevice::PhysicalDevice(Backend* backend,
|
PhysicalDevice::PhysicalDevice(Backend* backend, ComPtr<IDXGIAdapter3> hardwareAdapter)
|
||||||
ComPtr<IDXGIAdapter3> hardwareAdapter,
|
: Base(backend, std::move(hardwareAdapter), wgpu::BackendType::D3D11) {}
|
||||||
const TogglesState& adapterToggles)
|
|
||||||
: Base(backend, std::move(hardwareAdapter), wgpu::BackendType::D3D11, adapterToggles) {}
|
|
||||||
|
|
||||||
PhysicalDevice::~PhysicalDevice() = default;
|
PhysicalDevice::~PhysicalDevice() = default;
|
||||||
|
|
||||||
|
|
|
@ -26,9 +26,7 @@ class Backend;
|
||||||
|
|
||||||
class PhysicalDevice : public d3d::PhysicalDevice {
|
class PhysicalDevice : public d3d::PhysicalDevice {
|
||||||
public:
|
public:
|
||||||
PhysicalDevice(Backend* backend,
|
PhysicalDevice(Backend* backend, ComPtr<IDXGIAdapter3> hardwareAdapter);
|
||||||
ComPtr<IDXGIAdapter3> hardwareAdapter,
|
|
||||||
const TogglesState& adapterToggles);
|
|
||||||
~PhysicalDevice() override;
|
~PhysicalDevice() override;
|
||||||
|
|
||||||
// PhysicalDeviceBase Implementation
|
// PhysicalDeviceBase Implementation
|
||||||
|
|
|
@ -64,12 +64,11 @@ const PlatformFunctions* Backend::GetFunctions() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<Ref<PhysicalDeviceBase>> Backend::CreatePhysicalDeviceFromIDXGIAdapter(
|
ResultOrError<Ref<PhysicalDeviceBase>> Backend::CreatePhysicalDeviceFromIDXGIAdapter(
|
||||||
ComPtr<IDXGIAdapter> dxgiAdapter,
|
ComPtr<IDXGIAdapter> dxgiAdapter) {
|
||||||
const TogglesState& adapterToggles) {
|
|
||||||
ComPtr<IDXGIAdapter3> dxgiAdapter3;
|
ComPtr<IDXGIAdapter3> dxgiAdapter3;
|
||||||
DAWN_TRY(CheckHRESULT(dxgiAdapter.As(&dxgiAdapter3), "DXGIAdapter retrieval"));
|
DAWN_TRY(CheckHRESULT(dxgiAdapter.As(&dxgiAdapter3), "DXGIAdapter retrieval"));
|
||||||
Ref<PhysicalDevice> physicalDevice =
|
Ref<PhysicalDevice> physicalDevice =
|
||||||
AcquireRef(new PhysicalDevice(this, std::move(dxgiAdapter3), adapterToggles));
|
AcquireRef(new PhysicalDevice(this, std::move(dxgiAdapter3)));
|
||||||
DAWN_TRY(physicalDevice->Initialize());
|
DAWN_TRY(physicalDevice->Initialize());
|
||||||
|
|
||||||
return {std::move(physicalDevice)};
|
return {std::move(physicalDevice)};
|
||||||
|
|
|
@ -36,8 +36,7 @@ class Backend final : public d3d::Backend {
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
ResultOrError<Ref<PhysicalDeviceBase>> CreatePhysicalDeviceFromIDXGIAdapter(
|
ResultOrError<Ref<PhysicalDeviceBase>> CreatePhysicalDeviceFromIDXGIAdapter(
|
||||||
ComPtr<IDXGIAdapter> dxgiAdapter,
|
ComPtr<IDXGIAdapter> dxgiAdapter) override;
|
||||||
const TogglesState& adapterToggles) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
using Base = d3d::Backend;
|
using Base = d3d::Backend;
|
||||||
|
|
|
@ -29,10 +29,8 @@
|
||||||
|
|
||||||
namespace dawn::native::d3d12 {
|
namespace dawn::native::d3d12 {
|
||||||
|
|
||||||
PhysicalDevice::PhysicalDevice(Backend* backend,
|
PhysicalDevice::PhysicalDevice(Backend* backend, ComPtr<IDXGIAdapter3> hardwareAdapter)
|
||||||
ComPtr<IDXGIAdapter3> hardwareAdapter,
|
: Base(backend, std::move(hardwareAdapter), wgpu::BackendType::D3D12) {}
|
||||||
const TogglesState& adapterToggles)
|
|
||||||
: Base(backend, std::move(hardwareAdapter), wgpu::BackendType::D3D12, adapterToggles) {}
|
|
||||||
|
|
||||||
PhysicalDevice::~PhysicalDevice() {
|
PhysicalDevice::~PhysicalDevice() {
|
||||||
CleanUpDebugLayerFilters();
|
CleanUpDebugLayerFilters();
|
||||||
|
|
|
@ -27,9 +27,7 @@ class Backend;
|
||||||
|
|
||||||
class PhysicalDevice : public d3d::PhysicalDevice {
|
class PhysicalDevice : public d3d::PhysicalDevice {
|
||||||
public:
|
public:
|
||||||
PhysicalDevice(Backend* backend,
|
PhysicalDevice(Backend* backend, ComPtr<IDXGIAdapter3> hardwareAdapter);
|
||||||
ComPtr<IDXGIAdapter3> hardwareAdapter,
|
|
||||||
const TogglesState& adapterToggles);
|
|
||||||
~PhysicalDevice() override;
|
~PhysicalDevice() override;
|
||||||
|
|
||||||
// PhysicalDeviceBase Implementation
|
// PhysicalDeviceBase Implementation
|
||||||
|
|
|
@ -26,11 +26,9 @@ class Backend : public BackendConnection {
|
||||||
explicit Backend(InstanceBase* instance);
|
explicit Backend(InstanceBase* instance);
|
||||||
~Backend() override;
|
~Backend() override;
|
||||||
|
|
||||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters(
|
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
|
||||||
const TogglesState& adapterToggles) override;
|
|
||||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
||||||
const AdapterDiscoveryOptionsBase* optionsBase,
|
const AdapterDiscoveryOptionsBase* optionsBase) override;
|
||||||
const TogglesState& adapterToggles) override;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace dawn::native::metal
|
} // namespace dawn::native::metal
|
||||||
|
|
|
@ -255,11 +255,8 @@ DAWN_NOINLINE bool IsGPUCounterSupported(id<MTLDevice> device,
|
||||||
|
|
||||||
class PhysicalDevice : public PhysicalDeviceBase {
|
class PhysicalDevice : public PhysicalDeviceBase {
|
||||||
public:
|
public:
|
||||||
PhysicalDevice(InstanceBase* instance,
|
PhysicalDevice(InstanceBase* instance, id<MTLDevice> device)
|
||||||
id<MTLDevice> device,
|
: PhysicalDeviceBase(instance, wgpu::BackendType::Metal), mDevice(device) {
|
||||||
const TogglesState& requiredAdapterToggle)
|
|
||||||
: PhysicalDeviceBase(instance, wgpu::BackendType::Metal, requiredAdapterToggle),
|
|
||||||
mDevice(device) {
|
|
||||||
mName = std::string([[*mDevice name] UTF8String]);
|
mName = std::string([[*mDevice name] UTF8String]);
|
||||||
|
|
||||||
PCIIDs ids;
|
PCIIDs ids;
|
||||||
|
@ -811,10 +808,9 @@ Backend::Backend(InstanceBase* instance) : BackendConnection(instance, wgpu::Bac
|
||||||
|
|
||||||
Backend::~Backend() = default;
|
Backend::~Backend() = default;
|
||||||
|
|
||||||
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
|
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
|
||||||
const TogglesState& adapterToggles) {
|
|
||||||
AdapterDiscoveryOptions options;
|
AdapterDiscoveryOptions options;
|
||||||
auto result = DiscoverAdapters(&options, adapterToggles);
|
auto result = DiscoverAdapters(&options);
|
||||||
if (result.IsError()) {
|
if (result.IsError()) {
|
||||||
GetInstance()->ConsumedError(result.AcquireError());
|
GetInstance()->ConsumedError(result.AcquireError());
|
||||||
return {};
|
return {};
|
||||||
|
@ -823,8 +819,7 @@ std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
||||||
const AdapterDiscoveryOptionsBase* optionsBase,
|
const AdapterDiscoveryOptionsBase* optionsBase) {
|
||||||
const TogglesState& adapterToggles) {
|
|
||||||
ASSERT(optionsBase->backendType == WGPUBackendType_Metal);
|
ASSERT(optionsBase->backendType == WGPUBackendType_Metal);
|
||||||
|
|
||||||
std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
|
std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
|
||||||
|
@ -832,8 +827,7 @@ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
||||||
NSRef<NSArray<id<MTLDevice>>> devices = AcquireNSRef(MTLCopyAllDevices());
|
NSRef<NSArray<id<MTLDevice>>> devices = AcquireNSRef(MTLCopyAllDevices());
|
||||||
|
|
||||||
for (id<MTLDevice> device in devices.Get()) {
|
for (id<MTLDevice> device in devices.Get()) {
|
||||||
Ref<PhysicalDevice> physicalDevice =
|
Ref<PhysicalDevice> physicalDevice = AcquireRef(new PhysicalDevice(GetInstance(), device));
|
||||||
AcquireRef(new PhysicalDevice(GetInstance(), device, adapterToggles));
|
|
||||||
if (!GetInstance()->ConsumedError(physicalDevice->Initialize())) {
|
if (!GetInstance()->ConsumedError(physicalDevice->Initialize())) {
|
||||||
physicalDevices.push_back(std::move(physicalDevice));
|
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.
|
// iOS only has a single device so MTLCopyAllDevices doesn't exist there.
|
||||||
#if defined(DAWN_PLATFORM_IOS)
|
#if defined(DAWN_PLATFORM_IOS)
|
||||||
Ref<PhysicalDevice> physicalDevice = AcquireRef(
|
Ref<PhysicalDevice> physicalDevice =
|
||||||
new PhysicalDevice(GetInstance(), MTLCreateSystemDefaultDevice(), adapterToggles));
|
AcquireRef(new PhysicalDevice(GetInstance(), MTLCreateSystemDefaultDevice()));
|
||||||
if (!GetInstance()->ConsumedError(physicalDevice->Initialize())) {
|
if (!GetInstance()->ConsumedError(physicalDevice->Initialize())) {
|
||||||
physicalDevices.push_back(std::move(physicalDevice));
|
physicalDevices.push_back(std::move(physicalDevice));
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,11 +32,7 @@ namespace dawn::native::null {
|
||||||
// Connect()
|
// Connect()
|
||||||
|
|
||||||
PhysicalDevice::PhysicalDevice(InstanceBase* instance)
|
PhysicalDevice::PhysicalDevice(InstanceBase* instance)
|
||||||
: PhysicalDevice(instance,
|
: PhysicalDeviceBase(instance, wgpu::BackendType::Null) {
|
||||||
TogglesState(ToggleStage::Adapter).InheritFrom(instance->GetTogglesState())) {}
|
|
||||||
|
|
||||||
PhysicalDevice::PhysicalDevice(InstanceBase* instance, const TogglesState& adapterToggles)
|
|
||||||
: PhysicalDeviceBase(instance, wgpu::BackendType::Null, adapterToggles) {
|
|
||||||
mVendorId = 0;
|
mVendorId = 0;
|
||||||
mDeviceId = 0;
|
mDeviceId = 0;
|
||||||
mName = "Null backend";
|
mName = "Null backend";
|
||||||
|
@ -90,13 +86,11 @@ class Backend : public BackendConnection {
|
||||||
explicit Backend(InstanceBase* instance)
|
explicit Backend(InstanceBase* instance)
|
||||||
: BackendConnection(instance, wgpu::BackendType::Null) {}
|
: BackendConnection(instance, wgpu::BackendType::Null) {}
|
||||||
|
|
||||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters(
|
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override {
|
||||||
const TogglesState& adapterToggles) override {
|
|
||||||
// There is always a single Null adapter because it is purely CPU based and doesn't
|
// There is always a single Null adapter because it is purely CPU based and doesn't
|
||||||
// depend on the system.
|
// depend on the system.
|
||||||
std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
|
std::vector<Ref<PhysicalDeviceBase>> physicalDevices;
|
||||||
Ref<PhysicalDevice> physicalDevice =
|
Ref<PhysicalDevice> physicalDevice = AcquireRef(new PhysicalDevice(GetInstance()));
|
||||||
AcquireRef(new PhysicalDevice(GetInstance(), adapterToggles));
|
|
||||||
physicalDevices.push_back(std::move(physicalDevice));
|
physicalDevices.push_back(std::move(physicalDevice));
|
||||||
return physicalDevices;
|
return physicalDevices;
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,7 +175,6 @@ class PhysicalDevice : public PhysicalDeviceBase {
|
||||||
// Create null adapter without providing toggles state for testing, only inherit instance's
|
// Create null adapter without providing toggles state for testing, only inherit instance's
|
||||||
// toggles state
|
// toggles state
|
||||||
explicit PhysicalDevice(InstanceBase* instance);
|
explicit PhysicalDevice(InstanceBase* instance);
|
||||||
PhysicalDevice(InstanceBase* instance, const TogglesState& adapterToggles);
|
|
||||||
~PhysicalDevice() override;
|
~PhysicalDevice() override;
|
||||||
|
|
||||||
// PhysicalDeviceBase Implementation
|
// PhysicalDeviceBase Implementation
|
||||||
|
|
|
@ -33,8 +33,7 @@ namespace dawn::native::opengl {
|
||||||
Backend::Backend(InstanceBase* instance, wgpu::BackendType backendType)
|
Backend::Backend(InstanceBase* instance, wgpu::BackendType backendType)
|
||||||
: BackendConnection(instance, backendType) {}
|
: BackendConnection(instance, backendType) {}
|
||||||
|
|
||||||
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
|
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
|
||||||
const TogglesState& adapterToggles) {
|
|
||||||
std::vector<Ref<PhysicalDeviceBase>> adapters;
|
std::vector<Ref<PhysicalDeviceBase>> adapters;
|
||||||
#if DAWN_PLATFORM_IS(WINDOWS)
|
#if DAWN_PLATFORM_IS(WINDOWS)
|
||||||
const char* eglLib = "libEGL.dll";
|
const char* eglLib = "libEGL.dll";
|
||||||
|
@ -70,7 +69,7 @@ std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
|
||||||
|
|
||||||
context->MakeCurrent();
|
context->MakeCurrent();
|
||||||
|
|
||||||
auto result = DiscoverAdapters(&options, adapterToggles);
|
auto result = DiscoverAdapters(&options);
|
||||||
|
|
||||||
if (result.IsError()) {
|
if (result.IsError()) {
|
||||||
GetInstance()->ConsumedError(result.AcquireError());
|
GetInstance()->ConsumedError(result.AcquireError());
|
||||||
|
@ -85,8 +84,7 @@ std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
||||||
const AdapterDiscoveryOptionsBase* optionsBase,
|
const AdapterDiscoveryOptionsBase* optionsBase) {
|
||||||
const TogglesState& adapterToggles) {
|
|
||||||
// TODO(cwallez@chromium.org): For now only create a single OpenGL adapter because don't
|
// TODO(cwallez@chromium.org): For now only create a single OpenGL adapter because don't
|
||||||
// know how to handle MakeCurrent.
|
// know how to handle MakeCurrent.
|
||||||
DAWN_INVALID_IF(mCreatedAdapter, "The OpenGL backend can only create a single adapter.");
|
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");
|
DAWN_INVALID_IF(options->getProc == nullptr, "AdapterDiscoveryOptions::getProc must be set");
|
||||||
|
|
||||||
Ref<PhysicalDevice> adapter = AcquireRef(new PhysicalDevice(
|
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->InitializeGLFunctions(options->getProc));
|
||||||
DAWN_TRY(adapter->Initialize());
|
DAWN_TRY(adapter->Initialize());
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,9 @@ class Backend : public BackendConnection {
|
||||||
public:
|
public:
|
||||||
Backend(InstanceBase* instance, wgpu::BackendType backendType);
|
Backend(InstanceBase* instance, wgpu::BackendType backendType);
|
||||||
|
|
||||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters(
|
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
|
||||||
const TogglesState& adapterToggles) override;
|
|
||||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
||||||
const AdapterDiscoveryOptionsBase* option,
|
const AdapterDiscoveryOptionsBase* option) override;
|
||||||
const TogglesState& adapterToggless) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool mCreatedAdapter = false;
|
bool mCreatedAdapter = false;
|
||||||
|
|
|
@ -53,10 +53,8 @@ uint32_t GetVendorIdFromVendors(const char* vendor) {
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
PhysicalDevice::PhysicalDevice(InstanceBase* instance,
|
PhysicalDevice::PhysicalDevice(InstanceBase* instance, wgpu::BackendType backendType)
|
||||||
wgpu::BackendType backendType,
|
: PhysicalDeviceBase(instance, backendType) {}
|
||||||
const TogglesState& adapterToggle)
|
|
||||||
: PhysicalDeviceBase(instance, backendType, adapterToggle) {}
|
|
||||||
|
|
||||||
MaybeError PhysicalDevice::InitializeGLFunctions(void* (*getProc)(const char*)) {
|
MaybeError PhysicalDevice::InitializeGLFunctions(void* (*getProc)(const char*)) {
|
||||||
// Use getProc to populate the dispatch table
|
// Use getProc to populate the dispatch table
|
||||||
|
|
|
@ -23,9 +23,7 @@ namespace dawn::native::opengl {
|
||||||
|
|
||||||
class PhysicalDevice : public PhysicalDeviceBase {
|
class PhysicalDevice : public PhysicalDeviceBase {
|
||||||
public:
|
public:
|
||||||
PhysicalDevice(InstanceBase* instance,
|
PhysicalDevice(InstanceBase* instance, wgpu::BackendType backendType);
|
||||||
wgpu::BackendType backendType,
|
|
||||||
const TogglesState& adapterToggle);
|
|
||||||
|
|
||||||
MaybeError InitializeGLFunctions(void* (*getProc)(const char*));
|
MaybeError InitializeGLFunctions(void* (*getProc)(const char*));
|
||||||
|
|
||||||
|
|
|
@ -457,10 +457,9 @@ Backend::Backend(InstanceBase* instance) : BackendConnection(instance, wgpu::Bac
|
||||||
|
|
||||||
Backend::~Backend() = default;
|
Backend::~Backend() = default;
|
||||||
|
|
||||||
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
|
std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters() {
|
||||||
const TogglesState& adapterToggles) {
|
|
||||||
AdapterDiscoveryOptions options;
|
AdapterDiscoveryOptions options;
|
||||||
auto result = DiscoverAdapters(&options, adapterToggles);
|
auto result = DiscoverAdapters(&options);
|
||||||
if (result.IsError()) {
|
if (result.IsError()) {
|
||||||
GetInstance()->ConsumedError(result.AcquireError());
|
GetInstance()->ConsumedError(result.AcquireError());
|
||||||
return {};
|
return {};
|
||||||
|
@ -469,8 +468,7 @@ std::vector<Ref<PhysicalDeviceBase>> Backend::DiscoverDefaultAdapters(
|
||||||
}
|
}
|
||||||
|
|
||||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
||||||
const AdapterDiscoveryOptionsBase* optionsBase,
|
const AdapterDiscoveryOptionsBase* optionsBase) {
|
||||||
const TogglesState& adapterToggles) {
|
|
||||||
ASSERT(optionsBase->backendType == WGPUBackendType_Vulkan);
|
ASSERT(optionsBase->backendType == WGPUBackendType_Vulkan);
|
||||||
|
|
||||||
const AdapterDiscoveryOptions* options =
|
const AdapterDiscoveryOptions* options =
|
||||||
|
@ -499,8 +497,8 @@ ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> Backend::DiscoverAdapters(
|
||||||
const std::vector<VkPhysicalDevice>& vkPhysicalDevices =
|
const std::vector<VkPhysicalDevice>& vkPhysicalDevices =
|
||||||
mVulkanInstances[icd]->GetVkPhysicalDevices();
|
mVulkanInstances[icd]->GetVkPhysicalDevices();
|
||||||
for (uint32_t i = 0; i < vkPhysicalDevices.size(); ++i) {
|
for (uint32_t i = 0; i < vkPhysicalDevices.size(); ++i) {
|
||||||
Ref<PhysicalDevice> physicalDevice = AcquireRef(new PhysicalDevice(
|
Ref<PhysicalDevice> physicalDevice = AcquireRef(
|
||||||
instance, mVulkanInstances[icd].Get(), vkPhysicalDevices[i], adapterToggles));
|
new PhysicalDevice(instance, mVulkanInstances[icd].Get(), vkPhysicalDevices[i]));
|
||||||
if (instance->ConsumedError(physicalDevice->Initialize())) {
|
if (instance->ConsumedError(physicalDevice->Initialize())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -91,11 +91,9 @@ class Backend : public BackendConnection {
|
||||||
|
|
||||||
MaybeError Initialize();
|
MaybeError Initialize();
|
||||||
|
|
||||||
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters(
|
std::vector<Ref<PhysicalDeviceBase>> DiscoverDefaultAdapters() override;
|
||||||
const TogglesState& adapterToggles) override;
|
|
||||||
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
ResultOrError<std::vector<Ref<PhysicalDeviceBase>>> DiscoverAdapters(
|
||||||
const AdapterDiscoveryOptionsBase* optionsBase,
|
const AdapterDiscoveryOptionsBase* optionsBase) override;
|
||||||
const TogglesState& adapterToggles) override;
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ityp::array<ICD, Ref<VulkanInstance>, 2> mVulkanInstances = {};
|
ityp::array<ICD, Ref<VulkanInstance>, 2> mVulkanInstances = {};
|
||||||
|
|
|
@ -58,9 +58,8 @@ gpu_info::DriverVersion DecodeVulkanDriverVersion(uint32_t vendorID, uint32_t ve
|
||||||
|
|
||||||
PhysicalDevice::PhysicalDevice(InstanceBase* instance,
|
PhysicalDevice::PhysicalDevice(InstanceBase* instance,
|
||||||
VulkanInstance* vulkanInstance,
|
VulkanInstance* vulkanInstance,
|
||||||
VkPhysicalDevice physicalDevice,
|
VkPhysicalDevice physicalDevice)
|
||||||
const TogglesState& adapterToggles)
|
: PhysicalDeviceBase(instance, wgpu::BackendType::Vulkan),
|
||||||
: PhysicalDeviceBase(instance, wgpu::BackendType::Vulkan, adapterToggles),
|
|
||||||
mVkPhysicalDevice(physicalDevice),
|
mVkPhysicalDevice(physicalDevice),
|
||||||
mVulkanInstance(vulkanInstance) {}
|
mVulkanInstance(vulkanInstance) {}
|
||||||
|
|
||||||
|
|
|
@ -29,8 +29,7 @@ class PhysicalDevice : public PhysicalDeviceBase {
|
||||||
public:
|
public:
|
||||||
PhysicalDevice(InstanceBase* instance,
|
PhysicalDevice(InstanceBase* instance,
|
||||||
VulkanInstance* vulkanInstance,
|
VulkanInstance* vulkanInstance,
|
||||||
VkPhysicalDevice physicalDevice,
|
VkPhysicalDevice physicalDevice);
|
||||||
const TogglesState& adapterToggles);
|
|
||||||
~PhysicalDevice() override;
|
~PhysicalDevice() override;
|
||||||
|
|
||||||
// PhysicalDeviceBase Implementation
|
// PhysicalDeviceBase Implementation
|
||||||
|
|
|
@ -25,10 +25,12 @@
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
std::unique_ptr<dawn::native::Instance> nativeInstance = nullptr;
|
std::unique_ptr<dawn::native::Instance> nativeInstance = nullptr;
|
||||||
WGPUAdapter nullBackendAdapter = nullptr;
|
wgpu::Adapter nullBackendAdapter = nullptr;
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
void SetupNullBackend(const benchmark::State& state) {
|
void SetupNullBackend(const benchmark::State& state) {
|
||||||
|
dawnProcSetProcs(&dawn::native::GetProcs());
|
||||||
|
|
||||||
if (!nativeInstance) {
|
if (!nativeInstance) {
|
||||||
nativeInstance = std::make_unique<dawn::native::Instance>();
|
nativeInstance = std::make_unique<dawn::native::Instance>();
|
||||||
nativeInstance->DiscoverDefaultAdapters();
|
nativeInstance->DiscoverDefaultAdapters();
|
||||||
|
@ -39,7 +41,7 @@ void SetupNullBackend(const benchmark::State& state) {
|
||||||
wgpu::AdapterProperties properties;
|
wgpu::AdapterProperties properties;
|
||||||
a.GetProperties(&properties);
|
a.GetProperties(&properties);
|
||||||
if (properties.backendType == wgpu::BackendType::Null) {
|
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) {
|
wgpu::Device CreateNullDevice(const wgpu::DeviceDescriptor& desc) {
|
||||||
dawnProcSetProcs(&dawn::native::GetProcs());
|
|
||||||
|
|
||||||
wgpu::Device device;
|
wgpu::Device device;
|
||||||
|
|
||||||
wgpu::Adapter(nullBackendAdapter)
|
nullBackendAdapter.RequestDevice(
|
||||||
.RequestDevice(
|
&desc,
|
||||||
&desc,
|
[](WGPURequestDeviceStatus status, WGPUDevice cDevice, char const* message,
|
||||||
[](WGPURequestDeviceStatus status, WGPUDevice cDevice, char const* message,
|
void* userdata) {
|
||||||
void* userdata) {
|
ASSERT(status == WGPURequestDeviceStatus_Success);
|
||||||
ASSERT(status == WGPURequestDeviceStatus_Success);
|
*reinterpret_cast<wgpu::Device*>(userdata) = wgpu::Device::Acquire(cDevice);
|
||||||
*reinterpret_cast<wgpu::Device*>(userdata) = wgpu::Device::Acquire(cDevice);
|
},
|
||||||
},
|
&device);
|
||||||
&device);
|
|
||||||
while (!device) {
|
while (!device) {
|
||||||
wgpuInstanceProcessEvents(nativeInstance->Get());
|
wgpuInstanceProcessEvents(nativeInstance->Get());
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,13 +263,11 @@ class AdapterCreationTest : public ::testing::Test {
|
||||||
if (properties.compatibilityMode) {
|
if (properties.compatibilityMode) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
swiftShaderAvailable =
|
swiftShaderAvailable |=
|
||||||
swiftShaderAvailable ||
|
|
||||||
gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID);
|
gpu_info::IsGoogleSwiftshader(properties.vendorID, properties.deviceID);
|
||||||
discreteGPUAvailable = discreteGPUAvailable ||
|
discreteGPUAvailable |= properties.adapterType == wgpu::AdapterType::DiscreteGPU;
|
||||||
properties.adapterType == wgpu::AdapterType::DiscreteGPU;
|
integratedGPUAvailable |=
|
||||||
integratedGPUAvailable = integratedGPUAvailable ||
|
properties.adapterType == wgpu::AdapterType::IntegratedGPU;
|
||||||
properties.adapterType == wgpu::AdapterType::IntegratedGPU;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -322,7 +320,7 @@ TEST_F(AdapterCreationTest, NullGivesDefaultAdapter) {
|
||||||
instance.RequestAdapter(nullptr, cb.Callback(), cb.MakeUserdata(this + 1));
|
instance.RequestAdapter(nullptr, cb.Callback(), cb.MakeUserdata(this + 1));
|
||||||
|
|
||||||
wgpu::Adapter adapter2 = wgpu::Adapter::Acquire(cAdapter);
|
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.
|
// Test that requesting the fallback adapter returns SwiftShader.
|
||||||
|
|
|
@ -26,18 +26,19 @@ class FeatureTests : public testing::Test {
|
||||||
: testing::Test(),
|
: testing::Test(),
|
||||||
mInstanceBase(dawn::native::InstanceBase::Create()),
|
mInstanceBase(dawn::native::InstanceBase::Create()),
|
||||||
mPhysicalDevice(mInstanceBase.Get()),
|
mPhysicalDevice(mInstanceBase.Get()),
|
||||||
mUnsafePhysicalDeviceDisallow(
|
mUnsafePhysicalDeviceDisallow(mInstanceBase.Get()),
|
||||||
mInstanceBase.Get(),
|
mUnsafePhysicalDevice(mInstanceBase.Get()),
|
||||||
|
mAdapterBase(&mPhysicalDevice, dawn::native::FeatureLevel::Core),
|
||||||
|
mUnsafeAdapterBaseDisallow(
|
||||||
|
&mUnsafePhysicalDeviceDisallow,
|
||||||
|
dawn::native::FeatureLevel::Core,
|
||||||
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)),
|
||||||
mUnsafePhysicalDevice(
|
mUnsafeAdapterBase(
|
||||||
mInstanceBase.Get(),
|
&mUnsafePhysicalDevice,
|
||||||
|
dawn::native::FeatureLevel::Core,
|
||||||
dawn::native::TogglesState(dawn::native::ToggleStage::Adapter)
|
dawn::native::TogglesState(dawn::native::ToggleStage::Adapter)
|
||||||
.SetForTesting(dawn::native::Toggle::AllowUnsafeAPIs, true, true)),
|
.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) {}
|
|
||||||
|
|
||||||
std::vector<wgpu::FeatureName> GetAllFeatureNames() {
|
std::vector<wgpu::FeatureName> GetAllFeatureNames() {
|
||||||
std::vector<wgpu::FeatureName> allFeatureNames(kTotalFeaturesCount);
|
std::vector<wgpu::FeatureName> allFeatureNames(kTotalFeaturesCount);
|
||||||
|
@ -149,7 +150,7 @@ TEST_F(FeatureTests, RequireAndGetEnabledFeatures) {
|
||||||
// AllowUnsafeAPIs or disables DisallowUnsafeApis, otherwise expect validation error.
|
// AllowUnsafeAPIs or disables DisallowUnsafeApis, otherwise expect validation error.
|
||||||
if (featuresInfo.GetFeatureInfo(featureName)->featureState ==
|
if (featuresInfo.GetFeatureInfo(featureName)->featureState ==
|
||||||
dawn::native::FeatureInfo::FeatureState::Experimental) {
|
dawn::native::FeatureInfo::FeatureState::Experimental) {
|
||||||
ASSERT_EQ(nullptr, deviceBase);
|
ASSERT_EQ(nullptr, deviceBase) << i;
|
||||||
} else {
|
} else {
|
||||||
// Requiring stable features should succeed.
|
// Requiring stable features should succeed.
|
||||||
ASSERT_NE(nullptr, deviceBase);
|
ASSERT_NE(nullptr, deviceBase);
|
||||||
|
|
|
@ -173,10 +173,10 @@ TEST_F(InstanceToggleTest, InstanceTogglesInheritToAdapterAndDevice) {
|
||||||
instance->DiscoverDefaultAdapters();
|
instance->DiscoverDefaultAdapters();
|
||||||
|
|
||||||
// Get the adapter created by instance with default toggles.
|
// Get the adapter created by instance with default toggles.
|
||||||
dawn::native::AdapterBase* nullAdapter = nullptr;
|
Ref<dawn::native::AdapterBase> nullAdapter;
|
||||||
for (auto& adapter : instance->GetAdapters()) {
|
for (auto& adapter : instance->GetAdapters()) {
|
||||||
if (adapter->GetPhysicalDevice()->GetBackendType() == wgpu::BackendType::Null) {
|
if (adapter->GetPhysicalDevice()->GetBackendType() == wgpu::BackendType::Null) {
|
||||||
nullAdapter = adapter.Get();
|
nullAdapter = adapter;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -260,6 +260,8 @@ TEST_F(DeviceCreationTest, CreateDeviceRequiringExperimentalFeatures) {
|
||||||
|
|
||||||
// Test creating device on the adapter with AllowUnsafeApis toggle enabled would succeed.
|
// Test creating device on the adapter with AllowUnsafeApis toggle enabled would succeed.
|
||||||
{
|
{
|
||||||
|
deviceDescriptor.nextInChain = nullptr;
|
||||||
|
|
||||||
wgpu::Device device = unsafeAdapter.CreateDevice(&deviceDescriptor);
|
wgpu::Device device = unsafeAdapter.CreateDevice(&deviceDescriptor);
|
||||||
EXPECT_NE(device, nullptr);
|
EXPECT_NE(device, nullptr);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue