diff --git a/examples/SampleUtils.cpp b/examples/SampleUtils.cpp index 99e151928d..ecb20c278f 100644 --- a/examples/SampleUtils.cpp +++ b/examples/SampleUtils.cpp @@ -45,13 +45,13 @@ enum class CmdBufType { // Default to D3D12, Metal, Vulkan, OpenGL in that order as D3D12 and Metal are the preferred on // their respective platforms, and Vulkan is preferred to OpenGL #if defined(DAWN_ENABLE_BACKEND_D3D12) - static utils::BackendType backendType = utils::BackendType::D3D12; + static dawn_native::BackendType backendType = dawn_native::BackendType::D3D12; #elif defined(DAWN_ENABLE_BACKEND_METAL) - static utils::BackendType backendType = utils::BackendType::Metal; + static dawn_native::BackendType backendType = dawn_native::BackendType::Metal; #elif defined(DAWN_ENABLE_BACKEND_OPENGL) - static utils::BackendType backendType = utils::BackendType::OpenGL; + static dawn_native::BackendType backendType = dawn_native::BackendType::OpenGL; #elif defined(DAWN_ENABLE_BACKEND_VULKAN) - static utils::BackendType backendType = utils::BackendType::Vulkan; + static dawn_native::BackendType backendType = dawn_native::BackendType::Vulkan; #else #error #endif @@ -184,23 +184,23 @@ bool InitSample(int argc, const char** argv) { if (std::string("-b") == argv[i] || std::string("--backend") == argv[i]) { i++; if (i < argc && std::string("d3d12") == argv[i]) { - backendType = utils::BackendType::D3D12; + backendType = dawn_native::BackendType::D3D12; continue; } if (i < argc && std::string("metal") == argv[i]) { - backendType = utils::BackendType::Metal; + backendType = dawn_native::BackendType::Metal; continue; } if (i < argc && std::string("null") == argv[i]) { - backendType = utils::BackendType::Null; + backendType = dawn_native::BackendType::Null; continue; } if (i < argc && std::string("opengl") == argv[i]) { - backendType = utils::BackendType::OpenGL; + backendType = dawn_native::BackendType::OpenGL; continue; } if (i < argc && std::string("vulkan") == argv[i]) { - backendType = utils::BackendType::Vulkan; + backendType = dawn_native::BackendType::Vulkan; continue; } fprintf(stderr, "--backend expects a backend name (opengl, metal, d3d12, null, vulkan)\n"); diff --git a/src/tests/DawnTest.cpp b/src/tests/DawnTest.cpp index 4cbbbaf977..0637495a2d 100644 --- a/src/tests/DawnTest.cpp +++ b/src/tests/DawnTest.cpp @@ -26,34 +26,22 @@ #include "utils/TerribleCommandBuffer.h" #include +#include #include "GLFW/glfw3.h" namespace { - utils::BackendType ParamToBackendType(BackendType type) { + std::string ParamName(dawn_native::BackendType type) { switch (type) { - case D3D12Backend: - return utils::BackendType::D3D12; - case MetalBackend: - return utils::BackendType::Metal; - case OpenGLBackend: - return utils::BackendType::OpenGL; - case VulkanBackend: - return utils::BackendType::Vulkan; - default: - UNREACHABLE(); - } - } - - std::string ParamName(BackendType type) { - switch (type) { - case D3D12Backend: + case dawn_native::BackendType::D3D12: return "D3D12"; - case MetalBackend: + case dawn_native::BackendType::Metal: return "Metal"; - case OpenGLBackend: + case dawn_native::BackendType::Null: + return "Null"; + case dawn_native::BackendType::OpenGL: return "OpenGL"; - case VulkanBackend: + case dawn_native::BackendType::Vulkan: return "Vulkan"; default: UNREACHABLE(); @@ -63,10 +51,10 @@ namespace { // Windows don't usually like to be bound to one API than the other, for example switching // from Vulkan to OpenGL causes crashes on some drivers. Because of this, we lazily created // a window for each backing API. - GLFWwindow* windows[NumBackendTypes]; + std::unordered_map windows; // Creates a GLFW window set up for use with a given backend. - GLFWwindow* GetWindowForBackend(utils::BackendBinding* binding, BackendType type) { + GLFWwindow* GetWindowForBackend(utils::BackendBinding* binding, dawn_native::BackendType type) { GLFWwindow** window = &windows[type]; if (*window != nullptr) { @@ -185,7 +173,7 @@ bool DawnTest::IsMacOS() const { bool gTestUsesWire = false; void DawnTest::SetUp() { - mBinding.reset(utils::CreateBinding(ParamToBackendType(GetParam()))); + mBinding.reset(utils::CreateBinding(GetParam())); DAWN_ASSERT(mBinding != nullptr); GLFWwindow* testWindow = GetWindowForBackend(mBinding.get(), GetParam()); @@ -456,24 +444,20 @@ std::ostream& operator<<(std::ostream& stream, const RGBA8& color) { << ", " << static_cast(color.b) << ", " << static_cast(color.a) << ")"; } -std::ostream& operator<<(std::ostream& stream, BackendType backend) { - return stream << ParamName(backend); -} - namespace detail { - bool IsBackendAvailable(BackendType type) { + bool IsBackendAvailable(dawn_native::BackendType type) { switch (type) { #if defined(DAWN_ENABLE_BACKEND_D3D12) - case D3D12Backend: + case dawn_native::BackendType::D3D12: #endif #if defined(DAWN_ENABLE_BACKEND_METAL) - case MetalBackend: + case dawn_native::BackendType::Metal: #endif #if defined(DAWN_ENABLE_BACKEND_OPENGL) - case OpenGLBackend: + case dawn_native::BackendType::OpenGL: #endif #if defined(DAWN_ENABLE_BACKEND_VULKAN) - case VulkanBackend: + case dawn_native::BackendType::Vulkan: #endif return true; @@ -482,8 +466,9 @@ namespace detail { } } - std::vector FilterBackends(const BackendType* types, size_t numParams) { - std::vector backends; + std::vector FilterBackends(const dawn_native::BackendType* types, + size_t numParams) { + std::vector backends; for (size_t i = 0; i < numParams; ++i) { if (IsBackendAvailable(types[i])) { @@ -493,6 +478,10 @@ namespace detail { return backends; } + std::string GetParamName(const testing::TestParamInfo& info) { + return ParamName(info.param); + } + // Helper classes to set expectations template diff --git a/src/tests/DawnTest.h b/src/tests/DawnTest.h index f0c88239c8..b77777e207 100644 --- a/src/tests/DawnTest.h +++ b/src/tests/DawnTest.h @@ -56,15 +56,11 @@ struct RGBA8 { }; std::ostream& operator<<(std::ostream& stream, const RGBA8& color); -// Backend types used in the DAWN_INSTANTIATE_TEST -enum BackendType { - D3D12Backend, - MetalBackend, - OpenGLBackend, - VulkanBackend, - NumBackendTypes, -}; -std::ostream& operator<<(std::ostream& stream, BackendType backend); +// Shorthands for backend types used in the DAWN_INSTANTIATE_TEST +static constexpr dawn_native::BackendType D3D12Backend = dawn_native::BackendType::D3D12; +static constexpr dawn_native::BackendType MetalBackend = dawn_native::BackendType::Metal; +static constexpr dawn_native::BackendType OpenGLBackend = dawn_native::BackendType::OpenGL; +static constexpr dawn_native::BackendType VulkanBackend = dawn_native::BackendType::Vulkan; namespace utils { class BackendBinding; @@ -79,7 +75,7 @@ namespace dawn_wire { class CommandHandler; } // namespace dawn_wire -class DawnTest : public ::testing::TestWithParam { +class DawnTest : public ::testing::TestWithParam { public: DawnTest(); ~DawnTest(); @@ -192,7 +188,7 @@ class DawnTest : public ::testing::TestWithParam { INSTANTIATE_TEST_CASE_P(, testName, \ testing::ValuesIn(::detail::FilterBackends( \ testName##params, sizeof(testName##params) / sizeof(firstParam))), \ - testing::PrintToStringParamName()); + ::detail::GetParamName); // Skip a test when the given condition is satisfied. #define DAWN_SKIP_TEST_IF(condition) \ @@ -203,8 +199,10 @@ class DawnTest : public ::testing::TestWithParam { namespace detail { // Helper functions used for DAWN_INSTANTIATE_TEST - bool IsBackendAvailable(BackendType type); - std::vector FilterBackends(const BackendType* types, size_t numParams); + bool IsBackendAvailable(dawn_native::BackendType type); + std::vector FilterBackends(const dawn_native::BackendType* types, + size_t numParams); + std::string GetParamName(const testing::TestParamInfo& info); // All classes used to implement the deferred expectations should inherit from this. class Expectation { diff --git a/src/utils/BackendBinding.cpp b/src/utils/BackendBinding.cpp index a3fcf25542..3145856b0c 100644 --- a/src/utils/BackendBinding.cpp +++ b/src/utils/BackendBinding.cpp @@ -38,30 +38,30 @@ namespace utils { mWindow = window; } - BackendBinding* CreateBinding(BackendType type) { + BackendBinding* CreateBinding(dawn_native::BackendType type) { switch (type) { #if defined(DAWN_ENABLE_BACKEND_D3D12) - case BackendType::D3D12: + case dawn_native::BackendType::D3D12: return CreateD3D12Binding(); #endif #if defined(DAWN_ENABLE_BACKEND_METAL) - case BackendType::Metal: + case dawn_native::BackendType::Metal: return CreateMetalBinding(); #endif #if defined(DAWN_ENABLE_BACKEND_NULL) - case BackendType::Null: + case dawn_native::BackendType::Null: return CreateNullBinding(); #endif #if defined(DAWN_ENABLE_BACKEND_OPENGL) - case BackendType::OpenGL: + case dawn_native::BackendType::OpenGL: return CreateOpenGLBinding(); #endif #if defined(DAWN_ENABLE_BACKEND_VULKAN) - case BackendType::Vulkan: + case dawn_native::BackendType::Vulkan: return CreateVulkanBinding(); #endif diff --git a/src/utils/BackendBinding.h b/src/utils/BackendBinding.h index 622f8d7360..44b7eb4f87 100644 --- a/src/utils/BackendBinding.h +++ b/src/utils/BackendBinding.h @@ -15,7 +15,7 @@ #ifndef UTILS_BACKENDBINDING_H_ #define UTILS_BACKENDBINDING_H_ -#include +#include struct GLFWwindow; typedef struct dawnProcTable_s dawnProcTable; @@ -23,14 +23,6 @@ typedef struct dawnDeviceImpl* dawnDevice; namespace utils { - enum class BackendType { - D3D12, - Metal, - OpenGL, - Null, - Vulkan, - }; - class BackendBinding { public: virtual ~BackendBinding() = default; @@ -46,7 +38,7 @@ namespace utils { GLFWwindow* mWindow = nullptr; }; - BackendBinding* CreateBinding(BackendType type); + BackendBinding* CreateBinding(dawn_native::BackendType type); } // namespace utils