Skip to content

Commit 25ede9b

Browse files
committed
debug: Log framebuffer details when not complete
1 parent 4e566d5 commit 25ede9b

File tree

3 files changed

+114
-13
lines changed

3 files changed

+114
-13
lines changed

hw/xbox/nv2a/debug.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Geforce NV2A PGRAPH OpenGL Renderer debug routines
3+
*
4+
* Copyright (c) 2025 Matt Borgerson
5+
*
6+
* This library is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 2 of the License, or (at your option) any later version.
10+
*
11+
* This library is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public
17+
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
#include "hw/xbox/nv2a/debug_gl.h"
21+
22+
#include <stdio.h>
23+
24+
#include "qemu/osdep.h"
25+
26+
#ifdef XEMU_DEBUG_BUILD
27+
28+
static GLenum framebuffer_attachments[] = { GL_COLOR_ATTACHMENT0,
29+
GL_DEPTH_ATTACHMENT,
30+
GL_STENCIL_ATTACHMENT,
31+
GL_DEPTH_STENCIL_ATTACHMENT };
32+
33+
void gl_debug_assert_framebuffer_complete(const char *source_file, int line)
34+
{
35+
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
36+
if (status == GL_FRAMEBUFFER_COMPLETE) {
37+
return;
38+
}
39+
40+
fprintf(stderr,
41+
"OpenGL framebuffer status: 0x%X (%d) != "
42+
"GL_FRAMEBUFFER_COMPLETE at %s:%d\n",
43+
status, status, source_file, line);
44+
45+
GLint objectType, objectName;
46+
for (int i = 0; i < ARRAY_SIZE(framebuffer_attachments); ++i) {
47+
GLenum attachment = framebuffer_attachments[i];
48+
49+
glGetFramebufferAttachmentParameteriv(
50+
GL_FRAMEBUFFER, attachment, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE,
51+
&objectType);
52+
53+
if (objectType == GL_NONE) {
54+
fprintf(stderr, "\t0x%X: GL_NONE\n", attachment);
55+
} else {
56+
glGetFramebufferAttachmentParameteriv(
57+
GL_FRAMEBUFFER, attachment,
58+
GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, &objectName);
59+
60+
fprintf(stderr, "\t0x%X: type=%d, name=%d\n", attachment,
61+
objectType, objectName);
62+
63+
if (objectType == GL_TEXTURE) {
64+
GLint width, height, internalFormat;
65+
glBindTexture(GL_TEXTURE_2D, objectName);
66+
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_WIDTH,
67+
&width);
68+
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0, GL_TEXTURE_HEIGHT,
69+
&height);
70+
glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
71+
GL_TEXTURE_INTERNAL_FORMAT,
72+
&internalFormat);
73+
fprintf(stderr, "\t\tTexture: %dx%d, format=0x%X\n", width,
74+
height, internalFormat);
75+
}
76+
}
77+
}
78+
79+
assert(!"OpenGL GL_FRAMEBUFFER status != GL_FRAMEBUFFER_COMPLETE");
80+
}
81+
82+
#endif // ifdef XEMU_DEBUG_BUILD

hw/xbox/nv2a/debug_gl.h

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,30 @@
1+
/*
2+
* Geforce NV2A PGRAPH OpenGL Renderer debug routines
3+
*
4+
* Copyright (c) 2025 Matt Borgerson
5+
*
6+
* This library is free software; you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public
8+
* License as published by the Free Software Foundation; either
9+
* version 2 of the License, or (at your option) any later version.
10+
*
11+
* This library is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14+
* Lesser General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Lesser General Public
17+
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
120
#ifndef XEMU_HW_XBOX_NV2A_DEBUG_GL_H_
221
#define XEMU_HW_XBOX_NV2A_DEBUG_GL_H_
322

423
#ifdef XEMU_DEBUG_BUILD
524

6-
#define ASSERT_NO_GL_ERROR() \
25+
#include <epoxy/gl.h>
26+
27+
#define ASSERT_NO_GL_ERROR() \
728
do { \
829
GLenum error = glGetError(); \
930
if (error != GL_NO_ERROR) { \
@@ -13,18 +34,15 @@
1334
} \
1435
} while (0)
1536

16-
#define ASSERT_FRAMEBUFFER_COMPLETE() \
17-
do { \
18-
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER); \
19-
if (status != GL_FRAMEBUFFER_COMPLETE) { \
20-
fprintf(stderr, \
21-
"OpenGL framebuffer status: 0x%X (%d) != " \
22-
"GL_FRAMEBUFFER_COMPLETE at %s:%d\n", \
23-
status, status, __FILE__, __LINE__); \
24-
assert( \
25-
!"OpenGL GL_FRAMEBUFFER status != GL_FRAMEBUFFER_COMPLETE"); \
26-
} \
27-
} while (0)
37+
#if defined(__clang__) && defined(__FILE_NAME__)
38+
#define ASSERT_FRAMEBUFFER_COMPLETE() \
39+
gl_debug_assert_framebuffer_complete(__FILE_NAME__, __LINE__)
40+
#else
41+
#define ASSERT_FRAMEBUFFER_COMPLETE() \
42+
gl_debug_assert_framebuffer_complete(__FILE__, __LINE__)
43+
#endif
44+
45+
void gl_debug_assert_framebuffer_complete(const char *source_file, int line);
2846

2947
#else
3048

hw/xbox/nv2a/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
specific_ss.add(files(
2+
'debug.c',
23
'nv2a.c',
34
'pbus.c',
45
'pcrtc.c',

0 commit comments

Comments
 (0)