diff options
Diffstat (limited to '3rdparty/bgfx/src/bgfx_p.h')
-rw-r--r-- | 3rdparty/bgfx/src/bgfx_p.h | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/3rdparty/bgfx/src/bgfx_p.h b/3rdparty/bgfx/src/bgfx_p.h index 02955987eff..e624dba372d 100644 --- a/3rdparty/bgfx/src/bgfx_p.h +++ b/3rdparty/bgfx/src/bgfx_p.h @@ -62,9 +62,9 @@ # define RMT_USE_D3D11 BGFX_CONFIG_RENDERER_DIRECT3D11 # define RMT_USE_OPENGL BGFX_CONFIG_RENDERER_OPENGL # include <remotery/lib/Remotery.h> -# define BGFX_PROFILER_SCOPE(_group, _name, _color) rmt_ScopedCPUSample(_group##_##_name) -# define BGFX_PROFILER_BEGIN(_group, _name, _color) rmt_BeginCPUSample(_group##_##_name) -# define BGFX_PROFILER_BEGIN_DYNAMIC(_namestr) rmt_BeginCPUSampleDynamic(_namestr) +# define BGFX_PROFILER_SCOPE(_group, _name, _color) rmt_ScopedCPUSample(_group##_##_name, RMTSF_None) +# define BGFX_PROFILER_BEGIN(_group, _name, _color) rmt_BeginCPUSample(_group##_##_name, RMTSF_None) +# define BGFX_PROFILER_BEGIN_DYNAMIC(_namestr) rmt_BeginCPUSampleDynamic(_namestr, RMTSF_None) # define BGFX_PROFILER_END() rmt_EndCPUSample() # define BGFX_PROFILER_SET_CURRENT_THREAD_NAME(_name) rmt_SetCurrentThreadName(_name) # else @@ -364,6 +364,19 @@ namespace bgfx ; } + inline uint8_t calcNumMips(uint8_t _numMips, uint16_t _width, uint16_t _height, uint16_t _depth = 1) + { + if (1 < _numMips) + { + const uint32_t max = bx::uint32_max(bx::uint32_max(_width, _height), _depth); + const uint32_t num = 1 + uint32_t(bx::flog2(float(max) ) ); + + return uint8_t(num); + } + + return 1; + } + void dump(const VertexDecl& _decl); struct TextVideoMem @@ -1460,8 +1473,9 @@ namespace bgfx void setState(uint64_t _state, uint32_t _rgba) { uint8_t blend = ( (_state&BGFX_STATE_BLEND_MASK)>>BGFX_STATE_BLEND_SHIFT)&0xff; + uint8_t alphaRef = ( (_state&BGFX_STATE_ALPHA_REF_MASK)>>BGFX_STATE_ALPHA_REF_SHIFT)&0xff; // transparency sort order table - m_key.m_trans = "\x0\x1\x1\x2\x2\x1\x2\x1\x2\x1\x1\x1\x1\x1\x1\x1\x1\x1\x1"[( (blend)&0xf) + (!!blend)]; + m_key.m_trans = "\x0\x2\x2\x3\x3\x2\x3\x2\x3\x2\x2\x2\x2\x2\x2\x2\x2\x2\x2"[( (blend)&0xf) + (!!blend)] + !!alphaRef; m_draw.m_stateFlags = _state; m_draw.m_rgba = _rgba; } @@ -2060,7 +2074,7 @@ namespace bgfx virtual void updateTexture(TextureHandle _handle, uint8_t _side, uint8_t _mip, const Rect& _rect, uint16_t _z, uint16_t _depth, uint16_t _pitch, const Memory* _mem) = 0; virtual void updateTextureEnd() = 0; virtual void readTexture(TextureHandle _handle, void* _data) = 0; - virtual void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height) = 0; + virtual void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips) = 0; virtual void overrideInternal(TextureHandle _handle, uintptr_t _ptr) = 0; virtual uintptr_t getInternal(TextureHandle _handle) = 0; virtual void destroyTexture(TextureHandle _handle) = 0; @@ -2159,6 +2173,7 @@ namespace bgfx resizeTexture(handle , uint16_t(m_resolution.m_width) , uint16_t(m_resolution.m_height) + , textureRef.m_numMips ); m_resolution.m_flags |= BGFX_RESET_INTERNAL_FORCE; } @@ -2626,8 +2641,9 @@ namespace bgfx uint16_t flags = BGFX_BUFFER_NONE; cmdbuf.write(flags); - tib = (TransientIndexBuffer*)BX_ALLOC(g_allocator, sizeof(TransientIndexBuffer)+_size); - tib->data = (uint8_t*)&tib[1]; + const uint32_t size = BX_ALIGN_16(sizeof(TransientIndexBuffer) ) + BX_ALIGN_16(_size); + tib = (TransientIndexBuffer*)BX_ALIGNED_ALLOC(g_allocator, size, 16); + tib->data = (uint8_t *)tib + BX_ALIGN_16(sizeof(TransientIndexBuffer) ); tib->size = _size; tib->handle = handle; } @@ -2641,7 +2657,7 @@ namespace bgfx cmdbuf.write(_tib->handle); m_submit->free(_tib->handle); - BX_FREE(g_allocator, _tib); + BX_ALIGNED_FREE(g_allocator, _tib, 16); } BGFX_API_FUNC(void allocTransientIndexBuffer(TransientIndexBuffer* _tib, uint32_t _num) ) @@ -2682,8 +2698,9 @@ namespace bgfx uint16_t flags = BGFX_BUFFER_NONE; cmdbuf.write(flags); - tvb = (TransientVertexBuffer*)BX_ALLOC(g_allocator, sizeof(TransientVertexBuffer)+_size); - tvb->data = (uint8_t*)&tvb[1]; + const uint32_t size = BX_ALIGN_16(sizeof(TransientVertexBuffer) ) + BX_ALIGN_16(_size); + tvb = (TransientVertexBuffer*)BX_ALIGNED_ALLOC(g_allocator, size, 16); + tvb->data = (uint8_t *)tvb + BX_ALIGN_16(sizeof(TransientVertexBuffer) ); tvb->size = _size; tvb->startVertex = 0; tvb->stride = stride; @@ -2700,7 +2717,7 @@ namespace bgfx cmdbuf.write(_tvb->handle); m_submit->free(_tvb->handle); - BX_FREE(g_allocator, _tvb); + BX_ALIGNED_FREE(g_allocator, _tvb, 16); } BGFX_API_FUNC(void allocTransientVertexBuffer(TransientVertexBuffer* _tvb, uint32_t _num, const VertexDecl& _decl) ) @@ -3104,6 +3121,7 @@ namespace bgfx ref.m_refCount = 1; ref.m_bbRatio = uint8_t(_ratio); ref.m_format = uint8_t(_info->format); + ref.m_numMips = imageContainer.m_numMips; ref.m_owned = false; CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateTexture); @@ -3146,12 +3164,13 @@ namespace bgfx return readTexture(textureHandle, _data); } - void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height) + void resizeTexture(TextureHandle _handle, uint16_t _width, uint16_t _height, uint8_t _numMips) { const TextureRef& textureRef = m_textureRef[_handle.idx]; BX_CHECK(BackbufferRatio::Count != textureRef.m_bbRatio, ""); getTextureSizeFromRatio(BackbufferRatio::Enum(textureRef.m_bbRatio), _width, _height); + _numMips = calcNumMips(_numMips, _width, _height); BX_TRACE("Resize %3d: %4dx%d %s" , _handle.idx @@ -3164,6 +3183,7 @@ namespace bgfx cmdbuf.write(_handle); cmdbuf.write(_width); cmdbuf.write(_height); + cmdbuf.write(_numMips); } void textureTakeOwnership(TextureHandle _handle) @@ -4009,6 +4029,7 @@ namespace bgfx int16_t m_refCount; uint8_t m_bbRatio; uint8_t m_format; + uint8_t m_numMips; bool m_owned; }; |