2 * Copyright (c) 2024 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/graphics/gles/gl-proxy-implementation.h>
24 #include <dali/integration-api/debug.h>
27 #include <dali/internal/system/common/environment-options.h>
31 const int NUM_FRAMES_PER_SECOND(60);
40 Sampler::Sampler(const char* description)
41 : mDescription(description),
42 mAccumulatedSquare(0),
51 void Sampler::Increment()
58 mAccumulatedSquare = 0;
63 mCurrentFrameCount = 0;
66 void Sampler::Accumulate()
70 mMin = mCurrentFrameCount;
71 mMax = mCurrentFrameCount;
75 if(mCurrentFrameCount < mMin)
77 mMin = mCurrentFrameCount;
79 if(mCurrentFrameCount > mMax)
81 mMax = mCurrentFrameCount;
87 mAccumulated += mCurrentFrameCount;
88 mAccumulatedSquare += (static_cast<uint64_t>(mCurrentFrameCount) * static_cast<uint64_t>(mCurrentFrameCount));
89 mCurrentFrameCount = 0;
91 const char* Sampler::GetDescription() const
96 float Sampler::GetMeanValue() const
101 meanValue = static_cast<double>(mAccumulated) / static_cast<double>(mNumSamples);
106 float Sampler::GetStandardDeviation() const
108 float standardDeviation = 0.0f;
111 standardDeviation = sqrtf(mNumSamples * mAccumulatedSquare - (mAccumulated * mAccumulated)) / mNumSamples;
113 return standardDeviation;
116 float Sampler::GetMin() const
121 float Sampler::GetMax() const
126 uint64_t Sampler::GetCount() const
131 ObjectCounter::ObjectCounter(const char* description)
132 : mDescription(description),
138 void ObjectCounter::Increment()
147 void ObjectCounter::Decrement()
152 unsigned int ObjectCounter::GetCount() const
156 unsigned int ObjectCounter::GetPeak() const
161 const char* ObjectCounter::GetDescription() const
166 GlProxyImplementation::GlProxyImplementation(const EnvironmentOptions& environmentOptions)
167 : mEnvironmentOptions(environmentOptions),
168 mActiveTextureSampler("ActiveTexture calls"),
169 mClearSampler("Clear calls"),
170 mBindBufferSampler("Bind buffers"),
171 mBindTextureSampler("Bind textures"),
172 mDrawSampler("Draw calls"),
173 mUniformSampler("Uniform sets"),
174 mUseProgramSampler("Used programs"),
175 mBufferCount("Buffer Count"),
176 mTextureCount("Texture Count"),
177 mProgramCount("Program Count"),
178 mCurrentFrameCount(0),
183 GlProxyImplementation::~GlProxyImplementation()
187 void GlProxyImplementation::PreRender()
191 void GlProxyImplementation::PostRender()
193 // Accumulate counts in each sampler
196 // When we reach the desired frame count, output the averages from the samples
198 mCurrentFrameCount++;
200 if(mCurrentFrameCount >= mEnvironmentOptions.GetGlesCallTime() * NUM_FRAMES_PER_SECOND)
202 mCurrentFrameCount = 0;
205 if(!mEnvironmentOptions.GetGlesCallAccumulate())
212 void GlProxyImplementation::Clear(GLbitfield mask)
214 mClearSampler.Increment();
215 GlImplementation::Clear(mask);
218 void GlProxyImplementation::GenBuffers(GLsizei n, GLuint* buffers)
220 mBufferCount.Increment();
221 GlImplementation::GenBuffers(n, buffers);
224 void GlProxyImplementation::DeleteBuffers(GLsizei n, const GLuint* buffers)
226 mBufferCount.Decrement();
227 GlImplementation::DeleteBuffers(n, buffers);
230 void GlProxyImplementation::BindBuffer(GLenum target, GLuint buffer)
232 mBindBufferSampler.Increment();
233 GlImplementation::BindBuffer(target, buffer);
236 void GlProxyImplementation::GenTextures(GLsizei n, GLuint* textures)
238 mTextureCount.Increment();
239 GlImplementation::GenTextures(n, textures);
242 void GlProxyImplementation::DeleteTextures(GLsizei n, const GLuint* textures)
244 mTextureCount.Decrement();
245 GlImplementation::DeleteTextures(n, textures);
248 void GlProxyImplementation::ActiveTexture(GLenum texture)
250 mActiveTextureSampler.Increment();
251 GlImplementation::ActiveTexture(texture);
254 void GlProxyImplementation::BindTexture(GLenum target, GLuint texture)
256 mBindTextureSampler.Increment();
257 GlImplementation::BindTexture(target, texture);
260 void GlProxyImplementation::DrawArrays(GLenum mode, GLint first, GLsizei count)
262 mDrawSampler.Increment();
263 GlImplementation::DrawArrays(mode, first, count);
266 void GlProxyImplementation::DrawElements(GLenum mode, GLsizei count, GLenum type, const void* indices)
268 mDrawSampler.Increment();
269 GlImplementation::DrawElements(mode, count, type, indices);
272 void GlProxyImplementation::Uniform1f(GLint location, GLfloat x)
274 mUniformSampler.Increment();
275 GlImplementation::Uniform1f(location, x);
278 void GlProxyImplementation::Uniform1fv(GLint location, GLsizei count, const GLfloat* v)
280 mUniformSampler.Increment();
281 GlImplementation::Uniform1fv(location, count, v);
284 void GlProxyImplementation::Uniform1i(GLint location, GLint x)
286 mUniformSampler.Increment();
287 GlImplementation::Uniform1i(location, x);
290 void GlProxyImplementation::Uniform1iv(GLint location, GLsizei count, const GLint* v)
292 mUniformSampler.Increment();
293 GlImplementation::Uniform1iv(location, count, v);
296 void GlProxyImplementation::Uniform2f(GLint location, GLfloat x, GLfloat y)
298 mUniformSampler.Increment();
299 GlImplementation::Uniform2f(location, x, y);
302 void GlProxyImplementation::Uniform2fv(GLint location, GLsizei count, const GLfloat* v)
304 mUniformSampler.Increment();
305 GlImplementation::Uniform2fv(location, count, v);
308 void GlProxyImplementation::Uniform2i(GLint location, GLint x, GLint y)
310 mUniformSampler.Increment();
311 GlImplementation::Uniform2i(location, x, y);
314 void GlProxyImplementation::Uniform2iv(GLint location, GLsizei count, const GLint* v)
316 mUniformSampler.Increment();
317 GlImplementation::Uniform2iv(location, count, v);
320 void GlProxyImplementation::Uniform3f(GLint location, GLfloat x, GLfloat y, GLfloat z)
322 mUniformSampler.Increment();
323 GlImplementation::Uniform3f(location, x, y, z);
326 void GlProxyImplementation::Uniform3fv(GLint location, GLsizei count, const GLfloat* v)
328 mUniformSampler.Increment();
329 GlImplementation::Uniform3fv(location, count, v);
332 void GlProxyImplementation::Uniform3i(GLint location, GLint x, GLint y, GLint z)
334 mUniformSampler.Increment();
335 GlImplementation::Uniform3i(location, x, y, z);
338 void GlProxyImplementation::Uniform3iv(GLint location, GLsizei count, const GLint* v)
340 mUniformSampler.Increment();
341 GlImplementation::Uniform3iv(location, count, v);
344 void GlProxyImplementation::Uniform4f(GLint location, GLfloat x, GLfloat y, GLfloat z, GLfloat w)
346 mUniformSampler.Increment();
347 GlImplementation::Uniform4f(location, x, y, z, w);
350 void GlProxyImplementation::Uniform4fv(GLint location, GLsizei count, const GLfloat* v)
352 mUniformSampler.Increment();
353 GlImplementation::Uniform4fv(location, count, v);
356 void GlProxyImplementation::Uniform4i(GLint location, GLint x, GLint y, GLint z, GLint w)
358 mUniformSampler.Increment();
359 GlImplementation::Uniform4i(location, x, y, z, w);
362 void GlProxyImplementation::Uniform4iv(GLint location, GLsizei count, const GLint* v)
364 mUniformSampler.Increment();
365 GlImplementation::Uniform4iv(location, count, v);
368 void GlProxyImplementation::UniformMatrix2fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
370 mUniformSampler.Increment();
371 GlImplementation::UniformMatrix2fv(location, count, transpose, value);
374 void GlProxyImplementation::UniformMatrix3fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
376 mUniformSampler.Increment();
377 GlImplementation::UniformMatrix3fv(location, count, transpose, value);
380 void GlProxyImplementation::UniformMatrix4fv(GLint location, GLsizei count, GLboolean transpose, const GLfloat* value)
382 mUniformSampler.Increment();
383 GlImplementation::UniformMatrix4fv(location, count, transpose, value);
386 GLuint GlProxyImplementation::CreateProgram(void)
388 mProgramCount.Increment();
389 return GlImplementation::CreateProgram();
392 void GlProxyImplementation::DeleteProgram(GLuint program)
394 mProgramCount.Decrement();
395 GlImplementation::DeleteProgram(program);
398 void GlProxyImplementation::UseProgram(GLuint program)
400 mUseProgramSampler.Increment();
401 GlImplementation::UseProgram(program);
404 void GlProxyImplementation::AccumulateSamples()
406 // Accumulate counts in each sampler
407 mActiveTextureSampler.Accumulate();
408 mClearSampler.Accumulate();
409 mBindBufferSampler.Accumulate();
410 mBindTextureSampler.Accumulate();
411 mDrawSampler.Accumulate();
412 mUniformSampler.Accumulate();
413 mUseProgramSampler.Accumulate();
416 void GlProxyImplementation::LogResults()
418 Debug::LogMessage(Debug::INFO, "OpenGL ES statistics sampled over %d frames) operations per frame:\n", mTotalFrameCount);
419 LogCalls(mActiveTextureSampler);
420 LogCalls(mClearSampler);
421 LogCalls(mBindBufferSampler);
422 LogCalls(mBindTextureSampler);
423 LogCalls(mDrawSampler);
424 LogCalls(mUniformSampler);
425 LogCalls(mUseProgramSampler);
426 Debug::LogMessage(Debug::INFO, "OpenGL ES Object Count:\n");
427 LogObjectCounter(mBufferCount);
428 LogObjectCounter(mTextureCount);
429 LogObjectCounter(mProgramCount);
432 void GlProxyImplementation::LogCalls(const Sampler& sampler)
434 Debug::LogMessage(Debug::INFO, " %s : Mean %5.2f (Min:%5.2f, Max:%5.2f, StdDev:%5.2f, Actual:%d)\n", sampler.GetDescription(), sampler.GetMeanValue(), sampler.GetMin(), sampler.GetMax(), sampler.GetStandardDeviation(), sampler.GetCount());
437 void GlProxyImplementation::LogObjectCounter(const ObjectCounter& sampler)
439 Debug::LogMessage(Debug::INFO, " %s : %u (Peak:%u)\n", sampler.GetDescription(), sampler.GetCount(), sampler.GetPeak());
442 void GlProxyImplementation::ResetSamplers()
444 mActiveTextureSampler.Reset();
445 mClearSampler.Reset();
446 mBindBufferSampler.Reset();
447 mBindTextureSampler.Reset();
448 mDrawSampler.Reset();
449 mUniformSampler.Reset();
450 mUseProgramSampler.Reset();
451 mTotalFrameCount = 0;
454 } // namespace Adaptor
456 } // namespace Internal