Skip to content

Commit

Permalink
viewers: Add 3DFX viewer
Browse files Browse the repository at this point in the history
Add a viewer for 3DFX state. This shows all triangles and textures involved in
the most recent frame, and allows showing of framebuffer, depth buffer, and
wireframes.

It currently does not work properly in SLI configurations (only the first card
will be viewed) and trilinear textures will not display correctly.
  • Loading branch information
sarah-walker-pcem committed Nov 21, 2024
1 parent 7efe8fb commit cff2731
Show file tree
Hide file tree
Showing 12 changed files with 1,190 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ find_package(OpenAL REQUIRED)
include_directories(${OPENAL_INCLUDE_DIR})

if(${PCEM_DISPLAY_ENGINE} STREQUAL "wxWidgets")
find_package(wxWidgets REQUIRED COMPONENTS core base xrc)
find_package(wxWidgets REQUIRED COMPONENTS core base xrc adv)
include(${wxWidgets_USE_FILE})
set(DISPLAY_ENGINE_LIBRARIES ${wxWidgets_LIBRARIES})
endif()
Expand Down
3 changes: 3 additions & 0 deletions includes/private/video/vid_voodoo_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ typedef struct voodoo_t {
unsigned int vertex_next_age;
int num_verticies;
int cull_pingpong;
int in_strip;

int flush;

Expand Down Expand Up @@ -463,6 +464,8 @@ typedef struct voodoo_t {
uint8_t *vram, *changedvram;

void *p;

int viewer_active;
} voodoo_t;

typedef struct voodoo_set_t {
Expand Down
12 changes: 12 additions & 0 deletions includes/private/wx-ui/viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ void viewer_add(char *title, viewer_t *viewer, void *p);
void viewer_open(void *hwnd, int id);
void viewer_remove(void *viewer);
void viewer_update(viewer_t *viewer, void *p);
void viewer_call(viewer_t *viewer, void *p, void (*func)(void *v, void *param), void *param);
void viewer_close_all();
void viewer_notify_pause();
void viewer_notify_resume();
void update_viewers_menu(void *menu);

extern viewer_t viewer_font;
extern viewer_t viewer_palette;
extern viewer_t viewer_palette_16;
extern viewer_t viewer_voodoo;
extern viewer_t viewer_vram;

#define IDM_VIEWER 1600
Expand All @@ -45,6 +49,14 @@ class Viewer: public wxFrame
virtual ~Viewer()
{
}

virtual void NotifyPause()
{
}

virtual void NotifyResume()
{
}
};

#endif
Expand Down
18 changes: 18 additions & 0 deletions includes/private/wx-ui/viewer_voodoo.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef _VIEWER_VOODOO_H_
#define _VIEWER_VOODOO_H_

#ifdef __cplusplus
extern "C" {
#endif

void voodoo_viewer_swap_buffer(void *v, void *param);
void voodoo_viewer_queue_triangle(void *v, void *param);
void voodoo_viewer_begin_strip(void *v, void *param);
void voodoo_viewer_end_strip(void *v, void *param);
void voodoo_viewer_use_texture(void *v, void *param);

#ifdef __cplusplus
}
#endif

#endif
5 changes: 5 additions & 0 deletions src/video/vid_voodoo.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "vid_voodoo_regs.h"
#include "vid_voodoo_render.h"
#include "vid_voodoo_texture.h"
#include "viewer.h"

rgba8_t rgb332[0x100], ai44[0x100], rgb565[0x10000], argb1555[0x10000], argb4444[0x10000], ai88[0x10000];

Expand Down Expand Up @@ -1156,6 +1157,8 @@ void *voodoo_2d3d_card_init(int type) {
voodoo->disp_buffer = 0;
voodoo->draw_buffer = 1;

viewer_add("3DFX Voodoo render", &viewer_voodoo, voodoo);

return voodoo;
}

Expand Down Expand Up @@ -1209,6 +1212,8 @@ void *voodoo_init() {
mem_mapping_add(&voodoo_set->snoop_mapping, 0, 0, NULL, voodoo_snoop_readw, voodoo_snoop_readl, NULL, voodoo_snoop_writew,
voodoo_snoop_writel, NULL, MEM_MAPPING_EXTERNAL, voodoo_set);

viewer_add("3DFX Voodoo render", &viewer_voodoo, voodoo_set->voodoos[0]);

return voodoo_set;
}

Expand Down
19 changes: 19 additions & 0 deletions src/video/vid_voodoo_reg.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include "vid_voodoo_render.h"
#include "vid_voodoo_setup.h"
#include "vid_voodoo_texture.h"
#include "viewer.h"
#include "viewer_voodoo.h"

enum { CHIP_FBI = 0x1, CHIP_TREX0 = 0x2, CHIP_TREX1 = 0x4, CHIP_TREX2 = 0x8 };

Expand All @@ -43,6 +45,8 @@ void voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) {
// pclog("swapbufferCMD %08x %08x\n", val, voodoo->leftOverlayBuf);

voodoo_wait_for_render_thread_idle(voodoo);
if (voodoo->viewer_active)
viewer_call(&viewer_voodoo, voodoo, voodoo_viewer_swap_buffer, NULL);
if (!(val & 1)) {
banshee_set_overlay_addr(voodoo->p, voodoo->leftOverlayBuf);
thread_lock_mutex(voodoo->swap_mutex);
Expand Down Expand Up @@ -82,6 +86,8 @@ void voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) {
// pclog("Swap buffer %08x %d %p %i\n", val, voodoo->swap_count, &voodoo->swap_count, (voodoo ==
// voodoo->set->voodoos[1]) ? 1 : 0); voodoo->front_offset = params->front_offset;
voodoo_wait_for_render_thread_idle(voodoo);
if (voodoo->viewer_active)
viewer_call(&viewer_voodoo, voodoo, voodoo_viewer_swap_buffer, NULL);
if (!(val & 1)) {
memset(voodoo->dirty_line, 1, sizeof(voodoo->dirty_line));
voodoo->front_offset = voodoo->params.front_offset;
Expand Down Expand Up @@ -265,6 +271,11 @@ void voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) {

case SST_triangleCMD:
case SST_remap_triangleCMD:
if (voodoo->in_strip) {
voodoo->in_strip = 0;
if (voodoo->viewer_active)
viewer_call(&viewer_voodoo, voodoo, voodoo_viewer_end_strip, NULL);
}
voodoo->params.sign = val & (1 << 31);

if (voodoo->ncc_dirty[0])
Expand Down Expand Up @@ -466,6 +477,11 @@ void voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) {
break;

case SST_ftriangleCMD:
if (voodoo->in_strip) {
voodoo->in_strip = 0;
if (voodoo->viewer_active)
viewer_call(&viewer_voodoo, voodoo, voodoo_viewer_end_strip, NULL);
}
voodoo->params.sign = val & (1 << 31);

if (voodoo->ncc_dirty[0])
Expand Down Expand Up @@ -745,6 +761,9 @@ void voodoo_reg_writel(uint32_t addr, uint32_t val, void *p) {

voodoo->num_verticies = 1;
voodoo->cull_pingpong = 0;
if (voodoo->viewer_active)
viewer_call(&viewer_voodoo, voodoo, voodoo_viewer_begin_strip, NULL);
voodoo->in_strip = 1;
break;
case SST_sDrawTriCMD:
// pclog("sDrawTriCMD %i %i\n", voodoo->num_verticies, voodoo->sSetupMode & SETUPMODE_STRIP_MODE);
Expand Down
5 changes: 5 additions & 0 deletions src/video/vid_voodoo_render.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "vid_voodoo_regs.h"
#include "vid_voodoo_render.h"
#include "vid_voodoo_texture.h"
#include "viewer.h"
#include "viewer_voodoo.h"

typedef struct voodoo_state_t {
int xstart, xend, xdir;
Expand Down Expand Up @@ -1504,6 +1506,9 @@ void voodoo_queue_triangle(voodoo_t *voodoo, voodoo_params_t *params) {
if (voodoo->dual_tmus)
voodoo_use_texture(voodoo, params, 1);

if (voodoo->viewer_active)
viewer_call(&viewer_voodoo, voodoo, voodoo_viewer_queue_triangle, NULL);

memcpy(params_new, params, sizeof(voodoo_params_t));

voodoo->params_write_idx++;
Expand Down
8 changes: 8 additions & 0 deletions src/video/vid_voodoo_texture.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include "vid_voodoo_regs.h"
#include "vid_voodoo_render.h"
#include "vid_voodoo_texture.h"
#include "viewer.h"
#include "viewer_voodoo.h"

void voodoo_recalc_tex(voodoo_t *voodoo, int tmu) {
int aspect = (voodoo->params.tLOD[tmu] >> 21) & 3;
Expand Down Expand Up @@ -133,13 +135,16 @@ void voodoo_use_texture(voodoo_t *voodoo, voodoo_params_t *params, int tmu) {
else
addr = params->texBaseAddr[tmu];


/*Try to find texture in cache*/
for (c = 0; c < TEX_CACHE_MAX; c++) {
if (voodoo->texture_cache[tmu][c].base == addr &&
voodoo->texture_cache[tmu][c].tLOD == (params->tLOD[tmu] & 0xf00fff) &&
voodoo->texture_cache[tmu][c].palette_checksum == palette_checksum) {
params->tex_entry[tmu] = c;
voodoo->texture_cache[tmu][c].refcount++;
if (voodoo->viewer_active)
viewer_call(&viewer_voodoo, voodoo, voodoo_viewer_use_texture, (void *)(uintptr_t)tmu);
return;
}
}
Expand Down Expand Up @@ -428,6 +433,9 @@ void voodoo_use_texture(voodoo_t *voodoo, voodoo_params_t *params, int tmu) {

params->tex_entry[tmu] = c;
voodoo->texture_cache[tmu][c].refcount++;

if (voodoo->viewer_active)
viewer_call(&viewer_voodoo, voodoo, voodoo_viewer_use_texture, (void *)(uintptr_t)tmu);
}

void flush_texture_cache(voodoo_t *voodoo, uint32_t dirty_addr, int tmu) {
Expand Down
29 changes: 28 additions & 1 deletion src/wx-ui/viewers/viewer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void viewer_add(char *title, viewer_t *viewer, void *p)

void viewer_open(void *parent, int id)
{
Viewer *i = (Viewer *)viewer_routs[id].viewer->open(parent, viewer_routs[0].p, viewer_routs[id].title.c_str());
Viewer *i = (Viewer *)viewer_routs[id].viewer->open(parent, viewer_routs[id].p, viewer_routs[id].title.c_str());
if (i)
viewer_windows.push_back(i);
}
Expand All @@ -71,6 +71,33 @@ void viewer_update(viewer_t *viewer, void *p)
}
}

void viewer_notify_pause()
{
for (std::list<Viewer *>::iterator it = viewer_windows.begin(); it != viewer_windows.end(); it++)
{
(*it)->NotifyPause();
}
}

void viewer_notify_resume()
{
for (std::list<Viewer *>::iterator it = viewer_windows.begin(); it != viewer_windows.end(); it++)
{
(*it)->NotifyResume();
}
}

void viewer_call(viewer_t *viewer, void *p, void (*func)(void *v, void *param), void *param)
{
for (std::list<Viewer *>::iterator it = viewer_windows.begin(); it != viewer_windows.end(); it++)
{
if ((*it)->p == p)
{
func(*it, param);
}
}
}

void update_viewers_menu(void *menu)
{
wxMenuItem *m = ((wxMenu *)menu)->FindItem(XRCID("IDM_VIEW"));
Expand Down
Loading

0 comments on commit cff2731

Please sign in to comment.