From f3508f57b1492904c46ff9b19baa05f9e2c6b552 Mon Sep 17 00:00:00 2001 From: baldurk Date: Fri, 28 Apr 2017 17:40:42 +0100 Subject: [PATCH] Don't completely reset a constant buffer view if the vars are the same * It's annoying to have the constant buffer view reset and collapse everything, especially if moving between draws where the variables are the same because the shader hasn't changed. * We can just compare the previous set of variables to the new set and if the types and structures (member variables etc) are the same, then just update the values in-place. --- .../Windows/ConstantBufferPreviewer.cpp | 63 +++++++++++++++++++ qrenderdoc/Windows/ConstantBufferPreviewer.h | 5 ++ 2 files changed, 68 insertions(+) diff --git a/qrenderdoc/Windows/ConstantBufferPreviewer.cpp b/qrenderdoc/Windows/ConstantBufferPreviewer.cpp index 6e9176466..9cffae358 100644 --- a/qrenderdoc/Windows/ConstantBufferPreviewer.cpp +++ b/qrenderdoc/Windows/ConstantBufferPreviewer.cpp @@ -187,9 +187,72 @@ void ConstantBufferPreviewer::addVariables(RDTreeWidgetItem *root, } } +bool ConstantBufferPreviewer::updateVariables(RDTreeWidgetItem *root, + const rdctype::array &prevVars, + const rdctype::array &newVars) +{ + // mismatched child count? can't update + if(prevVars.count != newVars.count) + return false; + + for(int i = 0; i < prevVars.count; i++) + { + const ShaderVariable &a = prevVars[i]; + const ShaderVariable &b = newVars[i]; + + // different names? can't update + if(strcmp(a.name.c_str(), b.name.c_str())) + return false; + + // different size or type? can't update + if(a.rows != b.rows || a.columns != b.columns || a.displayAsHex != b.displayAsHex || + a.isStruct != b.isStruct || a.type != b.type) + return false; + + // update this node's value column + RDTreeWidgetItem *node = root->child(i); + + node->setText(1, VarString(b)); + + if(a.rows > 1) + { + for(uint32_t r = 0; r < a.rows; r++) + node->child(r)->setText(1, RowString(b, r)); + } + + if(a.members.count > 0) + { + // recurse to update child members. This handles a and b having different number of variables + bool updated = updateVariables(node, a.members, b.members); + + if(!updated) + return false; + } + } + + // got this far without bailing? we updated! + return true; +} + void ConstantBufferPreviewer::setVariables(const rdctype::array &vars) { ui->variables->setUpdatesEnabled(false); + + // try to update the variables in-place by only changing their values, if the set of variables + // matches *exactly* to what we had before. + // + // This keeps things like expanded structs and matrices when moving between drawcalls + bool updated = updateVariables(ui->variables->invisibleRootItem(), m_Vars, vars); + + // update the variables either way + m_Vars = vars; + + if(updated) + { + ui->variables->setUpdatesEnabled(true); + return; + } + ui->variables->clear(); ui->saveCSV->setEnabled(false); diff --git a/qrenderdoc/Windows/ConstantBufferPreviewer.h b/qrenderdoc/Windows/ConstantBufferPreviewer.h index 328639092..e8b955477 100644 --- a/qrenderdoc/Windows/ConstantBufferPreviewer.h +++ b/qrenderdoc/Windows/ConstantBufferPreviewer.h @@ -77,6 +77,11 @@ private: void addVariables(RDTreeWidgetItem *root, const rdctype::array &vars); void setVariables(const rdctype::array &vars); + rdctype::array m_Vars; + + bool updateVariables(RDTreeWidgetItem *root, const rdctype::array &prevVars, + const rdctype::array &newVars); + void updateLabels(); static QList m_Previews;