mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 03:44:02 +02:00
IMprove the counting and namoing of the new couters the gl swapchain
This commit is contained in:
parent
6b2b68e691
commit
507d3e5a39
11 changed files with 64 additions and 35 deletions
|
@ -229,7 +229,7 @@ Item {
|
|||
text: " Count: " + root.gpuTextures;
|
||||
}
|
||||
StatText {
|
||||
text: "GL Context FBO Memory: " + root.glContextFBOMemory + " MB";
|
||||
text: "GL Swapchain Memory: " + root.glContextSwapchainMemory + " MB";
|
||||
}
|
||||
StatText {
|
||||
text: "QML Texture Memory: " + root.qmlTextureMemory + " MB";
|
||||
|
|
|
@ -289,7 +289,9 @@ 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(glContextSwapchainMemory, (int)BYTES_TO_MB(gl::Context::getSwapchainMemoryUsage()));
|
||||
|
||||
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,7 +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, glContextSwapchainMemory, 0)
|
||||
STATS_PROPERTY(int, qmlTextureMemory, 0)
|
||||
STATS_PROPERTY(int, gpuTextureMemory, 0)
|
||||
STATS_PROPERTY(int, gpuTextureVirtualMemory, 0)
|
||||
|
@ -183,7 +183,7 @@ signals:
|
|||
void localInternalChanged();
|
||||
void localLeavesChanged();
|
||||
void timingStatsChanged();
|
||||
void glContextFBOMemoryChanged();
|
||||
void glContextSwapchainMemoryChanged();
|
||||
void qmlTextureMemoryChanged();
|
||||
void gpuBuffersChanged();
|
||||
void gpuTexturesChanged();
|
||||
|
|
|
@ -41,22 +41,22 @@ static bool enableDebugLogger = QProcessEnvironment::systemEnvironment().contain
|
|||
using namespace gl;
|
||||
|
||||
|
||||
std::atomic<size_t> Context::_defaultFBOMemoryUsage { 0 };
|
||||
std::atomic<size_t> Context::_totalSwapchainMemoryUsage { 0 };
|
||||
|
||||
size_t Context::getDefaultFBOMemoryUsage() { return _defaultFBOMemoryUsage.load(); }
|
||||
size_t Context::getSwapchainMemoryUsage() { return _totalSwapchainMemoryUsage.load(); }
|
||||
|
||||
size_t Context::evalMemoryUsage(uint32_t width, uint32_t height) {
|
||||
return width * height * 4;
|
||||
size_t Context::evalSurfaceMemoryUsage(uint32_t width, uint32_t height, uint32_t pixelSize) {
|
||||
return width * height * pixelSize;
|
||||
}
|
||||
|
||||
void Context::updateDefaultFBOMemoryUsage(size_t prevFBOSize, size_t newFBOSize) {
|
||||
if (prevFBOSize == newFBOSize) {
|
||||
void Context::updateSwapchainMemoryUsage(size_t prevSize, size_t newSize) {
|
||||
if (prevSize == newSize) {
|
||||
return;
|
||||
}
|
||||
if (newFBOSize > prevFBOSize) {
|
||||
_defaultFBOMemoryUsage.fetch_add(newFBOSize - prevFBOSize);
|
||||
if (newSize > prevSize) {
|
||||
_totalSwapchainMemoryUsage.fetch_add(newSize - prevSize);
|
||||
} else {
|
||||
_defaultFBOMemoryUsage.fetch_sub(prevFBOSize - newFBOSize);
|
||||
_totalSwapchainMemoryUsage.fetch_sub(prevSize - newSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,18 +99,35 @@ void Context::release() {
|
|||
if (PRIMARY == this) {
|
||||
PRIMARY = nullptr;
|
||||
}
|
||||
}
|
||||
updateSwapchainMemoryCounter();
|
||||
}
|
||||
|
||||
Context::~Context() {
|
||||
release();
|
||||
}
|
||||
|
||||
void Context::updateSwapchainMemoryCounter() {
|
||||
if (_window) {
|
||||
auto newSize = _window->size();
|
||||
auto newMemSize = gl::Context::evalSurfaceMemoryUsage(newSize.width(), newSize.height(), _swapchainPixelSize);
|
||||
gl::Context::updateSwapchainMemoryUsage(_swapchainMemoryUsage, newMemSize);
|
||||
_swapchainMemoryUsage = newMemSize;
|
||||
} else {
|
||||
// No window ? no more swapchain
|
||||
gl::Context::updateSwapchainMemoryUsage(_swapchainMemoryUsage, 0);
|
||||
_swapchainMemoryUsage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Context::setWindow(QWindow* window) {
|
||||
release();
|
||||
_window = window;
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
_hwnd = (HWND)window->winId();
|
||||
#endif
|
||||
|
||||
updateSwapchainMemoryCounter();
|
||||
}
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
|
@ -119,6 +136,8 @@ static const char* PRIMARY_CONTEXT_PROPERTY_NAME = "com.highfidelity.gl.primaryC
|
|||
bool Context::makeCurrent() {
|
||||
BOOL result = wglMakeCurrent(_hdc, _hglrc);
|
||||
assert(result);
|
||||
updateSwapchainMemoryCounter();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -238,6 +257,10 @@ void Context::create() {
|
|||
wglChoosePixelFormatARB(_hdc, &formatAttribs[0], NULL, 1, &pixelFormat, &numFormats);
|
||||
DescribePixelFormat(_hdc, pixelFormat, sizeof(pfd), &pfd);
|
||||
}
|
||||
// The swap chain pixel size for swap chains is : rgba32 * double buffer + depth24stencil8
|
||||
_swapchainPixelSize = 32 * 2 + 32;
|
||||
updateSwapchainMemoryCounter();
|
||||
|
||||
SetPixelFormat(_hdc, pixelFormat, &pfd);
|
||||
{
|
||||
std::vector<int> contextAttribs;
|
||||
|
|
|
@ -59,12 +59,16 @@ namespace gl {
|
|||
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);
|
||||
static size_t evalSurfaceMemoryUsage(uint32_t width, uint32_t height, uint32_t pixelSize);
|
||||
static size_t getSwapchainMemoryUsage();
|
||||
static void updateSwapchainMemoryUsage(size_t prevSize, size_t newSize);
|
||||
|
||||
private:
|
||||
static std::atomic<size_t> _defaultFBOMemoryUsage;
|
||||
static std::atomic<size_t> _totalSwapchainMemoryUsage;
|
||||
|
||||
size_t _swapchainMemoryUsage { 0 };
|
||||
size_t _swapchainPixelSize { 0 };
|
||||
void updateSwapchainMemoryCounter();
|
||||
};
|
||||
|
||||
class OffscreenContext : public Context {
|
||||
|
|
|
@ -45,6 +45,7 @@ void Context::moveToThread(QThread* thread) {
|
|||
|
||||
#ifndef Q_OS_WIN
|
||||
bool Context::makeCurrent() {
|
||||
updateSwapchainMemoryCounter();
|
||||
return _context->makeCurrent(_window);
|
||||
}
|
||||
|
||||
|
@ -70,6 +71,9 @@ void Context::create() {
|
|||
}
|
||||
_context->setFormat(getDefaultOpenGLSurfaceFormat());
|
||||
_context->create();
|
||||
|
||||
_swapchainPixelSize = evalGLFormatSwapchainPixelSize(_context->format());
|
||||
updateSwapchainMemoryCounter();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -13,6 +13,15 @@
|
|||
|
||||
#include <QtOpenGL/QGL>
|
||||
|
||||
size_t evalGLFormatSwapchainPixelSize(const QSurfaceFormat& format) {
|
||||
size_t pixelSize = format.redBufferSize() + format.greenBufferSize() + format.blueBufferSize() + format.alphaBufferSize();
|
||||
if (format.swapBehavior() > 0) {
|
||||
pixelSize *= format.swapBehavior(); // multiply the color buffer pixel size by the actual swapchain depth
|
||||
}
|
||||
pixelSize += format.stencilBufferSize() + format.depthBufferSize();
|
||||
return pixelSize;
|
||||
}
|
||||
|
||||
const QSurfaceFormat& getDefaultOpenGLSurfaceFormat() {
|
||||
static QSurfaceFormat format;
|
||||
static std::once_flag once;
|
||||
|
|
|
@ -26,6 +26,8 @@ class QGLFormat;
|
|||
template<class F>
|
||||
void setGLFormatVersion(F& format, int major = 4, int minor = 5) { format.setVersion(major, minor); }
|
||||
|
||||
size_t evalGLFormatSwapchainPixelSize(const QSurfaceFormat& format);
|
||||
|
||||
const QSurfaceFormat& getDefaultOpenGLSurfaceFormat();
|
||||
QJsonObject getGLContextData();
|
||||
int glVersionToInteger(QString glVersion);
|
||||
|
|
|
@ -24,8 +24,7 @@
|
|||
|
||||
OffscreenGLCanvas::OffscreenGLCanvas() :
|
||||
_context(new QOpenGLContext),
|
||||
_offscreenSurface(new QOffscreenSurface),
|
||||
_offscreenSurfaceCurrentMemoryUsage(0)
|
||||
_offscreenSurface(new QOffscreenSurface)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -35,8 +34,6 @@ OffscreenGLCanvas::~OffscreenGLCanvas() {
|
|||
delete _context;
|
||||
_context = nullptr;
|
||||
|
||||
gl::Context::updateDefaultFBOMemoryUsage(_offscreenSurfaceCurrentMemoryUsage, 0);
|
||||
|
||||
_offscreenSurface->destroy();
|
||||
delete _offscreenSurface;
|
||||
_offscreenSurface = nullptr;
|
||||
|
@ -60,15 +57,6 @@ 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);
|
||||
|
@ -79,8 +67,6 @@ bool OffscreenGLCanvas::makeCurrent() {
|
|||
qCDebug(glLogging) << "GL Renderer: " << QString((const char*) glGetString(GL_RENDERER));
|
||||
});
|
||||
|
||||
updateMemoryCounter();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,6 @@ protected:
|
|||
std::once_flag _reportOnce;
|
||||
QOpenGLContext* _context{ nullptr };
|
||||
QOffscreenSurface* _offscreenSurface{ nullptr };
|
||||
size_t _offscreenSurfaceCurrentMemoryUsage { 0 };
|
||||
void updateMemoryCounter();
|
||||
};
|
||||
|
||||
#endif // hifi_OffscreenGLCanvas_h
|
||||
|
|
|
@ -186,6 +186,7 @@ GLTexture::~GLTexture() {
|
|||
Backend::updateTextureGPUFramebufferMemoryUsage(_size, 0);
|
||||
}
|
||||
}
|
||||
Backend::updateTextureGPUVirtualMemoryUsage(_virtualSize, 0);
|
||||
}
|
||||
|
||||
void GLTexture::createTexture() {
|
||||
|
|
Loading…
Reference in a new issue