[PATCH] glretrace: Add a new --stub-fs to stub out fragment shaders
Carl Worth
cworth at cworth.org
Sat Aug 4 09:39:48 PDT 2012
With this option, all fragment shaders will be replaced with a stub
shader that simply draws solid magenta. This can be useful for
measuring the time spent in all other portions of the pipeline.
---
José Fonseca <jose.r.fonseca at gmail.com> writes:
> One thing to watch out is that the vertex shader could be potentially
> simplified because its outputs don't get used by the fragment shader.
Sure. So we're back to "we really need better performance-measuring
extensions" as we already agreed.
> Concerning your change, would it be possible to use a
> glGetShaderiv(GL_SHADER_TYPE) instead of the fragmentShaders set?
Good idea. That's less code, so obviously better. See below.
retrace/glretrace.py | 30 ++++++++++++++++++++++++++++++
retrace/retrace.hpp | 5 +++++
retrace/retrace_main.cpp | 8 ++++++--
3 files changed, 41 insertions(+), 2 deletions(-)
diff --git a/retrace/glretrace.py b/retrace/glretrace.py
index 08fc6a0..b22c0c0 100644
--- a/retrace/glretrace.py
+++ b/retrace/glretrace.py
@@ -289,10 +289,39 @@ class GlRetracer(Retracer):
print r' if (pipeline) {'
print r' _pipelineHasBeenBound = true;'
print r' }'
+
+ if function.name in ('glShaderSource', 'glShaderSourceARB'):
+ if (function.name == 'glShaderSource'):
+ shader_name = 'shader';
+ else:
+ shader_name = 'shaderObj';
+ print r' if (retrace::stubFragmentShaders) {'
+ print r' GLint shader_type;'
+ print r' glGetShaderiv(%s, GL_SHADER_TYPE, &shader_type);' % (shader_name)
+ print r' if (shader_type == GL_FRAGMENT_SHADER) {'
+ print r' count = 1;'
+ print r' string[0] = "#version 120\n\n"'
+ print r' "void main()\n"'
+ print r' "{\n"'
+ print r' " /* Magenta! */\n"'
+ print r' " gl_FragColor = vec4(1, 0, 1, 1);\n"'
+ print r' "}";'
+ print r' length[0] = strlen(string[0]);'
+ print r' }'
+ print r' }'
if function.name == 'glCreateShaderProgramv':
# When dumping state, break down glCreateShaderProgramv so that the
# shader source can be recovered.
+ print r' if (retrace::stubFragmentShaders && type == GL_FRAGMENT_SHADER) {'
+ print r' count = 1;'
+ print r' strings[0] = "#version 120\n\n"'
+ print r' "void main()\n"'
+ print r' "{\n"'
+ print r' " /* Magenta! */\n"'
+ print r' " gl_FragColor = vec4(1, 0, 1, 1);\n"'
+ print r' "}";'
+ print r' }'
print r' if (retrace::dumpingState) {'
print r' GLuint _shader = glCreateShader(type);'
print r' if (_shader) {'
@@ -477,6 +506,7 @@ class GlRetracer(Retracer):
if __name__ == '__main__':
print r'''
#include <string.h>
+#include <set>
#include "glproc.hpp"
#include "glretrace.hpp"
diff --git a/retrace/retrace.hpp b/retrace/retrace.hpp
index 0ee0e55..be49156 100644
--- a/retrace/retrace.hpp
+++ b/retrace/retrace.hpp
@@ -152,6 +152,11 @@ extern bool profiling;
*/
extern bool dumpingState;
+/**
+ * Stubbing out fragment shaders (to measure vertex shader contribution)
+ */
+extern bool stubFragmentShaders;
+
extern bool doubleBuffer;
extern bool coreProfile;
diff --git a/retrace/retrace_main.cpp b/retrace/retrace_main.cpp
index 093ab17..1538e0a 100644
--- a/retrace/retrace_main.cpp
+++ b/retrace/retrace_main.cpp
@@ -55,7 +55,7 @@ int verbosity = 0;
bool debug = true;
bool profiling = false;
bool dumpingState = false;
-
+bool stubFragmentShaders = false;
bool doubleBuffer = true;
bool coreProfile = false;
@@ -290,7 +290,9 @@ usage(const char *argv0) {
" -S CALLSET calls to snapshot (default is every frame)\n"
" -v increase output verbosity\n"
" -D CALLNO dump state at specific call no\n"
- " -w waitOnFinish on final frame\n";
+ " -w waitOnFinish on final frame\n"
+ " --stub-fs Replace all fragment shaders with stub drawing magenta\n."
+ " This allows for profiling to separate fragment-shader time.\n";
}
@@ -319,6 +321,8 @@ int main(int argc, char **argv)
retrace::debug = false;
retrace::profiling = true;
retrace::verbosity = -1;
+ } else if (!strcmp(arg, "--stub-fs")) {
+ retrace::stubFragmentShaders = true;
} else if (!strcmp(arg, "-c")) {
comparePrefix = argv[++i];
if (compareFrequency.empty()) {
--
1.7.10
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/apitrace/attachments/20120804/9d60ce10/attachment.pgp>
More information about the apitrace
mailing list