Fix vertex modification race condition by using displaylist parsed event

This commit is contained in:
Mr-Wiseguy
2025-12-12 02:12:42 -05:00
parent 8fa0dd559f
commit 674efaa5ce
5 changed files with 27 additions and 4 deletions
+2 -2
View File
@@ -5,9 +5,9 @@ LD ?= ld.lld
GBI_DEFINE := -DF3DEX_GBI
CFLAGS := -target mips -mips2 -mabi=32 -O2 -G0 -mno-abicalls -mno-odd-spreg -mno-check-zero-division \
-fomit-frame-pointer -ffast-math -fno-unsafe-math-optimizations -fno-builtin-memset \
-fomit-frame-pointer -ffast-math -fno-unsafe-math-optimizations -fno-builtin-memset -funsigned-char \
-Wall -Wextra -Wno-incompatible-library-redeclaration -Wno-unused-parameter -Wno-unknown-pragmas -Wno-unused-variable -Wno-missing-braces -Wno-unsupported-floating-point-opt -Wno-cast-function-type-mismatch
CPPFLAGS := -nostdinc -D_LANGUAGE_C -DMIPS -I ../lib/bk-decomp/include -I ../lib/bk-decomp/include/2.0L -I ../lib/bk-decomp/include/2.0L/PR -I../lib/rt64/include $(GBI_DEFINE)
CPPFLAGS := -nostdinc -D_LANGUAGE_C -DMIPS -I ../lib/bk-decomp/include -I ../lib/bk-decomp/include/2.0L -I ../lib/bk-decomp/include/2.0L/PR -I../lib/rt64/include -I../lib/N64ModernRuntime/ultramodern/include $(GBI_DEFINE)
LDFLAGS := -nostdlib -T patches.ld -T syms.ld -Map patches.map --unresolved-symbols=ignore-all --emit-relocs
C_SRCS := $(wildcard *.c)
+14 -1
View File
@@ -1,4 +1,5 @@
#include "patches.h"
#include "ultra_extensions.h"
#include "misc_funcs.h"
#include "core1/core1.h"
#include "core1/vimgr.h"
@@ -22,7 +23,7 @@ extern struct{
void func_802E39D0(Gfx **gdl, Mtx **mptr, Vtx **vptr, s32 framebuffer_idx, s32 arg4);
// 10x the original sizes.
// 16x the original sizes.
#define GFX_BUFFER_COUNT 37000
#define MTX_BUFFER_COUNT 7000
#define VTX_BUFFER_COUNT 4300
@@ -65,6 +66,7 @@ RECOMP_PATCH void graphicsCache_init(void){
}
// @recomp Patched to check for graphics stack overflow after processing a frame.
// Also patched to wait for a message when the displaylist is completed immediately after queueing it to solve vertex modification race conditions.
RECOMP_PATCH void game_draw(s32 arg0){
Gfx *gfx;
Gfx *gfx_start;
@@ -115,7 +117,18 @@ RECOMP_PATCH void game_draw(s32 arg0){
if(D_8037E8E0.unkC == 0){
sp2C = gfx;
viMgr_func_8024C1DC();
// @recomp Set up the message queue and event for waiting on DL completion.
OSMesgQueue dl_complete_queue;
OSMesg dl_complete_queue_buf;
osCreateMesgQueue(&dl_complete_queue, &dl_complete_queue_buf, 1);
osExQueueDisplaylistEvent(&dl_complete_queue, NULL, gfx_start, OS_EX_DISPLAYLIST_EVENT_PARSED);
func_80253EC4(gfx_start, sp2C);
// @recomp Wait for the displaylist to be completed after submitting it. This removes the race condition
// that exists with vertex modifications for texture scrolling.
osRecvMesg(&dl_complete_queue, NULL, OS_MESG_BLOCK);
if(arg0) {
scissorBox_setDefault();
+1
View File
@@ -35,3 +35,4 @@ osVirtualToPhysical_recomp = 0x8F000078;
osPiStartDma_recomp = 0x8F00007C;
recomp_abort = 0x8F000080;
recomp_get_target_aspect_ratio = 0x8F000084;
osExQueueDisplaylistEvent_recomp = 0x8F000088;
+9
View File
@@ -0,0 +1,9 @@
#ifndef __ULTRA_EXTENSIONS_H__
#define __ULTRA_EXTENSIONS_H__
// TODO remove when the recompiler automatically renames symbols in patch recompilation.
#define osExQueueDisplaylistEvent osExQueueDisplaylistEvent_recomp
#include "ultramodern/extensions.h"
#endif