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