diff --git a/3rdparty/bgfx/README.md b/3rdparty/bgfx/README.md index 19c0a07167a..2b444eb809f 100644 --- a/3rdparty/bgfx/README.md +++ b/3rdparty/bgfx/README.md @@ -115,6 +115,8 @@ C++ and using bgfx to support multiple rendering APIs. http://makingartstudios.itch.io/dls - DLS the digital logic simulator game. ![dls-screenshot](https://img.itch.io/aW1hZ2UvMzk3MTgvMTc5MjQ4LnBuZw==/original/kA%2FQPb.png) +https://github.com/mamedev/mame MAME - Multiple Arcade Machine Emulator + [Building](https://bkaradzic.github.io/bgfx/build.html) ------------------------------------------------------- diff --git a/3rdparty/bgfx/examples/common/imgui/imgui.cpp b/3rdparty/bgfx/examples/common/imgui/imgui.cpp index 3bc68d3d61d..2655e6ce0a1 100644 --- a/3rdparty/bgfx/examples/common/imgui/imgui.cpp +++ b/3rdparty/bgfx/examples/common/imgui/imgui.cpp @@ -468,7 +468,7 @@ struct Imgui IMGUI_create(_data, _size, _fontSize, m_allocator); - m_nvg = nvgCreate(1, m_view); + m_nvg = nvgCreate(1, m_view, m_allocator); nvgCreateFontMem(m_nvg, "default", (unsigned char*)_data, INT32_MAX, 0); nvgFontSize(m_nvg, _fontSize); nvgFontFace(m_nvg, "default"); diff --git a/3rdparty/bgfx/examples/common/nanovg/nanovg.h b/3rdparty/bgfx/examples/common/nanovg/nanovg.h index 1f55dcd3f70..692d1bd2be8 100644 --- a/3rdparty/bgfx/examples/common/nanovg/nanovg.h +++ b/3rdparty/bgfx/examples/common/nanovg/nanovg.h @@ -598,8 +598,10 @@ struct NVGparams { }; typedef struct NVGparams NVGparams; -NVGcontext* nvgCreate(int edgeaa, unsigned char viewid); -void nvgViewId(struct NVGcontext* ctx, unsigned char viewid); +namespace bx { struct AllocatorI; } + +NVGcontext* nvgCreate(int edgeaa, unsigned char _viewId, bx::AllocatorI* _allocator = NULL); +void nvgViewId(struct NVGcontext* ctx, unsigned char _viewId); void nvgDelete(struct NVGcontext* ctx); // Constructor and destructor, called by the render back-end. diff --git a/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp b/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp index fc276ff32fd..1da34bd790f 100644 --- a/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp +++ b/3rdparty/bgfx/examples/common/nanovg/nanovg_bgfx.cpp @@ -23,14 +23,13 @@ #define NVG_ANTIALIAS 1 #include -#include -#include #include #include "nanovg.h" #include #include +#include BX_PRAGMA_DIAGNOSTIC_IGNORED_MSVC(4244); // warning C4244: '=' : conversion from '' to '', possible loss of data @@ -113,6 +112,8 @@ namespace struct GLNVGcontext { + bx::AllocatorI* m_allocator; + bgfx::ProgramHandle prog; bgfx::UniformHandle u_scissorMat; bgfx::UniformHandle u_paintMat; @@ -131,7 +132,7 @@ namespace bgfx::TextureHandle texMissing; bgfx::TransientVertexBuffer tvb; - uint8_t viewid; + uint8_t m_viewId; struct GLNVGtexture* textures; float view[2]; @@ -177,7 +178,7 @@ namespace { int old = gl->ctextures; gl->ctextures = (gl->ctextures == 0) ? 2 : gl->ctextures*2; - gl->textures = (struct GLNVGtexture*)realloc(gl->textures, sizeof(struct GLNVGtexture)*gl->ctextures); + gl->textures = (struct GLNVGtexture*)BX_REALLOC(gl->m_allocator, gl->textures, sizeof(struct GLNVGtexture)*gl->ctextures); memset(&gl->textures[old], 0xff, (gl->ctextures-old)*sizeof(struct GLNVGtexture) ); if (gl->textures == NULL) @@ -548,7 +549,7 @@ namespace struct GLNVGcontext* gl = (struct GLNVGcontext*)_userPtr; gl->view[0] = (float)width; gl->view[1] = (float)height; - bgfx::setViewRect(gl->viewid, 0, 0, width, height); + bgfx::setViewRect(gl->m_viewId, 0, 0, width, height); } static void fan(uint32_t _start, uint32_t _count) @@ -596,7 +597,7 @@ namespace bgfx::setVertexBuffer(&gl->tvb); bgfx::setTexture(0, gl->s_tex, gl->th); fan(paths[i].fillOffset, paths[i].fillCount); - bgfx::submit(gl->viewid, gl->prog); + bgfx::submit(gl->m_viewId, gl->prog); } } @@ -620,7 +621,7 @@ namespace ); bgfx::setVertexBuffer(&gl->tvb, paths[i].strokeOffset, paths[i].strokeCount); bgfx::setTexture(0, gl->s_tex, gl->th); - bgfx::submit(gl->viewid, gl->prog); + bgfx::submit(gl->m_viewId, gl->prog); } } @@ -635,7 +636,7 @@ namespace | BGFX_STENCIL_OP_FAIL_Z_ZERO | BGFX_STENCIL_OP_PASS_Z_ZERO ); - bgfx::submit(gl->viewid, gl->prog); + bgfx::submit(gl->m_viewId, gl->prog); } static void glnvg__convexFill(struct GLNVGcontext* gl, struct GLNVGcall* call) @@ -652,7 +653,7 @@ namespace bgfx::setVertexBuffer(&gl->tvb); bgfx::setTexture(0, gl->s_tex, gl->th); fan(paths[i].fillOffset, paths[i].fillCount); - bgfx::submit(gl->viewid, gl->prog); + bgfx::submit(gl->m_viewId, gl->prog); } if (gl->edgeAntiAlias) @@ -665,7 +666,7 @@ namespace ); bgfx::setVertexBuffer(&gl->tvb, paths[i].strokeOffset, paths[i].strokeCount); bgfx::setTexture(0, gl->s_tex, gl->th); - bgfx::submit(gl->viewid, gl->prog); + bgfx::submit(gl->m_viewId, gl->prog); } } } @@ -685,7 +686,7 @@ namespace ); bgfx::setVertexBuffer(&gl->tvb, paths[i].strokeOffset, paths[i].strokeCount); bgfx::setTexture(0, gl->s_tex, gl->th); - bgfx::submit(gl->viewid, gl->prog); + bgfx::submit(gl->m_viewId, gl->prog); } } @@ -698,7 +699,7 @@ namespace bgfx::setState(gl->state); bgfx::setVertexBuffer(&gl->tvb, call->vertexOffset, call->vertexCount); bgfx::setTexture(0, gl->s_tex, gl->th); - bgfx::submit(gl->viewid, gl->prog); + bgfx::submit(gl->m_viewId, gl->prog); } } @@ -791,7 +792,7 @@ namespace if (gl->ncalls+1 > gl->ccalls) { gl->ccalls = gl->ccalls == 0 ? 32 : gl->ccalls * 2; - gl->calls = (struct GLNVGcall*)realloc(gl->calls, sizeof(struct GLNVGcall) * gl->ccalls); + gl->calls = (struct GLNVGcall*)BX_REALLOC(gl->m_allocator, gl->calls, sizeof(struct GLNVGcall) * gl->ccalls); } ret = &gl->calls[gl->ncalls++]; memset(ret, 0, sizeof(struct GLNVGcall) ); @@ -804,7 +805,7 @@ namespace if (gl->npaths + n > gl->cpaths) { GLNVGpath* paths; int cpaths = glnvg__maxi(gl->npaths + n, 128) + gl->cpaths / 2; // 1.5x Overallocate - paths = (GLNVGpath*)realloc(gl->paths, sizeof(GLNVGpath) * cpaths); + paths = (GLNVGpath*)BX_REALLOC(gl->m_allocator, gl->paths, sizeof(GLNVGpath) * cpaths); if (paths == NULL) return -1; gl->paths = paths; gl->cpaths = cpaths; @@ -821,7 +822,7 @@ namespace { NVGvertex* verts; int cverts = glnvg__maxi(gl->nverts + n, 4096) + gl->cverts/2; // 1.5x Overallocate - verts = (NVGvertex*)realloc(gl->verts, sizeof(NVGvertex) * cverts); + verts = (NVGvertex*)BX_REALLOC(gl->m_allocator, gl->verts, sizeof(NVGvertex) * cverts); if (verts == NULL) return -1; gl->verts = verts; gl->cverts = cverts; @@ -837,7 +838,7 @@ namespace if (gl->nuniforms+n > gl->cuniforms) { gl->cuniforms = gl->cuniforms == 0 ? glnvg__maxi(n, 32) : gl->cuniforms * 2; - gl->uniforms = (unsigned char*)realloc(gl->uniforms, gl->cuniforms * structSize); + gl->uniforms = (unsigned char*)BX_REALLOC(gl->m_allocator, gl->uniforms, gl->cuniforms * structSize); } ret = gl->nuniforms * structSize; gl->nuniforms += n; @@ -1023,18 +1024,32 @@ namespace } } - free(gl->textures); - - free(gl); + BX_FREE(gl->m_allocator, gl->uniforms); + BX_FREE(gl->m_allocator, gl->verts); + BX_FREE(gl->m_allocator, gl->paths); + BX_FREE(gl->m_allocator, gl->calls); + BX_FREE(gl->m_allocator, gl->textures); + BX_FREE(gl->m_allocator, gl); } } // namespace -NVGcontext* nvgCreate(int edgeaa, unsigned char viewid) +NVGcontext* nvgCreate(int edgeaa, unsigned char _viewId, bx::AllocatorI* _allocator) { + if (NULL == _allocator) + { +#if BX_CONFIG_ALLOCATOR_CRT + static bx::CrtAllocator allocator; + _allocator = &allocator; +#else + BX_CHECK(false, "No allocator has been passed to nvgCreate(). Either specify a bx::AllocatorI instance or enable BX_CONFIG_ALLOCATOR_CRT directive."); + return NULL; +#endif // BX_CONFIG_ALLOCATOR_CRT + } + struct NVGparams params; struct NVGcontext* ctx = NULL; - struct GLNVGcontext* gl = (struct GLNVGcontext*)malloc(sizeof(struct GLNVGcontext) ); + struct GLNVGcontext* gl = (struct GLNVGcontext*)BX_ALLOC(_allocator, sizeof(struct GLNVGcontext) ); if (gl == NULL) goto error; memset(gl, 0, sizeof(struct GLNVGcontext) ); @@ -1053,8 +1068,9 @@ NVGcontext* nvgCreate(int edgeaa, unsigned char viewid) params.userPtr = gl; params.edgeAntiAlias = edgeaa; + gl->m_allocator = _allocator; gl->edgeAntiAlias = edgeaa; - gl->viewid = uint8_t(viewid); + gl->m_viewId = uint8_t(_viewId); ctx = nvgCreateInternal(¶ms); if (ctx == NULL) goto error; @@ -1071,11 +1087,11 @@ error: return NULL; } -void nvgViewId(struct NVGcontext* ctx, unsigned char viewid) +void nvgViewId(struct NVGcontext* ctx, unsigned char _viewId) { struct NVGparams* params = nvgInternalParams(ctx); struct GLNVGcontext* gl = (struct GLNVGcontext*)params->userPtr; - gl->viewid = uint8_t(viewid); + gl->m_viewId = uint8_t(_viewId); } void nvgDelete(struct NVGcontext* ctx) diff --git a/3rdparty/bgfx/src/bgfx_p.h b/3rdparty/bgfx/src/bgfx_p.h index 9e4e5a17184..594310d284f 100644 --- a/3rdparty/bgfx/src/bgfx_p.h +++ b/3rdparty/bgfx/src/bgfx_p.h @@ -925,6 +925,10 @@ namespace bgfx float* toPtr(uint32_t _cacheIdx) { + BX_CHECK(_cacheIdx < BGFX_CONFIG_MAX_MATRIX_CACHE, "Matrix cache out of bounds index %d (max: %d)" + , _cacheIdx + , BGFX_CONFIG_MAX_MATRIX_CACHE + ); return m_cache[_cacheIdx].un.val; } @@ -1493,8 +1497,12 @@ namespace bgfx void setTransform(uint32_t _cache, uint16_t _num) { + BX_CHECK(_cache < BGFX_CONFIG_MAX_MATRIX_CACHE, "Matrix cache out of bounds index %d (max: %d)" + , _cache + , BGFX_CONFIG_MAX_MATRIX_CACHE + ); m_draw.m_matrix = _cache; - m_draw.m_num = _num; + m_draw.m_num = uint16_t(bx::uint32_min(_cache+_num, BGFX_CONFIG_MAX_MATRIX_CACHE-1) - _cache); } void setIndexBuffer(IndexBufferHandle _handle, uint32_t _firstIndex, uint32_t _numIndices) diff --git a/3rdparty/bgfx/src/renderer_d3d11.cpp b/3rdparty/bgfx/src/renderer_d3d11.cpp index 1e36af03985..5bacc5561d4 100644 --- a/3rdparty/bgfx/src/renderer_d3d11.cpp +++ b/3rdparty/bgfx/src/renderer_d3d11.cpp @@ -3397,7 +3397,6 @@ BX_PRAGMA_DIAGNOSTIC_POP(); void* m_uniforms[BGFX_CONFIG_MAX_UNIFORMS]; Matrix4 m_predefinedUniforms[PredefinedUniform::Count]; UniformRegistry m_uniformReg; - ViewState m_viewState; StateCacheT m_blendStateCache; StateCacheT m_depthStencilStateCache; @@ -4729,8 +4728,7 @@ BX_PRAGMA_DIAGNOSTIC_POP(); _render->m_hmdInitialized = m_ovr.isInitialized(); const bool hmdEnabled = m_ovr.isEnabled() || m_ovr.isDebug(); - ViewState& viewState = m_viewState; - viewState.reset(_render, hmdEnabled); + ViewState viewState(_render, hmdEnabled); bool wireframe = !!(_render->m_debug&BGFX_DEBUG_WIREFRAME); bool scissorEnabled = false; diff --git a/3rdparty/bgfx/src/renderer_gl.cpp b/3rdparty/bgfx/src/renderer_gl.cpp index be4ab0a09d7..ff6184ccc98 100644 --- a/3rdparty/bgfx/src/renderer_gl.cpp +++ b/3rdparty/bgfx/src/renderer_gl.cpp @@ -2389,7 +2389,10 @@ namespace bgfx { namespace gl if (BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGL) || BX_ENABLED(BGFX_CONFIG_RENDERER_OPENGLES >= 30) ) { - GL_CHECK(glBindSampler(0, 0) ); + if (m_samplerObjectSupport) + { + GL_CHECK(glBindSampler(0, 0) ); + } } } } diff --git a/3rdparty/bx/include/bx/allocator.h b/3rdparty/bx/include/bx/allocator.h index 3a6ca4f6e26..50d526535b6 100644 --- a/3rdparty/bx/include/bx/allocator.h +++ b/3rdparty/bx/include/bx/allocator.h @@ -13,7 +13,7 @@ #include #if BX_CONFIG_ALLOCATOR_CRT -# include +# include #endif // BX_CONFIG_ALLOCATOR_CRT #if BX_CONFIG_ALLOCATOR_DEBUG diff --git a/3rdparty/bx/include/bx/thread.h b/3rdparty/bx/include/bx/thread.h index fb9e07df6f8..015bd57eff8 100644 --- a/3rdparty/bx/include/bx/thread.h +++ b/3rdparty/bx/include/bx/thread.h @@ -8,6 +8,9 @@ #if BX_PLATFORM_POSIX # include +# if defined(__GLIBC__) && !( (__GLIBC__ > 2) || ( (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12) ) ) +# include +# endif // defined(__GLIBC__) ... #elif BX_PLATFORM_WINRT using namespace Platform; using namespace Windows::Foundation; @@ -149,7 +152,13 @@ namespace bx { #if BX_PLATFORM_OSX || BX_PLATFORM_IOS pthread_setname_np(_name); -#elif (BX_PLATFORM_LINUX && defined(__GLIBC__)) || BX_PLATFORM_BSD +#elif BX_PLATFORM_LINUX +# if defined(__GLIBC__) && (__GLIBC__ > 2) || ( (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 12) ) + pthread_setname_np(m_handle, _name); +# else + prctl(PR_SET_NAME,_name, 0, 0, 0); +# endif // defined(__GLIBC__) ... +#elif BX_PLATFORM_BSD pthread_setname_np(m_handle, _name); #elif BX_PLATFORM_WINDOWS && BX_COMPILER_MSVC # pragma pack(push, 8)