From e5031c589773e8c190fc471037e1c293fbe30f4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Wed, 28 Mar 2018 18:05:49 -0700 Subject: [PATCH] Added texture&rt memory stats. --- include/bgfx/bgfx.h | 3 ++ include/bgfx/c99/bgfx.h | 3 ++ include/bgfx/defines.h | 2 +- src/bgfx_p.h | 64 +++++++++++++++++++++++++++++++---------- 4 files changed, 56 insertions(+), 16 deletions(-) diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index 1d387778e..c212984f7 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -838,6 +838,9 @@ namespace bgfx uint16_t numVertexBuffers; //!< Number of used vertex buffers. uint16_t numVertexDecls; //!< Number of used vertex declarations. + int64_t textureMemoryUsed; //!< + int64_t rtMemoryUsed; //!< + int64_t gpuMemoryMax; //!< Maximum available GPU memory for application. int64_t gpuMemoryUsed; //!< Amount of GPU memory used by the application. diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index 2be14a0f9..700130d8b 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -386,6 +386,9 @@ typedef struct bgfx_stats uint16_t numVertexBuffers; uint16_t numVertexDecls; + int64_t textureMemoryUsed; + int64_t rtMemoryUsed; + int64_t gpuMemoryMax; int64_t gpuMemoryUsed; diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index 74a2ac70e..c8fdc9808 100644 --- a/include/bgfx/defines.h +++ b/include/bgfx/defines.h @@ -6,7 +6,7 @@ #ifndef BGFX_DEFINES_H_HEADER_GUARD #define BGFX_DEFINES_H_HEADER_GUARD -#define BGFX_API_VERSION UINT32_C(63) +#define BGFX_API_VERSION UINT32_C(64) /// Color RGB/alpha/depth write. When it's not specified write will be disabled. #define BGFX_STATE_WRITE_R UINT64_C(0x0000000000000001) //!< Enable R write. diff --git a/src/bgfx_p.h b/src/bgfx_p.h index d5b6c346a..c1fe72886 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -2679,6 +2679,8 @@ namespace bgfx , m_colorPaletteDirty(0) , m_frames(0) , m_debug(BGFX_DEBUG_NONE) + , m_rtMemoryUsed(0) + , m_textureMemoryUsed(0) , m_renderCtx(NULL) , m_renderMain(NULL) , m_renderNoop(NULL) @@ -2819,6 +2821,9 @@ namespace bgfx stats.numVertexBuffers = m_vertexBufferHandle.getNumHandles(); stats.numVertexDecls = m_vertexDeclHandle.getNumHandles(); + stats.textureMemoryUsed = m_textureMemoryUsed; + stats.rtMemoryUsed = m_rtMemoryUsed; + return &stats; } @@ -3869,11 +3874,22 @@ namespace bgfx TextureRef& ref = m_textureRef[handle.idx]; ref.init(_ratio , _info->format + , _info->storageSize , imageContainer.m_numMips , 0 != (g_caps.supported & BGFX_CAPS_TEXTURE_DIRECT_ACCESS) , _immutable + , 0 != (_flags & BGFX_TEXTURE_RT_MASK) ); + if (ref.m_rt) + { + m_rtMemoryUsed += int64_t(ref.m_storageSize); + } + else + { + m_textureMemoryUsed += int64_t(ref.m_storageSize); + } + CommandBuffer& cmdbuf = getCommandBuffer(CommandBuffer::CreateTexture); cmdbuf.write(handle); cmdbuf.write(_mem); @@ -3991,6 +4007,15 @@ namespace bgfx { ref.m_name.clear(); + if (ref.m_rt) + { + m_rtMemoryUsed -= int64_t(ref.m_storageSize); + } + else + { + m_textureMemoryUsed -= int64_t(ref.m_storageSize); + } + bool ok = m_submit->free(_handle); BX_UNUSED(ok); BX_CHECK(ok, "Texture handle %d is already destroyed!", _handle.idx); @@ -4648,28 +4673,34 @@ namespace bgfx void init( BackbufferRatio::Enum _ratio , TextureFormat::Enum _format + , uint32_t _storageSize , uint8_t _numMips , bool _ptrPending , bool _immutable + , bool _rt ) { - m_ptr = _ptrPending ? (void*)UINTPTR_MAX : NULL; - m_refCount = 1; - m_bbRatio = uint8_t(_ratio); - m_format = uint8_t(_format); - m_numMips = _numMips; - m_owned = false; - m_immutable = _immutable; + m_ptr = _ptrPending ? (void*)UINTPTR_MAX : NULL; + m_storageSize = _storageSize; + m_refCount = 1; + m_bbRatio = uint8_t(_ratio); + m_format = uint8_t(_format); + m_numMips = _numMips; + m_owned = false; + m_immutable = _immutable; + m_rt = _rt; } - String m_name; - void* m_ptr; - int16_t m_refCount; - uint8_t m_bbRatio; - uint8_t m_format; - uint8_t m_numMips; - bool m_owned; - bool m_immutable; + String m_name; + void* m_ptr; + uint32_t m_storageSize; + int16_t m_refCount; + uint8_t m_bbRatio; + uint8_t m_format; + uint8_t m_numMips; + bool m_owned; + bool m_immutable; + bool m_rt; }; struct FrameBufferRef @@ -4711,6 +4742,9 @@ namespace bgfx uint32_t m_frames; uint32_t m_debug; + int64_t m_rtMemoryUsed; + int64_t m_textureMemoryUsed; + TextVideoMemBlitter m_textVideoMemBlitter; ClearQuad m_clearQuad;