| 224 | } |
| 225 | |
| 226 | Tr2GpuResourcePool::Buffer Tr2GpuResourcePool::GetPersistentBuffer( const char* name, const Tr2BufferDescriptionAL& desc, const BufferInitializer& initializer ) |
| 227 | { |
| 228 | if( desc.count == 0 ) |
| 229 | { |
| 230 | CCP_LOGERR( "Invalid buffer description for a persistent buffer %s (elements=%u, stride=%u, format=%u)", name, desc.count, desc.stride, (uint32_t)desc.format ); |
| 231 | return {}; |
| 232 | } |
| 233 | auto found = find_if( begin( m_persistentBuffers ), end( m_persistentBuffers ), [&]( const auto& x ) { |
| 234 | return CompatibleDescriptions( x->resource.GetDesc(), desc ) && x->name == name; |
| 235 | } ); |
| 236 | USE_MAIN_THREAD_RENDER_CONTEXT(); |
| 237 | if( found == end( m_persistentBuffers ) ) |
| 238 | { |
| 239 | auto buf = std::make_shared<BufferRec>(); |
| 240 | auto initData = std::get_if<const void*>( &initializer ); |
| 241 | if( FAILED( buf->resource.Create( desc, initData ? *initData : nullptr, renderContext ) ) ) |
| 242 | { |
| 243 | CCP_LOGERR( "Failed to create a temporary buffer %s (elements=%u, stride=%u, format=%u)", name, desc.count, desc.stride, (uint32_t)desc.format ); |
| 244 | return Buffer(); |
| 245 | } |
| 246 | buf->resource.SetName( name ); |
| 247 | if( auto initFunc = std::get_if<std::function<void( Tr2BufferAL & buffer, Tr2RenderContextAL & renderContext )>>( &initializer ) ) |
| 248 | { |
| 249 | ( *initFunc )( buf->resource, renderContext ); |
| 250 | } |
| 251 | buf->lastAccessFrame = renderContext.GetRecordingFrameNumber(); |
| 252 | buf->name = name; |
| 253 | m_persistentBuffers.push_back( buf ); |
| 254 | return Buffer( buf ); |
| 255 | } |
| 256 | ( *found )->lastAccessFrame = renderContext.GetRecordingFrameNumber(); |
| 257 | return Buffer( *found ); |
| 258 | } |
| 259 | |
| 260 | void Tr2GpuResourcePool::SetDebugMode( bool enable ) |
| 261 | { |
no test coverage detected