mirror of
https://github.com/bkaradzic/bgfx.git
synced 2026-02-19 21:42:59 +01:00
Invalidate occlusion queries in flight when new occlusion query with the same id is created.
This commit is contained in:
@@ -2475,6 +2475,15 @@ namespace bgfx
|
||||
}
|
||||
break;
|
||||
|
||||
case CommandBuffer::InvalidateOcclusionQuery:
|
||||
{
|
||||
OcclusionQueryHandle handle;
|
||||
_cmdbuf.read(handle);
|
||||
|
||||
m_renderCtx->invalidateOcclusionQuery(handle);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
BX_CHECK(false, "Invalid command: %d", command);
|
||||
break;
|
||||
|
||||
13
src/bgfx_p.h
13
src/bgfx_p.h
@@ -633,6 +633,7 @@ namespace bgfx
|
||||
CreateFrameBuffer,
|
||||
CreateUniform,
|
||||
UpdateViewName,
|
||||
InvalidateOcclusionQuery,
|
||||
End,
|
||||
RendererShutdownEnd,
|
||||
DestroyVertexDecl,
|
||||
@@ -2170,6 +2171,7 @@ namespace bgfx
|
||||
virtual void updateViewName(uint8_t _id, const char* _name) = 0;
|
||||
virtual void updateUniform(uint16_t _loc, const void* _data, uint32_t _size) = 0;
|
||||
virtual void setMarker(const char* _marker, uint32_t _size) = 0;
|
||||
virtual void invalidateOcclusionQuery(OcclusionQueryHandle _handle) = 0;
|
||||
virtual void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) = 0;
|
||||
virtual void blitSetup(TextVideoMemBlitter& _blitter) = 0;
|
||||
virtual void blitRender(TextVideoMemBlitter& _blitter, uint32_t _numIndices) = 0;
|
||||
@@ -3600,7 +3602,11 @@ namespace bgfx
|
||||
if (isValid(handle) )
|
||||
{
|
||||
m_submit->m_occlusion[handle.idx] = UINT8_MAX;
|
||||
|
||||
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::InvalidateOcclusionQuery);
|
||||
cmdbuf.write(handle);
|
||||
}
|
||||
|
||||
return handle;
|
||||
}
|
||||
|
||||
@@ -3632,8 +3638,11 @@ namespace bgfx
|
||||
if (isValid(_handle) )
|
||||
{
|
||||
FrameBufferRef& ref = m_frameBufferRef[_handle.idx];
|
||||
BX_CHECK(ref.m_window, "requestScreenShot can be done only for window frame buffer handles (handle: %d).", _handle.idx); BX_UNUSED(ref);
|
||||
return;
|
||||
if (!ref.m_window)
|
||||
{
|
||||
BX_TRACE("requestScreenShot can be done only for window frame buffer handles (handle: %d).", _handle.idx);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::RequestScreenShot);
|
||||
|
||||
@@ -2081,6 +2081,11 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
}
|
||||
}
|
||||
|
||||
void invalidateOcclusionQuery(OcclusionQueryHandle _handle) BX_OVERRIDE
|
||||
{
|
||||
m_occlusionQuery.invalidate(_handle);
|
||||
}
|
||||
|
||||
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE;
|
||||
|
||||
void blitSetup(TextVideoMemBlitter& _blitter) BX_OVERRIDE
|
||||
@@ -5220,18 +5225,36 @@ BX_PRAGMA_DIAGNOSTIC_POP();
|
||||
{
|
||||
Query& query = m_query[m_control.m_read];
|
||||
|
||||
uint64_t result = 0;
|
||||
HRESULT hr = deviceCtx->GetData(query.m_ptr, &result, sizeof(result), _wait ? 0 : D3D11_ASYNC_GETDATA_DONOTFLUSH);
|
||||
if (S_FALSE == hr)
|
||||
if (isValid(query.m_handle) )
|
||||
{
|
||||
break;
|
||||
uint64_t result = 0;
|
||||
HRESULT hr = deviceCtx->GetData(query.m_ptr, &result, sizeof(result), _wait ? 0 : D3D11_ASYNC_GETDATA_DONOTFLUSH);
|
||||
if (S_FALSE == hr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
_render->m_occlusion[query.m_handle.idx] = 0 < result;
|
||||
}
|
||||
|
||||
_render->m_occlusion[query.m_handle.idx] = 0 < result;
|
||||
m_control.consume(1);
|
||||
}
|
||||
}
|
||||
|
||||
void OcclusionQueryD3D11::invalidate(OcclusionQueryHandle _handle)
|
||||
{
|
||||
const uint32_t size = m_control.m_size;
|
||||
|
||||
for (uint32_t ii = 0, num = m_control.available(); ii < num; ++ii)
|
||||
{
|
||||
Query& query = m_query[(m_control.m_read + ii) % size];
|
||||
if (query.m_handle.idx == _handle.idx)
|
||||
{
|
||||
query.m_handle.idx = bgfx::invalidHandle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RendererContextD3D11::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter)
|
||||
{
|
||||
if (updateResolution(_render->m_resolution) )
|
||||
|
||||
@@ -338,6 +338,7 @@ namespace bgfx { namespace d3d11
|
||||
void begin(Frame* _render, OcclusionQueryHandle _handle);
|
||||
void end();
|
||||
void resolve(Frame* _render, bool _wait = false);
|
||||
void invalidate(OcclusionQueryHandle _handle);
|
||||
|
||||
struct Query
|
||||
{
|
||||
|
||||
@@ -1639,6 +1639,11 @@ namespace bgfx { namespace d3d12
|
||||
{
|
||||
}
|
||||
|
||||
void invalidateOcclusionQuery(OcclusionQueryHandle _handle) BX_OVERRIDE
|
||||
{
|
||||
m_occlusionQuery.invalidate(_handle);
|
||||
}
|
||||
|
||||
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE;
|
||||
|
||||
void blitSetup(TextVideoMemBlitter& _blitter) BX_OVERRIDE
|
||||
@@ -4718,7 +4723,10 @@ data.NumQualityLevels = 0;
|
||||
while (0 == m_control.reserve(1) )
|
||||
{
|
||||
OcclusionQueryHandle handle = m_handle[m_control.m_read];
|
||||
_render->m_occlusion[handle.idx] = 0 < m_result[handle.idx];
|
||||
if (isValid(handle) )
|
||||
{
|
||||
_render->m_occlusion[handle.idx] = 0 < m_result[handle.idx];
|
||||
}
|
||||
m_control.consume(1);
|
||||
}
|
||||
|
||||
@@ -4746,6 +4754,20 @@ data.NumQualityLevels = 0;
|
||||
m_control.commit(1);
|
||||
}
|
||||
|
||||
void OcclusionQueryD3D12::invalidate(OcclusionQueryHandle _handle)
|
||||
{
|
||||
const uint32_t size = m_control.m_size;
|
||||
|
||||
for (uint32_t ii = 0, num = m_control.available(); ii < num; ++ii)
|
||||
{
|
||||
OcclusionQueryHandle& handle = m_handle[(m_control.m_read + ii) % size];
|
||||
if (handle.idx == _handle.idx)
|
||||
{
|
||||
handle.idx = bgfx::invalidHandle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Bind
|
||||
{
|
||||
D3D12_GPU_DESCRIPTOR_HANDLE m_srvHandle;
|
||||
|
||||
@@ -481,6 +481,7 @@ namespace bgfx { namespace d3d12
|
||||
void shutdown();
|
||||
void begin(ID3D12GraphicsCommandList* _commandList, Frame* _render, OcclusionQueryHandle _handle);
|
||||
void end(ID3D12GraphicsCommandList* _commandList);
|
||||
void invalidate(OcclusionQueryHandle _handle);
|
||||
|
||||
ID3D12Resource* m_readback;
|
||||
ID3D12QueryHeap* m_queryHeap;
|
||||
|
||||
@@ -1232,6 +1232,11 @@ namespace bgfx { namespace d3d9
|
||||
BX_UNUSED(_marker, _size);
|
||||
}
|
||||
|
||||
void invalidateOcclusionQuery(OcclusionQueryHandle _handle) BX_OVERRIDE
|
||||
{
|
||||
m_occlusionQuery.invalidate(_handle);
|
||||
}
|
||||
|
||||
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE;
|
||||
|
||||
void blitSetup(TextVideoMemBlitter& _blitter) BX_OVERRIDE
|
||||
@@ -3569,18 +3574,36 @@ namespace bgfx { namespace d3d9
|
||||
{
|
||||
Query& query = m_query[m_control.m_read];
|
||||
|
||||
uint32_t result;
|
||||
HRESULT hr = query.m_ptr->GetData(&result, sizeof(result), 0);
|
||||
if (S_FALSE == hr)
|
||||
if (isValid(query.m_handle) )
|
||||
{
|
||||
break;
|
||||
uint32_t result;
|
||||
HRESULT hr = query.m_ptr->GetData(&result, sizeof(result), 0);
|
||||
if (S_FALSE == hr)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
_render->m_occlusion[query.m_handle.idx] = 0 < result;
|
||||
}
|
||||
|
||||
_render->m_occlusion[query.m_handle.idx] = 0 < result;
|
||||
m_control.consume(1);
|
||||
}
|
||||
}
|
||||
|
||||
void OcclusionQueryD3D9::invalidate(OcclusionQueryHandle _handle)
|
||||
{
|
||||
const uint32_t size = m_control.m_size;
|
||||
|
||||
for (uint32_t ii = 0, num = m_control.available(); ii < num; ++ii)
|
||||
{
|
||||
Query& query = m_query[(m_control.m_read + ii) % size];
|
||||
if (query.m_handle.idx == _handle.idx)
|
||||
{
|
||||
query.m_handle.idx = bgfx::invalidHandle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RendererContextD3D9::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter)
|
||||
{
|
||||
IDirect3DDevice9* device = m_device;
|
||||
|
||||
@@ -468,6 +468,7 @@ namespace bgfx { namespace d3d9
|
||||
void begin(Frame* _render, OcclusionQueryHandle _handle);
|
||||
void end();
|
||||
void resolve(Frame* _render, bool _wait = false);
|
||||
void invalidate(OcclusionQueryHandle _handle);
|
||||
|
||||
struct Query
|
||||
{
|
||||
|
||||
@@ -2584,6 +2584,11 @@ namespace bgfx { namespace gl
|
||||
GL_CHECK(glInsertEventMarker(_size, _marker) );
|
||||
}
|
||||
|
||||
void invalidateOcclusionQuery(OcclusionQueryHandle _handle) BX_OVERRIDE
|
||||
{
|
||||
m_occlusionQuery.invalidate(_handle);
|
||||
}
|
||||
|
||||
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE;
|
||||
|
||||
void blitSetup(TextVideoMemBlitter& _blitter) BX_OVERRIDE
|
||||
@@ -6124,24 +6129,43 @@ namespace bgfx { namespace gl
|
||||
while (0 != m_control.available() )
|
||||
{
|
||||
Query& query = m_query[m_control.m_read];
|
||||
int32_t result;
|
||||
|
||||
if (!_wait)
|
||||
if (isValid(query.m_handle) )
|
||||
{
|
||||
GL_CHECK(glGetQueryObjectiv(query.m_id, GL_QUERY_RESULT_AVAILABLE, &result) );
|
||||
int32_t result;
|
||||
|
||||
if (!result)
|
||||
if (!_wait)
|
||||
{
|
||||
break;
|
||||
GL_CHECK(glGetQueryObjectiv(query.m_id, GL_QUERY_RESULT_AVAILABLE, &result) );
|
||||
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
GL_CHECK(glGetQueryObjectiv(query.m_id, GL_QUERY_RESULT, &result) );
|
||||
_render->m_occlusion[query.m_handle.idx] = 0 < result;
|
||||
}
|
||||
|
||||
GL_CHECK(glGetQueryObjectiv(query.m_id, GL_QUERY_RESULT, &result) );
|
||||
_render->m_occlusion[query.m_handle.idx] = 0 < result;
|
||||
m_control.consume(1);
|
||||
}
|
||||
}
|
||||
|
||||
void OcclusionQueryGL::invalidate(OcclusionQueryHandle _handle)
|
||||
{
|
||||
const uint32_t size = m_control.m_size;
|
||||
|
||||
for (uint32_t ii = 0, num = m_control.available(); ii < num; ++ii)
|
||||
{
|
||||
Query& query = m_query[(m_control.m_read + ii) % size];
|
||||
if (query.m_handle.idx == _handle.idx)
|
||||
{
|
||||
query.m_handle.idx = bgfx::invalidHandle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RendererContextGL::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter)
|
||||
{
|
||||
BGFX_GPU_PROFILER_BEGIN_DYNAMIC("rendererSubmit");
|
||||
|
||||
@@ -1505,6 +1505,7 @@ namespace bgfx { namespace gl
|
||||
void begin(Frame* _render, OcclusionQueryHandle _handle);
|
||||
void end();
|
||||
void resolve(Frame* _render, bool _wait = false);
|
||||
void invalidate(OcclusionQueryHandle _handle);
|
||||
|
||||
struct Query
|
||||
{
|
||||
|
||||
@@ -896,6 +896,7 @@ namespace bgfx { namespace mtl
|
||||
void begin(RenderCommandEncoder& _rce, Frame* _render, OcclusionQueryHandle _handle);
|
||||
void end(RenderCommandEncoder& _rce);
|
||||
void resolve(Frame* _render, bool _wait = false);
|
||||
void invalidate(OcclusionQueryHandle _handle);
|
||||
|
||||
struct Query
|
||||
{
|
||||
|
||||
@@ -970,6 +970,11 @@ namespace bgfx { namespace mtl
|
||||
}
|
||||
}
|
||||
|
||||
void invalidateOcclusionQuery(OcclusionQueryHandle _handle) BX_OVERRIDE
|
||||
{
|
||||
m_occlusionQuery.invalidate(_handle);
|
||||
}
|
||||
|
||||
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE;
|
||||
|
||||
void blitSetup(TextVideoMemBlitter& _blitter) BX_OVERRIDE
|
||||
@@ -1692,7 +1697,6 @@ namespace bgfx { namespace mtl
|
||||
return _visible == (0 != _render->m_occlusion[_handle.idx]);
|
||||
}
|
||||
|
||||
|
||||
BlitCommandEncoder getBlitCommandEncoder()
|
||||
{
|
||||
if ( m_blitCommandEncoder == NULL)
|
||||
@@ -2932,12 +2936,30 @@ namespace bgfx { namespace mtl
|
||||
{
|
||||
Query& query = m_query[m_control.m_read];
|
||||
|
||||
uint64_t result = ( (uint64_t*)m_buffer.contents() )[query.m_handle.idx];
|
||||
_render->m_occlusion[query.m_handle.idx] = 0 < result;
|
||||
if (isValid(query.m_handle) )
|
||||
{
|
||||
uint64_t result = ( (uint64_t*)m_buffer.contents() )[query.m_handle.idx];
|
||||
_render->m_occlusion[query.m_handle.idx] = 0 < result;
|
||||
}
|
||||
|
||||
m_control.consume(1);
|
||||
}
|
||||
}
|
||||
|
||||
void OcclusionQueryMTL::invalidate(OcclusionQueryHandle _handle)
|
||||
{
|
||||
const uint32_t size = m_control.m_size;
|
||||
|
||||
for (uint32_t ii = 0, num = m_control.available(); ii < num; ++ii)
|
||||
{
|
||||
Query& query = m_query[(m_control.m_read + ii) % size];
|
||||
if (query.m_handle.idx == _handle.idx)
|
||||
{
|
||||
query.m_handle.idx = bgfx::invalidHandle;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void RendererContextMtl::submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE
|
||||
{
|
||||
m_cmd.finish(false);
|
||||
|
||||
@@ -193,6 +193,10 @@ namespace bgfx { namespace noop
|
||||
{
|
||||
}
|
||||
|
||||
void invalidateOcclusionQuery(OcclusionQueryHandle /*_handle*/) BX_OVERRIDE
|
||||
{
|
||||
}
|
||||
|
||||
void submit(Frame* /*_render*/, ClearQuad& /*_clearQuad*/, TextVideoMemBlitter& /*_textVideoMemBlitter*/) BX_OVERRIDE
|
||||
{
|
||||
}
|
||||
|
||||
@@ -2118,6 +2118,11 @@ VK_IMPORT_DEVICE
|
||||
{
|
||||
}
|
||||
|
||||
void invalidateOcclusionQuery(OcclusionQueryHandle _handle) BX_OVERRIDE
|
||||
{
|
||||
BX_UNUSED(_handle);
|
||||
}
|
||||
|
||||
void submit(Frame* _render, ClearQuad& _clearQuad, TextVideoMemBlitter& _textVideoMemBlitter) BX_OVERRIDE;
|
||||
|
||||
void blitSetup(TextVideoMemBlitter& /*_blitter*/) BX_OVERRIDE
|
||||
|
||||
Reference in New Issue
Block a user