summaryrefslogtreecommitdiff
path: root/retrace
diff options
context:
space:
mode:
authorMark Janes <mark.a.janes@intel.com>2017-06-19 13:13:18 -0700
committerMark Janes <mark.a.janes@intel.com>2017-08-28 16:33:55 -0700
commit1d212d698490ec0137c5adda47a49cb51fdad0f6 (patch)
treec9ff422022e966899bc737e138dde42118e35667 /retrace
parent6adb597155abef79fbc27004835151fe065d696c (diff)
Uniforms: enable override of uniform data
Diffstat (limited to 'retrace')
-rw-r--r--retrace/daemon/glframe_retrace.cpp11
-rw-r--r--retrace/daemon/glframe_retrace.hpp4
-rw-r--r--retrace/daemon/glframe_retrace_context.cpp9
-rw-r--r--retrace/daemon/glframe_retrace_context.hpp3
-rw-r--r--retrace/daemon/glframe_retrace_interface.hpp4
-rw-r--r--retrace/daemon/glframe_retrace_render.cpp24
-rw-r--r--retrace/daemon/glframe_retrace_render.hpp18
-rw-r--r--retrace/daemon/glframe_retrace_skeleton.cpp16
-rw-r--r--retrace/daemon/glframe_retrace_stub.cpp39
-rw-r--r--retrace/daemon/glframe_retrace_stub.hpp4
-rw-r--r--retrace/daemon/glframe_uniforms.cpp82
-rw-r--r--retrace/daemon/glframe_uniforms.hpp3
-rw-r--r--retrace/daemon/playback.proto9
-rw-r--r--retrace/daemon/ui/glframe_retrace_model.cpp5
-rw-r--r--retrace/daemon/ui/glframe_uniform_model.cpp19
-rw-r--r--retrace/daemon/ui/glframe_uniform_model.hpp4
16 files changed, 253 insertions, 1 deletions
diff --git a/retrace/daemon/glframe_retrace.cpp b/retrace/daemon/glframe_retrace.cpp
index a08ce2fe..8b66388c 100644
--- a/retrace/daemon/glframe_retrace.cpp
+++ b/retrace/daemon/glframe_retrace.cpp
@@ -375,3 +375,14 @@ FrameRetrace::retraceUniform(const RenderSelection &selection,
for (auto i : m_contexts)
i->retraceUniform(selection, experimentCount, m_tracker, callback);
}
+
+void
+FrameRetrace::setUniform(const RenderSelection &selection,
+ const std::string &name,
+ int index,
+ const std::string &data) {
+ // reset to beginning of frame
+ parser->setBookmark(frame_start.start);
+ for (auto i : m_contexts)
+ i->setUniform(selection, name, index, data);
+}
diff --git a/retrace/daemon/glframe_retrace.hpp b/retrace/daemon/glframe_retrace.hpp
index c0572bc6..c562be7f 100644
--- a/retrace/daemon/glframe_retrace.hpp
+++ b/retrace/daemon/glframe_retrace.hpp
@@ -109,6 +109,10 @@ class FrameRetrace : public IFrameRetrace {
void retraceUniform(const RenderSelection &selection,
ExperimentId experimentCount,
OnFrameRetrace *callback);
+ void setUniform(const RenderSelection &selection,
+ const std::string &name,
+ int index,
+ const std::string &data);
private:
// these are global
diff --git a/retrace/daemon/glframe_retrace_context.cpp b/retrace/daemon/glframe_retrace_context.cpp
index 67c27b86..4f24d281 100644
--- a/retrace/daemon/glframe_retrace_context.cpp
+++ b/retrace/daemon/glframe_retrace_context.cpp
@@ -473,3 +473,12 @@ RetraceContext::retraceUniform(const RenderSelection &selection,
}
}
}
+
+void
+RetraceContext::setUniform(const RenderSelection &selection,
+ const std::string &name, int index,
+ const std::string &data) {
+ for (auto r : m_renders)
+ if (isSelected(r.first, selection))
+ r.second->setUniform(name, index, data);
+}
diff --git a/retrace/daemon/glframe_retrace_context.hpp b/retrace/daemon/glframe_retrace_context.hpp
index ac768dcd..cd5d2508 100644
--- a/retrace/daemon/glframe_retrace_context.hpp
+++ b/retrace/daemon/glframe_retrace_context.hpp
@@ -103,6 +103,9 @@ class RetraceContext {
ExperimentId experimentCount,
const StateTrack &tracker,
OnFrameRetrace *callback);
+ void setUniform(const RenderSelection &selection,
+ const std::string &name, int index,
+ const std::string &data);
private:
trace::AbstractParser *m_parser;
diff --git a/retrace/daemon/glframe_retrace_interface.hpp b/retrace/daemon/glframe_retrace_interface.hpp
index 1b3e39cd..a10322a6 100644
--- a/retrace/daemon/glframe_retrace_interface.hpp
+++ b/retrace/daemon/glframe_retrace_interface.hpp
@@ -337,6 +337,10 @@ class IFrameRetrace {
virtual void retraceUniform(const RenderSelection &selection,
ExperimentId experimentCount,
OnFrameRetrace *callback) = 0;
+ virtual void setUniform(const RenderSelection &selection,
+ const std::string &name,
+ int index,
+ const std::string &data) = 0;
};
class FrameState {
diff --git a/retrace/daemon/glframe_retrace_render.cpp b/retrace/daemon/glframe_retrace_render.cpp
index e41bc597..8e5013a3 100644
--- a/retrace/daemon/glframe_retrace_render.cpp
+++ b/retrace/daemon/glframe_retrace_render.cpp
@@ -35,6 +35,7 @@
#include "glframe_logger.hpp"
#include "glframe_metrics.hpp"
#include "glframe_state.hpp"
+#include "glframe_uniforms.hpp"
#include "retrace.hpp"
#include "glstate_internal.hpp"
#include "trace_parser.hpp"
@@ -174,6 +175,19 @@ RetraceRender::RetraceRender(trace::AbstractParser *parser,
}
void
+RetraceRender::overrideUniforms() const {
+ if (m_uniform_overrides.size() == 0)
+ return;
+ Uniforms u;
+ for (auto i : m_uniform_overrides) {
+ u.overrideUniform(i.first.name,
+ i.first.index,
+ i.second);
+ }
+ u.set();
+}
+
+void
RetraceRender::retraceRenderTarget(const StateTrack &tracker,
RenderTargetType type) const {
// check that the parser is in correct state
@@ -208,6 +222,8 @@ RetraceRender::retraceRenderTarget(const StateTrack &tracker,
StateTrack::useProgramGL(m_retrace_program);
}
+ overrideUniforms();
+
// retrace the final render
trace::Call *call = m_parser->parse_call();
assert(call);
@@ -291,6 +307,8 @@ RetraceRender::retrace(const StateTrack &tracker) const {
StateTrack::useProgramGL(m_retrace_program);
}
+ overrideUniforms();
+
// retrace the final render
trace::Call *call = m_parser->parse_call();
assert(call);
@@ -352,3 +370,9 @@ void
RetraceRender::simpleShader(bool simple) {
m_simple_shader = simple;
}
+
+void
+RetraceRender::setUniform(const std::string &name, int index,
+ const std::string &data) {
+ m_uniform_overrides[UniformKey(name, index)] = data;
+}
diff --git a/retrace/daemon/glframe_retrace_render.hpp b/retrace/daemon/glframe_retrace_render.hpp
index af8113b1..36d56b38 100644
--- a/retrace/daemon/glframe_retrace_render.hpp
+++ b/retrace/daemon/glframe_retrace_render.hpp
@@ -28,6 +28,7 @@
#ifndef _GLFRAME_RETRACE_RENDER_HPP_
#define _GLFRAME_RETRACE_RENDER_HPP_
+#include <map>
#include <string>
#include <vector>
@@ -73,12 +74,16 @@ class RetraceRender {
void onApi(SelectionId selId,
RenderId renderId,
OnFrameRetrace *callback);
+ void setUniform(const std::string &name, int index,
+ const std::string &data);
static bool isRender(const trace::Call &c);
static bool changesContext(const trace::Call &c);
static bool endsFrame(const trace::Call &c);
static int currentRenderBuffer();
private:
+ void overrideUniforms() const;
+
trace::AbstractParser *m_parser;
retrace::Retracer *m_retracer;
RenderBookmark m_bookmark;
@@ -93,6 +98,19 @@ class RetraceRender {
bool m_end_of_frame, m_highlight_rt, m_changes_context;
std::vector<std::string> m_api_calls;
bool m_disabled, m_simple_shader;
+ struct UniformKey {
+ std::string name;
+ int index;
+ UniformKey(const std::string &n, int i) : name(n), index(i) {}
+ bool operator<(const UniformKey &o) const {
+ if (name < o.name)
+ return true;
+ if (name > o.name)
+ return false;
+ return index < o.index;
+ }
+ };
+ std::map<UniformKey, std::string> m_uniform_overrides;
};
} // namespace glretrace
diff --git a/retrace/daemon/glframe_retrace_skeleton.cpp b/retrace/daemon/glframe_retrace_skeleton.cpp
index 9b475734..23b2b588 100644
--- a/retrace/daemon/glframe_retrace_skeleton.cpp
+++ b/retrace/daemon/glframe_retrace_skeleton.cpp
@@ -369,6 +369,22 @@ FrameRetraceSkeleton::Run() {
writeResponse(m_socket, proto_response, &m_buf);
break;
}
+ case ApiTrace::SET_UNIFORM_REQUEST:
+ {
+ assert(request.has_set_uniform());
+ auto set_uniform = request.set_uniform();
+ RenderSelection selection;
+ makeRenderSelection(set_uniform.selection(), &selection);
+ auto data_begin = set_uniform.data().begin();
+ auto data_end = set_uniform.data().end();
+ const std::vector<unsigned char> uniform_data(data_begin,
+ data_end);
+ m_frame->setUniform(selection,
+ set_uniform.name(),
+ set_uniform.index(),
+ set_uniform.data());
+ break;
+ }
}
}
}
diff --git a/retrace/daemon/glframe_retrace_stub.cpp b/retrace/daemon/glframe_retrace_stub.cpp
index 4def13da..419f2dc4 100644
--- a/retrace/daemon/glframe_retrace_stub.cpp
+++ b/retrace/daemon/glframe_retrace_stub.cpp
@@ -906,6 +906,32 @@ class UniformRequest : public IRetraceRequest {
OnFrameRetrace *m_callback;
};
+class SetUniformRequest : public IRetraceRequest {
+ public:
+ SetUniformRequest(const RenderSelection &selection,
+ const std::string &name,
+ int index,
+ const std::string &data) {
+ m_proto_msg.set_requesttype(ApiTrace::SET_UNIFORM_REQUEST);
+ auto request = m_proto_msg.mutable_set_uniform();
+ auto selectionRequest = request->mutable_selection();
+ makeRenderSelection(selection, selectionRequest);
+ request->set_name(name);
+ request->set_index(index);
+ request->set_data(data);
+ }
+
+
+ virtual void retrace(RetraceSocket *s) {
+ {
+ s->request(m_proto_msg);
+ }
+ }
+
+ private:
+ RetraceRequest m_proto_msg;
+};
+
class NullRequest : public IRetraceRequest {
public:
// to pump the thread, and force it to stop
@@ -1153,3 +1179,16 @@ FrameRetraceStub::retraceUniform(const RenderSelection &selection,
&m_mutex,
selection, callback));
}
+
+void
+FrameRetraceStub::setUniform(const RenderSelection &selection,
+ const std::string &name,
+ int index,
+ const std::string &data) {
+ {
+ std::lock_guard<std::mutex> l(m_mutex);
+ assert(m_current_render_selection <= selection.id);
+ m_current_render_selection = selection.id;
+ }
+ m_thread->push(new SetUniformRequest(selection, name, index, data));
+}
diff --git a/retrace/daemon/glframe_retrace_stub.hpp b/retrace/daemon/glframe_retrace_stub.hpp
index 4c47f574..4514c774 100644
--- a/retrace/daemon/glframe_retrace_stub.hpp
+++ b/retrace/daemon/glframe_retrace_stub.hpp
@@ -89,6 +89,10 @@ class FrameRetraceStub : public IFrameRetrace {
virtual void retraceUniform(const RenderSelection &selection,
ExperimentId experimentCount,
OnFrameRetrace *callback);
+ virtual void setUniform(const RenderSelection &selection,
+ const std::string &name,
+ int index,
+ const std::string &data);
private:
mutable std::mutex m_mutex;
diff --git a/retrace/daemon/glframe_uniforms.cpp b/retrace/daemon/glframe_uniforms.cpp
index d03cfd9a..678beeca 100644
--- a/retrace/daemon/glframe_uniforms.cpp
+++ b/retrace/daemon/glframe_uniforms.cpp
@@ -30,6 +30,7 @@
#include <assert.h>
#include <GL/gl.h>
#include <GL/glext.h>
+#include <string.h>
#include <sstream>
#include <string>
@@ -54,6 +55,9 @@ class Uniform {
ExperimentId experimentCount,
RenderId renderId,
OnFrameRetrace *callback) const;
+ void overrideUniform(const std::string &name,
+ int index,
+ const std::string &value);
private:
enum UniformType {
@@ -537,6 +541,76 @@ Uniform::onUniform(SelectionId selectionCount,
m_name, t, d, m_data);
}
+void
+Uniform::overrideUniform(const std::string &name,
+ int index,
+ const std::string &value) {
+ if (name != m_name)
+ return;
+ glretrace::UniformType t;
+ switch (m_dataType) {
+ case k_float:
+ case k_vec2:
+ case k_vec3:
+ case k_vec4:
+ case k_mat2:
+ case k_mat3:
+ case k_mat4:
+ case k_mat2x3:
+ case k_mat2x4:
+ case k_mat3x2:
+ case k_mat3x4:
+ case k_mat4x2:
+ case k_mat4x3:
+ t = kFloatUniform;
+ break;
+ case k_int:
+ case k_ivec2:
+ case k_ivec3:
+ case k_ivec4:
+ case k_sampler:
+ t = kIntUniform;
+ break;
+ case k_uint:
+ case k_uivec2:
+ case k_uivec3:
+ case k_uivec4:
+ t = kUIntUniform;
+ break;
+ case k_bool:
+ case k_bvec2:
+ case k_bvec3:
+ case k_bvec4:
+ t = kBoolUniform;
+ break;
+ default:
+ assert(false);
+ }
+ assert((unsigned)4*index < m_data.size());
+ void * dest = (4 * index) + m_data.data();
+ switch (t) {
+ case kFloatUniform:
+ {
+ const float f = std::stof(value);
+ assert(sizeof(f) == 4);
+ memcpy(dest, &f, sizeof(f));
+ break;
+ }
+ case kIntUniform:
+ case kUIntUniform:
+ case kBoolUniform:
+ {
+ const uint32_t i = std::stoi(value);
+ assert(sizeof(i) == 4);
+ memcpy(dest, &i, sizeof(i));
+ break;
+ }
+ default:
+ assert(false);
+ }
+}
+
+
Uniforms::Uniforms() {
int prog, uniform_count;
GL::GetError();
@@ -572,3 +646,11 @@ Uniforms::onUniform(SelectionId selectionCount,
u->onUniform(selectionCount, experimentCount,
renderId, callback);
}
+
+void
+Uniforms::overrideUniform(const std::string &name,
+ int index,
+ const std::string &value) {
+ for (auto u : m_uniforms)
+ u->overrideUniform(name, index, value);
+}
diff --git a/retrace/daemon/glframe_uniforms.hpp b/retrace/daemon/glframe_uniforms.hpp
index 64cbfed9..5ad87919 100644
--- a/retrace/daemon/glframe_uniforms.hpp
+++ b/retrace/daemon/glframe_uniforms.hpp
@@ -48,6 +48,9 @@ class Uniforms {
ExperimentId experimentCount,
RenderId renderId,
OnFrameRetrace *callback) const;
+ void overrideUniform(const std::string &name,
+ int index,
+ const std::string &value);
private:
std::vector<Uniform*> m_uniforms;
};
diff --git a/retrace/daemon/playback.proto b/retrace/daemon/playback.proto
index 2b4e46e7..93242b1e 100644
--- a/retrace/daemon/playback.proto
+++ b/retrace/daemon/playback.proto
@@ -18,6 +18,7 @@ enum RequestType {
DISABLE_REQUEST = 9;
SIMPLE_SHADER_REQUEST = 10;
UNIFORM_REQUEST = 11;
+ SET_UNIFORM_REQUEST = 12;
};
message OpenFileRequest {
@@ -211,6 +212,13 @@ message UniformResponse {
required bytes data = 7;
}
+message SetUniformRequest {
+ required RenderSelection selection = 1;
+ required string name = 2;
+ required uint32 index = 3;
+ required string data = 4;
+}
+
message DisableRequest {
required RenderSelection selection = 1;
required bool disable = 2;
@@ -234,6 +242,7 @@ message RetraceRequest {
optional DisableRequest disable = 10;
optional SimpleRequest simpleShader = 11;
optional UniformRequest uniform = 12;
+ optional SetUniformRequest set_uniform = 13;
}
message RetraceResponse {
diff --git a/retrace/daemon/ui/glframe_retrace_model.cpp b/retrace/daemon/ui/glframe_retrace_model.cpp
index c2caec29..79939910 100644
--- a/retrace/daemon/ui/glframe_retrace_model.cpp
+++ b/retrace/daemon/ui/glframe_retrace_model.cpp
@@ -65,7 +65,7 @@ using glretrace::UniformDimension;
FrameRetraceModel::FrameRetraceModel()
: m_experiment(&m_retrace),
m_rendertarget(new QRenderTargetModel(this)),
- m_uniforms(new QUniformsModel()),
+ m_uniforms(new QUniformsModel(&m_retrace)),
m_state(NULL),
m_selection(NULL),
m_selection_count(0),
@@ -416,6 +416,8 @@ FrameRetraceModel::setSelection(QSelection *s) {
s, &QSelection::experiment);
connect(s, &QSelection::onExperiment,
&m_shaders, &QRenderShadersList::onExperiment);
+ connect(m_uniforms, &QUniformsModel::uniformExperiment,
+ s, &QSelection::experiment);
}
void
@@ -533,6 +535,7 @@ FrameRetraceModel::onExperiment(ExperimentId experiment_count) {
refreshBarMetrics();
retrace_shader_assemblies();
retrace_batch();
+ retrace_uniforms();
}
void
diff --git a/retrace/daemon/ui/glframe_uniform_model.cpp b/retrace/daemon/ui/glframe_uniform_model.cpp
index 736d332d..d35d55b4 100644
--- a/retrace/daemon/ui/glframe_uniform_model.cpp
+++ b/retrace/daemon/ui/glframe_uniform_model.cpp
@@ -45,6 +45,10 @@ using glretrace::UniformDimension;
QUniformsModel::QUniformsModel() {
}
+QUniformsModel::QUniformsModel(IFrameRetrace *retrace)
+ : m_retrace(retrace) {
+}
+
QUniformsModel::~QUniformsModel() {
}
@@ -74,6 +78,7 @@ QUniformsModel::onUniform(SelectionId selectionCount,
ScopedLock s(m_protect);
QUniformValue *u = new QUniformValue(name, type, dimension, data);
m_uniforms_by_renderid[renderId].push_back(u);
+ m_sel_count = selectionCount;
}
void
@@ -228,4 +233,18 @@ void
QUniformsModel::setUniform(const QString &name,
const int index,
const QString &value) {
+ RenderSelection selection;
+ selection.id = m_sel_count;
+ auto render = m_uniforms_by_renderid.begin();
+ for (int i = 0; i < m_index; ++i)
+ ++render;
+
+ selection.series.push_back(RenderSequence(render->first,
+ RenderId(render->first() + 1)));
+ m_retrace->setUniform(selection,
+ name.toStdString(),
+ index,
+ value.toStdString());
+ emit uniformExperiment();
}
+
diff --git a/retrace/daemon/ui/glframe_uniform_model.hpp b/retrace/daemon/ui/glframe_uniform_model.hpp
index 811fa2a8..e6a2ca2c 100644
--- a/retrace/daemon/ui/glframe_uniform_model.hpp
+++ b/retrace/daemon/ui/glframe_uniform_model.hpp
@@ -92,6 +92,7 @@ class QUniformsModel : public QObject,
NOTIFY uniformsChanged)
public:
QUniformsModel();
+ explicit QUniformsModel(IFrameRetrace *retrace);
~QUniformsModel();
QStringList renders() const;
QQmlListProperty<QUniformValue> uniforms();
@@ -113,13 +114,16 @@ class QUniformsModel : public QObject,
void rendersChanged();
// after index is selected, uniform data is available
void uniformsChanged();
+ void uniformExperiment();
private:
// stores a list of render sets, collated by uniform interface. If
// two renders have identical uniforms, then they appear in the same
// set.
+ IFrameRetrace *m_retrace;
QStringList m_renders;
SelectionId m_sel_count;
+ ExperimentId m_experiment_count;
int m_index;
typedef QList<QUniformValue *> uniform_list;
std::map<RenderId, uniform_list> m_uniforms_by_renderid;