Browse Source

Added init debug&profile prarameters for device creation.

Branimir Karadžić 7 years ago
parent
commit
694735f95c

+ 3 - 0
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

+ 2 - 0
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;

+ 1 - 1
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.

+ 2 - 0
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)
 	{

+ 2 - 2
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 <psapi.h>
 #	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

+ 5 - 4
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);

+ 12 - 6
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);
 			}

+ 5 - 1
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) );

+ 6 - 1
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"