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
|
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
|
#if BGFX_CONFIG_MULTITHREADED && !BX_PLATFORM_OSX && !BX_PLATFORM_IOS
|
||||||
# define BGFX_CHECK_MAIN_THREAD() \
|
# define BGFX_CHECK_MAIN_THREAD() \
|
||||||
|
@ -353,7 +353,6 @@ namespace bgfx
|
||||||
|
|
||||||
void blit(RendererContextI* _renderCtx, TextVideoMemBlitter& _blitter, const TextVideoMem& _mem)
|
void blit(RendererContextI* _renderCtx, TextVideoMemBlitter& _blitter, const TextVideoMem& _mem)
|
||||||
{
|
{
|
||||||
BGFX_CHECK_RENDER_THREAD();
|
|
||||||
struct Vertex
|
struct Vertex
|
||||||
{
|
{
|
||||||
float m_x;
|
float m_x;
|
||||||
|
@ -762,6 +761,7 @@ namespace bgfx
|
||||||
if (NULL == s_ctx)
|
if (NULL == s_ctx)
|
||||||
{
|
{
|
||||||
s_renderFrameCalled = true;
|
s_renderFrameCalled = true;
|
||||||
|
s_threadIndex = ~BGFX_MAIN_THREAD_MAGIC;
|
||||||
return RenderFrame::NoContext;
|
return RenderFrame::NoContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -919,16 +919,21 @@ namespace bgfx
|
||||||
// When bgfx::renderFrame is called before init render thread
|
// When bgfx::renderFrame is called before init render thread
|
||||||
// should not be created.
|
// should not be created.
|
||||||
BX_TRACE("Application called bgfx::renderFrame directly, not creating render thread.");
|
BX_TRACE("Application called bgfx::renderFrame directly, not creating render thread.");
|
||||||
|
m_singleThreaded = ~BGFX_MAIN_THREAD_MAGIC == s_threadIndex;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
BX_TRACE("Creating rendering thread.");
|
BX_TRACE("Creating rendering thread.");
|
||||||
m_thread.init(renderThread, this);
|
m_thread.init(renderThread, this);
|
||||||
|
m_singleThreaded = false;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
BX_TRACE("Multithreaded renderer is disabled.");
|
BX_TRACE("Multithreaded renderer is disabled.");
|
||||||
|
m_singleThreaded = true;
|
||||||
#endif // BGFX_CONFIG_MULTITHREADED
|
#endif // BGFX_CONFIG_MULTITHREADED
|
||||||
|
|
||||||
|
s_threadIndex = BGFX_MAIN_THREAD_MAGIC;
|
||||||
|
|
||||||
for (uint32_t ii = 0; ii < BX_COUNTOF(m_viewRemap); ++ii)
|
for (uint32_t ii = 0; ii < BX_COUNTOF(m_viewRemap); ++ii)
|
||||||
{
|
{
|
||||||
m_viewRemap[ii] = uint8_t(ii);
|
m_viewRemap[ii] = uint8_t(ii);
|
||||||
|
@ -977,6 +982,10 @@ namespace bgfx
|
||||||
g_caps.rendererType = m_renderCtx->getRendererType();
|
g_caps.rendererType = m_renderCtx->getRendererType();
|
||||||
initAttribTypeSizeTable(g_caps.rendererType);
|
initAttribTypeSizeTable(g_caps.rendererType);
|
||||||
|
|
||||||
|
g_caps.supported |= 0
|
||||||
|
| (BX_ENABLED(BGFX_CONFIG_MULTITHREADED) && !m_singleThreaded ? BGFX_CAPS_RENDERER_MULTITHREADED : 0)
|
||||||
|
;
|
||||||
|
|
||||||
dumpCaps();
|
dumpCaps();
|
||||||
|
|
||||||
m_textVideoMemBlitter.init();
|
m_textVideoMemBlitter.init();
|
||||||
|
@ -1166,7 +1175,8 @@ namespace bgfx
|
||||||
|
|
||||||
bx::xchg(m_render, m_submit);
|
bx::xchg(m_render, m_submit);
|
||||||
|
|
||||||
if (!BX_ENABLED(BGFX_CONFIG_MULTITHREADED) )
|
if (!BX_ENABLED(BGFX_CONFIG_MULTITHREADED)
|
||||||
|
|| m_singleThreaded)
|
||||||
{
|
{
|
||||||
renderFrame();
|
renderFrame();
|
||||||
}
|
}
|
||||||
|
@ -1986,9 +1996,6 @@ again:
|
||||||
BX_TRACE("Init...");
|
BX_TRACE("Init...");
|
||||||
|
|
||||||
memset(&g_caps, 0, sizeof(g_caps) );
|
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.maxViews = BGFX_CONFIG_MAX_VIEWS;
|
||||||
g_caps.maxDrawCalls = BGFX_CONFIG_MAX_DRAW_CALLS;
|
g_caps.maxDrawCalls = BGFX_CONFIG_MAX_DRAW_CALLS;
|
||||||
g_caps.maxFBAttachments = 1;
|
g_caps.maxFBAttachments = 1;
|
||||||
|
@ -2016,8 +2023,6 @@ again:
|
||||||
s_callbackStub = BX_NEW(g_allocator, CallbackStub);
|
s_callbackStub = BX_NEW(g_allocator, CallbackStub);
|
||||||
}
|
}
|
||||||
|
|
||||||
s_threadIndex = BGFX_MAIN_THREAD_MAGIC;
|
|
||||||
|
|
||||||
s_ctx = BX_ALIGNED_NEW(g_allocator, Context, 16);
|
s_ctx = BX_ALIGNED_NEW(g_allocator, Context, 16);
|
||||||
s_ctx->init(_type);
|
s_ctx->init(_type);
|
||||||
|
|
||||||
|
|
34
src/bgfx_p.h
34
src/bgfx_p.h
|
@ -1910,6 +1910,7 @@ namespace bgfx
|
||||||
, m_rendererInitialized(false)
|
, m_rendererInitialized(false)
|
||||||
, m_exit(false)
|
, m_exit(false)
|
||||||
, m_flipAfterRender(false)
|
, m_flipAfterRender(false)
|
||||||
|
, m_singleThreaded(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3446,28 +3447,40 @@ namespace bgfx
|
||||||
#if BGFX_CONFIG_MULTITHREADED
|
#if BGFX_CONFIG_MULTITHREADED
|
||||||
void gameSemPost()
|
void gameSemPost()
|
||||||
{
|
{
|
||||||
m_gameSem.post();
|
if (!m_singleThreaded)
|
||||||
|
{
|
||||||
|
m_gameSem.post();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void gameSemWait()
|
void gameSemWait()
|
||||||
{
|
{
|
||||||
int64_t start = bx::getHPCounter();
|
if (!m_singleThreaded)
|
||||||
bool ok = m_gameSem.wait();
|
{
|
||||||
BX_CHECK(ok, "Semaphore wait failed."); BX_UNUSED(ok);
|
int64_t start = bx::getHPCounter();
|
||||||
m_render->m_waitSubmit = bx::getHPCounter()-start;
|
bool ok = m_gameSem.wait();
|
||||||
|
BX_CHECK(ok, "Semaphore wait failed."); BX_UNUSED(ok);
|
||||||
|
m_render->m_waitSubmit = bx::getHPCounter()-start;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderSemPost()
|
void renderSemPost()
|
||||||
{
|
{
|
||||||
m_renderSem.post();
|
if (!m_singleThreaded)
|
||||||
|
{
|
||||||
|
m_renderSem.post();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void renderSemWait()
|
void renderSemWait()
|
||||||
{
|
{
|
||||||
int64_t start = bx::getHPCounter();
|
if (!m_singleThreaded)
|
||||||
bool ok = m_renderSem.wait();
|
{
|
||||||
BX_CHECK(ok, "Semaphore wait failed."); BX_UNUSED(ok);
|
int64_t start = bx::getHPCounter();
|
||||||
m_submit->m_waitRender = bx::getHPCounter() - start;
|
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_renderSem;
|
||||||
|
@ -3598,6 +3611,7 @@ namespace bgfx
|
||||||
bool m_rendererInitialized;
|
bool m_rendererInitialized;
|
||||||
bool m_exit;
|
bool m_exit;
|
||||||
bool m_flipAfterRender;
|
bool m_flipAfterRender;
|
||||||
|
bool m_singleThreaded;
|
||||||
|
|
||||||
typedef UpdateBatchT<256> TextureUpdateBatch;
|
typedef UpdateBatchT<256> TextureUpdateBatch;
|
||||||
BX_ALIGN_DECL_CACHE_LINE(TextureUpdateBatch m_textureUpdateBatch);
|
BX_ALIGN_DECL_CACHE_LINE(TextureUpdateBatch m_textureUpdateBatch);
|
||||||
|
|
Loading…
Reference in a new issue