From b1878edd2e8020a8629f6ffc2b626323f4b2a84a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Mon, 6 Oct 2014 22:10:55 -0700 Subject: [PATCH] Cleanup. --- src/renderer_d3d.h | 21 ++++++++++---------- src/renderer_d3d11.cpp | 44 +++++++++++++++++++++++------------------- src/renderer_d3d11.h | 2 -- src/renderer_d3d9.cpp | 32 ++++++++++++++---------------- 4 files changed, 50 insertions(+), 49 deletions(-) diff --git a/src/renderer_d3d.h b/src/renderer_d3d.h index e7c0243c..e21666c8 100644 --- a/src/renderer_d3d.h +++ b/src/renderer_d3d.h @@ -57,17 +57,18 @@ namespace bgfx #define DX_RELEASE(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_CHECK) #define DX_RELEASE_WARNONLY(_ptr, _expected) _DX_RELEASE(_ptr, _expected, BX_WARN) - typedef int (WINAPI *D3DPERF_BeginEventFunc)(DWORD _color, LPCWSTR _wszName); - typedef int (WINAPI *D3DPERF_EndEventFunc)(); - typedef void (WINAPI *D3DPERF_SetMarkerFunc)(DWORD _color, LPCWSTR _wszName); - typedef void (WINAPI *D3DPERF_SetRegionFunc)(DWORD _color, LPCWSTR _wszName); - typedef BOOL (WINAPI *D3DPERF_QueryRepeatFrameFunc)(); - typedef void (WINAPI *D3DPERF_SetOptionsFunc)(DWORD _options); - typedef DWORD (WINAPI *D3DPERF_GetStatusFunc)(); + typedef int (WINAPI* PFN_D3DPERF_BEGIN_EVENT)(DWORD _color, LPCWSTR _wszName); + typedef int (WINAPI* PFN_D3DPERF_END_EVENT)(); + typedef void (WINAPI* PFN_D3DPERF_SET_MARKER)(DWORD _color, LPCWSTR _wszName); + typedef void (WINAPI* PFN_D3DPERF_SET_REGION)(DWORD _color, LPCWSTR _wszName); + typedef BOOL (WINAPI* PFN_D3DPERF_QUERY_REPEAT_FRAME)(); + typedef void (WINAPI* PFN_D3DPERF_SET_OPTIONS)(DWORD _options); + typedef DWORD (WINAPI* PFN_D3DPERF_GET_STATUS)(); + typedef HRESULT (WINAPI* PFN_CREATE_DXGI_FACTORY)(REFIID _riid, void** _factory); -#define _PIX_SETMARKER(_col, _name) m_D3DPERF_SetMarker(_col, _name) -#define _PIX_BEGINEVENT(_col, _name) m_D3DPERF_BeginEvent(_col, _name) -#define _PIX_ENDEVENT() m_D3DPERF_EndEvent() +#define _PIX_SETMARKER(_col, _name) D3DPERF_SetMarker(_col, _name) +#define _PIX_BEGINEVENT(_col, _name) D3DPERF_BeginEvent(_col, _name) +#define _PIX_ENDEVENT() D3DPERF_EndEvent() #if BGFX_CONFIG_DEBUG_PIX # define PIX_SETMARKER(_color, _name) _PIX_SETMARKER(_color, _name) diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 92a56ff5..a094a82a 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -537,6 +537,14 @@ RENDERDOC_IMPORT } #endif // BGFX_CONFIG_DEBUG_PIX +#if USE_D3D11_DYNAMIC_LIB + static PFN_D3D11_CREATE_DEVICE D3D11CreateDevice; + static PFN_CREATE_DXGI_FACTORY CreateDXGIFactory; + static PFN_D3DPERF_SET_MARKER D3DPERF_SetMarker; + static PFN_D3DPERF_BEGIN_EVENT D3DPERF_BeginEvent; + static PFN_D3DPERF_END_EVENT D3DPERF_EndEvent; +#endif // USE_D3D11_DYNAMIC_LIB + struct RendererContextD3D11 : public RendererContextI { RendererContextD3D11() @@ -559,6 +567,8 @@ RENDERDOC_IMPORT m_d3d11dll = bx::dlopen("d3d11.dll"); BGFX_FATAL(NULL != m_d3d11dll, Fatal::UnableToInitialize, "Failed to load d3d11.dll."); + m_d3d9dll = NULL; + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) { // D3D11_1.h has ID3DUserDefinedAnnotation @@ -566,33 +576,30 @@ RENDERDOC_IMPORT m_d3d9dll = bx::dlopen("d3d9.dll"); BGFX_FATAL(NULL != m_d3d9dll, Fatal::UnableToInitialize, "Failed to load d3d9.dll."); - m_D3DPERF_SetMarker = (D3DPERF_SetMarkerFunc )bx::dlsym(m_d3d9dll, "D3DPERF_SetMarker" ); - m_D3DPERF_BeginEvent = (D3DPERF_BeginEventFunc)bx::dlsym(m_d3d9dll, "D3DPERF_BeginEvent"); - m_D3DPERF_EndEvent = (D3DPERF_EndEventFunc )bx::dlsym(m_d3d9dll, "D3DPERF_EndEvent" ); - BX_CHECK(NULL != m_D3DPERF_SetMarker - && NULL != m_D3DPERF_BeginEvent - && NULL != m_D3DPERF_EndEvent + D3DPERF_SetMarker = (PFN_D3DPERF_SET_MARKER )bx::dlsym(m_d3d9dll, "D3DPERF_SetMarker" ); + D3DPERF_BeginEvent = (PFN_D3DPERF_BEGIN_EVENT)bx::dlsym(m_d3d9dll, "D3DPERF_BeginEvent"); + D3DPERF_EndEvent = (PFN_D3DPERF_END_EVENT )bx::dlsym(m_d3d9dll, "D3DPERF_EndEvent" ); + BX_CHECK(NULL != D3DPERF_SetMarker + && NULL != D3DPERF_BeginEvent + && NULL != D3DPERF_EndEvent , "Failed to initialize PIX events." ); } - PFN_D3D11_CREATE_DEVICE d3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)bx::dlsym(m_d3d11dll, "D3D11CreateDevice"); - BGFX_FATAL(NULL != d3D11CreateDevice, Fatal::UnableToInitialize, "Function D3D11CreateDevice not found."); + D3D11CreateDevice = (PFN_D3D11_CREATE_DEVICE)bx::dlsym(m_d3d11dll, "D3D11CreateDevice"); + BGFX_FATAL(NULL != D3D11CreateDevice, Fatal::UnableToInitialize, "Function D3D11CreateDevice not found."); m_dxgidll = bx::dlopen("dxgi.dll"); BGFX_FATAL(NULL != m_dxgidll, Fatal::UnableToInitialize, "Failed to load dxgi.dll."); - PFN_CREATEDXGIFACTORY dxgiCreateDXGIFactory = (PFN_CREATEDXGIFACTORY)bx::dlsym(m_dxgidll, "CreateDXGIFactory"); - BGFX_FATAL(NULL != dxgiCreateDXGIFactory, Fatal::UnableToInitialize, "Function CreateDXGIFactory not found."); -#else - PFN_D3D11_CREATE_DEVICE d3D11CreateDevice = D3D11CreateDevice; - PFN_CREATEDXGIFACTORY dxgiCreateDXGIFactory = CreateDXGIFactory; + CreateDXGIFactory = (PFN_CREATE_DXGI_FACTORY)bx::dlsym(m_dxgidll, "CreateDXGIFactory"); + BGFX_FATAL(NULL != CreateDXGIFactory, Fatal::UnableToInitialize, "Function CreateDXGIFactory not found."); #endif // USE_D3D11_DYNAMIC_LIB HRESULT hr; IDXGIFactory* factory; - hr = dxgiCreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory); + hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory); BGFX_FATAL(SUCCEEDED(hr), Fatal::UnableToInitialize, "Unable to create DXGI factory."); m_adapter = NULL; @@ -662,7 +669,7 @@ RENDERDOC_IMPORT D3D_FEATURE_LEVEL featureLevel; - hr = d3D11CreateDevice(m_adapter + hr = D3D11CreateDevice(m_adapter , m_driverType , NULL , flags @@ -803,6 +810,7 @@ RENDERDOC_IMPORT #if USE_D3D11_DYNAMIC_LIB bx::dlclose(m_dxgidll); + bx::dlclose(m_d3d9dll); bx::dlclose(m_d3d11dll); #endif // USE_D3D11_DYNAMIC_LIB } @@ -1988,12 +1996,8 @@ RENDERDOC_IMPORT } } - void* m_d3d9dll; - D3DPERF_SetMarkerFunc m_D3DPERF_SetMarker; - D3DPERF_BeginEventFunc m_D3DPERF_BeginEvent; - D3DPERF_EndEventFunc m_D3DPERF_EndEvent; - #if USE_D3D11_DYNAMIC_LIB + void* m_d3d9dll; void* m_d3d11dll; void* m_dxgidll; #endif // USE_D3D11_DYNAMIC_LIB diff --git a/src/renderer_d3d11.h b/src/renderer_d3d11.h index d51ed7ef..3b558450 100644 --- a/src/renderer_d3d11.h +++ b/src/renderer_d3d11.h @@ -31,8 +31,6 @@ namespace bgfx { - typedef HRESULT (WINAPI * PFN_CREATEDXGIFACTORY)(REFIID _riid, void** _factory); - template class StateCacheT { diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index bed15596..45d7456e 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -254,6 +254,10 @@ namespace bgfx static const GUID IID_IDirect3D9 = { 0x81bdcbca, 0x64d4, 0x426d, { 0xae, 0x8d, 0xad, 0x1, 0x47, 0xf4, 0x27, 0x5c } }; static const GUID IID_IDirect3DDevice9Ex = { 0xb18b10ce, 0x2649, 0x405a, { 0x87, 0xf, 0x95, 0xf7, 0x77, 0xd4, 0x31, 0x3a } }; + static PFN_D3DPERF_SET_MARKER D3DPERF_SetMarker; + static PFN_D3DPERF_BEGIN_EVENT D3DPERF_BeginEvent; + static PFN_D3DPERF_END_EVENT D3DPERF_EndEvent; + struct RendererContextD3D9 : public RendererContextI { RendererContextD3D9() @@ -301,18 +305,18 @@ namespace bgfx m_d3d9dll = bx::dlopen("d3d9.dll"); BGFX_FATAL(NULL != m_d3d9dll, Fatal::UnableToInitialize, "Failed to load d3d9.dll."); -#if BGFX_CONFIG_DEBUG_PIX - m_D3DPERF_SetMarker = (D3DPERF_SetMarkerFunc )bx::dlsym(m_d3d9dll, "D3DPERF_SetMarker"); - m_D3DPERF_BeginEvent = (D3DPERF_BeginEventFunc)bx::dlsym(m_d3d9dll, "D3DPERF_BeginEvent"); - m_D3DPERF_EndEvent = (D3DPERF_EndEventFunc )bx::dlsym(m_d3d9dll, "D3DPERF_EndEvent"); - - BX_CHECK(NULL != m_D3DPERF_SetMarker - && NULL != m_D3DPERF_BeginEvent - && NULL != m_D3DPERF_EndEvent - , "Failed to initialize PIX events." - ); -#endif // BGFX_CONFIG_DEBUG_PIX + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + { + D3DPERF_SetMarker = (PFN_D3DPERF_SET_MARKER )bx::dlsym(m_d3d9dll, "D3DPERF_SetMarker"); + D3DPERF_BeginEvent = (PFN_D3DPERF_BEGIN_EVENT)bx::dlsym(m_d3d9dll, "D3DPERF_BeginEvent"); + D3DPERF_EndEvent = (PFN_D3DPERF_END_EVENT )bx::dlsym(m_d3d9dll, "D3DPERF_EndEvent"); + BX_CHECK(NULL != D3DPERF_SetMarker + && NULL != D3DPERF_BeginEvent + && NULL != D3DPERF_EndEvent + , "Failed to initialize PIX events." + ); + } #if BGFX_CONFIG_RENDERER_DIRECT3D9EX m_d3d9ex = NULL; @@ -1595,12 +1599,6 @@ namespace bgfx #if BX_PLATFORM_WINDOWS D3DCAPS9 m_caps; - -# if BGFX_CONFIG_DEBUG_PIX - D3DPERF_SetMarkerFunc m_D3DPERF_SetMarker; - D3DPERF_BeginEventFunc m_D3DPERF_BeginEvent; - D3DPERF_EndEventFunc m_D3DPERF_EndEvent; -# endif // BGFX_CONFIG_DEBUG_PIX #endif // BX_PLATFORM_WINDOWS #if BGFX_CONFIG_RENDERER_DIRECT3D9EX