From eae908891112b5b4525d6aa3b1d762cc2e93ee6e Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 11 Jul 2015 12:31:55 -0400 Subject: [PATCH 1/9] Convert plGBufferCell hsTArrays to std::vector --- .../PubUtilLib/plPipeline/plGBufferGroup.cpp | 58 +++++++++---------- .../PubUtilLib/plPipeline/plGBufferGroup.h | 6 +- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp index 472dbda4..a56cd22e 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp @@ -117,7 +117,7 @@ plGBufferGroup::plGBufferGroup( uint8_t format, bool vertsVolatile, bool idxVola fColorBuffStorage.Reset(); fVertexBufferRefs.Reset(); fIndexBufferRefs.Reset(); - fCells.Reset(); + fCells.clear(); fNumVerts = fNumIndices = 0; fFormat = format; @@ -222,8 +222,8 @@ void plGBufferGroup::CleanUp( void ) delete [] fColorBuffStorage[ i ]; } - for( i = 0; i < fCells.GetCount(); i++ ) - delete fCells[ i ]; + for (auto i : fCells) + delete i; fVertBuffStorage.Reset(); fVertBuffSizes.Reset(); @@ -236,7 +236,7 @@ void plGBufferGroup::CleanUp( void ) fColorBuffStorage.Reset(); fColorBuffCounts.Reset(); - fCells.Reset(); + fCells.clear(); } //// SetVertexBufferRef /////////////////////////////////////////////////////// @@ -455,8 +455,8 @@ void plGBufferGroup::Read( hsStream *s ) { temp = s->ReadLE32(); - fCells.Append( new hsTArray ); - fCells[ i ]->SetCount( temp ); + fCells.push_back( new std::vector ); + fCells[ i ]->resize( temp ); for( j = 0; j < temp; j++ ) (*fCells[ i ])[ j ].Read( s ); @@ -498,7 +498,7 @@ void plGBufferGroup::Write( hsStream *s ) { #ifdef MF_VERTCODE_ENABLED - hsAssert(fCells[i]->GetCount() == 1, "Data must be interleaved for compression"); + hsAssert(fCells[i]->size() == 1, "Data must be interleaved for compression"); uint32_t numVerts = fVertBuffSizes[i] / fStride; s->WriteLE16((uint16_t)numVerts); coder.Write(s, fVertBuffStorage[i], fFormat, fStride, (uint16_t)numVerts); @@ -538,8 +538,8 @@ void plGBufferGroup::Write( hsStream *s ) /// Write out cell arrays for( i = 0; i < fVertBuffStorage.GetCount(); i++ ) { - s->WriteLE32( fCells[ i ]->GetCount() ); - for( j = 0; j < fCells[ i ]->GetCount(); j++ ) + s->WriteLE32( fCells[ i ]->size() ); + for( j = 0; j < fCells[ i ]->size(); j++ ) (*fCells[ i ])[ j ].Write( s ); } @@ -567,7 +567,7 @@ void plGBufferGroup::DeleteVertsFromStorage( uint32_t which, uint32_t start, uint32_t amount; - hsAssert( fCells[ which ]->GetCount() == 1, "Cannot delete verts on a mixed buffer group" ); + hsAssert( fCells[ which ]->size() == 1, "Cannot delete verts on a mixed buffer group" ); // Adjust cell 0 (*fCells[ which ])[ 0 ].fLength -= length; @@ -662,14 +662,12 @@ uint32_t plGBufferGroup::GetNumPrimaryVertsLeft( void ) const uint32_t plGBufferGroup::GetNumVertsLeft( uint32_t idx ) const { - if( idx >= fCells.GetCount() ) + if( idx >= fCells.size() ) return kMaxNumVertsPerBuffer; - uint32_t i, total = kMaxNumVertsPerBuffer; - - - for( i = 0; i < fCells[ idx ]->GetCount(); i++ ) - total -= (*fCells[ idx ])[ i ].fLength; + uint32_t total = kMaxNumVertsPerBuffer; + for( const auto& i : *fCells[ idx ] ) + total -= i.fLength; return total; } @@ -679,7 +677,7 @@ uint32_t plGBufferGroup::GetNumVertsLeft( uint32_t idx ) const uint32_t plGBufferGroup::IMakeCell( uint32_t vbIndex, uint8_t flags, uint32_t vStart, uint32_t cStart, uint32_t len, uint32_t *offset ) { - hsTArray *cells = fCells[ vbIndex ]; + std::vector* cells = fCells[ vbIndex ]; if( !(flags & kReserveInterleaved) ) @@ -690,27 +688,27 @@ uint32_t plGBufferGroup::IMakeCell( uint32_t vbIndex, uint8_t flags, uint32_t v /// we never merge any separated cells if( flags & kReserveSeparated ) - cells->Append( plGBufferCell( vStart, cStart, len ) ); + cells->emplace_back(vStart, cStart, len); else - cells->Append( plGBufferCell( (uint32_t)-1, cStart, len ) ); + cells->emplace_back((uint32_t)-1, cStart, len); *offset = 0; } else { /// Merge if the last cell was an interleaved cell - if( cells->GetCount() > 0 && (*cells)[ cells->GetCount() - 1 ].fColorStart == (uint32_t)-1 ) + if( !cells->empty() && cells->back().fColorStart == (uint32_t)-1 ) { - *offset = (*cells)[ cells->GetCount() - 1 ].fLength; - (*cells)[ cells->GetCount() - 1 ].fLength += len; + *offset = cells->back().fLength; + cells->back().fLength += len; } else { - cells->Append( plGBufferCell( vStart, (uint32_t)-1, len ) ); + cells->emplace_back(vStart, (uint32_t)-1, len); *offset = 0; } } - return cells->GetCount() - 1; + return cells->size() - 1; } //// ReserveVertStorage /////////////////////////////////////////////////////// @@ -758,7 +756,7 @@ bool plGBufferGroup::ReserveVertStorage( uint32_t numVerts, uint32_t *vbIndex fColorBuffStorage.Append( nil ); fColorBuffCounts.Append( 0 ); - fCells.Append( new hsTArray ); + fCells.push_back( new std::vector ); } *vbIndex = i; @@ -875,7 +873,7 @@ void plGBufferGroup::AppendToColorStorage( plGeometrySpan *srcSpan, uint32_t void plGBufferGroup::IGetStartVtxPointer( uint32_t vbIndex, uint32_t cell, uint32_t offset, uint8_t *&tempPtr, plGBufferColor *&cPtr ) { hsAssert( vbIndex < fVertBuffStorage.GetCount(), "Invalid vbIndex in StuffToVertStorage()" ); - hsAssert( cell < fCells[ vbIndex ]->GetCount(), "Invalid cell in StuffToVertStorage()" ); + hsAssert( cell < fCells[ vbIndex ]->size(), "Invalid cell in StuffToVertStorage()" ); tempPtr = fVertBuffStorage[ vbIndex ]; cPtr = fColorBuffStorage[ vbIndex ]; @@ -894,7 +892,7 @@ void plGBufferGroup::IGetStartVtxPointer( uint32_t vbIndex, uint32_t cell, ui uint32_t plGBufferGroup::GetVertBufferCount( uint32_t idx ) const { - return GetVertStartFromCell( idx, fCells[ idx ]->GetCount(), 0 ); + return GetVertStartFromCell( idx, fCells[ idx ]->size(), 0 ); } //// GetVertStartFromCell ///////////////////////////////////////////////////// @@ -905,7 +903,7 @@ uint32_t plGBufferGroup::GetVertStartFromCell( uint32_t vbIndex, uint32_t cell, hsAssert( vbIndex < fVertBuffStorage.GetCount(), "Invalid vbIndex in StuffToVertStorage()" ); - hsAssert( cell <= fCells[ vbIndex ]->GetCount(), "Invalid cell in StuffToVertStorage()" ); + hsAssert( cell <= fCells[ vbIndex ]->size(), "Invalid cell in StuffToVertStorage()" ); numVerts = 0; for( i = 0; i < cell; i++ ) @@ -929,7 +927,7 @@ void plGBufferGroup::StuffToVertStorage( plGeometrySpan *srcSpan, uint32_t vb hsAssert( vbIndex < fVertBuffStorage.GetCount(), "Invalid vbIndex in StuffToVertStorage()" ); - hsAssert( cell < fCells[ vbIndex ]->GetCount(), "Invalid cell in StuffToVertStorage()" ); + hsAssert( cell < fCells[ vbIndex ]->size(), "Invalid cell in StuffToVertStorage()" ); IGetStartVtxPointer( vbIndex, cell, offset, tempPtr, cPtr ); cellPtr = &(*fCells[ vbIndex ])[ cell ]; @@ -1131,7 +1129,7 @@ plGBufferTriangle *plGBufferGroup::ConvertToTriList( int16_t spanIndex, uint32 hsAssert( whichVtx < fVertBuffStorage.GetCount(), "Invalid vertex buffer ID to ConvertToTriList()" ); hsAssert( start < fIdxBuffCounts[ whichIdx ], "Invalid start index to ConvertToTriList()" ); hsAssert( start + numTriangles * 3 <= fIdxBuffCounts[ whichIdx ], "Invalid count to ConvertToTriList()" ); - hsAssert( whichCell < fCells[ whichVtx ]->GetCount(), "Invalid cell to ConvertToTriList()" ); + hsAssert( whichCell < fCells[ whichVtx ]->size(), "Invalid cell to ConvertToTriList()" ); /// Create the array and fill it array = new plGBufferTriangle[ numTriangles ]; diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h index 9973c2ec..a4900a51 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h @@ -138,7 +138,7 @@ class plGBufferGroup hsTArray fColorBuffStorage; - hsTArray *> fCells; + std::vector*> fCells; virtual void ISendStorageToBuffers( plPipeline *pipe, bool adjustForNvidiaLighting ); @@ -241,8 +241,8 @@ class plGBufferGroup hsGDeviceRef *GetVertexBufferRef( uint32_t i ); hsGDeviceRef *GetIndexBufferRef( uint32_t i ); - uint32_t GetNumCells( uint32_t idx ) const { return fCells[ idx ]->GetCount(); } - plGBufferCell *GetCell( uint32_t idx, uint32_t cell ) { return &( (*fCells[ idx ])[ cell ] ); } + size_t GetNumCells( size_t idx ) const { return fCells[ idx ]->size(); } + plGBufferCell *GetCell( size_t idx, size_t cell ) { return &( (*fCells[ idx ])[ cell ] ); } void SetVertexBufferRef( uint32_t index, hsGDeviceRef *vb ); void SetIndexBufferRef( uint32_t index, hsGDeviceRef *ib ); From e7a0f4a4d1f7833d4be6cfd89f933e349904ea06 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 11 Jul 2015 18:32:18 -0400 Subject: [PATCH 2/9] GBufferGroup colors to std::vector --- .../PubUtilLib/plPipeline/plGBufferGroup.cpp | 28 +++++++++---------- .../PubUtilLib/plPipeline/plGBufferGroup.h | 14 +++++----- 2 files changed, 21 insertions(+), 21 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp index a56cd22e..66974a85 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp @@ -114,7 +114,7 @@ plGBufferGroup::plGBufferGroup( uint8_t format, bool vertsVolatile, bool idxVola { fVertBuffStorage.Reset(); fIdxBuffStorage.Reset(); - fColorBuffStorage.Reset(); + fColorBuffStorage.clear(); fVertexBufferRefs.Reset(); fIndexBufferRefs.Reset(); fCells.clear(); @@ -216,7 +216,7 @@ void plGBufferGroup::CleanUp( void ) plProfile_DelMem(MemBufGrpIndex, fIdxBuffCounts[i] * sizeof(uint16_t)); delete [] fIdxBuffStorage[ i ]; } - for( i = 0; i < fColorBuffStorage.GetCount(); i++ ) + for (size_t i = 0; i < fColorBuffStorage.size(); ++i) { plProfile_DelMem(MemBufGrpVertex, fColorBuffCounts[i] * sizeof(plGBufferColor)); delete [] fColorBuffStorage[ i ]; @@ -233,8 +233,8 @@ void plGBufferGroup::CleanUp( void ) fIdxBuffCounts.Reset(); fIdxBuffStarts.Reset(); fIdxBuffEnds.Reset(); - fColorBuffStorage.Reset(); - fColorBuffCounts.Reset(); + fColorBuffStorage.clear(); + fColorBuffCounts.clear(); fCells.clear(); } @@ -374,7 +374,7 @@ void plGBufferGroup::Read( hsStream *s ) fVertBuffSizes.Reset(); fVertBuffStarts.Reset(); fVertBuffEnds.Reset(); - fColorBuffCounts.Reset(); + fColorBuffCounts.clear(); fIdxBuffCounts.Reset(); fIdxBuffStarts.Reset(); fIdxBuffEnds.Reset(); @@ -401,8 +401,8 @@ void plGBufferGroup::Read( hsStream *s ) coder.Read(s, vData, fFormat, fStride, numVerts); - fColorBuffCounts.Append(0); - fColorBuffStorage.Append(nil); + fColorBuffCounts.push_back(0); + fColorBuffStorage.push_back(nullptr); } else @@ -420,7 +420,7 @@ void plGBufferGroup::Read( hsStream *s ) plProfile_NewMem(MemBufGrpVertex, temp); temp = s->ReadLE32(); - fColorBuffCounts.Append( temp ); + fColorBuffCounts.push_back( temp ); if( temp > 0 ) { @@ -431,7 +431,7 @@ void plGBufferGroup::Read( hsStream *s ) else cData = nil; - fColorBuffStorage.Append( cData ); + fColorBuffStorage.push_back( cData ); } } @@ -753,8 +753,8 @@ bool plGBufferGroup::ReserveVertStorage( uint32_t numVerts, uint32_t *vbIndex fVertBuffStarts.Append(0); fVertBuffEnds.Append(-1); - fColorBuffStorage.Append( nil ); - fColorBuffCounts.Append( 0 ); + fColorBuffStorage.push_back(nullptr); + fColorBuffCounts.push_back(0); fCells.push_back( new std::vector ); } @@ -795,15 +795,15 @@ bool plGBufferGroup::ReserveVertStorage( uint32_t numVerts, uint32_t *vbIndex } /// Switch over - if( storagePtr != nil ) + if (storagePtr) { if( fVertBuffStorage[ i ] != nil ) delete [] fVertBuffStorage[ i ]; fVertBuffStorage[ i ] = storagePtr; } - if( cStoragePtr != nil ) + if (cStoragePtr) { - if( fColorBuffStorage[ i ] != nil ) + if (fColorBuffStorage[ i ]) delete [] fColorBuffStorage[ i ]; fColorBuffStorage[ i ] = cStoragePtr; fColorBuffCounts[ i ] += numVerts; diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h index a4900a51..a611e550 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h @@ -125,18 +125,18 @@ class plGBufferGroup hsTArray fVertexBufferRefs; hsTArray fIndexBufferRefs; - hsTArray fVertBuffSizes; - hsTArray fIdxBuffCounts; - hsTArray fColorBuffCounts; - hsTArray fVertBuffStorage; - hsTArray fIdxBuffStorage; + hsTArray fVertBuffSizes; + hsTArray fIdxBuffCounts; + std::vector fColorBuffCounts; + hsTArray fVertBuffStorage; + hsTArray fIdxBuffStorage; hsTArray fVertBuffStarts; hsTArray fVertBuffEnds; hsTArray fIdxBuffStarts; hsTArray fIdxBuffEnds; - hsTArray fColorBuffStorage; + std::vector fColorBuffStorage; std::vector*> fCells; @@ -236,7 +236,7 @@ class plGBufferGroup uint8_t *GetVertBufferData( uint32_t idx ) { return fVertBuffStorage[ idx ]; } uint16_t *GetIndexBufferData( uint32_t idx ) { return fIdxBuffStorage[ idx ]; } - plGBufferColor *GetColorBufferData( uint32_t idx ) { return fColorBuffStorage[ idx ]; } + plGBufferColor *GetColorBufferData( size_t idx ) { return fColorBuffStorage[ idx ]; } hsGDeviceRef *GetVertexBufferRef( uint32_t i ); hsGDeviceRef *GetIndexBufferRef( uint32_t i ); From a94fc1bf0bb752d76103e04f230bb6ebf436b833 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 11 Jul 2015 18:49:57 -0400 Subject: [PATCH 3/9] plGBufferGroup vertex storage to std::vector --- .../PubUtilLib/plPipeline/plGBufferGroup.cpp | 82 +++++++++---------- .../PubUtilLib/plPipeline/plGBufferGroup.h | 10 +-- 2 files changed, 42 insertions(+), 50 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp index 66974a85..45730248 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp @@ -112,7 +112,7 @@ void plGBufferCell::Write( hsStream *s ) plGBufferGroup::plGBufferGroup( uint8_t format, bool vertsVolatile, bool idxVolatile, int LOD ) { - fVertBuffStorage.Reset(); + fVertBuffStorage.clear(); fIdxBuffStorage.Reset(); fColorBuffStorage.clear(); fVertexBufferRefs.Reset(); @@ -202,16 +202,13 @@ void plGBufferGroup::PurgeIndexBuffer(uint32_t idx) void plGBufferGroup::CleanUp( void ) { - int i; - - // Clean up the storage - for( i = 0; i < fVertBuffStorage.GetCount(); i++ ) + for (size_t i = 0; i < fVertBuffSizes.size(); ++i) { plProfile_DelMem(MemBufGrpVertex, fVertBuffSizes[i]); delete [] fVertBuffStorage[ i ]; } - for( i = 0; i < fIdxBuffStorage.GetCount(); i++ ) + for (size_t i = 0; i < fIdxBuffStorage.GetCount(); i++) { plProfile_DelMem(MemBufGrpIndex, fIdxBuffCounts[i] * sizeof(uint16_t)); delete [] fIdxBuffStorage[ i ]; @@ -225,10 +222,10 @@ void plGBufferGroup::CleanUp( void ) for (auto i : fCells) delete i; - fVertBuffStorage.Reset(); - fVertBuffSizes.Reset(); - fVertBuffStarts.Reset(); - fVertBuffEnds.Reset(); + fVertBuffStorage.clear(); + fVertBuffSizes.clear(); + fVertBuffStarts.clear(); + fVertBuffEnds.clear(); fIdxBuffStorage.Reset(); fIdxBuffCounts.Reset(); fIdxBuffStarts.Reset(); @@ -309,19 +306,14 @@ void plGBufferGroup::ISendStorageToBuffers( plPipeline *pipe, bool adjustForN plProfile_BeginTiming(DrawRefillVertex); /// Creating or refreshing? - int i; - for( i = 0; i < fVertBuffStorage.GetCount(); i++ ) - { + for (size_t i = 0; i < fVertBuffStorage.size(); i++) pipe->CheckVertexBufferRef(this, i); - } plProfile_EndTiming(DrawRefillVertex); plProfile_BeginTiming(DrawRefillIndex); - for( i = 0; i < fIdxBuffStorage.GetCount(); i++ ) - { + for (size_t i = 0; i < fIdxBuffStorage.GetCount(); i++) pipe->CheckIndexBufferRef(this, i); - } plProfile_EndTiming(DrawRefillIndex); } @@ -371,14 +363,14 @@ void plGBufferGroup::Read( hsStream *s ) totalDynSize = s->ReadLE32(); fStride = ICalcVertexSize( fLiteStride ); - fVertBuffSizes.Reset(); - fVertBuffStarts.Reset(); - fVertBuffEnds.Reset(); + fVertBuffSizes.clear(); + fVertBuffStarts.clear(); + fVertBuffEnds.clear(); fColorBuffCounts.clear(); fIdxBuffCounts.Reset(); fIdxBuffStarts.Reset(); fIdxBuffEnds.Reset(); - fVertBuffStorage.Reset(); + fVertBuffStorage.clear(); fIdxBuffStorage.Reset(); plVertCoder coder; @@ -391,12 +383,12 @@ void plGBufferGroup::Read( hsStream *s ) const uint16_t numVerts = s->ReadLE16(); const uint32_t size = numVerts * fStride; - fVertBuffSizes.Append(size); - fVertBuffStarts.Append(0); - fVertBuffEnds.Append(-1); + fVertBuffSizes.push_back(size); + fVertBuffStarts.push_back(0); + fVertBuffEnds.push_back(-1); vData = new uint8_t[size]; - fVertBuffStorage.Append( vData ); + fVertBuffStorage.push_back( vData ); plProfile_NewMem(MemBufGrpVertex, temp); coder.Read(s, vData, fFormat, fStride, numVerts); @@ -409,14 +401,14 @@ void plGBufferGroup::Read( hsStream *s ) { temp = s->ReadLE32(); - fVertBuffSizes.Append( temp ); - fVertBuffStarts.Append(0); - fVertBuffEnds.Append(-1); + fVertBuffSizes.push_back( temp ); + fVertBuffStarts.push_back(0); + fVertBuffEnds.push_back(-1); vData = new uint8_t[ temp ]; - hsAssert( vData != nil, "Not enough memory to read in vertices" ); + hsAssert(vData, "Not enough memory to read in vertices"); s->Read( temp, (void *)vData ); - fVertBuffStorage.Append( vData ); + fVertBuffStorage.push_back( vData ); plProfile_NewMem(MemBufGrpVertex, temp); temp = s->ReadLE32(); @@ -451,7 +443,7 @@ void plGBufferGroup::Read( hsStream *s ) } /// Read in cell arrays, one per vBuffer - for( i = 0; i < fVertBuffStorage.GetCount(); i++ ) + for( i = 0; i < fVertBuffStorage.size(); i++ ) { temp = s->ReadLE32(); @@ -482,9 +474,9 @@ void plGBufferGroup::Write( hsStream *s ) /// Calc total dynamic data size, for fun totalDynSize = 0; - for( i = 0; i < fVertBuffSizes.GetCount(); i++ ) - totalDynSize += fVertBuffSizes[ i ]; - for( i = 0; i < fIdxBuffCounts.GetCount(); i++ ) + for (auto it : fVertBuffSizes) + totalDynSize += it; + for ( i = 0; i < fIdxBuffCounts.GetCount(); i++ ) totalDynSize += sizeof( uint16_t ) * fIdxBuffCounts[ i ]; s->WriteLE( fFormat ); @@ -493,8 +485,8 @@ void plGBufferGroup::Write( hsStream *s ) plVertCoder coder; /// Write out dyanmic data - s->WriteLE32( (uint32_t)fVertBuffStorage.GetCount() ); - for( i = 0; i < fVertBuffStorage.GetCount(); i++ ) + s->WriteLE32( (uint32_t)fVertBuffStorage.size() ); + for (i = 0; i < fVertBuffStorage.size(); ++i) { #ifdef MF_VERTCODE_ENABLED @@ -536,7 +528,7 @@ void plGBufferGroup::Write( hsStream *s ) } /// Write out cell arrays - for( i = 0; i < fVertBuffStorage.GetCount(); i++ ) + for (i = 0; i < fVertBuffStorage.size(); i++) { s->WriteLE32( fCells[ i ]->size() ); for( j = 0; j < fCells[ i ]->size(); j++ ) @@ -733,7 +725,7 @@ bool plGBufferGroup::ReserveVertStorage( uint32_t numVerts, uint32_t *vbIndex /// Find a spot if( !(flags & kReserveIsolate) ) { - for( i = 0; i < fVertBuffStorage.GetCount(); i++ ) + for( i = 0; i < fVertBuffStorage.size(); i++ ) { if( GetNumVertsLeft( i ) >= numVerts ) break; @@ -741,17 +733,17 @@ bool plGBufferGroup::ReserveVertStorage( uint32_t numVerts, uint32_t *vbIndex } else { - i = fVertBuffStorage.GetCount(); + i = fVertBuffStorage.size(); } - if( i == fVertBuffStorage.GetCount() ) + if( i == fVertBuffStorage.size() ) { if( (flags & kReserveInterleaved) || (flags & kReserveSeparated) ) { - fVertBuffStorage.Append( nil ); - fVertBuffSizes.Append( 0 ); + fVertBuffStorage.push_back(nullptr); + fVertBuffSizes.push_back(0); } - fVertBuffStarts.Append(0); - fVertBuffEnds.Append(-1); + fVertBuffStarts.push_back(0); + fVertBuffEnds.push_back(-1); fColorBuffStorage.push_back(nullptr); fColorBuffCounts.push_back(0); @@ -1126,7 +1118,7 @@ plGBufferTriangle *plGBufferGroup::ConvertToTriList( int16_t spanIndex, uint32 /// Sanity checks hsAssert( whichIdx < fIdxBuffStorage.GetCount(), "Invalid index buffer ID to ConvertToTriList()" ); - hsAssert( whichVtx < fVertBuffStorage.GetCount(), "Invalid vertex buffer ID to ConvertToTriList()" ); + hsAssert( whichVtx < fVertBuffStorage.size(), "Invalid vertex buffer ID to ConvertToTriList()" ); hsAssert( start < fIdxBuffCounts[ whichIdx ], "Invalid start index to ConvertToTriList()" ); hsAssert( start + numTriangles * 3 <= fIdxBuffCounts[ whichIdx ], "Invalid count to ConvertToTriList()" ); hsAssert( whichCell < fCells[ whichVtx ]->size(), "Invalid cell to ConvertToTriList()" ); diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h index a611e550..07568dba 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h @@ -125,14 +125,14 @@ class plGBufferGroup hsTArray fVertexBufferRefs; hsTArray fIndexBufferRefs; - hsTArray fVertBuffSizes; + std::vector fVertBuffSizes; hsTArray fIdxBuffCounts; std::vector fColorBuffCounts; - hsTArray fVertBuffStorage; + std::vector fVertBuffStorage; hsTArray fIdxBuffStorage; - hsTArray fVertBuffStarts; - hsTArray fVertBuffEnds; + std::vector fVertBuffStarts; + std::vector fVertBuffEnds; hsTArray fIdxBuffStarts; hsTArray fIdxBuffEnds; @@ -231,7 +231,7 @@ class plGBufferGroup void SetIndexBufferEnd(uint32_t idx, uint32_t e) { fIdxBuffEnds[idx] = e; } /////////////////////////////////////////////////////////////////////////////// - uint32_t GetNumVertexBuffers( void ) const { return fVertBuffStorage.GetCount(); } + uint32_t GetNumVertexBuffers( void ) const { return fVertBuffStorage.size(); } uint32_t GetNumIndexBuffers( void ) const { return fIdxBuffStorage.GetCount(); } uint8_t *GetVertBufferData( uint32_t idx ) { return fVertBuffStorage[ idx ]; } From 6fd7ba5b8df4a56202f92d161e846300b6bf9f37 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 11 Jul 2015 19:15:21 -0400 Subject: [PATCH 4/9] plGBufferGroup index storage to std::vector --- .../PubUtilLib/plPipeline/plGBufferGroup.cpp | 54 +++++++++---------- .../PubUtilLib/plPipeline/plGBufferGroup.h | 10 ++-- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp index 45730248..20e98b72 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp @@ -113,7 +113,7 @@ void plGBufferCell::Write( hsStream *s ) plGBufferGroup::plGBufferGroup( uint8_t format, bool vertsVolatile, bool idxVolatile, int LOD ) { fVertBuffStorage.clear(); - fIdxBuffStorage.Reset(); + fIdxBuffStorage.clear(); fColorBuffStorage.clear(); fVertexBufferRefs.Reset(); fIndexBufferRefs.Reset(); @@ -208,7 +208,7 @@ void plGBufferGroup::CleanUp( void ) plProfile_DelMem(MemBufGrpVertex, fVertBuffSizes[i]); delete [] fVertBuffStorage[ i ]; } - for (size_t i = 0; i < fIdxBuffStorage.GetCount(); i++) + for (size_t i = 0; i < fIdxBuffStorage.size(); i++) { plProfile_DelMem(MemBufGrpIndex, fIdxBuffCounts[i] * sizeof(uint16_t)); delete [] fIdxBuffStorage[ i ]; @@ -226,10 +226,10 @@ void plGBufferGroup::CleanUp( void ) fVertBuffSizes.clear(); fVertBuffStarts.clear(); fVertBuffEnds.clear(); - fIdxBuffStorage.Reset(); - fIdxBuffCounts.Reset(); - fIdxBuffStarts.Reset(); - fIdxBuffEnds.Reset(); + fIdxBuffStorage.clear(); + fIdxBuffCounts.clear(); + fIdxBuffStarts.clear(); + fIdxBuffEnds.clear(); fColorBuffStorage.clear(); fColorBuffCounts.clear(); @@ -312,7 +312,7 @@ void plGBufferGroup::ISendStorageToBuffers( plPipeline *pipe, bool adjustForN plProfile_BeginTiming(DrawRefillIndex); - for (size_t i = 0; i < fIdxBuffStorage.GetCount(); i++) + for (size_t i = 0; i < fIdxBuffStorage.size(); i++) pipe->CheckIndexBufferRef(this, i); plProfile_EndTiming(DrawRefillIndex); @@ -367,11 +367,11 @@ void plGBufferGroup::Read( hsStream *s ) fVertBuffStarts.clear(); fVertBuffEnds.clear(); fColorBuffCounts.clear(); - fIdxBuffCounts.Reset(); - fIdxBuffStarts.Reset(); - fIdxBuffEnds.Reset(); + fIdxBuffCounts.clear(); + fIdxBuffStarts.clear(); + fIdxBuffEnds.clear(); fVertBuffStorage.clear(); - fIdxBuffStorage.Reset(); + fIdxBuffStorage.clear(); plVertCoder coder; /// Create buffers and read in as we go @@ -431,14 +431,14 @@ void plGBufferGroup::Read( hsStream *s ) for( i = 0; i < count; i++ ) { temp = s->ReadLE32(); - fIdxBuffCounts.Append( temp ); - fIdxBuffStarts.Append(0); - fIdxBuffEnds.Append(-1); + fIdxBuffCounts.push_back(temp); + fIdxBuffStarts.push_back(0); + fIdxBuffEnds.push_back(-1); iData = new uint16_t[ temp ]; hsAssert( iData != nil, "Not enough memory to read in indices" ); s->ReadLE16( temp, (uint16_t *)iData ); - fIdxBuffStorage.Append( iData ); + fIdxBuffStorage.push_back( iData ); plProfile_NewMem(MemBufGrpIndex, temp * sizeof(uint16_t)); } @@ -476,8 +476,8 @@ void plGBufferGroup::Write( hsStream *s ) totalDynSize = 0; for (auto it : fVertBuffSizes) totalDynSize += it; - for ( i = 0; i < fIdxBuffCounts.GetCount(); i++ ) - totalDynSize += sizeof( uint16_t ) * fIdxBuffCounts[ i ]; + for (auto it : fIdxBuffCounts) + totalDynSize += sizeof( uint16_t ) * it; s->WriteLE( fFormat ); s->WriteLE32( totalDynSize ); @@ -520,8 +520,8 @@ void plGBufferGroup::Write( hsStream *s ) #endif // MF_VERTCODE_ENABLED } - s->WriteLE32( (uint32_t)fIdxBuffCounts.GetCount() ); - for( i = 0; i < fIdxBuffStorage.GetCount(); i++ ) + s->WriteLE32( (uint32_t)fIdxBuffCounts.size() ); + for( i = 0; i < fIdxBuffStorage.size(); i++ ) { s->WriteLE32( fIdxBuffCounts[ i ] ); s->WriteLE16( fIdxBuffCounts[ i ], fIdxBuffStorage[ i ] ); @@ -1036,19 +1036,19 @@ bool plGBufferGroup::ReserveIndexStorage( uint32_t numIndices, uint32_t *ibIn } /// Find a spot - for( i = 0; i < fIdxBuffStorage.GetCount(); i++ ) + for( i = 0; i < fIdxBuffStorage.size(); i++ ) { if( fIdxBuffCounts[ i ] + numIndices < kMaxNumIndicesPerBuffer ) break; } - if( i == fIdxBuffStorage.GetCount() ) + if( i == fIdxBuffStorage.size() ) { - fIdxBuffStorage.Append( nil ); - fIdxBuffCounts.Append( 0 ); + fIdxBuffStorage.push_back(nullptr); + fIdxBuffCounts.push_back(0); - fIdxBuffStarts.Append(0); - fIdxBuffEnds.Append(-1); + fIdxBuffStarts.push_back(0); + fIdxBuffEnds.push_back(-1); } *ibIndex = i; @@ -1117,7 +1117,7 @@ plGBufferTriangle *plGBufferGroup::ConvertToTriList( int16_t spanIndex, uint32 /// Sanity checks - hsAssert( whichIdx < fIdxBuffStorage.GetCount(), "Invalid index buffer ID to ConvertToTriList()" ); + hsAssert( whichIdx < fIdxBuffStorage.size(), "Invalid index buffer ID to ConvertToTriList()" ); hsAssert( whichVtx < fVertBuffStorage.size(), "Invalid vertex buffer ID to ConvertToTriList()" ); hsAssert( start < fIdxBuffCounts[ whichIdx ], "Invalid start index to ConvertToTriList()" ); hsAssert( start + numTriangles * 3 <= fIdxBuffCounts[ whichIdx ], "Invalid count to ConvertToTriList()" ); @@ -1179,7 +1179,7 @@ void plGBufferGroup::StuffFromTriList( uint32_t which, uint32_t start, uint32 /// Sanity checks - hsAssert( which < fIdxBuffStorage.GetCount(), "Invalid index buffer ID to StuffFromTriList()" ); + hsAssert( which < fIdxBuffStorage.size(), "Invalid index buffer ID to StuffFromTriList()" ); hsAssert( start < fIdxBuffCounts[ which ], "Invalid start index to StuffFromTriList()" ); hsAssert( start + numTriangles * 3 <= fIdxBuffCounts[ which ], "Invalid count to StuffFromTriList()" ); diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h index 07568dba..4147c866 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h @@ -126,15 +126,15 @@ class plGBufferGroup hsTArray fIndexBufferRefs; std::vector fVertBuffSizes; - hsTArray fIdxBuffCounts; + std::vector fIdxBuffCounts; std::vector fColorBuffCounts; std::vector fVertBuffStorage; - hsTArray fIdxBuffStorage; + std::vector fIdxBuffStorage; std::vector fVertBuffStarts; std::vector fVertBuffEnds; - hsTArray fIdxBuffStarts; - hsTArray fIdxBuffEnds; + std::vector fIdxBuffStarts; + std::vector fIdxBuffEnds; std::vector fColorBuffStorage; @@ -232,7 +232,7 @@ class plGBufferGroup /////////////////////////////////////////////////////////////////////////////// uint32_t GetNumVertexBuffers( void ) const { return fVertBuffStorage.size(); } - uint32_t GetNumIndexBuffers( void ) const { return fIdxBuffStorage.GetCount(); } + uint32_t GetNumIndexBuffers( void ) const { return fIdxBuffStorage.size(); } uint8_t *GetVertBufferData( uint32_t idx ) { return fVertBuffStorage[ idx ]; } uint16_t *GetIndexBufferData( uint32_t idx ) { return fIdxBuffStorage[ idx ]; } From 662552e6e8e3f6138fed74a13d2cbd147cf47866 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 11 Jul 2015 19:27:16 -0400 Subject: [PATCH 5/9] plGBufferGroup device refs to std::vector --- .../PubUtilLib/plPipeline/plGBufferGroup.cpp | 74 +++++++++---------- .../PubUtilLib/plPipeline/plGBufferGroup.h | 14 ++-- 2 files changed, 42 insertions(+), 46 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp index 20e98b72..588fd63c 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp @@ -115,8 +115,8 @@ plGBufferGroup::plGBufferGroup( uint8_t format, bool vertsVolatile, bool idxVola fVertBuffStorage.clear(); fIdxBuffStorage.clear(); fColorBuffStorage.clear(); - fVertexBufferRefs.Reset(); - fIndexBufferRefs.Reset(); + fVertexBufferRefs.clear(); + fIndexBufferRefs.clear(); fCells.clear(); fNumVerts = fNumIndices = 0; @@ -131,29 +131,25 @@ plGBufferGroup::plGBufferGroup( uint8_t format, bool vertsVolatile, bool idxVola plGBufferGroup::~plGBufferGroup() { - uint32_t i; - CleanUp(); - for( i = 0; i < fVertexBufferRefs.GetCount(); i++ ) - hsRefCnt_SafeUnRef( fVertexBufferRefs[ i ] ); - - for( i = 0; i < fIndexBufferRefs.GetCount(); i++ ) - hsRefCnt_SafeUnRef( fIndexBufferRefs[ i ] ); - - fVertexBufferRefs.Reset(); - fIndexBufferRefs.Reset(); + for (auto i : fVertexBufferRefs) { + hsRefCnt_SafeUnRef(i); + } + for (auto i : fIndexBufferRefs) { + hsRefCnt_SafeUnRef(i); + } } -void plGBufferGroup::DirtyVertexBuffer(int i) +void plGBufferGroup::DirtyVertexBuffer(size_t i) { - if( (i < fVertexBufferRefs.GetCount()) && fVertexBufferRefs[i] ) + if( (i < fVertexBufferRefs.size()) && fVertexBufferRefs[i] ) fVertexBufferRefs[i]->SetDirty(true); } -void plGBufferGroup::DirtyIndexBuffer(int i) +void plGBufferGroup::DirtyIndexBuffer(size_t i) { - if( (i < fIndexBufferRefs.GetCount()) && fIndexBufferRefs[i] ) + if( (i < fIndexBufferRefs.size()) && fIndexBufferRefs[i] ) fIndexBufferRefs[i]->SetDirty(true); } @@ -240,11 +236,11 @@ void plGBufferGroup::CleanUp( void ) void plGBufferGroup::SetVertexBufferRef( uint32_t index, hsGDeviceRef *vb ) { - hsAssert( index < fVertexBufferRefs.GetCount() + 1, "Vertex buffers must be assigned linearly!" ); + hsAssert( index < fVertexBufferRefs.size() + 1, "Vertex buffers must be assigned linearly!" ); - if( (int)index > (int)fVertexBufferRefs.GetCount() - 1 ) + if (index > fVertexBufferRefs.size() - 1) { - fVertexBufferRefs.Append( vb ); + fVertexBufferRefs.push_back( vb ); hsRefCnt_SafeRef( vb ); } else @@ -258,11 +254,11 @@ void plGBufferGroup::SetVertexBufferRef( uint32_t index, hsGDeviceRef *vb ) void plGBufferGroup::SetIndexBufferRef( uint32_t index, hsGDeviceRef *ib ) { - hsAssert( index < fIndexBufferRefs.GetCount() + 1, "Index buffers must be assigned linearly!" ); + hsAssert( index < fIndexBufferRefs.size() + 1, "Index buffers must be assigned linearly!" ); - if( (int)index > (int)fIndexBufferRefs.GetCount() - 1 ) + if(index > fIndexBufferRefs.size() - 1) { - fIndexBufferRefs.Append( ib ); + fIndexBufferRefs.push_back( ib ); hsRefCnt_SafeRef( ib ); } else @@ -285,16 +281,16 @@ void plGBufferGroup::PrepForRendering( plPipeline *pipe, bool adjustForNvidia hsGDeviceRef* plGBufferGroup::GetVertexBufferRef(uint32_t i) { - if( i >= fVertexBufferRefs.GetCount() ) - fVertexBufferRefs.ExpandAndZero(i+1); + if( i >= fVertexBufferRefs.size() ) + fVertexBufferRefs.resize(i+1); return fVertexBufferRefs[i]; } hsGDeviceRef* plGBufferGroup::GetIndexBufferRef(uint32_t i) { - if( i >= fIndexBufferRefs.GetCount() ) - fIndexBufferRefs.ExpandAndZero(i+1); + if( i >= fIndexBufferRefs.size() ) + fIndexBufferRefs.resize(i+1); return fIndexBufferRefs[i]; } @@ -580,10 +576,10 @@ void plGBufferGroup::DeleteVertsFromStorage( uint32_t which, uint32_t start, fVertBuffSizes[ which ] -= length; plProfile_DelMem(MemBufGrpVertex, length); - if( fVertexBufferRefs.GetCount() > which && fVertexBufferRefs[ which ] != nil ) + if (fVertexBufferRefs.size() > which && fVertexBufferRefs[which]) { hsRefCnt_SafeUnRef(fVertexBufferRefs[which]); - fVertexBufferRefs[which] = nil; + fVertexBufferRefs[which] = nullptr; } } @@ -603,8 +599,8 @@ void plGBufferGroup::AdjustIndicesInStorage( uint32_t which, uint16_t threshh fIdxBuffStorage[ which ][ i ] += delta; } - if( fIndexBufferRefs.GetCount() > which && fIndexBufferRefs[ which ] != nil ) - fIndexBufferRefs[ which ]->SetDirty( true ); + if (fIndexBufferRefs.size() > which && fIndexBufferRefs[which]) + fIndexBufferRefs[which]->SetDirty( true ); } @@ -633,10 +629,10 @@ void plGBufferGroup::DeleteIndicesFromStorage( uint32_t which, uint32_t start fIdxBuffCounts[ which ] -= length; plProfile_DelMem(MemBufGrpIndex, length * sizeof(uint16_t)); - if( fIndexBufferRefs.GetCount() > which && fIndexBufferRefs[ which ] != nil ) + if (fIndexBufferRefs.size() > which && fIndexBufferRefs[which]) { hsRefCnt_SafeUnRef(fIndexBufferRefs[which]); - fIndexBufferRefs[which] = nil; + fIndexBufferRefs[which] = nullptr; } } @@ -802,10 +798,10 @@ bool plGBufferGroup::ReserveVertStorage( uint32_t numVerts, uint32_t *vbIndex plProfile_NewMem(MemBufGrpVertex, numVerts * sizeof(plGBufferColor)); } - if( fVertexBufferRefs.GetCount() > i && fVertexBufferRefs[ i ] != nil ) + if (fVertexBufferRefs.size() > i && fVertexBufferRefs[i]) { hsRefCnt_SafeUnRef(fVertexBufferRefs[i]); - fVertexBufferRefs[i] = nil; + fVertexBufferRefs[i] = nullptr; } /// Append a cell entry @@ -1015,7 +1011,7 @@ void plGBufferGroup::StuffToVertStorage( plGeometrySpan *srcSpan, uint32_t vb cPtr++; } - if( ( vbIndex < fVertexBufferRefs.GetCount() ) && fVertexBufferRefs[ vbIndex ] ) + if( ( vbIndex < fVertexBufferRefs.size() ) && fVertexBufferRefs[ vbIndex ] ) fVertexBufferRefs[ vbIndex ]->SetDirty( true ); } @@ -1071,10 +1067,10 @@ bool plGBufferGroup::ReserveIndexStorage( uint32_t numIndices, uint32_t *ibIn plProfile_NewMem(MemBufGrpIndex, numIndices * sizeof(uint16_t)); /// All done! - if( fIndexBufferRefs.GetCount() > i && fIndexBufferRefs[ i ] != nil ) + if ( fIndexBufferRefs.size() > i && fIndexBufferRefs[i]) { hsRefCnt_SafeUnRef(fIndexBufferRefs[i]); - fIndexBufferRefs[i] = nil; + fIndexBufferRefs[i] = nullptr; } return true; @@ -1200,8 +1196,8 @@ void plGBufferGroup::StuffFromTriList( uint32_t which, uint32_t start, uint32 #endif // MF_SPEED_THIS_UP /// All done! Just make sure we refresh before we render... - if( fIndexBufferRefs.GetCount() > which && fIndexBufferRefs[ which ] != nil ) - fIndexBufferRefs[ which ]->SetDirty( true ); + if (fIndexBufferRefs.size() > which && fIndexBufferRefs[which]) + fIndexBufferRefs[which]->SetDirty(true); } diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h index 4147c866..d12f119a 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h @@ -121,9 +121,9 @@ class plGBufferGroup bool fVertsVolatile; bool fIdxVolatile; int fLOD; - - hsTArray fVertexBufferRefs; - hsTArray fIndexBufferRefs; + + std::vector fVertexBufferRefs; + std::vector fIndexBufferRefs; std::vector fVertBuffSizes; std::vector fIdxBuffCounts; @@ -188,10 +188,10 @@ class plGBufferGroup static uint8_t CalcNumUVs( uint8_t format ) { return ( format & kUVCountMask ); } static uint8_t UVCountToFormat( uint8_t numUVs ) { return numUVs & kUVCountMask; } - void DirtyVertexBuffer(int i); - void DirtyIndexBuffer(int i); - bool VertexReady(int i) const { return (i < fVertexBufferRefs.GetCount()) && fVertexBufferRefs[i]; } - bool IndexReady(int i) const { return (i < fIndexBufferRefs.GetCount()) && fIndexBufferRefs[i]; } + void DirtyVertexBuffer(size_t i); + void DirtyIndexBuffer(size_t i); + bool VertexReady(size_t i) const { return (i < fVertexBufferRefs.size()) && fVertexBufferRefs[i]; } + bool IndexReady(size_t i) const { return (i < fIndexBufferRefs.size()) && fIndexBufferRefs[i]; } uint8_t GetVertexSize( void ) const { return fStride; } uint8_t GetVertexLiteStride( void ) const { return fLiteStride; } uint8_t GetVertexFormat( void ) const { return fFormat; } From 7721eebcc15ef5820cf2066aa346bfa40392320c Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 11 Jul 2015 19:29:07 -0400 Subject: [PATCH 6/9] WTF constructor... --- .../PubUtilLib/plPipeline/plGBufferGroup.cpp | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp index 588fd63c..f386a36a 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp @@ -110,21 +110,11 @@ void plGBufferCell::Write( hsStream *s ) //// Constructor ////////////////////////////////////////////////////////////// -plGBufferGroup::plGBufferGroup( uint8_t format, bool vertsVolatile, bool idxVolatile, int LOD ) +plGBufferGroup::plGBufferGroup(uint8_t format, bool vertsVolatile, bool idxVolatile, int LOD) + : fNumVerts(0), fNumIndices(0), fFormat(format), fVertsVolatile(vertsVolatile), + fIdxVolatile(idxVolatile), fLOD(LOD) { - fVertBuffStorage.clear(); - fIdxBuffStorage.clear(); - fColorBuffStorage.clear(); - fVertexBufferRefs.clear(); - fIndexBufferRefs.clear(); - fCells.clear(); - fNumVerts = fNumIndices = 0; - - fFormat = format; - fStride = ICalcVertexSize( fLiteStride ); - fVertsVolatile = vertsVolatile; - fIdxVolatile = idxVolatile; - fLOD = LOD; + fStride = ICalcVertexSize(fLiteStride); } //// Destructor /////////////////////////////////////////////////////////////// From a2842b5d862f3858126d8f1888a9d1916327f7d8 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 11 Jul 2015 19:32:04 -0400 Subject: [PATCH 7/9] Fix some debug stragglers --- Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp index f386a36a..68d050c4 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp @@ -850,7 +850,7 @@ void plGBufferGroup::AppendToColorStorage( plGeometrySpan *srcSpan, uint32_t void plGBufferGroup::IGetStartVtxPointer( uint32_t vbIndex, uint32_t cell, uint32_t offset, uint8_t *&tempPtr, plGBufferColor *&cPtr ) { - hsAssert( vbIndex < fVertBuffStorage.GetCount(), "Invalid vbIndex in StuffToVertStorage()" ); + hsAssert( vbIndex < fVertBuffStorage.size(), "Invalid vbIndex in StuffToVertStorage()" ); hsAssert( cell < fCells[ vbIndex ]->size(), "Invalid cell in StuffToVertStorage()" ); tempPtr = fVertBuffStorage[ vbIndex ]; @@ -880,7 +880,7 @@ uint32_t plGBufferGroup::GetVertStartFromCell( uint32_t vbIndex, uint32_t cell, uint32_t i, numVerts; - hsAssert( vbIndex < fVertBuffStorage.GetCount(), "Invalid vbIndex in StuffToVertStorage()" ); + hsAssert( vbIndex < fVertBuffStorage.size(), "Invalid vbIndex in StuffToVertStorage()" ); hsAssert( cell <= fCells[ vbIndex ]->size(), "Invalid cell in StuffToVertStorage()" ); numVerts = 0; @@ -904,7 +904,7 @@ void plGBufferGroup::StuffToVertStorage( plGeometrySpan *srcSpan, uint32_t vb plGBufferCell *cellPtr; - hsAssert( vbIndex < fVertBuffStorage.GetCount(), "Invalid vbIndex in StuffToVertStorage()" ); + hsAssert( vbIndex < fVertBuffStorage.size(), "Invalid vbIndex in StuffToVertStorage()" ); hsAssert( cell < fCells[ vbIndex ]->size(), "Invalid cell in StuffToVertStorage()" ); IGetStartVtxPointer( vbIndex, cell, offset, tempPtr, cPtr ); @@ -1196,7 +1196,7 @@ void plGBufferGroup::StuffFromTriList( uint32_t which, uint32_t start, uint32 void plGBufferGroup::StuffTri( uint32_t iBuff, uint32_t iTri, uint16_t idx0, uint16_t idx1, uint16_t idx2 ) { /// Sanity checks - hsAssert( iBuff < fIdxBuffStorage.GetCount(), "Invalid index buffer ID to StuffFromTriList()" ); + hsAssert( iBuff < fIdxBuffStorage.size(), "Invalid index buffer ID to StuffFromTriList()" ); hsAssert( iTri < fIdxBuffCounts[ iBuff ], "Invalid start index to StuffFromTriList()" ); fIdxBuffStorage[ iBuff ][ iTri + 0 ] = idx0; From 4c68c6e5f84c000144d663d053a641e5fc593343 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 12 Jul 2015 16:26:32 -0400 Subject: [PATCH 8/9] Reserve GBufferGroup vector memory --- .../Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp index 68d050c4..66c942f9 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp @@ -360,8 +360,15 @@ void plGBufferGroup::Read( hsStream *s ) fIdxBuffStorage.clear(); plVertCoder coder; + /// Create buffers and read in as we go count = s->ReadLE32(); + fVertBuffSizes.reserve(count); + fVertBuffStarts.reserve(count); + fVertBuffEnds.reserve(count); + fVertBuffStorage.reserve(count); + fColorBuffCounts.reserve(count); + fColorBuffStorage.reserve(count); for( i = 0; i < count; i++ ) { if( fFormat & kEncoded ) @@ -414,6 +421,10 @@ void plGBufferGroup::Read( hsStream *s ) } count = s->ReadLE32(); + fIdxBuffCounts.reserve(count); + fIdxBuffStarts.reserve(count); + fIdxBuffEnds.reserve(count); + fIdxBuffStorage.reserve(count); for( i = 0; i < count; i++ ) { temp = s->ReadLE32(); @@ -429,6 +440,7 @@ void plGBufferGroup::Read( hsStream *s ) } /// Read in cell arrays, one per vBuffer + fCells.reserve(fVertBuffStorage.size()); for( i = 0; i < fVertBuffStorage.size(); i++ ) { temp = s->ReadLE32(); From f48a80ab60b794252a46685dde5787598d22ba63 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 12 Jul 2015 16:34:25 -0400 Subject: [PATCH 9/9] Nuke totally unnesecary vector pointer --- .../PubUtilLib/plPipeline/plGBufferGroup.cpp | 72 +++++++++---------- .../PubUtilLib/plPipeline/plGBufferGroup.h | 6 +- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp index 66c942f9..f83c6ebc 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.cpp @@ -205,9 +205,6 @@ void plGBufferGroup::CleanUp( void ) delete [] fColorBuffStorage[ i ]; } - for (auto i : fCells) - delete i; - fVertBuffStorage.clear(); fVertBuffSizes.clear(); fVertBuffStarts.clear(); @@ -440,16 +437,15 @@ void plGBufferGroup::Read( hsStream *s ) } /// Read in cell arrays, one per vBuffer - fCells.reserve(fVertBuffStorage.size()); + fCells.resize(fVertBuffStorage.size()); for( i = 0; i < fVertBuffStorage.size(); i++ ) { temp = s->ReadLE32(); - fCells.push_back( new std::vector ); - fCells[ i ]->resize( temp ); + fCells[ i ].resize( temp ); for( j = 0; j < temp; j++ ) - (*fCells[ i ])[ j ].Read( s ); + fCells[ i ][ j ].Read( s ); } } @@ -488,7 +484,7 @@ void plGBufferGroup::Write( hsStream *s ) { #ifdef MF_VERTCODE_ENABLED - hsAssert(fCells[i]->size() == 1, "Data must be interleaved for compression"); + hsAssert(fCells[i].size() == 1, "Data must be interleaved for compression"); uint32_t numVerts = fVertBuffSizes[i] / fStride; s->WriteLE16((uint16_t)numVerts); coder.Write(s, fVertBuffStorage[i], fFormat, fStride, (uint16_t)numVerts); @@ -528,9 +524,9 @@ void plGBufferGroup::Write( hsStream *s ) /// Write out cell arrays for (i = 0; i < fVertBuffStorage.size(); i++) { - s->WriteLE32( fCells[ i ]->size() ); - for( j = 0; j < fCells[ i ]->size(); j++ ) - (*fCells[ i ])[ j ].Write( s ); + s->WriteLE32( fCells[ i ].size() ); + for( j = 0; j < fCells[ i ].size(); j++ ) + fCells[ i ][ j ].Write( s ); } #ifdef VERT_LOG @@ -557,10 +553,10 @@ void plGBufferGroup::DeleteVertsFromStorage( uint32_t which, uint32_t start, uint32_t amount; - hsAssert( fCells[ which ]->size() == 1, "Cannot delete verts on a mixed buffer group" ); + hsAssert( fCells[ which ].size() == 1, "Cannot delete verts on a mixed buffer group" ); // Adjust cell 0 - (*fCells[ which ])[ 0 ].fLength -= length; + fCells[ which ][ 0 ].fLength -= length; start *= fStride; length *= fStride; @@ -656,7 +652,7 @@ uint32_t plGBufferGroup::GetNumVertsLeft( uint32_t idx ) const return kMaxNumVertsPerBuffer; uint32_t total = kMaxNumVertsPerBuffer; - for( const auto& i : *fCells[ idx ] ) + for( const auto& i : fCells[ idx ] ) total -= i.fLength; return total; @@ -667,7 +663,7 @@ uint32_t plGBufferGroup::GetNumVertsLeft( uint32_t idx ) const uint32_t plGBufferGroup::IMakeCell( uint32_t vbIndex, uint8_t flags, uint32_t vStart, uint32_t cStart, uint32_t len, uint32_t *offset ) { - std::vector* cells = fCells[ vbIndex ]; + std::vector& cells = fCells[ vbIndex ]; if( !(flags & kReserveInterleaved) ) @@ -678,27 +674,27 @@ uint32_t plGBufferGroup::IMakeCell( uint32_t vbIndex, uint8_t flags, uint32_t v /// we never merge any separated cells if( flags & kReserveSeparated ) - cells->emplace_back(vStart, cStart, len); + cells.emplace_back(vStart, cStart, len); else - cells->emplace_back((uint32_t)-1, cStart, len); + cells.emplace_back((uint32_t)-1, cStart, len); *offset = 0; } else { /// Merge if the last cell was an interleaved cell - if( !cells->empty() && cells->back().fColorStart == (uint32_t)-1 ) + if( !cells.empty() && cells.back().fColorStart == (uint32_t)-1 ) { - *offset = cells->back().fLength; - cells->back().fLength += len; + *offset = cells.back().fLength; + cells.back().fLength += len; } else { - cells->emplace_back(vStart, (uint32_t)-1, len); + cells.emplace_back(vStart, (uint32_t)-1, len); *offset = 0; } } - return cells->size() - 1; + return cells.size() - 1; } //// ReserveVertStorage /////////////////////////////////////////////////////// @@ -746,7 +742,7 @@ bool plGBufferGroup::ReserveVertStorage( uint32_t numVerts, uint32_t *vbIndex fColorBuffStorage.push_back(nullptr); fColorBuffCounts.push_back(0); - fCells.push_back( new std::vector ); + fCells.emplace_back(); } *vbIndex = i; @@ -852,7 +848,7 @@ void plGBufferGroup::AppendToColorStorage( plGeometrySpan *srcSpan, uint32_t if( !ReserveVertStorage( srcSpan->fNumVerts, vbIndex, cell, offset, kReserveColors ) ) return; - (*fCells[ *vbIndex ])[ *cell ].fVtxStart = (*fCells[ *vbIndex ])[ origCell ].fVtxStart; + fCells[ *vbIndex ][ *cell ].fVtxStart = fCells[ *vbIndex ][ origCell ].fVtxStart; StuffToVertStorage( srcSpan, *vbIndex, *cell, *offset, kReserveColors ); } @@ -863,17 +859,17 @@ void plGBufferGroup::AppendToColorStorage( plGeometrySpan *srcSpan, uint32_t void plGBufferGroup::IGetStartVtxPointer( uint32_t vbIndex, uint32_t cell, uint32_t offset, uint8_t *&tempPtr, plGBufferColor *&cPtr ) { hsAssert( vbIndex < fVertBuffStorage.size(), "Invalid vbIndex in StuffToVertStorage()" ); - hsAssert( cell < fCells[ vbIndex ]->size(), "Invalid cell in StuffToVertStorage()" ); + hsAssert( cell < fCells[ vbIndex ].size(), "Invalid cell in StuffToVertStorage()" ); tempPtr = fVertBuffStorage[ vbIndex ]; cPtr = fColorBuffStorage[ vbIndex ]; - tempPtr += (*fCells[ vbIndex ])[ cell ].fVtxStart; - cPtr += (*fCells[ vbIndex ])[ cell ].fColorStart; + tempPtr += fCells[ vbIndex ][ cell ].fVtxStart; + cPtr += fCells[ vbIndex ][ cell ].fColorStart; if( offset > 0 ) { - tempPtr += offset * ( ( (*fCells[ vbIndex ])[ cell ].fColorStart == (uint32_t)-1 ) ? fStride : fLiteStride ); + tempPtr += offset * ( ( fCells[ vbIndex ][ cell ].fColorStart == (uint32_t)-1 ) ? fStride : fLiteStride ); cPtr += offset; } } @@ -882,7 +878,7 @@ void plGBufferGroup::IGetStartVtxPointer( uint32_t vbIndex, uint32_t cell, ui uint32_t plGBufferGroup::GetVertBufferCount( uint32_t idx ) const { - return GetVertStartFromCell( idx, fCells[ idx ]->size(), 0 ); + return GetVertStartFromCell( idx, fCells[ idx ].size(), 0 ); } //// GetVertStartFromCell ///////////////////////////////////////////////////// @@ -893,11 +889,11 @@ uint32_t plGBufferGroup::GetVertStartFromCell( uint32_t vbIndex, uint32_t cell, hsAssert( vbIndex < fVertBuffStorage.size(), "Invalid vbIndex in StuffToVertStorage()" ); - hsAssert( cell <= fCells[ vbIndex ]->size(), "Invalid cell in StuffToVertStorage()" ); + hsAssert( cell <= fCells[ vbIndex ].size(), "Invalid cell in StuffToVertStorage()" ); numVerts = 0; for( i = 0; i < cell; i++ ) - numVerts += (*fCells[ vbIndex ])[ i ].fLength; + numVerts += fCells[ vbIndex ][ i ].fLength; numVerts += offset; @@ -917,10 +913,10 @@ void plGBufferGroup::StuffToVertStorage( plGeometrySpan *srcSpan, uint32_t vb hsAssert( vbIndex < fVertBuffStorage.size(), "Invalid vbIndex in StuffToVertStorage()" ); - hsAssert( cell < fCells[ vbIndex ]->size(), "Invalid cell in StuffToVertStorage()" ); + hsAssert( cell < fCells[ vbIndex ].size(), "Invalid cell in StuffToVertStorage()" ); IGetStartVtxPointer( vbIndex, cell, offset, tempPtr, cPtr ); - cellPtr = &(*fCells[ vbIndex ])[ cell ]; + cellPtr = &fCells[ vbIndex ][ cell ]; stride = ( cellPtr->fColorStart != (uint32_t)-1 ) ? fLiteStride : fStride; numVerts = srcSpan->fNumVerts; @@ -1119,7 +1115,7 @@ plGBufferTriangle *plGBufferGroup::ConvertToTriList( int16_t spanIndex, uint32 hsAssert( whichVtx < fVertBuffStorage.size(), "Invalid vertex buffer ID to ConvertToTriList()" ); hsAssert( start < fIdxBuffCounts[ whichIdx ], "Invalid start index to ConvertToTriList()" ); hsAssert( start + numTriangles * 3 <= fIdxBuffCounts[ whichIdx ], "Invalid count to ConvertToTriList()" ); - hsAssert( whichCell < fCells[ whichVtx ]->size(), "Invalid cell to ConvertToTriList()" ); + hsAssert( whichCell < fCells[ whichVtx ].size(), "Invalid cell to ConvertToTriList()" ); /// Create the array and fill it array = new plGBufferTriangle[ numTriangles ]; @@ -1128,7 +1124,7 @@ plGBufferTriangle *plGBufferGroup::ConvertToTriList( int16_t spanIndex, uint32 storagePtr = fIdxBuffStorage[ whichIdx ]; IGetStartVtxPointer( whichVtx, whichCell, 0, vertStgPtr, wastePtr ); offsetBy = GetVertStartFromCell( whichVtx, whichCell, 0 ); - stride = ( (*fCells[ whichVtx ])[ whichCell ].fColorStart == (uint32_t)-1 ) ? fStride : fLiteStride; + stride = ( fCells[ whichVtx ][ whichCell ].fColorStart == (uint32_t)-1 ) ? fStride : fLiteStride; for( i = 0, j = 0; i < numTriangles; i++, j += 3 ) { @@ -1246,7 +1242,7 @@ uint32_t &plGBufferGroup::Color( int iBuff, uint32_t cell, int iVtx ) IGetStartVtxPointer( iBuff, cell, iVtx, vertStgPtr, cPtr ); - if( (*fCells[ iBuff ])[ cell ].fColorStart != (uint32_t)-1 ) + if( fCells[ iBuff ][ cell ].fColorStart != (uint32_t)-1 ) return *(uint32_t *)( &cPtr->fDiffuse ); else return *(uint32_t *)( vertStgPtr + 2 * sizeof( hsPoint3 ) ); @@ -1259,7 +1255,7 @@ uint32_t &plGBufferGroup::Specular( int iBuff, uint32_t cell, int iVtx ) IGetStartVtxPointer( iBuff, cell, iVtx, vertStgPtr, cPtr ); - if( (*fCells[ iBuff ])[ cell ].fColorStart != (uint32_t)-1 ) + if( fCells[ iBuff ][ cell ].fColorStart != (uint32_t)-1 ) return *(uint32_t *)( &cPtr->fSpecular ); else return *(uint32_t *)( vertStgPtr + 2 * sizeof( hsPoint3 ) ); @@ -1274,7 +1270,7 @@ hsPoint3 &plGBufferGroup::UV( int iBuff, uint32_t cell, int iVtx, int channel vertStgPtr += 2 * sizeof( hsPoint3 ) + channel * sizeof( hsPoint3 ); - if( (*fCells[ iBuff ])[ cell ].fColorStart != (uint32_t)-1 ) + if( fCells[ iBuff ][ cell ].fColorStart != (uint32_t)-1 ) return *(hsPoint3 *)( vertStgPtr ); else return *(hsPoint3 *)( vertStgPtr + 2 * sizeof( uint32_t ) ); diff --git a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h index d12f119a..5bf8a57a 100644 --- a/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h +++ b/Sources/Plasma/PubUtilLib/plPipeline/plGBufferGroup.h @@ -138,7 +138,7 @@ class plGBufferGroup std::vector fColorBuffStorage; - std::vector*> fCells; + std::vector> fCells; virtual void ISendStorageToBuffers( plPipeline *pipe, bool adjustForNvidiaLighting ); @@ -241,8 +241,8 @@ class plGBufferGroup hsGDeviceRef *GetVertexBufferRef( uint32_t i ); hsGDeviceRef *GetIndexBufferRef( uint32_t i ); - size_t GetNumCells( size_t idx ) const { return fCells[ idx ]->size(); } - plGBufferCell *GetCell( size_t idx, size_t cell ) { return &( (*fCells[ idx ])[ cell ] ); } + size_t GetNumCells( size_t idx ) const { return fCells[ idx ].size(); } + plGBufferCell *GetCell( size_t idx, size_t cell ) { return &(fCells[ idx ][ cell ]); } void SetVertexBufferRef( uint32_t index, hsGDeviceRef *vb ); void SetIndexBufferRef( uint32_t index, hsGDeviceRef *ib );