Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: tools/gpu/gl/GLTestContext.cpp

Issue 2390383002: Revert of skpbench: add option for gpu timing (Closed)
Patch Set: Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « tools/gpu/TestContext.cpp ('k') | tools/skpbench/_benchresult.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2013 Google Inc. 2 * Copyright 2013 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GLTestContext.h" 8 #include "GLTestContext.h"
9
10 #include "GpuTimer.h"
11 #include "gl/GrGLUtil.h" 9 #include "gl/GrGLUtil.h"
12 10
13 namespace { 11 namespace {
14 12
15 class GLFenceSync : public sk_gpu_test::FenceSync { 13 class GLFenceSync : public sk_gpu_test::FenceSync {
16 public: 14 public:
17 static GLFenceSync* CreateIfSupported(const sk_gpu_test::GLTestContext*); 15 static GLFenceSync* CreateIfSupported(const sk_gpu_test::GLTestContext*);
18 16
19 sk_gpu_test::PlatformFence SK_WARN_UNUSED_RESULT insertFence() const overrid e; 17 sk_gpu_test::PlatformFence SK_WARN_UNUSED_RESULT insertFence() const overrid e;
20 bool waitFence(sk_gpu_test::PlatformFence fence) const override; 18 bool waitFence(sk_gpu_test::PlatformFence fence) const override;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 bool GLFenceSync::waitFence(sk_gpu_test::PlatformFence fence) const { 70 bool GLFenceSync::waitFence(sk_gpu_test::PlatformFence fence) const {
73 GLsync glsync = reinterpret_cast<GLsync>(fence); 71 GLsync glsync = reinterpret_cast<GLsync>(fence);
74 return GL_WAIT_FAILED != fGLClientWaitSync(glsync, GL_SYNC_FLUSH_COMMANDS_BI T, -1); 72 return GL_WAIT_FAILED != fGLClientWaitSync(glsync, GL_SYNC_FLUSH_COMMANDS_BI T, -1);
75 } 73 }
76 74
77 void GLFenceSync::deleteFence(sk_gpu_test::PlatformFence fence) const { 75 void GLFenceSync::deleteFence(sk_gpu_test::PlatformFence fence) const {
78 GLsync glsync = reinterpret_cast<GLsync>(fence); 76 GLsync glsync = reinterpret_cast<GLsync>(fence);
79 fGLDeleteSync(glsync); 77 fGLDeleteSync(glsync);
80 } 78 }
81 79
82 class GLGpuTimer : public sk_gpu_test::GpuTimer {
83 public:
84 static GLGpuTimer* CreateIfSupported(const sk_gpu_test::GLTestContext*);
85
86 QueryStatus checkQueryStatus(sk_gpu_test::PlatformTimerQuery) override;
87 std::chrono::nanoseconds getTimeElapsed(sk_gpu_test::PlatformTimerQuery) ove rride;
88 void deleteQuery(sk_gpu_test::PlatformTimerQuery) override;
89
90 private:
91 GLGpuTimer(bool disjointSupport, const sk_gpu_test::GLTestContext*, const ch ar* ext = "");
92
93 bool validate() const;
94
95 sk_gpu_test::PlatformTimerQuery onQueueTimerStart() const override;
96 void onQueueTimerStop(sk_gpu_test::PlatformTimerQuery) const override;
97
98 static constexpr GrGLenum GL_QUERY_RESULT = 0x8866;
99 static constexpr GrGLenum GL_QUERY_RESULT_AVAILABLE = 0x8867;
100 static constexpr GrGLenum GL_TIME_ELAPSED = 0x88bf;
101 static constexpr GrGLenum GL_GPU_DISJOINT = 0x8fbb;
102
103 typedef void (GR_GL_FUNCTION_TYPE* GLGetIntegervProc) (GrGLenum, GrGLint*);
104 typedef void (GR_GL_FUNCTION_TYPE* GLGenQueriesProc) (GrGLsizei, GrGLuint*);
105 typedef void (GR_GL_FUNCTION_TYPE* GLDeleteQueriesProc) (GrGLsizei, const Gr GLuint*);
106 typedef void (GR_GL_FUNCTION_TYPE* GLBeginQueryProc) (GrGLenum, GrGLuint);
107 typedef void (GR_GL_FUNCTION_TYPE* GLEndQueryProc) (GrGLenum);
108 typedef void (GR_GL_FUNCTION_TYPE* GLGetQueryObjectuivProc) (GrGLuint, GrGLe num, GrGLuint*);
109 typedef void (GR_GL_FUNCTION_TYPE* GLGetQueryObjectui64vProc) (GrGLuint, GrG Lenum, GrGLuint64*);
110
111 GLGetIntegervProc fGLGetIntegerv;
112 GLGenQueriesProc fGLGenQueries;
113 GLDeleteQueriesProc fGLDeleteQueries;
114 GLBeginQueryProc fGLBeginQuery;
115 GLEndQueryProc fGLEndQuery;
116 GLGetQueryObjectuivProc fGLGetQueryObjectuiv;
117 GLGetQueryObjectui64vProc fGLGetQueryObjectui64v;
118
119
120 typedef sk_gpu_test::GpuTimer INHERITED;
121 };
122
123 GLGpuTimer* GLGpuTimer::CreateIfSupported(const sk_gpu_test::GLTestContext* ctx) {
124 SkAutoTDelete<GLGpuTimer> ret;
125 const GrGLInterface* gl = ctx->gl();
126 if (gl->fExtensions.has("GL_EXT_disjoint_timer_query")) {
127 ret.reset(new GLGpuTimer(true, ctx, "EXT"));
128 } else if (kGL_GrGLStandard == gl->fStandard &&
129 (GrGLGetVersion(gl) > GR_GL_VER(3,3) || gl->fExtensions.has("GL_A RB_timer_query"))) {
130 ret.reset(new GLGpuTimer(false, ctx));
131 } else if (gl->fExtensions.has("GL_EXT_timer_query")) {
132 ret.reset(new GLGpuTimer(false, ctx, "EXT"));
133 }
134 return ret && ret->validate() ? ret.release() : nullptr;
135 }
136
137 GLGpuTimer::GLGpuTimer(bool disjointSupport, const sk_gpu_test::GLTestContext* c tx, const char* ext)
138 : INHERITED(disjointSupport) {
139 ctx->getGLProcAddress(&fGLGetIntegerv, "glGetIntegerv");
140 ctx->getGLProcAddress(&fGLGenQueries, "glGenQueries", ext);
141 ctx->getGLProcAddress(&fGLDeleteQueries, "glDeleteQueries", ext);
142 ctx->getGLProcAddress(&fGLBeginQuery, "glBeginQuery", ext);
143 ctx->getGLProcAddress(&fGLEndQuery, "glEndQuery", ext);
144 ctx->getGLProcAddress(&fGLGetQueryObjectuiv, "glGetQueryObjectuiv", ext);
145 ctx->getGLProcAddress(&fGLGetQueryObjectui64v, "glGetQueryObjectui64v", ext) ;
146 }
147
148 bool GLGpuTimer::validate() const {
149 return fGLGetIntegerv && fGLGenQueries && fGLDeleteQueries && fGLBeginQuery && fGLEndQuery &&
150 fGLGetQueryObjectuiv && fGLGetQueryObjectui64v;
151 }
152
153 sk_gpu_test::PlatformTimerQuery GLGpuTimer::onQueueTimerStart() const {
154 GrGLuint queryID;
155 fGLGenQueries(1, &queryID);
156 if (!queryID) {
157 return sk_gpu_test::kInvalidTimerQuery;
158 }
159 if (this->disjointSupport()) {
160 // Clear the disjoint flag.
161 GrGLint disjoint;
162 fGLGetIntegerv(GL_GPU_DISJOINT, &disjoint);
163 }
164 fGLBeginQuery(GL_TIME_ELAPSED, queryID);
165 return static_cast<sk_gpu_test::PlatformTimerQuery>(queryID);
166 }
167
168 void GLGpuTimer::onQueueTimerStop(sk_gpu_test::PlatformTimerQuery platformTimer) const {
169 if (sk_gpu_test::kInvalidTimerQuery == platformTimer) {
170 return;
171 }
172 fGLEndQuery(GL_TIME_ELAPSED);
173 }
174
175 sk_gpu_test::GpuTimer::QueryStatus
176 GLGpuTimer::checkQueryStatus(sk_gpu_test::PlatformTimerQuery platformTimer) {
177 const GrGLuint queryID = static_cast<GrGLuint>(platformTimer);
178 if (!queryID) {
179 return QueryStatus::kInvalid;
180 }
181 GrGLuint available = 0;
182 fGLGetQueryObjectuiv(queryID, GL_QUERY_RESULT_AVAILABLE, &available);
183 if (!available) {
184 return QueryStatus::kPending;
185 }
186 if (this->disjointSupport()) {
187 GrGLint disjoint = 1;
188 fGLGetIntegerv(GL_GPU_DISJOINT, &disjoint);
189 if (disjoint) {
190 return QueryStatus::kDisjoint;
191 }
192 }
193 return QueryStatus::kAccurate;
194 }
195
196 std::chrono::nanoseconds GLGpuTimer::getTimeElapsed(sk_gpu_test::PlatformTimerQu ery platformTimer) {
197 SkASSERT(this->checkQueryStatus(platformTimer) >= QueryStatus::kDisjoint);
198 const GrGLuint queryID = static_cast<GrGLuint>(platformTimer);
199 GrGLuint64 nanoseconds;
200 fGLGetQueryObjectui64v(queryID, GL_QUERY_RESULT, &nanoseconds);
201 return std::chrono::nanoseconds(nanoseconds);
202 }
203
204 void GLGpuTimer::deleteQuery(sk_gpu_test::PlatformTimerQuery platformTimer) {
205 const GrGLuint queryID = static_cast<GrGLuint>(platformTimer);
206 fGLDeleteQueries(1, &queryID);
207 }
208
209 } // anonymous namespace 80 } // anonymous namespace
210 81
211 namespace sk_gpu_test { 82 namespace sk_gpu_test {
212 83
213 GLTestContext::GLTestContext() : TestContext() {} 84 GLTestContext::GLTestContext() : TestContext() {}
214 85
215 GLTestContext::~GLTestContext() { 86 GLTestContext::~GLTestContext() {
216 SkASSERT(nullptr == fGL.get()); 87 SkASSERT(nullptr == fGL.get());
217 } 88 }
218 89
219 void GLTestContext::init(const GrGLInterface* gl, FenceSync* fenceSync) { 90 void GLTestContext::init(const GrGLInterface* gl, FenceSync* fenceSync) {
220 SkASSERT(!fGL.get()); 91 SkASSERT(!fGL.get());
221 fGL.reset(gl); 92 fGL.reset(gl);
222 fFenceSync = fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this); 93 fFenceSync = fenceSync ? fenceSync : GLFenceSync::CreateIfSupported(this);
223 fGpuTimer = GLGpuTimer::CreateIfSupported(this);
224 } 94 }
225 95
226 void GLTestContext::teardown() { 96 void GLTestContext::teardown() {
227 fGL.reset(nullptr); 97 fGL.reset(nullptr);
228 INHERITED::teardown(); 98 INHERITED::teardown();
229 } 99 }
230 100
231 void GLTestContext::testAbandon() { 101 void GLTestContext::testAbandon() {
232 INHERITED::testAbandon(); 102 INHERITED::testAbandon();
233 if (fGL) { 103 if (fGL) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 GR_GL_NEAREST)); 138 GR_GL_NEAREST));
269 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S, 139 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_S,
270 GR_GL_CLAMP_TO_EDGE)); 140 GR_GL_CLAMP_TO_EDGE));
271 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T, 141 GR_GL_CALL(fGL, TexParameteri(GR_GL_TEXTURE_RECTANGLE, GR_GL_TEXTURE_WRAP_T,
272 GR_GL_CLAMP_TO_EDGE)); 142 GR_GL_CLAMP_TO_EDGE));
273 GR_GL_CALL(fGL, TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width , height, 0, 143 GR_GL_CALL(fGL, TexImage2D(GR_GL_TEXTURE_RECTANGLE, 0, internalFormat, width , height, 0,
274 externalFormat, externalType, data)); 144 externalFormat, externalType, data));
275 return id; 145 return id;
276 } 146 }
277 } // namespace sk_gpu_test 147 } // namespace sk_gpu_test
OLDNEW
« no previous file with comments | « tools/gpu/TestContext.cpp ('k') | tools/skpbench/_benchresult.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698