Skip to content

Commit

Permalink
Merge pull request Roman971#9 from rrealmuto/dl_fixes
Browse files Browse the repository at this point in the history
Add DL double buffering
  • Loading branch information
GSKirox authored Jul 24, 2024
2 parents 378b310 + 6674738 commit 3354826
Show file tree
Hide file tree
Showing 8 changed files with 21,326 additions and 21,302 deletions.
1,045 changes: 524 additions & 521 deletions ASM/build/asm_symbols.txt

Large diffs are not rendered by default.

Binary file modified ASM/build/bundle.o
Binary file not shown.
1,088 changes: 545 additions & 543 deletions ASM/build/c_symbols.txt

Large diffs are not rendered by default.

69 changes: 55 additions & 14 deletions ASM/c/gfx.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,24 @@ extern uint8_t FONT_RESOURCE[];
extern uint8_t DPAD_RESOURCE[];
extern uint8_t TRIFORCE_SPRITE_RESOURCE[];

z64_disp_buf_t* rando_db __attribute__ ((aligned (16)));
const unsigned int RANDO_DB_SIZE = 0x5000;
#define RANDO_OVERLAY_DB_SIZE 0xA00 // Size of overlay display buffer, in GFX commands which are 8 bytes

z64_disp_buf_t rando_overlay_db __attribute__ ((aligned (16)));
#if DEBUG_MODE
z64_disp_buf_t* debug_db __attribute__ ((aligned (16)));
const unsigned int DEBUG_DB_SIZE = 0x2000;
z64_disp_buf_t debug_db __attribute__ ((aligned (16)));
#define DEBUG_DB_SIZE 0x400
#endif

typedef struct {
Gfx rando_overlay[RANDO_OVERLAY_DB_SIZE];
#if DEBUG_MODE
Gfx debug[DEBUG_DB_SIZE];
#endif
} RandoGFXPool;

RandoGFXPool randoGfxPools[2]; // Rando GFX Pools. Need 2 because Display Lists need to be double buffered
uint8_t randoGfxPoolIndex; // Index which is incremented every frame to determine which gfx pool to use

Gfx setup_db[] = {
gsDPPipeSync(),

Expand Down Expand Up @@ -224,19 +234,52 @@ void sprite_draw(z64_disp_buf_t* db, sprite_t* sprite, int tile_index,
}

void rando_display_buffer_init() {
randoGfxPoolIndex = 0;
}

void rando_display_buffer_reset() {
RandoGFXPool* pool = &randoGfxPools[randoGfxPoolIndex & 1];
#if DEBUG_MODE
debug_db = heap_alloc(sizeof(z64_disp_buf_t));
debug_db->size = DEBUG_DB_SIZE;
debug_db->buf = heap_alloc(DEBUG_DB_SIZE);
debug_db->p = &debug_db->buf[0];
debug_db.size = sizeof(pool->debug);
debug_db.buf = &pool->debug[0];
debug_db.p = &debug_db.buf[0];
#endif
rando_db = heap_alloc(sizeof(z64_disp_buf_t));
rando_db->size = RANDO_DB_SIZE;
rando_db->buf = heap_alloc(RANDO_DB_SIZE);
rando_db->p = &rando_db->buf[0];
rando_overlay_db.size = sizeof(pool->rando_overlay);
rando_overlay_db.buf = &pool->rando_overlay[0];
rando_overlay_db.p = &rando_overlay_db.buf[0];
}

void close_rando_display_buffer() {
char error_msg[256];

OPEN_DISPS(z64_ctxt.gfx);

#if DEBUG_MODE
if (((int) debug_db.p - (int) debug_db.buf) > debug_db.size) {
sprintf(error_msg, "size = %x\nmax = %x\np = %p\nbuf = %p\nd = %p", ((int) debug_db.p - (int) debug_db.buf),
debug_db.size, debug_db.p, debug_db.buf, debug_db.d);
Fault_AddHungupAndCrashImpl("Debug display buffer exceeded!", error_msg);
}

gSPEndDisplayList(debug_db.p++);
gSPDisplayList(OVERLAY_DISP++, debug_db.buf);
#endif

if (((int) rando_overlay_db.p - (int) rando_overlay_db.buf) > rando_overlay_db.size) {
sprintf(error_msg, "size = %x\nmax = %x\np = %p\nbuf = %p\nd = %p", ((int) rando_overlay_db.p - (int) rando_overlay_db.buf),
rando_overlay_db.size, rando_overlay_db.p, rando_overlay_db.buf, rando_overlay_db.d);
Fault_AddHungupAndCrashImpl("Randomizer display buffer exceeded!", error_msg);
}

gSPEndDisplayList(rando_overlay_db.p++);
gSPDisplayList(OVERLAY_DISP++, rando_overlay_db.buf);

CLOSE_DISPS();
randoGfxPoolIndex++;
}

void gfx_init() {
rando_display_buffer_init();
file_t title_static = {
NULL, z64_file_select_static_vaddr, z64_file_select_static_vsize
};
Expand Down Expand Up @@ -288,6 +331,4 @@ void gfx_init() {
font_sprite.buf[2*i] = (FONT_RESOURCE[i] >> 4) | 0xF0;
font_sprite.buf[2*i + 1] = FONT_RESOURCE[i] | 0xF0;
}

rando_display_buffer_init();
}
8 changes: 5 additions & 3 deletions ASM/c/gfx.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
extern Gfx setup_db[];
extern Gfx empty_dlist[];
extern void* z64_ItemIcons[130];
extern z64_disp_buf_t* rando_db;
extern z64_disp_buf_t* debug_db;
extern z64_disp_buf_t rando_overlay_db;
extern z64_disp_buf_t debug_db;

#define WORK_DISP __gfxCtx->work.p
#define POLY_OPA_DISP __gfxCtx->poly_opa.p
Expand Down Expand Up @@ -66,5 +66,7 @@ void sprite_texture_4b(z64_disp_buf_t* db, sprite_t* sprite, int tile_index,
int16_t left, int16_t top, int16_t width, int16_t height);

void z64_Gfx_SetupDL_42Opa(z64_gfx_t* gfx_ctxt);

void rando_display_buffer_init();
void rando_display_buffer_reset();
void close_rando_display_buffer();
#endif
47 changes: 9 additions & 38 deletions ASM/c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ void c_init() {
}

void before_game_state_update() {
rando_display_buffer_reset();
handle_pending_items();
handle_dpad();
update_misc_colors();
Expand All @@ -47,49 +48,19 @@ void before_game_state_update() {
display_misc_messages();
}

void close_rando_display_buffer() {
char error_msg[256];

OPEN_DISPS(z64_ctxt.gfx);

#if DEBUG_MODE
if (((int) debug_db->p - (int) debug_db->buf) > debug_db->size) {
sprintf(error_msg, "size = %x\nmax = %x\np = %p\nbuf = %p\nd = %p", ((int) debug_db->p - (int) debug_db->buf),
debug_db->size, debug_db->p, debug_db->buf, debug_db->d);
Fault_AddHungupAndCrashImpl("Debug display buffer exceeded!", error_msg);
}

gSPEndDisplayList(debug_db->p++);
debug_db->p = &debug_db->buf[0];
gSPDisplayList(OVERLAY_DISP++, debug_db->buf);
#endif

if (((int) rando_db->p - (int) rando_db->buf) > rando_db->size) {
sprintf(error_msg, "size = %x\nmax = %x\np = %p\nbuf = %p\nd = %p", ((int) rando_db->p - (int) rando_db->buf),
rando_db->size, rando_db->p, rando_db->buf, rando_db->d);
Fault_AddHungupAndCrashImpl("Randomizer display buffer exceeded!", error_msg);
}

gSPEndDisplayList(rando_db->p++);
rando_db->p = &rando_db->buf[0];
gSPDisplayList(OVERLAY_DISP++, rando_db->buf);

CLOSE_DISPS();
}

void after_game_state_update() {
// Checks if the prerender screen is being drawn before drawing new HUD things.
// Else this will cause graphical and/or lag issues on some emulators when pausing.
if (R_PAUSE_BG_PRERENDER_STATE != PAUSE_BG_PRERENDER_PROCESS) {
draw_dungeon_info(rando_db);
draw_triforce_count(rando_db);
draw_boss_key(&z64_game, rando_db);
draw_silver_rupee_count(&z64_game, rando_db);
draw_illegal_model_text(rando_db);
draw_input_viewer(rando_db);
display_song_name(rando_db);
draw_dungeon_info(&rando_overlay_db);
draw_triforce_count(&rando_overlay_db);
draw_boss_key(&z64_game, &rando_overlay_db);
draw_silver_rupee_count(&z64_game, &rando_overlay_db);
draw_illegal_model_text(&rando_overlay_db);
draw_input_viewer(&rando_overlay_db);
display_song_name(&rando_overlay_db);
#if DEBUG_MODE
debug_utilities(debug_db);
debug_utilities(&debug_db);
#endif
}
close_rando_display_buffer();
Expand Down
Loading

0 comments on commit 3354826

Please sign in to comment.