Small vertex cache cleanup

This commit is contained in:
Robert Beckebans 2022-03-16 15:24:08 +01:00
parent 00612732d4
commit 51294e6549
5 changed files with 22 additions and 18 deletions

View file

@ -793,7 +793,7 @@ drawSurf_t* idRenderModelOverlay::CreateOverlayDrawSurf( const viewEntity_t* spa
drawSurf->renderZFail = 0;
R_SetupDrawSurfShader( drawSurf, material, &space->entityDef->parms );
R_SetupDrawSurfJoints( drawSurf, newTri, NULL, nullptr );
R_SetupDrawSurfJoints( drawSurf, newTri, NULL );
return drawSurf;
}

View file

@ -1509,7 +1509,7 @@ idRenderModel* R_EntityDefDynamicModel( idRenderEntityLocal* def );
void R_ClearEntityDefDynamicModel( idRenderEntityLocal* def );
void R_SetupDrawSurfShader( drawSurf_t* drawSurf, const idMaterial* shader, const renderEntity_t* renderEntity );
void R_SetupDrawSurfJoints( drawSurf_t* drawSurf, const srfTriangles_t* tri, const idMaterial* shader, nvrhi::ICommandList* commandList );
void R_SetupDrawSurfJoints( drawSurf_t* drawSurf, const srfTriangles_t* tri, const idMaterial* shader, nvrhi::ICommandList* commandList = nullptr );
void R_LinkDrawSurfToView( drawSurf_t* drawSurf, viewDef_t* viewDef );
void R_AddModels();

View file

@ -66,10 +66,12 @@ static void MapGeoBufferSet( geoBufferSet_t& gbs )
{
gbs.mappedVertexBase = ( byte* )gbs.vertexBuffer.MapBuffer( BM_WRITE );
}
if( gbs.mappedIndexBase == NULL )
{
gbs.mappedIndexBase = ( byte* )gbs.indexBuffer.MapBuffer( BM_WRITE );
}
if( gbs.mappedJointBase == NULL && gbs.jointBuffer.GetAllocedSize() != 0 )
{
gbs.mappedJointBase = ( byte* )gbs.jointBuffer.MapBuffer( BM_WRITE );
@ -88,11 +90,13 @@ static void UnmapGeoBufferSet( geoBufferSet_t& gbs )
gbs.vertexBuffer.UnmapBuffer();
gbs.mappedVertexBase = NULL;
}
if( gbs.mappedIndexBase != NULL )
{
gbs.indexBuffer.UnmapBuffer();
gbs.mappedIndexBase = NULL;
}
if( gbs.mappedJointBase != NULL )
{
gbs.jointBuffer.UnmapBuffer();

View file

@ -119,9 +119,9 @@ public:
void FreeStaticData();
// this data is only valid for one frame of rendering
vertCacheHandle_t AllocVertex( const void* data, int num, size_t size, nvrhi::ICommandList* commandList );
vertCacheHandle_t AllocIndex( const void* data, int num, size_t size, nvrhi::ICommandList* commandList );
vertCacheHandle_t AllocJoint( const void* data, int num, size_t size, nvrhi::ICommandList* commandList );
vertCacheHandle_t AllocVertex( const void* data, int num, size_t size = sizeof( idDrawVert ), nvrhi::ICommandList* commandList = nullptr );
vertCacheHandle_t AllocIndex( const void* data, int num, size_t size = sizeof( triIndex_t ), nvrhi::ICommandList* commandList = nullptr );
vertCacheHandle_t AllocJoint( const void* data, int num, size_t size = sizeof( idJointMat ), nvrhi::ICommandList* commandList = nullptr );
// this data is valid until the next map load
vertCacheHandle_t AllocStaticVertex( const void* data, int bytes, nvrhi::ICommandList* commandList );

View file

@ -750,7 +750,7 @@ void R_AddSingleModel( viewEntity_t* vEntity )
// make sure we have an ambient cache and all necessary normals / tangents
if( !vertexCache.CacheIsCurrent( tri->indexCache ) )
{
tri->indexCache = vertexCache.AllocIndex( tri->indexes, tri->numIndexes, sizeof( triIndex_t ), nullptr );
tri->indexCache = vertexCache.AllocIndex( tri->indexes, tri->numIndexes );
}
if( !vertexCache.CacheIsCurrent( tri->ambientCache ) )
@ -765,7 +765,7 @@ void R_AddSingleModel( viewEntity_t* vEntity )
//assert( false ); // this should no longer be hit
// RB end
}
tri->ambientCache = vertexCache.AllocVertex( tri->verts, tri->numVerts, sizeof( idDrawVert ), nullptr );
tri->ambientCache = vertexCache.AllocVertex( tri->verts, tri->numVerts );
}
// add the surface for drawing
@ -807,14 +807,14 @@ void R_AddSingleModel( viewEntity_t* vEntity )
// copy verts and indexes to this frame's hardware memory if they aren't already there
if( !vertexCache.CacheIsCurrent( tri->ambientCache ) )
{
tri->ambientCache = vertexCache.AllocVertex( tri->verts, tri->numVerts, sizeof( idDrawVert ), nullptr );
tri->ambientCache = vertexCache.AllocVertex( tri->verts, tri->numVerts );
}
if( !vertexCache.CacheIsCurrent( tri->indexCache ) )
{
tri->indexCache = vertexCache.AllocIndex( tri->indexes, tri->numIndexes, sizeof( triIndex_t ), nullptr );
tri->indexCache = vertexCache.AllocIndex( tri->indexes, tri->numIndexes );
}
R_SetupDrawSurfJoints( baseDrawSurf, tri, shader, nullptr );
R_SetupDrawSurfJoints( baseDrawSurf, tri, shader );
baseDrawSurf->numIndexes = tri->numIndexes;
baseDrawSurf->ambientCache = tri->ambientCache;
@ -907,7 +907,7 @@ void R_AddSingleModel( viewEntity_t* vEntity )
// when using shadow volumes
if( r_cullDynamicLightTriangles.GetBool() && !r_skipDynamicShadows.GetBool() && !r_useShadowMapping.GetBool() && shader->SurfaceCastsShadow() )
{
vertCacheHandle_t lightIndexCache = vertexCache.AllocIndex( NULL, lightDrawSurf->numIndexes, sizeof( triIndex_t ), nullptr );
vertCacheHandle_t lightIndexCache = vertexCache.AllocIndex( NULL, lightDrawSurf->numIndexes );
if( vertexCache.CacheIsCurrent( lightIndexCache ) )
{
lightDrawSurf->indexCache = lightIndexCache;
@ -968,7 +968,7 @@ void R_AddSingleModel( viewEntity_t* vEntity )
lightDrawSurf->renderZFail = 0;
lightDrawSurf->shaderRegisters = shaderRegisters;
R_SetupDrawSurfJoints( lightDrawSurf, tri, shader, nullptr );
R_SetupDrawSurfJoints( lightDrawSurf, tri, shader );
// Determine which linked list to add the light surface to.
// There will only be localSurfaces if the light casts shadows and
@ -1096,7 +1096,7 @@ void R_AddSingleModel( viewEntity_t* vEntity )
// make sure we have an ambient cache and all necessary normals / tangents
if( !vertexCache.CacheIsCurrent( tri->indexCache ) )
{
tri->indexCache = vertexCache.AllocIndex( tri->indexes, tri->numIndexes, sizeof( triIndex_t ), nullptr );
tri->indexCache = vertexCache.AllocIndex( tri->indexes, tri->numIndexes );
}
// throw the entire source surface at it without any per-triangle culling
@ -1116,7 +1116,7 @@ void R_AddSingleModel( viewEntity_t* vEntity )
//assert( false ); // this should no longer be hit
// RB end
}
tri->ambientCache = vertexCache.AllocVertex( tri->verts, tri->numVerts, sizeof( idDrawVert ), nullptr );
tri->ambientCache = vertexCache.AllocVertex( tri->verts, tri->numVerts );
}
shadowDrawSurf->ambientCache = tri->ambientCache;
@ -1135,7 +1135,7 @@ void R_AddSingleModel( viewEntity_t* vEntity )
R_SetupDrawSurfShader( shadowDrawSurf, shader, renderEntity );
}
R_SetupDrawSurfJoints( shadowDrawSurf, tri, shader, nullptr );
R_SetupDrawSurfJoints( shadowDrawSurf, tri, shader );
// determine which linked list to add the shadow surface to
@ -1220,7 +1220,7 @@ void R_AddSingleModel( viewEntity_t* vEntity )
// duplicates them with w set to 0 and 1 for the vertex program to project.
// This is constant for any number of lights, the vertex program takes care
// of projecting the verts to infinity for a particular light.
tri->shadowCache = vertexCache.AllocVertex( NULL, tri->numVerts * 2, sizeof( idShadowVert ), nullptr );
tri->shadowCache = vertexCache.AllocVertex( NULL, tri->numVerts * 2, sizeof( idShadowVert ) );
idShadowVert* shadowVerts = ( idShadowVert* )vertexCache.MappedVertexBuffer( tri->shadowCache );
idShadowVert::CreateShadowCache( shadowVerts, tri->verts, tri->numVerts );
}
@ -1228,7 +1228,7 @@ void R_AddSingleModel( viewEntity_t* vEntity )
const int maxShadowVolumeIndexes = tri->numSilEdges * 6 + tri->numIndexes * 2;
shadowDrawSurf->numIndexes = 0;
shadowDrawSurf->indexCache = vertexCache.AllocIndex( NULL, maxShadowVolumeIndexes, sizeof( triIndex_t ), nullptr );
shadowDrawSurf->indexCache = vertexCache.AllocIndex( NULL, maxShadowVolumeIndexes );
shadowDrawSurf->shadowCache = tri->shadowCache;
shadowDrawSurf->scissorRect = vLight->scissorRect; // default to the light scissor and light depth bounds
shadowDrawSurf->shadowVolumeState = SHADOWVOLUME_DONE; // assume the shadow volume is done in case the index cache allocation failed
@ -1306,7 +1306,7 @@ void R_AddSingleModel( viewEntity_t* vEntity )
shadowDrawSurf->sort = 0.0f;
shadowDrawSurf->shaderRegisters = NULL;
R_SetupDrawSurfJoints( shadowDrawSurf, tri, NULL, nullptr );
R_SetupDrawSurfJoints( shadowDrawSurf, tri, NULL );
// determine which linked list to add the shadow surface to
shadowDrawSurf->linkChain = shader->TestMaterialFlag( MF_NOSELFSHADOW ) ? &vLight->localShadows : &vLight->globalShadows;