From c7d535bd72b195c042a125450de158b91f9fc0eb Mon Sep 17 00:00:00 2001 From: "Li, Hao" Date: Wed, 16 Oct 2019 09:24:55 +0000 Subject: [PATCH] Prioritize discrete GPU in end2end tests - Prefer discrete GPU on multi-GPU systems, otherwise get integrated GPU. - Add a test to check adapter filter. BUG=dawn:184 Change-Id: Ib1c3e81e20a15aeaf18746892324ce5144b7fda1 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/9320 Commit-Queue: Corentin Wallez Reviewed-by: Corentin Wallez --- src/tests/DawnTest.cpp | 25 +++++++++++++++---------- src/tests/DawnTest.h | 2 ++ src/tests/end2end/BasicTests.cpp | 7 +++++++ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/src/tests/DawnTest.cpp b/src/tests/DawnTest.cpp index a86edb114a..bd87c2e05c 100644 --- a/src/tests/DawnTest.cpp +++ b/src/tests/DawnTest.cpp @@ -378,22 +378,23 @@ void DawnTestBase::SetUp() { for (const dawn_native::Adapter& adapter : adapters) { if (adapter.GetBackendType() == backendType) { + if (adapter.GetDeviceType() == dawn_native::DeviceType::CPU) { + continue; + } + + // Filter adapter by vendor id if (HasVendorIdFilter()) { if (adapter.GetPCIInfo().vendorId == GetVendorIdFilter()) { mBackendAdapter = adapter; break; } - } else { - mBackendAdapter = adapter; + continue; + } - // 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; - } + // Prefer discrete GPU on multi-GPU systems, otherwise get integrated GPU. + mBackendAdapter = adapter; + if (mBackendAdapter.GetDeviceType() == dawn_native::DeviceType::DiscreteGPU) { + break; } } } @@ -484,6 +485,10 @@ bool DawnTestBase::EndExpectDeviceError() { return mError; } +dawn_native::PCIInfo DawnTestBase::GetPCIInfo() const { + return mPCIInfo; +} + // static void DawnTestBase::OnDeviceError(DawnErrorType type, const char* message, void* userdata) { ASSERT(type != DAWN_ERROR_TYPE_NO_ERROR); diff --git a/src/tests/DawnTest.h b/src/tests/DawnTest.h index ff68b76b4d..ba3ea78033 100644 --- a/src/tests/DawnTest.h +++ b/src/tests/DawnTest.h @@ -175,6 +175,8 @@ class DawnTestBase { bool HasVendorIdFilter() const; uint32_t GetVendorIdFilter() const; + dawn_native::PCIInfo GetPCIInfo() const; + protected: dawn::Device device; dawn::Queue queue; diff --git a/src/tests/end2end/BasicTests.cpp b/src/tests/end2end/BasicTests.cpp index 86a448793c..d5bb75467c 100644 --- a/src/tests/end2end/BasicTests.cpp +++ b/src/tests/end2end/BasicTests.cpp @@ -19,6 +19,13 @@ class BasicTests : public DawnTest { }; +// Test adapter filter by vendor id. +TEST_P(BasicTests, VendorIdFilter) { + DAWN_SKIP_TEST_IF(!HasVendorIdFilter()); + + ASSERT_EQ(GetPCIInfo().vendorId, GetVendorIdFilter()); +} + // Test Buffer::SetSubData changes the content of the buffer, but really this is the most // basic test possible, and tests the test harness TEST_P(BasicTests, BufferSetSubData) {