mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-20 05:43:12 +01:00
Added ability to programmatically capture frame with RenderDoc.
This commit is contained in:
@@ -63,7 +63,7 @@ int _main_(int _argc, char** _argv)
|
||||
|
||||
// Advance to next frame. Rendering thread will be kicked to
|
||||
// process submitted rendering primitives.
|
||||
bgfx_frame();
|
||||
bgfx_frame(false);
|
||||
}
|
||||
|
||||
// Shutdown bgfx.
|
||||
|
||||
@@ -34,6 +34,8 @@ BX_PRAGMA_DIAGNOSTIC_IGNORED_GCC("-Wunused-result");
|
||||
#include "fontstash.h"
|
||||
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_DISK
|
||||
#define LODEPNG_NO_COMPILE_ANCILLARY_CHUNKS
|
||||
@@ -41,6 +43,7 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
#define LODEPNG_NO_COMPILE_ALLOCATORS
|
||||
#define LODEPNG_NO_COMPILE_CPP
|
||||
#include <lodepng/lodepng.cpp>
|
||||
BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
|
||||
void* lodepng_malloc(size_t _size)
|
||||
{
|
||||
|
||||
@@ -938,13 +938,15 @@ namespace bgfx
|
||||
/// just swaps internal buffers, kicks render thread, and returns. In
|
||||
/// 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
|
||||
/// double/multi buffering data outside the library and passing it to
|
||||
/// library via `bgfx::makeRef` calls.
|
||||
///
|
||||
/// @attention C99 equivalent is `bgfx_frame`.
|
||||
///
|
||||
uint32_t frame();
|
||||
uint32_t frame(bool _capture = false);
|
||||
|
||||
/// Returns current renderer backend API type.
|
||||
///
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#ifndef 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.
|
||||
|
||||
@@ -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 uint32_t bgfx_frame();
|
||||
BGFX_C_API uint32_t bgfx_frame(bool _capture);
|
||||
|
||||
/**/
|
||||
BGFX_C_API bgfx_renderer_type_t bgfx_get_renderer_type();
|
||||
|
||||
@@ -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);
|
||||
void (*shutdown)();
|
||||
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)();
|
||||
const bgfx_caps_t* (*get_caps)();
|
||||
const bgfx_hmd_t* (*get_hmd)();
|
||||
|
||||
12
src/bgfx.cpp
12
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.");
|
||||
|
||||
@@ -1480,6 +1480,8 @@ namespace bgfx
|
||||
m_occlusionQuerySet.clear();
|
||||
}
|
||||
|
||||
m_submit->m_capture = _capture;
|
||||
|
||||
BGFX_PROFILER_SCOPE(bgfx, main_thread_frame, 0xff2040ff);
|
||||
// wait for render thread to finish
|
||||
renderSemWait();
|
||||
@@ -2510,10 +2512,10 @@ namespace bgfx
|
||||
s_ctx->reset(_width, _height, _flags);
|
||||
}
|
||||
|
||||
uint32_t frame()
|
||||
uint32_t frame(bool _capture)
|
||||
{
|
||||
BGFX_CHECK_MAIN_THREAD();
|
||||
return s_ctx->frame();
|
||||
return s_ctx->frame(_capture);
|
||||
}
|
||||
|
||||
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_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()
|
||||
|
||||
@@ -1375,6 +1375,8 @@ namespace bgfx
|
||||
, m_waitSubmit(0)
|
||||
, m_waitRender(0)
|
||||
, m_hmdInitialized(false)
|
||||
, m_capture(false)
|
||||
, m_discard(false)
|
||||
{
|
||||
SortKey term;
|
||||
term.reset();
|
||||
@@ -1428,6 +1430,7 @@ namespace bgfx
|
||||
m_cmdPre.start();
|
||||
m_cmdPost.start();
|
||||
m_uniformBuffer->reset();
|
||||
m_capture = false;
|
||||
m_discard = false;
|
||||
}
|
||||
|
||||
@@ -1836,6 +1839,7 @@ namespace bgfx
|
||||
int64_t m_waitRender;
|
||||
|
||||
bool m_hmdInitialized;
|
||||
bool m_capture;
|
||||
bool m_discard;
|
||||
};
|
||||
|
||||
@@ -3865,7 +3869,7 @@ namespace bgfx
|
||||
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 freeDynamicBuffers();
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace bgfx
|
||||
}
|
||||
|
||||
pRENDERDOC_GetAPI RENDERDOC_GetAPI;
|
||||
static RENDERDOC_API_1_0_0* s_renderDoc;
|
||||
static RENDERDOC_API_1_0_1* s_renderDoc;
|
||||
|
||||
void* loadRenderDoc()
|
||||
{
|
||||
@@ -105,6 +105,14 @@ namespace bgfx
|
||||
}
|
||||
}
|
||||
|
||||
void renderDocTriggerCapture()
|
||||
{
|
||||
if (NULL != s_renderDoc)
|
||||
{
|
||||
s_renderDoc->TriggerCapture();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
#else
|
||||
@@ -121,6 +129,10 @@ namespace bgfx
|
||||
{
|
||||
}
|
||||
|
||||
void renderDocTriggerCapture()
|
||||
{
|
||||
}
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
#endif // BGFX_CONFIG_DEBUG_PIX && (BX_PLATFORM_WINDOWS || BX_PLATFORM_LINUX)
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace bgfx
|
||||
{
|
||||
void* loadRenderDoc();
|
||||
void unloadRenderDoc(void*);
|
||||
void renderDocTriggerCapture();
|
||||
|
||||
} // namespace bgfx
|
||||
|
||||
|
||||
@@ -5020,6 +5020,11 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_render->m_capture)
|
||||
{
|
||||
renderDocTriggerCapture();
|
||||
}
|
||||
|
||||
PIX_BEGINEVENT(D3DCOLOR_RGBA(0xff, 0x00, 0x00, 0xff), L"rendererSubmit");
|
||||
BGFX_GPU_PROFILER_BEGIN_DYNAMIC("rendererSubmit");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user