HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
diagnostic.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_GLF_DIAGNOSTIC_H
8 #define PXR_IMAGING_GLF_DIAGNOSTIC_H
9 
10 /// \file glf/diagnostic.h
11 
12 #include "pxr/pxr.h"
13 #include "pxr/imaging/glf/api.h"
15 #include "pxr/base/tf/diagnostic.h"
16 
17 #include <string>
18 #include <cstdint>
19 
21 
22 
23 /// Posts diagnostic errors for all GL errors in the current context.
24 /// This macro tags the diagnostic errors with the name of the calling
25 /// function.
26 #define GLF_POST_PENDING_GL_ERRORS() \
27  GlfPostPendingGLErrors(__ARCH_PRETTY_FUNCTION__)
28 
29 /// Posts diagnostic errors for all GL errors in the current context.
30 GLF_API
31 void GlfPostPendingGLErrors(std::string const & where = std::string());
32 
33 /// Registers GlfDefaultDebugOutputMessageCallback as the
34 /// debug message callback for the current GL context.
35 GLF_API
37 
38 /// A GL debug output message callback method which posts diagnostic
39 /// errors for messages of type DEBUG_TYPE_ERROR and diagnostic warnings
40 /// for other message types.
41 GLF_API
44  GLsizei length, char const * message, GLvoid const * userParam);
45 
46 /// Returns a string representation of debug output enum values.
47 GLF_API
48 char const * GlfDebugEnumToString(GLenum debugEnum);
49 
50 /// Emit a GlfDebugGroup tracing the current function.
51 #define GLF_GROUP_FUNCTION() \
52  GlfDebugGroup __glf_group_function(__ARCH_PRETTY_FUNCTION__)
53 
54 /// Emit a GlfDebugGroup tracing the current scope with the given string.
55 #define GLF_GROUP_SCOPE(str) \
56  GlfDebugGroup __glf_group_scope(str)
57 
58 /// \class GlfDebugGroup
59 ///
60 /// Represents a GL debug group in Glf
61 ///
62 /// The debug group conditionally adds debug objects to the GL stream
63 /// based on the value to the environment variable GLF_ENABLE_DIAGNOSTIC_TRACE.
64 /// If set to 1 (true) the debug objects will be pushed and popped in
65 /// the command stream as long as the GL implementation and version supports it.
66 ///
68  public:
69  /// Pushes a new debug group onto the GL api debug trace stack
70  GLF_API
71  GlfDebugGroup(char const *message);
72 
73  /// Pops a debug group off the GL api debug trace stack
74  GLF_API
76 
77  GlfDebugGroup() = delete;
78  GlfDebugGroup(GlfDebugGroup const&) = delete;
79  GlfDebugGroup& operator =(GlfDebugGroup const&) = delete;
80 };
81 
82 /// Label a buffer object to improve tracing in the debug output.
83 GLF_API
84 void GlfDebugLabelBuffer(GLuint id, char const *label);
85 
86 /// Label a shader object to improve tracing in the debug output.
87 GLF_API
88 void GlfDebugLabelShader(GLuint id, char const *label);
89 
90 /// Label a program object to improve tracing in the debug output.
91 GLF_API
92 void GlfDebugLabelProgram(GLuint id, char const *label);
93 
94 /// \class GlfGLQueryObject
95 ///
96 /// Represents a GL query object in Glf
97 ///
99 public:
100  GLF_API
102  GLF_API
104 
105  /// Begin query for the given \p target
106  /// target has to be one of
107  /// GL_SAMPLES_PASSED, GL_ANY_SAMPLES_PASSED,
108  /// GL_ANY_SAMPLES_PASSED_CONSERVATIVE, GL_PRIMITIVES_GENERATED
109  /// GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
110  /// GL_TIME_ELAPSED, GL_TIMESTAMP
111  GLF_API
112  void Begin(GLenum target);
113 
114  /// equivalent to Begin(GL_SAMPLES_PASSED).
115  /// The number of samples that pass the depth test for all drawing
116  /// commands within the scope of the query will be returned.
117  GLF_API
118  void BeginSamplesPassed();
119 
120  /// equivalent to Begin(GL_PRIMITIVES_GENERATED).
121  /// The number of primitives sent to the rasterizer by the scoped
122  /// drawing command will be returned.
123  GLF_API
125 
126  /// equivalent to Begin(GL_TIME_ELAPSED).
127  /// The time that it takes for the GPU to execute all of the scoped commands
128  /// will be returned in nanoseconds.
129  GLF_API
130  void BeginTimeElapsed();
131 
132  /// End query
133  GLF_API
134  void End();
135 
136  /// Return the query result (synchronous)
137  /// stalls CPU until the result becomes available.
138  GLF_API
139  int64_t GetResult();
140 
141  /// Return the query result (asynchronous)
142  /// returns 0 if the result hasn't been available.
143  GLF_API
144  int64_t GetResultNoWait();
145 
146  GlfGLQueryObject(GlfGLQueryObject const&) = delete;
147  GlfGLQueryObject& operator =(GlfGLQueryObject const&) = delete;
148 private:
149  GLuint _id;
150  GLenum _target;
151 };
152 
153 
155 
156 #endif
GLuint GLsizei const GLchar * message
Definition: glcorearb.h:2543
GLuint GLsizei const GLchar * label
Definition: glcorearb.h:2545
#define GLF_API
Definition: api.h:23
GLF_API void GlfDefaultDebugOutputMessageCallback(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, char const *message, GLvoid const *userParam)
GLF_API void BeginTimeElapsed()
GLF_API ~GlfGLQueryObject()
GLF_API void BeginSamplesPassed()
GLuint GLsizei GLsizei * length
Definition: glcorearb.h:795
GLF_API int64_t GetResultNoWait()
unsigned int GLuint
Definition: cl.hpp:167
unsigned int GLenum
Definition: cl.hpp:166
GLF_API int64_t GetResult()
GLF_API GlfGLQueryObject()
GlfDebugGroup()=delete
const void * userParam
Definition: glcorearb.h:2541
void GLvoid
Definition: glcorearb.h:87
GLF_API void End()
End query.
int GLsizei
Definition: glcorearb.h:91
GLint GLint GLsizei GLint GLenum GLenum type
Definition: glcorearb.h:108
GLF_API void BeginPrimitivesGenerated()
GLF_API ~GlfDebugGroup()
Pops a debug group off the GL api debug trace stack.
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
GlfGLQueryObject & operator=(GlfGLQueryObject const &)=delete
GLF_API void GlfPostPendingGLErrors(std::string const &where=std::string())
Posts diagnostic errors for all GL errors in the current context.
GLenum target
Definition: glcorearb.h:1667
GLenum GLenum severity
Definition: glcorearb.h:2539
GLF_API void Begin(GLenum target)
GLF_API void GlfRegisterDefaultDebugOutputMessageCallback()
GLF_API void GlfDebugLabelBuffer(GLuint id, char const *label)
Label a buffer object to improve tracing in the debug output.
GLF_API char const * GlfDebugEnumToString(GLenum debugEnum)
Returns a string representation of debug output enum values.
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GLF_API void GlfDebugLabelShader(GLuint id, char const *label)
Label a shader object to improve tracing in the debug output.
GlfDebugGroup & operator=(GlfDebugGroup const &)=delete
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GLF_API void GlfDebugLabelProgram(GLuint id, char const *label)
Label a program object to improve tracing in the debug output.