From ef3ad2bdd123f57916057dceaab23dd926f58f21 Mon Sep 17 00:00:00 2001 From: Pierre-Eric Pelloux-Prayer Date: Thu, 20 Jun 2019 20:56:38 +0200 Subject: [PATCH] Fix gpudrivenrendering example on Linux Skip the first frame because the content of m_drawcallInstanceCounts is uninitialized, and the atomicAdd used in RENDER_PASS_OCCLUDE_PROPS_ID can produce random results. Fixes #1794 --- examples/37-gpudrivenrendering/gpudrivenrendering.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/examples/37-gpudrivenrendering/gpudrivenrendering.cpp b/examples/37-gpudrivenrendering/gpudrivenrendering.cpp index fec214a0f..ec7b2f247 100644 --- a/examples/37-gpudrivenrendering/gpudrivenrendering.cpp +++ b/examples/37-gpudrivenrendering/gpudrivenrendering.cpp @@ -695,6 +695,7 @@ public: m_timeOffset = bx::getHPCounter(); m_useIndirect = true; + m_firstFrame = true; imguiCreate(); } @@ -823,7 +824,7 @@ public: bgfx::setTexture(0, s_texOcclusionDepth, getTexture(m_hiZDepthBuffer, 0)); bgfx::setImage(1, getTexture(m_hiZBuffer, 0), 0, bgfx::Access::Write); - + bgfx::dispatch(RENDER_PASS_HIZ_DOWNSCALE_ID, m_programCopyZ, width/16, height/16); } @@ -916,7 +917,9 @@ public: // Set "material" data (currently a color only) bgfx::setUniform(u_color, &m_materials[0].m_color, m_noofMaterials); - if (m_useIndirect) + // We can't use indirect drawing for the first frame because the content of m_drawcallInstanceCounts + // is initially undefined. + if (m_useIndirect && !m_firstFrame) { // Set vertex and index buffer. bgfx::setVertexBuffer(0, m_allPropsVertexbufferHandle); @@ -967,6 +970,7 @@ public: } } } + m_firstFrame = false; } bool update() override @@ -1131,6 +1135,7 @@ public: uint8_t m_noofHiZMips; bool m_useIndirect; + bool m_firstFrame; Camera m_camera; Mouse m_mouse;