OGLplus (0.52.0) a C++ wrapper for OpenGL

AMD_performance_monitor.hpp
Go to the documentation of this file.
1 
14 #pragma once
15 #ifndef OGLPLUS_EXT_AMD_PERFORMANCE_MONITOR_1203031902_HPP
16 #define OGLPLUS_EXT_AMD_PERFORMANCE_MONITOR_1203031902_HPP
17 
18 #include <oglplus/extension.hpp>
19 #include <oglplus/enumerations.hpp>
21 
22 #include <cassert>
23 #include <vector>
24 
25 namespace oglplus {
26 
27 #if OGLPLUS_DOCUMENTATION_ONLY || GL_AMD_performance_monitor
28 
30 
36 OGLPLUS_ENUM_CLASS_BEGIN(PerfMonitorAMDType, GLenum)
37 #include <oglplus/enums/ext/amd_perf_monitor_type.ipp>
38 OGLPLUS_ENUM_CLASS_END(PerfMonitorAMDType)
39 
40 #if !OGLPLUS_NO_ENUM_VALUE_NAMES
41 #include <oglplus/enums/ext/amd_perf_monitor_type_names.ipp>
42 #endif
43 
44 #if !OGLPLUS_ENUM_VALUE_RANGES
45 #include <oglplus/enums/ext/amd_perf_monitor_type_range.ipp>
46 #endif
47 
50 
52 
58 {
59 private:
60  GLuint _group;
61  GLuint _counter;
62 
63  friend class PerfMonitorAMDGroup;
64  friend class ObjectOps<tag::DirectState, tag::PerfMonitorAMD>;
65 
66  PerfMonitorAMDCounter(GLuint group, GLuint counter)
67  : _group(group)
68  , _counter(counter)
69  { }
70 public:
72 
76  String GetString(void) const
77  {
78  GLsizei length = 0;
79  OGLPLUS_GLFUNC(GetPerfMonitorCounterStringAMD)(
80  _group,
81  _counter,
82  0,
83  &length,
84  nullptr
85  );
86  OGLPLUS_CHECK(
87  GetPerfMonitorCounterStringAMD,
88  Error,
89  Index(_group)
90  );
91 
92  std::vector<GLchar> buffer(length);
93  OGLPLUS_GLFUNC(GetPerfMonitorCounterStringAMD)(
94  _group,
95  _counter,
96  GLsizei(buffer.size()),
97  &length,
98  buffer.data()
99  );
100  OGLPLUS_CHECK(
101  GetPerfMonitorCounterStringAMD,
102  Error,
103  Index(_group)
104  );
105  return String(buffer.data(), buffer.size());
106  }
107 
109 
115  {
116  GLenum result;
117  OGLPLUS_GLFUNC(GetPerfMonitorCounterInfoAMD)(
118  _group,
119  _counter,
120  GL_COUNTER_TYPE_AMD,
121  &result
122  );
123  OGLPLUS_CHECK(
124  GetPerfMonitorCounterInfoAMD,
125  Error,
126  Index(_group)
127  );
128  return PerfMonitorAMDType(result);
129  }
130 };
131 
133 
139 {
140 private:
141  GLuint _group;
142 
143  friend class AMD_performance_monitor;
144 
145  PerfMonitorAMDGroup(GLuint group)
146  : _group(group)
147  { }
148 public:
150 
154  String GetString(void) const
155  {
156  GLsizei length = 0;
157  OGLPLUS_GLFUNC(GetPerfMonitorGroupStringAMD)(
158  _group,
159  0,
160  &length,
161  nullptr
162  );
163  OGLPLUS_CHECK(
164  GetPerfMonitorGroupStringAMD,
165  Error,
166  Index(_group)
167  );
168 
169  std::vector<GLchar> buffer(length);
170  OGLPLUS_GLFUNC(GetPerfMonitorGroupStringAMD)(
171  _group,
172  GLsizei(buffer.size()),
173  &length,
174  buffer.data()
175  );
176  OGLPLUS_CHECK(
177  GetPerfMonitorGroupStringAMD,
178  Error,
179  Index(_group)
180  );
181  return String(buffer.data(), buffer.size());
182  }
183 
185 
190  GLint& max_active_counters,
191  std::vector<PerfMonitorAMDCounter>& counters
192  ) const
193  {
194  GLint count = 0;
195  OGLPLUS_GLFUNC(GetPerfMonitorCountersAMD)(
196  _group,
197  &count,
198  &max_active_counters,
199  0,
200  nullptr
201  );
202  OGLPLUS_CHECK(
203  GetPerfMonitorCountersAMD,
204  Error,
205  Index(_group)
206  );
207 
208  std::vector<GLuint> buffer(count);
209  OGLPLUS_GLFUNC(GetPerfMonitorCountersAMD)(
210  _group,
211  &count,
212  &max_active_counters,
213  buffer.size(),
214  buffer.data()
215  );
216  OGLPLUS_CHECK(
217  GetPerfMonitorCountersAMD,
218  Error,
219  Index(_group)
220  );
221 
222  counters.clear();
223  counters.reserve(count);
224  for(auto i=buffer.begin(), e=buffer.end(); i!=e; ++i)
225  counters.push_back(PerfMonitorAMDCounter(_group, *i));
226  }
227 
229 
233  std::vector<PerfMonitorAMDCounter>
234  GetCounters(GLint& max_active_counters) const
235  {
236  std::vector<PerfMonitorAMDCounter> result;
237  GetCounters(max_active_counters, result);
238  return result;
239  }
240 
241 };
242 
244 
250 {
251 private:
252  PerfMonitorAMDCounter _counter;
253 
254  union {
255  GLfloat _fl;
256  struct {
257  GLuint _lo;
258  GLuint _hi;
259  } _qw;
260  };
261 
263  PerfMonitorAMDCounter counter,
264  GLuint lo,
265  GLuint hi
266  ): _counter(counter)
267  {
268  _qw._lo = lo;
269  _qw._hi = hi;
270  }
271 
272  friend class ObjectOps<tag::DirectState, tag::PerfMonitorAMD>;
273 public:
276  {
277  return _counter;
278  }
279 
281  GLuint Low(void) const
282  {
283  return _qw._lo;
284  }
285 
287  GLuint High(void) const
288  {
289  return _qw._lo;
290  }
291 
293  GLfloat Float(void) const
294  {
295  return _fl;
296  }
297 };
298 
300 
307 template <>
308 class ObjGenDelOps<tag::PerfMonitorAMD>
309 {
310 protected:
311  static void Gen(tag::Generate, GLsizei count, GLuint* names)
312  {
313  assert(names != nullptr);
314  OGLPLUS_GLFUNC(GenPerfMonitorsAMD)(count, names);
315  OGLPLUS_CHECK_SIMPLE(GenSamplers);
316  }
317 
318  static void Delete(GLsizei count, GLuint* names)
319  {
320  assert(names != nullptr);
321  OGLPLUS_GLFUNC(DeletePerfMonitorsAMD)(count, names);
322  OGLPLUS_VERIFY_SIMPLE(DeleteSamplers);
323  }
324 
325  static GLboolean IsA(GLuint name)
326  {
327  assert(name != 0);
328  return GL_TRUE;
329  }
330 };
331 
333 
335 template <>
336 class ObjectOps<tag::DirectState, tag::PerfMonitorAMD>
337  : public ObjZeroOps<tag::DirectState, tag::PerfMonitorAMD>
338 {
339 protected:
340  ObjectOps(void){ }
341 public:
343 
350  bool enable,
351  const std::vector<PerfMonitorAMDCounter>& counters
352  ) const
353  {
354  if(counters.empty()) return;
355 
356  std::vector<GLuint> list(counters.size());
357  GLuint group = counters[0]._group;
358 
359  for(size_t i=0, n=counters.size(); i!=n; ++i)
360  {
361  assert(group == counters[i]._group);
362  list[i] = counters[i]._counter;
363  }
364 
365  OGLPLUS_GLFUNC(SelectPerfMonitorCountersAMD)(
366  this->_name,
367  enable? GL_TRUE: GL_FALSE,
368  group,
369  GLint(list.size()),
370  list.data()
371  );
372  OGLPLUS_CHECK(
373  SelectPerfMonitorCountersAMD,
374  ObjectError,
375  Object(*this)
376  );
377  }
378 
380 
384  void Begin(void) const
385  {
386  OGLPLUS_GLFUNC(BeginPerfMonitorAMD)(this->_name);
387  OGLPLUS_CHECK(
388  BeginPerfMonitorAMD,
389  ObjectError,
390  Object(*this)
391  );
392  }
393 
395 
399  void End(void) const
400  {
401  OGLPLUS_GLFUNC(EndPerfMonitorAMD)(this->_name);
402  OGLPLUS_CHECK(
403  EndPerfMonitorAMD,
404  ObjectError,
405  Object(*this)
406  );
407  }
408 
410 
415  bool ResultAvailable(void) const
416  {
417  GLuint result = 0;
418  OGLPLUS_GLFUNC(GetPerfMonitorCounterDataAMD)(
419  this->_name,
420  GL_PERFMON_RESULT_AVAILABLE_AMD,
421  sizeof(result),
422  &result,
423  nullptr
424  );
425  OGLPLUS_CHECK(
426  GetPerfMonitorCounterDataAMD,
427  ObjectError,
428  Object(*this)
429  );
430  return result != 0;
431  }
432 
434 
440  void Result(std::vector<PerfMonitorAMDResult>& results) const
441  {
442  GLuint size = 0;
443  OGLPLUS_GLFUNC(GetPerfMonitorCounterDataAMD)(
444  this->_name,
445  GL_PERFMON_RESULT_SIZE_AMD,
446  sizeof(size),
447  &size,
448  nullptr
449  );
450  OGLPLUS_CHECK(
451  GetPerfMonitorCounterDataAMD,
452  ObjectError,
453  Object(*this)
454  );
455 
456  std::vector<GLuint> data(size / sizeof(GLuint));
457  OGLPLUS_GLFUNC(GetPerfMonitorCounterDataAMD)(
458  this->_name,
459  GL_PERFMON_RESULT_AMD,
460  data.size() * sizeof(GLuint),
461  data.data(),
462  nullptr
463  );
464  OGLPLUS_CHECK(
465  GetPerfMonitorCounterDataAMD,
466  ObjectError,
467  Object(*this)
468  );
469 
470  results.clear();
471  results.reserve(data.size() / 3);
472 
473  auto i = data.begin(), e = data.end();
474  while(i != e)
475  {
476  GLuint group = *i++;
477  assert(i != e);
478  GLuint ctr = *i++;
479  assert(i != e);
480 
481  PerfMonitorAMDCounter counter(group, ctr);
482  auto type = counter.Type();
483  GLuint lo = *i++, hi = 0;
485  hi = *i++;
486 
487  results.push_back(PerfMonitorAMDResult(counter, lo, hi));
488  }
489  }
490 };
491 
493 typedef ObjectOps<tag::DirectState, tag::PerfMonitorAMD>
495 
497 
503 typedef Object<PerfMonitorAMDOps> PerfMonitorAMD;
504 
506 
513 {
514 public:
515  OGLPLUS_EXTENSION_CLASS(AMD, performance_monitor)
516 
517 
518 
522  void GetGroups(std::vector<PerfMonitorAMDGroup>& groups) const
523  {
524  GLint count = 0;
525  OGLPLUS_GLFUNC(GetPerfMonitorGroupsAMD)(
526  &count,
527  0,
528  nullptr
529  );
530  OGLPLUS_CHECK_SIMPLE(GetPerfMonitorGroupsAMD);
531 
532  std::vector<GLuint> buffer(count);
533  OGLPLUS_GLFUNC(GetPerfMonitorGroupsAMD)(
534  &count,
535  buffer.size(),
536  buffer.data()
537  );
538  OGLPLUS_CHECK_SIMPLE(GetPerfMonitorGroupsAMD);
539 
540  groups.clear();
541  groups.reserve(count);
542  for(auto i=buffer.begin(), e=buffer.end(); i!=e; ++i)
543  groups.push_back(PerfMonitorAMDGroup(*i));
544  }
545 
547 
551  std::vector<PerfMonitorAMDGroup> GetGroups(void) const
552  {
553  std::vector<PerfMonitorAMDGroup> result;
554  GetGroups(result);
555  return result;
556  }
557 };
558 #endif
559 
560 } // namespace oglplus
561 
562 #endif // include guard
String GetString(void) const
Returns a string describing the monitor counter.
Definition: AMD_performance_monitor.hpp:76
Object< PerfMonitorAMDOps > PerfMonitorAMD
An oglplus_object encapsulating the performance monitor functionality.
Definition: AMD_performance_monitor.hpp:503
Funcions and classes for handling and wrapping OpenGL extensions.
std::vector< PerfMonitorAMDGroup > GetGroups(void) const
Returns the available performance counter groups.
Definition: AMD_performance_monitor.hpp:551
GLuint High(void) const
Returns the high dword of the result.
Definition: AMD_performance_monitor.hpp:287
Generic OpenGL object wrapper.
Enumeration-related declarations.
GLuint Low(void) const
Returns the low dword of the result.
Definition: AMD_performance_monitor.hpp:281
PerfMonitorAMDType
Performance counter type.
Definition: AMD_performance_monitor.hpp:36
Implements operations applicable to named (non-zero) objects.
Definition: wrap_tpl.hpp:45
String GetString(void) const
Returns a string describing the monitor group.
Definition: AMD_performance_monitor.hpp:154
PerfMonitorAMDCounter Counter(void) const
Returns the counter that this is a result of.
Definition: AMD_performance_monitor.hpp:275
GLfloat Float(void) const
Returns the floating-point value of the result.
Definition: AMD_performance_monitor.hpp:293
void GetCounters(GLint &max_active_counters, std::vector< PerfMonitorAMDCounter > &counters) const
Queries the performance counters in this group.
Definition: AMD_performance_monitor.hpp:189
ObjectOps< tag::DirectState, tag::PerfMonitorAMD > PerfMonitorAMDOps
PerfMonitorAMD operations with direct state access.
Definition: AMD_performance_monitor.hpp:494
Implements operations applicable to any object including object 0 (zero)
Definition: fwd.hpp:157
Wrapper for performance counter result.
Definition: AMD_performance_monitor.hpp:249
std::vector< PerfMonitorAMDCounter > GetCounters(GLint &max_active_counters) const
Returns the performance counters in this group.
Definition: AMD_performance_monitor.hpp:234
void Result(std::vector< PerfMonitorAMDResult > &results) const
Returns the results.
Definition: AMD_performance_monitor.hpp:440
::std::basic_string< GLchar > String
String class.
Definition: def.hpp:36
Exception class for general OpenGL errors.
Definition: basic.hpp:43
Exception class for GL object-related errors.
Definition: object.hpp:24
bool ResultAvailable(void) const
Returns true if results are available.
Definition: AMD_performance_monitor.hpp:415
void End(void) const
Ends a monitoring session on this monitor.
Definition: AMD_performance_monitor.hpp:399
Wrapper for the AMD_performance_monitor extension.
Definition: AMD_performance_monitor.hpp:512
Wrapper for performance monitor group functionality.
Definition: AMD_performance_monitor.hpp:138
void Begin(void) const
Begins a monitoring session on this monitor.
Definition: AMD_performance_monitor.hpp:384
PerfMonitorAMDType Type(void) const
Returns the type of the counter.
Definition: AMD_performance_monitor.hpp:114
Wrapper for performance monitor counter functionality.
Definition: AMD_performance_monitor.hpp:57
void SelectCounters(bool enable, const std::vector< PerfMonitorAMDCounter > &counters) const
Enables or disables the specified counters for this monitor.
Definition: AMD_performance_monitor.hpp:349

Copyright © 2010-2014 Matúš Chochlík, University of Žilina, Žilina, Slovakia.
<matus.chochlik -at- fri.uniza.sk>
<chochlik -at -gmail.com>
Documentation generated on Mon Sep 22 2014 by Doxygen (version 1.8.6).