Skip to content

Commit

Permalink
gpu timers can now be insert via callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasmr committed Jul 13, 2019
1 parent 4440d1a commit 03c34f9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 6 deletions.
48 changes: 42 additions & 6 deletions microprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,35 @@



#if MICROPROFILE_GPU_TIMERS && MICROPROFILE_GPU_TIMER_CALLBACKS
static MicroProfileGpuInsertTimeStamp_CB MicroProfileGpuInsertTimeStamp = 0;
static MicroProfileGpuGetTimeStamp_CB MicroProfileGpuGetTimeStamp = 0;
static MicroProfileTicksPerSecondGpu_CB MicroProfileTicksPerSecondGpu = 0;
static MicroProfileGetGpuTickReference_CB MicroProfileGetGpuTickReference = 0;
static MicroProfileGpuFlip_CB MicroProfileGpuFlip = 0;
static MicroProfileGpuShutdown_CB MicroProfileGpuShutdown = 0;

void MicroProfileGpuSetCallbacks(
MicroProfileGpuInsertTimeStamp_CB InsertTimeStamp,
MicroProfileGpuGetTimeStamp_CB GetTimeStamp,
MicroProfileTicksPerSecondGpu_CB TicksPerSecond,
MicroProfileGetGpuTickReference_CB GetTickReference,
MicroProfileGpuFlip_CB Flip,
MicroProfileGpuShutdown_CB Shutdown)
{
MicroProfileGpuInsertTimeStamp = InsertTimeStamp;
MicroProfileGpuGetTimeStamp = GetTimeStamp;
MicroProfileTicksPerSecondGpu = TicksPerSecond;
MicroProfileGetGpuTickReference = GetTickReference;
MicroProfileGpuFlip = Flip;
MicroProfileGpuShutdown = Shutdown;
}
#endif

#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#endif

#include <thread>
#include <mutex>
#include <atomic>
Expand Down Expand Up @@ -1102,11 +1131,6 @@ uint64_t MicroProfileTick()
#include <windows.h>
#define fopen microprofile_fopen_helper

#pragma warning(push)
#pragma warning(disable: 4244) //possible loss of data
#pragma warning(disable: 4100) //unreferenced formal parameter
#pragma warning(disable: 4091)

FILE* microprofile_fopen_helper(const char* filename, const char* mode)
{
FILE* F = 0;
Expand Down Expand Up @@ -1224,7 +1248,19 @@ void MicroProfileDumpToFile();


#if MICROPROFILE_DEBUG
#ifdef _WIN32
void uprintf(const char* fmt, ...)
{
va_list args;
va_start(args, fmt);
char buffer[1024];
vsnprintf(buffer, sizeof(buffer) - 1, fmt, args);
OutputDebugStringA(buffer);
va_end(args);
}
#else
#define uprintf(...) printf(__VA_ARGS__)
#endif
#else
#define uprintf(...) do{}while(0)
#endif
Expand Down Expand Up @@ -2492,7 +2528,7 @@ void MicroProfileEnterGpu(MicroProfileToken nToken, MicroProfileThreadLogGpu* pL
uint32_t nStackPos = pLog->nStackScope++;
if(nStackPos < MICROPROFILE_STACK_MAX)
{
MicroProfileScopeStateC* pScopeState = &pLog->ScopeState[pLog->nStackScope];
MicroProfileScopeStateC* pScopeState = &pLog->ScopeState[nStackPos];
pScopeState->Token = nToken;
pScopeState->nTick = MicroProfileGpuEnterInternal(pLog, nToken);
}
Expand Down
21 changes: 21 additions & 0 deletions microprofile.h
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,10 @@ typedef void (*MicroProfileOnFreeze)(int nFrozen);
#define MICROPROFILE_GPU_TIMERS 1
#endif

#ifndef MICROPROFILE_GPU_TIMER_CALLBACKS
#define MICROPROFILE_GPU_TIMER_CALLBACKS 0
#endif

#ifndef MICROPROFILE_GPU_FRAME_DELAY
#define MICROPROFILE_GPU_FRAME_DELAY 5 //must be > 0
#endif
Expand Down Expand Up @@ -636,12 +640,29 @@ MICROPROFILE_API void MicroProfileDumpFileImmediately(const char* pHtml, const c
MICROPROFILE_API uint32_t MicroProfileWebServerPort();

#if MICROPROFILE_GPU_TIMERS
#if MICROPROFILE_GPU_TIMER_CALLBACKS
typedef uint32_t (*MicroProfileGpuInsertTimeStamp_CB)(void* pContext);
typedef uint64_t (*MicroProfileGpuGetTimeStamp_CB)(uint32_t nKey);
typedef uint64_t (*MicroProfileTicksPerSecondGpu_CB)();
typedef int (*MicroProfileGetGpuTickReference_CB)(int64_t* pOutCPU, int64_t* pOutGpu);
typedef uint32_t (*MicroProfileGpuFlip_CB)(void*);
typedef void (*MicroProfileGpuShutdown_CB)();
MICROPROFILE_API void MicroProfileGpuSetCallbacks(
MicroProfileGpuInsertTimeStamp_CB InsertTimeStamp,
MicroProfileGpuGetTimeStamp_CB GetTimeStamp,
MicroProfileTicksPerSecondGpu_CB TicksPerSecond,
MicroProfileGetGpuTickReference_CB GetTickReference,
MicroProfileGpuFlip_CB Flip,
MicroProfileGpuShutdown_CB Shutdown);
#else
MICROPROFILE_API uint32_t MicroProfileGpuInsertTimeStamp(void* pContext);
MICROPROFILE_API uint64_t MicroProfileGpuGetTimeStamp(uint32_t nKey);
MICROPROFILE_API uint64_t MicroProfileTicksPerSecondGpu();
MICROPROFILE_API int MicroProfileGetGpuTickReference(int64_t* pOutCPU, int64_t* pOutGpu);
MICROPROFILE_API uint32_t MicroProfileGpuFlip(void*);
MICROPROFILE_API void MicroProfileGpuShutdown();
#endif

#else
#define MicroProfileGpuInsertTimeStamp(a) 1
#define MicroProfileGpuGetTimeStamp(a) 0
Expand Down

0 comments on commit 03c34f9

Please sign in to comment.