From 35716c204d2caebe01417bfec3750f5f63000229 Mon Sep 17 00:00:00 2001 From: "Li, Hao" Date: Mon, 8 Jul 2019 03:25:54 +0000 Subject: [PATCH] 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 Reviewed-by: Corentin Wallez --- src/tests/DawnTest.cpp | 59 +++++++++++++++++++++++++++++++++++------- src/tests/DawnTest.h | 7 +++++ 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/tests/DawnTest.cpp b/src/tests/DawnTest.cpp index 71e93411ea..c82b756553 100644 --- a/src/tests/DawnTest.cpp +++ b/src/tests/DawnTest.cpp @@ -114,14 +114,26 @@ DawnTestEnvironment::DawnTestEnvironment(int argc, char** argv) { 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) { 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" " -d, --enable-backend-validation: Enable backend validation (defaults" " to disabled)\n" " -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; continue; } @@ -181,6 +193,7 @@ void DawnTestEnvironment::SetUp() { std::cout << " type: " << DeviceTypeName(adapter.GetDeviceType()) << ", backend: " << ParamName(adapter.GetBackendType()) << "\n"; std::cout << " vendorId: 0x" << vendorId.str() << ", deviceId: 0x" << deviceId.str() + << (mHasVendorIdFilter && mVendorIdFilter == pci.vendorId ? " [Selected]" : "") << "\n"; } std::cout << std::endl; @@ -202,6 +215,14 @@ GLFWwindow* DawnTestEnvironment::GetWindowForBackend(dawn_native::BackendType ty return mWindows.at(type); } +bool DawnTestEnvironment::HasVendorIdFilter() const { + return mHasVendorIdFilter; +} + +uint32_t DawnTestEnvironment::GetVendorIdFilter() const { + return mVendorIdFilter; +} + void DawnTestEnvironment::CreateBackendWindow(dawn_native::BackendType type) { glfwDefaultWindowHints(); utils::SetupGLFWWindowHintsForBackend(type); @@ -304,6 +325,14 @@ bool DawnTest::IsBackendValidationEnabled() const { return gTestEnv->IsBackendValidationEnabled(); } +bool DawnTest::HasVendorIdFilter() const { + return gTestEnv->HasVendorIdFilter(); +} + +uint32_t DawnTest::GetVendorIdFilter() const { + return gTestEnv->GetVendorIdFilter(); +} + void DawnTest::SetUp() { // Get an adapter for the backend to use, and create the device. dawn_native::Adapter backendAdapter; @@ -314,14 +343,24 @@ void DawnTest::SetUp() { for (const dawn_native::Adapter& adapter : adapters) { if (adapter.GetBackendType() == backendType) { - 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; + // TODO(hao.x.li@intel.com): Filter adapter for OpenGL backend once + // https://bugs.chromium.org/p/dawn/issues/detail?id=184 is resolved. + if (HasVendorIdFilter() && backendType != dawn_native::BackendType::OpenGL) { + if (adapter.GetPCIInfo().vendorId == GetVendorIdFilter()) { + backendAdapter = adapter; + 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; + } } } } diff --git a/src/tests/DawnTest.h b/src/tests/DawnTest.h index 2ec8a075eb..a45fb40be1 100644 --- a/src/tests/DawnTest.h +++ b/src/tests/DawnTest.h @@ -112,6 +112,8 @@ class DawnTestEnvironment : public testing::Environment { bool IsBackendValidationEnabled() const; dawn_native::Instance* GetInstance() const; GLFWwindow* GetWindowForBackend(dawn_native::BackendType type) const; + bool HasVendorIdFilter() const; + uint32_t GetVendorIdFilter() const; private: void CreateBackendWindow(dawn_native::BackendType type); @@ -119,6 +121,8 @@ class DawnTestEnvironment : public testing::Environment { bool mUseWire = false; bool mEnableBackendValidation = false; bool mBeginCaptureOnStartup = false; + bool mHasVendorIdFilter = false; + uint32_t mVendorIdFilter = 0; std::unique_ptr mInstance; // 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 { void StartExpectDeviceError(); bool EndExpectDeviceError(); + bool HasVendorIdFilter() const; + uint32_t GetVendorIdFilter() const; + protected: dawn::Device device; dawn::Queue queue;