Add adapter filter flag by vendor id for end2end tests

Now end2end tests always run with first adapter (the last adapter for
Metal because of dawn:29) on multi-GPU systems. Add
'--adapter-vendor-id' flag to make it run with specified adapter.

BUG=dawn:181

Change-Id: Iaff3ab92a502f88b24e4aa8a5ed3cb4d1d5925e3
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/8460
Commit-Queue: Hao Li <hao.x.li@intel.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Li, Hao 2019-07-08 03:25:54 +00:00 committed by Commit Bot service account
parent 769edd065b
commit 35716c204d
2 changed files with 56 additions and 10 deletions

View File

@ -114,14 +114,26 @@ DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) {
continue; continue;
} }
if (strstr(argv[i], "--adapter-vendor-id") != 0) {
const char* value = strchr(argv[i], '=');
if (value != nullptr) {
mVendorIdFilter = strtoul(value + 1, nullptr, 16);
// Set filter flag if vendor id is non-zero.
mHasVendorIdFilter = mVendorIdFilter != 0;
}
continue;
}
if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) { if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
std::cout << "\n\nUsage: " << argv[0] std::cout << "\n\nUsage: " << argv[0]
<< " [GTEST_FLAGS...] [-w] [--enable-validation-layers]\n" << " [GTEST_FLAGS...] [-w] [-d] [-c] [--adapter-vendor-id=x]\n"
" -w, --use-wire: Run the tests through the wire (defaults to no wire)\n" " -w, --use-wire: Run the tests through the wire (defaults to no wire)\n"
" -d, --enable-backend-validation: Enable backend validation (defaults" " -d, --enable-backend-validation: Enable backend validation (defaults"
" to disabled)\n" " to disabled)\n"
" -c, --begin-capture-on-startup: Begin debug capture on startup " " -c, --begin-capture-on-startup: Begin debug capture on startup "
"(defaults to no capture)" "(defaults to no capture)\n"
" --adapter-vendor-id: Select adapter by vendor id to run end2end tests"
"on multi-GPU systems \n"
<< std::endl; << std::endl;
continue; continue;
} }
@ -181,6 +193,7 @@ void DawnTestEnvironment::SetUp() {
std::cout << " type: " << DeviceTypeName(adapter.GetDeviceType()) std::cout << " type: " << DeviceTypeName(adapter.GetDeviceType())
<< ", backend: " << ParamName(adapter.GetBackendType()) << "\n"; << ", backend: " << ParamName(adapter.GetBackendType()) << "\n";
std::cout << " vendorId: 0x" << vendorId.str() << ", deviceId: 0x" << deviceId.str() std::cout << " vendorId: 0x" << vendorId.str() << ", deviceId: 0x" << deviceId.str()
<< (mHasVendorIdFilter && mVendorIdFilter == pci.vendorId ? " [Selected]" : "")
<< "\n"; << "\n";
} }
std::cout << std::endl; std::cout << std::endl;
@ -202,6 +215,14 @@ GLFWwindow* DawnTestEnvironment::GetWindowForBackend(dawn_native::BackendType ty
return mWindows.at(type); return mWindows.at(type);
} }
bool DawnTestEnvironment::HasVendorIdFilter() const {
return mHasVendorIdFilter;
}
uint32_t DawnTestEnvironment::GetVendorIdFilter() const {
return mVendorIdFilter;
}
void DawnTestEnvironment::CreateBackendWindow(dawn_native::BackendType type) { void DawnTestEnvironment::CreateBackendWindow(dawn_native::BackendType type) {
glfwDefaultWindowHints(); glfwDefaultWindowHints();
utils::SetupGLFWWindowHintsForBackend(type); utils::SetupGLFWWindowHintsForBackend(type);
@ -304,6 +325,14 @@ bool DawnTest::IsBackendValidationEnabled() const {
return gTestEnv->IsBackendValidationEnabled(); return gTestEnv->IsBackendValidationEnabled();
} }
bool DawnTest::HasVendorIdFilter() const {
return gTestEnv->HasVendorIdFilter();
}
uint32_t DawnTest::GetVendorIdFilter() const {
return gTestEnv->GetVendorIdFilter();
}
void DawnTest::SetUp() { void DawnTest::SetUp() {
// Get an adapter for the backend to use, and create the device. // Get an adapter for the backend to use, and create the device.
dawn_native::Adapter backendAdapter; dawn_native::Adapter backendAdapter;
@ -314,14 +343,24 @@ 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) {
backendAdapter = adapter; // TODO(hao.x.li@intel.com): Filter adapter for OpenGL backend once
// On Metal, select the last adapter so that the discrete GPU is tested on // https://bugs.chromium.org/p/dawn/issues/detail?id=184 is resolved.
// multi-GPU systems. if (HasVendorIdFilter() && backendType != dawn_native::BackendType::OpenGL) {
// TODO(cwallez@chromium.org): Replace this with command line arguments requesting if (adapter.GetPCIInfo().vendorId == GetVendorIdFilter()) {
// a specific device / vendor ID once the macOS 10.13 SDK is rolled and correct backendAdapter = adapter;
// PCI info collection is implemented on Metal. break;
if (backendType != dawn_native::BackendType::Metal) { }
break; } else {
backendAdapter = adapter;
// On Metal, select the last adapter so that the discrete GPU is tested on
// multi-GPU systems.
// TODO(cwallez@chromium.org): Replace this with command line arguments
// requesting a specific device / vendor ID once the macOS 10.13 SDK is rolled
// and correct PCI info collection is implemented on Metal.
if (backendType != dawn_native::BackendType::Metal) {
break;
}
} }
} }
} }

View File

@ -112,6 +112,8 @@ class DawnTestEnvironment : public testing::Environment {
bool IsBackendValidationEnabled() const; bool IsBackendValidationEnabled() const;
dawn_native::Instance* GetInstance() const; dawn_native::Instance* GetInstance() const;
GLFWwindow* GetWindowForBackend(dawn_native::BackendType type) const; GLFWwindow* GetWindowForBackend(dawn_native::BackendType type) const;
bool HasVendorIdFilter() const;
uint32_t GetVendorIdFilter() const;
private: private:
void CreateBackendWindow(dawn_native::BackendType type); void CreateBackendWindow(dawn_native::BackendType type);
@ -119,6 +121,8 @@ class DawnTestEnvironment : public testing::Environment {
bool mUseWire = false; bool mUseWire = false;
bool mEnableBackendValidation = false; bool mEnableBackendValidation = false;
bool mBeginCaptureOnStartup = false; bool mBeginCaptureOnStartup = false;
bool mHasVendorIdFilter = false;
uint32_t mVendorIdFilter = 0;
std::unique_ptr<dawn_native::Instance> mInstance; std::unique_ptr<dawn_native::Instance> mInstance;
// Windows don't usually like to be bound to one API than the other, for example switching // Windows don't usually like to be bound to one API than the other, for example switching
@ -157,6 +161,9 @@ class DawnTest : public ::testing::TestWithParam<DawnTestParam> {
void StartExpectDeviceError(); void StartExpectDeviceError();
bool EndExpectDeviceError(); bool EndExpectDeviceError();
bool HasVendorIdFilter() const;
uint32_t GetVendorIdFilter() const;
protected: protected:
dawn::Device device; dawn::Device device;
dawn::Queue queue; dawn::Queue queue;