Remove redundant BackendType enums

BUG=dawn:29

Change-Id: Iaef26ca12a7a8721de17edb76e8fd4ff66cac0bd
Reviewed-on: https://dawn-review.googlesource.com/c/4342
Reviewed-by: Stephen White <senorblanco@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2019-02-05 12:17:20 +00:00 committed by Commit Bot service account
parent 00976d0db1
commit 8c88e1ddce
5 changed files with 51 additions and 72 deletions

View File

@ -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");

View File

@ -26,34 +26,22 @@
#include "utils/TerribleCommandBuffer.h"
#include <iostream>
#include <unordered_map>
#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<dawn_native::BackendType, GLFWwindow*> 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<int>(color.b) << ", " << static_cast<int>(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<BackendType> FilterBackends(const BackendType* types, size_t numParams) {
std::vector<BackendType> backends;
std::vector<dawn_native::BackendType> FilterBackends(const dawn_native::BackendType* types,
size_t numParams) {
std::vector<dawn_native::BackendType> 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<dawn_native::BackendType>& info) {
return ParamName(info.param);
}
// Helper classes to set expectations
template <typename T>

View File

@ -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<BackendType> {
class DawnTest : public ::testing::TestWithParam<dawn_native::BackendType> {
public:
DawnTest();
~DawnTest();
@ -192,7 +188,7 @@ class DawnTest : public ::testing::TestWithParam<BackendType> {
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<BackendType> {
namespace detail {
// Helper functions used for DAWN_INSTANTIATE_TEST
bool IsBackendAvailable(BackendType type);
std::vector<BackendType> FilterBackends(const BackendType* types, size_t numParams);
bool IsBackendAvailable(dawn_native::BackendType type);
std::vector<dawn_native::BackendType> FilterBackends(const dawn_native::BackendType* types,
size_t numParams);
std::string GetParamName(const testing::TestParamInfo<dawn_native::BackendType>& info);
// All classes used to implement the deferred expectations should inherit from this.
class Expectation {

View File

@ -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

View File

@ -15,7 +15,7 @@
#ifndef UTILS_BACKENDBINDING_H_
#define UTILS_BACKENDBINDING_H_
#include <dawn/dawn_wsi.h>
#include <dawn_native/DawnNative.h>
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