diff --git a/r_local.h b/r_local.h index c80109e91..ee8ec80fc 100644 --- a/r_local.h +++ b/r_local.h @@ -591,7 +591,7 @@ ATTR_DATA_CACHE_ALIGN ; visplane_t *R_FindPlane(fixed_t height, int flatandlight, - int start, int stop) + int start, int stop, visplane_t **visplanes_hash) ATTR_DATA_CACHE_ALIGN ; @@ -645,7 +645,6 @@ __attribute__((aligned(16))) /* */ visplane_t * volatile visplanes/*[MAXVISPLANES]*/, * volatile lastvisplane; int * volatile gsortedvisplanes; - visplane_t * volatile * visplanes_hash; /* */ /* openings / misc refresh memory */ diff --git a/r_main.c b/r_main.c index 55e603b25..49a5d8a36 100644 --- a/r_main.c +++ b/r_main.c @@ -533,7 +533,7 @@ extern pixel_t *screens[2]; /* [viewportWidth*viewportHeight]; */ */ static void R_Setup (int displayplayer, visplane_t *visplanes_, - visplane_t **visplanes_hash_, sector_t **vissectors_, viswallextra_t *viswallex_) + sector_t **vissectors_, viswallextra_t *viswallex_) { int i; int damagecount, bonuscount; @@ -735,7 +735,6 @@ static void R_Setup (int displayplayer, visplane_t *visplanes_, vd->lastsegclip = vd->segclip; vd->lastvisplane = vd->visplanes + 1; /* visplanes[0] is left empty */ - vd->visplanes_hash = visplanes_hash_; vd->gsortedvisplanes = NULL; @@ -757,9 +756,6 @@ static void R_Setup (int displayplayer, visplane_t *visplanes_, vd->vissectors = vissectors_; vd->lastvissector = vd->vissectors; /* no subsectors visible yet */ - for (i = 0; i < NUM_VISPLANES_BUCKETS; i++) - vd->visplanes_hash[i] = NULL; - #ifndef MARS phasetime[0] = samplecount; #endif @@ -769,17 +765,12 @@ static void R_Setup (int displayplayer, visplane_t *visplanes_, void Mars_Sec_R_Setup(void) { - int i; - Mars_ClearCacheLines(&vd, 1); Mars_ClearCacheLines(vd, (sizeof(*vd) + 31) / 16); Mars_ClearCacheLine(&viewportbuffer); Mars_ClearCacheLines(vd->visplanes, (sizeof(visplane_t)*MAXVISPLANES+31)/16); - for (i = 0; i < NUM_VISPLANES_BUCKETS; i++) - vd->visplanes_hash[i] = NULL; - I_SetThreadLocalVar(DOOMTLS_COLUMNCACHE, vd->columncache[1]); } @@ -820,12 +811,12 @@ void R_InitClipBounds(uint32_t *clipbounds) } visplane_t* R_FindPlane(fixed_t height, - int flatandlight, int start, int stop) + int flatandlight, int start, int stop, visplane_t **visplanes_hash) { visplane_t *check, *tail, *next; int hash = R_PlaneHash(height, flatandlight); - tail = vd->visplanes_hash[hash]; + tail = visplanes_hash[hash]; for (check = tail; check; check = next) { next = check->next; @@ -860,7 +851,7 @@ visplane_t* R_FindPlane(fixed_t height, R_MarkOpenPlane(check); check->next = tail; - vd->visplanes_hash[hash] = check; + visplanes_hash[hash] = check; return check; } @@ -900,7 +891,6 @@ extern ref8_start; void R_RenderPlayerView(int displayplayer) { visplane_t visplanes_[MAXVISPLANES]; - visplane_t *visplanes_hash_[NUM_VISPLANES_BUCKETS]; sector_t *vissectors_[MAXVISSSEC]; viswallextra_t viswallex_[MAXWALLCMDS + 1] __attribute__((aligned(16))); @@ -916,7 +906,7 @@ void R_RenderPlayerView(int displayplayer) if (debugscreenactive) I_DebugScreen(); - R_Setup(displayplayer, visplanes_, visplanes_hash_, vissectors_, viswallex_); + R_Setup(displayplayer, visplanes_, vissectors_, viswallex_); #ifndef JAGUAR R_BSP(); @@ -960,14 +950,12 @@ void R_RenderPlayerView(int displayplayer) boolean drawworld = !(players[consoleplayer].automapflags & AF_ACTIVE); __attribute__((aligned(16))) visplane_t visplanes_[MAXVISPLANES]; - __attribute__((aligned(16))) - visplane_t *visplanes_hash_[NUM_VISPLANES_BUCKETS]; sector_t *vissectors_[(MAXVISSSEC > MAXVISSPRITES ? MAXVISSSEC : MAXVISSPRITES) + 1]; viswallextra_t viswallex_[MAXWALLCMDS + 1] __attribute__((aligned(16))); t_total = I_GetFRTCounter(); - R_Setup(displayplayer, visplanes_, visplanes_hash_, vissectors_, viswallex_); + R_Setup(displayplayer, visplanes_, vissectors_, viswallex_); Mars_R_BeginWallPrep(drawworld); diff --git a/r_phase2.c b/r_phase2.c index e6db681d4..89f7265f7 100644 --- a/r_phase2.c +++ b/r_phase2.c @@ -8,12 +8,19 @@ #include "r_local.h" #include "mars.h" +typedef struct +{ + uint32_t clipbounds[SCREENWIDTH/2+1]; + __attribute__((aligned(16))) + visplane_t *visplanes_hash[NUM_VISPLANES_BUCKETS]; +} phase2Work_t; + static fixed_t R_PointToDist(fixed_t x, fixed_t y) ATTR_DATA_CACHE_ALIGN; static fixed_t R_ScaleFromGlobalAngle(fixed_t rw_distance, angle_t visangle, angle_t normalangle) ATTR_DATA_CACHE_ALIGN; static void R_SetupCalc(viswall_t* wc, fixed_t hyp, angle_t normalangle, int angle1) ATTR_DATA_CACHE_ALIGN; void R_WallLatePrep(viswall_t* wc, mapvertex_t *verts) ATTR_DATA_CACHE_ALIGN; // the volatiles help gcc produce less silly SH2 assembler code -static void R_SegLoop(viswall_t* segl, unsigned short *restrict clipbounds, volatile fixed_t floorheight, +static void R_SegLoop(viswall_t* segl, phase2Work_t *work, volatile fixed_t floorheight, volatile fixed_t floornewheight, volatile fixed_t ceilingnewheight) ATTR_DATA_CACHE_ALIGN __attribute__((noinline)); void R_WallPrep(void) ATTR_DATA_CACHE_ALIGN __attribute__((noinline)); @@ -175,7 +182,7 @@ void R_WallLatePrep(viswall_t* wc, mapvertex_t *verts) // // Main seg clipping loop // -static void R_SegLoop(viswall_t* segl, unsigned short * restrict clipbounds, +static void R_SegLoop(viswall_t* segl, phase2Work_t *work, volatile fixed_t floorheight, volatile fixed_t floornewheight, volatile fixed_t ceilingnewheight) { const volatile int actionbits = segl->actionbits; @@ -186,6 +193,10 @@ static void R_SegLoop(viswall_t* segl, unsigned short * restrict clipbounds, int x, start = segl->start; const int stop = segl->stop; + unsigned short * restrict clipbounds = work->clipbounds; + + visplane_t **visplanes_hash = work->visplanes_hash; + const volatile fixed_t ceilingheight = segl->ceilingheight; const int floorandlight = ((segl->seglightlevel & 0xff) << 16) | segl->floorpicnum; @@ -264,7 +275,7 @@ static void R_SegLoop(viswall_t* segl, unsigned short * restrict clipbounds, { if (!MARKEDOPEN(flooropen[x])) { - visplane_t *floor = R_FindPlane(floorheight, floorandlight, x, stop); + visplane_t *floor = R_FindPlane(floorheight, floorandlight, x, stop, visplanes_hash); flooropen = floor->open; } flooropen[x] = (top << 8) + (bottom-1); @@ -286,7 +297,7 @@ static void R_SegLoop(viswall_t* segl, unsigned short * restrict clipbounds, { if (!MARKEDOPEN(ceilopen[x])) { - visplane_t *ceiling = R_FindPlane(ceilingheight, ceilandlight, x, stop); + visplane_t *ceiling = R_FindPlane(ceilingheight, ceilandlight, x, stop, visplanes_hash); ceilopen = ceiling->open; } ceilopen[x] = (top << 8) + (bottom-1); @@ -304,8 +315,8 @@ void Mars_Sec_R_WallPrep(void) viswall_t *segl; viswallextra_t *seglex; viswall_t *first, *last, *verylast; - uint32_t clipbounds_[SCREENWIDTH/2+1]; - uint16_t *clipbounds = (uint16_t *)clipbounds_; + phase2Work_t work; + uint16_t *clipbounds = (uint16_t *)work.clipbounds; mapvertex_t *verts; volatile uint8_t *addedsegs = (volatile uint8_t *)&MARS_SYS_COMM6; volatile uint8_t *readysegs = addedsegs + 1; @@ -315,7 +326,10 @@ void Mars_Sec_R_WallPrep(void) for (i = 0; i < SCREENWIDTH+2; i++) vp0open[i] = 0; - R_InitClipBounds(clipbounds_); + for (i = 0; i < NUM_VISPLANES_BUCKETS; i++) + work.visplanes_hash[i] = NULL; + + R_InitClipBounds(work.clipbounds); first = last = vd->viswalls; verylast = NULL; @@ -345,7 +359,7 @@ void Mars_Sec_R_WallPrep(void) #endif R_WallLatePrep(segl, verts); - R_SegLoop(segl, clipbounds, seglex->floorheight, seglex->floornewheight, seglex->ceilnewheight); + R_SegLoop(segl, &work, seglex->floorheight, seglex->floornewheight, seglex->ceilnewheight); seglex++; *readysegs = *readysegs + 1;