mirror of
https://github.com/ZDoom/qzdoom.git
synced 2024-11-24 21:11:39 +00:00
Move frame memory allocator into RenderThread
This commit is contained in:
parent
627a388d57
commit
45f623faf4
17 changed files with 49 additions and 44 deletions
|
@ -335,7 +335,7 @@ namespace swrenderer
|
|||
|
||||
RenderPortal *renderportal = Thread->Portal.get();
|
||||
|
||||
DrawSegment *draw_segment = RenderMemory::NewObject<DrawSegment>();
|
||||
DrawSegment *draw_segment = Thread->FrameMemory->NewObject<DrawSegment>();
|
||||
Thread->DrawSegments->Push(draw_segment);
|
||||
|
||||
draw_segment->CurrentPortalUniq = renderportal->CurrentPortalUniq;
|
||||
|
@ -373,8 +373,8 @@ namespace swrenderer
|
|||
}
|
||||
else if (backsector == NULL)
|
||||
{
|
||||
draw_segment->sprtopclip = RenderMemory::AllocMemory<short>(stop - start);
|
||||
draw_segment->sprbottomclip = RenderMemory::AllocMemory<short>(stop - start);
|
||||
draw_segment->sprtopclip = Thread->FrameMemory->AllocMemory<short>(stop - start);
|
||||
draw_segment->sprbottomclip = Thread->FrameMemory->AllocMemory<short>(stop - start);
|
||||
fillshort(draw_segment->sprtopclip, stop - start, viewheight);
|
||||
memset(draw_segment->sprbottomclip, -1, (stop - start) * sizeof(short));
|
||||
draw_segment->silhouette = SIL_BOTH;
|
||||
|
@ -407,13 +407,13 @@ namespace swrenderer
|
|||
{
|
||||
if (doorclosed || (rw_backcz1 <= rw_frontfz1 && rw_backcz2 <= rw_frontfz2))
|
||||
{
|
||||
draw_segment->sprbottomclip = RenderMemory::AllocMemory<short>(stop - start);
|
||||
draw_segment->sprbottomclip = Thread->FrameMemory->AllocMemory<short>(stop - start);
|
||||
memset(draw_segment->sprbottomclip, -1, (stop - start) * sizeof(short));
|
||||
draw_segment->silhouette |= SIL_BOTTOM;
|
||||
}
|
||||
if (doorclosed || (rw_backfz1 >= rw_frontcz1 && rw_backfz2 >= rw_frontcz2))
|
||||
{ // killough 1/17/98, 2/8/98
|
||||
draw_segment->sprtopclip = RenderMemory::AllocMemory<short>(stop - start);
|
||||
draw_segment->sprtopclip = Thread->FrameMemory->AllocMemory<short>(stop - start);
|
||||
fillshort(draw_segment->sprtopclip, stop - start, viewheight);
|
||||
draw_segment->silhouette |= SIL_TOP;
|
||||
}
|
||||
|
@ -453,7 +453,7 @@ namespace swrenderer
|
|||
maskedtexture = true;
|
||||
|
||||
// kg3D - backup for mid and fake walls
|
||||
draw_segment->bkup = RenderMemory::AllocMemory<short>(stop - start);
|
||||
draw_segment->bkup = Thread->FrameMemory->AllocMemory<short>(stop - start);
|
||||
memcpy(draw_segment->bkup, &Thread->OpaquePass->ceilingclip[start], sizeof(short)*(stop - start));
|
||||
|
||||
draw_segment->bFogBoundary = IsFogBoundary(frontsector, backsector);
|
||||
|
@ -462,8 +462,8 @@ namespace swrenderer
|
|||
if (sidedef->GetTexture(side_t::mid).isValid())
|
||||
draw_segment->bFakeBoundary |= 4; // it is also mid texture
|
||||
|
||||
draw_segment->maskedtexturecol = RenderMemory::AllocMemory<fixed_t>(stop - start);
|
||||
draw_segment->swall = RenderMemory::AllocMemory<float>(stop - start);
|
||||
draw_segment->maskedtexturecol = Thread->FrameMemory->AllocMemory<fixed_t>(stop - start);
|
||||
draw_segment->swall = Thread->FrameMemory->AllocMemory<float>(stop - start);
|
||||
|
||||
lwal = draw_segment->maskedtexturecol;
|
||||
swal = draw_segment->swall;
|
||||
|
@ -563,13 +563,13 @@ namespace swrenderer
|
|||
// save sprite clipping info
|
||||
if (((draw_segment->silhouette & SIL_TOP) || maskedtexture) && draw_segment->sprtopclip == nullptr)
|
||||
{
|
||||
draw_segment->sprtopclip = RenderMemory::AllocMemory<short>(stop - start);
|
||||
draw_segment->sprtopclip = Thread->FrameMemory->AllocMemory<short>(stop - start);
|
||||
memcpy(draw_segment->sprtopclip, &Thread->OpaquePass->ceilingclip[start], sizeof(short)*(stop - start));
|
||||
}
|
||||
|
||||
if (((draw_segment->silhouette & SIL_BOTTOM) || maskedtexture) && draw_segment->sprbottomclip == nullptr)
|
||||
{
|
||||
draw_segment->sprbottomclip = RenderMemory::AllocMemory<short>(stop - start);
|
||||
draw_segment->sprbottomclip = Thread->FrameMemory->AllocMemory<short>(stop - start);
|
||||
memcpy(draw_segment->sprbottomclip, &Thread->OpaquePass->floorclip[start], sizeof(short)*(stop - start));
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
#include "g_level.h"
|
||||
#include "gl/dynlights/gl_dynlight.h"
|
||||
#include "swrenderer/r_memory.h"
|
||||
#include "swrenderer/r_renderthread.h"
|
||||
#include "swrenderer/scene/r_opaque_pass.h"
|
||||
#include "swrenderer/scene/r_3dfloors.h"
|
||||
#include "swrenderer/scene/r_portal.h"
|
||||
|
@ -43,19 +44,19 @@ CVAR(Bool, tilt, false, 0);
|
|||
|
||||
namespace swrenderer
|
||||
{
|
||||
VisiblePlane::VisiblePlane()
|
||||
VisiblePlane::VisiblePlane(RenderThread *thread)
|
||||
{
|
||||
picnum.SetNull();
|
||||
height.set(0.0, 0.0, 1.0, 0.0);
|
||||
|
||||
bottom = RenderMemory::AllocMemory<uint16_t>(viewwidth);
|
||||
top = RenderMemory::AllocMemory<uint16_t>(viewwidth);
|
||||
bottom = thread->FrameMemory->AllocMemory<uint16_t>(viewwidth);
|
||||
top = thread->FrameMemory->AllocMemory<uint16_t>(viewwidth);
|
||||
|
||||
fillshort(bottom, viewwidth, 0);
|
||||
fillshort(top, viewwidth, 0x7fff);
|
||||
}
|
||||
|
||||
void VisiblePlane::AddLights(FLightNode *node)
|
||||
void VisiblePlane::AddLights(RenderThread *thread, FLightNode *node)
|
||||
{
|
||||
if (!r_dynlights)
|
||||
return;
|
||||
|
@ -77,7 +78,7 @@ namespace swrenderer
|
|||
}
|
||||
if (!found)
|
||||
{
|
||||
VisiblePlaneLight *newlight = RenderMemory::NewObject<VisiblePlaneLight>();
|
||||
VisiblePlaneLight *newlight = thread->FrameMemory->NewObject<VisiblePlaneLight>();
|
||||
newlight->next = lights;
|
||||
newlight->lightsource = node->lightsource;
|
||||
lights = newlight;
|
||||
|
|
|
@ -35,9 +35,9 @@ namespace swrenderer
|
|||
|
||||
struct VisiblePlane
|
||||
{
|
||||
VisiblePlane();
|
||||
VisiblePlane(RenderThread *thread);
|
||||
|
||||
void AddLights(FLightNode *node);
|
||||
void AddLights(RenderThread *thread, FLightNode *node);
|
||||
void Render(RenderThread *thread, fixed_t alpha, bool additive, bool masked);
|
||||
|
||||
VisiblePlane *next = nullptr; // Next visplane in hash chain -- killough
|
||||
|
|
|
@ -58,7 +58,7 @@ namespace swrenderer
|
|||
|
||||
VisiblePlane *VisiblePlaneList::Add(unsigned hash)
|
||||
{
|
||||
VisiblePlane *newplane = RenderMemory::NewObject<VisiblePlane>();
|
||||
VisiblePlane *newplane = Thread->FrameMemory->NewObject<VisiblePlane>(Thread);
|
||||
newplane->next = visplanes[hash];
|
||||
visplanes[hash] = newplane;
|
||||
return newplane;
|
||||
|
|
|
@ -68,7 +68,4 @@ namespace swrenderer
|
|||
FreeBlocks.push_back(std::move(block));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::unique_ptr<RenderMemory::MemoryBlock>> RenderMemory::UsedBlocks;
|
||||
std::vector<std::unique_ptr<RenderMemory::MemoryBlock>> RenderMemory::FreeBlocks;
|
||||
}
|
||||
|
|
|
@ -21,23 +21,23 @@ namespace swrenderer
|
|||
class RenderMemory
|
||||
{
|
||||
public:
|
||||
static void Clear();
|
||||
void Clear();
|
||||
|
||||
template<typename T>
|
||||
static T *AllocMemory(int size = 1)
|
||||
T *AllocMemory(int size = 1)
|
||||
{
|
||||
return (T*)AllocBytes(sizeof(T) * size);
|
||||
}
|
||||
|
||||
template<typename T, typename... Types>
|
||||
static T *NewObject(Types &&... args)
|
||||
T *NewObject(Types &&... args)
|
||||
{
|
||||
void *ptr = AllocBytes(sizeof(T));
|
||||
return new (ptr)T(std::forward<Types>(args)...);
|
||||
}
|
||||
|
||||
private:
|
||||
static void *AllocBytes(int size);
|
||||
void *AllocBytes(int size);
|
||||
|
||||
enum { BlockSize = 1024 * 1024 };
|
||||
|
||||
|
@ -52,7 +52,7 @@ namespace swrenderer
|
|||
uint8_t *Data;
|
||||
uint32_t Position;
|
||||
};
|
||||
static std::vector<std::unique_ptr<MemoryBlock>> UsedBlocks;
|
||||
static std::vector<std::unique_ptr<MemoryBlock>> FreeBlocks;
|
||||
std::vector<std::unique_ptr<MemoryBlock>> UsedBlocks;
|
||||
std::vector<std::unique_ptr<MemoryBlock>> FreeBlocks;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -47,11 +47,13 @@
|
|||
#include "swrenderer/plane/r_visibleplanelist.h"
|
||||
#include "swrenderer/segments/r_drawsegment.h"
|
||||
#include "swrenderer/segments/r_clipsegment.h"
|
||||
#include "r_memory.h"
|
||||
|
||||
namespace swrenderer
|
||||
{
|
||||
RenderThread::RenderThread()
|
||||
{
|
||||
FrameMemory = std::make_unique<RenderMemory>();
|
||||
OpaquePass = std::make_unique<RenderOpaquePass>(this);
|
||||
TranslucentPass = std::make_unique<RenderTranslucentPass>(this);
|
||||
SpriteList = std::make_unique<VisibleSpriteList>();
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace swrenderer
|
|||
class VisiblePlaneList;
|
||||
class DrawSegmentList;
|
||||
class RenderClipSegment;
|
||||
class RenderMemory;
|
||||
|
||||
class RenderThread
|
||||
{
|
||||
|
@ -43,6 +44,7 @@ namespace swrenderer
|
|||
RenderThread();
|
||||
~RenderThread();
|
||||
|
||||
std::unique_ptr<RenderMemory> FrameMemory;
|
||||
std::unique_ptr<RenderOpaquePass> OpaquePass;
|
||||
std::unique_ptr<RenderTranslucentPass> TranslucentPass;
|
||||
std::unique_ptr<VisibleSpriteList> SpriteList;
|
||||
|
|
|
@ -519,7 +519,7 @@ namespace swrenderer
|
|||
) : nullptr;
|
||||
|
||||
if (ceilingplane)
|
||||
ceilingplane->AddLights(frontsector->lighthead);
|
||||
ceilingplane->AddLights(Thread, frontsector->lighthead);
|
||||
|
||||
if (cameraLight->FixedLightLevel() < 0 && frontsector->e && frontsector->e->XFloor.lightlist.Size())
|
||||
{
|
||||
|
@ -560,7 +560,7 @@ namespace swrenderer
|
|||
) : nullptr;
|
||||
|
||||
if (floorplane)
|
||||
floorplane->AddLights(frontsector->lighthead);
|
||||
floorplane->AddLights(Thread, frontsector->lighthead);
|
||||
|
||||
// kg3D - fake planes rendering
|
||||
if (r_3dfloors && frontsector->e && frontsector->e->XFloor.ffloors.Size())
|
||||
|
@ -625,7 +625,7 @@ namespace swrenderer
|
|||
basecolormap);
|
||||
|
||||
if (floorplane)
|
||||
floorplane->AddLights(frontsector->lighthead);
|
||||
floorplane->AddLights(Thread, frontsector->lighthead);
|
||||
|
||||
FakeDrawLoop(sub, floorplane, ceilingplane, foggy, basecolormap);
|
||||
clip3d->fake3D = 0;
|
||||
|
@ -691,7 +691,7 @@ namespace swrenderer
|
|||
basecolormap);
|
||||
|
||||
if (ceilingplane)
|
||||
ceilingplane->AddLights(frontsector->lighthead);
|
||||
ceilingplane->AddLights(Thread, frontsector->lighthead);
|
||||
|
||||
FakeDrawLoop(sub, floorplane, ceilingplane, foggy, basecolormap);
|
||||
clip3d->fake3D = 0;
|
||||
|
|
|
@ -186,7 +186,7 @@ namespace swrenderer
|
|||
}
|
||||
|
||||
// Create a drawseg to clip sprites to the sky plane
|
||||
DrawSegment *draw_segment = RenderMemory::NewObject<DrawSegment>();
|
||||
DrawSegment *draw_segment = Thread->FrameMemory->NewObject<DrawSegment>();
|
||||
draw_segment->CurrentPortalUniq = CurrentPortalUniq;
|
||||
draw_segment->siz1 = INT_MAX;
|
||||
draw_segment->siz2 = INT_MAX;
|
||||
|
@ -195,8 +195,8 @@ namespace swrenderer
|
|||
draw_segment->x1 = pl->left;
|
||||
draw_segment->x2 = pl->right;
|
||||
draw_segment->silhouette = SIL_BOTH;
|
||||
draw_segment->sprbottomclip = RenderMemory::AllocMemory<short>(pl->right - pl->left);
|
||||
draw_segment->sprtopclip = RenderMemory::AllocMemory<short>(pl->right - pl->left);
|
||||
draw_segment->sprbottomclip = Thread->FrameMemory->AllocMemory<short>(pl->right - pl->left);
|
||||
draw_segment->sprtopclip = Thread->FrameMemory->AllocMemory<short>(pl->right - pl->left);
|
||||
draw_segment->maskedtexturecol = nullptr;
|
||||
draw_segment->swall = nullptr;
|
||||
draw_segment->bFogBoundary = false;
|
||||
|
@ -526,7 +526,7 @@ namespace swrenderer
|
|||
|
||||
void RenderPortal::AddLinePortal(line_t *linedef, int x1, int x2, const short *topclip, const short *bottomclip)
|
||||
{
|
||||
WallPortals.Push(RenderMemory::NewObject<PortalDrawseg>(linedef, x1, x2, topclip, bottomclip));
|
||||
WallPortals.Push(Thread->FrameMemory->NewObject<PortalDrawseg>(Thread, linedef, x1, x2, topclip, bottomclip));
|
||||
}
|
||||
}
|
||||
/*
|
||||
|
|
|
@ -113,7 +113,7 @@ namespace swrenderer
|
|||
MaskedCycles.Reset();
|
||||
WallScanCycles.Reset();
|
||||
|
||||
RenderMemory::Clear();
|
||||
Thread->FrameMemory->Clear();
|
||||
|
||||
Clip3DFloors *clip3d = Thread->Clip3DFloors.get();
|
||||
clip3d->Cleanup();
|
||||
|
|
|
@ -32,17 +32,18 @@
|
|||
#include "r_data/colormaps.h"
|
||||
#include "swrenderer/segments/r_portalsegment.h"
|
||||
#include "swrenderer/r_memory.h"
|
||||
#include "swrenderer/r_renderthread.h"
|
||||
|
||||
namespace swrenderer
|
||||
{
|
||||
PortalDrawseg::PortalDrawseg(line_t *linedef, int x1, int x2, const short *topclip, const short *bottomclip) : x1(x1), x2(x2)
|
||||
PortalDrawseg::PortalDrawseg(RenderThread *thread, line_t *linedef, int x1, int x2, const short *topclip, const short *bottomclip) : x1(x1), x2(x2)
|
||||
{
|
||||
src = linedef;
|
||||
dst = linedef->special == Line_Mirror ? linedef : linedef->getPortalDestination();
|
||||
len = x2 - x1;
|
||||
|
||||
ceilingclip = RenderMemory::AllocMemory<short>(len);
|
||||
floorclip = RenderMemory::AllocMemory<short>(len);
|
||||
ceilingclip = thread->FrameMemory->AllocMemory<short>(len);
|
||||
floorclip = thread->FrameMemory->AllocMemory<short>(len);
|
||||
memcpy(ceilingclip, topclip, len * sizeof(short));
|
||||
memcpy(floorclip, bottomclip, len * sizeof(short));
|
||||
|
||||
|
|
|
@ -15,10 +15,12 @@
|
|||
|
||||
namespace swrenderer
|
||||
{
|
||||
class RenderThread;
|
||||
|
||||
/* portal structure, this is used in r_ code in order to store drawsegs with portals (and mirrors) */
|
||||
struct PortalDrawseg
|
||||
{
|
||||
PortalDrawseg(line_t *linedef, int x1, int x2, const short *topclip, const short *bottomclip);
|
||||
PortalDrawseg(RenderThread *thread, line_t *linedef, int x1, int x2, const short *topclip, const short *bottomclip);
|
||||
|
||||
line_t* src = nullptr; // source line (the one drawn) this doesn't change over render loops
|
||||
line_t* dst = nullptr; // destination line (the one that the portal is linked with, equals 'src' for mirrors)
|
||||
|
|
|
@ -182,7 +182,7 @@ namespace swrenderer
|
|||
return;
|
||||
|
||||
// store information in a vissprite
|
||||
RenderParticle *vis = RenderMemory::NewObject<RenderParticle>();
|
||||
RenderParticle *vis = thread->FrameMemory->NewObject<RenderParticle>();
|
||||
|
||||
vis->CurrentPortalUniq = renderportal->CurrentPortalUniq;
|
||||
vis->heightsec = heightsec;
|
||||
|
|
|
@ -159,7 +159,7 @@ namespace swrenderer
|
|||
double yscale = spriteScale.Y / tex->Scale.Y;
|
||||
|
||||
// store information in a vissprite
|
||||
RenderSprite *vis = RenderMemory::NewObject<RenderSprite>();
|
||||
RenderSprite *vis = thread->FrameMemory->NewObject<RenderSprite>();
|
||||
|
||||
vis->CurrentPortalUniq = renderportal->CurrentPortalUniq;
|
||||
vis->xscale = FLOAT2FIXED(xscale);
|
||||
|
|
|
@ -107,7 +107,7 @@ namespace swrenderer
|
|||
}
|
||||
}
|
||||
|
||||
RenderVoxel *vis = RenderMemory::NewObject<RenderVoxel>();
|
||||
RenderVoxel *vis = thread->FrameMemory->NewObject<RenderVoxel>();
|
||||
|
||||
vis->CurrentPortalUniq = renderportal->CurrentPortalUniq;
|
||||
vis->xscale = FLOAT2FIXED(xscale);
|
||||
|
|
|
@ -105,7 +105,7 @@ namespace swrenderer
|
|||
gzt = pos.Z + scale.Y * scaled_to;
|
||||
gzb = pos.Z + scale.Y * scaled_bo;
|
||||
|
||||
RenderWallSprite *vis = RenderMemory::NewObject<RenderWallSprite>();
|
||||
RenderWallSprite *vis = thread->FrameMemory->NewObject<RenderWallSprite>();
|
||||
vis->CurrentPortalUniq = renderportal->CurrentPortalUniq;
|
||||
vis->x1 = wallc.sx1 < renderportal->WindowLeft ? renderportal->WindowLeft : wallc.sx1;
|
||||
vis->x2 = wallc.sx2 >= renderportal->WindowRight ? renderportal->WindowRight : wallc.sx2;
|
||||
|
|
Loading…
Reference in a new issue