mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 20:15:15 +02:00
Merge pull request #8901 from samcake/blue
Adding more detailed counters for texture memory consumption
This commit is contained in:
commit
001cfc7e15
15 changed files with 138 additions and 6 deletions
|
@ -215,6 +215,9 @@ Item {
|
|||
StatText {
|
||||
text: " Commited Memory: " + root.gpuTextureMemory + " MB";
|
||||
}
|
||||
StatText {
|
||||
text: " Framebuffer Memory: " + root.gpuTextureFramebufferMemory + " MB";
|
||||
}
|
||||
StatText {
|
||||
text: " Sparse Memory: " + root.gpuTextureSparseMemory + " MB";
|
||||
visible: 0 != root.gpuSparseTextureEnabled;
|
||||
|
@ -225,6 +228,9 @@ Item {
|
|||
StatText {
|
||||
text: " Count: " + root.gpuTextures;
|
||||
}
|
||||
StatText {
|
||||
text: "GL Swapchain Memory: " + root.glContextSwapchainMemory + " 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"
|
||||
|
@ -289,9 +291,13 @@ 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(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()));
|
||||
STAT_UPDATE(gpuTextureFramebufferMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUFramebufferMemoryUsage()));
|
||||
STAT_UPDATE(gpuTextureSparseMemory, (int)BYTES_TO_MB(gpu::Texture::getTextureGPUSparseMemoryUsage()));
|
||||
STAT_UPDATE(gpuSparseTextureEnabled, gpu::Texture::getEnableSparseTextures() ? 1 : 0);
|
||||
STAT_UPDATE(gpuFreeMemory, (int)BYTES_TO_MB(gpu::Context::getFreeGPUMemory()));
|
||||
|
|
|
@ -90,9 +90,11 @@ class Stats : public QQuickItem {
|
|||
STATS_PROPERTY(int, gpuBuffers, 0)
|
||||
STATS_PROPERTY(int, gpuTextures, 0)
|
||||
STATS_PROPERTY(int, gpuTexturesSparse, 0)
|
||||
STATS_PROPERTY(int, glContextSwapchainMemory, 0)
|
||||
STATS_PROPERTY(int, qmlTextureMemory, 0)
|
||||
STATS_PROPERTY(int, gpuTextureMemory, 0)
|
||||
STATS_PROPERTY(int, gpuTextureVirtualMemory, 0)
|
||||
STATS_PROPERTY(int, gpuTextureFramebufferMemory, 0)
|
||||
STATS_PROPERTY(int, gpuTextureSparseMemory, 0)
|
||||
STATS_PROPERTY(int, gpuSparseTextureEnabled, 0)
|
||||
STATS_PROPERTY(int, gpuFreeMemory, 0)
|
||||
|
@ -181,12 +183,14 @@ signals:
|
|||
void localInternalChanged();
|
||||
void localLeavesChanged();
|
||||
void timingStatsChanged();
|
||||
void glContextSwapchainMemoryChanged();
|
||||
void qmlTextureMemoryChanged();
|
||||
void gpuBuffersChanged();
|
||||
void gpuTexturesChanged();
|
||||
void gpuTexturesSparseChanged();
|
||||
void gpuTextureMemoryChanged();
|
||||
void gpuTextureVirtualMemoryChanged();
|
||||
void gpuTextureFramebufferMemoryChanged();
|
||||
void gpuTextureSparseMemoryChanged();
|
||||
void gpuSparseTextureEnabledChanged();
|
||||
void gpuFreeMemoryChanged();
|
||||
|
|
|
@ -40,6 +40,27 @@ static bool enableDebugLogger = QProcessEnvironment::systemEnvironment().contain
|
|||
|
||||
using namespace gl;
|
||||
|
||||
|
||||
std::atomic<size_t> Context::_totalSwapchainMemoryUsage { 0 };
|
||||
|
||||
size_t Context::getSwapchainMemoryUsage() { return _totalSwapchainMemoryUsage.load(); }
|
||||
|
||||
size_t Context::evalSurfaceMemoryUsage(uint32_t width, uint32_t height, uint32_t pixelSize) {
|
||||
return width * height * pixelSize;
|
||||
}
|
||||
|
||||
void Context::updateSwapchainMemoryUsage(size_t prevSize, size_t newSize) {
|
||||
if (prevSize == newSize) {
|
||||
return;
|
||||
}
|
||||
if (newSize > prevSize) {
|
||||
_totalSwapchainMemoryUsage.fetch_add(newSize - prevSize);
|
||||
} else {
|
||||
_totalSwapchainMemoryUsage.fetch_sub(prevSize - newSize);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Context* Context::PRIMARY = nullptr;
|
||||
|
||||
Context::Context() {}
|
||||
|
@ -78,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(), (uint32_t) _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
|
||||
|
@ -98,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;
|
||||
}
|
||||
|
||||
|
@ -217,6 +257,11 @@ 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 + depth24stencil8
|
||||
// We don't apply the length of the swap chain into this pixelSize since it is not vsible for the Process (on windows).
|
||||
_swapchainPixelSize = 32 + 32;
|
||||
updateSwapchainMemoryCounter();
|
||||
|
||||
SetPixelFormat(_hdc, pixelFormat, &pfd);
|
||||
{
|
||||
std::vector<int> contextAttribs;
|
||||
|
@ -277,6 +322,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,17 @@ class Context {
|
|||
virtual void create();
|
||||
QOpenGLContext* qglContext();
|
||||
void moveToThread(QThread* thread);
|
||||
|
||||
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> _totalSwapchainMemoryUsage;
|
||||
|
||||
size_t _swapchainMemoryUsage { 0 };
|
||||
size_t _swapchainPixelSize { 0 };
|
||||
void updateSwapchainMemoryCounter();
|
||||
};
|
||||
|
||||
class OffscreenContext : public Context {
|
||||
|
@ -67,6 +79,7 @@ class Context {
|
|||
virtual ~OffscreenContext();
|
||||
void create() override;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // hifi_gpu_GPUConfig_h
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include <QtPlatformHeaders/QWGLNativeContext>
|
||||
#endif
|
||||
|
||||
#include "GLHelpers.h"
|
||||
|
||||
using namespace gl;
|
||||
|
||||
void Context::destroyContext(QOpenGLContext* context) {
|
||||
|
@ -45,6 +47,7 @@ void Context::moveToThread(QThread* thread) {
|
|||
|
||||
#ifndef Q_OS_WIN
|
||||
bool Context::makeCurrent() {
|
||||
updateSwapchainMemoryCounter();
|
||||
return _context->makeCurrent(_window);
|
||||
}
|
||||
|
||||
|
@ -70,6 +73,9 @@ void Context::create() {
|
|||
}
|
||||
_context->setFormat(getDefaultOpenGLSurfaceFormat());
|
||||
_context->create();
|
||||
|
||||
_swapchainPixelSize = evalGLFormatSwapchainPixelSize(_context->format());
|
||||
updateSwapchainMemoryCounter();
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -13,6 +13,17 @@
|
|||
|
||||
#include <QtOpenGL/QGL>
|
||||
|
||||
size_t evalGLFormatSwapchainPixelSize(const QSurfaceFormat& format) {
|
||||
size_t pixelSize = format.redBufferSize() + format.greenBufferSize() + format.blueBufferSize() + format.alphaBufferSize();
|
||||
// We don't apply the length of the swap chain into this pixelSize since it is not vsible for the Process (on windows).
|
||||
// Let s keep this here remember that:
|
||||
// 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);
|
||||
|
|
|
@ -17,11 +17,15 @@
|
|||
#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)
|
||||
{
|
||||
}
|
||||
|
||||
OffscreenGLCanvas::~OffscreenGLCanvas() {
|
||||
|
@ -56,7 +60,6 @@ bool OffscreenGLCanvas::create(QOpenGLContext* sharedContext) {
|
|||
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));
|
||||
|
|
|
@ -181,6 +181,10 @@ GLTexture::~GLTexture() {
|
|||
// the GL45Texture destructor for doing any required work tracking GPU stats
|
||||
backend->releaseTexture(_id, _size);
|
||||
}
|
||||
|
||||
if (!_external && !_transferrable) {
|
||||
Backend::updateTextureGPUFramebufferMemoryUsage(_size, 0);
|
||||
}
|
||||
}
|
||||
Backend::updateTextureGPUVirtualMemoryUsage(_virtualSize, 0);
|
||||
}
|
||||
|
@ -217,6 +221,9 @@ void GLTexture::withPreservedTexture(std::function<void()> f) const {
|
|||
}
|
||||
|
||||
void GLTexture::setSize(GLuint size) const {
|
||||
if (!_external && !_transferrable) {
|
||||
Backend::updateTextureGPUFramebufferMemoryUsage(_size, size);
|
||||
}
|
||||
Backend::updateTextureGPUMemoryUsage(_size, size);
|
||||
const_cast<GLuint&>(_size) = size;
|
||||
}
|
||||
|
|
|
@ -170,7 +170,8 @@ std::atomic<Buffer::Size> Context::_bufferGPUMemoryUsage { 0 };
|
|||
std::atomic<uint32_t> Context::_textureGPUCount{ 0 };
|
||||
std::atomic<uint32_t> Context::_textureGPUSparseCount { 0 };
|
||||
std::atomic<Texture::Size> Context::_textureGPUMemoryUsage { 0 };
|
||||
std::atomic<Texture::Size> Context::_textureGPUVirtualMemoryUsage{ 0 };
|
||||
std::atomic<Texture::Size> Context::_textureGPUVirtualMemoryUsage { 0 };
|
||||
std::atomic<Texture::Size> Context::_textureGPUFramebufferMemoryUsage { 0 };
|
||||
std::atomic<Texture::Size> Context::_textureGPUSparseMemoryUsage { 0 };
|
||||
std::atomic<uint32_t> Context::_textureGPUTransferCount { 0 };
|
||||
|
||||
|
@ -262,6 +263,17 @@ void Context::updateTextureGPUVirtualMemoryUsage(Size prevObjectSize, Size newOb
|
|||
}
|
||||
}
|
||||
|
||||
void Context::updateTextureGPUFramebufferMemoryUsage(Size prevObjectSize, Size newObjectSize) {
|
||||
if (prevObjectSize == newObjectSize) {
|
||||
return;
|
||||
}
|
||||
if (newObjectSize > prevObjectSize) {
|
||||
_textureGPUFramebufferMemoryUsage.fetch_add(newObjectSize - prevObjectSize);
|
||||
} else {
|
||||
_textureGPUFramebufferMemoryUsage.fetch_sub(prevObjectSize - newObjectSize);
|
||||
}
|
||||
}
|
||||
|
||||
void Context::updateTextureGPUSparseMemoryUsage(Size prevObjectSize, Size newObjectSize) {
|
||||
if (prevObjectSize == newObjectSize) {
|
||||
return;
|
||||
|
@ -310,6 +322,10 @@ Context::Size Context::getTextureGPUVirtualMemoryUsage() {
|
|||
return _textureGPUVirtualMemoryUsage.load();
|
||||
}
|
||||
|
||||
Context::Size Context::getTextureGPUFramebufferMemoryUsage() {
|
||||
return _textureGPUFramebufferMemoryUsage.load();
|
||||
}
|
||||
|
||||
Context::Size Context::getTextureGPUSparseMemoryUsage() {
|
||||
return _textureGPUSparseMemoryUsage.load();
|
||||
}
|
||||
|
@ -329,6 +345,7 @@ void Backend::incrementTextureGPUSparseCount() { Context::incrementTextureGPUSpa
|
|||
void Backend::decrementTextureGPUSparseCount() { Context::decrementTextureGPUSparseCount(); }
|
||||
void Backend::updateTextureGPUMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize) { Context::updateTextureGPUMemoryUsage(prevObjectSize, newObjectSize); }
|
||||
void Backend::updateTextureGPUVirtualMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize) { Context::updateTextureGPUVirtualMemoryUsage(prevObjectSize, newObjectSize); }
|
||||
void Backend::updateTextureGPUFramebufferMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize) { Context::updateTextureGPUFramebufferMemoryUsage(prevObjectSize, newObjectSize); }
|
||||
void Backend::updateTextureGPUSparseMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize) { Context::updateTextureGPUSparseMemoryUsage(prevObjectSize, newObjectSize); }
|
||||
void Backend::incrementTextureGPUTransferCount() { Context::incrementTextureGPUTransferCount(); }
|
||||
void Backend::decrementTextureGPUTransferCount() { Context::decrementTextureGPUTransferCount(); }
|
||||
|
|
|
@ -101,6 +101,7 @@ public:
|
|||
static void updateTextureGPUMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize);
|
||||
static void updateTextureGPUSparseMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize);
|
||||
static void updateTextureGPUVirtualMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize);
|
||||
static void updateTextureGPUFramebufferMemoryUsage(Resource::Size prevObjectSize, Resource::Size newObjectSize);
|
||||
static void incrementTextureGPUTransferCount();
|
||||
static void decrementTextureGPUTransferCount();
|
||||
|
||||
|
@ -210,6 +211,7 @@ public:
|
|||
static Size getFreeGPUMemory();
|
||||
static Size getTextureGPUMemoryUsage();
|
||||
static Size getTextureGPUVirtualMemoryUsage();
|
||||
static Size getTextureGPUFramebufferMemoryUsage();
|
||||
static Size getTextureGPUSparseMemoryUsage();
|
||||
static uint32_t getTextureGPUTransferCount();
|
||||
|
||||
|
@ -249,6 +251,7 @@ protected:
|
|||
static void updateTextureGPUMemoryUsage(Size prevObjectSize, Size newObjectSize);
|
||||
static void updateTextureGPUSparseMemoryUsage(Size prevObjectSize, Size newObjectSize);
|
||||
static void updateTextureGPUVirtualMemoryUsage(Size prevObjectSize, Size newObjectSize);
|
||||
static void updateTextureGPUFramebufferMemoryUsage(Size prevObjectSize, Size newObjectSize);
|
||||
static void incrementTextureGPUTransferCount();
|
||||
static void decrementTextureGPUTransferCount();
|
||||
|
||||
|
@ -264,6 +267,7 @@ protected:
|
|||
static std::atomic<Size> _textureGPUMemoryUsage;
|
||||
static std::atomic<Size> _textureGPUSparseMemoryUsage;
|
||||
static std::atomic<Size> _textureGPUVirtualMemoryUsage;
|
||||
static std::atomic<Size> _textureGPUFramebufferMemoryUsage;
|
||||
static std::atomic<uint32_t> _textureGPUTransferCount;
|
||||
|
||||
|
||||
|
|
|
@ -102,6 +102,11 @@ Texture::Size Texture::getTextureGPUVirtualMemoryUsage() {
|
|||
return Context::getTextureGPUVirtualMemoryUsage();
|
||||
}
|
||||
|
||||
|
||||
Texture::Size Texture::getTextureGPUFramebufferMemoryUsage() {
|
||||
return Context::getTextureGPUFramebufferMemoryUsage();
|
||||
}
|
||||
|
||||
Texture::Size Texture::getTextureGPUSparseMemoryUsage() {
|
||||
return Context::getTextureGPUSparseMemoryUsage();
|
||||
}
|
||||
|
|
|
@ -154,6 +154,7 @@ public:
|
|||
static uint32_t getTextureGPUSparseCount();
|
||||
static Size getTextureGPUMemoryUsage();
|
||||
static Size getTextureGPUVirtualMemoryUsage();
|
||||
static Size getTextureGPUFramebufferMemoryUsage();
|
||||
static Size getTextureGPUSparseMemoryUsage();
|
||||
static uint32_t getTextureGPUTransferCount();
|
||||
static Size getAllowedGPUMemoryUsage();
|
||||
|
|
Loading…
Reference in a new issue