From dbe32317b223e1faf55d452ec068979f5ce50308 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 23 Jun 2025 20:08:04 +0200 Subject: [PATCH] allocate tiltlighting buffer in R_AllocViewMemory again just removes the ugly stuff in the span drawers needs to be tested a little, but should be fine --- src/r_draw.cpp | 27 ++++++++++++++++++++++++++- src/r_draw_span.cpp | 31 ------------------------------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/r_draw.cpp b/src/r_draw.cpp index e399fab0e..833e64ec2 100644 --- a/src/r_draw.cpp +++ b/src/r_draw.cpp @@ -34,6 +34,10 @@ #include "hardware/hw_main.h" #endif +#ifdef HAVE_THREADS +#include "core/thread_pool.h" +#endif + // ========================================================================== // COMMON DATA FOR 8bpp AND 16bpp // ========================================================================== @@ -77,7 +81,19 @@ floatv3_t *ds_su, *ds_sv, *ds_sz; float focallengthf; // For, uh, tilted lighting, duh. -//static INT32 *tiltlighting; +#ifdef HAVE_THREADS +#ifdef _WIN32 +#include +#define local_for_thread static __thread +#else +#include +#define local_for_thread thread_local static +#endif +#else +#define local_for_thread static +#endif + +local_for_thread INT32 *tiltlighting; // -------------------------------------------- // c drawer routines @@ -470,6 +486,15 @@ static void R_AllocViewMemory(void) xtoviewangle = static_cast(Z_Realloc(xtoviewangle, sizeof(*xtoviewangle) * (viewwidth + 1), PU_STATIC, NULL)); + auto init_tiltlighting = [] { + tiltlighting = static_cast(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); // dont use Zone memory since its not thread safe + }; + + init_tiltlighting(); +#ifdef HAVE_THREADS + srb2::g_main_threadpool->for_each(std::move(init_tiltlighting)); +#endif + R_AllocSegMemory(); R_AllocClipSegMemory(); R_AllocPlaneMemory(); diff --git a/src/r_draw_span.cpp b/src/r_draw_span.cpp index bd74b4f83..833b5c1eb 100644 --- a/src/r_draw_span.cpp +++ b/src/r_draw_span.cpp @@ -13,18 +13,6 @@ /// \brief span drawer functions /// \note no includes because this is included as part of r_draw.cpp -#ifdef HAVE_THREADS -#ifdef _WIN32 -#include -#define local_for_thread static __thread -#else -#include -#define local_for_thread thread_local static -#endif -#else -#define local_for_thread static -#endif - // ========================================================================== // SPANS // ========================================================================== @@ -210,15 +198,6 @@ static void R_DrawTiltedSpanTemplate(drawspandata_t* ds) float endz, endu, endv; UINT32 stepu, stepv; UINT32 bit; - local_for_thread INT32 *tiltlighting = NULL; - local_for_thread INT32 oldviewwidth = 0; - - // dont realloc every frame pls thx - if (tiltlighting == NULL || oldviewwidth != viewwidth) - { - tiltlighting = static_cast(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); - oldviewwidth = viewwidth; - } INT32 x1 = ds->x1; const INT32 nflatxshift = ds->nflatxshift; @@ -411,16 +390,6 @@ void R_DrawFogSpan_Tilted(drawspandata_t* ds) float iz = ds->szp.z + ds->szp.y*(centery-ds->y) + ds->szp.x*(ds->x1-centerx); UINT8 *dest; - local_for_thread INT32 *tiltlighting = NULL; - local_for_thread INT32 oldviewwidth = 0; - - // dont realloc every frame pls thx - if (tiltlighting == NULL || oldviewwidth != viewwidth) - { - tiltlighting = static_cast(realloc(tiltlighting, sizeof(*tiltlighting) * viewwidth)); - oldviewwidth = viewwidth; - } - dest = R_Address(ds->x1, ds->y); const INT32 stride = vid.width;