José Fonseca | 589082d | 2011-03-30 09:10:40 +0100 | [diff] [blame] | 1 | /************************************************************************** |
| 2 | * |
| 3 | * Copyright 2011 Jose Fonseca |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to deal |
| 8 | * in the Software without restriction, including without limitation the rights |
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | * copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 | * THE SOFTWARE. |
| 23 | * |
| 24 | **************************************************************************/ |
| 25 | |
Jose Fonseca | 9653f95 | 2015-05-19 16:32:43 +0100 | [diff] [blame] | 26 | #pragma once |
José Fonseca | 589082d | 2011-03-30 09:10:40 +0100 | [diff] [blame] | 27 | |
José Fonseca | 32871ed | 2011-04-10 13:40:52 +0100 | [diff] [blame] | 28 | #include "glws.hpp" |
José Fonseca | 2741ed8 | 2011-10-07 23:36:39 +0100 | [diff] [blame] | 29 | #include "retrace.hpp" |
Alexander Trukhin | 019b38b | 2015-06-29 20:28:26 +0300 | [diff] [blame] | 30 | #include "metric_backend.hpp" |
José Fonseca | 32871ed | 2011-04-10 13:40:52 +0100 | [diff] [blame] | 31 | |
Jose Fonseca | cda621d | 2015-08-06 13:57:06 +0100 | [diff] [blame] | 32 | #include "os_thread.hpp" |
Mark Janes | 95feab7 | 2019-12-20 17:01:56 -0800 | [diff] [blame] | 33 | #include "retrace_swizzle.hpp" |
Jose Fonseca | cda621d | 2015-08-06 13:57:06 +0100 | [diff] [blame] | 34 | |
José Fonseca | 32871ed | 2011-04-10 13:40:52 +0100 | [diff] [blame] | 35 | |
Alexander Trukhin | 44c83b7 | 2017-03-11 15:41:21 +0300 | [diff] [blame] | 36 | class MetricWriter; |
| 37 | |
José Fonseca | 32871ed | 2011-04-10 13:40:52 +0100 | [diff] [blame] | 38 | namespace glretrace { |
| 39 | |
Jose Fonseca | d41db36 | 2016-04-16 15:32:13 +0100 | [diff] [blame] | 40 | class Context |
| 41 | { |
| 42 | public: |
James Benton | 60139d6 | 2012-08-09 14:23:44 +0100 | [diff] [blame] | 43 | Context(glws::Context* context) |
Jose Fonseca | 83fb890 | 2016-04-14 07:03:44 +0100 | [diff] [blame] | 44 | : wsContext(context) |
James Benton | 60139d6 | 2012-08-09 14:23:44 +0100 | [diff] [blame] | 45 | { |
| 46 | } |
| 47 | |
Jose Fonseca | d41db36 | 2016-04-16 15:32:13 +0100 | [diff] [blame] | 48 | private: |
| 49 | unsigned refCount = 1; |
José Fonseca | b54d9bb | 2012-10-24 20:04:54 +0100 | [diff] [blame] | 50 | ~Context(); |
James Benton | 60139d6 | 2012-08-09 14:23:44 +0100 | [diff] [blame] | 51 | |
Jose Fonseca | d41db36 | 2016-04-16 15:32:13 +0100 | [diff] [blame] | 52 | public: |
| 53 | inline void |
| 54 | aquire(void) { |
| 55 | assert(refCount); |
| 56 | ++refCount; |
| 57 | } |
| 58 | |
| 59 | inline void |
| 60 | release(void) { |
| 61 | assert(refCount); |
| 62 | if (--refCount == 0) { |
| 63 | delete this; |
| 64 | } |
| 65 | } |
| 66 | |
James Benton | 60139d6 | 2012-08-09 14:23:44 +0100 | [diff] [blame] | 67 | glws::Context* wsContext; |
José Fonseca | 5ed4ca6 | 2012-10-19 17:34:30 +0100 | [diff] [blame] | 68 | |
| 69 | // Bound drawable |
Jose Fonseca | 83fb890 | 2016-04-14 07:03:44 +0100 | [diff] [blame] | 70 | glws::Drawable *drawable = nullptr; |
Brian Paul | de04a06 | 2016-10-06 10:59:22 -0600 | [diff] [blame] | 71 | glws::Drawable *readable = nullptr; |
José Fonseca | 5ed4ca6 | 2012-10-19 17:34:30 +0100 | [diff] [blame] | 72 | |
Jose Fonseca | 8e0a030 | 2016-05-04 23:53:46 +0100 | [diff] [blame] | 73 | // Active program (unswizzled) for profiling |
| 74 | GLuint currentUserProgram = 0; |
| 75 | |
| 76 | // Current program (swizzled) for uniform swizzling |
| 77 | GLuint currentProgram = 0; |
| 78 | GLuint currentPipeline = 0; |
| 79 | |
Jose Fonseca | 12b8217 | 2015-08-06 13:41:54 +0100 | [diff] [blame] | 80 | bool insideBeginEnd = false; |
| 81 | bool insideList = false; |
Jose Fonseca | a7caf01 | 2016-04-14 07:11:12 +0100 | [diff] [blame] | 82 | bool needsFlush = false; |
Jose Fonseca | 12b8217 | 2015-08-06 13:41:54 +0100 | [diff] [blame] | 83 | |
Jose Fonseca | 83fb890 | 2016-04-14 07:03:44 +0100 | [diff] [blame] | 84 | bool used = false; |
Jose Fonseca | e58cc50 | 2015-06-27 12:57:08 +0100 | [diff] [blame] | 85 | |
Jose Fonseca | 83fb890 | 2016-04-14 07:03:44 +0100 | [diff] [blame] | 86 | bool KHR_debug = false; |
Jose Fonseca | 267a88f | 2016-01-23 08:42:04 +0000 | [diff] [blame] | 87 | GLsizei maxDebugMessageLength = 0; |
Rob Clark | fe43ae7 | 2016-01-20 16:52:11 -0500 | [diff] [blame] | 88 | |
Jose Fonseca | 9ed6462 | 2016-04-04 13:36:12 +0100 | [diff] [blame] | 89 | inline glfeatures::Profile |
Jose Fonseca | e58cc50 | 2015-06-27 12:57:08 +0100 | [diff] [blame] | 90 | profile(void) const { |
| 91 | return wsContext->profile; |
| 92 | } |
Jose Fonseca | 6d7ddcc | 2015-08-25 22:05:36 +0100 | [diff] [blame] | 93 | |
Jose Fonseca | 9ed6462 | 2016-04-04 13:36:12 +0100 | [diff] [blame] | 94 | inline glfeatures::Profile |
Jose Fonseca | 6d7ddcc | 2015-08-25 22:05:36 +0100 | [diff] [blame] | 95 | actualProfile(void) const { |
| 96 | return wsContext->actualProfile; |
| 97 | } |
| 98 | |
Jose Fonseca | 8d6653a | 2016-04-04 15:42:25 +0100 | [diff] [blame] | 99 | inline const glfeatures::Features & |
| 100 | features(void) const { |
| 101 | return wsContext->actualFeatures; |
| 102 | } |
| 103 | |
José Fonseca | d1c301f | 2012-10-18 15:22:41 +0100 | [diff] [blame] | 104 | inline bool |
| 105 | hasExtension(const char *extension) const { |
| 106 | return wsContext->hasExtension(extension); |
| 107 | } |
James Benton | 60139d6 | 2012-08-09 14:23:44 +0100 | [diff] [blame] | 108 | }; |
José Fonseca | 32871ed | 2011-04-10 13:40:52 +0100 | [diff] [blame] | 109 | |
Alexander Trukhin | 87a0777 | 2015-06-29 21:13:48 +0300 | [diff] [blame] | 110 | extern bool metricBackendsSetup; |
Alexander Trukhin | 1d0bf77 | 2015-08-24 23:17:43 +0300 | [diff] [blame] | 111 | extern bool profilingContextAcquired; |
Alexander Trukhin | 87a0777 | 2015-06-29 21:13:48 +0300 | [diff] [blame] | 112 | extern bool profilingBoundaries[QUERY_BOUNDARY_LIST_END]; |
Alexander Trukhin | 260a97b | 2015-06-29 21:13:48 +0300 | [diff] [blame] | 113 | extern unsigned profilingBoundariesIndex[QUERY_BOUNDARY_LIST_END]; |
Alexander Trukhin | 87a0777 | 2015-06-29 21:13:48 +0300 | [diff] [blame] | 114 | extern std::vector<MetricBackend*> metricBackends; |
| 115 | extern MetricBackend* curMetricBackend; |
Alexander Trukhin | 44c83b7 | 2017-03-11 15:41:21 +0300 | [diff] [blame] | 116 | MetricWriter& profiler(); |
Alexander Trukhin | 87a0777 | 2015-06-29 21:13:48 +0300 | [diff] [blame] | 117 | |
Jose Fonseca | 9ed6462 | 2016-04-04 13:36:12 +0100 | [diff] [blame] | 118 | extern glfeatures::Profile defaultProfile; |
José Fonseca | 797901b | 2013-10-29 18:59:08 +0000 | [diff] [blame] | 119 | |
Carl Worth | 3700777 | 2012-08-28 11:45:52 -0700 | [diff] [blame] | 120 | extern bool supportsARBShaderObjects; |
José Fonseca | a50b897 | 2012-04-26 23:18:28 +0100 | [diff] [blame] | 121 | |
Jose Fonseca | 0dbd33a | 2016-04-16 15:04:04 +0100 | [diff] [blame] | 122 | extern OS_THREAD_LOCAL Context * |
Jose Fonseca | cda621d | 2015-08-06 13:57:06 +0100 | [diff] [blame] | 123 | currentContextPtr; |
| 124 | |
| 125 | |
| 126 | static inline Context * |
| 127 | getCurrentContext(void) { |
| 128 | return currentContextPtr; |
| 129 | } |
José Fonseca | a50b897 | 2012-04-26 23:18:28 +0100 | [diff] [blame] | 130 | |
José Fonseca | 958d980 | 2012-10-19 15:39:49 +0100 | [diff] [blame] | 131 | |
| 132 | int |
José Fonseca | e0f2ff0 | 2015-01-05 22:17:50 +0000 | [diff] [blame] | 133 | parseAttrib(const trace::Value *attribs, int param, int default_ = 0, int terminator = 0); |
José Fonseca | 958d980 | 2012-10-19 15:39:49 +0100 | [diff] [blame] | 134 | |
Jose Fonseca | 9ed6462 | 2016-04-04 13:36:12 +0100 | [diff] [blame] | 135 | glfeatures::Profile |
José Fonseca | 9ee5803 | 2014-05-28 18:27:20 +0100 | [diff] [blame] | 136 | parseContextAttribList(const trace::Value *attribs); |
| 137 | |
José Fonseca | 958d980 | 2012-10-19 15:39:49 +0100 | [diff] [blame] | 138 | |
José Fonseca | a50b897 | 2012-04-26 23:18:28 +0100 | [diff] [blame] | 139 | glws::Drawable * |
Jose Fonseca | 9ed6462 | 2016-04-04 13:36:12 +0100 | [diff] [blame] | 140 | createDrawable(glfeatures::Profile profile); |
José Fonseca | a50b897 | 2012-04-26 23:18:28 +0100 | [diff] [blame] | 141 | |
| 142 | glws::Drawable * |
| 143 | createDrawable(void); |
| 144 | |
José Fonseca | e23365e | 2012-10-22 18:55:52 +0100 | [diff] [blame] | 145 | glws::Drawable * |
Brian Paul | 14b02d4 | 2015-10-26 15:38:18 -0600 | [diff] [blame] | 146 | createPbuffer(int width, int height, const glws::pbuffer_info *info); |
José Fonseca | e23365e | 2012-10-22 18:55:52 +0100 | [diff] [blame] | 147 | |
James Benton | 60139d6 | 2012-08-09 14:23:44 +0100 | [diff] [blame] | 148 | Context * |
Jose Fonseca | 9ed6462 | 2016-04-04 13:36:12 +0100 | [diff] [blame] | 149 | createContext(Context *shareContext, glfeatures::Profile profile); |
José Fonseca | a50b897 | 2012-04-26 23:18:28 +0100 | [diff] [blame] | 150 | |
James Benton | 60139d6 | 2012-08-09 14:23:44 +0100 | [diff] [blame] | 151 | Context * |
| 152 | createContext(Context *shareContext = 0); |
José Fonseca | a50b897 | 2012-04-26 23:18:28 +0100 | [diff] [blame] | 153 | |
| 154 | bool |
James Benton | 60139d6 | 2012-08-09 14:23:44 +0100 | [diff] [blame] | 155 | makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context); |
José Fonseca | a50b897 | 2012-04-26 23:18:28 +0100 | [diff] [blame] | 156 | |
Brian Paul | de04a06 | 2016-10-06 10:59:22 -0600 | [diff] [blame] | 157 | bool |
| 158 | makeCurrent(trace::Call &call, glws::Drawable *drawable, |
| 159 | glws::Drawable *readable, Context *context); |
| 160 | |
José Fonseca | 32871ed | 2011-04-10 13:40:52 +0100 | [diff] [blame] | 161 | |
José Fonseca | 32871ed | 2011-04-10 13:40:52 +0100 | [diff] [blame] | 162 | void |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 163 | checkGlError(trace::Call &call); |
José Fonseca | 32871ed | 2011-04-10 13:40:52 +0100 | [diff] [blame] | 164 | |
Jose Fonseca | bb6634d | 2016-01-22 23:12:21 +0000 | [diff] [blame] | 165 | void |
Jose Fonseca | 267a88f | 2016-01-23 08:42:04 +0000 | [diff] [blame] | 166 | insertCallMarker(trace::Call &call, Context *currentContext); |
Jose Fonseca | bb6634d | 2016-01-22 23:12:21 +0000 | [diff] [blame] | 167 | |
Mark Janes | 95feab7 | 2019-12-20 17:01:56 -0800 | [diff] [blame] | 168 | void |
| 169 | mapResourceLocation(GLuint program, GLenum programInterface, |
| 170 | GLint index, |
| 171 | const trace::Array *props, |
| 172 | const trace::Array *params, |
| 173 | std::map<GLhandleARB, retrace::map<GLint>> &location_map); |
| 174 | void |
| 175 | trackResourceName(GLuint program, GLenum programInterface, |
| 176 | GLint index, const std::string &traced_name); |
Jose Fonseca | bb6634d | 2016-01-22 23:12:21 +0000 | [diff] [blame] | 177 | |
Mark Janes | 35b2536 | 2020-01-02 20:47:44 -0800 | [diff] [blame] | 178 | void |
| 179 | mapUniformBlockName(GLuint program, |
| 180 | GLint index, |
| 181 | const std::string &traced_name, |
| 182 | std::map<GLuint, retrace::map<GLuint>> &uniformBlock_map); |
| 183 | |
José Fonseca | 2741ed8 | 2011-10-07 23:36:39 +0100 | [diff] [blame] | 184 | extern const retrace::Entry gl_callbacks[]; |
| 185 | extern const retrace::Entry cgl_callbacks[]; |
| 186 | extern const retrace::Entry glx_callbacks[]; |
| 187 | extern const retrace::Entry wgl_callbacks[]; |
Chia-I Wu | d71895d | 2011-11-02 20:16:36 +0800 | [diff] [blame] | 188 | extern const retrace::Entry egl_callbacks[]; |
José Fonseca | 06aa284 | 2011-05-05 07:55:54 +0100 | [diff] [blame] | 189 | |
José Fonseca | b4a3d14 | 2011-10-27 07:43:19 +0100 | [diff] [blame] | 190 | void frame_complete(trace::Call &call); |
James Benton | b5801e3 | 2012-08-09 14:22:24 +0100 | [diff] [blame] | 191 | void initContext(); |
Alexander Trukhin | 1d0bf77 | 2015-08-24 23:17:43 +0300 | [diff] [blame] | 192 | void beforeContextSwitch(); |
| 193 | void afterContextSwitch(); |
James Benton | b5801e3 | 2012-08-09 14:22:24 +0100 | [diff] [blame] | 194 | |
José Fonseca | e4999b9 | 2011-05-05 00:31:01 +0100 | [diff] [blame] | 195 | |
José Fonseca | 757b2b6 | 2011-09-19 10:09:53 +0100 | [diff] [blame] | 196 | void updateDrawable(int width, int height); |
José Fonseca | 32871ed | 2011-04-10 13:40:52 +0100 | [diff] [blame] | 197 | |
James Benton | ef6880f | 2012-07-23 18:12:27 +0100 | [diff] [blame] | 198 | void flushQueries(); |
James Benton | c53c649 | 2012-08-13 18:21:16 +0100 | [diff] [blame] | 199 | void beginProfile(trace::Call &call, bool isDraw); |
| 200 | void endProfile(trace::Call &call, bool isDraw); |
James Benton | addf7f9 | 2012-07-20 18:56:19 +0100 | [diff] [blame] | 201 | |
Alexander Trukhin | 019b38b | 2015-06-29 20:28:26 +0300 | [diff] [blame] | 202 | MetricBackend* getBackend(std::string backendName); |
| 203 | |
Alexander Trukhin | 87a0777 | 2015-06-29 21:13:48 +0300 | [diff] [blame] | 204 | bool isLastPass(); |
| 205 | |
Alexander Trukhin | 7f9933f | 2015-06-29 21:13:48 +0300 | [diff] [blame] | 206 | void listMetricsCLI(); |
| 207 | |
Alexander Trukhin | 87a0777 | 2015-06-29 21:13:48 +0300 | [diff] [blame] | 208 | void enableMetricsFromCLI(const char* metrics, QueryBoundary pollingRule); |
| 209 | |
José Fonseca | 04e95f6 | 2014-12-12 21:09:21 +0000 | [diff] [blame] | 210 | GLenum |
| 211 | blockOnFence(trace::Call &call, GLsync sync, GLbitfield flags); |
| 212 | |
| 213 | GLenum |
| 214 | clientWaitSync(trace::Call &call, GLsync sync, GLbitfield flags, GLuint64 timeout); |
| 215 | |
Brian Paul | cb68a60 | 2015-10-26 15:59:04 -0600 | [diff] [blame] | 216 | |
| 217 | // WGL_ARB_render_texture |
| 218 | bool |
| 219 | bindTexImage(glws::Drawable *pBuffer, int iBuffer); |
| 220 | |
| 221 | // WGL_ARB_render_texture |
| 222 | bool |
| 223 | releaseTexImage(glws::Drawable *pBuffer, int iBuffer); |
| 224 | |
| 225 | // WGL_ARB_render_texture |
| 226 | bool |
| 227 | setPbufferAttrib(glws::Drawable *pBuffer, const int *attribList); |
| 228 | |
José Fonseca | 32871ed | 2011-04-10 13:40:52 +0100 | [diff] [blame] | 229 | } /* namespace glretrace */ |
| 230 | |
| 231 | |