Skip to content

Commit

Permalink
Realign msurfacelighting_t to 32byte boundary(minor perf boost); re-e…
Browse files Browse the repository at this point in the history
…nable mat_updatelightstyleseveryframe convar; some debug build fixes(gcc12?); change dlight_debug to have 4 lights(max per surface)
  • Loading branch information
LWSS committed Sep 5, 2022
1 parent 7df358a commit 4c2fdc3
Show file tree
Hide file tree
Showing 13 changed files with 178 additions and 97 deletions.
2 changes: 1 addition & 1 deletion appframework/glmdisplaydb_linuxwin.inl
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ void GLMDisplayInfo::Dump( int which )
SDLAPP_FUNC;

GLMPRINTF(("\n #%d: GLMDisplayInfo @ %08x, pixwidth=%d pixheight=%d",
which, (int)this, m_info.m_displayPixelWidth, m_info.m_displayPixelHeight ));
which, (uintptr_t)this, m_info.m_displayPixelWidth, m_info.m_displayPixelHeight ));

FOR_EACH_VEC( *m_modes, i )
{
Expand Down
2 changes: 1 addition & 1 deletion cmake/source_posix_base.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ set(LINUX_DEBUG_FLAGS " -ggdb -g3 -fno-eliminate-unused-debug-symbols ")
#$Configuration "Debug"
if (CMAKE_BUILD_TYPE STREQUAL "DEBUG")
message(STATUS "Building in Debug mode")
add_definitions(-DBASE -DDEBUG -D_DEBUG)
add_definitions(-DBASE -DDEBUG -D_DEBUG -DDBGFLAG_ASSERT)
if( OSXALL )
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -gdwarf-2 -g2 -Og -march=native")
elseif( LINUXALL )
Expand Down
159 changes: 85 additions & 74 deletions engine/gl_lightmap.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
Expand Down Expand Up @@ -1594,16 +1594,21 @@ unsigned int R_UpdateDlightState( dlight_t *pLights, SurfaceHandle_t surfID, con
if ( !bOnlyUseLightStyles )
{
// add all the dynamic lights
if( bLightmap && ( pLighting->m_nDLightFrame == r_framecount ) )
// lwss add: hack this so we can restore 32-byte alignment
//if( bLightmap && ( pLighting->m_nDLightFrame == r_framecount ) )
if( bLightmap && ( pLighting->m_wantsDlightThisFrame) )
{
dlightMask = R_ComputeDynamicLightMask( pLights, surfID, pLighting, entityToWorld );
}

// if there was no dlight after adding, remove/disable
if ( !dlightMask || !pLighting->m_fDLightBits )
{
pLighting->m_fDLightBits = 0;
MSurf_Flags(surfID) &= ~SURFDRAW_HASDLIGHT;
}
// lwss add: turn this off after computing the lightmask
pLighting->m_wantsDlightThisFrame = false;
}
return dlightMask;
}
Expand Down Expand Up @@ -2081,9 +2086,9 @@ void GL_RebuildLightmaps( void )
// Input : *fa - surface pointer
//-----------------------------------------------------------------------------

#ifdef UPDATE_LIGHTSTYLES_EVERY_FRAME
//#ifdef UPDATE_LIGHTSTYLES_EVERY_FRAME
ConVar mat_updatelightstyleseveryframe( "mat_updatelightstyleseveryframe", "0" );
#endif
//#endif

int __cdecl LightmapPageCompareFunc( const void *pElem0, const void *pElem1 )
{
Expand Down Expand Up @@ -2132,74 +2137,80 @@ void R_BuildLightmapUpdateList()
void R_CheckForLightmapUpdates( SurfaceHandle_t surfID, int nTransformIndex )
{
msurfacelighting_t *pLighting = SurfaceLighting( surfID );
if ( pLighting->m_nLastComputedFrame != r_framecount )
{
int nFlags = MSurf_Flags( surfID );

if( nFlags & SURFDRAW_NOLIGHT )
return;

// check for lightmap modification
bool bChanged = false;
if( nFlags & SURFDRAW_HASLIGHTSYTLES )
{
#ifdef UPDATE_LIGHTSTYLES_EVERY_FRAME
if( mat_updatelightstyleseveryframe.GetBool() && ( pLighting->m_nStyles[0] != 0 || pLighting->m_nStyles[1] != 255 ) )
{
bChanged = true;
}
#endif
for( int maps = 0; maps < MAXLIGHTMAPS && pLighting->m_nStyles[maps] != 255; maps++ )
{
if( d_lightstyleframe[pLighting->m_nStyles[maps]] > pLighting->m_nLastComputedFrame )
{
bChanged = true;
break;
}
}
}

// was it dynamic this frame (pLighting->m_nDLightFrame == r_framecount)
// or dynamic previously (pLighting->m_fDLightBits)
bool bDLightChanged = ( pLighting->m_nDLightFrame == r_framecount ) || pLighting->m_fDLightBits;
bool bOnlyUseLightStyles = false;
if ( r_dynamic.GetInt() == 0 || r_keepstyledlightmapsonly.GetBool() )
{
bOnlyUseLightStyles = true;
}
else
{
bChanged |= bDLightChanged;
}

if ( bChanged )
{
bool bNeedsBumpmap = SurfNeedsBumpedLightmaps( surfID );
bool bNeedsLightmap = SurfNeedsLightmap( surfID );

if( !bNeedsBumpmap && !bNeedsLightmap )
return;

if( materialSortInfoArray )
{
int nSortID = MSurf_MaterialSortID( surfID );
Assert( nSortID >= 0 && nSortID < g_WorldStaticMeshes.Count() );
if (( materialSortInfoArray[nSortID].lightmapPageID == MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE ) ||
( materialSortInfoArray[nSortID].lightmapPageID == MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE_BUMP ) )
{
return;
}
}
bool bDlightsInLightmap = bNeedsLightmap || bNeedsBumpmap;
unsigned int nDlightMask = R_UpdateDlightState( cl_dlights, surfID, g_LightmapTransformList[nTransformIndex].xform, bOnlyUseLightStyles, bDlightsInLightmap );


int nIndex = g_LightmapUpdateList.AddToTail();
g_LightmapUpdateList[nIndex].m_SurfHandle = surfID;
g_LightmapUpdateList[nIndex].m_nTransformIndex = nTransformIndex;
g_LightmapUpdateList[nIndex].m_nDlightMask= nDlightMask;
g_LightmapUpdateList[nIndex].m_bNeedsLightmap = bNeedsLightmap;
g_LightmapUpdateList[nIndex].m_bNeedsBumpmap = bNeedsBumpmap;
}
}
if ( pLighting->m_nLastComputedFrame == r_framecount )
return;

int nFlags = MSurf_Flags( surfID );

if( nFlags & SURFDRAW_NOLIGHT )
return;

// check for lightmap modification
bool bChanged = false;
if( nFlags & SURFDRAW_HASLIGHTSYTLES )
{
//#ifdef UPDATE_LIGHTSTYLES_EVERY_FRAME //lwss: enable this
if( mat_updatelightstyleseveryframe.GetBool() && ( pLighting->m_nStyles[0] != 0 || pLighting->m_nStyles[1] != 255 ) )
{
bChanged = true;
}
else
//#endif
{
for( int maps = 0; maps < MAXLIGHTMAPS && pLighting->m_nStyles[maps] != 255; maps++ )
{
if( d_lightstyleframe[pLighting->m_nStyles[maps]] > pLighting->m_nLastComputedFrame )
{
bChanged = true;
break;
}
}
}
}

// was it dynamic this frame (pLighting->m_nDLightFrame == r_framecount)
// or dynamic previously (pLighting->m_fDLightBits)
// lwss add: hack this so we can restore 32-byte alignment
//bool bDLightChanged = ( pLighting->m_nDLightFrame == r_framecount ) || pLighting->m_fDLightBits;
bool bDLightChanged = pLighting->m_wantsDlightThisFrame || pLighting->m_fDLightBits;

bool bOnlyUseLightStyles = false;
if ( r_dynamic.GetInt() == 0 || r_keepstyledlightmapsonly.GetBool() )
{
bOnlyUseLightStyles = true;
}
else
{
bChanged |= bDLightChanged;
}

if ( bChanged )
{
bool bNeedsBumpmap = SurfNeedsBumpedLightmaps( surfID );
bool bNeedsLightmap = SurfNeedsLightmap( surfID );

if( !bNeedsBumpmap && !bNeedsLightmap )
return;

if( materialSortInfoArray )
{
int nSortID = MSurf_MaterialSortID( surfID );
Assert( nSortID >= 0 && nSortID < g_WorldStaticMeshes.Count() );
if (( materialSortInfoArray[nSortID].lightmapPageID == MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE ) ||
( materialSortInfoArray[nSortID].lightmapPageID == MATERIAL_SYSTEM_LIGHTMAP_PAGE_WHITE_BUMP ) )
{
return;
}
}
bool bDlightsInLightmap = bNeedsLightmap || bNeedsBumpmap;
unsigned int nDlightMask = R_UpdateDlightState( cl_dlights, surfID, g_LightmapTransformList[nTransformIndex].xform, bOnlyUseLightStyles, bDlightsInLightmap );


int nIndex = g_LightmapUpdateList.AddToTail();
g_LightmapUpdateList[nIndex].m_SurfHandle = surfID;
g_LightmapUpdateList[nIndex].m_nTransformIndex = nTransformIndex;
g_LightmapUpdateList[nIndex].m_nDlightMask= nDlightMask;
g_LightmapUpdateList[nIndex].m_bNeedsLightmap = bNeedsLightmap;
g_LightmapUpdateList[nIndex].m_bNeedsBumpmap = bNeedsBumpmap;
}
}
12 changes: 7 additions & 5 deletions engine/gl_model_private.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
Expand Down Expand Up @@ -501,9 +501,10 @@ struct msurfacelighting_t
short m_LightmapExtents[2];
short m_OffsetIntoLightmapPage[2];

int m_nLastComputedFrame; // last frame the surface's lightmap was recomputed
bool m_wantsDlightThisFrame : 1; // lwss add: hack this so we can restore 32-byte alignment
unsigned int m_nLastComputedFrame : 31; // last frame the surface's lightmap was recomputed
int m_fDLightBits; // Indicates which dlights illuminates this surface.
int m_nDLightFrame; // Indicates the last frame in which dlights illuminated this surface
//int m_nDLightFrame; // Indicates the last frame in which dlights illuminated this surface

unsigned char m_nStyles[MAXLIGHTMAPS]; // index into d_lightstylevalue[] for animated lights
// no one surface can be effected by more than 4
Expand All @@ -522,6 +523,7 @@ const int WORLD_DECAL_HANDLE_INVALID = 0xFFFF;
typedef unsigned short WorldDecalHandle_t;

// NOTE: 32-bytes. Aligned/indexed often
// KISAKTODO: Align this struct back to 32-bytes (good luck)
struct msurface2_t
{
unsigned int flags; // see SURFDRAW_ #defines (only 22-bits right now)
Expand All @@ -534,9 +536,9 @@ struct msurface2_t
cplane_t* plane; // pointer to shared plane
#endif
int firstvertindex; // look up in model->vertindices[] (only uses 17-18 bits?)
WorldDecalHandle_t decals;
WorldDecalHandle_t decals; // unsigned short
ShadowDecalHandle_t m_ShadowDecals; // unsigned short
OverlayFragmentHandle_t m_nFirstOverlayFragment; // First overlay fragment on the surface (short)
OverlayFragmentHandle_t m_nFirstOverlayFragment; // First overlay fragment on the surface (unsigned short)
short materialSortID;
unsigned short vertBufferIndex;

Expand Down
10 changes: 7 additions & 3 deletions engine/gl_rlight.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
Expand Down Expand Up @@ -118,14 +118,18 @@ DYNAMIC LIGHTS
// Returns true if the surface has the specified dlight already set on it for this frame.
inline bool R_IsDLightAlreadyMarked( msurfacelighting_t *pLighting, int bit )
{
return (pLighting->m_nDLightFrame == r_framecount) && (pLighting->m_fDLightBits & bit);
// lwss add: hack this so we can restore 32-byte alignment
//return (pLighting->m_nDLightFrame == r_framecount) && (pLighting->m_fDLightBits & bit);
return (pLighting->m_wantsDlightThisFrame) && (pLighting->m_fDLightBits & bit);
}

// Mark the surface as changed by the specified dlight (so its texture gets updated when
// it comes time to render).
inline void R_MarkSurfaceDLight( SurfaceHandle_t surfID, msurfacelighting_t *pLighting, int bit)
{
pLighting->m_nDLightFrame = r_framecount;
//pLighting->m_nDLightFrame = r_framecount;
// lwss add: hack this so we can restore 32-byte alignment
pLighting->m_wantsDlightThisFrame = true;
pLighting->m_fDLightBits |= bit;
MSurf_Flags( surfID ) |= SURFDRAW_HASDLIGHT;
}
Expand Down
58 changes: 56 additions & 2 deletions game/client/c_baseentity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5396,16 +5396,44 @@ CON_COMMAND( cl_sizeof, "Determines the size of the specified client class." )

CON_COMMAND_F( dlight_debug, "Creates a dlight in front of the player", FCVAR_CHEAT )
{
dlight_t *el = effects->CL_AllocDlight( 1 );
C_BasePlayer *player = C_BasePlayer::GetLocalPlayer();
if ( !player )
return;

//lwss: added 3 more dlights to test 4x(MAX) on 1 surface
dlight_t *el = effects->CL_AllocDlight( 1 );
dlight_t *el2 = effects->CL_AllocDlight( 2 );
dlight_t *el3 = effects->CL_AllocDlight( 3 );
dlight_t *el4 = effects->CL_AllocDlight( 4 );

Vector start = player->EyePosition();
Vector forward;
player->EyeVectors( &forward );
Vector end = start + forward * MAX_TRACE_LENGTH;
// sloppy but works
Vector forward2 = forward;
forward2.x += 0.10f;
forward2.NormalizeInPlace();
Vector forward3 = forward;
forward3.x -= 0.10f;
forward2.NormalizeInPlace();
Vector forward4 = forward;
forward4.y += 0.10f;
forward4.NormalizeInPlace();

Vector end = start + forward * MAX_TRACE_LENGTH;
Vector end2 = start + forward2 * MAX_TRACE_LENGTH;
Vector end3 = start + forward3 * MAX_TRACE_LENGTH;
Vector end4 = start + forward4 * MAX_TRACE_LENGTH;

trace_t tr;
trace_t tr2;
trace_t tr3;
trace_t tr4;
UTIL_TraceLine( start, end, MASK_SHOT_HULL & (~CONTENTS_GRATE), player, COLLISION_GROUP_NONE, &tr );
UTIL_TraceLine( start, end2, MASK_SHOT_HULL & (~CONTENTS_GRATE), player, COLLISION_GROUP_NONE, &tr2 );
UTIL_TraceLine( start, end3, MASK_SHOT_HULL & (~CONTENTS_GRATE), player, COLLISION_GROUP_NONE, &tr3 );
UTIL_TraceLine( start, end4, MASK_SHOT_HULL & (~CONTENTS_GRATE), player, COLLISION_GROUP_NONE, &tr4 );

el->origin = tr.endpos - forward * 12.0f;
el->radius = 200;
el->decay = el->radius / 5.0f;
Expand All @@ -5415,6 +5443,32 @@ CON_COMMAND_F( dlight_debug, "Creates a dlight in front of the player", FCVAR_CH
el->color.b = 64;
el->color.exponent = 5;

el2->origin = tr2.endpos - forward2 * 12.0f;
el2->radius = 200;
el2->decay = el2->radius / 5.0f;
el2->die = gpGlobals->curtime + 5.0f;
el2->color.r = 55;
el2->color.g = 50;
el2->color.b = 255;
el2->color.exponent = 5;

el3->origin = tr3.endpos - forward3 * 12.0f;
el3->radius = 200;
el3->decay = el3->radius / 5.0f;
el3->die = gpGlobals->curtime + 5.0f;
el3->color.r = 5;
el3->color.g = 220;
el3->color.b = 10;
el3->color.exponent = 5;

el4->origin = tr4.endpos - forward4 * 12.0f;
el4->radius = 200;
el4->decay = el4->radius / 5.0f;
el4->die = gpGlobals->curtime + 5.0f;
el4->color.r = 225;
el4->color.g = 22;
el4->color.b = 22;
el4->color.exponent = 5;
}
//-----------------------------------------------------------------------------
// Purpose:
Expand Down
4 changes: 2 additions & 2 deletions game/client/cstrike15/clientmode_csnormal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3742,8 +3742,8 @@ bool __MsgFunc_PlayerDecalDigitalSignature( const CCSUsrMsg_PlayerDecalDigitalSi
g_CSClientGameStats.AddClientCSGOGameEvent( k_CSClientCsgoGameEventType_SprayApplication, vecCheck, pLocalPlayer->EyeAngles(), ( uint64( unStickerKitID ) << 32 ) | uint64( unTintID ) );

#ifdef _DEBUG
DevMsg( "Client decal signature (%llu) @(%.2f,%.2f,%.2f) T%u requested\n", cl2gc.Body().itemid(),
msg.data().endpos( 0 ), msg.data().endpos( 1 ), msg.data().endpos( 2 ), msg.data().rtime() );
//DevMsg( "Client decal signature (%llu) @(%.2f,%.2f,%.2f) T%u requested\n", cl2gc.Body().itemid(), msg.data().endpos( 0 ), msg.data().endpos( 1 ), msg.data().endpos( 2 ), msg.data().rtime() );
DevMsg( "Client decal signature @(%.2f,%.2f,%.2f) T%u requested\n", msg.data().endpos( 0 ), msg.data().endpos( 1 ), msg.data().endpos( 2 ), msg.data().rtime() );
#endif

return true;
Expand Down
9 changes: 6 additions & 3 deletions game/shared/econ/econ_item_inventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1308,7 +1308,8 @@ bool CPlayerInventory::AddEconDefaultEquippedDefinition( CEconDefaultEquippedDef
void CPlayerInventory::SOCreated( const CSteamID & steamIDOwner, const GCSDK::CSharedObject *pObject, GCSDK::ESOCacheEvent eEvent )
{
#ifdef _DEBUG
Msg("CPlayerInventory::SOCreated %s [event = %u]\n", CSteamID( owner.ID() ).Render(), eEvent );
//Msg("CPlayerInventory::SOCreated %s [event = %u]\n", CSteamID( owner.ID() ).Render(), eEvent );
Msg("CPlayerInventory::SOCreated [event = %u]\n", eEvent );
#endif
GCSDK::SOID_t owner( steamIDOwner ); //lwss hack
if ( owner != m_OwnerID )
Expand Down Expand Up @@ -1492,7 +1493,8 @@ void CPlayerInventory::PostSOUpdate(const CSteamID &steamIDOwner, GCSDK::ESOCach
void CPlayerInventory::SODestroyed( const CSteamID & steamIDOwner, const GCSDK::CSharedObject *pObject, GCSDK::ESOCacheEvent eEvent )
{
#ifdef _DEBUG
Msg("CPlayerInventory::SODestroyed %s [event = %u]\n", CSteamID( owner.ID() ).Render(), eEvent );
//Msg("CPlayerInventory::SODestroyed %s [event = %u]\n", CSteamID( owner.ID() ).Render(), eEvent );
Msg("CPlayerInventory::SODestroyed [event = %u]\n", eEvent );
#endif
GCSDK::SOID_t owner( steamIDOwner ); //lwss hack

Expand Down Expand Up @@ -1607,7 +1609,8 @@ void CPlayerInventory::MarkSetItemDescriptionsDirty( int nItemSetIndex )
void CPlayerInventory::SOCacheUnsubscribed( const CSteamID & steamIDOwner, GCSDK::ESOCacheEvent eEvent )
{
#ifdef _DEBUG
Msg("CPlayerInventory::SOCacheUnsubscribed %s [event = %u]\n", CSteamID( ID.ID() ).Render(), eEvent );
//Msg("CPlayerInventory::SOCacheUnsubscribed %s [event = %u]\n", CSteamID( ID.ID() ).Render(), eEvent );
Msg("CPlayerInventory::SOCacheUnsubscribed [event = %u]\n", eEvent );
#endif
GCSDK::SOID_t owner( steamIDOwner ); //lwss hack

Expand Down
Loading

1 comment on commit 4c2fdc3

@LWSS
Copy link
Contributor Author

@LWSS LWSS commented on 4c2fdc3 Sep 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2022-09-04-175324_1913x1078_scrot

Please sign in to comment.