Browse Source

Added ability to programmatically capture frame with RenderDoc.

Branimir Karadžić 9 years ago
parent
commit
e46135da8c

+ 1 - 1
examples/25-c99/helloworld.c

@@ -63,7 +63,7 @@ int _main_(int _argc, char** _argv)
 
 
 		// Advance to next frame. Rendering thread will be kicked to
 		// Advance to next frame. Rendering thread will be kicked to
 		// process submitted rendering primitives.
 		// process submitted rendering primitives.
-		bgfx_frame();
+		bgfx_frame(false);
 	}
 	}
 
 
 	// Shutdown bgfx.
 	// Shutdown bgfx.

+ 3 - 0
examples/common/nanovg/nanovg.cpp

@@ -34,6 +34,8 @@ BX_PRAGMA_DIAGNOSTIC_IGNORED_GCC("-Wunused-result");
 #include "fontstash.h"
 #include "fontstash.h"
 BX_PRAGMA_DIAGNOSTIC_POP();
 BX_PRAGMA_DIAGNOSTIC_POP();
 
 
+BX_PRAGMA_DIAGNOSTIC_PUSH();
+BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4127) // warning C4127: conditional expression is constant
 #define LODEPNG_NO_COMPILE_ENCODER
 #define LODEPNG_NO_COMPILE_ENCODER
 #define LODEPNG_NO_COMPILE_DISK
 #define LODEPNG_NO_COMPILE_DISK
 #define LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
 #define LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
@@ -41,6 +43,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 #define LODEPNG_NO_COMPILE_ALLOCATORS
 #define LODEPNG_NO_COMPILE_ALLOCATORS
 #define LODEPNG_NO_COMPILE_CPP
 #define LODEPNG_NO_COMPILE_CPP
 #include <lodepng/lodepng.cpp>
 #include <lodepng/lodepng.cpp>
+BX_PRAGMA_DIAGNOSTIC_POP();
 
 
 void* lodepng_malloc(size_t _size)
 void* lodepng_malloc(size_t _size)
 {
 {

+ 3 - 1
include/bgfx/bgfx.h

@@ -938,13 +938,15 @@ namespace bgfx
 	/// just swaps internal buffers, kicks render thread, and returns. In
 	/// just swaps internal buffers, kicks render thread, and returns. In
 	/// singlethreaded renderer this call does frame rendering.
 	/// singlethreaded renderer this call does frame rendering.
 	///
 	///
+	/// @param[in] _capture Capture frame with graphics debugger.
+	///
 	/// @returns Current frame number. This might be used in conjunction with
 	/// @returns Current frame number. This might be used in conjunction with
 	///   double/multi buffering data outside the library and passing it to
 	///   double/multi buffering data outside the library and passing it to
 	///   library via `bgfx::makeRef` calls.
 	///   library via `bgfx::makeRef` calls.
 	///
 	///
 	/// @attention C99 equivalent is `bgfx_frame`.
 	/// @attention C99 equivalent is `bgfx_frame`.
 	///
 	///
-	uint32_t frame();
+	uint32_t frame(bool _capture = false);
 
 
 	/// Returns current renderer backend API type.
 	/// Returns current renderer backend API type.
 	///
 	///

+ 1 - 1
include/bgfx/bgfxdefines.h

@@ -6,7 +6,7 @@
 #ifndef BGFX_DEFINES_H_HEADER_GUARD
 #ifndef BGFX_DEFINES_H_HEADER_GUARD
 #define BGFX_DEFINES_H_HEADER_GUARD
 #define BGFX_DEFINES_H_HEADER_GUARD
 
 
-#define BGFX_API_VERSION UINT32_C(14)
+#define BGFX_API_VERSION UINT32_C(15)
 
 
 ///
 ///
 #define BGFX_STATE_RGB_WRITE               UINT64_C(0x0000000000000001) //!< Enable RGB write.
 #define BGFX_STATE_RGB_WRITE               UINT64_C(0x0000000000000001) //!< Enable RGB write.

+ 1 - 1
include/bgfx/c99/bgfx.h

@@ -505,7 +505,7 @@ BGFX_C_API void bgfx_shutdown();
 BGFX_C_API void bgfx_reset(uint32_t _width, uint32_t _height, uint32_t _flags);
 BGFX_C_API void bgfx_reset(uint32_t _width, uint32_t _height, uint32_t _flags);
 
 
 /**/
 /**/
-BGFX_C_API uint32_t bgfx_frame();
+BGFX_C_API uint32_t bgfx_frame(bool _capture);
 
 
 /**/
 /**/
 BGFX_C_API bgfx_renderer_type_t bgfx_get_renderer_type();
 BGFX_C_API bgfx_renderer_type_t bgfx_get_renderer_type();

+ 1 - 1
include/bgfx/c99/bgfxplatform.h

@@ -85,7 +85,7 @@ typedef struct bgfx_interface_vtbl
     bool (*init)(bgfx_renderer_type_t _type, uint16_t _vendorId, uint16_t _deviceId, bgfx_callback_interface_t* _callback, bgfx_allocator_interface_t* _allocator);
     bool (*init)(bgfx_renderer_type_t _type, uint16_t _vendorId, uint16_t _deviceId, bgfx_callback_interface_t* _callback, bgfx_allocator_interface_t* _allocator);
     void (*shutdown)();
     void (*shutdown)();
     void (*reset)(uint32_t _width, uint32_t _height, uint32_t _flags);
     void (*reset)(uint32_t _width, uint32_t _height, uint32_t _flags);
-    uint32_t (*frame)();
+    uint32_t (*frame)(bool _capture);
     bgfx_renderer_type_t (*get_renderer_type)();
     bgfx_renderer_type_t (*get_renderer_type)();
     const bgfx_caps_t* (*get_caps)();
     const bgfx_caps_t* (*get_caps)();
     const bgfx_hmd_t* (*get_hmd)();
     const bgfx_hmd_t* (*get_hmd)();

+ 7 - 5
src/bgfx.cpp

@@ -1471,7 +1471,7 @@ namespace bgfx
 		}
 		}
 	}
 	}
 
 
-	uint32_t Context::frame()
+	uint32_t Context::frame(bool _capture)
 	{
 	{
 		BX_CHECK(0 == m_instBufferCount, "Instance buffer allocated, but not used. This is incorrect, and causes memory leak.");
 		BX_CHECK(0 == m_instBufferCount, "Instance buffer allocated, but not used. This is incorrect, and causes memory leak.");
 
 
@@ -1480,6 +1480,8 @@ namespace bgfx
 			m_occlusionQuerySet.clear();
 			m_occlusionQuerySet.clear();
 		}
 		}
 
 
+		m_submit->m_capture = _capture;
+
 		BGFX_PROFILER_SCOPE(bgfx, main_thread_frame, 0xff2040ff);
 		BGFX_PROFILER_SCOPE(bgfx, main_thread_frame, 0xff2040ff);
 		// wait for render thread to finish
 		// wait for render thread to finish
 		renderSemWait();
 		renderSemWait();
@@ -2510,10 +2512,10 @@ namespace bgfx
 		s_ctx->reset(_width, _height, _flags);
 		s_ctx->reset(_width, _height, _flags);
 	}
 	}
 
 
-	uint32_t frame()
+	uint32_t frame(bool _capture)
 	{
 	{
 		BGFX_CHECK_MAIN_THREAD();
 		BGFX_CHECK_MAIN_THREAD();
-		return s_ctx->frame();
+		return s_ctx->frame(_capture);
 	}
 	}
 
 
 	const Caps* getCaps()
 	const Caps* getCaps()
@@ -3859,9 +3861,9 @@ BGFX_C_API void bgfx_reset(uint32_t _width, uint32_t _height, uint32_t _flags)
 	bgfx::reset(_width, _height, _flags);
 	bgfx::reset(_width, _height, _flags);
 }
 }
 
 
-BGFX_C_API uint32_t bgfx_frame()
+BGFX_C_API uint32_t bgfx_frame(bool _capture)
 {
 {
-	return bgfx::frame();
+	return bgfx::frame(_capture);
 }
 }
 
 
 BGFX_C_API bgfx_renderer_type_t bgfx_get_renderer_type()
 BGFX_C_API bgfx_renderer_type_t bgfx_get_renderer_type()

+ 5 - 1
src/bgfx_p.h

@@ -1375,6 +1375,8 @@ namespace bgfx
 			, m_waitSubmit(0)
 			, m_waitSubmit(0)
 			, m_waitRender(0)
 			, m_waitRender(0)
 			, m_hmdInitialized(false)
 			, m_hmdInitialized(false)
+			, m_capture(false)
+			, m_discard(false)
 		{
 		{
 			SortKey term;
 			SortKey term;
 			term.reset();
 			term.reset();
@@ -1428,6 +1430,7 @@ namespace bgfx
 			m_cmdPre.start();
 			m_cmdPre.start();
 			m_cmdPost.start();
 			m_cmdPost.start();
 			m_uniformBuffer->reset();
 			m_uniformBuffer->reset();
+			m_capture = false;
 			m_discard = false;
 			m_discard = false;
 		}
 		}
 
 
@@ -1836,6 +1839,7 @@ namespace bgfx
 		int64_t m_waitRender;
 		int64_t m_waitRender;
 
 
 		bool m_hmdInitialized;
 		bool m_hmdInitialized;
+		bool m_capture;
 		bool m_discard;
 		bool m_discard;
 	};
 	};
 
 
@@ -3865,7 +3869,7 @@ namespace bgfx
 			blit(_id, _dst, _dstMip, _dstX, _dstY, _dstZ, textureHandle, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth);
 			blit(_id, _dst, _dstMip, _dstX, _dstY, _dstZ, textureHandle, _srcMip, _srcX, _srcY, _srcZ, _width, _height, _depth);
 		}
 		}
 
 
-		BGFX_API_FUNC(uint32_t frame() );
+		BGFX_API_FUNC(uint32_t frame(bool _capture = false) );
 
 
 		void dumpViewStats();
 		void dumpViewStats();
 		void freeDynamicBuffers();
 		void freeDynamicBuffers();

+ 13 - 1
src/debug_renderdoc.cpp

@@ -56,7 +56,7 @@ namespace bgfx
 	}
 	}
 
 
 	pRENDERDOC_GetAPI RENDERDOC_GetAPI;
 	pRENDERDOC_GetAPI RENDERDOC_GetAPI;
-	static RENDERDOC_API_1_0_0* s_renderDoc;
+	static RENDERDOC_API_1_0_1* s_renderDoc;
 
 
 	void* loadRenderDoc()
 	void* loadRenderDoc()
 	{
 	{
@@ -105,6 +105,14 @@ namespace bgfx
 		}
 		}
 	}
 	}
 
 
+	void renderDocTriggerCapture()
+	{
+		if (NULL != s_renderDoc)
+		{
+			s_renderDoc->TriggerCapture();
+		}
+	}
+
 } // namespace bgfx
 } // namespace bgfx
 
 
 #else
 #else
@@ -121,6 +129,10 @@ namespace bgfx
 	{
 	{
 	}
 	}
 
 
+	void renderDocTriggerCapture()
+	{
+	}
+
 } // namespace bgfx
 } // namespace bgfx
 
 
 #endif // BGFX_CONFIG_DEBUG_PIX && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX)
 #endif // BGFX_CONFIG_DEBUG_PIX && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX)

+ 1 - 0
src/debug_renderdoc.h

@@ -10,6 +10,7 @@ namespace bgfx
 {
 {
 	void* loadRenderDoc();
 	void* loadRenderDoc();
 	void unloadRenderDoc(void*);
 	void unloadRenderDoc(void*);
+	void renderDocTriggerCapture();
 
 
 } // namespace bgfx
 } // namespace bgfx
 
 

+ 5 - 0
src/renderer_d3d11.cpp

@@ -5020,6 +5020,11 @@ BX_PRAGMA_DIAGNOSTIC_POP();
 			return;
 			return;
 		}
 		}
 
 
+		if (_render->m_capture)
+		{
+			renderDocTriggerCapture();
+		}
+
 		PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), L"rendererSubmit");
 		PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), L"rendererSubmit");
 		BGFX_GPU_PROFILER_BEGIN_DYNAMIC("rendererSubmit");
 		BGFX_GPU_PROFILER_BEGIN_DYNAMIC("rendererSubmit");