| // Copyright 2022 The Dawn Authors |
| // |
| // Licensed under the Apache License, Version 2.0 (the "License"); |
| // you may not use this file except in compliance with the License. |
| // You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, software |
| // distributed under the License is distributed on an "AS IS" BASIS, |
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| // See the License for the specific language governing permissions and |
| // limitations under the License. |
| |
| #include "dawn/tests/AdapterTestConfig.h" |
| |
| #include <initializer_list> |
| #include <ostream> |
| #include <string> |
| #include <vector> |
| |
| #include "dawn/common/Assert.h" |
| #include "dawn/webgpu_cpp.h" |
| |
| BackendTestConfig::BackendTestConfig(wgpu::BackendType backendType, |
| std::initializer_list<const char*> forceEnabledWorkarounds, |
| std::initializer_list<const char*> forceDisabledWorkarounds) |
| : backendType(backendType), |
| forceEnabledWorkarounds(forceEnabledWorkarounds), |
| forceDisabledWorkarounds(forceDisabledWorkarounds) {} |
| |
| BackendTestConfig D3D11Backend(std::initializer_list<const char*> forceEnabledWorkarounds, |
| std::initializer_list<const char*> forceDisabledWorkarounds) { |
| return BackendTestConfig(wgpu::BackendType::D3D11, forceEnabledWorkarounds, |
| forceDisabledWorkarounds); |
| } |
| |
| BackendTestConfig D3D12Backend(std::initializer_list<const char*> forceEnabledWorkarounds, |
| std::initializer_list<const char*> forceDisabledWorkarounds) { |
| return BackendTestConfig(wgpu::BackendType::D3D12, forceEnabledWorkarounds, |
| forceDisabledWorkarounds); |
| } |
| |
| BackendTestConfig MetalBackend(std::initializer_list<const char*> forceEnabledWorkarounds, |
| std::initializer_list<const char*> forceDisabledWorkarounds) { |
| return BackendTestConfig(wgpu::BackendType::Metal, forceEnabledWorkarounds, |
| forceDisabledWorkarounds); |
| } |
| |
| BackendTestConfig NullBackend(std::initializer_list<const char*> forceEnabledWorkarounds, |
| std::initializer_list<const char*> forceDisabledWorkarounds) { |
| return BackendTestConfig(wgpu::BackendType::Null, forceEnabledWorkarounds, |
| forceDisabledWorkarounds); |
| } |
| |
| BackendTestConfig OpenGLBackend(std::initializer_list<const char*> forceEnabledWorkarounds, |
| std::initializer_list<const char*> forceDisabledWorkarounds) { |
| return BackendTestConfig(wgpu::BackendType::OpenGL, forceEnabledWorkarounds, |
| forceDisabledWorkarounds); |
| } |
| |
| BackendTestConfig OpenGLESBackend(std::initializer_list<const char*> forceEnabledWorkarounds, |
| std::initializer_list<const char*> forceDisabledWorkarounds) { |
| return BackendTestConfig(wgpu::BackendType::OpenGLES, forceEnabledWorkarounds, |
| forceDisabledWorkarounds); |
| } |
| |
| BackendTestConfig VulkanBackend(std::initializer_list<const char*> forceEnabledWorkarounds, |
| std::initializer_list<const char*> forceDisabledWorkarounds) { |
| return BackendTestConfig(wgpu::BackendType::Vulkan, forceEnabledWorkarounds, |
| forceDisabledWorkarounds); |
| } |
| |
| TestAdapterProperties::TestAdapterProperties(const wgpu::AdapterProperties& properties, |
| bool selected) |
| : vendorID(properties.vendorID), |
| vendorName(properties.vendorName), |
| architecture(properties.architecture), |
| deviceID(properties.deviceID), |
| name(properties.name), |
| driverDescription(properties.driverDescription), |
| adapterType(properties.adapterType), |
| backendType(properties.backendType), |
| compatibilityMode(properties.compatibilityMode), |
| selected(selected) {} |
| |
| std::string TestAdapterProperties::ParamName() const { |
| switch (backendType) { |
| case wgpu::BackendType::D3D11: |
| return "D3D11"; |
| case wgpu::BackendType::D3D12: |
| return "D3D12"; |
| case wgpu::BackendType::Metal: |
| return "Metal"; |
| case wgpu::BackendType::Null: |
| return "Null"; |
| case wgpu::BackendType::OpenGL: |
| return "OpenGL"; |
| case wgpu::BackendType::OpenGLES: |
| return "OpenGLES"; |
| case wgpu::BackendType::Vulkan: |
| return "Vulkan"; |
| case wgpu::BackendType::Undefined: |
| default: |
| UNREACHABLE(); |
| } |
| } |
| |
| std::string TestAdapterProperties::AdapterTypeName() const { |
| switch (adapterType) { |
| case wgpu::AdapterType::DiscreteGPU: |
| return "Discrete GPU"; |
| case wgpu::AdapterType::IntegratedGPU: |
| return "Integrated GPU"; |
| case wgpu::AdapterType::CPU: |
| return "CPU"; |
| case wgpu::AdapterType::Unknown: |
| return "Unknown"; |
| default: |
| UNREACHABLE(); |
| } |
| } |
| |
| AdapterTestParam::AdapterTestParam(const BackendTestConfig& config, |
| const TestAdapterProperties& adapterProperties) |
| : adapterProperties(adapterProperties), |
| forceEnabledWorkarounds(config.forceEnabledWorkarounds), |
| forceDisabledWorkarounds(config.forceDisabledWorkarounds) {} |
| |
| std::ostream& operator<<(std::ostream& os, const AdapterTestParam& param) { |
| os << param.adapterProperties.ParamName() << " " << param.adapterProperties.name; |
| |
| // In a Windows Remote Desktop session there are two adapters named "Microsoft Basic Render |
| // Driver" with different adapter types. We must differentiate them to avoid any tests using the |
| // same name. |
| if (param.adapterProperties.deviceID == 0x008C) { |
| std::string adapterType = param.adapterProperties.AdapterTypeName(); |
| os << " " << adapterType; |
| } |
| |
| for (const char* forceEnabledWorkaround : param.forceEnabledWorkarounds) { |
| os << "; e:" << forceEnabledWorkaround; |
| } |
| for (const char* forceDisabledWorkaround : param.forceDisabledWorkarounds) { |
| os << "; d:" << forceDisabledWorkaround; |
| } |
| return os; |
| } |