Add proper defines for backend enablement
This commit is contained in:
parent
a7bfc9d2ac
commit
275817a93a
|
@ -21,6 +21,19 @@ project(nxt C CXX)
|
|||
|
||||
option(NXT_USE_WERROR "Treat warnings as error (useful for CI)" 0)
|
||||
|
||||
# Default values for the backend-enabling options
|
||||
if (WIN32)
|
||||
set(NXT_ENABLE_D3D12 ON)
|
||||
elseif(APPLE)
|
||||
set(NXT_ENABLE_METAL ON)
|
||||
endif()
|
||||
|
||||
option(NXT_ENABLE_D3D12 "Enable compilation of the D3D12 backend" OFF)
|
||||
option(NXT_ENABLE_METAL "Enable compilation of the Metal backend" OFF)
|
||||
option(NXT_ENABLE_NULL "Enable compilation of the Null backend" ON)
|
||||
option(NXT_ENABLE_OPENGL "Enable compilation of the OpenGL backend" ON)
|
||||
option(NXT_ENABLE_VULKAN "Enable compilation of the Vulkan backend" OFF)
|
||||
|
||||
################################################################################
|
||||
# Precompute compile flags and defines, functions to set them
|
||||
################################################################################
|
||||
|
@ -35,6 +48,22 @@ if(CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInf
|
|||
list(APPEND NXT_DEFS "NXT_ENABLE_ASSERTS")
|
||||
endif()
|
||||
|
||||
if (NXT_ENABLE_D3D12)
|
||||
list(APPEND NXT_INTERNAL_DEFS "NXT_ENABLE_BACKEND_D3D12")
|
||||
endif()
|
||||
if (NXT_ENABLE_METAL)
|
||||
list(APPEND NXT_INTERNAL_DEFS "NXT_ENABLE_BACKEND_METAL")
|
||||
endif()
|
||||
if (NXT_ENABLE_NULL)
|
||||
list(APPEND NXT_INTERNAL_DEFS "NXT_ENABLE_BACKEND_NULL")
|
||||
endif()
|
||||
if (NXT_ENABLE_OPENGL)
|
||||
list(APPEND NXT_INTERNAL_DEFS "NXT_ENABLE_BACKEND_OPENGL")
|
||||
endif()
|
||||
if (NXT_ENABLE_VULKAN)
|
||||
list(APPEND NXT_INTERNAL_DEFS "NXT_ENABLE_BACKEND_VULKAN")
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
# Define NOMINMAX to prevent conflicts between std::min/max and the min/max macros in WinDef.h
|
||||
list(APPEND NXT_DEFS "NOMINMAX")
|
||||
|
|
|
@ -39,12 +39,18 @@ enum class CmdBufType {
|
|||
//TODO(cwallez@chromium.org) double terrible cmdbuf
|
||||
};
|
||||
|
||||
#if defined(__APPLE__)
|
||||
static utils::BackendType backendType = utils::BackendType::Metal;
|
||||
#elif defined(_WIN32)
|
||||
// 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(NXT_ENABLE_BACKEND_D3D12)
|
||||
static utils::BackendType backendType = utils::BackendType::D3D12;
|
||||
#else
|
||||
#elif defined(NXT_ENABLE_BACKEND_METAL)
|
||||
static utils::BackendType backendType = utils::BackendType::Metal;
|
||||
#elif defined(NXT_ENABLE_BACKEND_VULKAN)
|
||||
static utils::BackendType backendType = utils::BackendType::OpenGL;
|
||||
#elif defined(NXT_ENABLE_BACKEND_OPENGL)
|
||||
static utils::BackendType backendType = utils::BackendType::Vulkan;
|
||||
#else
|
||||
#error
|
||||
#endif
|
||||
|
||||
static CmdBufType cmdBufType = CmdBufType::Terrible;
|
||||
|
|
|
@ -19,53 +19,11 @@ set(OPENGL_DIR ${CMAKE_CURRENT_SOURCE_DIR}/opengl)
|
|||
set(D3D12_DIR ${CMAKE_CURRENT_SOURCE_DIR}/d3d12)
|
||||
set(TESTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/tests)
|
||||
|
||||
list(APPEND BACKEND_SOURCES
|
||||
${BACKEND_DIR}/BindGroup.cpp
|
||||
${BACKEND_DIR}/BindGroup.h
|
||||
${BACKEND_DIR}/BindGroupLayout.cpp
|
||||
${BACKEND_DIR}/BindGroupLayout.h
|
||||
${BACKEND_DIR}/Builder.cpp
|
||||
${BACKEND_DIR}/Builder.h
|
||||
${BACKEND_DIR}/Buffer.cpp
|
||||
${BACKEND_DIR}/Buffer.h
|
||||
${BACKEND_DIR}/CommandAllocator.cpp
|
||||
${BACKEND_DIR}/CommandAllocator.h
|
||||
${BACKEND_DIR}/CommandBuffer.cpp
|
||||
${BACKEND_DIR}/CommandBuffer.h
|
||||
${BACKEND_DIR}/DepthStencilState.cpp
|
||||
${BACKEND_DIR}/DepthStencilState.h
|
||||
${BACKEND_DIR}/CommandBufferStateTracker.cpp
|
||||
${BACKEND_DIR}/CommandBufferStateTracker.h
|
||||
${BACKEND_DIR}/Device.cpp
|
||||
${BACKEND_DIR}/Device.h
|
||||
${BACKEND_DIR}/Forward.h
|
||||
${BACKEND_DIR}/Framebuffer.cpp
|
||||
${BACKEND_DIR}/Framebuffer.h
|
||||
${BACKEND_DIR}/InputState.cpp
|
||||
${BACKEND_DIR}/InputState.h
|
||||
${BACKEND_DIR}/PerStage.cpp
|
||||
${BACKEND_DIR}/PerStage.h
|
||||
${BACKEND_DIR}/Pipeline.cpp
|
||||
${BACKEND_DIR}/Pipeline.h
|
||||
${BACKEND_DIR}/PipelineLayout.cpp
|
||||
${BACKEND_DIR}/PipelineLayout.h
|
||||
${BACKEND_DIR}/Queue.cpp
|
||||
${BACKEND_DIR}/Queue.h
|
||||
${BACKEND_DIR}/RenderPass.cpp
|
||||
${BACKEND_DIR}/RenderPass.h
|
||||
${BACKEND_DIR}/RefCounted.cpp
|
||||
${BACKEND_DIR}/RefCounted.h
|
||||
${BACKEND_DIR}/Sampler.cpp
|
||||
${BACKEND_DIR}/Sampler.h
|
||||
${BACKEND_DIR}/ShaderModule.cpp
|
||||
${BACKEND_DIR}/ShaderModule.h
|
||||
${BACKEND_DIR}/Texture.cpp
|
||||
${BACKEND_DIR}/Texture.h
|
||||
${BACKEND_DIR}/ToBackend.h
|
||||
)
|
||||
|
||||
################################################################################
|
||||
# OpenGL Backend
|
||||
################################################################################
|
||||
|
||||
if (NXT_ENABLE_OPENGL)
|
||||
Generate(
|
||||
LIB_NAME opengl_autogen
|
||||
LIB_TYPE STATIC
|
||||
|
@ -99,8 +57,13 @@ list(APPEND BACKEND_SOURCES
|
|||
${OPENGL_DIR}/TextureGL.cpp
|
||||
${OPENGL_DIR}/TextureGL.h
|
||||
)
|
||||
endif()
|
||||
|
||||
# Null backend
|
||||
################################################################################
|
||||
# Null Backend
|
||||
################################################################################
|
||||
|
||||
if (NXT_ENABLE_NULL)
|
||||
Generate(
|
||||
LIB_NAME null_autogen
|
||||
LIB_TYPE STATIC
|
||||
|
@ -118,10 +81,13 @@ list(APPEND BACKEND_SOURCES
|
|||
${NULL_DIR}/NullBackend.cpp
|
||||
${NULL_DIR}/NullBackend.h
|
||||
)
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# Metal Backend
|
||||
################################################################################
|
||||
|
||||
if (APPLE)
|
||||
if (NXT_ENABLE_METAL)
|
||||
Generate(
|
||||
LIB_NAME metal_autogen
|
||||
LIB_TYPE STATIC
|
||||
|
@ -161,9 +127,11 @@ if (APPLE)
|
|||
)
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# D3D12 Backend
|
||||
################################################################################
|
||||
|
||||
if (WIN32)
|
||||
if (NXT_ENABLE_D3D12)
|
||||
Generate(
|
||||
LIB_NAME d3d12_autogen
|
||||
LIB_TYPE STATIC
|
||||
|
@ -266,13 +234,68 @@ if (WIN32)
|
|||
)
|
||||
endif()
|
||||
|
||||
################################################################################
|
||||
# Common sources definition of the library
|
||||
################################################################################
|
||||
|
||||
list(APPEND BACKEND_SOURCES
|
||||
${BACKEND_DIR}/BindGroup.cpp
|
||||
${BACKEND_DIR}/BindGroup.h
|
||||
${BACKEND_DIR}/BindGroupLayout.cpp
|
||||
${BACKEND_DIR}/BindGroupLayout.h
|
||||
${BACKEND_DIR}/Builder.cpp
|
||||
${BACKEND_DIR}/Builder.h
|
||||
${BACKEND_DIR}/Buffer.cpp
|
||||
${BACKEND_DIR}/Buffer.h
|
||||
${BACKEND_DIR}/CommandAllocator.cpp
|
||||
${BACKEND_DIR}/CommandAllocator.h
|
||||
${BACKEND_DIR}/CommandBuffer.cpp
|
||||
${BACKEND_DIR}/CommandBuffer.h
|
||||
${BACKEND_DIR}/DepthStencilState.cpp
|
||||
${BACKEND_DIR}/DepthStencilState.h
|
||||
${BACKEND_DIR}/CommandBufferStateTracker.cpp
|
||||
${BACKEND_DIR}/CommandBufferStateTracker.h
|
||||
${BACKEND_DIR}/Device.cpp
|
||||
${BACKEND_DIR}/Device.h
|
||||
${BACKEND_DIR}/Forward.h
|
||||
${BACKEND_DIR}/Framebuffer.cpp
|
||||
${BACKEND_DIR}/Framebuffer.h
|
||||
${BACKEND_DIR}/InputState.cpp
|
||||
${BACKEND_DIR}/InputState.h
|
||||
${BACKEND_DIR}/PerStage.cpp
|
||||
${BACKEND_DIR}/PerStage.h
|
||||
${BACKEND_DIR}/Pipeline.cpp
|
||||
${BACKEND_DIR}/Pipeline.h
|
||||
${BACKEND_DIR}/PipelineLayout.cpp
|
||||
${BACKEND_DIR}/PipelineLayout.h
|
||||
${BACKEND_DIR}/Queue.cpp
|
||||
${BACKEND_DIR}/Queue.h
|
||||
${BACKEND_DIR}/RenderPass.cpp
|
||||
${BACKEND_DIR}/RenderPass.h
|
||||
${BACKEND_DIR}/RefCounted.cpp
|
||||
${BACKEND_DIR}/RefCounted.h
|
||||
${BACKEND_DIR}/Sampler.cpp
|
||||
${BACKEND_DIR}/Sampler.h
|
||||
${BACKEND_DIR}/ShaderModule.cpp
|
||||
${BACKEND_DIR}/ShaderModule.h
|
||||
${BACKEND_DIR}/Texture.cpp
|
||||
${BACKEND_DIR}/Texture.h
|
||||
${BACKEND_DIR}/ToBackend.h
|
||||
)
|
||||
|
||||
add_library(nxt_backend STATIC ${BACKEND_SOURCES})
|
||||
NXTInternalTarget("backend" nxt_backend)
|
||||
target_link_libraries(nxt_backend nxt_common glfw glad spirv_cross)
|
||||
|
||||
target_link_libraries(nxt_backend nxt_common opengl_autogen null_autogen glfw glad spirv_cross)
|
||||
if (APPLE)
|
||||
target_link_libraries(nxt_backend metal_autogen)
|
||||
endif()
|
||||
if (WIN32)
|
||||
if (NXT_ENABLE_D3D12)
|
||||
target_link_libraries(nxt_backend d3d12_autogen)
|
||||
endif()
|
||||
if (NXT_ENABLE_METAL)
|
||||
target_link_libraries(nxt_backend metal_autogen)
|
||||
endif()
|
||||
if (NXT_ENABLE_NULL)
|
||||
target_link_libraries(nxt_backend null_autogen)
|
||||
endif()
|
||||
if (NXT_ENABLE_OPENGL)
|
||||
target_link_libraries(nxt_backend opengl_autogen)
|
||||
endif()
|
||||
|
|
|
@ -276,17 +276,24 @@ std::ostream& operator<< (std::ostream& stream, const RGBA8& color) {
|
|||
|
||||
namespace detail {
|
||||
bool IsBackendAvailable(BackendType type) {
|
||||
#if defined(__APPLE__)
|
||||
return type == MetalBackend;
|
||||
#elif defined(_WIN32)
|
||||
return type == D3D12Backend;
|
||||
#elif __linux__
|
||||
// Temporarily silence a warning while Linux doesn't have a backend that can be tested.
|
||||
(void) type;
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
switch (type) {
|
||||
#if defined(NXT_ENABLE_BACKEND_D3D12)
|
||||
case D3D12Backend:
|
||||
#endif
|
||||
#if defined(NXT_ENABLE_BACKEND_METAL)
|
||||
case MetalBackend:
|
||||
#endif
|
||||
#if defined(NXT_ENABLE_BACKEND_OPENGL)
|
||||
case OpenGLBackend:
|
||||
#endif
|
||||
#if defined(NXT_ENABLE_BACKEND_VULKAN)
|
||||
case VulkanBackend:
|
||||
#endif
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<BackendType> FilterBackends(const BackendType* types, size_t numParams) {
|
||||
|
|
|
@ -18,11 +18,21 @@
|
|||
|
||||
namespace utils {
|
||||
|
||||
#if defined(NXT_ENABLE_BACKEND_D3D12)
|
||||
BackendBinding* CreateD3D12Binding();
|
||||
#endif
|
||||
#if defined(NXT_ENABLE_BACKEND_METAL)
|
||||
BackendBinding* CreateMetalBinding();
|
||||
BackendBinding* CreateOpenGLBinding();
|
||||
#endif
|
||||
#if defined(NXT_ENABLE_BACKEND_NULL)
|
||||
BackendBinding* CreateNullBinding();
|
||||
#endif
|
||||
#if defined(NXT_ENABLE_BACKEND_OPENGL)
|
||||
BackendBinding* CreateOpenGLBinding();
|
||||
#endif
|
||||
#if defined(NXT_ENABLE_BACKEND_VULKAN)
|
||||
BackendBinding* CreateVulkanBinding();
|
||||
#endif
|
||||
|
||||
void BackendBinding::SetWindow(GLFWwindow* window) {
|
||||
this->window = window;
|
||||
|
@ -30,31 +40,33 @@ namespace utils {
|
|||
|
||||
BackendBinding* CreateBinding(BackendType type) {
|
||||
switch (type) {
|
||||
#if defined(NXT_ENABLE_BACKEND_D3D12)
|
||||
case BackendType::D3D12:
|
||||
#if defined(_WIN32)
|
||||
return CreateD3D12Binding();
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
|
||||
case BackendType::OpenGL:
|
||||
return CreateOpenGLBinding();
|
||||
|
||||
#if defined(NXT_ENABLE_BACKEND_METAL)
|
||||
case BackendType::Metal:
|
||||
#if defined(__APPLE__)
|
||||
return CreateMetalBinding();
|
||||
#else
|
||||
return nullptr;
|
||||
#endif
|
||||
|
||||
#if defined(NXT_ENABLE_BACKEND_NULL)
|
||||
case BackendType::Null:
|
||||
return CreateNullBinding();
|
||||
#endif
|
||||
|
||||
#if defined(NXT_ENABLE_BACKEND_OPENGL)
|
||||
case BackendType::OpenGL:
|
||||
return CreateOpenGLBinding();
|
||||
#endif
|
||||
|
||||
#if defined(NXT_ENABLE_BACKEND_VULKAN)
|
||||
case BackendType::Vulkan:
|
||||
return nullptr; // TODO(cwallez@chromium.org) change it to CreateVulkanBinding();
|
||||
return CreateVulkanBinding();
|
||||
#endif
|
||||
|
||||
default:
|
||||
UNREACHABLE();
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,21 +17,31 @@ set(UTILS_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|||
list(APPEND UTILS_SOURCES
|
||||
${UTILS_DIR}/BackendBinding.cpp
|
||||
${UTILS_DIR}/BackendBinding.h
|
||||
${UTILS_DIR}/NullBinding.cpp
|
||||
${UTILS_DIR}/OpenGLBinding.cpp
|
||||
${UTILS_DIR}/NXTHelpers.cpp
|
||||
${UTILS_DIR}/NXTHelpers.h
|
||||
)
|
||||
|
||||
if (APPLE)
|
||||
if (NXT_ENABLE_D3D12)
|
||||
list(APPEND UTILS_SOURCES
|
||||
${UTILS_DIR}/D3D12Binding.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if (NXT_ENABLE_METAL)
|
||||
list(APPEND UTILS_SOURCES
|
||||
${UTILS_DIR}/MetalBinding.mm
|
||||
)
|
||||
endif()
|
||||
|
||||
if (WIN32)
|
||||
if (NXT_ENABLE_NULL)
|
||||
list(APPEND UTILS_SOURCES
|
||||
${UTILS_DIR}/D3D12Binding.cpp
|
||||
${UTILS_DIR}/NullBinding.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
if (NXT_ENABLE_OPENGL)
|
||||
list(APPEND UTILS_SOURCES
|
||||
${UTILS_DIR}/OpenGLBinding.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
|
Loading…
Reference in New Issue