mirror of
https://github.com/scratchfoundation/bgfx.git
synced 2024-11-28 18:45:54 -05:00
Added ability to run in single-thread mode without rebuild.
This commit is contained in:
parent
ab22eca640
commit
57f61b7e32
2 changed files with 37 additions and 18 deletions
21
src/bgfx.cpp
21
src/bgfx.cpp
|
@ -7,7 +7,7 @@
|
|||
|
||||
namespace bgfx
|
||||
{
|
||||
#define BGFX_MAIN_THREAD_MAGIC 0x78666762
|
||||
#define BGFX_MAIN_THREAD_MAGIC UINT32_C(0x78666762)
|
||||
|
||||
#if BGFX_CONFIG_MULTITHREADED && !BX_PLATFORM_OSX && !BX_PLATFORM_IOS
|
||||
# define BGFX_CHECK_MAIN_THREAD() \
|
||||
|
@ -353,7 +353,6 @@ namespace bgfx
|
|||
|
||||
void blit(RendererContextI* _renderCtx, TextVideoMemBlitter& _blitter, const TextVideoMem& _mem)
|
||||
{
|
||||
BGFX_CHECK_RENDER_THREAD();
|
||||
struct Vertex
|
||||
{
|
||||
float m_x;
|
||||
|
@ -762,6 +761,7 @@ namespace bgfx
|
|||
if (NULL == s_ctx)
|
||||
{
|
||||
s_renderFrameCalled = true;
|
||||
s_threadIndex = ~BGFX_MAIN_THREAD_MAGIC;
|
||||
return RenderFrame::NoContext;
|
||||
}
|
||||
|
||||
|
@ -919,16 +919,21 @@ namespace bgfx
|
|||
// When bgfx::renderFrame is called before init render thread
|
||||
// should not be created.
|
||||
BX_TRACE("Application called bgfx::renderFrame directly, not creating render thread.");
|
||||
m_singleThreaded = ~BGFX_MAIN_THREAD_MAGIC == s_threadIndex;
|
||||
}
|
||||
else
|
||||
{
|
||||
BX_TRACE("Creating rendering thread.");
|
||||
m_thread.init(renderThread, this);
|
||||
m_singleThreaded = false;
|
||||
}
|
||||
#else
|
||||
BX_TRACE("Multithreaded renderer is disabled.");
|
||||
m_singleThreaded = true;
|
||||
#endif // BGFX_CONFIG_MULTITHREADED
|
||||
|
||||
s_threadIndex = BGFX_MAIN_THREAD_MAGIC;
|
||||
|
||||
for (uint32_t ii = 0; ii < BX_COUNTOF(m_viewRemap); ++ii)
|
||||
{
|
||||
m_viewRemap[ii] = uint8_t(ii);
|
||||
|
@ -977,6 +982,10 @@ namespace bgfx
|
|||
g_caps.rendererType = m_renderCtx->getRendererType();
|
||||
initAttribTypeSizeTable(g_caps.rendererType);
|
||||
|
||||
g_caps.supported |= 0
|
||||
| (BX_ENABLED(BGFX_CONFIG_MULTITHREADED) && !m_singleThreaded ? BGFX_CAPS_RENDERER_MULTITHREADED : 0)
|
||||
;
|
||||
|
||||
dumpCaps();
|
||||
|
||||
m_textVideoMemBlitter.init();
|
||||
|
@ -1166,7 +1175,8 @@ namespace bgfx
|
|||
|
||||
bx::xchg(m_render, m_submit);
|
||||
|
||||
if (!BX_ENABLED(BGFX_CONFIG_MULTITHREADED) )
|
||||
if (!BX_ENABLED(BGFX_CONFIG_MULTITHREADED)
|
||||
|| m_singleThreaded)
|
||||
{
|
||||
renderFrame();
|
||||
}
|
||||
|
@ -1986,9 +1996,6 @@ again:
|
|||
BX_TRACE("Init...");
|
||||
|
||||
memset(&g_caps, 0, sizeof(g_caps) );
|
||||
g_caps.supported = 0
|
||||
| (BGFX_CONFIG_MULTITHREADED ? BGFX_CAPS_RENDERER_MULTITHREADED : 0)
|
||||
;
|
||||
g_caps.maxViews = BGFX_CONFIG_MAX_VIEWS;
|
||||
g_caps.maxDrawCalls = BGFX_CONFIG_MAX_DRAW_CALLS;
|
||||
g_caps.maxFBAttachments = 1;
|
||||
|
@ -2016,8 +2023,6 @@ again:
|
|||
s_callbackStub = BX_NEW(g_allocator, CallbackStub);
|
||||
}
|
||||
|
||||
s_threadIndex = BGFX_MAIN_THREAD_MAGIC;
|
||||
|
||||
s_ctx = BX_ALIGNED_NEW(g_allocator, Context, 16);
|
||||
s_ctx->init(_type);
|
||||
|
||||
|
|
14
src/bgfx_p.h
14
src/bgfx_p.h
|
@ -1910,6 +1910,7 @@ namespace bgfx
|
|||
, m_rendererInitialized(false)
|
||||
, m_exit(false)
|
||||
, m_flipAfterRender(false)
|
||||
, m_singleThreaded(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -3445,30 +3446,42 @@ namespace bgfx
|
|||
|
||||
#if BGFX_CONFIG_MULTITHREADED
|
||||
void gameSemPost()
|
||||
{
|
||||
if (!m_singleThreaded)
|
||||
{
|
||||
m_gameSem.post();
|
||||
}
|
||||
}
|
||||
|
||||
void gameSemWait()
|
||||
{
|
||||
if (!m_singleThreaded)
|
||||
{
|
||||
int64_t start = bx::getHPCounter();
|
||||
bool ok = m_gameSem.wait();
|
||||
BX_CHECK(ok, "Semaphore wait failed."); BX_UNUSED(ok);
|
||||
m_render->m_waitSubmit = bx::getHPCounter()-start;
|
||||
}
|
||||
}
|
||||
|
||||
void renderSemPost()
|
||||
{
|
||||
if (!m_singleThreaded)
|
||||
{
|
||||
m_renderSem.post();
|
||||
}
|
||||
}
|
||||
|
||||
void renderSemWait()
|
||||
{
|
||||
if (!m_singleThreaded)
|
||||
{
|
||||
int64_t start = bx::getHPCounter();
|
||||
bool ok = m_renderSem.wait();
|
||||
BX_CHECK(ok, "Semaphore wait failed."); BX_UNUSED(ok);
|
||||
m_submit->m_waitRender = bx::getHPCounter() - start;
|
||||
}
|
||||
}
|
||||
|
||||
bx::Semaphore m_renderSem;
|
||||
bx::Semaphore m_gameSem;
|
||||
|
@ -3598,6 +3611,7 @@ namespace bgfx
|
|||
bool m_rendererInitialized;
|
||||
bool m_exit;
|
||||
bool m_flipAfterRender;
|
||||
bool m_singleThreaded;
|
||||
|
||||
typedef UpdateBatchT<256> TextureUpdateBatch;
|
||||
BX_ALIGN_DECL_CACHE_LINE(TextureUpdateBatch m_textureUpdateBatch);
|
||||
|
|
Loading…
Reference in a new issue