diff --git a/hw/xbox/Makefile.objs b/hw/xbox/Makefile.objs
index 84f900713e..636660cd1c 100644
--- a/hw/xbox/Makefile.objs
+++ b/hw/xbox/Makefile.objs
@@ -2,7 +2,7 @@ obj-y += xbox.o chihiro.o
obj-y += xbox_pci.o acpi_xbox.o
obj-y += amd_smbus.o smbus_xbox_smc.o smbus_cx25871.o smbus_adm1032.o
obj-y += nvnet.o
-obj-y += nv2a.o nv2a_vsh.o nv2a_psh.o nv2a_shaders.o
+obj-y += nv2a.o nv2a_vsh.o nv2a_psh.o nv2a_shaders.o nv2a_debug.o
obj-y += swizzle.o g-lru-cache.o
obj-y += mcpx_apu.o mcpx_aci.o
obj-y += lpc47m157.o
diff --git a/hw/xbox/nv2a.c b/hw/xbox/nv2a.c
index 8e2d5432e8..a9c552ff5d 100644
--- a/hw/xbox/nv2a.c
+++ b/hw/xbox/nv2a.c
@@ -34,87 +34,10 @@
#include "hw/xbox/swizzle.h"
#include "hw/xbox/u_format_r11g11b10f.h"
#include "hw/xbox/nv2a_shaders.h"
+#include "hw/xbox/nv2a_debug.h"
#include "hw/xbox/nv2a.h"
-// #define DEBUG_NV2A
-#ifdef DEBUG_NV2A
-# define NV2A_DPRINTF(format, ...) printf("nv2a: " format, ## __VA_ARGS__)
-#else
-# define NV2A_DPRINTF(format, ...) do { } while (0)
-#endif
-
-// #define DEBUG_NV2A_GL
-#ifdef DEBUG_NV2A_GL
-
-static void gl_debug_message(bool cc, const char *fmt, ...)
-{
- size_t n;
- char buffer[1024];
- va_list ap;
- va_start(ap, fmt);
- n = vsnprintf(buffer, sizeof(buffer), fmt, ap);
- assert(n <= sizeof(buffer));
- va_end(ap);
- 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);
- }
-}
-
-static void gl_debug_group_begin(const char *fmt, ...)
-{
- size_t n;
- char buffer[1024];
- va_list ap;
- va_start(ap, fmt);
- n = vsnprintf(buffer, sizeof(buffer), fmt, ap);
- assert(n <= sizeof(buffer));
- va_end(ap);
-
- /* Check for errors before entering group */
- assert(glGetError() == GL_NO_ERROR);
- glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, n, buffer);
-}
-
-static void gl_debug_group_end(void)
-{
- /* Check for errors when leaving group */
- assert(glGetError() == GL_NO_ERROR);
- glPopDebugGroup();
-}
-
-static void gl_debug_label(GLenum target, GLuint name, const char *fmt, ...)
-{
- size_t n;
- char buffer[1024];
- va_list ap;
- va_start(ap, fmt);
- n = vsnprintf(buffer, sizeof(buffer), fmt, ap);
- assert(n <= sizeof(buffer));
- va_end(ap);
-
- glObjectLabel(target, name, n, buffer);
-}
-
-# define NV2A_GL_DPRINTF(cc, format, ...) \
- gl_debug_message(cc, "nv2a: " format, ## __VA_ARGS__)
-# define NV2A_GL_DGROUP_BEGIN(format, ...) \
- gl_debug_group_begin("nv2a: " format, ## __VA_ARGS__)
-# define NV2A_GL_DGROUP_END() \
- gl_debug_group_end()
-# define NV2A_GL_DLABEL(target, name, format, ...) \
- gl_debug_label(target, name, "nv2a: { " format " }", ## __VA_ARGS__)
-
-#else
-# define NV2A_GL_DPRINTF(cc, format, ...) do { } while (0)
-# 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)
-#endif
-
#define USE_TEXTURE_CACHE
#define NV_NUM_BLOCKS 21
diff --git a/hw/xbox/nv2a.h b/hw/xbox/nv2a.h
index 281e4cbbad..24b665aad7 100644
--- a/hw/xbox/nv2a.h
+++ b/hw/xbox/nv2a.h
@@ -22,4 +22,4 @@
void nv2a_init(PCIBus *bus, int devfn, MemoryRegion *ram);
-#endif
\ No newline at end of file
+#endif
diff --git a/hw/xbox/nv2a_debug.c b/hw/xbox/nv2a_debug.c
new file mode 100644
index 0000000000..63f107644d
--- /dev/null
+++ b/hw/xbox/nv2a_debug.c
@@ -0,0 +1,81 @@
+/*
+ * QEMU Geforce NV2A debug helpers
+ *
+ * Copyright (c) 2015 Jannik Vogel
+ * Copyright (c) 2012 espes
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 or
+ * (at your option) version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see .
+ */
+
+#include "hw/xbox/nv2a_debug.h"
+
+#ifdef DEBUG_NV2A_GL
+
+#include
+#include
+#include
+
+void gl_debug_message(bool cc, const char *fmt, ...)
+{
+ size_t n;
+ char buffer[1024];
+ va_list ap;
+ va_start(ap, fmt);
+ n = vsnprintf(buffer, sizeof(buffer), fmt, ap);
+ assert(n <= sizeof(buffer));
+ va_end(ap);
+ 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);
+ }
+}
+
+void gl_debug_group_begin(const char *fmt, ...)
+{
+ size_t n;
+ char buffer[1024];
+ va_list ap;
+ va_start(ap, fmt);
+ n = vsnprintf(buffer, sizeof(buffer), fmt, ap);
+ assert(n <= sizeof(buffer));
+ va_end(ap);
+
+ /* Check for errors before entering group */
+ assert(glGetError() == GL_NO_ERROR);
+ glPushDebugGroup(GL_DEBUG_SOURCE_APPLICATION, 0, n, buffer);
+}
+
+void gl_debug_group_end(void)
+{
+ /* Check for errors when leaving group */
+ assert(glGetError() == GL_NO_ERROR);
+ glPopDebugGroup();
+}
+
+void gl_debug_label(GLenum target, GLuint name, const char *fmt, ...)
+{
+ size_t n;
+ char buffer[1024];
+ va_list ap;
+ va_start(ap, fmt);
+ n = vsnprintf(buffer, sizeof(buffer), fmt, ap);
+ assert(n <= sizeof(buffer));
+ va_end(ap);
+
+ glObjectLabel(target, name, n, buffer);
+}
+
+#endif
diff --git a/hw/xbox/nv2a_debug.h b/hw/xbox/nv2a_debug.h
new file mode 100644
index 0000000000..2ec727845b
--- /dev/null
+++ b/hw/xbox/nv2a_debug.h
@@ -0,0 +1,58 @@
+/*
+ * QEMU Geforce NV2A debug helpers
+ *
+ * Copyright (c) 2015 Jannik Vogel
+ * Copyright (c) 2012 espes
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 or
+ * (at your option) version 3 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see .
+ */
+
+#ifndef HW_NV2A_DEBUG_H
+#define HW_NV2A_DEBUG_H
+
+// #define DEBUG_NV2A
+#ifdef DEBUG_NV2A
+# define NV2A_DPRINTF(format, ...) printf("nv2a: " format, ## __VA_ARGS__)
+#else
+# define NV2A_DPRINTF(format, ...) do { } while (0)
+#endif
+
+// #define DEBUG_NV2A_GL
+#ifdef DEBUG_NV2A_GL
+
+#include
+#include "gl/gloffscreen.h"
+
+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, ...);
+
+# define NV2A_GL_DPRINTF(cc, format, ...) \
+ gl_debug_message(cc, "nv2a: " format, ## __VA_ARGS__)
+# define NV2A_GL_DGROUP_BEGIN(format, ...) \
+ gl_debug_group_begin("nv2a: " format, ## __VA_ARGS__)
+# define NV2A_GL_DGROUP_END() \
+ gl_debug_group_end()
+# define NV2A_GL_DLABEL(target, name, format, ...) \
+ gl_debug_label(target, name, "nv2a: { " format " }", ## __VA_ARGS__)
+
+#else
+# define NV2A_GL_DPRINTF(cc, format, ...) do { } while (0)
+# 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)
+#endif
+
+#endif
diff --git a/hw/xbox/nv2a_shaders.c b/hw/xbox/nv2a_shaders.c
index 3b08e8eabd..95780dd560 100644
--- a/hw/xbox/nv2a_shaders.c
+++ b/hw/xbox/nv2a_shaders.c
@@ -19,16 +19,10 @@
*/
#include "qemu-common.h"
+#include "hw/xbox/nv2a_debug.h"
#include "hw/xbox/nv2a_shaders_common.h"
#include "hw/xbox/nv2a_shaders.h"
-// #define NV2A_DEBUG
-#ifdef NV2A_DEBUG
-# define NV2A_DPRINTF(format, ...) printf("nv2a: " format, ## __VA_ARGS__)
-#else
-# define NV2A_DPRINTF(format, ...) do { } while (0)
-#endif
-
static void generate_geometry_shader_pass_vertex(QString* s, const char* v)
{
qstring_append_fmt(s, " gl_Position = gl_in[%s].gl_Position;\n", v);