HACK: abuse batching system for sprites and drawnodes
use batching system without sorting for order sensitive things like sprites and transparent stuff even despite not being "optimally" sorted, drawing them in one go, instead of directly still gives a nice speed increase in certain cases (on my ryzen 5600 i get around 120fps+ on teiai towers starting area!)
This commit is contained in:
1 parent
0fef290858
commit
0adf356325
3 files changed
+29
-10
No files matched your search
@@ -236,7 +236,7 @@ static int comparePolygonsNoShaders(const void *p1, const void *p2)
|
||||
|
||||
// This function organizes the geometry collected by HWR_ProcessPolygon calls into batches and uses
|
||||
// the rendering backend to draw them.
|
||||
void HWR_RenderBatches(void)
|
||||
void HWR_RenderBatches(boolean sort)
|
||||
{
|
||||
int finalVertexWritePos = 0; // position in finalVertexArray
|
||||
int finalIndexWritePos = 0; // position in finalVertexIndexArray
|
||||
@@ -287,10 +287,15 @@ void HWR_RenderBatches(void)
|
||||
polygonArraySorted[i] = &polygonArray[i];
|
||||
}
|
||||
|
||||
// sort polygons
|
||||
PS_START_TIMING(ps_hw_batchsorttime);
|
||||
qs22j(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), (useshader ? comparePolygons : comparePolygonsNoShaders));
|
||||
PS_STOP_TIMING(ps_hw_batchsorttime);
|
||||
if (sort)
|
||||
{
|
||||
// sort polygons
|
||||
PS_START_TIMING(ps_hw_batchsorttime);
|
||||
qs22j(polygonArraySorted, polygonArraySize, sizeof(PolygonArrayEntry *), (useshader ? comparePolygons : comparePolygonsNoShaders));
|
||||
PS_STOP_TIMING(ps_hw_batchsorttime);
|
||||
}
|
||||
else
|
||||
ps_hw_batchsorttime.value.p = 0;
|
||||
|
||||
// sort order
|
||||
// 1. shader
|
||||
@@ -299,7 +304,9 @@ void HWR_RenderBatches(void)
|
||||
// 4. colors + light level
|
||||
// not sure about what order of the last 2 should be, or if it even matters
|
||||
|
||||
PS_START_TIMING(ps_hw_batchdrawtime);
|
||||
// dont overwrite this on consecutive calls
|
||||
if (!sort)
|
||||
PS_START_TIMING(ps_hw_batchdrawtime);
|
||||
|
||||
currentShader = polygonArraySorted[0]->shader;
|
||||
currentTexture = polygonArraySorted[0]->texture;
|
||||
@@ -494,7 +501,8 @@ void HWR_RenderBatches(void)
|
||||
polygonArraySize = 0;
|
||||
unsortedVertexArraySize = 0;
|
||||
|
||||
PS_STOP_TIMING(ps_hw_batchdrawtime);
|
||||
if (!sort)
|
||||
PS_STOP_TIMING(ps_hw_batchdrawtime);
|
||||
}
|
||||
|
||||
#endif // HWRENDER
|
||||
@@ -37,7 +37,7 @@ typedef struct
|
||||
void HWR_StartBatching(void);
|
||||
void HWR_SetCurrentTexture(GLMipmap_t *texture);
|
||||
void HWR_ProcessPolygon(FSurfaceInfo *pSurf, FOutVector *pOutVerts, FUINT iNumPts, FBITFIELD PolyFlags, int shader, boolean horizonSpecial);
|
||||
void HWR_RenderBatches(void);
|
||||
void HWR_RenderBatches(boolean sort);
|
||||
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
|
||||
@@ -4383,6 +4383,9 @@ static void HWR_RenderDrawNodes(void)
|
||||
// Okay! Let's draw it all! Woo!
|
||||
GL_SetTransform(&atransform);
|
||||
|
||||
if (LIKELY(cv_glbatching.value))
|
||||
HWR_StartBatching();
|
||||
|
||||
for (i = 0; i < numdrawnodes; i++)
|
||||
{
|
||||
gl_drawnode_t *drawnode = &drawnodes[sortindex[i]];
|
||||
@@ -4434,6 +4437,9 @@ static void HWR_RenderDrawNodes(void)
|
||||
}
|
||||
}
|
||||
|
||||
if (LIKELY(cv_glbatching.value))
|
||||
HWR_RenderBatches(false);
|
||||
|
||||
PS_STOP_TIMING(ps_hw_nodedrawtime);
|
||||
|
||||
drawnodes.clear(); // clear so our size is 0 again!
|
||||
@@ -5390,6 +5396,7 @@ void HWR_SetTransform(float fpov)
|
||||
void HWR_ClearClipper(void)
|
||||
{
|
||||
const angle_t a1 = gld_FrustumAngle(gl_aimingangle);
|
||||
|
||||
gld_clipper_Clear();
|
||||
gld_clipper_SafeAddClipRange(viewangle + a1, viewangle - a1);
|
||||
#ifdef HAVE_SPHEREFRUSTRUM
|
||||
@@ -5472,7 +5479,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_
|
||||
{
|
||||
if (allow_portals && rootportal)
|
||||
{
|
||||
HWR_PortalFrame(rootportal);// for portalclipsector, it could have gone null from search
|
||||
HWR_PortalFrame(rootportal); // for portalclipsector, it could have gone null from search
|
||||
HWR_PortalClipping(rootportal);
|
||||
}
|
||||
}
|
||||
@@ -5522,7 +5529,7 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_
|
||||
PS_STOP_TIMING(ps_bsptime);
|
||||
|
||||
if (LIKELY(cv_glbatching.value))
|
||||
HWR_RenderBatches();
|
||||
HWR_RenderBatches(true);
|
||||
|
||||
if constexpr (Type == RenderViewpointType::kPortal)
|
||||
{
|
||||
@@ -5546,10 +5553,14 @@ void HWR_RenderViewpoint(gl_portal_t *rootportal, player_t *player, int stencil_
|
||||
HWR_SortVisSprites();
|
||||
PS_STOP_TIMING(ps_hw_spritesorttime);
|
||||
PS_START_TIMING(ps_hw_spritedrawtime);
|
||||
if (LIKELY(cv_glbatching.value))
|
||||
HWR_StartBatching();
|
||||
if (UNLIKELY(cv_glmdls.value))
|
||||
HWR_DrawSprites<DrawSpritesType::kModels>();
|
||||
else
|
||||
HWR_DrawSprites<DrawSpritesType::kSprites>();
|
||||
if (LIKELY(cv_glbatching.value))
|
||||
HWR_RenderBatches(false);
|
||||
PS_STOP_TIMING(ps_hw_spritedrawtime);
|
||||
|
||||
ps_numdrawnodes.value.i = 0;
|
||||
|
||||
Reference in new issue
Block a user