Skip to content

Commit

Permalink
nv2a: Add Vulkan renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
mborgerson committed Dec 31, 2024
1 parent e639e0c commit a538580
Show file tree
Hide file tree
Showing 114 changed files with 23,344 additions and 10,297 deletions.
4 changes: 2 additions & 2 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ IndentWidth: 4
AccessModifierOffset: -4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: '.*_BEGIN$' # only PREC_BEGIN ?
MacroBlockEnd: '.*_END$'
#MacroBlockBegin: '.*_BEGIN$' # only PREC_BEGIN ?
#MacroBlockEnd: '.*_END$'
MaxEmptyLinesToKeep: 2
#PenaltyBreakBeforeFirstCallParameter: 19
#PenaltyBreakComment: 300
Expand Down
13 changes: 11 additions & 2 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,18 @@
[submodule "tomlplusplus"]
path = tomlplusplus
url = https://github.com/marzer/tomlplusplus
[submodule "hw/xbox/nv2a/thirdparty/nv2a_vsh_cpu"]
path = hw/xbox/nv2a/thirdparty/nv2a_vsh_cpu
[submodule "hw/xbox/nv2a/pgraph/thirdparty/nv2a_vsh_cpu"]
path = hw/xbox/nv2a/pgraph/thirdparty/nv2a_vsh_cpu
url = https://github.com/abaire/nv2a_vsh_cpu.git
[submodule "ui/thirdparty/httplib"]
path = ui/thirdparty/httplib
url = https://github.com/yhirose/cpp-httplib
[submodule "hw/xbox/nv2a/pgraph/vk/thirdparty/VulkanMemoryAllocator"]
path = thirdparty/VulkanMemoryAllocator
url = https://github.com/GPUOpen-LibrariesAndSDKs/VulkanMemoryAllocator
[submodule "thirdparty/volk"]
path = thirdparty/volk
url = https://github.com/zeux/volk
[submodule "thirdparty/SPIRV-Reflect"]
path = thirdparty/SPIRV-Reflect
url = https://github.com/KhronosGroup/SPIRV-Reflect
6 changes: 6 additions & 0 deletions config_spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ input:
default: 18 # w

display:
renderer:
type: enum
values: ["NULL", OPENGL, VULKAN]
default: OPENGL
vulkan:
validation_layers: bool
quality:
surface_scale:
type: integer
Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ else
git_submodules_action="ignore"
fi

git_submodules="ui/keycodemapdb ui/thirdparty/imgui ui/thirdparty/implot ui/thirdparty/httplib util/xxHash tomlplusplus genconfig hw/xbox/nv2a/thirdparty/nv2a_vsh_cpu"
git_submodules="ui/keycodemapdb ui/thirdparty/imgui ui/thirdparty/implot ui/thirdparty/httplib util/xxHash tomlplusplus genconfig hw/xbox/nv2a/pgraph/thirdparty/nv2a_vsh_cpu thirdparty/volk thirdparty/VulkanMemoryAllocator thirdparty/SPIRV-Reflect"
git="git"

# Don't accept a target_list environment variable.
Expand Down
3 changes: 3 additions & 0 deletions debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ Build-Depends: debhelper (>= 11),
libssl-dev,
libpcap-dev,
libslirp-dev,
glslang-dev,
libvulkan-dev,

Standards-Version: 3.9.8
Homepage: https://xemu.app
XS-Debian-Vcs-Browser: https://github.com/mborgerson/xemu
Expand Down
98 changes: 45 additions & 53 deletions hw/xbox/nv2a/debug.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/*
* QEMU Geforce NV2A debug helpers
* QEMU Geforce NV2A profiling and debug helpers
*
* Copyright (c) 2015 Jannik Vogel
* Copyright (c) 2012 espes
* Copyright (c) 2015 Jannik Vogel
* Copyright (c) 2018-2023 Matt Borgerson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
Expand All @@ -18,8 +19,8 @@
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#ifndef HW_NV2A_DEBUG_H
#define HW_NV2A_DEBUG_H
#ifndef HW_XBOX_NV2A_DEBUG_H
#define HW_XBOX_NV2A_DEBUG_H

#include <stdint.h>

Expand All @@ -36,54 +37,6 @@
# define NV2A_DPRINTF(format, ...) do { } while (0)
#endif

// #define DEBUG_NV2A_GL
#ifdef DEBUG_NV2A_GL

#include <stdbool.h>
#include "gl/gloffscreen.h"
#include "config-host.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__)
# 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__)
#define NV2A_GL_DFRAME_TERMINATOR() \
gl_debug_frame_terminator()

#ifdef __cplusplus
extern "C" {
#endif

#ifdef CONFIG_RENDERDOC
bool nv2a_dbg_renderdoc_available(void);
void nv2a_dbg_renderdoc_capture_frames(uint32_t num_frames);
#endif

#ifdef __cplusplus
}
#endif

#else
# define NV2A_GL_DPRINTF(cc, format, ...) do { \
if (cc) NV2A_DPRINTF(format "\n", ##__VA_ARGS__ ); \
} 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)
# define NV2A_GL_DFRAME_TERMINATOR() do { } while (0)
#endif

/* Debug prints to identify when unimplemented or unconfirmed features
* are being exercised. These cases likely result in graphical problems of
* varying degree, but should otherwise not crash the system. Enable this
Expand Down Expand Up @@ -111,6 +64,22 @@ void nv2a_dbg_renderdoc_capture_frames(uint32_t num_frames);
#endif

#define NV2A_PROF_COUNTERS_XMAC \
_X(NV2A_PROF_FINISH_VERTEX_BUFFER_DIRTY) \
_X(NV2A_PROF_FINISH_SURFACE_CREATE) \
_X(NV2A_PROF_FINISH_SURFACE_DOWN) \
_X(NV2A_PROF_FINISH_NEED_BUFFER_SPACE) \
_X(NV2A_PROF_FINISH_FRAMEBUFFER_DIRTY) \
_X(NV2A_PROF_FINISH_PRESENTING) \
_X(NV2A_PROF_FINISH_FLIP_STALL) \
_X(NV2A_PROF_FINISH_FLUSH) \
_X(NV2A_PROF_CLEAR) \
_X(NV2A_PROF_QUEUE_SUBMIT) \
_X(NV2A_PROF_QUEUE_SUBMIT_AUX) \
_X(NV2A_PROF_PIPELINE_NOTDIRTY) \
_X(NV2A_PROF_PIPELINE_GEN) \
_X(NV2A_PROF_PIPELINE_BIND) \
_X(NV2A_PROF_PIPELINE_MERGE) \
_X(NV2A_PROF_PIPELINE_RENDERPASSES) \
_X(NV2A_PROF_BEGIN_ENDS) \
_X(NV2A_PROF_DRAW_ARRAYS) \
_X(NV2A_PROF_INLINE_BUFFERS) \
Expand All @@ -120,18 +89,26 @@ void nv2a_dbg_renderdoc_capture_frames(uint32_t num_frames);
_X(NV2A_PROF_SHADER_GEN) \
_X(NV2A_PROF_SHADER_BIND) \
_X(NV2A_PROF_SHADER_BIND_NOTDIRTY) \
_X(NV2A_PROF_SHADER_UBO_DIRTY) \
_X(NV2A_PROF_SHADER_UBO_NOTDIRTY) \
_X(NV2A_PROF_ATTR_BIND) \
_X(NV2A_PROF_TEX_UPLOAD) \
_X(NV2A_PROF_TEX_BIND) \
_X(NV2A_PROF_GEOM_BUFFER_UPDATE_1) \
_X(NV2A_PROF_GEOM_BUFFER_UPDATE_2) \
_X(NV2A_PROF_GEOM_BUFFER_UPDATE_3) \
_X(NV2A_PROF_GEOM_BUFFER_UPDATE_4) \
_X(NV2A_PROF_GEOM_BUFFER_UPDATE_4_NOTDIRTY) \
_X(NV2A_PROF_SURF_SWIZZLE) \
_X(NV2A_PROF_SURF_CREATE) \
_X(NV2A_PROF_SURF_DOWNLOAD) \
_X(NV2A_PROF_SURF_UPLOAD) \
_X(NV2A_PROF_SURF_TO_TEX) \
_X(NV2A_PROF_SURF_TO_TEX_FALLBACK) \
_X(NV2A_PROF_QUEUE_SUBMIT_1) \
_X(NV2A_PROF_QUEUE_SUBMIT_2) \
_X(NV2A_PROF_QUEUE_SUBMIT_3) \
_X(NV2A_PROF_QUEUE_SUBMIT_4) \
_X(NV2A_PROF_QUEUE_SUBMIT_5) \

enum NV2A_PROF_COUNTERS_ENUM {
#define _X(x) x,
Expand Down Expand Up @@ -161,6 +138,21 @@ extern NV2AStats g_nv2a_stats;

const char *nv2a_profile_get_counter_name(unsigned int cnt);
int nv2a_profile_get_counter_value(unsigned int cnt);
void nv2a_profile_increment(void);
void nv2a_profile_flip_stall(void);

static inline void nv2a_profile_inc_counter(enum NV2A_PROF_COUNTERS_ENUM cnt)
{
g_nv2a_stats.frame_working.counters[cnt] += 1;
}

#ifdef CONFIG_RENDERDOC
void nv2a_dbg_renderdoc_init(void);
void *nv2a_dbg_renderdoc_get_api(void);
bool nv2a_dbg_renderdoc_available(void);
void nv2a_dbg_renderdoc_capture_frames(int num_frames);
extern int renderdoc_capture_frames;
#endif

#ifdef __cplusplus
}
Expand Down
6 changes: 0 additions & 6 deletions hw/xbox/nv2a/gl/meson.build

This file was deleted.

12 changes: 1 addition & 11 deletions hw/xbox/nv2a/meson.build
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
specific_ss.add(files(
'nv2a.c',
'debug.c',
'pbus.c',
'pcrtc.c',
'pfb.c',
'pfifo.c',
'pgraph.c',
'pmc.c',
'pramdac.c',
'prmcio.c',
'prmdio.c',
'prmvio.c',
'psh.c',
'ptimer.c',
'pvideo.c',
'shaders.c',
'stubs.c',
'user.c',
'vsh.c',
'swizzle.c',
's3tc.c',
))
subdir('gl')

subdir('thirdparty')
specific_ss.add(nv2a_vsh_cpu)
subdir('pgraph')
28 changes: 18 additions & 10 deletions hw/xbox/nv2a/nv2a.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ static void nv2a_get_offsets(VGACommonState *s,
*pline_compare = line_compare;
}

const uint8_t *nv2a_get_dac_palette(void)
{
return g_nv2a->puserdac.palette;
}

int nv2a_get_screen_off(void)
{
return g_nv2a->vga.sr[VGA_SEQ_CLOCK_MODE] & VGA_SR01_SCREEN_OFF;
}

static void nv2a_vga_gfx_update(void *opaque)
{
VGACommonState *vga = opaque;
Expand Down Expand Up @@ -277,7 +287,7 @@ static void nv2a_reset(NV2AState *d)
}

memset(d->pfifo.regs, 0, sizeof(d->pfifo.regs));
memset(d->pgraph.regs, 0, sizeof(d->pgraph.regs));
memset(d->pgraph.regs_, 0, sizeof(d->pgraph.regs_));
memset(d->pvideo.regs, 0, sizeof(d->pvideo.regs));

d->pcrtc.start = 0;
Expand Down Expand Up @@ -365,11 +375,10 @@ static void nv2a_vm_state_change(void *opaque, bool running, RunState state)
if (state == RUN_STATE_SAVE_VM) {
nv2a_lock_fifo(d);
qatomic_set(&d->pfifo.halt, true);
qatomic_set(&d->pgraph.download_dirty_surfaces_pending, true);
qemu_event_reset(&d->pgraph.dirty_surfaces_download_complete);
d->pgraph.renderer->ops.pre_savevm_trigger(d);
nv2a_unlock_fifo(d);
qemu_mutex_unlock_iothread();
qemu_event_wait(&d->pgraph.dirty_surfaces_download_complete);
d->pgraph.renderer->ops.pre_savevm_wait(d);
qemu_mutex_lock_iothread();
nv2a_lock_fifo(d);
} else if (state == RUN_STATE_RESTORE_VM) {
Expand All @@ -382,11 +391,10 @@ static void nv2a_vm_state_change(void *opaque, bool running, RunState state)
nv2a_unlock_fifo(d);
} else if (state == RUN_STATE_SHUTDOWN) {
nv2a_lock_fifo(d);
qatomic_set(&d->pgraph.shader_cache_writeback_pending, true);
qemu_event_reset(&d->pgraph.shader_cache_writeback_complete);
d->pgraph.renderer->ops.pre_shutdown_trigger(d);
nv2a_unlock_fifo(d);
qemu_mutex_unlock_iothread();
qemu_event_wait(&d->pgraph.shader_cache_writeback_complete);
d->pgraph.renderer->ops.pre_shutdown_wait(d);
qemu_mutex_lock_iothread();
}
}
Expand Down Expand Up @@ -515,9 +523,9 @@ static const VMStateDescription vmstate_nv2a = {
VMSTATE_UINT32(pgraph.inline_buffer_length, NV2AState), // fixme
VMSTATE_UINT32(pgraph.draw_arrays_length, NV2AState),
VMSTATE_UINT32(pgraph.draw_arrays_max_count, NV2AState),
VMSTATE_INT32_ARRAY(pgraph.gl_draw_arrays_start, NV2AState, 1250),
VMSTATE_INT32_ARRAY(pgraph.gl_draw_arrays_count, NV2AState, 1250),
VMSTATE_UINT32_ARRAY(pgraph.regs, NV2AState, 0x2000),
VMSTATE_INT32_ARRAY(pgraph.draw_arrays_start, NV2AState, 1250),
VMSTATE_INT32_ARRAY(pgraph.draw_arrays_count, NV2AState, 1250),
VMSTATE_UINT32_ARRAY(pgraph.regs_, NV2AState, 0x2000),
VMSTATE_UINT32(pmc.pending_interrupts, NV2AState),
VMSTATE_UINT32(pmc.enabled_interrupts, NV2AState),
VMSTATE_UINT32(pfifo.pending_interrupts, NV2AState),
Expand Down
2 changes: 1 addition & 1 deletion hw/xbox/nv2a/nv2a.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#define HW_NV2A_H

void nv2a_init(PCIBus *bus, int devfn, MemoryRegion *ram);
void nv2a_gl_context_init(void);
void nv2a_context_init(void);
int nv2a_get_framebuffer_surface(void);
void nv2a_set_surface_scale_factor(unsigned int scale);
unsigned int nv2a_get_surface_scale_factor(void);
Expand Down
Loading

0 comments on commit a538580

Please sign in to comment.