Skip to content

Commit 5691ea6

Browse files
committed
NUKE surface sorting by fog
#1408 had removed the hacky way of drawing fog surfaces and made them into actual stages. This change removes the sorting by fog index since it now has no positive effect (and potentially has a negative one, preventing surfaces from being merged). The fognum bits are redistributed towards drawsurf indexes and entity count.
1 parent e91cb12 commit 5691ea6

File tree

6 files changed

+10
-39
lines changed

6 files changed

+10
-39
lines changed

src/engine/renderer/Material.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2036,7 +2036,7 @@ void MaterialSystem::AddAutospriteSurfaces() {
20362036
for ( const drawSurf_t &drawSurf : autospriteSurfaces )
20372037
{
20382038
R_AddDrawSurf( drawSurf.surface, drawSurf.shader,
2039-
drawSurf.lightmapNum(), drawSurf.fogNum(), drawSurf.bspSurface );
2039+
drawSurf.lightmapNum(), drawSurf.fog, drawSurf.bspSurface );
20402040
}
20412041
}
20422042

src/engine/renderer/ShadeCommon.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,6 @@ template<typename Obj> static bool hasExplicitelyDisabledLightMap( Obj* obj )
8787
return GetSurfaceShader( obj )->surfaceFlags & SURF_NOLIGHTMAP;
8888
}
8989

90-
inline size_t GetFogNum( shaderCommands_t* tess )
91-
{
92-
return tess->fogNum;
93-
}
94-
95-
inline size_t GetFogNum( drawSurf_t* drawSurf )
96-
{
97-
return drawSurf->fogNum();
98-
}
99-
10090
inline shaderStage_t* GetSurfaceLastStage( shaderCommands_t* tess )
10191
{
10292
return tess->surfaceLastStage;

src/engine/renderer/tr_backend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5446,7 +5446,7 @@ const RenderCommand *FinalisePortalCommand::ExecuteSelf( ) const
54465446
glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );
54475447

54485448
Tess_Begin( Tess_StageIteratorColor, shader,
5449-
nullptr, false, surface->lightmapNum(), surface->fogNum(), surface->bspSurface );
5449+
nullptr, false, surface->lightmapNum(), surface->fog, surface->bspSurface );
54505450
rb_surfaceTable[Util::ordinal( *( surface->surface ) )]( surface->surface );
54515451
Tess_End();
54525452

src/engine/renderer/tr_bsp.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2789,15 +2789,6 @@ static int LeafSurfaceCompare( const void *a, const void *b )
27892789
return 1;
27902790
}
27912791

2792-
if ( aa->fogIndex < bb->fogIndex )
2793-
{
2794-
return -1;
2795-
}
2796-
else if ( aa->fogIndex > bb->fogIndex )
2797-
{
2798-
return 1;
2799-
}
2800-
28012792
// sort by leaf
28022793
if ( aa->interactionBits < bb->interactionBits )
28032794
{

src/engine/renderer/tr_local.h

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,35 +1605,30 @@ enum class ssaoMode {
16051605
// 4. fogNum
16061606
// 5. index
16071607

1608-
static const uint64_t SORT_INDEX_BITS = 16;
1609-
static const uint64_t SORT_FOGNUM_BITS = 13;
1610-
static const uint64_t SORT_ENTITYNUM_BITS = 10;
1608+
static const uint64_t SORT_INDEX_BITS = 20;
1609+
static const uint64_t SORT_ENTITYNUM_BITS = 13;
16111610
static const uint64_t SORT_LIGHTMAP_BITS = 9;
16121611
static const uint64_t SORT_SHADER_BITS = 16;
1612+
static const uint64_t SORT_UNUSED_BITS = 6;
16131613

16141614
static_assert( SORT_SHADER_BITS +
16151615
SORT_LIGHTMAP_BITS +
16161616
SORT_ENTITYNUM_BITS +
1617-
SORT_FOGNUM_BITS +
1618-
SORT_INDEX_BITS == 64, "invalid number of drawSurface sort bits" );
1617+
SORT_INDEX_BITS +
1618+
SORT_UNUSED_BITS == 64, "invalid number of drawSurface sort bits" );
16191619

1620-
static const uint64_t SORT_FOGNUM_SHIFT = SORT_INDEX_BITS;
1621-
static const uint64_t SORT_ENTITYNUM_SHIFT = SORT_FOGNUM_BITS + SORT_FOGNUM_SHIFT;
1620+
static const uint64_t SORT_ENTITYNUM_SHIFT = SORT_INDEX_BITS;
16221621
static const uint64_t SORT_LIGHTMAP_SHIFT = SORT_ENTITYNUM_BITS + SORT_ENTITYNUM_SHIFT;
16231622
static const uint64_t SORT_SHADER_SHIFT = SORT_LIGHTMAP_BITS + SORT_LIGHTMAP_SHIFT;
16241623

16251624
#define MASKBITS( b ) ( 1 << (b) ) - 1
16261625
static const uint32_t SORT_INDEX_MASK = MASKBITS( SORT_INDEX_BITS );
1627-
static const uint32_t SORT_FOGNUM_MASK = MASKBITS( SORT_FOGNUM_BITS );
16281626
static const uint32_t SORT_ENTITYNUM_MASK = MASKBITS( SORT_ENTITYNUM_BITS );
16291627
static const uint32_t SORT_LIGHTMAP_MASK = MASKBITS( SORT_LIGHTMAP_BITS );
16301628
static const uint32_t SORT_SHADER_MASK = MASKBITS( SORT_SHADER_BITS );
16311629

16321630
static_assert( SORT_INDEX_MASK >= MAX_DRAWSURFS - 1, "not enough index bits" );
16331631

1634-
// need space for 0 fog (no fog), in addition to MAX_MAP_FOGS
1635-
static_assert( SORT_FOGNUM_MASK >= MAX_MAP_FOGS, "not enough fognum bits" );
1636-
16371632
// need space for tr.worldEntity, in addition to MAX_REF_ENTITIES
16381633
static_assert( SORT_ENTITYNUM_MASK >= MAX_REF_ENTITIES, "not enough entity bits" );
16391634

@@ -1652,7 +1647,6 @@ enum class ssaoMode {
16521647
int fog;
16531648
int portalNum = -1;
16541649

1655-
16561650
uint32_t materialPackIDs[MAX_SHADER_STAGES];
16571651
uint32_t materialIDs[MAX_SHADER_STAGES];
16581652

@@ -1671,21 +1665,17 @@ enum class ssaoMode {
16711665
inline int entityNum() const {
16721666
return int( ( sort >> SORT_ENTITYNUM_SHIFT ) & SORT_ENTITYNUM_MASK ) - 1;
16731667
}
1674-
inline int fogNum() const {
1675-
return int( ( sort >> SORT_FOGNUM_SHIFT ) & SORT_FOGNUM_MASK );
1676-
}
16771668
inline int lightmapNum() const {
16781669
return int( ( sort >> SORT_LIGHTMAP_SHIFT ) & SORT_LIGHTMAP_MASK ) - 1;
16791670
}
16801671
inline int shaderNum() const {
16811672
return int( sort >> SORT_SHADER_SHIFT );
16821673
}
16831674

1684-
inline void setSort( int shaderNum, int lightmapNum, int entityNum, int fogNum, int index ) {
1675+
inline void setSort( int shaderNum, int lightmapNum, int entityNum, int index ) {
16851676
entityNum = entityNum + 1; //world entity is -1
16861677
lightmapNum = lightmapNum + 1; //no lightmap is -1
16871678
sort = uint64_t( index & SORT_INDEX_MASK ) |
1688-
( uint64_t( fogNum & SORT_FOGNUM_MASK ) << SORT_FOGNUM_SHIFT ) |
16891679
( uint64_t( entityNum & SORT_ENTITYNUM_MASK ) << SORT_ENTITYNUM_SHIFT ) |
16901680
( uint64_t( lightmapNum & SORT_LIGHTMAP_MASK ) << SORT_LIGHTMAP_SHIFT ) |
16911681
( uint64_t( shaderNum & SORT_SHADER_MASK ) << SORT_SHADER_SHIFT );

src/engine/renderer/tr_main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1882,7 +1882,7 @@ int R_AddDrawSurf( surfaceType_t *surface, shader_t *shader, int lightmapNum, in
18821882
index = MAX_DRAWSURFS - index; // reverse the sorting (front:back -> back:front)
18831883
}
18841884

1885-
drawSurf->setSort( shader->sortedIndex, lightmapNum, entityNum, fogNum, index );
1885+
drawSurf->setSort( shader->sortedIndex, lightmapNum, entityNum, index );
18861886

18871887
tr.refdef.numDrawSurfs++;
18881888

0 commit comments

Comments
 (0)