blob: b19ba69b09d75c9a9e8a44bef1c2d839e00ec5b2 [file] [log] [blame]
José Fonseca589082d2011-03-30 09:10:40 +01001/**************************************************************************
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 Fonseca9653f952015-05-19 16:32:43 +010026#pragma once
José Fonseca589082d2011-03-30 09:10:40 +010027
José Fonseca32871ed2011-04-10 13:40:52 +010028#include "glws.hpp"
José Fonseca2741ed82011-10-07 23:36:39 +010029#include "retrace.hpp"
Alexander Trukhin019b38b2015-06-29 20:28:26 +030030#include "metric_backend.hpp"
José Fonseca32871ed2011-04-10 13:40:52 +010031
Jose Fonsecacda621d2015-08-06 13:57:06 +010032#include "os_thread.hpp"
Mark Janes95feab72019-12-20 17:01:56 -080033#include "retrace_swizzle.hpp"
Jose Fonsecacda621d2015-08-06 13:57:06 +010034
José Fonseca32871ed2011-04-10 13:40:52 +010035
Alexander Trukhin44c83b72017-03-11 15:41:21 +030036class MetricWriter;
37
José Fonseca32871ed2011-04-10 13:40:52 +010038namespace glretrace {
39
Jose Fonsecad41db362016-04-16 15:32:13 +010040class Context
41{
42public:
James Benton60139d62012-08-09 14:23:44 +010043 Context(glws::Context* context)
Jose Fonseca83fb8902016-04-14 07:03:44 +010044 : wsContext(context)
James Benton60139d62012-08-09 14:23:44 +010045 {
46 }
47
Jose Fonsecad41db362016-04-16 15:32:13 +010048private:
49 unsigned refCount = 1;
José Fonsecab54d9bb2012-10-24 20:04:54 +010050 ~Context();
James Benton60139d62012-08-09 14:23:44 +010051
Jose Fonsecad41db362016-04-16 15:32:13 +010052public:
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 Benton60139d62012-08-09 14:23:44 +010067 glws::Context* wsContext;
José Fonseca5ed4ca62012-10-19 17:34:30 +010068
69 // Bound drawable
Jose Fonseca83fb8902016-04-14 07:03:44 +010070 glws::Drawable *drawable = nullptr;
Brian Paulde04a062016-10-06 10:59:22 -060071 glws::Drawable *readable = nullptr;
José Fonseca5ed4ca62012-10-19 17:34:30 +010072
Jose Fonseca8e0a0302016-05-04 23:53:46 +010073 // 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 Fonseca12b82172015-08-06 13:41:54 +010080 bool insideBeginEnd = false;
81 bool insideList = false;
Jose Fonsecaa7caf012016-04-14 07:11:12 +010082 bool needsFlush = false;
Jose Fonseca12b82172015-08-06 13:41:54 +010083
Jose Fonseca83fb8902016-04-14 07:03:44 +010084 bool used = false;
Jose Fonsecae58cc502015-06-27 12:57:08 +010085
Jose Fonseca83fb8902016-04-14 07:03:44 +010086 bool KHR_debug = false;
Jose Fonseca267a88f2016-01-23 08:42:04 +000087 GLsizei maxDebugMessageLength = 0;
Rob Clarkfe43ae72016-01-20 16:52:11 -050088
Jose Fonseca9ed64622016-04-04 13:36:12 +010089 inline glfeatures::Profile
Jose Fonsecae58cc502015-06-27 12:57:08 +010090 profile(void) const {
91 return wsContext->profile;
92 }
Jose Fonseca6d7ddcc2015-08-25 22:05:36 +010093
Jose Fonseca9ed64622016-04-04 13:36:12 +010094 inline glfeatures::Profile
Jose Fonseca6d7ddcc2015-08-25 22:05:36 +010095 actualProfile(void) const {
96 return wsContext->actualProfile;
97 }
98
Jose Fonseca8d6653a2016-04-04 15:42:25 +010099 inline const glfeatures::Features &
100 features(void) const {
101 return wsContext->actualFeatures;
102 }
103
José Fonsecad1c301f2012-10-18 15:22:41 +0100104 inline bool
105 hasExtension(const char *extension) const {
106 return wsContext->hasExtension(extension);
107 }
James Benton60139d62012-08-09 14:23:44 +0100108};
José Fonseca32871ed2011-04-10 13:40:52 +0100109
Alexander Trukhin87a07772015-06-29 21:13:48 +0300110extern bool metricBackendsSetup;
Alexander Trukhin1d0bf772015-08-24 23:17:43 +0300111extern bool profilingContextAcquired;
Alexander Trukhin87a07772015-06-29 21:13:48 +0300112extern bool profilingBoundaries[QUERY_BOUNDARY_LIST_END];
Alexander Trukhin260a97b2015-06-29 21:13:48 +0300113extern unsigned profilingBoundariesIndex[QUERY_BOUNDARY_LIST_END];
Alexander Trukhin87a07772015-06-29 21:13:48 +0300114extern std::vector<MetricBackend*> metricBackends;
115extern MetricBackend* curMetricBackend;
Alexander Trukhin44c83b72017-03-11 15:41:21 +0300116MetricWriter& profiler();
Alexander Trukhin87a07772015-06-29 21:13:48 +0300117
Jose Fonseca9ed64622016-04-04 13:36:12 +0100118extern glfeatures::Profile defaultProfile;
José Fonseca797901b2013-10-29 18:59:08 +0000119
Carl Worth37007772012-08-28 11:45:52 -0700120extern bool supportsARBShaderObjects;
José Fonsecaa50b8972012-04-26 23:18:28 +0100121
Jose Fonseca0dbd33a2016-04-16 15:04:04 +0100122extern OS_THREAD_LOCAL Context *
Jose Fonsecacda621d2015-08-06 13:57:06 +0100123currentContextPtr;
124
125
126static inline Context *
127getCurrentContext(void) {
128 return currentContextPtr;
129}
José Fonsecaa50b8972012-04-26 23:18:28 +0100130
José Fonseca958d9802012-10-19 15:39:49 +0100131
132int
José Fonsecae0f2ff02015-01-05 22:17:50 +0000133parseAttrib(const trace::Value *attribs, int param, int default_ = 0, int terminator = 0);
José Fonseca958d9802012-10-19 15:39:49 +0100134
Jose Fonseca9ed64622016-04-04 13:36:12 +0100135glfeatures::Profile
José Fonseca9ee58032014-05-28 18:27:20 +0100136parseContextAttribList(const trace::Value *attribs);
137
José Fonseca958d9802012-10-19 15:39:49 +0100138
José Fonsecaa50b8972012-04-26 23:18:28 +0100139glws::Drawable *
Jose Fonseca9ed64622016-04-04 13:36:12 +0100140createDrawable(glfeatures::Profile profile);
José Fonsecaa50b8972012-04-26 23:18:28 +0100141
142glws::Drawable *
143createDrawable(void);
144
José Fonsecae23365e2012-10-22 18:55:52 +0100145glws::Drawable *
Brian Paul14b02d42015-10-26 15:38:18 -0600146createPbuffer(int width, int height, const glws::pbuffer_info *info);
José Fonsecae23365e2012-10-22 18:55:52 +0100147
James Benton60139d62012-08-09 14:23:44 +0100148Context *
Jose Fonseca9ed64622016-04-04 13:36:12 +0100149createContext(Context *shareContext, glfeatures::Profile profile);
José Fonsecaa50b8972012-04-26 23:18:28 +0100150
James Benton60139d62012-08-09 14:23:44 +0100151Context *
152createContext(Context *shareContext = 0);
José Fonsecaa50b8972012-04-26 23:18:28 +0100153
154bool
James Benton60139d62012-08-09 14:23:44 +0100155makeCurrent(trace::Call &call, glws::Drawable *drawable, Context *context);
José Fonsecaa50b8972012-04-26 23:18:28 +0100156
Brian Paulde04a062016-10-06 10:59:22 -0600157bool
158makeCurrent(trace::Call &call, glws::Drawable *drawable,
159 glws::Drawable *readable, Context *context);
160
José Fonseca32871ed2011-04-10 13:40:52 +0100161
José Fonseca32871ed2011-04-10 13:40:52 +0100162void
José Fonsecab4a3d142011-10-27 07:43:19 +0100163checkGlError(trace::Call &call);
José Fonseca32871ed2011-04-10 13:40:52 +0100164
Jose Fonsecabb6634d2016-01-22 23:12:21 +0000165void
Jose Fonseca267a88f2016-01-23 08:42:04 +0000166insertCallMarker(trace::Call &call, Context *currentContext);
Jose Fonsecabb6634d2016-01-22 23:12:21 +0000167
Mark Janes95feab72019-12-20 17:01:56 -0800168void
169mapResourceLocation(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);
174void
175trackResourceName(GLuint program, GLenum programInterface,
176 GLint index, const std::string &traced_name);
Jose Fonsecabb6634d2016-01-22 23:12:21 +0000177
Mark Janes35b25362020-01-02 20:47:44 -0800178void
179mapUniformBlockName(GLuint program,
180 GLint index,
181 const std::string &traced_name,
182 std::map<GLuint, retrace::map<GLuint>> &uniformBlock_map);
183
José Fonseca2741ed82011-10-07 23:36:39 +0100184extern const retrace::Entry gl_callbacks[];
185extern const retrace::Entry cgl_callbacks[];
186extern const retrace::Entry glx_callbacks[];
187extern const retrace::Entry wgl_callbacks[];
Chia-I Wud71895d2011-11-02 20:16:36 +0800188extern const retrace::Entry egl_callbacks[];
José Fonseca06aa2842011-05-05 07:55:54 +0100189
José Fonsecab4a3d142011-10-27 07:43:19 +0100190void frame_complete(trace::Call &call);
James Bentonb5801e32012-08-09 14:22:24 +0100191void initContext();
Alexander Trukhin1d0bf772015-08-24 23:17:43 +0300192void beforeContextSwitch();
193void afterContextSwitch();
James Bentonb5801e32012-08-09 14:22:24 +0100194
José Fonsecae4999b92011-05-05 00:31:01 +0100195
José Fonseca757b2b62011-09-19 10:09:53 +0100196void updateDrawable(int width, int height);
José Fonseca32871ed2011-04-10 13:40:52 +0100197
James Bentonef6880f2012-07-23 18:12:27 +0100198void flushQueries();
James Bentonc53c6492012-08-13 18:21:16 +0100199void beginProfile(trace::Call &call, bool isDraw);
200void endProfile(trace::Call &call, bool isDraw);
James Bentonaddf7f92012-07-20 18:56:19 +0100201
Alexander Trukhin019b38b2015-06-29 20:28:26 +0300202MetricBackend* getBackend(std::string backendName);
203
Alexander Trukhin87a07772015-06-29 21:13:48 +0300204bool isLastPass();
205
Alexander Trukhin7f9933f2015-06-29 21:13:48 +0300206void listMetricsCLI();
207
Alexander Trukhin87a07772015-06-29 21:13:48 +0300208void enableMetricsFromCLI(const char* metrics, QueryBoundary pollingRule);
209
José Fonseca04e95f62014-12-12 21:09:21 +0000210GLenum
211blockOnFence(trace::Call &call, GLsync sync, GLbitfield flags);
212
213GLenum
214clientWaitSync(trace::Call &call, GLsync sync, GLbitfield flags, GLuint64 timeout);
215
Brian Paulcb68a602015-10-26 15:59:04 -0600216
217// WGL_ARB_render_texture
218bool
219bindTexImage(glws::Drawable *pBuffer, int iBuffer);
220
221// WGL_ARB_render_texture
222bool
223releaseTexImage(glws::Drawable *pBuffer, int iBuffer);
224
225// WGL_ARB_render_texture
226bool
227setPbufferAttrib(glws::Drawable *pBuffer, const int *attribList);
228
José Fonseca32871ed2011-04-10 13:40:52 +0100229} /* namespace glretrace */
230
231