Add Adapter::GetDeviceType() (integrate vs. discrete vs. CPU)

BUG=chromium:852089
Change-Id: Ia447448392e09c5d604ae038b4758776ed3e66ee
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/5180
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Corentin Wallez 2019-04-15 16:36:25 +00:00 committed by Commit Bot service account
parent bff933affc
commit 2ec74dcc3f
9 changed files with 65 additions and 1 deletions

View File

@ -26,6 +26,10 @@ namespace dawn_native {
return mBackend;
}
DeviceType AdapterBase::GetDeviceType() const {
return mDeviceType;
}
const PCIInfo& AdapterBase::GetPCIInfo() const {
return mPCIInfo;
}

View File

@ -29,6 +29,7 @@ namespace dawn_native {
virtual ~AdapterBase() = default;
BackendType GetBackendType() const;
DeviceType GetDeviceType() const;
const PCIInfo& GetPCIInfo() const;
InstanceBase* GetInstance() const;
@ -36,6 +37,7 @@ namespace dawn_native {
protected:
PCIInfo mPCIInfo = {};
DeviceType mDeviceType = DeviceType::Unknown;
private:
virtual ResultOrError<DeviceBase*> CreateDeviceImpl() = 0;

View File

@ -41,6 +41,10 @@ namespace dawn_native {
return mImpl->GetBackendType();
}
DeviceType Adapter::GetDeviceType() const {
return mImpl->GetDeviceType();
}
const PCIInfo& Adapter::GetPCIInfo() const {
return mImpl->GetPCIInfo();
}

View File

@ -43,6 +43,13 @@ namespace dawn_native { namespace d3d12 {
mPCIInfo.deviceId = adapterDesc.DeviceId;
mPCIInfo.vendorId = adapterDesc.VendorId;
if (adapterDesc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE) {
mDeviceType = DeviceType::CPU;
} else {
// TODO(cwallez@chromium.org): properly detect integrated vs. discrete.
mDeviceType = DeviceType::DiscreteGPU;
}
std::wstring_convert<DeletableFacet<std::codecvt<wchar_t, char, std::mbstate_t>>> converter(
"Error converting");
mPCIInfo.name = converter.to_bytes(adapterDesc.Description);

View File

@ -129,6 +129,12 @@ namespace dawn_native { namespace metal {
mPCIInfo.deviceId = GetEntryProperty(entry, CFSTR("device-id"));
IOObjectRelease(entry);
}
if ([device isLowPower]) {
mDeviceType = DeviceType::IntegratedGPU;
} else {
mDeviceType = DeviceType::DiscreteGPU;
}
}
~Adapter() override {

View File

@ -28,6 +28,7 @@ namespace dawn_native { namespace null {
public:
Adapter(InstanceBase* instance) : AdapterBase(instance, BackendType::Null) {
mPCIInfo.name = "Null backend";
mDeviceType = DeviceType::CPU;
}
virtual ~Adapter() = default;

View File

@ -44,6 +44,21 @@ namespace dawn_native { namespace vulkan {
mPCIInfo.vendorId = mDeviceInfo.properties.vendorID;
mPCIInfo.name = mDeviceInfo.properties.deviceName;
switch (mDeviceInfo.properties.deviceType) {
case VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU:
mDeviceType = DeviceType::IntegratedGPU;
break;
case VK_PHYSICAL_DEVICE_TYPE_DISCRETE_GPU:
mDeviceType = DeviceType::DiscreteGPU;
break;
case VK_PHYSICAL_DEVICE_TYPE_CPU:
mDeviceType = DeviceType::CPU;
break;
default:
mDeviceType = DeviceType::Unknown;
break;
}
return {};
}

View File

@ -37,6 +37,13 @@ namespace dawn_native {
Vulkan,
};
enum class DeviceType {
DiscreteGPU,
IntegratedGPU,
CPU,
Unknown,
};
class InstanceBase;
class AdapterBase;
@ -53,6 +60,7 @@ namespace dawn_native {
~Adapter();
BackendType GetBackendType() const;
DeviceType GetDeviceType() const;
const PCIInfo& GetPCIInfo() const;
explicit operator bool() const;

View File

@ -52,6 +52,21 @@ namespace {
}
}
const char* DeviceTypeName(dawn_native::DeviceType type) {
switch (type) {
case dawn_native::DeviceType::DiscreteGPU:
return "Discrete GPU";
case dawn_native::DeviceType::IntegratedGPU:
return "Integrated GPU";
case dawn_native::DeviceType::CPU:
return "CPU";
case dawn_native::DeviceType::Unknown:
return "Unknown";
default:
UNREACHABLE();
}
}
struct MapReadUserdata {
DawnTest* test;
size_t slot;
@ -130,7 +145,9 @@ void DawnTestEnvironment::SetUp() {
deviceId << std::setfill('0') << std::uppercase << std::internal << std::hex << std::setw(4)
<< pci.deviceId;
std::cout << " - \"" << pci.name << "\" on " << ParamName(adapter.GetBackendType()) << "\n";
std::cout << " - \"" << pci.name << "\"\n";
std::cout << " type: " << DeviceTypeName(adapter.GetDeviceType())
<< ", backend: " << ParamName(adapter.GetBackendType()) << "\n";
std::cout << " vendorId: 0x" << vendorId.str() << ", deviceId: 0x" << deviceId.str()
<< "\n";
}