diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index 9846ca5cf..4eac7aff8 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -625,6 +625,9 @@ namespace bgfx /// matching id. uint16_t deviceId; + bool debug; //!< Enable device for debuging. + bool profile; //!< Enable device for profiling. + Resolution resolution; //!< Backbuffer resolution and reset parameters. struct Limits diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index 590fa29c9..605dd7fc1 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -639,6 +639,8 @@ typedef struct bgfx_init_s bgfx_renderer_type_t type; uint16_t vendorId; uint16_t deviceId; + bool debug; + bool profiling; bgfx_resolution_t resolution; bgfx_init_limits_t limits; diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index b9e2c4217..92253837e 100644 --- a/include/bgfx/defines.h +++ b/include/bgfx/defines.h @@ -6,7 +6,7 @@ #ifndef BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD -#define BGFX_API_VERSION UINT32_C(72) +#define BGFX_API_VERSION UINT32_C(73) /// Color RGB/alpha/depth write. When it's not specified write will be disabled. #define BGFX_STATE_WRITE_R UINT64_C(0x0000000000000001) //!< Enable R write. diff --git a/src/bgfx.cpp b/src/bgfx.cpp index 0cbc3b620..5e627a6c3 100644 --- a/src/bgfx.cpp +++ b/src/bgfx.cpp @@ -2815,6 +2815,8 @@ namespace bgfx : type(RendererType::Count) , vendorId(BGFX_PCI_ID_NONE) , deviceId(0) + , debug(BX_ENABLED(BGFX_CONFIG_DEBUG) ) + , profile(BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) , callback(NULL) , allocator(NULL) { diff --git a/src/debug_renderdoc.cpp b/src/debug_renderdoc.cpp index 6e45be7e3..c802806e4 100644 --- a/src/debug_renderdoc.cpp +++ b/src/debug_renderdoc.cpp @@ -5,7 +5,7 @@ #include "bgfx_p.h" -#if BGFX_CONFIG_DEBUG_PIX && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX) +#if BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX # if BX_PLATFORM_WINDOWS # include # endif // BX_PLATFORM_WINDOWS @@ -154,4 +154,4 @@ namespace bgfx } // namespace bgfx -#endif // BGFX_CONFIG_DEBUG_PIX && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX) +#endif // BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 9ffc9e089..45f8589d0 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -724,7 +724,8 @@ namespace bgfx { namespace d3d11 #endif // BGFX_CONFIG_USE_OVR m_ovr.init(vrImpl); - if (!m_ovr.isInitialized() ) + if (!m_ovr.isInitialized() + && (_init.debug || _init.profile) ) { m_renderdocdll = loadRenderDoc(); } @@ -891,7 +892,7 @@ namespace bgfx { namespace d3d11 | D3D11_CREATE_DEVICE_SINGLETHREADED | D3D11_CREATE_DEVICE_BGRA_SUPPORT // | D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS - | (BX_ENABLED(BGFX_CONFIG_DEBUG) ? D3D11_CREATE_DEVICE_DEBUG : 0) + | (_init.debug ? D3D11_CREATE_DEVICE_DEBUG : 0) ; hr = E_FAIL; @@ -1090,7 +1091,7 @@ namespace bgfx { namespace d3d11 } #endif // USE_D3D11_DYNAMIC_LIB - if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) + if (_init.debug) { hr = m_device->QueryInterface(IID_ID3D11InfoQueue, (void**)&m_infoQueue); @@ -1465,7 +1466,7 @@ namespace bgfx { namespace d3d11 mbstowcs(s_viewNameW[ii], s_viewName[ii], BGFX_CONFIG_MAX_VIEW_NAME_RESERVED); } - if (BX_ENABLED(BGFX_CONFIG_DEBUG) + if (_init.debug && NULL != m_infoQueue) { m_infoQueue->SetBreakOnSeverity(D3D11_MESSAGE_SEVERITY_ERROR, true); diff --git a/src/renderer_d3d12.cpp b/src/renderer_d3d12.cpp index 95b72f3fd..2c02ff653 100644 --- a/src/renderer_d3d12.cpp +++ b/src/renderer_d3d12.cpp @@ -664,7 +664,12 @@ namespace bgfx { namespace d3d12 } #endif // BGFX_CONFIG_DEBUG_PIX && BX_PLATFORM_WINDOWS - m_renderdocdll = loadRenderDoc(); + if (_init.debug + || _init.profile) + { + m_renderdocdll = loadRenderDoc(); + } + setGraphicsDebuggerPresent(NULL != m_renderdocdll || NULL != m_winPixEvent); m_fbh.idx = kInvalidHandle; @@ -729,14 +734,15 @@ namespace bgfx { namespace d3d12 HRESULT hr; - if (BX_ENABLED(BGFX_CONFIG_DEBUG||BGFX_CONFIG_DEBUG_PIX) ) + if (_init.debug + || _init.profile) { ID3D12Debug* debug0; hr = D3D12GetDebugInterface(IID_ID3D12Debug, (void**)&debug0); if (SUCCEEDED(hr) ) { - if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) + if (_init.debug) { debug0->EnableDebugLayer(); @@ -759,7 +765,7 @@ namespace bgfx { namespace d3d12 } #if BX_PLATFORM_XBOXONE - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) + if (_init.profile) { // https://github.com/Microsoft/Xbox-ATG-Samples/blob/76d236e3bd372aceec18b2ad0556a7879dbd9628/XDKSamples/IntroGraphics/SimpleTriangle12/DeviceResources.cpp#L67 debug0->SetProcessDebugFlags(D3D12XBOX_PROCESS_DEBUG_FLAG_INSTRUMENTED); @@ -936,7 +942,7 @@ namespace bgfx { namespace d3d12 | DXGI_MWA_NO_ALT_ENTER ) ); - if (BX_ENABLED(BGFX_CONFIG_DEBUG) ) + if (_init.debug) { hr = m_device->QueryInterface(IID_ID3D12InfoQueue, (void**)&m_infoQueue); @@ -1780,7 +1786,7 @@ namespace bgfx { namespace d3d12 void setMarker(const char* _marker, uint32_t /*_size*/) override { - if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX)) + if (BX_ENABLED(BGFX_CONFIG_DEBUG_PIX) ) { PIX3_SETMARKER(m_commandList, D3DCOLOR_MARKER, _marker); } diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index ef3c5c958..a8d05ef5b 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -1786,7 +1786,11 @@ BX_TRACE("%d, %d, %d, %s", _array, _srgb, _mipAutogen, getName(_format) ); ErrorState::Enum errorState = ErrorState::Default; - m_renderdocdll = loadRenderDoc(); + if (_init.debug + || _init.profile) + { + m_renderdocdll = loadRenderDoc(); + } m_fbh.idx = kInvalidHandle; bx::memSet(m_uniforms, 0, sizeof(m_uniforms) ); diff --git a/src/renderer_vk.cpp b/src/renderer_vk.cpp index c121dacd9..b2c2821ed 100644 --- a/src/renderer_vk.cpp +++ b/src/renderer_vk.cpp @@ -743,7 +743,12 @@ VK_IMPORT_DEVICE m_qfiGraphics = UINT32_MAX; m_qfiCompute = UINT32_MAX; - m_renderdocdll = loadRenderDoc(); + if (_init.debug + || _init.profile) + { + m_renderdocdll = loadRenderDoc(); + } + m_vulkan1dll = bx::dlopen( #if BX_PLATFORM_WINDOWS "vulkan-1.dll"