Raster triangles faster at the expense of memory

This commit is contained in:
Robert Beckebans 2024-08-30 16:41:32 +02:00
parent 4be1312188
commit b889c56e92
6 changed files with 94 additions and 1 deletions

View file

@ -1,7 +1,8 @@
bind "I" "toggle r_showSurfaceInfo"
bind "N" "noclip"
bind "M" "spawn moveable_macbethchart"
//bind "M" "spawn moveable_macbethchart"
bind "M" "maskShot"
bind "O" "toggle r_useMaskedOcclusionCulling"
bind "P" "toggle r_showPortals"
// bind "P" "toggle r_showViewEnvprobes 1 2 0"

View file

@ -40,6 +40,7 @@ MEM_TAG( TRI_SIL_EDGE )
MEM_TAG( TRI_DOMINANT_TRIS )
MEM_TAG( TRI_MIR_VERT )
MEM_TAG( TRI_DUP_VERT )
MEM_TAG( TRI_MOC_VERT )
MEM_TAG( SRFTRIS )
MEM_TAG( TEMP ) // Temp data which should be automatically freed at the end of the function
MEM_TAG( PAGE )

View file

@ -84,6 +84,11 @@ struct srfTriangles_t
triIndex_t* silIndexes; // indexes changed to be the first vertex with same XYZ, ignoring normal and texcoords
// RB begin
idVec4* mocVerts; // idDrawVert has no w position
unsigned int* mocIndexes; // uint32 instead of uint16 for the Masked Software Occlusion Culling SIMD loading code
// RB end
int numMirroredVerts; // this many verts at the end of the vert list are tangent mirrors
int* mirroredVerts; // tri->mirroredVerts[0] is the mirror of tri->numVerts - tri->numMirroredVerts + 0

View file

@ -1632,6 +1632,7 @@ int R_TriSurfMemory( const srfTriangles_t* tri );
void R_BoundTriSurf( srfTriangles_t* tri );
void R_RemoveDuplicatedTriangles( srfTriangles_t* tri );
void R_CreateSilIndexes( srfTriangles_t* tri );
void R_CreateMaskedOcclusionCullingTris( srfTriangles_t* tri ); // RB
void R_RemoveDegenerateTriangles( srfTriangles_t* tri );
void R_RemoveUnusedVerts( srfTriangles_t* tri );
void R_RangeCheckIndexes( const srfTriangles_t* tri );

View file

@ -334,6 +334,8 @@ void R_RenderSingleModel( viewEntity_t* vEntity )
if( !gpuSkinned )
//if( model->IsStaticWorldModel() )
{
#if 0
// super simple bruteforce
idVec4 triVerts[3];
unsigned int triIndices[] = { 0, 1, 2 };
@ -359,6 +361,14 @@ void R_RenderSingleModel( viewEntity_t* vEntity )
tr.maskedOcclusionCulling->RenderTriangles( ( float* )triVerts, triIndices, 1, NULL, MaskedOcclusionCulling::BACKFACE_CCW );
}
#else
R_CreateMaskedOcclusionCullingTris( tri );
idRenderMatrix mvp;
idRenderMatrix::Transpose( vEntity->unjitteredMVP, mvp );
tr.maskedOcclusionCulling->RenderTriangles( tri->mocVerts->ToFloatPtr(), tri->mocIndexes, tri->numIndexes / 3, ( float* )&mvp[0][0], MaskedOcclusionCulling::BACKFACE_CCW, MaskedOcclusionCulling::CLIP_PLANE_ALL, MaskedOcclusionCulling::VertexLayout( 16, 4, 8 ) );
#endif
}
#if 0
else

View file

@ -4,6 +4,7 @@
Doom 3 BFG Edition GPL Source Code
Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
Copyright (C) 2020 Stephen Pridham (Mikkelsen tangent space support)
Copyright (C) 2021-2024 Robert Beckebans
This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
@ -251,6 +252,13 @@ int R_TriSurfMemory( const srfTriangles_t* tri )
total += tri->numDupVerts * sizeof( tri->dupVerts[0] );
}
// RB: added MOC
if( tri->mocIndexes != NULL )
{
total += tri->numIndexes * sizeof( tri->mocIndexes[0] );
}
// RB end
total += sizeof( *tri );
return total;
@ -293,6 +301,13 @@ void R_FreeStaticTriSurf( srfTriangles_t* tri )
Mem_Free( tri->verts );
}
}
// RB begin
if( tri->mocVerts != NULL )
{
Mem_Free( tri->mocVerts );
}
// RB end
}
if( !tri->referencedIndexes )
@ -309,6 +324,12 @@ void R_FreeStaticTriSurf( srfTriangles_t* tri )
{
Mem_Free( tri->silIndexes );
}
// RB begin
if( tri->mocIndexes != NULL )
{
Mem_Free( tri->mocIndexes );
}
// RB end
if( tri->dominantTris != NULL )
{
Mem_Free( tri->dominantTris );
@ -449,6 +470,28 @@ void R_AllocStaticTriSurfDupVerts( srfTriangles_t* tri, int numDupVerts )
tri->dupVerts = ( int* )Mem_Alloc16( numDupVerts * 2 * sizeof( *tri->dupVerts ), TAG_TRI_DUP_VERT );
}
/*
=================
R_AllocStaticTriSurfMocIndexes
=================
*/
void R_AllocStaticTriSurfMocIndexes( srfTriangles_t* tri, int numIndexes )
{
assert( tri->mocIndexes == NULL );
tri->mocIndexes = ( unsigned int* )Mem_Alloc16( numIndexes * sizeof( unsigned int ), TAG_TRI_MOC_VERT );
}
/*
=================
R_AllocStaticTriSurfMocVerts
=================
*/
void R_AllocStaticTriSurfMocVerts( srfTriangles_t* tri, int numVerts )
{
assert( tri->mocVerts == NULL );
tri->mocVerts = ( idVec4* )Mem_Alloc16( numVerts * sizeof( idVec4 ), TAG_TRI_MOC_VERT );
}
/*
=================
R_ResizeStaticTriSurfVerts
@ -693,6 +736,9 @@ void R_CreateDupVerts( srfTriangles_t* tri )
memcpy( tri->dupVerts, tempDupVerts.Ptr(), tri->numDupVerts * 2 * sizeof( tri->dupVerts[0] ) );
}
/*
===============
R_FaceNegativePolarity
@ -1795,6 +1841,9 @@ void R_CleanupTriangles( srfTriangles_t* tri, bool createNormals, bool identifyS
{
R_DeriveTangents( tri );
}
// RB: duplicate data appropiate for MOC SIMD fetches
R_CreateMaskedOcclusionCullingTris( tri );
}
/*
@ -2192,3 +2241,29 @@ idVec3 R_ClosestPointPointTriangle( const idVec3& point, const idVec3& vertex1,
return result;
}
void R_CreateMaskedOcclusionCullingTris( srfTriangles_t* tri )
{
//assert( tri->mocVerts == NULL );
if( tri->mocVerts == NULL )
{
R_AllocStaticTriSurfMocVerts( tri, tri->numVerts );
for( int i = 0; i < tri->numVerts; i++ )
{
tri->mocVerts[i].ToVec3() = tri->verts[i].xyz;
tri->mocVerts[i].w = 1.0f;
}
}
if( tri->mocIndexes == NULL )
{
R_AllocStaticTriSurfMocIndexes( tri, tri->numIndexes );
for( int i = 0; i < tri->numIndexes; i++ )
{
tri->mocIndexes[i] = tri->indexes[i];
}
}
}
// RB end