Check for GL debug extensions before use

This commit is contained in:
Jannik Vogel 2018-06-28 23:53:15 +02:00 committed by Matt Borgerson
parent 0f190369d3
commit a9db473231
5 changed files with 62 additions and 33 deletions

View File

@ -35,7 +35,6 @@
#if defined(__APPLE__) /* macOS-Specific GL Includes */
#include <OpenGL/OpenGL.h>
#include <OpenGL/gl3.h>
#include <OpenGL/glext.h>
#elif defined(_WIN32) /* Windows-Specific GL Includes */
#include <epoxy/wgl.h>

View File

@ -66,11 +66,6 @@ GloContext *glo_context_create(void)
return context;
}
void* glo_get_extension_proc(const char* ext_proc)
{
return dlsym(RTLD_NEXT, ext_proc);
}
/* Set current context */
void glo_set_current(GloContext *context)
{

View File

@ -18,27 +18,48 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "nv2a_debug.h"
#ifdef DEBUG_NV2A_GL
#include "qemu/osdep.h"
#include <stdio.h>
#include <stdbool.h>
#include <stdarg.h>
#include <assert.h>
#include "nv2a_debug.h"
#include "gl/glextensions.h"
static bool has_GL_GREMEDY_frame_terminator = false;
static bool has_GL_KHR_debug = false;
void gl_debug_initialize(void)
{
if (glo_check_extension("GL_KHR_debug")) {
has_GL_KHR_debug = glo_check_extension("GL_KHR_debug");
has_GL_GREMEDY_frame_terminator = glo_check_extension("GL_GREMEDY_frame_terminator");
if (has_GL_KHR_debug) {
#if defined(__APPLE__)
/* On macOS, calling glEnable(GL_DEBUG_OUTPUT) will result in error
* GL_INVALID_ENUM.
*
* According to GL_KHR_debug this should work, therefore probably
* not a bug in our code.
*
* It appears however that we can safely ignore this error, and the
* debug functions which we depend on will still work as expected,
* so skip the call for this platform.
*/
#else
glEnable(GL_DEBUG_OUTPUT);
assert(glGetError() == GL_NO_ERROR);
#endif
}
}
void gl_debug_message(bool cc, const char *fmt, ...)
{
if (!has_GL_KHR_debug) {
return;
}
size_t n;
char buffer[1024];
va_list ap;
@ -47,10 +68,8 @@ void gl_debug_message(bool cc, const char *fmt, ...)
assert(n <= sizeof(buffer));
va_end(ap);
if(glDebugMessageInsert) {
glDebugMessageInsert(GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER,
0, GL_DEBUG_SEVERITY_NOTIFICATION, n, buffer);
}
if (cc) {
fwrite(buffer, sizeof(char), n, stdout);
fputc('\n', stdout);
@ -59,6 +78,8 @@ void gl_debug_message(bool cc, const char *fmt, ...)
void gl_debug_group_begin(const char *fmt, ...)
{
/* Debug group begin */
if (has_GL_KHR_debug) {
size_t n;
char buffer[1024];
va_list ap;
@ -67,12 +88,11 @@ void gl_debug_group_begin(const char *fmt, ...)
assert(n <= sizeof(buffer));
va_end(ap);
/* Check for errors before entering group */
assert(glGetError() == GL_NO_ERROR);
if (glPushDebugGroup) {
glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, n, buffer);
}
/* Check for errors before starting real commands in group */
assert(glGetError() == GL_NO_ERROR);
}
void gl_debug_group_end(void)
@ -80,13 +100,18 @@ void gl_debug_group_end(void)
/* Check for errors when leaving group */
assert(glGetError() == GL_NO_ERROR);
if (glPopDebugGroup) {
/* Debug group end */
if (has_GL_KHR_debug) {
glPopDebugGroup();
}
}
void gl_debug_label(GLenum target, GLuint name, const char *fmt, ...)
{
if (!has_GL_KHR_debug) {
return;
}
size_t n;
char buffer[1024];
va_list ap;
@ -95,9 +120,16 @@ void gl_debug_label(GLenum target, GLuint name, const char *fmt, ...)
assert(n <= sizeof(buffer));
va_end(ap);
if (glObjectLabel) {
glObjectLabel(target, name, n, buffer);
}
void gl_debug_frame_terminator(void)
{
if (!has_GL_GREMEDY_frame_terminator) {
return;
}
glFrameTerminatorGREMEDY();
}
#endif

View File

@ -34,10 +34,12 @@
#include <stdbool.h>
#include "gl/gloffscreen.h"
void gl_debug_initialize(void);
void gl_debug_message(bool cc, const char *fmt, ...);
void gl_debug_group_begin(const char *fmt, ...);
void gl_debug_group_end(void);
void gl_debug_label(GLenum target, GLuint name, const char *fmt, ...);
void gl_debug_frame_terminator(void);
# define NV2A_GL_DPRINTF(cc, format, ...) \
gl_debug_message(cc, "nv2a: " format, ## __VA_ARGS__)
@ -47,6 +49,8 @@ void gl_debug_label(GLenum target, GLuint name, const char *fmt, ...);
gl_debug_group_end()
# define NV2A_GL_DLABEL(target, name, format, ...) \
gl_debug_label(target, name, "nv2a: { " format " }", ## __VA_ARGS__)
#define NV2A_GL_DFRAME_TERMINATOR() \
gl_debug_frame_terminator()
#else
# define NV2A_GL_DPRINTF(cc, format, ...) do { \
@ -55,6 +59,7 @@ void gl_debug_label(GLenum target, GLuint name, const char *fmt, ...);
# define NV2A_GL_DGROUP_BEGIN(format, ...) do { } while (0)
# define NV2A_GL_DGROUP_END() do { } while (0)
# define NV2A_GL_DLABEL(target, name, format, ...) do { } while (0)
# define NV2A_GL_DFRAME_TERMINATOR() do { } while (0)
#endif
#endif

View File

@ -650,9 +650,7 @@ static void pgraph_method(NV2AState *d,
GET_MASK(pg->regs[NV_PGRAPH_SURFACE],
NV_PGRAPH_SURFACE_WRITE_3D));
if (glFrameTerminatorGREMEDY) {
glFrameTerminatorGREMEDY();
}
NV2A_GL_DFRAME_TERMINATOR();
break;
}