From 9902cac3eea5ab0574a26e4e0a4bd86ae6b5c9cb Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 7 Apr 2025 08:35:33 +0200 Subject: [PATCH] some software optimizations from: https://git.do.srb2.org/Hanicef/SRB2Classic/-/merge_requests/6#d4bba40be8388ccd557d03ef4e4a36d0728c7751_645_587 minus the buffer flipping change, karts resolution stuff is hell and even worse due to birdmod things maybe will look into that sometime --- src/r_draw8.c | 129 +++++++++++++++++++++++-------------------------- src/r_segs.c | 12 ++--- src/r_things.c | 2 +- 3 files changed, 68 insertions(+), 75 deletions(-) diff --git a/src/r_draw8.c b/src/r_draw8.c index ff373aa79..72cf7f043 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -25,9 +25,9 @@ void R_DrawColumn_8(void) { INT32 count; - register UINT8 *dest; - register fixed_t frac; - fixed_t fracstep; + UINT8 *restrict dest; + intptr_t frac; + intptr_t fracstep; INT32 npow2min; INT32 npow2max; @@ -57,10 +57,10 @@ void R_DrawColumn_8(void) // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. - register const UINT8 *source = dc_source; - register const lighttable_t *colormap = dc_colormap; + const UINT8 *restrict source = dc_source; + const lighttable_t *restrict colormap = dc_colormap; - register INT32 heightmask = dc_sourcelength-1; + intptr_t heightmask = dc_sourcelength-1; npow2min = -1; npow2max = dc_sourcelength; @@ -77,10 +77,7 @@ void R_DrawColumn_8(void) } else { - while (frac >= heightmask) - { - frac -= heightmask; - } + frac %= heightmask; } do @@ -105,20 +102,20 @@ void R_DrawColumn_8(void) dest += vid.width; + +#if __SIZEOF_POINTER__ < 8 // 64-bit systems have large enough numbers for this to be a non-issue // Avoid overflow. if (fracstep > 0x7FFFFFFF - frac) { frac += fracstep - heightmask; } else +#endif { frac += fracstep; } - while (frac >= heightmask) - { - frac -= heightmask; - } + frac %= heightmask; } while (--count); } else @@ -147,9 +144,10 @@ void R_DrawColumn_8(void) void R_Draw2sMultiPatchColumn_8(void) { INT32 count; - register UINT8 *dest; - register fixed_t frac; - fixed_t fracstep; + UINT8 *restrict dest; + intptr_t frac; + intptr_t fracstep; + INT32 npow2min; INT32 npow2max; @@ -178,10 +176,11 @@ void R_Draw2sMultiPatchColumn_8(void) // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. - register const UINT8 *source = dc_source; - register const lighttable_t *colormap = dc_colormap; - register INT32 heightmask = dc_sourcelength-1; - register UINT8 val; + const UINT8 *restrict source = dc_source; + const lighttable_t *restrict colormap = dc_colormap; + intptr_t heightmask = dc_sourcelength-1; + UINT8 val; + npow2min = -1; npow2max = dc_sourcelength; @@ -198,10 +197,7 @@ void R_Draw2sMultiPatchColumn_8(void) } else { - while (frac >= heightmask) - { - frac -= heightmask; - } + frac %= heightmask; } do @@ -233,19 +229,18 @@ void R_Draw2sMultiPatchColumn_8(void) dest += vid.width; // Avoid overflow. +#if __SIZEOF_POINTER__ < 8 if (fracstep > 0x7FFFFFFF - frac) { frac += fracstep - heightmask; } else +#endif { frac += fracstep; } - while (frac >= heightmask) - { - frac -= heightmask; - } + frac %= heightmask; } while (--count); } else @@ -285,9 +280,10 @@ void R_Draw2sMultiPatchColumn_8(void) void R_Draw2sMultiPatchTranslucentColumn_8(void) { INT32 count; - register UINT8 *dest; - register fixed_t frac; - fixed_t fracstep; + UINT8 *restrict dest; + intptr_t frac; + intptr_t fracstep; + INT32 npow2min; INT32 npow2max; @@ -316,11 +312,12 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. - register const UINT8 *source = dc_source; - register const UINT8 *transmap = dc_transmap; - register const lighttable_t *colormap = dc_colormap; - register INT32 heightmask = dc_sourcelength-1; + const UINT8 *restrict source = dc_source; + const UINT8 *transmap = dc_transmap; + const lighttable_t *restrict colormap = dc_colormap; + intptr_t heightmask = dc_sourcelength-1; register UINT8 val; + npow2min = -1; npow2max = dc_sourcelength; @@ -337,10 +334,7 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) } else { - while (frac >= heightmask) - { - frac -= heightmask; - } + frac %= heightmask; } do @@ -372,19 +366,18 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) dest += vid.width; // Avoid overflow. +#if __SIZEOF_POINTER__ < 8 if (fracstep > 0x7FFFFFFF - frac) { frac += fracstep - heightmask; } else +#endif { frac += fracstep; } - while (frac >= heightmask) - { - frac -= heightmask; - } + frac %= heightmask; } while (--count); } else @@ -470,8 +463,10 @@ void R_DrawShadeColumn_8(void) void R_DrawTranslucentColumn_8(void) { register INT32 count; - register UINT8 *dest; - register fixed_t frac, fracstep; + UINT8 *restrict dest; + intptr_t frac; + intptr_t fracstep; + INT32 npow2min; INT32 npow2max; @@ -496,10 +491,11 @@ void R_DrawTranslucentColumn_8(void) // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. - register const UINT8 *source = dc_source; - register const UINT8 *transmap = dc_transmap; - register const lighttable_t *colormap = dc_colormap; - register INT32 heightmask = dc_sourcelength-1; + const UINT8 *restrict source = dc_source; + const UINT8 *transmap = dc_transmap; + const lighttable_t *restrict colormap = dc_colormap; + intptr_t heightmask = dc_sourcelength-1; + npow2min = -1; npow2max = dc_sourcelength; @@ -516,10 +512,7 @@ void R_DrawTranslucentColumn_8(void) } else { - while (frac >= heightmask) - { - frac -= heightmask; - } + frac %= heightmask; } do @@ -579,8 +572,10 @@ void R_DrawTranslucentColumn_8(void) void R_DrawTranslatedTranslucentColumn_8(void) { register INT32 count; - register UINT8 *dest; - register fixed_t frac, fracstep; + UINT8 *restrict dest; + intptr_t frac; + intptr_t fracstep; + INT32 npow2min; INT32 npow2max; @@ -605,7 +600,8 @@ void R_DrawTranslatedTranslucentColumn_8(void) // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. - register INT32 heightmask = dc_sourcelength-1; + intptr_t heightmask = dc_sourcelength-1; + npow2min = -1; npow2max = dc_sourcelength; @@ -622,10 +618,7 @@ void R_DrawTranslatedTranslucentColumn_8(void) } else { - while (frac >= heightmask) - { - frac -= heightmask; - } + frac %= heightmask; } do @@ -739,15 +732,15 @@ void R_DrawTranslatedColumn_8(void) */ void R_DrawSpan_8 (void) { - fixed_t xposition; - fixed_t yposition; - fixed_t xstep, ystep; + uintptr_t xposition; + uintptr_t yposition; + uintptr_t xstep, ystep; register UINT32 bit; - UINT8 *source; - UINT8 *colormap; - register UINT8 *dest; - const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; + UINT8 *restrict source; + UINT8 *restrict colormap; + UINT8 *restrict dest; + const UINT8 *restrict deststop = screens[0] + vid.rowbytes * vid.height; register size_t count = (ds_x2 - ds_x1 + 1); size_t i; diff --git a/src/r_segs.c b/src/r_segs.c index c27492680..8a9f0dc29 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -322,7 +322,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) if (!ldef->alpha) return; - + if (ldef->blendmode) { if (ldef->alpha == NUMTRANSMAPS || ldef->blendmode == AST_MODULATE) @@ -628,7 +628,7 @@ void R_RenderMaskedSegRange(drawseg_t *ds, INT32 x1, INT32 x2) // draw the texture col = (column_t *)((UINT8 *)R_GetColumn(texnum, maskedtexturecol[dc_x]) - 3); - + colfunc_2s(col); } spryscale += rw_scalestep; @@ -1581,7 +1581,7 @@ static void R_RenderSegLoop (void) { if (curline->polyseg && (ffloor[i].polyobj != curline->polyseg)) continue; - + ffloor[i].f_clip[rw_x] = ffloor[i].c_clip[rw_x] = (INT16)((ffloor[i].b_frac >> HEIGHTBITS) & 0xFFFF); ffloor[i].b_frac += ffloor[i].b_step; } @@ -1590,7 +1590,7 @@ static void R_RenderSegLoop (void) topfrac += topstep; bottomfrac += bottomstep; } - + //colfunc = wallcolfunc; } @@ -1690,7 +1690,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) while (need > maxopenings); openings = Z_Realloc(openings, maxopenings * sizeof (*openings), PU_STATIC, NULL); lastopening = openings + pos; - + if (oldopenings == NULL) return; @@ -2817,7 +2817,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) R_ExpandPlane(ffloor[i].plane, rw_x, rw_stopx - 1); } } - + rw_silhouette = &(ds_p->silhouette); rw_tsilheight = &(ds_p->tsilheight); rw_bsilheight = &(ds_p->bsilheight); diff --git a/src/r_things.c b/src/r_things.c index 8872271f4..f32ae0ad2 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -897,7 +897,7 @@ static void R_DrawVisSprite(vissprite_t *vis) else { // Non-paper drawing loop - for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) + for (dc_x = vis->x1; dc_x <= vis->x2 && (frac>>FRACBITS) < patch->width; dc_x++, frac += vis->xiscale) { texturecolumn = CLAMP(frac >> FRACBITS, 0, SHORT(patch->width) - 1); column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn]));