Bug 910429 - Add KHR_debug support to GLContext. - r=bjacob
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 08 Oct 2013 16:20:24 -0700
changeset 150135 18cb711670f699eaa96df0e718c478f5fa55f7b2
parent 150134 57be8afcd68b9300b55db74bc1da3cc1874e9570
child 150136 c277c55cd10ca5cbb4cf171242cd4bf4e2040cdd
push id34765
push userjgilbert@mozilla.com
push dateTue, 08 Oct 2013 23:20:39 +0000
treeherdermozilla-inbound@18cb711670f6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbjacob
bugs910429
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 910429 - Add KHR_debug support to GLContext. - r=bjacob
gfx/gl/GLContext.cpp
gfx/gl/GLContext.h
gfx/gl/GLContextSymbols.h
gfx/gl/GLTypes.h
--- a/gfx/gl/GLContext.cpp
+++ b/gfx/gl/GLContext.cpp
@@ -111,16 +111,17 @@ static const char *sExtensionNames[] = {
     "GL_ARB_instanced_arrays",
     "GL_NV_instanced_arrays",
     "GL_ANGLE_instanced_arrays",
     "GL_EXT_occlusion_query_boolean",
     "GL_ARB_occlusion_query2",
     "GL_EXT_transform_feedback",
     "GL_NV_transform_feedback",
     "GL_ANGLE_depth_texture",
+    "GL_KHR_debug",
     nullptr
 };
 
 static bool
 ParseGLVersion(GLContext* gl, unsigned int* version)
 {
     GLenum error = gl->fGetError();
     if (error != LOCAL_GL_NO_ERROR) {
@@ -969,16 +970,49 @@ GLContext::InitWithPrefix(const char *pr
             if (!LoadSymbols(queryObjectsSymbols, trygl, prefix)) {
                 NS_ERROR("GL supports query objects iv getter without supplying its function.");
 
                 MarkUnsupported(GLFeature::get_query_object_iv);
                 mSymbols.fGetQueryObjectiv = nullptr;
             }
         }
 
+        if (IsExtensionSupported(KHR_debug)) {
+            SymLoadStruct extSymbols[] = {
+                { (PRFuncPtr*) &mSymbols.fDebugMessageControl,  { "DebugMessageControl",  "DebugMessageControlKHR",  nullptr } },
+                { (PRFuncPtr*) &mSymbols.fDebugMessageInsert,   { "DebugMessageInsert",   "DebugMessageInsertKHR",   nullptr } },
+                { (PRFuncPtr*) &mSymbols.fDebugMessageCallback, { "DebugMessageCallback", "DebugMessageCallbackKHR", nullptr } },
+                { (PRFuncPtr*) &mSymbols.fGetDebugMessageLog,   { "GetDebugMessageLog",   "GetDebugMessageLogKHR",   nullptr } },
+                { (PRFuncPtr*) &mSymbols.fGetPointerv,          { "GetPointerv",          "GetPointervKHR",          nullptr } },
+                { (PRFuncPtr*) &mSymbols.fPushDebugGroup,       { "PushDebugGroup",       "PushDebugGroupKHR",       nullptr } },
+                { (PRFuncPtr*) &mSymbols.fPopDebugGroup,        { "PopDebugGroup",        "PopDebugGroupKHR",        nullptr } },
+                { (PRFuncPtr*) &mSymbols.fObjectLabel,          { "ObjectLabel",          "ObjectLabelKHR",          nullptr } },
+                { (PRFuncPtr*) &mSymbols.fGetObjectLabel,       { "GetObjectLabel",       "GetObjectLabelKHR",       nullptr } },
+                { (PRFuncPtr*) &mSymbols.fObjectPtrLabel,       { "ObjectPtrLabel",       "ObjectPtrLabelKHR",       nullptr } },
+                { (PRFuncPtr*) &mSymbols.fGetObjectPtrLabel,    { "GetObjectPtrLabel",    "GetObjectPtrLabelKHR",    nullptr } },
+                { nullptr, { nullptr } },
+            };
+
+            if (!LoadSymbols(&extSymbols[0], trygl, prefix)) {
+                NS_ERROR("GL supports KHR_debug without supplying its functions.");
+
+                MarkExtensionUnsupported(KHR_debug);
+                mSymbols.fDebugMessageControl  = nullptr;
+                mSymbols.fDebugMessageInsert   = nullptr;
+                mSymbols.fDebugMessageCallback = nullptr;
+                mSymbols.fGetDebugMessageLog   = nullptr;
+                mSymbols.fGetPointerv          = nullptr;
+                mSymbols.fPushDebugGroup       = nullptr;
+                mSymbols.fPopDebugGroup        = nullptr;
+                mSymbols.fObjectLabel          = nullptr;
+                mSymbols.fGetObjectLabel       = nullptr;
+                mSymbols.fObjectPtrLabel       = nullptr;
+                mSymbols.fGetObjectPtrLabel    = nullptr;
+            }
+        }
 
         // Load developer symbols, don't fail if we can't find them.
         SymLoadStruct auxSymbols[] = {
                 { (PRFuncPtr*) &mSymbols.fGetTexImage, { "GetTexImage", nullptr } },
                 { (PRFuncPtr*) &mSymbols.fGetTexLevelParameteriv, { "GetTexLevelParameteriv", nullptr } },
                 { nullptr, { nullptr } },
         };
         bool warnOnFailures = DebugMode();
--- a/gfx/gl/GLContext.h
+++ b/gfx/gl/GLContext.h
@@ -390,16 +390,17 @@ public:
         ARB_instanced_arrays,
         NV_instanced_arrays,
         ANGLE_instanced_arrays,
         EXT_occlusion_query_boolean,
         ARB_occlusion_query2,
         EXT_transform_feedback,
         NV_transform_feedback,
         ANGLE_depth_texture,
+        KHR_debug,
         Extensions_Max,
         Extensions_End
     };
 
     bool IsExtensionSupported(GLExtensions aKnownExtension) const {
         return mAvailableExtensions[aKnownExtension];
     }
 
@@ -891,16 +892,37 @@ public:
     }
 
     void fCullFace(GLenum mode) {
         BEFORE_GL_CALL;
         mSymbols.fCullFace(mode);
         AFTER_GL_CALL;
     }
 
+    void fDebugMessageCallback(GLDEBUGPROC callback, const GLvoid* userParam) {
+        BEFORE_GL_CALL;
+        ASSERT_SYMBOL_PRESENT(fDebugMessageCallback);
+        mSymbols.fDebugMessageCallback(callback, userParam);
+        AFTER_GL_CALL;
+    }
+
+    void fDebugMessageControl(GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint* ids, realGLboolean enabled) {
+        BEFORE_GL_CALL;
+        ASSERT_SYMBOL_PRESENT(fDebugMessageControl);
+        mSymbols.fDebugMessageControl(source, type, severity, count, ids, enabled);
+        AFTER_GL_CALL;
+    }
+
+    void fDebugMessageInsert(GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* buf) {
+        BEFORE_GL_CALL;
+        ASSERT_SYMBOL_PRESENT(fDebugMessageInsert);
+        mSymbols.fDebugMessageInsert(source, type, id, severity, length, buf);
+        AFTER_GL_CALL;
+    }
+
     void fDetachShader(GLuint program, GLuint shader) {
         BEFORE_GL_CALL;
         mSymbols.fDetachShader(program, shader);
         AFTER_GL_CALL;
     }
 
     void fDepthFunc(GLenum func) {
         BEFORE_GL_CALL;
@@ -1089,16 +1111,45 @@ public:
     }
 
     void fGetBufferParameteriv(GLenum target, GLenum pname, GLint* params) {
         BEFORE_GL_CALL;
         mSymbols.fGetBufferParameteriv(target, pname, params);
         AFTER_GL_CALL;
     }
 
+    GLuint fGetDebugMessageLog(GLuint count, GLsizei bufsize, GLenum* sources, GLenum* types, GLuint* ids, GLenum* severities, GLsizei* lengths, GLchar* messageLog) {
+        BEFORE_GL_CALL;
+        ASSERT_SYMBOL_PRESENT(fGetDebugMessageLog);
+        GLuint ret = mSymbols.fGetDebugMessageLog(count, bufsize, sources, types, ids, severities, lengths, messageLog);
+        AFTER_GL_CALL;
+        return ret;
+    }
+
+    void fGetPointerv(GLenum pname, GLvoid** params) {
+        BEFORE_GL_CALL;
+        ASSERT_SYMBOL_PRESENT(fGetPointerv);
+        mSymbols.fGetPointerv(pname, params);
+        AFTER_GL_CALL;
+    }
+
+    void fGetObjectLabel(GLenum identifier, GLuint name, GLsizei bufSize, GLsizei* length, GLchar* label) {
+        BEFORE_GL_CALL;
+        ASSERT_SYMBOL_PRESENT(fGetObjectLabel);
+        mSymbols.fGetObjectLabel(identifier, name, bufSize, length, label);
+        AFTER_GL_CALL;
+    }
+
+    void fGetObjectPtrLabel(GLvoid* ptr, GLsizei bufSize, GLsizei* length, GLchar* label) {
+        BEFORE_GL_CALL;
+        ASSERT_SYMBOL_PRESENT(fGetObjectPtrLabel);
+        mSymbols.fGetObjectPtrLabel(ptr, bufSize, length, label);
+        AFTER_GL_CALL;
+    }
+
     void fGenerateMipmap(GLenum target) {
         BEFORE_GL_CALL;
         mSymbols.fGenerateMipmap(target);
         AFTER_GL_CALL;
     }
 
     void fGetProgramiv(GLuint program, GLenum pname, GLint* param) {
         BEFORE_GL_CALL;
@@ -1249,16 +1300,30 @@ public:
     }
 
     void fLinkProgram(GLuint program) {
         BEFORE_GL_CALL;
         mSymbols.fLinkProgram(program);
         AFTER_GL_CALL;
     }
 
+    void fObjectLabel(GLenum identifier, GLuint name, GLsizei length, const GLchar* label) {
+        BEFORE_GL_CALL;
+        ASSERT_SYMBOL_PRESENT(fObjectLabel);
+        mSymbols.fObjectLabel(identifier, name, length, label);
+        AFTER_GL_CALL;
+    }
+
+    void fObjectPtrLabel(GLvoid* ptr, GLsizei length, const GLchar* label) {
+        BEFORE_GL_CALL;
+        ASSERT_SYMBOL_PRESENT(fObjectPtrLabel);
+        mSymbols.fObjectPtrLabel(ptr, length, label);
+        AFTER_GL_CALL;
+    }
+
     void fPixelStorei(GLenum pname, GLint param) {
         BEFORE_GL_CALL;
         mSymbols.fPixelStorei(pname, param);
         AFTER_GL_CALL;
     }
 
     void fPointParameterf(GLenum pname, GLfloat param) {
         BEFORE_GL_CALL;
@@ -1267,16 +1332,30 @@ public:
     }
 
     void fPolygonOffset(GLfloat factor, GLfloat bias) {
         BEFORE_GL_CALL;
         mSymbols.fPolygonOffset(factor, bias);
         AFTER_GL_CALL;
     }
 
+    void fPopDebugGroup() {
+        BEFORE_GL_CALL;
+        ASSERT_SYMBOL_PRESENT(fPopDebugGroup);
+        mSymbols.fPopDebugGroup();
+        AFTER_GL_CALL;
+    }
+
+    void fPushDebugGroup(GLenum source, GLuint id, GLsizei length, const GLchar* message) {
+        BEFORE_GL_CALL;
+        ASSERT_SYMBOL_PRESENT(fPushDebugGroup);
+        mSymbols.fPushDebugGroup(source, id, length, message);
+        AFTER_GL_CALL;
+    }
+
     void fReadBuffer(GLenum mode) {
         BEFORE_GL_CALL;
         mSymbols.fReadBuffer(mode);
         AFTER_GL_CALL;
     }
 
 private:
     void raw_fReadPixels(GLint x, GLint y, GLsizei width, GLsizei height, GLenum format, GLenum type, GLvoid *pixels) {
--- a/gfx/gl/GLContextSymbols.h
+++ b/gfx/gl/GLContextSymbols.h
@@ -437,14 +437,38 @@ struct GLContextSymbols
     PFNGLGETTRANSFORMFEEDBACKVARYING fGetTransformFeedbackVarying;
 
     typedef void (GLAPIENTRY * PFNGLGETINTEGERI_V) (GLenum param, GLuint index, GLint* values);
     PFNGLGETINTEGERI_V fGetIntegeri_v;
 
     // EXT_transform_feedback only
     typedef void (GLAPIENTRY * PFNGLBINDBUFFEROFFSET) (GLenum target, GLuint index, GLuint buffer, GLintptr offset);
     PFNGLBINDBUFFEROFFSET fBindBufferOffset;
+
+    // KHR_debug
+    typedef void (GLAPIENTRY * PFNGLDEBUGMESSAGECONTROL) (GLenum source, GLenum type, GLenum severity, GLsizei count, const GLuint* ids, realGLboolean enabled);
+    PFNGLDEBUGMESSAGECONTROL fDebugMessageControl;
+    typedef void (GLAPIENTRY * PFNGLDEBUGMESSAGEINSERT) (GLenum source, GLenum type, GLuint id, GLenum severity, GLsizei length, const GLchar* buf);
+    PFNGLDEBUGMESSAGEINSERT fDebugMessageInsert;
+    typedef void (GLAPIENTRY * PFNGLDEBUGMESSAGECALLBACK) (GLDEBUGPROC callback, const GLvoid* userParam);
+    PFNGLDEBUGMESSAGECALLBACK fDebugMessageCallback;
+    typedef GLuint (GLAPIENTRY * PFNGLDEBUGMESSAGELOG) (GLuint count, GLsizei bufsize, GLenum* sources, GLenum* types, GLuint* ids, GLenum* severities, GLsizei* lengths, GLchar* messageLog);
+    PFNGLDEBUGMESSAGELOG fGetDebugMessageLog;
+    typedef void (GLAPIENTRY * PFNGLGETPOINTERV) (GLenum pname, GLvoid** params);
+    PFNGLGETPOINTERV fGetPointerv;
+    typedef void (GLAPIENTRY * PFNGLPUSHDEBUGGROUP) (GLenum source, GLuint id, GLsizei length, const GLchar* message);
+    PFNGLPUSHDEBUGGROUP fPushDebugGroup;
+    typedef void (GLAPIENTRY * PFNGLPOPDEBUGGROUP) (void);
+    PFNGLPOPDEBUGGROUP fPopDebugGroup;
+    typedef void (GLAPIENTRY * PFNGLOBJECTLABEL) (GLenum identifier, GLuint name, GLsizei length, const GLchar* label);
+    PFNGLOBJECTLABEL fObjectLabel;
+    typedef void (GLAPIENTRY * PFNGLGETOBJECTLABEL) (GLenum identifier, GLuint name, GLsizei bufSize, GLsizei* length, GLchar* label);
+    PFNGLGETOBJECTLABEL fGetObjectLabel;
+    typedef void (GLAPIENTRY * PFNGLOBJECTPTRLABEL) (GLvoid* ptr, GLsizei length, const GLchar* label);
+    PFNGLOBJECTPTRLABEL fObjectPtrLabel;
+    typedef void (GLAPIENTRY * PFNGLGETOBJECTPTRLABEL) (GLvoid* ptr, GLsizei bufSize, GLsizei* length, GLchar* label);
+    PFNGLGETOBJECTPTRLABEL fGetObjectPtrLabel;
 };
 
 }
 }
 
 #endif /* GLCONTEXTSYMBOLS_H_ */
--- a/gfx/gl/GLTypes.h
+++ b/gfx/gl/GLTypes.h
@@ -3,16 +3,27 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #if !defined(GLTYPES_H_)
 #define GLTYPES_H_
 
 #include <stddef.h>
 #include <stdint.h>
 
+#ifndef GLAPIENTRY
+# ifdef WIN32
+#  include <windef.h>
+#  define GLAPIENTRY APIENTRY
+#  define GLAPI
+# else
+#  define GLAPIENTRY
+#  define GLAPI
+# endif
+#endif
+
 typedef int8_t realGLboolean;
 
 #if !defined(__gltypes_h_) && !defined(__gl_h_)
 #define __gltypes_h_
 #define __gl_h_
 
 typedef uint32_t GLenum;
 typedef uint32_t GLbitfield;
@@ -44,16 +55,25 @@ typedef intptr_t GLintptr;
 // ARB_sync
 typedef struct __GLsync* GLsync;
 typedef int64_t GLint64;
 typedef uint64_t GLuint64;
 
 // OES_EGL_image (GLES)
 typedef void* GLeglImage;
 
+// KHR_debug
+typedef void (GLAPIENTRY *GLDEBUGPROC)(GLenum source,
+                                       GLenum type,
+                                       GLuint id,
+                                       GLenum severity,
+                                       GLsizei length,
+                                       const GLchar* message,
+                                       const GLvoid* userParam);
+
 // EGL types
 typedef void* EGLImage;
 typedef int EGLint;
 typedef unsigned int EGLBoolean;
 typedef unsigned int EGLenum;
 typedef void *EGLConfig;
 typedef void *EGLContext;
 typedef void *EGLDisplay;
@@ -66,19 +86,9 @@ typedef uint64_t EGLTime;
 
 #define EGL_NO_CONTEXT       ((EGLContext)0)
 #define EGL_NO_DISPLAY       ((EGLDisplay)0)
 #define EGL_NO_SURFACE       ((EGLSurface)0)
 #define EGL_NO_CONFIG        ((EGLConfig)nullptr)
 #define EGL_NO_SYNC          ((EGLSync)0)
 #define EGL_NO_IMAGE         ((EGLImage)0)
 
-#ifndef GLAPIENTRY
-# ifdef WIN32
-#  define GLAPIENTRY APIENTRY
-#  define GLAPI
-# else
-#  define GLAPIENTRY
-#  define GLAPI
-# endif
 #endif
-
-#endif