From 3512fed2bdfb3315075defee4f16993fa6943557 Mon Sep 17 00:00:00 2001 From: Mark Janes Date: Fri, 1 Sep 2017 19:07:58 -0700 Subject: State: Initial implementation of state model Stores the state data for display in the UI. --- retrace/daemon/glframe_retrace_interface.hpp | 3 + retrace/daemon/glframe_retrace_stub.cpp | 10 ++- retrace/daemon/ui/CMakeLists.txt | 2 + retrace/daemon/ui/glframe_retrace_model.cpp | 11 ++- retrace/daemon/ui/glframe_retrace_model.hpp | 5 ++ retrace/daemon/ui/glframe_state_model.cpp | 130 +++++++++++++++++++++++++++ retrace/daemon/ui/glframe_state_model.hpp | 106 ++++++++++++++++++++++ 7 files changed, 264 insertions(+), 3 deletions(-) create mode 100644 retrace/daemon/ui/glframe_state_model.cpp create mode 100644 retrace/daemon/ui/glframe_state_model.hpp (limited to 'retrace') diff --git a/retrace/daemon/glframe_retrace_interface.hpp b/retrace/daemon/glframe_retrace_interface.hpp index c1f072d2..59773d0e 100644 --- a/retrace/daemon/glframe_retrace_interface.hpp +++ b/retrace/daemon/glframe_retrace_interface.hpp @@ -178,6 +178,7 @@ class ExperimentId { bool operator>(const ExperimentId &o) const { return value > o.value; } bool operator<=(const ExperimentId &o) const { return value <= o.value; } bool operator!=(const ExperimentId &o) const { return value != o.value; } + bool operator==(const ExperimentId &o) const { return value == o.value; } static const uint32_t INVALID_EXPERIMENT = (-1 & ~ID_PREFIX_MASK); private: uint32_t value; @@ -258,12 +259,14 @@ enum UniformDimension { enum StateItem { CULL_FACE = 0x0B44, CULL_FACE_MODE = 0x0B45, + INVALID_NAME = -1, }; struct StateKey { StateItem name; int index; + StateKey() : name(INVALID_NAME), index(0) {} StateKey(StateItem n, int i) : name(n), index(i) {} }; diff --git a/retrace/daemon/glframe_retrace_stub.cpp b/retrace/daemon/glframe_retrace_stub.cpp index 968afc37..7c39f7da 100644 --- a/retrace/daemon/glframe_retrace_stub.cpp +++ b/retrace/daemon/glframe_retrace_stub.cpp @@ -970,9 +970,15 @@ class StateRequest : public IRetraceRequest { s->response(&response); assert(response.has_state()); const auto &state_response = response.state(); - if (state_response.render_id() == (unsigned int)-1) - // all responses sent + if (state_response.render_id() == (unsigned int)-1) { + // all responses sent. Send a bogus state to inform the + // model that uniforms are complete + m_callback->onState(SelectionId(SelectionId::INVALID_SELECTION), + ExperimentId(ExperimentId::INVALID_EXPERIMENT-1), + RenderId(RenderId::INVALID_RENDER), + glretrace::StateKey(), ""); break; + } const auto selection = SelectionId(state_response.selection_count()); { diff --git a/retrace/daemon/ui/CMakeLists.txt b/retrace/daemon/ui/CMakeLists.txt index 22b959d8..5967284b 100644 --- a/retrace/daemon/ui/CMakeLists.txt +++ b/retrace/daemon/ui/CMakeLists.txt @@ -39,6 +39,8 @@ set (UI_SRC glframe_retrace_model.cpp glframe_shader_model.hpp glframe_shader_model.cpp + glframe_state_model.hpp + glframe_state_model.cpp glframe_uniform_model.hpp glframe_uniform_model.cpp ) diff --git a/retrace/daemon/ui/glframe_retrace_model.cpp b/retrace/daemon/ui/glframe_retrace_model.cpp index 7da82b3c..63a355d8 100644 --- a/retrace/daemon/ui/glframe_retrace_model.cpp +++ b/retrace/daemon/ui/glframe_retrace_model.cpp @@ -41,6 +41,7 @@ #include "glframe_rendertarget_model.hpp" #include "glframe_socket.hpp" #include "glframe_uniform_model.hpp" +#include "glframe_state_model.hpp" using glretrace::DEBUG; using glretrace::ERR; @@ -66,6 +67,7 @@ FrameRetraceModel::FrameRetraceModel() : m_experiment(&m_retrace), m_rendertarget(new QRenderTargetModel(this)), m_uniforms(new QUniformsModel(&m_retrace)), + m_stateModel(new QStateModel(&m_retrace)), m_state(NULL), m_selection(NULL), m_selection_count(0), @@ -88,6 +90,12 @@ FrameRetraceModel::~FrameRetraceModel() { m_state = NULL; } m_retrace.Shutdown(); + delete m_rendertarget; + delete m_uniforms; + delete m_stateModel; + for (auto i : m_metrics_model) + delete i; + m_metrics_model.clear(); } FrameState *frame_state_off_thread(std::string filename, @@ -620,7 +628,8 @@ FrameRetraceModel::onState(SelectionId selectionCount, RenderId renderId, StateKey item, const std::string &value) { - std::cout << value << "\n"; + m_stateModel->onState(selectionCount, experimentCount, + renderId, item, value); } void diff --git a/retrace/daemon/ui/glframe_retrace_model.hpp b/retrace/daemon/ui/glframe_retrace_model.hpp index 5d485f6b..3908d55c 100644 --- a/retrace/daemon/ui/glframe_retrace_model.hpp +++ b/retrace/daemon/ui/glframe_retrace_model.hpp @@ -56,6 +56,7 @@ class FrameRetrace; class QSelection; class QRenderTargetModel; class QUniformsModel; +class QStateModel; class QRenderBookmark : public QObject { Q_OBJECT @@ -121,6 +122,8 @@ class FrameRetraceModel : public QObject, READ rendertarget CONSTANT) Q_PROPERTY(glretrace::QUniformsModel* uniformModel READ uniformModel CONSTANT) + Q_PROPERTY(glretrace::QStateModel* stateModel + READ stateModel CONSTANT) public: FrameRetraceModel(); @@ -192,6 +195,7 @@ class FrameRetraceModel : public QObject, QRenderShadersList *shaders() { return &m_shaders; } QExperimentModel *experiments() { return &m_experiment; } QUniformsModel *uniformModel() { return m_uniforms; } + QStateModel *stateModel() { return m_stateModel; } QApiModel *api() { return &m_api; } QBatchModel *batch() { return &m_batch; } QRenderTargetModel *rendertarget() { return m_rendertarget; } @@ -251,6 +255,7 @@ class FrameRetraceModel : public QObject, QExperimentModel m_experiment; QRenderTargetModel *m_rendertarget; QUniformsModel *m_uniforms; + QStateModel *m_stateModel; FrameState *m_state; QSelection *m_selection; SelectionId m_selection_count; diff --git a/retrace/daemon/ui/glframe_state_model.cpp b/retrace/daemon/ui/glframe_state_model.cpp new file mode 100644 index 00000000..5a0d47ff --- /dev/null +++ b/retrace/daemon/ui/glframe_state_model.cpp @@ -0,0 +1,130 @@ +/************************************************************************** + * + * Copyright 2017 Intel Corporation + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * Authors: + * Mark Janes + **************************************************************************/ + +#include "glframe_state_model.hpp" + +#include +#include + +#include "glframe_os.hpp" + +using glretrace::QStateModel; +using glretrace::QStateValue; +using glretrace::StateItem; + +QStateValue::QStateValue(const std::string &_name, + const std::vector &_choices) + : m_name(_name.c_str()) { + for (auto c : _choices) + m_choices.append(QString::fromStdString(c)); +} + +void +QStateValue::insert(int index, const std::string &value) { + while (m_values.size() < index) + m_values.append(QString()); + if (m_values.size() == index) + m_values.append(QString::fromStdString(value)); + else + m_values[index] = QString::fromStdString(value); +} + +QStateModel::QStateModel() {} + +QStateModel::QStateModel(IFrameRetrace *retrace) {} + +QStateModel::~QStateModel() {} + +QQmlListProperty QStateModel::state() { + ScopedLock s(m_protect); + QList l; + for (auto i : m_state_by_name) + l.push_back(i.second); + + return QQmlListProperty(this, l); +} + +std::string +state_name_to_string(StateItem n) { + switch (n) { + case glretrace::CULL_FACE: + return std::string("CULL_FACE"); + case glretrace::CULL_FACE_MODE: + return std::string("CULL_FACE_MODE"); + default: + assert(false); + } +} + +std::vector +name_to_choines(StateItem n) { + switch (n) { + case glretrace::CULL_FACE: + return {"true", "false"}; + case glretrace::CULL_FACE_MODE: + return {"GL_FRONT", "GL_BACK", "GL_FRONT_AND_BACK"}; + default: + assert(false); + } +} + +void QStateModel::onState(SelectionId selectionCount, + ExperimentId experimentCount, + RenderId renderId, + StateKey item, + const std::string &value) { + ScopedLock s(m_protect); + if ((selectionCount > m_sel_count) || + (experimentCount > m_experiment_count)) { + m_sel_count = selectionCount; + m_experiment_count = experimentCount; + } else { + assert(selectionCount == m_sel_count); + assert(experimentCount == m_experiment_count); + } + if (selectionCount == SelectionId(SelectionId::INVALID_SELECTION)) { + emit stateChanged(); + return; + } + const auto name = state_name_to_string(item.name); + auto state_value = m_state_by_name.find(name); + if (state_value == m_state_by_name.end()) { + QStateValue *i = new QStateValue(name, + name_to_choines(item.name)); + m_state_by_name[name] = i; + state_value = m_state_by_name.find(name); + } + state_value->second->insert(item.index, value); +} + +void +QStateModel::setState(const QString &name, + const int index, + const QString &value) { + assert(false); +} + diff --git a/retrace/daemon/ui/glframe_state_model.hpp b/retrace/daemon/ui/glframe_state_model.hpp new file mode 100644 index 00000000..f98ce463 --- /dev/null +++ b/retrace/daemon/ui/glframe_state_model.hpp @@ -0,0 +1,106 @@ +/************************************************************************** + * + * Copyright 2017 Intel Corporation + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + * + * Authors: + * Mark Janes + **************************************************************************/ + +#ifndef _GLFRAME_STATE_MODEL_HPP_ +#define _GLFRAME_STATE_MODEL_HPP_ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "glframe_retrace_interface.hpp" +#include "glframe_traits.hpp" + +namespace glretrace { + +class QStateValue : public QObject, NoCopy, NoAssign, NoMove { + Q_OBJECT + + Q_PROPERTY(QString name READ name CONSTANT) + Q_PROPERTY(QList values READ values CONSTANT) + // Q_PROPERTY(QUniformDimension dimension READ dimension CONSTANT) + Q_PROPERTY(QList choices READ choices CONSTANT) + + public: + QStateValue() {} + QStateValue(const std::string &_name, + const std::vector &_choices); + void insert(int index, const std::string &value); + + QString name() const { return m_name; } + QList values() const { return m_values; } + QList choices() const { return m_choices; } + + private: + QString m_name; + QList m_values, m_choices; +}; + +class QStateModel : public QObject, + NoCopy, NoAssign, NoMove { + Q_OBJECT + Q_PROPERTY(QQmlListProperty state READ state + NOTIFY stateChanged) + public: + QStateModel(); + explicit QStateModel(IFrameRetrace *retrace); + ~QStateModel(); + QQmlListProperty state(); + void onState(SelectionId selectionCount, + ExperimentId experimentCount, + RenderId renderId, + StateKey item, + const std::string &value); + // void clear(); + Q_INVOKABLE void setState(const QString &name, + const int index, + const QString &value); + + signals: + // after index is selected, uniform data is available + void stateExperiment(); + void stateChanged(); + + private: + IFrameRetrace *m_retrace; + SelectionId m_sel_count; + ExperimentId m_experiment_count; + // typedef QList StateList; + std::map m_state_by_name; + mutable std::mutex m_protect; +}; + +} // namespace glretrace + +#endif // _GLFRAME_STATE_MODEL_HPP_ -- cgit v1.2.3