Implement bare-bones functionality for gpu contexts in the C api

This commit is contained in:
Ashley Ruglys 2021-11-17 11:27:52 +01:00
parent 1002e949d6
commit 91b4058dc4
No known key found for this signature in database
GPG Key ID: 1CDD7E27FB663837
2 changed files with 107 additions and 1 deletions

View File

@ -97,11 +97,42 @@ 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;
#ifdef TRACY_MANUAL_LIFETIME
TRACY_API void ___tracy_startup_profiler(void);
TRACY_API void ___tracy_shutdown_profiler(void);
@ -120,6 +151,12 @@ 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, int active );
TRACY_API void ___tracy_emit_gpu_zone_end( const struct ___tracy_gpu_zone_end_data data, int active );
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 );
#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 );

View File

@ -3965,6 +3965,75 @@ 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, int active )
{
if( !active ) return;
{
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, int active )
{
if( !active ) return;
{
TracyLfqPrepareC( tracy::QueueType::GpuZoneEnd );
tracy::MemWrite( &item->gpuZoneEnd.cpuTime, tracy::Profiler::GetTime() );
tracy::MemWrite( &item->gpuNewContext.thread, tracy::GetThreadHandle() );
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;
}
}
# ifdef TRACY_MANUAL_LIFETIME
TRACY_API void ___tracy_startup_profiler( void )
{