Perform GPU to CPU resynchronization on each collect event.

This commit is contained in:
Bartosz Taudul 2017-11-25 13:33:57 +01:00
parent 0100266234
commit a515bf8878
5 changed files with 75 additions and 0 deletions

View File

@ -102,6 +102,22 @@ public:
tail.store( magic + 1, std::memory_order_release ); tail.store( magic + 1, std::memory_order_release );
m_tail = ( m_tail + 1 ) % QueryCount; m_tail = ( m_tail + 1 ) % QueryCount;
} }
{
int64_t tgpu;
glGetInteger64v( GL_TIMESTAMP, &tgpu );
int64_t tcpu = Profiler::GetTime();
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
item->hdr.type = QueueType::GpuResync;
item->gpuResync.cpuTime = tcpu;
item->gpuResync.gpuTime = tgpu;
item->gpuResync.context = m_context;
tail.store( magic + 1, std::memory_order_release );
}
} }
private: private:

View File

@ -26,6 +26,7 @@ enum class QueueType : uint8_t
GpuZoneBegin, GpuZoneBegin,
GpuZoneEnd, GpuZoneEnd,
GpuTime, GpuTime,
GpuResync,
StringData, StringData,
ThreadName, ThreadName,
CustomStringData, CustomStringData,
@ -162,6 +163,13 @@ struct QueueGpuTime
uint16_t context; uint16_t context;
}; };
struct QueueGpuResync
{
int64_t cpuTime;
int64_t gpuTime;
uint16_t context;
};
struct QueueHeader struct QueueHeader
{ {
union union
@ -192,6 +200,7 @@ struct QueueItem
QueueGpuZoneBegin gpuZoneBegin; QueueGpuZoneBegin gpuZoneBegin;
QueueGpuZoneEnd gpuZoneEnd; QueueGpuZoneEnd gpuZoneEnd;
QueueGpuTime gpuTime; QueueGpuTime gpuTime;
QueueGpuResync gpuResync;
}; };
}; };
@ -219,6 +228,7 @@ static const size_t QueueDataSize[] = {
sizeof( QueueHeader ) + sizeof( QueueGpuZoneBegin ), sizeof( QueueHeader ) + sizeof( QueueGpuZoneBegin ),
sizeof( QueueHeader ) + sizeof( QueueGpuZoneEnd ), sizeof( QueueHeader ) + sizeof( QueueGpuZoneEnd ),
sizeof( QueueHeader ) + sizeof( QueueGpuTime ), sizeof( QueueHeader ) + sizeof( QueueGpuTime ),
sizeof( QueueHeader ) + sizeof( QueueGpuResync ),
// keep all QueueStringTransfer below // keep all QueueStringTransfer below
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // string data sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // string data
sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // thread name sizeof( QueueHeader ) + sizeof( QueueStringTransfer ), // thread name

View File

@ -151,6 +151,12 @@ struct ThreadData
Vector<MessageData*> messages; Vector<MessageData*> messages;
}; };
struct GpuCtxResync
{
int64_t timeDiff;
uint16_t events;
};
struct GpuCtxData struct GpuCtxData
{ {
int64_t timeDiff; int64_t timeDiff;
@ -159,6 +165,7 @@ struct GpuCtxData
Vector<GpuEvent*> timeline; Vector<GpuEvent*> timeline;
Vector<GpuEvent*> stack; Vector<GpuEvent*> stack;
Vector<GpuEvent*> queue; Vector<GpuEvent*> queue;
Vector<GpuCtxResync> resync;
uint8_t accuracyBits; uint8_t accuracyBits;
bool showFull; bool showFull;
}; };

View File

@ -619,6 +619,9 @@ void View::Process( const QueueItem& ev )
case QueueType::GpuTime: case QueueType::GpuTime:
ProcessGpuTime( ev.gpuTime ); ProcessGpuTime( ev.gpuTime );
break; break;
case QueueType::GpuResync:
ProcessGpuResync( ev.gpuResync );
break;
case QueueType::Terminate: case QueueType::Terminate:
m_terminate = true; m_terminate = true;
break; break;
@ -912,6 +915,44 @@ void View::ProcessGpuTime( const QueueGpuTime& ev )
} }
ctx->queue.erase( ctx->queue.begin() ); ctx->queue.erase( ctx->queue.begin() );
if( !ctx->resync.empty() )
{
auto& resync = ctx->resync.front();
assert( resync.events > 0 );
resync.events--;
if( resync.events == 0 )
{
ctx->timeDiff = resync.timeDiff;
ctx->resync.erase( ctx->resync.begin() );
}
}
}
void View::ProcessGpuResync( const QueueGpuResync& ev )
{
auto it = m_gpuCtxMap.find( ev.context );
assert( it != m_gpuCtxMap.end() );
auto ctx = it->second;
const auto timeDiff = int64_t( ev.cpuTime * m_timerMul - ev.gpuTime );
if( ctx->queue.empty() )
{
assert( ctx->resync.empty() );
ctx->timeDiff = timeDiff;
}
else
{
if( ctx->resync.empty() )
{
ctx->resync.push_back( { timeDiff, uint16_t( ctx->queue.size() ) } );
}
else
{
const auto last = ctx->resync.back().events;
ctx->resync.push_back( { timeDiff, uint16_t( ctx->queue.size() - last ) } );
}
}
} }
void View::CheckString( uint64_t ptr ) void View::CheckString( uint64_t ptr )

View File

@ -76,6 +76,7 @@ private:
tracy_force_inline void ProcessGpuZoneBegin( const QueueGpuZoneBegin& ev ); tracy_force_inline void ProcessGpuZoneBegin( const QueueGpuZoneBegin& ev );
tracy_force_inline void ProcessGpuZoneEnd( const QueueGpuZoneEnd& ev ); tracy_force_inline void ProcessGpuZoneEnd( const QueueGpuZoneEnd& ev );
tracy_force_inline void ProcessGpuTime( const QueueGpuTime& ev ); tracy_force_inline void ProcessGpuTime( const QueueGpuTime& ev );
tracy_force_inline void ProcessGpuResync( const QueueGpuResync& ev );
void CheckString( uint64_t ptr ); void CheckString( uint64_t ptr );
void CheckThreadString( uint64_t id ); void CheckThreadString( uint64_t id );