REvisiting the stats counter for the gpu context in the hope of better understanding the gpu texture streaming behavior

This commit is contained in:
samcake 2017-05-16 18:21:24 -07:00
parent e446d0f8c9
commit b466964817
7 changed files with 199 additions and 26 deletions

View file

@ -28,6 +28,47 @@ class QImage;
namespace gpu {
template <typename T>
struct ContextMetric {
std::atomic<T> _value { 0 };
std::atomic<T> _maximum { 0 };
T getValue() { return _value; }
T getMaximum() { return _maximum; }
void increment() {
auto total = ++_value;
if (total > _maximum.load()) {
_maximum = total;
}
}
void increment() {
--_value;
}
void update(T prevValue, T newValue) {
if (prevValue == newValue) {
return;
}
if (newValue > prevValue) {
auto total = _value.fetch_add(newValue - prevValue);
if (total > _maximum.load()) {
_maximum = total;
}
} else {
_value.fetch_sub(prevValue - newValue);
}
}
void reset() {
_value = 0;
_maximum = 0;
}
};
using ContextMetricCount = ContextMetric<uint32_t>;
using ContextMetricSize = ContextMetric<Size>;
struct ContextStats {
public:
int _ISNumFormatChanges = 0;
@ -107,12 +148,27 @@ public:
static void decrementTextureGPUSparseCount();
static void updateTextureTransferPendingSize(Resource::Size prevObjectSize, Resource::Size newObjectSize);
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 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();
static ContextMetricSize freeGPUMemSize;
static ContextMetricCount bufferCount;
static ContextMetricSize bufferGPUMemSize;
static ContextMetricCount textureCount;
static ContextMetricSize textureGPUMemSize;
static ContextMetricSize textureResidentGPUMemSize;
static ContextMetricSize textureResourceGPUMemSize;
static ContextMetricSize textureFramebufferGPUMemSize;
static ContextMetricCount textureTransferCount;
protected:
virtual bool isStereo() {
return _stereo._enable;
@ -224,14 +280,16 @@ public:
static Size getBufferGPUMemoryUsage();
static uint32_t getTextureGPUCount();
static uint32_t getTextureGPUSparseCount();
static uint32_t getTextureGPUResourceCount();
static Size getFreeGPUMemory();
static Size getUsedGPUMemory();
static Size getTextureTransferPendingSize();
static Size getTextureGPUMemoryUsage();
static Size getTextureGPUVirtualMemoryUsage();
static Size getTextureGPUResourceMemoryUsage();
static Size getTextureGPUResidentMemoryUsage();
static Size getTextureGPUFramebufferMemoryUsage();
static Size getTextureGPUSparseMemoryUsage();
static uint32_t getTextureGPUTransferCount();
protected:
@ -269,16 +327,21 @@ protected:
static void setFreeGPUMemory(Size size);
static void incrementTextureGPUCount();
static void decrementTextureGPUCount();
static void incrementTextureGPUSparseCount();
static void decrementTextureGPUSparseCount();
static void updateTextureTransferPendingSize(Size prevObjectSize, Size newObjectSize);
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 incrementTextureGPUResourceCount();
static void decrementTextureGPUResourceCount();
static void incrementTextureGPUTransferCount();
static void decrementTextureGPUTransferCount();
static void updateTextureTransferPendingSize(Size prevObjectSize, Size newObjectSize);
static void updateTextureGPUMemoryUsage(Size prevObjectSize, Size newObjectSize);
static void updateTextureGPUResourceMemoryUsage(Size prevObjectSize, Size newObjectSize);
static void updateTextureGPUResidentMemoryUsage(Size prevObjectSize, Size newObjectSize);
static void updateTextureGPUFramebufferMemoryUsage(Size prevObjectSize, Size newObjectSize);
// Buffer, Texture and Fence Counters
static std::atomic<Size> _freeGPUMemory;
static std::atomic<uint32_t> _fenceCount;

View file

@ -85,10 +85,6 @@ uint32_t Texture::getTextureGPUCount() {
return Context::getTextureGPUCount();
}
uint32_t Texture::getTextureGPUSparseCount() {
return Context::getTextureGPUSparseCount();
}
Texture::Size Texture::getTextureTransferPendingSize() {
return Context::getTextureTransferPendingSize();
}
@ -97,19 +93,18 @@ Texture::Size Texture::getTextureGPUMemoryUsage() {
return Context::getTextureGPUMemoryUsage();
}
Texture::Size Texture::getTextureGPUVirtualMemoryUsage() {
return Context::getTextureGPUVirtualMemoryUsage();
Texture::Size getTextureGPUResourceMemoryUsage() {
return Context::getTextureGPUResourceMemoryUsage();
}
Texture::Size getTextureGPUResidentMemoryUsage() {
return Context::getTextureGPUResidentMemoryUsage();
}
Texture::Size Texture::getTextureGPUFramebufferMemoryUsage() {
return Context::getTextureGPUFramebufferMemoryUsage();
}
Texture::Size Texture::getTextureGPUSparseMemoryUsage() {
return Context::getTextureGPUSparseMemoryUsage();
}
uint32_t Texture::getTextureGPUTransferCount() {
return Context::getTextureGPUTransferCount();
}

View file

@ -178,12 +178,11 @@ public:
static uint32_t getTextureCPUCount();
static Size getTextureCPUMemoryUsage();
static uint32_t getTextureGPUCount();
static uint32_t getTextureGPUSparseCount();
static Size getTextureTransferPendingSize();
static Size getTextureGPUMemoryUsage();
static Size getTextureGPUVirtualMemoryUsage();
static Size getTextureGPUResourceMemoryUsage();
static Size getTextureGPUResidentMemoryUsage();
static Size getTextureGPUFramebufferMemoryUsage();
static Size getTextureGPUSparseMemoryUsage();
static uint32_t getTextureGPUTransferCount();
static Size getAllowedGPUMemoryUsage();
static void setAllowedGPUMemoryUsage(Size size);

View file

@ -34,6 +34,9 @@ void EngineStats::run(const RenderContextPointer& renderContext) {
config->textureGPUMemoryUsage = gpu::Texture::getTextureGPUMemoryUsage();
config->textureGPUVirtualMemoryUsage = gpu::Texture::getTextureGPUVirtualMemoryUsage();
config->textureGPUTransferCount = gpu::Texture::getTextureGPUTransferCount();
config->textureTransferPendingSize = gpu::Texture::getTextureTransferPendingSize();
config->textureGPUFramebufferSize = gpu::Texture::getTextureGPUFramebufferMemoryUsage();
renderContext->args->_context->getFrameStats(_gpuStats);

View file

@ -36,6 +36,10 @@ namespace render {
Q_PROPERTY(qint64 textureGPUVirtualMemoryUsage MEMBER textureGPUVirtualMemoryUsage NOTIFY dirty)
Q_PROPERTY(quint32 textureGPUTransferCount MEMBER textureGPUTransferCount NOTIFY dirty)
Q_PROPERTY(quint32 textureTransferPendingSize MEMBER textureTransferPendingSize NOTIFY dirty)
Q_PROPERTY(qint64 textureGPUFramebufferSize MEMBER textureGPUFramebufferSize NOTIFY dirty)
Q_PROPERTY(quint32 frameAPIDrawcallCount MEMBER frameAPIDrawcallCount NOTIFY dirty)
Q_PROPERTY(quint32 frameDrawcallCount MEMBER frameDrawcallCount NOTIFY dirty)
Q_PROPERTY(quint32 frameDrawcallRate MEMBER frameDrawcallRate NOTIFY dirty)
@ -64,7 +68,10 @@ namespace render {
qint64 textureCPUMemoryUsage{ 0 };
qint64 textureGPUMemoryUsage{ 0 };
qint64 textureGPUVirtualMemoryUsage{ 0 };
quint32 textureGPUTransferCount{ 0 };
quint32 textureGPUTransferCount { 0 };
qint64 textureTransferPendingSize { 0 };
qint64 textureGPUFramebufferSize { 0 };
quint32 frameAPIDrawcallCount{ 0 };
quint32 frameDrawcallCount{ 0 };

View file

@ -0,0 +1,21 @@
//
// textureMonitor.js
// examples/utilities/tools/render
//
// Sam Gateau, created on 3/22/2016.
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
// Set up the qml ui
var qml = Script.resolvePath('textureMonitor.qml');
var window = new OverlayWindow({
title: 'Textures',
source: qml,
width: 320,
height: 720
});
window.setPosition(500, 50);
window.closed.connect(function() { Script.stop(); });

View file

@ -0,0 +1,85 @@
//
// texture monitor.qml
// examples/utilities/render
//
// Created by Sam Gateau on 5/17/2017
// Copyright 2016 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
//
import QtQuick 2.5
import QtQuick.Controls 1.4
import "../lib/plotperf"
Item {
id: texMex
anchors.fill:parent
Column {
id: stats
spacing: 8
anchors.fill:parent
property var config: Render.getConfig("Stats")
function evalEvenHeight() {
// Why do we have to do that manually ? cannot seem to find a qml / anchor / layout mode that does that ?
return (height - spacing * (children.length - 1)) / children.length
}
PlotPerf {
title: "Num Textures"
height: parent.evalEvenHeight()
object: stats.config
plots: [
{
prop: "textureCPUCount",
label: "CPU",
color: "#00B4EF"
},
{
prop: "textureGPUCount",
label: "GPU",
color: "#1AC567"
},
{
prop: "textureGPUTransferCount",
label: "Transfer",
color: "#9495FF"
}
]
}
PlotPerf {
title: "gpu::Texture Memory"
height: parent.evalEvenHeight()
object: stats.config
valueScale: 1048576
valueUnit: "Mb"
valueNumDigits: "1"
plots: [
{
prop: "textureCPUMemoryUsage",
label: "CPU",
color: "#00B4EF"
},
{
prop: "textureGPUMemoryUsage",
label: "GPU",
color: "#1AC567"
},
{
prop: "textureTransferPendingSize",
label: "Pending Transfer",
color: "#9495FF"
},
{
prop: "textureGPUFramebufferSize",
label: "Framebuffer",
color: "#EF93D1"
}
]
}
}
}