From 6adb0090d0a72ba89d76a64cd56525972c55dfd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Branimir=20Karad=C5=BEi=C4=87?= Date: Sun, 3 Dec 2017 19:42:06 -0800 Subject: [PATCH] Added resource stats. --- examples/common/example-glue.cpp | 22 ++++++++++++ include/bgfx/bgfx.h | 58 +++++++++++++++++++------------- include/bgfx/c99/bgfx.h | 12 +++++++ include/bgfx/defines.h | 2 +- src/bgfx_p.h | 13 +++++++ 5 files changed, 83 insertions(+), 24 deletions(-) diff --git a/examples/common/example-glue.cpp b/examples/common/example-glue.cpp index 6bc2a9124..8224ea67d 100644 --- a/examples/common/example-glue.cpp +++ b/examples/common/example-glue.cpp @@ -151,6 +151,8 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText) const char* items[bgfx::RendererType::Count]; int32_t current = 0; + + for (uint8_t ii = 0; ii < num; ++ii) { items[ii] = bgfx::getRendererName(supportedRenderers[ii]); @@ -218,6 +220,26 @@ void showExampleDialog(entry::AppI* _app, const char* _errorText) ImGui::Text("GPU mem: %s / %s", tmp0, tmp1); } + if (ImGui::CollapsingHeader("Resources") ) + { + const bgfx::Caps* caps = bgfx::getCaps(); + + ImGui::PushFont(ImGui::Font::Mono); + ImGui::Text("Res: Num / Max"); + ImGui::Text("DIB: %4d / %4d", stats->numDynamicIndexBuffers, caps->limits.maxDynamicIndexBuffers); + ImGui::Text("DVB: %4d / %4d", stats->numDynamicVertexBuffers, caps->limits.maxDynamicVertexBuffers); + ImGui::Text(" FB: %4d / %4d", stats->numFrameBuffers, caps->limits.maxFrameBuffers); + ImGui::Text(" IB: %4d / %4d", stats->numIndexBuffers, caps->limits.maxIndexBuffers); + ImGui::Text(" OQ: %4d / %4d", stats->numOcclusionQueries, caps->limits.maxOcclusionQueries); + ImGui::Text(" P: %4d / %4d", stats->numPrograms, caps->limits.maxPrograms); + ImGui::Text(" S: %4d / %4d", stats->numShaders, caps->limits.maxShaders); + ImGui::Text(" T: %4d / %4d", stats->numTextures, caps->limits.maxTextures); + ImGui::Text(" U: %4d / %4d", stats->numUniforms, caps->limits.maxUniforms); + ImGui::Text(" VB: %4d / %4d", stats->numVertexBuffers, caps->limits.maxVertexBuffers); + ImGui::Text(" VD: %4d / %4d", stats->numVertexDecls, caps->limits.maxVertexDecls); + ImGui::PopFont(); + } + if (0 != stats->numViews) { if (ImGui::CollapsingHeader(ICON_FA_CLOCK_O " Profiler") ) diff --git a/include/bgfx/bgfx.h b/include/bgfx/bgfx.h index 1d9cf9c66..182f4984d 100644 --- a/include/bgfx/bgfx.h +++ b/include/bgfx/bgfx.h @@ -805,36 +805,48 @@ namespace bgfx /// struct Stats { - int64_t cpuTimeFrame; //!< CPU time between two `bgfx::frame` calls. - int64_t cpuTimeBegin; //!< Render thread CPU submit begin time. - int64_t cpuTimeEnd; //!< Render thread CPU submit end time. - int64_t cpuTimerFreq; //!< CPU timer frequency. + int64_t cpuTimeFrame; //!< CPU time between two `bgfx::frame` calls. + int64_t cpuTimeBegin; //!< Render thread CPU submit begin time. + int64_t cpuTimeEnd; //!< Render thread CPU submit end time. + int64_t cpuTimerFreq; //!< CPU timer frequency. - int64_t gpuTimeBegin; //!< GPU frame begin time. - int64_t gpuTimeEnd; //!< GPU frame end time. - int64_t gpuTimerFreq; //!< GPU timer frequency. + int64_t gpuTimeBegin; //!< GPU frame begin time. + int64_t gpuTimeEnd; //!< GPU frame end time. + int64_t gpuTimerFreq; //!< GPU timer frequency. - int64_t waitRender; //!< Time spent waiting for render backend thread to finish issuing - //! draw commands to underlying graphics API. - int64_t waitSubmit; //!< Time spent waiting for submit thread to advance to next frame. + int64_t waitRender; //!< Time spent waiting for render backend thread to finish issuing + //! draw commands to underlying graphics API. + int64_t waitSubmit; //!< Time spent waiting for submit thread to advance to next frame. - uint32_t numDraw; //!< Number of draw calls submitted. - uint32_t numCompute; //!< Number of compute calls submitted. - uint32_t maxGpuLatency; //!< GPU driver latency. + uint32_t numDraw; //!< Number of draw calls submitted. + uint32_t numCompute; //!< Number of compute calls submitted. + uint32_t maxGpuLatency; //!< GPU driver latency. - int64_t gpuMemoryMax; //!< Maximum available GPU memory for application. - int64_t gpuMemoryUsed; //!< Amount of GPU memory used. + uint16_t numDynamicIndexBuffers; //!< + uint16_t numDynamicVertexBuffers; //!< + uint16_t numFrameBuffers; //!< + uint16_t numIndexBuffers; //!< + uint16_t numOcclusionQueries; //!< + uint16_t numPrograms; //!< + uint16_t numShaders; //!< + uint16_t numTextures; //!< + uint16_t numUniforms; //!< + uint16_t numVertexBuffers; //!< + uint16_t numVertexDecls; //!< - uint16_t width; //!< Backbuffer width in pixels. - uint16_t height; //!< Backbuffer height in pixels. - uint16_t textWidth; //!< Debug text width in characters. - uint16_t textHeight; //!< Debug text height in characters. + int64_t gpuMemoryMax; //!< Maximum available GPU memory for application. + int64_t gpuMemoryUsed; //!< Amount of GPU memory used. - uint16_t numViews; //!< Number of view stats. - ViewStats* viewStats; //!< View stats. + uint16_t width; //!< Backbuffer width in pixels. + uint16_t height; //!< Backbuffer height in pixels. + uint16_t textWidth; //!< Debug text width in characters. + uint16_t textHeight; //!< Debug text height in characters. - uint8_t numEncoders; //!< Number of encoders used during frame. - EncoderStats* encoderStats; //!< Encoder stats. + uint16_t numViews; //!< Number of view stats. + ViewStats* viewStats; //!< View stats. + + uint8_t numEncoders; //!< Number of encoders used during frame. + EncoderStats* encoderStats; //!< Encoder stats. }; /// Encoder for submitting draw calls from multiple threads. Use `bgfx::begin()` diff --git a/include/bgfx/c99/bgfx.h b/include/bgfx/c99/bgfx.h index 33bce5be5..d5119f2f5 100644 --- a/include/bgfx/c99/bgfx.h +++ b/include/bgfx/c99/bgfx.h @@ -374,6 +374,18 @@ typedef struct bgfx_stats uint32_t numCompute; uint32_t maxGpuLatency; + uint16_t numDynamicIndexBuffers; + uint16_t numDynamicVertexBuffers; + uint16_t numFrameBuffers; + uint16_t numIndexBuffers; + uint16_t numOcclusionQueries; + uint16_t numPrograms; + uint16_t numShaders; + uint16_t numTextures; + uint16_t numUniforms; + uint16_t numVertexBuffers; + uint16_t numVertexDecls; + int64_t gpuMemoryMax; int64_t gpuMemoryUsed; diff --git a/include/bgfx/defines.h b/include/bgfx/defines.h index a111c486a..e5f28d226 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(58) +#define BGFX_API_VERSION UINT32_C(59) /// Color RGB/alpha/depth write. When it's not specified write will be disabled. #define BGFX_STATE_RGB_WRITE UINT64_C(0x0000000000000001) //!< Enable RGB write. diff --git a/src/bgfx_p.h b/src/bgfx_p.h index 1b784602c..ec1fc6880 100644 --- a/src/bgfx_p.h +++ b/src/bgfx_p.h @@ -2722,6 +2722,19 @@ namespace bgfx stats.textWidth = tvm->m_width; stats.textHeight = tvm->m_height; stats.encoderStats = m_encoderStats; + + stats.numDynamicIndexBuffers = m_dynamicIndexBufferHandle.getNumHandles(); + stats.numDynamicVertexBuffers = m_dynamicVertexBufferHandle.getNumHandles(); + stats.numFrameBuffers = m_frameBufferHandle.getNumHandles(); + stats.numIndexBuffers = m_indexBufferHandle.getNumHandles(); + stats.numOcclusionQueries = m_occlusionQueryHandle.getNumHandles(); + stats.numPrograms = m_programHandle.getNumHandles(); + stats.numShaders = m_shaderHandle.getNumHandles(); + stats.numTextures = m_textureHandle.getNumHandles(); + stats.numUniforms = m_uniformHandle.getNumHandles(); + stats.numVertexBuffers = m_vertexBufferHandle.getNumHandles(); + stats.numVertexDecls = m_vertexDeclHandle.getNumHandles(); + return &stats; }