Skip to content

Commit

Permalink
Moving over to a jump table for VU programs
Browse files Browse the repository at this point in the history
  • Loading branch information
nchalkley2 committed Dec 18, 2024
1 parent 649c929 commit 58d477e
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 92 deletions.
1 change: 1 addition & 0 deletions dependencies/egg-ps2-graphics-lib/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*.o
*.elf
*.vo
*.vcl_pp
*.vsm

lib/
Expand Down
3 changes: 2 additions & 1 deletion dependencies/egg-ps2-graphics-lib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ EE_SRC_DIR = src/
EE_LIB_DIR = lib/
EE_OBJS_DIR = obj/

EE_INCS += -I./include -I$(PS2SDK)/ports/include -I$(EE_SRC_DIR)
EE_INCS += -I./include -I./vu1 -I$(PS2SDK)/ports/include -I$(EE_SRC_DIR)

EE_LIB = $(EE_LIB_DIR)libegg-ps2-graphics-lib.a
EE_OBJS = src/egg-ps2-graphics-lib.o src/mesh.o src/vu_programs.o src/types.o src/draw.o src/texture.o src/gs_mem.o
Expand All @@ -25,6 +25,7 @@ clean:
rm -rf ./src/*.o
rm -rf ./vu1/*.vo
rm -rf ./vu1/*.vsm
rm -rf ./vu1/*.vcl_pp

include Makefile.vuprogs

Expand Down
12 changes: 8 additions & 4 deletions dependencies/egg-ps2-graphics-lib/Makefile.vuprogs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ RENDERERS = \
project \
project_clip \
vertex_color \
xgkick
xgkick \
jump_table

VSM_OBJS = $(addsuffix .vo, $(addprefix vu1/, $(RENDERERS)))
EE_OBJS += $(VSM_OBJS)
Expand All @@ -18,6 +19,9 @@ vu_progs: $(VSM_OBJS)
%.vo: %.vsm
$(EE_DVP) $< -o $@

.PRECIOUS: %.vsm
%.vsm: %.vcl
$(VCL) $< > $@
.PRECIOUS: %.vsm %.vcl_pp
%.vsm: %.vcl_pp
$(VCL) $< > $@

%.vcl_pp: %.vcl
cpp -P -undef $< > $@
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,5 @@ DECLARE_VU_PROGRAM(vertex_color_renderer);
DECLARE_VU_PROGRAM(project);
DECLARE_VU_PROGRAM(project_clip);
DECLARE_VU_PROGRAM(vertex_color);
DECLARE_VU_PROGRAM(jump_table);
} // namespace egg::ps2::graphics::vu1_programs
32 changes: 3 additions & 29 deletions dependencies/egg-ps2-graphics-lib/src/mesh.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,17 @@ void draw_untextured_strip(const Matrix& mesh_to_screen_matrix, const mesh_descr
packet2_utils_vu_close_unpack(get_current_vif_packet());

// Position data
packet2_utils_vu_add_unpack_data(get_current_vif_packet(), 8, mesh.pos, mesh.num_verts, 1);
packet2_utils_vu_add_unpack_data(get_current_vif_packet(), 11, mesh.pos, mesh.num_verts, 1);

if (mesh.color)
{
// Color data
packet2_utils_vu_add_unpack_data(get_current_vif_packet(), 8 + mesh.num_verts, mesh.color, mesh.num_verts, 1);
packet2_utils_vu_add_unpack_data(get_current_vif_packet(), 11 + mesh.num_verts, mesh.color, mesh.num_verts, 1);
}

assert((8 + (mesh.num_verts * 4)) < 496);
assert((11 + (mesh.num_verts * 4)) < 496);

packet2_utils_vu_add_start_program(get_current_vif_packet(), vu1_programs::get_project_clip().program_address);
// packet2_utils_vu_add_start_program(get_current_vif_packet(), vu1_programs::get_xgkick().program_address);

// {
// packet2_chain_open_cnt(get_current_vif_packet(), 0, 0, 0);
// packet2_add_u32(get_current_vif_packet(), MAKE_VIF_CODE(0, 0, P2_VIF_FLUSH, 0));
// packet2_vif_mscal(get_current_vif_packet(), vu1_programs::get_project_clip().program_address, 0);
// packet2_chain_close_tag(get_current_vif_packet());

// packet2_chain_open_cnt(get_current_vif_packet(), 0, 0, 0);
// packet2_add_u32(get_current_vif_packet(), MAKE_VIF_CODE(0, 0, P2_VIF_FLUSHE, 0));
// packet2_vif_mscal(get_current_vif_packet(), vu1_programs::get_xgkick().program_address, 0);
// packet2_chain_close_tag(get_current_vif_packet());
// }
}

#define MAKE_VIF_CODE(_immediate, _num, _cmd, _irq) ((u32)(_immediate) | ((u32)(_num) << 16) | ((u32)(_cmd) << 24) | ((u32)(_irq) << 31))
Expand Down Expand Up @@ -190,20 +177,7 @@ void draw_textured_strip(const Matrix& mesh_to_screen_matrix, const mesh_descrip

assert((11 + (mesh.num_verts * 6)) < 496);

// {
// packet2_chain_open_cnt(get_current_vif_packet(), 0, 0, 0);
// packet2_add_u32(get_current_vif_packet(), MAKE_VIF_CODE(0, 0, P2_VIF_FLUSH, 0));
// packet2_vif_mscal(get_current_vif_packet(), vu1_programs::get_project_clip().program_address, 0);
// packet2_chain_close_tag(get_current_vif_packet());

// packet2_chain_open_cnt(get_current_vif_packet(), 0, 0, 0);
// packet2_add_u32(get_current_vif_packet(), MAKE_VIF_CODE(0, 0, P2_VIF_FLUSH, 0));
// packet2_vif_mscal(get_current_vif_packet(), vu1_programs::get_xgkick().program_address, 0);
// packet2_chain_close_tag(get_current_vif_packet());
// }

packet2_utils_vu_add_start_program(get_current_vif_packet(), vu1_programs::get_project_clip().program_address);
//packet2_utils_vu_add_start_program(get_current_vif_packet(), vu1_programs::get_xgkick().program_address);
}

} // namespace
Expand Down
1 change: 1 addition & 0 deletions dependencies/egg-ps2-graphics-lib/src/vu_programs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ DEFINE_VU_PROGRAM(vertex_color_renderer, VertexColorRenderer);
DEFINE_VU_PROGRAM(project, Project);
DEFINE_VU_PROGRAM(project_clip, ProjectClip);
DEFINE_VU_PROGRAM(vertex_color, VertexColor);
DEFINE_VU_PROGRAM(jump_table, JumpTable);
} // namespace vu1_programs
} // namespace egg::ps2::graphics
14 changes: 14 additions & 0 deletions dependencies/egg-ps2-graphics-lib/vu1/jump_table.vcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "vu1_mem.h"

.syntax new
.name vsmJumpTable
.vu
.init_vf_all
.init_vi_all

--enter
--endenter


--exit
--endexit
25 changes: 13 additions & 12 deletions dependencies/egg-ps2-graphics-lib/vu1/project.vcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "vu1_mem.h"

.syntax new
.name vsmProject
Expand All @@ -11,24 +12,24 @@
; Updated dynamically
xtop iBase

lq matrixRow0, 0(iBase) ; load view-projection matrix
lq matrixRow1, 1(iBase)
lq matrixRow2, 2(iBase)
lq matrixRow3, 3(iBase)
lq matrixRow0, MATRIXROW0(iBase) ; load view-projection matrix
lq matrixRow1, MATRIXROW1(iBase)
lq matrixRow2, MATRIXROW2(iBase)
lq matrixRow3, MATRIXROW3(iBase)

lq.xyz scale, 4(iBase) ; load program params
lq.xyz scale, SCALE(iBase) ; load program params
; float : X, Y, Z - scale vector that we will use to scale the verts after projecting them.
; float : W - vert count.
ilw.w vertCount, 4(iBase)
lq primTag, 5(iBase) ; GIF tag - tell GS how many data we will send and what type
lq rgba, 6(iBase) ; RGBA mul
ilw.w vertCount, SCALE(iBase)
lq primTag, PRIMTAG(iBase) ; GIF tag - tell GS how many data we will send and what type
lq rgba, RGBA(iBase) ; RGBA mul
; u32 : R, G, B, A (0-128)

;lq fogSetting, 7(iBase) ; x = offset, y = scale
ilw.z compsPerPrim, 7(iBase)
ilw.w destOffset, 7(iBase) ; dest address offest (compsPerPrim * vertex count)
;lq fogSetting, FOG(iBase) ; x = offset, y = scale
ilw.z compsPerPrim, FOG(iBase)
ilw.w destOffset, FOG(iBase) ; dest address offest (compsPerPrim * vertex count)

iaddiu vertexInPtr, iBase, 8 ; pointer to vertex input data
iaddiu vertexInPtr, iBase, VERTEXIN ; pointer to vertex input data
iadd kickAddress, vertexInPtr, destOffset ; pointer for XGKICK
iadd vertexOutPtr, kickAddress, compsPerPrim ; pointer to first vert pos out
;////////////////////////////////////////////
Expand Down
31 changes: 15 additions & 16 deletions dependencies/egg-ps2-graphics-lib/vu1/project_clip.vcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "vu1_mem.h"

.syntax new
.name vsmProjectClip
Expand All @@ -7,31 +8,29 @@

--enter
--endenter
fcset 0x000000 ; VCL won't let us use CLIP without first zeroing
fcset 0x000000 ; VCL wont let us use CLIP without first zeroing
; the clip flags

;//////////// --- Load data --- /////////////
; Updated dynamically
xtop iBase

lq matrixRow0, 0(iBase) ; load view-projection matrix
lq matrixRow1, 1(iBase)
lq matrixRow2, 2(iBase)
lq matrixRow3, 3(iBase)
lq.xyz scale, 4(iBase) ; load program params
; float : X, Y, Z - scale vector that we will use to scale the verts after projecting them.
; float : W - vert count.
ilw.w vertCount, 4(iBase)
lq primTag, 5(iBase) ; GIF tag - tell GS how many data we will send and what type
lq rgba, 6(iBase) ; RGBA mul
lq matrixRow0, MATRIXROW0(iBase) ; load view-projection matrix
lq matrixRow1, MATRIXROW1(iBase)
lq matrixRow2, MATRIXROW2(iBase)
lq matrixRow3, MATRIXROW3(iBase)

lq.xyz scale, SCALE(iBase)
ilw.w vertCount, SCALE(iBase)
lq primTag, PRIMTAG(iBase) ; GIF tag - tell GS how many data we will send and what type
lq rgba, RGBA(iBase) ; RGBA mul
; u32 : R, G, B, A (0-128)

;lq fogSetting, 7(iBase) ; x = offset, y = scale
ilw.z compsPerPrim, 7(iBase)
ilw.w destOffset, 7(iBase) ; dest address offest (compsPerPrim * vertex count)
;lq fogSetting, FOG(iBase) ; x = offset, y = scale
ilw.z compsPerPrim, FOG(iBase)
ilw.w destOffset, FOG(iBase) ; dest address offest (compsPerPrim * vertex count)

iaddiu vertexInPtr, iBase, 8 ; pointer to vertex input data
iaddiu vertexInPtr, iBase, VERTEXIN ; pointer to vertex input data
iadd kickAddress, vertexInPtr, destOffset ; pointer for XGKICK
iadd vertexOutPtr, kickAddress, compsPerPrim ; pointer to first vert pos out
;////////////////////////////////////////////
Expand Down
23 changes: 7 additions & 16 deletions dependencies/egg-ps2-graphics-lib/vu1/vertex_color.vcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "vu1_mem.h"

.syntax new
.name vsmVertexColor
Expand All @@ -7,31 +8,21 @@

--enter
--endenter
fcset 0x000000 ; VCL won't let us use CLIP without first zeroing
; the clip flags
;//////////// --- Load data --- /////////////
; Updated dynamically
xtop iBase

; lq matrixRow0, 0(iBase) ; load view-projection matrix
; lq matrixRow1, 1(iBase)
; lq matrixRow2, 2(iBase)
; lq matrixRow3, 3(iBase)
lq.xyz scale, 4(iBase) ; load program params
lq.xyz scale, SCALE(iBase) ; load program params
; float : X, Y, Z - scale vector that we will use to scale the verts after projecting them.
; float : W - vert count.
ilw.w vertCount, 4(iBase)
;lq primTag, 5(iBase) ; GIF tag - tell GS how many data we will send and what type
lq rgba, 6(iBase) ; RGBA mul
ilw.w vertCount, SCALE(iBase)
lq rgba, RGBA(iBase) ; RGBA mul
; u32 : R, G, B, A (0-128)

;lq fogSetting, 7(iBase) ; x = offset, y = scale
ilw.z compsPerPrim, 7(iBase)
ilw.w destOffset, 7(iBase) ; dest address offest (compsPerPrim * vertex count)
ilw.z compsPerPrim, FOG(iBase)
ilw.w destOffset, FOG(iBase) ; dest address offest (compsPerPrim * vertex count)

iaddiu vertexInPtr, iBase, 8 ; pointer to vertex input data
iaddiu vertexInPtr, iBase, VERTEXIN ; pointer to vertex input data
iadd colorInPtr, vertexInPtr, vertCount ; pointer to color input data
iadd kickAddress, vertexInPtr, destOffset ; pointer for XGKICK
iadd vertexOutPtr, kickAddress, compsPerPrim ; pointer to first vert pos out
Expand Down
25 changes: 13 additions & 12 deletions dependencies/egg-ps2-graphics-lib/vu1/vertex_color_renderer.vcl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include "vu1_mem.h"

.syntax new
.name vsmVertexColorRenderer
Expand All @@ -10,30 +11,30 @@

;/////////////////////////////////////////////

fcset 0x000000 ; VCL won't let us use CLIP without first zeroing
fcset 0x000000 ; VCL wont let us use CLIP without first zeroing
; the clip flags


;//////////// --- Load data --- /////////////
; Updated dynamically
xtop iBase

lq matrixRow0, 0(iBase) ; load view-projection matrix
lq matrixRow1, 1(iBase)
lq matrixRow2, 2(iBase)
lq matrixRow3, 3(iBase)
lq matrixRow0, MATRIXROW0(iBase) ; load view-projection matrix
lq matrixRow1, MATRIXROW1(iBase)
lq matrixRow2, MATRIXROW2(iBase)
lq matrixRow3, MATRIXROW3(iBase)

lq.xyz scale, 4(iBase) ; load program params
lq.xyz scale, SCALE(iBase) ; load program params
; float : X, Y, Z - scale vector that we will use to scale the verts after projecting them.
; float : W - vert count.
ilw.w vertCount, 4(iBase)
lq primTag, 5(iBase) ; GIF tag - tell GS how many data we will send
lq rgba, 6(iBase) ; RGBA
ilw.w vertCount, SCALE(iBase)
lq primTag, PRIMTAG(iBase) ; GIF tag - tell GS how many data we will send and what type
lq rgba, RGBA(iBase) ; RGBA mul
; u32 : R, G, B, A (0-128)

lq fogSetting, 7(iBase) ; x = offset, y = scale
lq fogSetting, FOG(iBase) ; x = offset, y = scale

iaddiu vertexPtr, iBase, 8 ; pointer to vertex data
iaddiu vertexPtr, iBase, VERTEXIN ; pointer to vertex data
iadd colorPtr, vertexPtr, vertCount ; pointer to color data
iadd kickAddress, colorPtr, vertCount ; pointer for XGKICK
iadd destAddress, colorPtr, vertCount ; helper pointer for data inserting
Expand Down Expand Up @@ -92,7 +93,7 @@


; Fog
muly.w fog, vertex, fogSetting ; multiply the vertex's z by the fog scale (fogSetting[y])
muly.w fog, vertex, fogSetting ; multiply the vertexs z by the fog scale (fogSetting[y])
addx.w fog, fog, fogSetting ; add the fog start offset (fogSetting[x])

; Clamp fog from 0-255
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

;/////////////////////////////////////////////

fcset 0x000000 ; VCL won't let us use CLIP without first zeroing
fcset 0x000000 ; VCL wont let us use CLIP without first zeroing
; the clip flags


Expand Down Expand Up @@ -106,7 +106,7 @@


; Fog
muly.w fog, vertex, fogSetting ; multiply the vertex's z by the fog scale (fogSetting[y])
muly.w fog, vertex, fogSetting ; multiply the vertexs z by the fog scale (fogSetting[y])
addx.w fog, fog, fogSetting ; add the fog start offset (fogSetting[x])

; Clamp fog from 0-255
Expand Down
18 changes: 18 additions & 0 deletions dependencies/egg-ps2-graphics-lib/vu1/vu1_mem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#define MATRIXROW0 0
#define MATRIXROW1 (MATRIXROW0 + 1)
#define MATRIXROW2 (MATRIXROW1 + 1)
#define MATRIXROW3 (MATRIXROW2 + 1)

#define SCALE (MATRIXROW3 + 1)

#define PRIMTAG (SCALE + 1)
#define RGBA (PRIMTAG + 1)

#define FOG (RGBA + 1)

// Table of programs for the VU to run on the data
#define JUMPTABLE (FOG + 1)

#define VERTEXIN (JUMPTABLE + 2)

0 comments on commit 58d477e

Please sign in to comment.