From 9126ca8fd75d2c1b36365fa4f6ce28c51fd7ec11 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sat, 11 Oct 2014 11:24:37 -0700 Subject: [PATCH] Added DX12 stub. --- include/bgfx.c99.h | 2 +- include/bgfx.h | 10 +++++----- scripts/geometryc.lua | 3 +++ src/bgfx.cpp | 41 ++++++++++++++++++++++++++--------------- src/bgfx_p.h | 3 ++- src/config.h | 12 ++++++++++++ src/renderer_d3d12.cpp | 23 +++++++++++++++++++++++ src/vertexdecl.cpp | 18 ++++++++++-------- 8 files changed, 82 insertions(+), 30 deletions(-) create mode 100644 src/renderer_d3d12.cpp diff --git a/include/bgfx.c99.h b/include/bgfx.c99.h index 27ff54b2..3eb0c3f1 100644 --- a/include/bgfx.c99.h +++ b/include/bgfx.c99.h @@ -19,7 +19,7 @@ typedef enum bgfx_renderer_type BGFX_RENDERER_TYPE_NULL, BGFX_RENDERER_TYPE_DIRECT3D9, BGFX_RENDERER_TYPE_DIRECT3D11, - BGFX_RENDERER_TYPE_OPENGLES, + BGFX_RENDERER_TYPE_OPENGLES = 4, BGFX_RENDERER_TYPE_OPENGL, BGFX_RENDERER_TYPE_COUNT diff --git a/include/bgfx.h b/include/bgfx.h index 1bb58a46..c937626f 100644 --- a/include/bgfx.h +++ b/include/bgfx.h @@ -43,11 +43,11 @@ namespace bgfx /// Renderer type enumeration. enum Enum { - Null, //< No rendering. - Direct3D9, //< Direct3D 9.0 - Direct3D11, //< Direct3D 11.0 - OpenGLES, //< OpenGL ES 2.0+ - OpenGL, //< OpenGL 2.1+ + Null, //< No rendering. + Direct3D9, //< Direct3D 9.0 + Direct3D11, //< Direct3D 11.0 + OpenGLES = 4, //< OpenGL ES 2.0+ + OpenGL, //< OpenGL 2.1+ Count }; diff --git a/scripts/geometryc.lua b/scripts/geometryc.lua index a7a88f2d..66d14740 100644 --- a/scripts/geometryc.lua +++ b/scripts/geometryc.lua @@ -11,12 +11,15 @@ project "geometryc" BX_DIR .. "include", BGFX_DIR .. "include", BGFX_DIR .. "3rdparty/forsyth-too", + BGFX_DIR .. "3rdparty/ib-compress", BGFX_DIR .. "examples/common", } files { BGFX_DIR .. "3rdparty/forsyth-too/**.cpp", BGFX_DIR .. "3rdparty/forsyth-too/**.h", + BGFX_DIR .. "3rdparty/ib-compress/**.cpp", + BGFX_DIR .. "3rdparty/ib-compress/**.h", BGFX_DIR .. "src/vertexdecl.**", BGFX_DIR .. "tools/geometryc/**.cpp", BGFX_DIR .. "tools/geometryc/**.h", diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 83666c8d..fdc9b6d7 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -1300,6 +1300,9 @@ namespace bgfx extern RendererContextI* rendererCreateD3D11(); extern void rendererDestroyD3D11(); + extern RendererContextI* rendererCreateD3D12(); + extern void rendererDestroyD3D12(); + struct RendererCreator { RendererCreateFn createFn; @@ -1308,35 +1311,37 @@ namespace bgfx bool supported; }; - static const RendererCreator s_rendererCreator[RendererType::Count] = + static const RendererCreator s_rendererCreator[] = { { rendererCreateNULL, rendererDestroyNULL, BGFX_RENDERER_NULL_NAME, !!BGFX_CONFIG_RENDERER_NULL }, // Null { rendererCreateD3D9, rendererDestroyD3D9, BGFX_RENDERER_DIRECT3D9_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D9 }, // Direct3D9 { rendererCreateD3D11, rendererDestroyD3D11, BGFX_RENDERER_DIRECT3D11_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D11 }, // Direct3D11 + { rendererCreateD3D12, rendererDestroyD3D12, BGFX_RENDERER_DIRECT3D12_NAME, !!BGFX_CONFIG_RENDERER_DIRECT3D12 }, // Direct3D12 { rendererCreateGL, rendererDestroyGL, BGFX_RENDERER_OPENGL_NAME, !!BGFX_CONFIG_RENDERER_OPENGLES }, // OpenGLES { rendererCreateGL, rendererDestroyGL, BGFX_RENDERER_OPENGL_NAME, !!BGFX_CONFIG_RENDERER_OPENGL }, // OpenGL }; + BX_STATIC_ASSERT(BX_COUNTOF(s_rendererCreator) == RendererType::Count); - uint32_t getWindowsVersion() + static RendererDestroyFn s_rendererDestroyFn; + + bool windowsVersionIsOrAbove(uint32_t _winver) { #if BX_PLATFORM_WINDOWS OSVERSIONINFOEXA ovi; memset(&ovi, 0, sizeof(ovi) ); ovi.dwOSVersionInfoSize = sizeof(ovi); - if (!GetVersionExA( (LPOSVERSIONINFOA)&ovi) ) - { - return 0x0501; // _WIN32_WINNT_WINXP - } - - // _WIN32_WINNT_WINBLUE 0x0602 + // _WIN32_WINNT_WINBLUE 0x0603 // _WIN32_WINNT_WIN8 0x0602 // _WIN32_WINNT_WIN7 0x0601 // _WIN32_WINNT_VISTA 0x0600 - return (ovi.dwMajorVersion<<8) - | ovi.dwMinorVersion - ; + ovi.dwMajorVersion = HIBYTE(_winver); + ovi.dwMinorVersion = LOBYTE(_winver); + DWORDLONG cond = 0; + VER_SET_CONDITION(cond, VER_MAJORVERSION, VER_GREATER_EQUAL); + VER_SET_CONDITION(cond, VER_MINORVERSION, VER_GREATER_EQUAL); + return !!VerifyVersionInfoA(&ovi, VER_MAJORVERSION | VER_MINORVERSION, cond); #else - return 0; + return false; #endif // BX_PLATFORM_WINDOWS } @@ -1349,7 +1354,12 @@ again: { RendererType::Enum first = RendererType::Direct3D9; RendererType::Enum second = RendererType::Direct3D11; - if (0x601 <= getWindowsVersion() ) + if (windowsVersionIsOrAbove(0x0603) ) + { + first = RendererType::Direct3D11 /* Direct3D12 */; + second = RendererType::Direct3D11; + } + else if (windowsVersionIsOrAbove(0x0601) ) { first = RendererType::Direct3D11; second = RendererType::Direct3D9; @@ -1400,13 +1410,14 @@ again: goto again; } + s_rendererDestroyFn = s_rendererCreator[_type].destroyFn; + return renderCtx; } void rendererDestroy() { - const RendererType::Enum type = getRendererType(); - s_rendererCreator[type].destroyFn(); + s_rendererDestroyFn(); } void Context::rendererExecCommands(CommandBuffer& _cmdbuf) diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 97b8d6d9..1c16962b 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -137,8 +137,9 @@ namespace stl #define BGFX_SAMPLER_DEFAULT_FLAGS UINT32_C(0x10000000) -#define BGFX_RENDERER_DIRECT3D9_NAME "Direct3D 9" +#define BGFX_RENDERER_DIRECT3D9_NAME "Direct3D 9" #define BGFX_RENDERER_DIRECT3D11_NAME "Direct3D 11" +#define BGFX_RENDERER_DIRECT3D12_NAME "Direct3D 12" #define BGFX_RENDERER_NULL_NAME "NULL" #if BGFX_CONFIG_RENDERER_OPENGL diff --git a/src/config.h b/src/config.h index b51043fc..8fdaa6e8 100644 --- a/src/config.h +++ b/src/config.h @@ -14,6 +14,7 @@ #if !defined(BGFX_CONFIG_RENDERER_DIRECT3D9) \ && !defined(BGFX_CONFIG_RENDERER_DIRECT3D11) \ + && !defined(BGFX_CONFIG_RENDERER_DIRECT3D12) \ && !defined(BGFX_CONFIG_RENDERER_OPENGL) \ && !defined(BGFX_CONFIG_RENDERER_OPENGLES) \ && !defined(BGFX_CONFIG_RENDERER_NULL) @@ -31,6 +32,12 @@ ? 1 : 0) # endif // BGFX_CONFIG_RENDERER_DIRECT3D11 +# ifndef BGFX_CONFIG_RENDERER_DIRECT3D12 +# define BGFX_CONFIG_RENDERER_DIRECT3D12 (0 \ + || (BX_PLATFORM_WINDOWS && BX_PLATFORM_WINDOWS >= 0x0603 /*_WIN32_WINNT_WINBLUE*/) \ + ? 1 : 0) +# endif // BGFX_CONFIG_RENDERER_DIRECT3D12 + # ifndef BGFX_CONFIG_RENDERER_OPENGL # define BGFX_CONFIG_RENDERER_OPENGL (0 \ || BX_PLATFORM_WINDOWS \ @@ -55,6 +62,7 @@ # define BGFX_CONFIG_RENDERER_NULL (!(0 \ || BGFX_CONFIG_RENDERER_DIRECT3D9 \ || BGFX_CONFIG_RENDERER_DIRECT3D11 \ + || BGFX_CONFIG_RENDERER_DIRECT3D12 \ || BGFX_CONFIG_RENDERER_OPENGL \ || BGFX_CONFIG_RENDERER_OPENGLES \ ? 1 : 0) ) @@ -68,6 +76,10 @@ # define BGFX_CONFIG_RENDERER_DIRECT3D11 0 # endif // BGFX_CONFIG_RENDERER_DIRECT3D11 +# ifndef BGFX_CONFIG_RENDERER_DIRECT3D12 +# define BGFX_CONFIG_RENDERER_DIRECT3D12 0 +# endif // BGFX_CONFIG_RENDERER_DIRECT3D12 + # ifndef BGFX_CONFIG_RENDERER_OPENGL # define BGFX_CONFIG_RENDERER_OPENGL 0 # endif // BGFX_CONFIG_RENDERER_OPENGL diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp new file mode 100644 index 00000000..2186215b --- /dev/null +++ b/src/renderer_d3d12.cpp @@ -0,0 +1,23 @@ +/* + * Copyright 2011-2014 Branimir Karadzic. All rights reserved. + * License: http://www.opensource.org/licenses/BSD-2-Clause + */ + +#include "bgfx_p.h" + +#if BGFX_CONFIG_RENDERER_DIRECT3D12 +#else + +namespace bgfx +{ + RendererContextI* rendererCreateD3D12() + { + return NULL; + } + + void rendererDestroyD3D12() + { + } +} // namespace bgfx + +#endif // BGFX_CONFIG_RENDERER_DIRECT3D12 diff --git a/src/vertexdecl.cpp b/src/vertexdecl.cpp index dd00ce3c..6d585620 100644 --- a/src/vertexdecl.cpp +++ b/src/vertexdecl.cpp @@ -23,7 +23,7 @@ namespace bgfx { 4, 8, 12, 16 }, }; - static const uint8_t s_attribTypeSizeDx11[AttribType::Count][4] = + static const uint8_t s_attribTypeSizeDx1x[AttribType::Count][4] = { { 1, 2, 4, 4 }, { 2, 4, 8, 8 }, @@ -39,22 +39,24 @@ namespace bgfx { 4, 8, 12, 16 }, }; - static const uint8_t (*s_attribTypeSize[RendererType::Count])[AttribType::Count][4] = + static const uint8_t (*s_attribTypeSize[])[AttribType::Count][4] = { #if BGFX_CONFIG_RENDERER_DIRECT3D9 &s_attribTypeSizeDx9, -#elif BGFX_CONFIG_RENDERER_DIRECT3D11 - &s_attribTypeSizeDx11, +#elif BGFX_CONFIG_RENDERER_DIRECT3D11 || BGFX_CONFIG_RENDERER_DIRECT3D12 + &s_attribTypeSizeDx1x, #elif BGFX_CONFIG_RENDERER_OPENGL || BGFX_CONFIG_RENDERER_OPENGLES &s_attribTypeSizeGl, #else &s_attribTypeSizeDx9, #endif // BGFX_CONFIG_RENDERER_ - &s_attribTypeSizeDx9, - &s_attribTypeSizeDx11, - &s_attribTypeSizeGl, - &s_attribTypeSizeGl, + &s_attribTypeSizeDx9, // Direct3D9 + &s_attribTypeSizeDx1x, // Direct3D11 + &s_attribTypeSizeDx1x, // Direct3D12 + &s_attribTypeSizeGl, // OpenGLES + &s_attribTypeSizeGl, // OpenGL }; + BX_STATIC_ASSERT(BX_COUNTOF(s_attribTypeSize) == bgfx::RendererType::Count); void initAttribTypeSizeTable(RendererType::Enum _type) {