From ae07036f20bffcb8d4d1d59d1cc979e66394fffe Mon Sep 17 00:00:00 2001
From: Brad Davis <bdavis@saintandreas.org>
Date: Thu, 17 May 2018 14:29:06 -0700
Subject: [PATCH] Add ideal resource texture memory stat

---
 interface/resources/qml/Stats.qml | 6 ++++--
 interface/src/ui/Stats.cpp        | 1 +
 interface/src/ui/Stats.h          | 9 +++++++++
 libraries/gpu/src/gpu/Context.cpp | 5 +++++
 libraries/gpu/src/gpu/Context.h   | 2 ++
 5 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/interface/resources/qml/Stats.qml b/interface/resources/qml/Stats.qml
index d961285a46..2406fa048d 100644
--- a/interface/resources/qml/Stats.qml
+++ b/interface/resources/qml/Stats.qml
@@ -281,10 +281,12 @@ Item {
                         text: "  Pressure State: " + root.gpuTextureMemoryPressureState;
                     }
                     StatText {
-                        text: "  Resource Allocated / Populated / Pending: ";
+                        property bool showIdeal: (root.gpuTextureResourceIdealMemory != root.gpuTextureResourceMemory);
+                        text: "  Resource Allocated " + (showIdeal ? "(Ideal)" : "") + " / Populated / Pending: ";
                     }
                     StatText {
-                        text: "       " + root.gpuTextureResourceMemory + " / " + root.gpuTextureResourcePopulatedMemory + " / " + root.texturePendingTransfers + " MB";
+                        property bool showIdeal: (root.gpuTextureResourceIdealMemory != root.gpuTextureResourceMemory);
+                        text: "       " + root.gpuTextureResourceMemory + (showIdeal ? ("(" +  root.gpuTextureResourceIdealMemory + ")") : "") + " / " + root.gpuTextureResourcePopulatedMemory + " / " + root.texturePendingTransfers + " MB";
                     }
                     StatText {
                         text: "  Resident Memory: " + root.gpuTextureResidentMemory + " MB";
diff --git a/interface/src/ui/Stats.cpp b/interface/src/ui/Stats.cpp
index d54faf8b28..9d86745341 100644
--- a/interface/src/ui/Stats.cpp
+++ b/interface/src/ui/Stats.cpp
@@ -354,6 +354,7 @@ void Stats::updateStats(bool force) {
     STAT_UPDATE(gpuTextureResidentMemory, (int)BYTES_TO_MB(gpu::Context::getTextureResidentGPUMemSize()));
     STAT_UPDATE(gpuTextureFramebufferMemory, (int)BYTES_TO_MB(gpu::Context::getTextureFramebufferGPUMemSize()));
     STAT_UPDATE(gpuTextureResourceMemory, (int)BYTES_TO_MB(gpu::Context::getTextureResourceGPUMemSize()));
+    STAT_UPDATE(gpuTextureResourceIdealMemory, (int)BYTES_TO_MB(gpu::Context::getTextureResourceIdealGPUMemSize()));
     STAT_UPDATE(gpuTextureResourcePopulatedMemory, (int)BYTES_TO_MB(gpu::Context::getTextureResourcePopulatedGPUMemSize()));
     STAT_UPDATE(gpuTextureExternalMemory, (int)BYTES_TO_MB(gpu::Context::getTextureExternalGPUMemSize()));
 #if !defined(Q_OS_ANDROID)
diff --git a/interface/src/ui/Stats.h b/interface/src/ui/Stats.h
index 5c6a3db064..36e923261d 100644
--- a/interface/src/ui/Stats.h
+++ b/interface/src/ui/Stats.h
@@ -126,6 +126,7 @@ private: \
  * @property {number} gpuTextureResidentMemory - <em>Read-only.</em>
  * @property {number} gpuTextureFramebufferMemory - <em>Read-only.</em>
  * @property {number} gpuTextureResourceMemory - <em>Read-only.</em>
+ * @property {number} gpuTextureResourceIdealMemory - <em>Read-only.</em>
  * @property {number} gpuTextureResourcePopulatedMemory - <em>Read-only.</em>
  * @property {number} gpuTextureExternalMemory - <em>Read-only.</em>
  * @property {string} gpuTextureMemoryPressureState - <em>Read-only.</em>
@@ -270,6 +271,7 @@ class Stats : public QQuickItem {
     STATS_PROPERTY(int, gpuTextureResidentMemory, 0)
     STATS_PROPERTY(int, gpuTextureFramebufferMemory, 0)
     STATS_PROPERTY(int, gpuTextureResourceMemory, 0)
+    STATS_PROPERTY(int, gpuTextureResourceIdealMemory, 0)
     STATS_PROPERTY(int, gpuTextureResourcePopulatedMemory, 0)
     STATS_PROPERTY(int, gpuTextureExternalMemory, 0)
     STATS_PROPERTY(QString, gpuTextureMemoryPressureState, QString())
@@ -918,6 +920,13 @@ signals:
      */
     void gpuTextureResourceMemoryChanged();
 
+    /**jsdoc
+     * Triggered when the value of the <code>gpuTextureResourceIdealMemory</code> property changes.
+     * @function Stats.gpuTextureResourceIdealMemoryChanged
+     * @returns {Signal}
+     */
+    void gpuTextureResourceIdealMemoryChanged();
+
     /**jsdoc
      * Triggered when the value of the <code>gpuTextureResourcePopulatedMemory</code> property changes.
      * @function Stats.gpuTextureResourcePopulatedMemoryChanged
diff --git a/libraries/gpu/src/gpu/Context.cpp b/libraries/gpu/src/gpu/Context.cpp
index 75c80a0164..ad2be7af5e 100644
--- a/libraries/gpu/src/gpu/Context.cpp
+++ b/libraries/gpu/src/gpu/Context.cpp
@@ -270,6 +270,7 @@ ContextMetricCount Backend::texturePendingGPUTransferCount;
 ContextMetricSize  Backend::texturePendingGPUTransferMemSize;
 
 ContextMetricSize  Backend::textureResourcePopulatedGPUMemSize;
+ContextMetricSize  Backend::textureResourceIdealGPUMemSize;
 
 Size Context::getFreeGPUMemSize() {
     return Backend::freeGPUMemSize.getValue();
@@ -329,3 +330,7 @@ Size Context::getTexturePendingGPUTransferMemSize() {
 Size Context::getTextureResourcePopulatedGPUMemSize() {
     return Backend::textureResourcePopulatedGPUMemSize.getValue();
 }
+
+Size Context::getTextureResourceIdealGPUMemSize() {
+    return Backend::textureResourceIdealGPUMemSize.getValue();
+}
diff --git a/libraries/gpu/src/gpu/Context.h b/libraries/gpu/src/gpu/Context.h
index 8c5a4d493e..23c7edaff4 100644
--- a/libraries/gpu/src/gpu/Context.h
+++ b/libraries/gpu/src/gpu/Context.h
@@ -113,6 +113,7 @@ public:
     static ContextMetricCount texturePendingGPUTransferCount;
     static ContextMetricSize  texturePendingGPUTransferMemSize;
     static ContextMetricSize  textureResourcePopulatedGPUMemSize;
+    static ContextMetricSize  textureResourceIdealGPUMemSize;
 
 
 protected:
@@ -243,6 +244,7 @@ public:
     static Size getTexturePendingGPUTransferMemSize();
 
     static Size getTextureResourcePopulatedGPUMemSize();
+    static Size getTextureResourceIdealGPUMemSize();
 
 protected:
     Context(const Context& context);