Skip to content

Commit c1e8203

Browse files
committed
debug: Log GL errors during assertions in debug mode
1 parent ff1617d commit c1e8203

File tree

8 files changed

+68
-34
lines changed

8 files changed

+68
-34
lines changed

hw/xbox/nv2a/debug_gl.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef XEMU_HW_XBOX_NV2A_DEBUG_GL_H_
2+
#define XEMU_HW_XBOX_NV2A_DEBUG_GL_H_
3+
4+
#ifdef XEMU_DEBUG_BUILD
5+
#define ASSERT_NO_GL_ERROR() \
6+
do { \
7+
GLenum error = glGetError(); \
8+
if (error != GL_NO_ERROR) { \
9+
fprintf(stderr, "OpenGL error: 0x%X (%d) at %s:%d\n", error, \
10+
error, __FILE__, __LINE__); \
11+
assert(!"OpenGL error detected"); \
12+
} \
13+
} while (0)
14+
15+
#define ASSERT_FRAMEBUFFER_COMPLETE() \
16+
do { \
17+
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); \
18+
if (status != GL_FRAMEBUFFER_COMPLETE) { \
19+
fprintf(stderr, \
20+
"OpenGL framebuffer status: 0x%X (%d) != " \
21+
"GL_FRAMEBUFFER_COMPLETE at %s:%d\n", \
22+
status, status, __FILE__, __LINE__); \
23+
assert( \
24+
!"OpenGL GL_FRAMEBUFFER status != GL_FRAMEBUFFER_COMPLETE"); \
25+
} \
26+
} while (0)
27+
28+
#else
29+
#define CHECK_GL_ERROR() assert(glGetError() == GL_NO_ERROR)
30+
31+
#define ASSERT_FRAMEBUFFER_COMPLETE() \
32+
assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)
33+
34+
#endif // XEMU_DEBUG_BUILD
35+
36+
#endif // XEMU_HW_XBOX_NV2A_DEBUG_GL_H_

hw/xbox/nv2a/pgraph/gl/debug.c

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,7 @@
3535
#include "thirdparty/renderdoc_app.h"
3636
#endif
3737

38-
#define CHECK_GL_ERROR() do { \
39-
GLenum error = glGetError(); \
40-
if (error != GL_NO_ERROR) { \
41-
fprintf(stderr, "OpenGL error: 0x%X (%d) at %s:%d\n", error, error, __FILE__, __LINE__); \
42-
assert(!"OpenGL error detected"); \
43-
} \
44-
} while(0)
38+
#include "hw/xbox/nv2a/debug_gl.h"
4539

4640
static bool has_GL_GREMEDY_frame_terminator = false;
4741
static bool has_GL_KHR_debug = false;
@@ -65,7 +59,7 @@ void gl_debug_initialize(void)
6559
*/
6660
#else
6761
glEnable(GL_DEBUG_OUTPUT);
68-
assert(glGetError() == GL_NO_ERROR);
62+
ASSERT_NO_GL_ERROR();
6963
#endif
7064
}
7165

@@ -112,13 +106,13 @@ void gl_debug_group_begin(const char *fmt, ...)
112106
}
113107

114108
/* Check for errors before starting real commands in group */
115-
assert(glGetError() == GL_NO_ERROR);
109+
ASSERT_NO_GL_ERROR();
116110
}
117111

118112
void gl_debug_group_end(void)
119113
{
120114
/* Check for errors when leaving group */
121-
assert(glGetError() == GL_NO_ERROR);
115+
ASSERT_NO_GL_ERROR();
122116

123117
/* Debug group end */
124118
if (has_GL_KHR_debug) {
@@ -142,13 +136,12 @@ void gl_debug_label(GLenum target, GLuint name, const char *fmt, ...)
142136

143137
glObjectLabel(target, name, n, buffer);
144138

145-
GLenum err = glGetError();
146-
assert(err == GL_NO_ERROR);
139+
ASSERT_NO_GL_ERROR();
147140
}
148141

149142
void gl_debug_frame_terminator(void)
150143
{
151-
CHECK_GL_ERROR();
144+
ASSERT_NO_GL_ERROR();
152145

153146
#ifdef CONFIG_RENDERDOC
154147
if (nv2a_dbg_renderdoc_available()) {
@@ -190,7 +183,7 @@ void gl_debug_frame_terminator(void)
190183
#endif
191184
if (has_GL_GREMEDY_frame_terminator) {
192185
glFrameTerminatorGREMEDY();
193-
CHECK_GL_ERROR();
186+
ASSERT_NO_GL_ERROR();
194187
}
195188
}
196189

hw/xbox/nv2a/pgraph/gl/display.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "qemu/osdep.h"
2323
#include "hw/display/vga_int.h"
24+
#include "hw/xbox/nv2a/debug_gl.h"
2425
#include "hw/xbox/nv2a/nv2a_int.h"
2526
#include "hw/xbox/nv2a/pgraph/util.h"
2627
#include "renderer.h"
@@ -103,7 +104,7 @@ void pgraph_gl_init_display(NV2AState *d)
103104
glBufferData(GL_ARRAY_BUFFER, 0, NULL, GL_STATIC_DRAW);
104105
glGenFramebuffers(1, &r->disp_rndr.fbo);
105106
glGenTextures(1, &r->disp_rndr.pvideo_tex);
106-
assert(glGetError() == GL_NO_ERROR);
107+
ASSERT_NO_GL_ERROR();
107108

108109
glo_set_current(g_nv2a_context_render);
109110
}
@@ -336,7 +337,7 @@ static void render_display(NV2AState *d, SurfaceBinding *surface)
336337
GL_TEXTURE_2D, r->gl_display_buffer, 0);
337338
GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
338339
glDrawBuffers(1, DrawBuffers);
339-
assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
340+
ASSERT_FRAMEBUFFER_COMPLETE();
340341

341342
glBindTexture(GL_TEXTURE_2D, surface->gl_buffer);
342343
glBindVertexArray(r->disp_rndr.vao);
@@ -388,13 +389,13 @@ void pgraph_gl_sync(NV2AState *d)
388389
/* Wait for queued commands to complete */
389390
pgraph_gl_upload_surface_data(d, surface, !tcg_enabled());
390391
gl_fence();
391-
assert(glGetError() == GL_NO_ERROR);
392+
ASSERT_NO_GL_ERROR();
392393

393394
/* Render framebuffer in display context */
394395
glo_set_current(g_nv2a_context_display);
395396
render_display(d, surface);
396397
gl_fence();
397-
assert(glGetError() == GL_NO_ERROR);
398+
ASSERT_NO_GL_ERROR();
398399

399400
/* Switch back to original context */
400401
glo_set_current(g_nv2a_context_render);

hw/xbox/nv2a/pgraph/gl/shaders.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
#include "xemu-version.h"
2727
#include "ui/xemu-settings.h"
28+
#include "hw/xbox/nv2a/debug_gl.h"
2829
#include "hw/xbox/nv2a/pgraph/util.h"
2930
#include "debug.h"
3031
#include "renderer.h"
@@ -310,7 +311,7 @@ void pgraph_gl_shader_write_cache_reload_list(PGRAPHState *pg)
310311

311312
bool pgraph_gl_shader_load_from_memory(ShaderBinding *binding)
312313
{
313-
assert(glGetError() == GL_NO_ERROR);
314+
ASSERT_NO_GL_ERROR();
314315

315316
if (!binding->program) {
316317
return false;
@@ -677,7 +678,7 @@ void pgraph_gl_shader_cache_to_disk(ShaderBinding *binding)
677678
GLsizei program_size_copied;
678679
glGetProgramBinary(binding->gl_program, program_size, &program_size_copied,
679680
&binding->program_format, binding->program);
680-
assert(glGetError() == GL_NO_ERROR);
681+
ASSERT_NO_GL_ERROR();
681682

682683
binding->program_size = program_size_copied;
683684
binding->cached = true;
@@ -728,7 +729,7 @@ static void apply_uniform_updates(const UniformInfo *info, int *locs,
728729
}
729730
}
730731

731-
assert(glGetError() == GL_NO_ERROR);
732+
ASSERT_NO_GL_ERROR();
732733
}
733734

734735
// FIXME: Dirty tracking

hw/xbox/nv2a/pgraph/gl/surface.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#include "hw/xbox/nv2a/pgraph/pgraph.h"
2323
#include "ui/xemu-settings.h"
24+
#include "hw/xbox/nv2a/debug_gl.h"
2425
#include "hw/xbox/nv2a/nv2a_int.h"
2526
#include "hw/xbox/nv2a/pgraph/swizzle.h"
2627
#include "debug.h"
@@ -233,8 +234,8 @@ static void render_surface_to(NV2AState *d, SurfaceBinding *surface,
233234
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, gl_target,
234235
gl_texture, 0);
235236
glDrawBuffers(1, draw_buffers);
236-
assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
237-
assert(glGetError() == GL_NO_ERROR);
237+
ASSERT_FRAMEBUFFER_COMPLETE();
238+
ASSERT_NO_GL_ERROR();
238239

239240
float color[] = { 0.0f, 0.0f, 0.0f, 0.0f };
240241
glBindTexture(GL_TEXTURE_2D, surface->gl_buffer);
@@ -644,8 +645,7 @@ static void bind_current_surface(NV2AState *d)
644645
}
645646

646647
if (r->color_binding || r->zeta_binding) {
647-
assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) ==
648-
GL_FRAMEBUFFER_COMPLETE);
648+
ASSERT_FRAMEBUFFER_COMPLETE();
649649
}
650650
}
651651

@@ -700,7 +700,7 @@ static void surface_download_to_buffer(NV2AState *d, SurfaceBinding *surface,
700700
glFramebufferTexture2D(GL_FRAMEBUFFER, surface->fmt.gl_attachment,
701701
GL_TEXTURE_2D, surface->gl_buffer, 0);
702702

703-
assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE);
703+
ASSERT_FRAMEBUFFER_COMPLETE();
704704

705705
/* Read surface into memory */
706706
uint8_t *gl_read_buf = pixels;
@@ -1254,8 +1254,7 @@ static void update_surface_part(NV2AState *d, bool upload, bool color)
12541254

12551255
glFramebufferTexture2D(GL_FRAMEBUFFER, entry.fmt.gl_attachment,
12561256
GL_TEXTURE_2D, found->gl_buffer, 0);
1257-
assert(glCheckFramebufferStatus(GL_FRAMEBUFFER) ==
1258-
GL_FRAMEBUFFER_COMPLETE);
1257+
ASSERT_FRAMEBUFFER_COMPLETE();
12591258

12601259
surface->buffer_dirty = false;
12611260
}

hw/xbox/nv2a/pgraph/gl/vertex.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
#include "hw/xbox/nv2a/nv2a_regs.h"
23+
#include "hw/xbox/nv2a/debug_gl.h"
2324
#include <hw/xbox/nv2a/nv2a_int.h>
2425
#include "debug.h"
2526
#include "renderer.h"
@@ -280,7 +281,7 @@ void pgraph_gl_init_buffers(NV2AState *d)
280281
glGenVertexArrays(1, &r->gl_vertex_array);
281282
glBindVertexArray(r->gl_vertex_array);
282283

283-
assert(glGetError() == GL_NO_ERROR);
284+
ASSERT_NO_GL_ERROR();
284285
}
285286

286287
void pgraph_gl_finalize_buffers(PGRAPHState *pg)

hw/xbox/nv2a/pgraph/vk/display.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
#include "renderer.h"
2121
#include <math.h>
2222

23+
#include "hw/xbox/nv2a/debug_gl.h"
24+
2325
static uint8_t *convert_texture_data__CR8YB8CB8YA8(uint8_t *data_out,
2426
const uint8_t *data_in,
2527
unsigned int width,
@@ -682,7 +684,7 @@ static void create_display_image(PGRAPHState *pg, int width, int height)
682684

683685
glCreateMemoryObjectsEXT(1, &d->gl_memory_obj);
684686
glImportMemoryWin32HandleEXT(d->gl_memory_obj, memory_requirements.size, GL_HANDLE_TYPE_OPAQUE_WIN32_EXT, d->handle);
685-
assert(glGetError() == GL_NO_ERROR);
687+
ASSERT_NO_GL_ERROR();
686688

687689
#else
688690

@@ -697,7 +699,7 @@ static void create_display_image(PGRAPHState *pg, int width, int height)
697699
glImportMemoryFdEXT(d->gl_memory_obj, memory_requirements.size,
698700
GL_HANDLE_TYPE_OPAQUE_FD_EXT, d->fd);
699701
assert(glIsMemoryObjectEXT(d->gl_memory_obj));
700-
assert(glGetError() == GL_NO_ERROR);
702+
ASSERT_NO_GL_ERROR();
701703

702704
#endif // WIN32
703705

@@ -711,7 +713,7 @@ static void create_display_image(PGRAPHState *pg, int width, int height)
711713
glTexStorageMem2DEXT(GL_TEXTURE_2D, 1, gl_internal_format,
712714
image_create_info.extent.width,
713715
image_create_info.extent.height, d->gl_memory_obj, 0);
714-
assert(glGetError() == GL_NO_ERROR);
716+
ASSERT_NO_GL_ERROR();
715717

716718
#endif // HAVE_EXTERNAL_MEMORY
717719

ui/xemu.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555

5656
#include "hw/xbox/smbus.h" // For eject, drive tray
5757
#include "hw/xbox/nv2a/nv2a.h"
58+
#include "hw/xbox/nv2a/debug_gl.h"
5859
#include "ui/xemu-notifications.h"
5960

6061
#include <stb_image.h>
@@ -320,7 +321,7 @@ static void handle_keydown(SDL_Event *ev)
320321
{
321322
int win;
322323
struct sdl2_console *scon = get_scon_from_window(ev->key.windowID);
323-
if (scon == NULL) return;
324+
if (scon == NULL) return;
324325
int gui_key_modifier_pressed = get_mod_state();
325326
int gui_keysym = 0;
326327

@@ -1409,7 +1410,7 @@ int main(int argc, char **argv)
14091410

14101411
while (1) {
14111412
sdl2_gl_refresh(&sdl2_console[0].dcl);
1412-
assert(glGetError() == GL_NO_ERROR);
1413+
ASSERT_NO_GL_ERROR();
14131414
}
14141415

14151416
// rcu_unregister_thread();

0 commit comments

Comments
 (0)