From 2a49e5a143b8e7a9d4f29b9cfc6dd3cda47478ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Fri, 15 May 2015 13:14:35 -0700 Subject: [PATCH] Added flush after render reset flag. --- examples/common/entry/entry.cpp | 17 +++++++++-------- include/bgfxdefines.h | 5 +++-- src/glimports.h | 4 ++++ src/renderer_d3d11.cpp | 5 +++++ src/renderer_d3d9.cpp | 10 ++++++++++ src/renderer_gl.cpp | 5 +++++ 6 files changed, 36 insertions(+), 10 deletions(-) diff --git a/examples/common/entry/entry.cpp b/examples/common/entry/entry.cpp index 998f5cce..07826f1d 100644 --- a/examples/common/entry/entry.cpp +++ b/examples/common/entry/entry.cpp @@ -118,13 +118,14 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { if (_argc > 1) { - if (setOrToggle(s_reset, "vsync", BGFX_RESET_VSYNC, 1, _argc, _argv) - || setOrToggle(s_reset, "maxaniso", BGFX_RESET_MAXANISOTROPY, 1, _argc, _argv) - || setOrToggle(s_reset, "hmd", BGFX_RESET_HMD, 1, _argc, _argv) - || setOrToggle(s_reset, "hmddbg", BGFX_RESET_HMD_DEBUG, 1, _argc, _argv) - || setOrToggle(s_reset, "hmdrecenter", BGFX_RESET_HMD_RECENTER, 1, _argc, _argv) - || setOrToggle(s_reset, "msaa", BGFX_RESET_MSAA_X16, 1, _argc, _argv) - || setOrToggle(s_reset, "flip", BGFX_RESET_FLIP_AFTER_RENDER, 1, _argc, _argv) + if (setOrToggle(s_reset, "vsync", BGFX_RESET_VSYNC, 1, _argc, _argv) + || setOrToggle(s_reset, "maxaniso", BGFX_RESET_MAXANISOTROPY, 1, _argc, _argv) + || setOrToggle(s_reset, "hmd", BGFX_RESET_HMD, 1, _argc, _argv) + || setOrToggle(s_reset, "hmddbg", BGFX_RESET_HMD_DEBUG, 1, _argc, _argv) + || setOrToggle(s_reset, "hmdrecenter", BGFX_RESET_HMD_RECENTER, 1, _argc, _argv) + || setOrToggle(s_reset, "msaa", BGFX_RESET_MSAA_X16, 1, _argc, _argv) + || setOrToggle(s_reset, "flush", BGFX_RESET_FLUSH_AFTER_RENDER, 1, _argc, _argv) + || setOrToggle(s_reset, "flip", BGFX_RESET_FLIP_AFTER_RENDER, 1, _argc, _argv) ) { return 0; @@ -178,7 +179,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); { entry::Key::F4, entry::Modifier::LeftCtrl, 1, cmd, "graphics hmddbg" }, { entry::Key::F7, entry::Modifier::None, 1, cmd, "graphics vsync" }, { entry::Key::F8, entry::Modifier::None, 1, cmd, "graphics msaa" }, - { entry::Key::F9, entry::Modifier::None, 1, cmd, "graphics flip" }, + { entry::Key::F9, entry::Modifier::None, 1, cmd, "graphics flush" }, { entry::Key::Print, entry::Modifier::None, 1, cmd, "graphics screenshot" }, INPUT_BINDING_END diff --git a/include/bgfxdefines.h b/include/bgfxdefines.h index d67e1d87..e5ebaee0 100644 --- a/include/bgfxdefines.h +++ b/include/bgfxdefines.h @@ -324,8 +324,9 @@ #define BGFX_RESET_HMD UINT32_C(0x00000400) #define BGFX_RESET_HMD_DEBUG UINT32_C(0x00000800) #define BGFX_RESET_HMD_RECENTER UINT32_C(0x00001000) -#define BGFX_RESET_FLIP_AFTER_RENDER UINT32_C(0x00002000) -#define BGFX_RESET_SRGB_BACKBUFFER UINT32_C(0x00004000) +#define BGFX_RESET_FLUSH_AFTER_RENDER UINT32_C(0x00002000) +#define BGFX_RESET_FLIP_AFTER_RENDER UINT32_C(0x00004000) +#define BGFX_RESET_SRGB_BACKBUFFER UINT32_C(0x00008000) /// #define BGFX_CAPS_TEXTURE_COMPARE_LEQUAL UINT64_C(0x0000000000000001) diff --git a/src/glimports.h b/src/glimports.h index 3cd23e97..d3cd99af 100644 --- a/src/glimports.h +++ b/src/glimports.h @@ -106,6 +106,8 @@ typedef void (GL_APIENTRYP PFNGLENABLEPROC) (GLenum cap); typedef void (GL_APIENTRYP PFNGLENABLEIPROC) (GLenum cap, GLuint index); typedef void (GL_APIENTRYP PFNGLENABLEVERTEXATTRIBARRAYPROC) (GLuint index); typedef void (GL_APIENTRYP PFNGLENDQUERYPROC) (GLenum target); +typedef void (GL_APIENTRYP PFNGLFINISHPROC) (); +typedef void (GL_APIENTRYP PFNGLFLUSHPROC) (); typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERRENDERBUFFERPROC) (GLenum target, GLenum attachment, GLenum renderbuffertarget, GLuint renderbuffer); typedef void (GL_APIENTRYP PFNGLFRAMEBUFFERTEXTURE2DPROC) (GLenum target, GLenum attachment, GLenum textarget, GLuint texture, GLint level); typedef void (GL_APIENTRYP PFNGLGENBUFFERSPROC) (GLsizei n, GLuint *buffers); @@ -279,6 +281,8 @@ GL_IMPORT______(false, PFNGLENABLEPROC, glEnable); GL_IMPORT______(true, PFNGLENABLEIPROC, glEnablei); GL_IMPORT______(false, PFNGLENABLEVERTEXATTRIBARRAYPROC, glEnableVertexAttribArray); GL_IMPORT______(true, PFNGLENDQUERYPROC, glEndQuery); +GL_IMPORT______(false, PFNGLFINISHPROC, glFinish); +GL_IMPORT______(false, PFNGLFLUSHPROC, glFlush); GL_IMPORT______(true, PFNGLFRAMEBUFFERRENDERBUFFERPROC, glFramebufferRenderbuffer); GL_IMPORT______(true, PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D); GL_IMPORT______(false, PFNGLGENBUFFERSPROC, glGenBuffers); diff --git a/src/renderer_d3d11.cpp b/src/renderer_d3d11.cpp index 1d46ab53..8c12ca34 100644 --- a/src/renderer_d3d11.cpp +++ b/src/renderer_d3d11.cpp @@ -4376,6 +4376,11 @@ BX_PRAGMA_DIAGNOSTIC_POP(); if (0 < _render->m_num) { + if (0 != (m_resolution.m_flags & BGFX_RESET_FLUSH_AFTER_RENDER) ) + { + deviceCtx->Flush(); + } + captureElapsed = -bx::getHPCounter(); capture(); captureElapsed += bx::getHPCounter(); diff --git a/src/renderer_d3d9.cpp b/src/renderer_d3d9.cpp index 2a764a7e..399c2713 100644 --- a/src/renderer_d3d9.cpp +++ b/src/renderer_d3d9.cpp @@ -272,6 +272,7 @@ namespace bgfx { namespace d3d9 RendererContextD3D9() : m_d3d9(NULL) , m_device(NULL) + , m_flushQuery(NULL) , m_swapChain(NULL) , m_captureTexture(NULL) , m_captureSurface(NULL) @@ -1239,6 +1240,7 @@ namespace bgfx { namespace d3d9 capturePreReset(); + DX_RELEASE(m_flushQuery, 0); m_gpuTimer.preReset(); for (uint32_t ii = 0; ii < BX_COUNTOF(m_indexBuffers); ++ii) @@ -1268,6 +1270,7 @@ namespace bgfx { namespace d3d9 DX_CHECK(m_swapChain->GetBackBuffer(0, D3DBACKBUFFER_TYPE_MONO, &m_backBufferColor) ); DX_CHECK(m_device->GetDepthStencilSurface(&m_backBufferDepthStencil) ); + DX_CHECK(m_device->CreateQuery(D3DQUERYTYPE_EVENT, &m_flushQuery) ); m_gpuTimer.postReset(); capturePostReset(); @@ -1725,6 +1728,7 @@ namespace bgfx { namespace d3d9 IDirect3D9* m_d3d9; IDirect3DDevice9* m_device; + IDirect3DQuery9* m_flushQuery; TimerQueryD3D9 m_gpuTimer; D3DPOOL m_pool; @@ -3514,6 +3518,12 @@ namespace bgfx { namespace d3d9 if (0 < _render->m_num) { + if (0 != (m_resolution.m_flags & BGFX_RESET_FLUSH_AFTER_RENDER) ) + { + m_flushQuery->Issue(D3DISSUE_END); + m_flushQuery->GetData(NULL, 0, D3DGETDATA_FLUSH); + } + captureElapsed = -bx::getHPCounter(); capture(); captureElapsed += bx::getHPCounter(); diff --git a/src/renderer_gl.cpp b/src/renderer_gl.cpp index 54eb6eeb..a150cd52 100644 --- a/src/renderer_gl.cpp +++ b/src/renderer_gl.cpp @@ -5590,6 +5590,11 @@ namespace bgfx { namespace gl if (0 < _render->m_num) { + if (0 != (m_resolution.m_flags & BGFX_RESET_FLUSH_AFTER_RENDER) ) + { + GL_CHECK(glFlush() ); + } + captureElapsed = -bx::getHPCounter(); capture(); captureElapsed += bx::getHPCounter();