OpenGL: use vendor name to get PCI vendor id
OpenGL doesn't allow to query PCI information, but we can get vendor name through glGetString(GL_VENDOR), then match it with vendor id. BUG=dawn:184 Change-Id: Icdcdc6bfdb5cd561b5057e8b2eab06df2dd5cea1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/8940 Reviewed-by: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Austin Eng <enga@chromium.org> Commit-Queue: Hao Li <hao.x.li@intel.com>
This commit is contained in:
parent
5580970f59
commit
1ffb0d6a02
|
@ -14,11 +14,41 @@
|
||||||
|
|
||||||
#include "dawn_native/opengl/BackendGL.h"
|
#include "dawn_native/opengl/BackendGL.h"
|
||||||
|
|
||||||
|
#include "common/Constants.h"
|
||||||
#include "dawn_native/OpenGLBackend.h"
|
#include "dawn_native/OpenGLBackend.h"
|
||||||
#include "dawn_native/opengl/DeviceGL.h"
|
#include "dawn_native/opengl/DeviceGL.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
|
||||||
namespace dawn_native { namespace opengl {
|
namespace dawn_native { namespace opengl {
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
struct Vendor {
|
||||||
|
const char* vendorName;
|
||||||
|
uint32_t vendorId;
|
||||||
|
};
|
||||||
|
|
||||||
|
const Vendor kVendors[] = {{"ATI", kVendorID_AMD},
|
||||||
|
{"ARM", kVendorID_ARM},
|
||||||
|
{"Imagination", kVendorID_ImgTec},
|
||||||
|
{"Intel", kVendorID_Intel},
|
||||||
|
{"NVIDIA", kVendorID_Nvidia},
|
||||||
|
{"Qualcomm", kVendorID_Qualcomm}};
|
||||||
|
|
||||||
|
uint32_t GetVendorIdFromVendors(const char* vendor) {
|
||||||
|
uint32_t vendorId = 0;
|
||||||
|
for (const auto& it : kVendors) {
|
||||||
|
// Matching vendor name with vendor string
|
||||||
|
if (strstr(vendor, it.vendorName) != nullptr) {
|
||||||
|
vendorId = it.vendorId;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vendorId;
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
|
||||||
// The OpenGL backend's Adapter.
|
// The OpenGL backend's Adapter.
|
||||||
|
|
||||||
class Adapter : public AdapterBase {
|
class Adapter : public AdapterBase {
|
||||||
|
@ -38,6 +68,10 @@ namespace dawn_native { namespace opengl {
|
||||||
|
|
||||||
mPCIInfo.name = reinterpret_cast<const char*>(mFunctions.GetString(GL_RENDERER));
|
mPCIInfo.name = reinterpret_cast<const char*>(mFunctions.GetString(GL_RENDERER));
|
||||||
|
|
||||||
|
// Workaroud to find vendor id from vendor name
|
||||||
|
const char* vendor = reinterpret_cast<const char*>(mFunctions.GetString(GL_VENDOR));
|
||||||
|
mPCIInfo.vendorId = GetVendorIdFromVendors(vendor);
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strstr(argv[i], "--adapter-vendor-id") != 0) {
|
if (strstr(argv[i], "--adapter-vendor-id") != nullptr) {
|
||||||
const char* value = strchr(argv[i], '=');
|
const char* value = strchr(argv[i], '=');
|
||||||
if (value != nullptr) {
|
if (value != nullptr) {
|
||||||
mVendorIdFilter = strtoul(value + 1, nullptr, 16);
|
mVendorIdFilter = strtoul(value + 1, nullptr, 16);
|
||||||
|
@ -343,9 +343,7 @@ void DawnTest::SetUp() {
|
||||||
|
|
||||||
for (const dawn_native::Adapter& adapter : adapters) {
|
for (const dawn_native::Adapter& adapter : adapters) {
|
||||||
if (adapter.GetBackendType() == backendType) {
|
if (adapter.GetBackendType() == backendType) {
|
||||||
// TODO(hao.x.li@intel.com): Filter adapter for OpenGL backend once
|
if (HasVendorIdFilter()) {
|
||||||
// https://bugs.chromium.org/p/dawn/issues/detail?id=184 is resolved.
|
|
||||||
if (HasVendorIdFilter() && backendType != dawn_native::BackendType::OpenGL) {
|
|
||||||
if (adapter.GetPCIInfo().vendorId == GetVendorIdFilter()) {
|
if (adapter.GetPCIInfo().vendorId == GetVendorIdFilter()) {
|
||||||
backendAdapter = adapter;
|
backendAdapter = adapter;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue