mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 16:55:07 +02:00
trying to add counters for the default FBO
This commit is contained in:
parent
58b81e3b0c
commit
6b2b68e691
7 changed files with 62 additions and 3 deletions
|
@ -228,6 +228,9 @@ Item {
|
|||
StatText {
|
||||
text: " Count: " + root.gpuTextures;
|
||||
}
|
||||
StatText {
|
||||
text: "GL Context FBO Memory: " + root.glContextFBOMemory + " MB";
|
||||
}
|
||||
StatText {
|
||||
text: "QML Texture Memory: " + root.qmlTextureMemory + " MB";
|
||||
}
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
#include <PerfStat.h>
|
||||
#include <plugins/DisplayPlugin.h>
|
||||
|
||||
#include <gl/Context.h>
|
||||
|
||||
#include "BandwidthRecorder.h"
|
||||
#include "Menu.h"
|
||||
#include "Util.h"
|
||||
|
@ -287,6 +289,7 @@ void Stats::updateStats(bool force) {
|
|||
STAT_UPDATE(gpuBuffers, (int)gpu::Context::getBufferGPUCount());
|
||||
STAT_UPDATE(gpuTextures, (int)gpu::Context::getTextureGPUCount());
|
||||
STAT_UPDATE(gpuTexturesSparse, (int)gpu::Context::getTextureGPUSparseCount());
|
||||
STAT_UPDATE(glContextFBOMemory, (int)BYTES_TO_MB(gl::Context::getDefaultFBOMemoryUsage()));
|
||||
STAT_UPDATE(qmlTextureMemory, (int)BYTES_TO_MB(OffscreenQmlSurface::getUsedTextureMemory()));
|
||||
STAT_UPDATE(gpuTextureMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUMemoryUsage()));
|
||||
STAT_UPDATE(gpuTextureVirtualMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUVirtualMemoryUsage()));
|
||||
|
|
|
@ -90,6 +90,7 @@ class Stats : public QQuickItem {
|
|||
STATS_PROPERTY(int, gpuBuffers, 0)
|
||||
STATS_PROPERTY(int, gpuTextures, 0)
|
||||
STATS_PROPERTY(int, gpuTexturesSparse, 0)
|
||||
STATS_PROPERTY(int, glContextFBOMemory, 0)
|
||||
STATS_PROPERTY(int, qmlTextureMemory, 0)
|
||||
STATS_PROPERTY(int, gpuTextureMemory, 0)
|
||||
STATS_PROPERTY(int, gpuTextureVirtualMemory, 0)
|
||||
|
@ -182,6 +183,7 @@ signals:
|
|||
void localInternalChanged();
|
||||
void localLeavesChanged();
|
||||
void timingStatsChanged();
|
||||
void glContextFBOMemoryChanged();
|
||||
void qmlTextureMemoryChanged();
|
||||
void gpuBuffersChanged();
|
||||
void gpuTexturesChanged();
|
||||
|
|
|
@ -40,6 +40,27 @@ static bool enableDebugLogger = QProcessEnvironment::systemEnvironment().contain
|
|||
|
||||
using namespace gl;
|
||||
|
||||
|
||||
std::atomic<size_t> Context::_defaultFBOMemoryUsage { 0 };
|
||||
|
||||
size_t Context::getDefaultFBOMemoryUsage() { return _defaultFBOMemoryUsage.load(); }
|
||||
|
||||
size_t Context::evalMemoryUsage(uint32_t width, uint32_t height) {
|
||||
return width * height * 4;
|
||||
}
|
||||
|
||||
void Context::updateDefaultFBOMemoryUsage(size_t prevFBOSize, size_t newFBOSize) {
|
||||
if (prevFBOSize == newFBOSize) {
|
||||
return;
|
||||
}
|
||||
if (newFBOSize > prevFBOSize) {
|
||||
_defaultFBOMemoryUsage.fetch_add(newFBOSize - prevFBOSize);
|
||||
} else {
|
||||
_defaultFBOMemoryUsage.fetch_sub(prevFBOSize - newFBOSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Context* Context::PRIMARY = nullptr;
|
||||
|
||||
Context::Context() {}
|
||||
|
@ -277,6 +298,8 @@ void OffscreenContext::create() {
|
|||
_window->setSurfaceType(QSurface::OpenGLSurface);
|
||||
_window->create();
|
||||
setWindow(_window);
|
||||
QSize windowSize = _window->size() * _window->devicePixelRatio();
|
||||
qCDebug(glLogging) << "New Offscreen GLContext, window size = " << windowSize.width() << " , " << windowSize.height();
|
||||
QGuiApplication::processEvents();
|
||||
}
|
||||
Parent::create();
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
|
||||
#include <stdint.h>
|
||||
#include <QtGlobal>
|
||||
#include <atomic>
|
||||
|
||||
#if defined(Q_OS_WIN)
|
||||
#include <Windows.h>
|
||||
|
@ -23,7 +24,7 @@ class QThread;
|
|||
|
||||
namespace gl {
|
||||
|
||||
class Context {
|
||||
class Context {
|
||||
protected:
|
||||
QWindow* _window { nullptr };
|
||||
static Context* PRIMARY;
|
||||
|
@ -57,6 +58,13 @@ class Context {
|
|||
virtual void create();
|
||||
QOpenGLContext* qglContext();
|
||||
void moveToThread(QThread* thread);
|
||||
|
||||
static size_t getDefaultFBOMemoryUsage();
|
||||
static size_t evalMemoryUsage(uint32_t width, uint32_t height);
|
||||
static void updateDefaultFBOMemoryUsage(size_t prevFBOSize, size_t newFBOSize);
|
||||
|
||||
private:
|
||||
static std::atomic<size_t> _defaultFBOMemoryUsage;
|
||||
};
|
||||
|
||||
class OffscreenContext : public Context {
|
||||
|
@ -67,6 +75,7 @@ class Context {
|
|||
virtual ~OffscreenContext();
|
||||
void create() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // hifi_gpu_GPUConfig_h
|
||||
|
|
|
@ -17,11 +17,16 @@
|
|||
#include <QtGui/QOffscreenSurface>
|
||||
#include <QtGui/QOpenGLContext>
|
||||
|
||||
#include "Context.h"
|
||||
#include "GLHelpers.h"
|
||||
#include "GLLogging.h"
|
||||
|
||||
|
||||
OffscreenGLCanvas::OffscreenGLCanvas() : _context(new QOpenGLContext), _offscreenSurface(new QOffscreenSurface){
|
||||
OffscreenGLCanvas::OffscreenGLCanvas() :
|
||||
_context(new QOpenGLContext),
|
||||
_offscreenSurface(new QOffscreenSurface),
|
||||
_offscreenSurfaceCurrentMemoryUsage(0)
|
||||
{
|
||||
}
|
||||
|
||||
OffscreenGLCanvas::~OffscreenGLCanvas() {
|
||||
|
@ -30,6 +35,8 @@ OffscreenGLCanvas::~OffscreenGLCanvas() {
|
|||
delete _context;
|
||||
_context = nullptr;
|
||||
|
||||
gl::Context::updateDefaultFBOMemoryUsage(_offscreenSurfaceCurrentMemoryUsage, 0);
|
||||
|
||||
_offscreenSurface->destroy();
|
||||
delete _offscreenSurface;
|
||||
_offscreenSurface = nullptr;
|
||||
|
@ -53,10 +60,18 @@ bool OffscreenGLCanvas::create(QOpenGLContext* sharedContext) {
|
|||
return false;
|
||||
}
|
||||
|
||||
void OffscreenGLCanvas::updateMemoryCounter() {
|
||||
if (_offscreenSurface) {
|
||||
auto newSize =_offscreenSurface->size();
|
||||
auto newMemSize = gl::Context::evalMemoryUsage(newSize.width(), newSize.height());
|
||||
gl::Context::updateDefaultFBOMemoryUsage(_offscreenSurfaceCurrentMemoryUsage, newMemSize);
|
||||
_offscreenSurfaceCurrentMemoryUsage = newMemSize;
|
||||
}
|
||||
}
|
||||
|
||||
bool OffscreenGLCanvas::makeCurrent() {
|
||||
bool result = _context->makeCurrent(_offscreenSurface);
|
||||
Q_ASSERT(result);
|
||||
|
||||
std::call_once(_reportOnce, [this]{
|
||||
qCDebug(glLogging) << "GL Version: " << QString((const char*) glGetString(GL_VERSION));
|
||||
qCDebug(glLogging) << "GL Shader Language Version: " << QString((const char*) glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||
|
@ -64,6 +79,8 @@ bool OffscreenGLCanvas::makeCurrent() {
|
|||
qCDebug(glLogging) << "GL Renderer: " << QString((const char*) glGetString(GL_RENDERER));
|
||||
});
|
||||
|
||||
updateMemoryCounter();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,8 @@ protected:
|
|||
std::once_flag _reportOnce;
|
||||
QOpenGLContext* _context{ nullptr };
|
||||
QOffscreenSurface* _offscreenSurface{ nullptr };
|
||||
size_t _offscreenSurfaceCurrentMemoryUsage { 0 };
|
||||
void updateMemoryCounter();
|
||||
};
|
||||
|
||||
#endif // hifi_OffscreenGLCanvas_h
|
||||
|
|
Loading…
Reference in a new issue