Skip to content

Commit

Permalink
Merge pull request #256 from ogamespec/master
Browse files Browse the repository at this point in the history
gfx fixes
  • Loading branch information
ogamespec authored Aug 7, 2023
2 parents 80c75d9 + 1c75be4 commit a0bc04c
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 88 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Requirements: CMake, pthread.

## Progress

![Ikaruga_0130](/imgstore/Ikaruga_0130.png)
![progress_ikaruga](/imgstore/progress_ikaruga.png)

## Credits

Expand Down
Binary file removed imgstore/Ikaruga_0130.png
Binary file not shown.
Binary file added imgstore/progress_ikaruga.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 32 additions & 16 deletions src/cp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,14 @@ namespace GX

switch(cmd)
{
case CPCommand::CP_CMD_NOP:
case CPCommand::CP_CMD_NOP | 0:
case CPCommand::CP_CMD_NOP | 1:
case CPCommand::CP_CMD_NOP | 2:
case CPCommand::CP_CMD_NOP | 3:
case CPCommand::CP_CMD_NOP | 4:
case CPCommand::CP_CMD_NOP | 5:
case CPCommand::CP_CMD_NOP | 6:
case CPCommand::CP_CMD_NOP | 7:
return true;

case CPCommand::CP_CMD_VCACHE_INVD | 0:
Expand Down Expand Up @@ -1929,12 +1936,21 @@ namespace GX

uint8_t cmd = gxfifo->Read8();

//DBReport2(DbgChannel::GP, "GxCommand: 0x%02X\n", cmd);
if (logOpcode) {
Report(Channel::GP, "GxCommand: 0x%02X\n", cmd);
}

switch(cmd)
{
// do nothing
case CP_CMD_NOP:
case CP_CMD_NOP | 0:
case CP_CMD_NOP | 1:
case CP_CMD_NOP | 2:
case CP_CMD_NOP | 3:
case CP_CMD_NOP | 4:
case CP_CMD_NOP | 5:
case CP_CMD_NOP | 6:
case CP_CMD_NOP | 7:
break;

case CP_CMD_VCACHE_INVD | 0:
Expand All @@ -1945,7 +1961,7 @@ namespace GX
case CP_CMD_VCACHE_INVD | 5:
case CP_CMD_VCACHE_INVD | 6:
case CP_CMD_VCACHE_INVD | 7:
//DBReport2(DbgChannel::GP, "Invalidate V$\n");
//Report(Channel::GP, "Invalidate V$\n");
break;

case CP_CMD_CALL_DL | 0:
Expand All @@ -1963,7 +1979,7 @@ namespace GX

if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_CALL_DL: addr: 0x%08X, size: %i\n", physAddress, size);
Report(Channel::GP, "CP_CMD_CALL_DL: addr: 0x%08X, size: %i\n", physAddress, size);
}

FifoProcessor* callDlFifo = new FifoProcessor(this, fifoPtr, size);
Expand Down Expand Up @@ -2048,7 +2064,7 @@ namespace GX
start = gxfifo->Read16();
len = (start >> 12) + 1;
start &= 0xfff;
Report(Channel::GP, "OP_CMD_LOAD_INDXA: idx: %i, start: %i, len: %i\n", idx, start, len);
Report(Channel::GP, "CP_CMD_LOAD_INDXA: idx: %i, start: %i, len: %i\n", idx, start, len);
break;
}

Expand All @@ -2066,7 +2082,7 @@ namespace GX
start = gxfifo->Read16();
len = (start >> 12) + 1;
start &= 0xfff;
Report(Channel::GP, "OP_CMD_LOAD_INDXB: idx: %i, start: %i, len: %i\n", idx, start, len);
Report(Channel::GP, "CP_CMD_LOAD_INDXB: idx: %i, start: %i, len: %i\n", idx, start, len);
break;
}

Expand All @@ -2084,7 +2100,7 @@ namespace GX
start = gxfifo->Read16();
len = (start >> 12) + 1;
start &= 0xfff;
Report(Channel::GP, "OP_CMD_LOAD_INDXC: idx: %i, start: %i, len: %i\n", idx, start, len);
Report(Channel::GP, "CP_CMD_LOAD_INDXC: idx: %i, start: %i, len: %i\n", idx, start, len);
break;
}

Expand All @@ -2102,7 +2118,7 @@ namespace GX
start = gxfifo->Read16();
len = (start >> 12) + 1;
start &= 0xfff;
Report(Channel::GP, "OP_CMD_LOAD_INDXD: idx: %i, start: %i, len: %i\n", idx, start, len);
Report(Channel::GP, "CP_CMD_LOAD_INDXD: idx: %i, start: %i, len: %i\n", idx, start, len);
break;
}

Expand All @@ -2125,7 +2141,7 @@ namespace GX
usevat = vatnum;
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_DRAW_QUAD: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
Report(Channel::GP, "CP_CMD_DRAW_QUAD: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
}
/*/
1---2 tri1: 0-1-2
Expand Down Expand Up @@ -2168,7 +2184,7 @@ namespace GX
usevat = vatnum;
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_DRAW_TRIANGLE: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
Report(Channel::GP, "CP_CMD_DRAW_TRIANGLE: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
}
/*/
1---2 tri: 0-1-2
Expand Down Expand Up @@ -2211,7 +2227,7 @@ namespace GX
usevat = vatnum;
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_DRAW_STRIP: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
Report(Channel::GP, "CP_CMD_DRAW_STRIP: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
}
/*/
1---3---5 tri1: 0-1-2
Expand Down Expand Up @@ -2269,7 +2285,7 @@ namespace GX
usevat = vatnum;
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_DRAW_FAN: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
Report(Channel::GP, "CP_CMD_DRAW_FAN: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
}
/*/
1---2---3 tri1: 0-1-2
Expand Down Expand Up @@ -2326,7 +2342,7 @@ namespace GX
usevat = vatnum;
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_DRAW_LINE: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
Report(Channel::GP, "CP_CMD_DRAW_LINE: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
}
/*/
1 3 5
Expand Down Expand Up @@ -2370,7 +2386,7 @@ namespace GX
usevat = vatnum;
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_DRAW_LINESTRIP: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
Report(Channel::GP, "CP_CMD_DRAW_LINESTRIP: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
}
/*/
1 3 5
Expand Down Expand Up @@ -2423,7 +2439,7 @@ namespace GX
usevat = vatnum;
if (logDrawCommands)
{
Report(Channel::GP, "OP_CMD_DRAW_POINT: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
Report(Channel::GP, "CP_CMD_DRAW_POINT: vtxnum: %i, vat: %i\n", vtxnum, vatnum);
}
/*/
0---0 tri: 0-0-0 (1x1x1 tri)
Expand Down
28 changes: 20 additions & 8 deletions src/gfx.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "pch.h"

using namespace Debug;

namespace GX
{
GXCore::GXCore()
Expand Down Expand Up @@ -102,21 +104,24 @@ namespace GX

bool GXCore::GL_OpenSubsystem()
{
if (backend_started)
return true;

hdcgl = GetDC(hwndMain);

if (hdcgl == NULL) return FALSE;
if (hdcgl == NULL) return false;

if (GL_SetPixelFormat(hdcgl) == 0)
{
ReleaseDC(hwndMain, hdcgl);
return FALSE;
return false;
}

hglrc = wglCreateContext(hdcgl);
if (hglrc == NULL)
{
ReleaseDC(hwndMain, hdcgl);
return FALSE;
return false;
}

wglMakeCurrent(hdcgl, hglrc);
Expand All @@ -143,15 +148,21 @@ namespace GX
// clear performance counters
frames = tris = pts = lines = 0;

backend_started = true;
return true;
}

void GXCore::GL_CloseSubsystem()
{
if (!backend_started)
return;

//if(frameReady) GL_EndFrame();

wglMakeCurrent(NULL, NULL);
wglDeleteContext(hglrc);

backend_started = false;
}

// init rendering (call before drawing FIFO primitives)
Expand All @@ -162,7 +173,7 @@ namespace GX
BeginPaint(hwndMain, &psFrame);
glDrawBuffer(GL_BACK);

if (set_clear == TRUE)
if (set_clear)
{
glClearColor(
(float)(cr / 255.0f),
Expand All @@ -173,7 +184,7 @@ namespace GX

glClearDepth((double)(clear_z / 16777215.0));

set_clear = FALSE;
set_clear = false;
}

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
Expand All @@ -183,7 +194,7 @@ namespace GX
// done rendering (call when frame is ready)
void GXCore::GL_EndFrame()
{
BOOL showPerf = FALSE;
bool showPerf = false;
if (!frameReady) return;

/*/
Expand All @@ -202,15 +213,16 @@ namespace GX
// do snapshot
if (make_shot)
{
make_shot = FALSE;
GL_DoSnapshot(FALSE, snap_file, NULL, snap_w, snap_h);
make_shot = false;
GL_DoSnapshot(false, snap_file, NULL, snap_w, snap_h);
}

glFinish();
SwapBuffers(hdcgl);
EndPaint(hwndMain, &psFrame);

frameReady = 0;
//Report(Channel::GP, "gfx frame: %d\n", frames);
frames++;
tris = pts = lines = 0;
state.cpLoads = state.bpLoads = state.xfLoads = 0;
Expand Down
10 changes: 6 additions & 4 deletions src/gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,20 @@ namespace GX

FifoProcessor * fifo = nullptr; // Internal CP FIFO

bool GpRegsLog = false;
bool gxOpened = false;
bool frame_done = true;
bool logDrawCommands = false;
bool disableDraw = false;

// logging
bool logOpcode = false;
bool logDrawCommands = false;
bool GpRegsLog = false;

size_t usevat; // current VAT
Vertex* vtx; // current vertex to collect data

HWND hwndMain;

uint32_t lastFifoSize;

uint8_t cr = 0, cg = 0, cb = 0, ca = 0;
uint32_t clear_z = -1;
bool set_clear = false;
Expand All @@ -103,6 +104,7 @@ namespace GX

PAINTSTRUCT psFrame{};
int frameReady = 0;
bool backend_started = false;

// optionable
uint32_t scr_w = 640, scr_h = 480;
Expand Down
Loading

0 comments on commit a0bc04c

Please sign in to comment.