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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_GLF_DIAGNOSTIC_H
25 #define PXR_IMAGING_GLF_DIAGNOSTIC_H
26 
27 /// \file glf/diagnostic.h
28 
29 #include "pxr/pxr.h"
30 #include "pxr/imaging/glf/api.h"
32 #include "pxr/base/tf/diagnostic.h"
33 
34 #include <string>
35 #include <cstdint>
36 
38 
39 
40 /// Posts diagnostic errors for all GL errors in the current context.
41 /// This macro tags the diagnostic errors with the name of the calling
42 /// function.
43 #define GLF_POST_PENDING_GL_ERRORS() \
44  GlfPostPendingGLErrors(__ARCH_PRETTY_FUNCTION__)
45 
46 /// Posts diagnostic errors for all GL errors in the current context.
47 GLF_API
48 void GlfPostPendingGLErrors(std::string const & where = std::string());
49 
50 /// Registers GlfDefaultDebugOutputMessageCallback as the
51 /// debug message callback for the current GL context.
52 GLF_API
54 
55 /// A GL debug output message callback method which posts diagnostic
56 /// errors for messages of type DEBUG_TYPE_ERROR and diagnostic warnings
57 /// for other message types.
58 GLF_API
61  GLsizei length, char const * message, GLvoid const * userParam);
62 
63 /// Returns a string representation of debug output enum values.
64 GLF_API
65 char const * GlfDebugEnumToString(GLenum debugEnum);
66 
67 /// Emit a GlfDebugGroup tracing the current function.
68 #define GLF_GROUP_FUNCTION() \
69  GlfDebugGroup __glf_group_function(__ARCH_PRETTY_FUNCTION__)
70 
71 /// Emit a GlfDebugGroup tracing the current scope with the given string.
72 #define GLF_GROUP_SCOPE(str) \
73  GlfDebugGroup __glf_group_scope(str)
74 
75 /// \class GlfDebugGroup
76 ///
77 /// Represents a GL debug group in Glf
78 ///
79 /// The debug group conditionally adds debug objects to the GL stream
80 /// based on the value to the environment variable GLF_ENABLE_DIAGNOSTIC_TRACE.
81 /// If set to 1 (true) the debug objects will be pushed and popped in
82 /// the command stream as long as the GL implementation and version supports it.
83 ///
85  public:
86  /// Pushes a new debug group onto the GL api debug trace stack
87  GLF_API
88  GlfDebugGroup(char const *message);
89 
90  /// Pops a debug group off the GL api debug trace stack
91  GLF_API
93 
94  GlfDebugGroup() = delete;
95  GlfDebugGroup(GlfDebugGroup const&) = delete;
96  GlfDebugGroup& operator =(GlfDebugGroup const&) = delete;
97 };
98 
99 /// Label a buffer object to improve tracing in the debug output.
100 GLF_API
101 void GlfDebugLabelBuffer(GLuint id, char const *label);
102 
103 /// Label a shader object to improve tracing in the debug output.
104 GLF_API
105 void GlfDebugLabelShader(GLuint id, char const *label);
106 
107 /// Label a program object to improve tracing in the debug output.
108 GLF_API
109 void GlfDebugLabelProgram(GLuint id, char const *label);
110 
111 /// \class GlfGLQueryObject
112 ///
113 /// Represents a GL query object in Glf
114 ///
116 public:
117  GLF_API
119  GLF_API
121 
122  /// Begin query for the given \p target
123  /// target has to be one of
124  /// GL_SAMPLES_PASSED, GL_ANY_SAMPLES_PASSED,
125  /// GL_ANY_SAMPLES_PASSED_CONSERVATIVE, GL_PRIMITIVES_GENERATED
126  /// GL_TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN
127  /// GL_TIME_ELAPSED, GL_TIMESTAMP
128  GLF_API
129  void Begin(GLenum target);
130 
131  /// equivalent to Begin(GL_SAMPLES_PASSED).
132  /// The number of samples that pass the depth test for all drawing
133  /// commands within the scope of the query will be returned.
134  GLF_API
135  void BeginSamplesPassed();
136 
137  /// equivalent to Begin(GL_PRIMITIVES_GENERATED).
138  /// The number of primitives sent to the rasterizer by the scoped
139  /// drawing command will be returned.
140  GLF_API
142 
143  /// equivalent to Begin(GL_TIME_ELAPSED).
144  /// The time that it takes for the GPU to execute all of the scoped commands
145  /// will be returned in nanoseconds.
146  GLF_API
147  void BeginTimeElapsed();
148 
149  /// End query
150  GLF_API
151  void End();
152 
153  /// Return the query result (synchronous)
154  /// stalls CPU until the result becomes available.
155  GLF_API
156  int64_t GetResult();
157 
158  /// Return the query result (asynchronous)
159  /// returns 0 if the result hasn't been available.
160  GLF_API
161  int64_t GetResultNoWait();
162 
163  GlfGLQueryObject(GlfGLQueryObject const&) = delete;
164  GlfGLQueryObject& operator =(GlfGLQueryObject const&) = delete;
165 private:
166  GLuint _id;
167  GLenum _target;
168 };
169 
170 
172 
173 #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:40
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()
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
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
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:1441
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:91
GLF_API void GlfDebugLabelProgram(GLuint id, char const *label)
Label a program object to improve tracing in the debug output.
type
Definition: core.h:1059