MCPcopy Create free account
hub / github.com/carbonengine/trinity / Expand

Method Expand

trinity/Tr2SuballocatedBuffer.cpp:123–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

121}
122
123ALResult Tr2SuballocatedBuffer::Expand()
124{
125 USE_MAIN_THREAD_RENDER_CONTEXT();
126
127 //We have reached the allocator's max size. This probably means we're leaking a lot of memory.
128 if( m_allocator.GetCurrentSize() == m_allocator.GetMaxSize() )
129 {
130 CCP_LOGERR( "Max size reached for buffer '%s'. This probably means we're leaking a lot of memory.", m_name.c_str() );
131 return E_OUTOFMEMORY;
132 }
133
134 uint32_t oldBufferSize = static_cast<uint32_t>( m_allocator.GetCurrentSize() );
135 uint32_t newBufferSize = oldBufferSize + static_cast<uint32_t>( m_allocator.GetBlockSize() );
136
137 Tr2BufferAL newBuffer;
138 Tr2BufferDescriptionAL desc( 1, newBufferSize, m_gpuUsage, Tr2CpuUsage::READ | Tr2CpuUsage::WRITE );
139 ALResult result = newBuffer.Create( desc, nullptr, renderContext );
140 if( FAILED( result ) )
141 {
142 CCP_LOGERR( "Failed to allocate %zu MBs for buffer '%s'.", newBufferSize / size_t( 1024 * 1024 ), m_name.c_str() );
143 return result;
144 }
145 newBuffer.SetName( m_name.c_str() );
146
147 //If the previous buffer had valid data, we copy it over to the new buffer.
148 if( m_buffer.IsValid() )
149 {
150 renderContext.CopySubBuffer( newBuffer, 0, m_buffer, 0, oldBufferSize );
151 }
152
153 m_buffer = newBuffer;
154
155 m_allocator.Expand(); //Cannot fail, as we checked this first.
156
157 CCP_ASSERT( m_allocator.GetCurrentSize() == newBufferSize );
158
159 CCP_LOG( "Allocating more buffer memory for buffer '%s'. Total memory allocated: %zu MBs", m_name.c_str(), newBufferSize / size_t( 1024 * 1024 ) );
160 CCP_STATS_SET( suballocatedBufferCapacity, m_allocator.GetMaxSize() );
161
162 return S_OK;
163}
164
165ALResult Tr2SuballocatedBuffer::ReadBuffer( std::unique_ptr<uint8_t[]>& dest, uint32_t offset, uint32_t size, Tr2RenderContextAL& renderContext )
166{

Callers

nothing calls this directly

Calls 7

GetCurrentSizeMethod · 0.80
GetMaxSizeMethod · 0.80
GetBlockSizeMethod · 0.80
CreateMethod · 0.45
SetNameMethod · 0.45
IsValidMethod · 0.45
CopySubBufferMethod · 0.45

Tested by

no test coverage detected