mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-10 10:41:50 +00:00
Merge pull request #283 from expenses/c-gpu-zones
Implement a bare-bones C API for graphics profiling
This commit is contained in:
commit
2bd1e5bca7
44
TracyC.h
44
TracyC.h
@ -97,6 +97,38 @@ struct ___tracy_c_zone_context
|
||||
int active;
|
||||
};
|
||||
|
||||
struct ___tracy_gpu_time_data
|
||||
{
|
||||
int64_t gpuTime;
|
||||
uint16_t queryId;
|
||||
uint8_t context;
|
||||
};
|
||||
|
||||
struct ___tracy_gpu_zone_begin_data {
|
||||
uint64_t srcloc;
|
||||
uint16_t queryId;
|
||||
uint8_t context;
|
||||
};
|
||||
|
||||
struct ___tracy_gpu_zone_end_data {
|
||||
uint16_t queryId;
|
||||
uint8_t context;
|
||||
};
|
||||
|
||||
struct ___tracy_gpu_new_context_data {
|
||||
int64_t gpuTime;
|
||||
float period;
|
||||
uint8_t context;
|
||||
uint8_t flags;
|
||||
uint8_t type;
|
||||
};
|
||||
|
||||
struct ___tracy_gpu_context_name_data {
|
||||
uint8_t context;
|
||||
const char* name;
|
||||
uint16_t len;
|
||||
};
|
||||
|
||||
// Some containers don't support storing const types.
|
||||
// This struct, as visible to user, is immutable, so treat it as if const was declared here.
|
||||
typedef /*const*/ struct ___tracy_c_zone_context TracyCZoneCtx;
|
||||
@ -120,6 +152,18 @@ TRACY_API void ___tracy_emit_zone_name( TracyCZoneCtx ctx, const char* txt, size
|
||||
TRACY_API void ___tracy_emit_zone_color( TracyCZoneCtx ctx, uint32_t color );
|
||||
TRACY_API void ___tracy_emit_zone_value( TracyCZoneCtx ctx, uint64_t value );
|
||||
|
||||
TRACY_API void ___tracy_emit_gpu_zone_begin_alloc( const struct ___tracy_gpu_zone_begin_data );
|
||||
TRACY_API void ___tracy_emit_gpu_zone_end( const struct ___tracy_gpu_zone_end_data data );
|
||||
TRACY_API void ___tracy_emit_gpu_time( const struct ___tracy_gpu_time_data );
|
||||
TRACY_API void ___tracy_emit_gpu_new_context( const struct ___tracy_gpu_new_context_data );
|
||||
TRACY_API void ___tracy_emit_gpu_context_name( const struct ___tracy_gpu_context_name_data );
|
||||
|
||||
TRACY_API void ___tracy_emit_gpu_zone_begin_alloc_serial( const struct ___tracy_gpu_zone_begin_data );
|
||||
TRACY_API void ___tracy_emit_gpu_zone_end_serial( const struct ___tracy_gpu_zone_end_data data );
|
||||
TRACY_API void ___tracy_emit_gpu_time_serial( const struct ___tracy_gpu_time_data );
|
||||
TRACY_API void ___tracy_emit_gpu_new_context_serial( const struct ___tracy_gpu_new_context_data );
|
||||
TRACY_API void ___tracy_emit_gpu_context_name_serial( const struct ___tracy_gpu_context_name_data );
|
||||
|
||||
#if defined TRACY_HAS_CALLSTACK && defined TRACY_CALLSTACK
|
||||
# define TracyCZone( ctx, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { NULL, __func__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active );
|
||||
# define TracyCZoneN( ctx, name, active ) static const struct ___tracy_source_location_data TracyConcat(__tracy_source_location,__LINE__) = { name, __func__, __FILE__, (uint32_t)__LINE__, 0 }; TracyCZoneCtx ctx = ___tracy_emit_zone_begin_callstack( &TracyConcat(__tracy_source_location,__LINE__), TRACY_CALLSTACK, active );
|
||||
|
@ -3969,6 +3969,121 @@ TRACY_API uint64_t ___tracy_alloc_srcloc_name( uint32_t line, const char* source
|
||||
return tracy::Profiler::AllocSourceLocation( line, source, sourceSz, function, functionSz, name, nameSz );
|
||||
}
|
||||
|
||||
TRACY_API void ___tracy_emit_gpu_zone_begin_alloc( const struct ___tracy_gpu_zone_begin_data data )
|
||||
{
|
||||
TracyLfqPrepareC( tracy::QueueType::GpuZoneBeginAllocSrcLoc );
|
||||
tracy::MemWrite( &item->gpuZoneBegin.cpuTime, tracy::Profiler::GetTime() );
|
||||
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
|
||||
tracy::MemWrite( &item->gpuZoneBegin.srcloc, data.srcloc );
|
||||
tracy::MemWrite( &item->gpuZoneBegin.queryId, data.queryId );
|
||||
tracy::MemWrite( &item->gpuZoneBegin.context, data.context );
|
||||
TracyLfqCommitC;
|
||||
}
|
||||
|
||||
TRACY_API void ___tracy_emit_gpu_time( const struct ___tracy_gpu_time_data data )
|
||||
{
|
||||
TracyLfqPrepareC( tracy::QueueType::GpuTime );
|
||||
tracy::MemWrite( &item->gpuTime.gpuTime, data.gpuTime );
|
||||
tracy::MemWrite( &item->gpuTime.queryId, data.queryId );
|
||||
tracy::MemWrite( &item->gpuTime.context, data.context );
|
||||
TracyLfqCommitC;
|
||||
}
|
||||
|
||||
TRACY_API void ___tracy_emit_gpu_zone_end( const struct ___tracy_gpu_zone_end_data data )
|
||||
{
|
||||
TracyLfqPrepareC( tracy::QueueType::GpuZoneEnd );
|
||||
tracy::MemWrite( &item->gpuZoneEnd.cpuTime, tracy::Profiler::GetTime() );
|
||||
memset( &item->gpuZoneEnd.thread, 0, sizeof( item->gpuZoneEnd.thread ) );
|
||||
tracy::MemWrite( &item->gpuZoneEnd.queryId, data.queryId );
|
||||
tracy::MemWrite( &item->gpuZoneEnd.context, data.context );
|
||||
TracyLfqCommitC;
|
||||
}
|
||||
|
||||
TRACY_API void ___tracy_emit_gpu_new_context( ___tracy_gpu_new_context_data data )
|
||||
{
|
||||
TracyLfqPrepareC( tracy::QueueType::GpuNewContext );
|
||||
tracy::MemWrite( &item->gpuNewContext.cpuTime, tracy::Profiler::GetTime() );
|
||||
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
|
||||
tracy::MemWrite( &item->gpuNewContext.gpuTime, data.gpuTime );
|
||||
tracy::MemWrite( &item->gpuNewContext.period, data.period );
|
||||
tracy::MemWrite( &item->gpuNewContext.context, data.context );
|
||||
tracy::MemWrite( &item->gpuNewContext.flags, data.flags );
|
||||
tracy::MemWrite( &item->gpuNewContext.type, data.type );
|
||||
TracyLfqCommitC;
|
||||
}
|
||||
|
||||
TRACY_API void ___tracy_emit_gpu_context_name( const struct ___tracy_gpu_context_name_data data )
|
||||
{
|
||||
auto ptr = (char*)tracy::tracy_malloc( data.len );
|
||||
memcpy( ptr, data.name, data.len );
|
||||
|
||||
TracyLfqPrepareC( tracy::QueueType::GpuContextName );
|
||||
tracy::MemWrite( &item->gpuContextNameFat.context, data.context );
|
||||
tracy::MemWrite( &item->gpuContextNameFat.ptr, (uint64_t)ptr );
|
||||
tracy::MemWrite( &item->gpuContextNameFat.size, data.len );
|
||||
TracyLfqCommitC;
|
||||
}
|
||||
|
||||
TRACY_API void ___tracy_emit_gpu_zone_begin_alloc_serial( const struct ___tracy_gpu_zone_begin_data data )
|
||||
{
|
||||
auto item = tracy::Profiler::QueueSerial();
|
||||
tracy::MemWrite( &item->hdr.type, tracy::QueueType::GpuZoneBeginAllocSrcLocSerial );
|
||||
tracy::MemWrite( &item->gpuZoneBegin.cpuTime, tracy::Profiler::GetTime() );
|
||||
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
|
||||
tracy::MemWrite( &item->gpuZoneBegin.srcloc, data.srcloc );
|
||||
tracy::MemWrite( &item->gpuZoneBegin.queryId, data.queryId );
|
||||
tracy::MemWrite( &item->gpuZoneBegin.context, data.context );
|
||||
tracy::Profiler::QueueSerialFinish();
|
||||
}
|
||||
|
||||
TRACY_API void ___tracy_emit_gpu_time_serial( const struct ___tracy_gpu_time_data data )
|
||||
{
|
||||
auto item = tracy::Profiler::QueueSerial();
|
||||
tracy::MemWrite( &item->hdr.type, tracy::QueueType::GpuTime );
|
||||
tracy::MemWrite( &item->gpuTime.gpuTime, data.gpuTime );
|
||||
tracy::MemWrite( &item->gpuTime.queryId, data.queryId );
|
||||
tracy::MemWrite( &item->gpuTime.context, data.context );
|
||||
tracy::Profiler::QueueSerialFinish();
|
||||
}
|
||||
|
||||
TRACY_API void ___tracy_emit_gpu_zone_end_serial( const struct ___tracy_gpu_zone_end_data data )
|
||||
{
|
||||
auto item = tracy::Profiler::QueueSerial();
|
||||
tracy::MemWrite( &item->hdr.type, tracy::QueueType::GpuZoneEndSerial );
|
||||
tracy::MemWrite( &item->gpuZoneEnd.cpuTime, tracy::Profiler::GetTime() );
|
||||
memset( &item->gpuZoneEnd.thread, 0, sizeof( item->gpuZoneEnd.thread ) );
|
||||
tracy::MemWrite( &item->gpuZoneEnd.queryId, data.queryId );
|
||||
tracy::MemWrite( &item->gpuZoneEnd.context, data.context );
|
||||
tracy::Profiler::QueueSerialFinish();
|
||||
}
|
||||
|
||||
TRACY_API void ___tracy_emit_gpu_new_context_serial( ___tracy_gpu_new_context_data data )
|
||||
{
|
||||
auto item = tracy::Profiler::QueueSerial();
|
||||
tracy::MemWrite( &item->hdr.type, tracy::QueueType::GpuNewContext );
|
||||
tracy::MemWrite( &item->gpuNewContext.cpuTime, tracy::Profiler::GetTime() );
|
||||
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
|
||||
tracy::MemWrite( &item->gpuNewContext.gpuTime, data.gpuTime );
|
||||
tracy::MemWrite( &item->gpuNewContext.period, data.period );
|
||||
tracy::MemWrite( &item->gpuNewContext.context, data.context );
|
||||
tracy::MemWrite( &item->gpuNewContext.flags, data.flags );
|
||||
tracy::MemWrite( &item->gpuNewContext.type, data.type );
|
||||
tracy::Profiler::QueueSerialFinish();
|
||||
}
|
||||
|
||||
TRACY_API void ___tracy_emit_gpu_context_name_serial( const struct ___tracy_gpu_context_name_data data )
|
||||
{
|
||||
auto ptr = (char*)tracy::tracy_malloc( data.len );
|
||||
memcpy( ptr, data.name, data.len );
|
||||
|
||||
auto item = tracy::Profiler::QueueSerial();
|
||||
tracy::MemWrite( &item->hdr.type, tracy::QueueType::GpuContextName );
|
||||
tracy::MemWrite( &item->gpuContextNameFat.context, data.context );
|
||||
tracy::MemWrite( &item->gpuContextNameFat.ptr, (uint64_t)ptr );
|
||||
tracy::MemWrite( &item->gpuContextNameFat.size, data.len );
|
||||
tracy::Profiler::QueueSerialFinish();
|
||||
}
|
||||
|
||||
# ifdef TRACY_MANUAL_LIFETIME
|
||||
TRACY_API void ___tracy_startup_profiler( void )
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user