Skip to content

Commit

Permalink
Move visplanes hash table to sec SH2 stack
Browse files Browse the repository at this point in the history
  • Loading branch information
viciious committed Aug 26, 2024
1 parent 761daac commit 0a5afc5
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 28 deletions.
3 changes: 1 addition & 2 deletions r_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
;

Expand Down Expand Up @@ -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 */
Expand Down
24 changes: 6 additions & 18 deletions r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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]);
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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)));

Expand All @@ -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();
Expand Down Expand Up @@ -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);

Expand Down
30 changes: 22 additions & 8 deletions r_phase2.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 0a5afc5

Please sign in to comment.