demotool/ui-profiling.hh

77 lines
1.6 KiB
C++

#pragma once
#ifndef REAL_BUILD
# include "externals.hh"
#endif
struct T_ProfilerSamples
{
float sum;
uint32_t nSamples;
};
struct T_Profiler
{
static constexpr uint32_t Samples = 4;
static constexpr uint32_t History = 4;
static constexpr uint32_t Invalid = 0xffffffff;
~T_Profiler( );
void clear( );
void startFrame( );
void start( T_String const& section );
void end( T_String const& section );
void endFrame( );
uint32_t sections( ) const noexcept
{ return sections_.size( ); }
T_String const& nameOf(
const uint32_t section ) const
{ return sections_[ section ]; }
float durationOf( const uint32_t section ) const
{ return secDurations_[ section ]; }
float startOf( const uint32_t section ) const
{ return secStarts_[ section ]; }
void makeUI( );
bool& uiEnabled( ) { return uiEnabled_; }
private:
using T_SamplesList_ = T_StaticArray< T_ProfilerSamples , History >;
using T_Data_ = T_Array< T_SamplesList_ >;
void extendGPUQueries( ) noexcept;
static void addSample(
T_SamplesList_& list ,
uint64_t duration ) noexcept;
uint32_t find( T_String const& section ) const;
static float computeDuration(
T_SamplesList_ const& list ) noexcept;
uint32_t previous_;
uint32_t current_;
T_Array< T_String > sections_;
T_Array< uint32_t > chain_;
T_Array< uint32_t > parents_;
T_Data_ samples_;
T_Array< uint64_t > cpuStarts_;
T_Array< float > secCPUDurations_;
T_Array< float > secGPUDurations_;
T_Array< float > secDurations_;
T_Array< float > secStarts_;
bool uiEnabled_ = false;
T_Array< bool > displayed_;
T_Array< GLuint > gpuQueries_{ T_Array< GLuint >( 64 ) };
T_Data_ gpuSamples_;
};