mirror of
https://github.com/wolfpld/tracy
synced 2025-04-30 12:53:51 +00:00
GPU time transfer.
This commit is contained in:
parent
a0729d3500
commit
7ebaa46f75
@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
|
||||||
|
#include "Tracy.hpp"
|
||||||
#include "client/TracyProfiler.hpp"
|
#include "client/TracyProfiler.hpp"
|
||||||
|
|
||||||
#define TracyGpuZone( ctx, name ) static const tracy::SourceLocation __tracy_gpu_source_location { __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; auto ___tracy_gpu_zone = tracy::detail::__GpuHelper( ctx, name, &__tracy_gpu_source_location );
|
#define TracyGpuZone( ctx, name ) static const tracy::SourceLocation __tracy_gpu_source_location { __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; auto ___tracy_gpu_zone = tracy::detail::__GpuHelper( ctx, name, &__tracy_gpu_source_location );
|
||||||
@ -95,6 +96,48 @@ public:
|
|||||||
tail.store( magic + 1, std::memory_order_release );
|
tail.store( magic + 1, std::memory_order_release );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Collect()
|
||||||
|
{
|
||||||
|
ZoneScopedC( 0x881111 );
|
||||||
|
|
||||||
|
auto start = m_tail;
|
||||||
|
auto end = m_head + Num;
|
||||||
|
auto cnt = ( end - start ) % Num;
|
||||||
|
while( cnt > 1 )
|
||||||
|
{
|
||||||
|
auto mid = start + cnt / 2;
|
||||||
|
GLint available;
|
||||||
|
glGetQueryObjectiv( m_query[mid % Num], GL_QUERY_RESULT_AVAILABLE, &available );
|
||||||
|
if( available )
|
||||||
|
{
|
||||||
|
start = mid;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
end = mid;
|
||||||
|
}
|
||||||
|
cnt = ( end - start ) % Num;
|
||||||
|
}
|
||||||
|
|
||||||
|
start %= Num;
|
||||||
|
|
||||||
|
while( m_tail != start )
|
||||||
|
{
|
||||||
|
uint64_t time;
|
||||||
|
glGetQueryObjectui64v( m_query[m_tail], GL_QUERY_RESULT, &time );
|
||||||
|
|
||||||
|
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::GpuTime;
|
||||||
|
item->gpuTime.gpuTime = (int64_t)time;
|
||||||
|
item->gpuTime.context = m_context;
|
||||||
|
tail.store( magic + 1, std::memory_order_release );
|
||||||
|
m_tail = ( m_tail + 1 ) % Num;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
tracy_force_inline __GpuCtxScope<Num> SpawnZone( const char* name, const SourceLocation* srcloc )
|
tracy_force_inline __GpuCtxScope<Num> SpawnZone( const char* name, const SourceLocation* srcloc )
|
||||||
{
|
{
|
||||||
|
@ -32,6 +32,7 @@ enum class QueueType : uint8_t
|
|||||||
GpuNewContext,
|
GpuNewContext,
|
||||||
GpuZoneBegin,
|
GpuZoneBegin,
|
||||||
GpuZoneEnd,
|
GpuZoneEnd,
|
||||||
|
GpuTime,
|
||||||
NUM_TYPES
|
NUM_TYPES
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -163,6 +164,12 @@ struct QueueGpuZoneEnd
|
|||||||
uint16_t context;
|
uint16_t context;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct QueueGpuTime
|
||||||
|
{
|
||||||
|
int64_t gpuTime;
|
||||||
|
uint16_t context;
|
||||||
|
};
|
||||||
|
|
||||||
struct QueueHeader
|
struct QueueHeader
|
||||||
{
|
{
|
||||||
union
|
union
|
||||||
@ -193,6 +200,7 @@ struct QueueItem
|
|||||||
QueueGpuNewContext gpuNewContext;
|
QueueGpuNewContext gpuNewContext;
|
||||||
QueueGpuZoneBegin gpuZoneBegin;
|
QueueGpuZoneBegin gpuZoneBegin;
|
||||||
QueueGpuZoneEnd gpuZoneEnd;
|
QueueGpuZoneEnd gpuZoneEnd;
|
||||||
|
QueueGpuTime gpuTime;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -225,6 +233,7 @@ static const size_t QueueDataSize[] = {
|
|||||||
sizeof( QueueHeader ) + sizeof( QueueGpuNewContext ),
|
sizeof( QueueHeader ) + sizeof( QueueGpuNewContext ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueueGpuZoneBegin ),
|
sizeof( QueueHeader ) + sizeof( QueueGpuZoneBegin ),
|
||||||
sizeof( QueueHeader ) + sizeof( QueueGpuZoneEnd ),
|
sizeof( QueueHeader ) + sizeof( QueueGpuZoneEnd ),
|
||||||
|
sizeof( QueueHeader ) + sizeof( QueueGpuTime ),
|
||||||
};
|
};
|
||||||
|
|
||||||
static_assert( QueueItemSize == 32, "Queue item size not 32 bytes" );
|
static_assert( QueueItemSize == 32, "Queue item size not 32 bytes" );
|
||||||
|
@ -597,6 +597,9 @@ void View::Process( const QueueItem& ev )
|
|||||||
case QueueType::GpuZoneEnd:
|
case QueueType::GpuZoneEnd:
|
||||||
ProcessGpuZoneEnd( ev.gpuZoneEnd );
|
ProcessGpuZoneEnd( ev.gpuZoneEnd );
|
||||||
break;
|
break;
|
||||||
|
case QueueType::GpuTime:
|
||||||
|
ProcessGpuTime( ev.gpuTime );
|
||||||
|
break;
|
||||||
case QueueType::Terminate:
|
case QueueType::Terminate:
|
||||||
m_terminate = true;
|
m_terminate = true;
|
||||||
break;
|
break;
|
||||||
@ -908,6 +911,26 @@ void View::ProcessGpuZoneEnd( const QueueGpuZoneEnd& ev )
|
|||||||
zone->thread = ev.thread;
|
zone->thread = ev.thread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void View::ProcessGpuTime( const QueueGpuTime& ev )
|
||||||
|
{
|
||||||
|
assert( m_gpuData.size() >= ev.context );
|
||||||
|
auto ctx = m_gpuData[ev.context];
|
||||||
|
|
||||||
|
auto zone = ctx->queue.front();
|
||||||
|
if( zone->gpuStart == std::numeric_limits<int64_t>::max() )
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock( m_lock );
|
||||||
|
zone->gpuStart = ctx->timeDiff + ev.gpuTime;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lock( m_lock );
|
||||||
|
zone->gpuEnd = ctx->timeDiff + ev.gpuTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx->queue.erase( ctx->queue.begin() );
|
||||||
|
}
|
||||||
|
|
||||||
void View::CheckString( uint64_t ptr )
|
void View::CheckString( uint64_t ptr )
|
||||||
{
|
{
|
||||||
if( m_strings.find( ptr ) != m_strings.end() ) return;
|
if( m_strings.find( ptr ) != m_strings.end() ) return;
|
||||||
|
@ -70,6 +70,7 @@ private:
|
|||||||
void ProcessGpuNewContext( const QueueGpuNewContext& ev );
|
void ProcessGpuNewContext( const QueueGpuNewContext& ev );
|
||||||
void ProcessGpuZoneBegin( const QueueGpuZoneBegin& ev );
|
void ProcessGpuZoneBegin( const QueueGpuZoneBegin& ev );
|
||||||
void ProcessGpuZoneEnd( const QueueGpuZoneEnd& ev );
|
void ProcessGpuZoneEnd( const QueueGpuZoneEnd& ev );
|
||||||
|
void ProcessGpuTime( const QueueGpuTime& ev );
|
||||||
|
|
||||||
void CheckString( uint64_t ptr );
|
void CheckString( uint64_t ptr );
|
||||||
void CheckThreadString( uint64_t id );
|
void CheckThreadString( uint64_t id );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user