// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.
#pragma once
#if COMPILE_WITH_PROFILER
#include "Engine/Core/Types/BaseTypes.h"
///
/// Object that stores various render statistics.
///
API_STRUCT() struct RenderStatsData
{
DECLARE_SCRIPTING_TYPE_MINIMAL(RenderStatsData);
///
/// The draw calls count.
///
API_FIELD() int64 DrawCalls;
///
/// The compute shader dispatch calls count.
///
API_FIELD() int64 DispatchCalls;
///
/// The vertices drawn count.
///
API_FIELD() int64 Vertices;
///
/// The triangles drawn count.
///
API_FIELD() int64 Triangles;
///
/// The pipeline state changes count.
///
API_FIELD() int64 PipelineStateChanges;
///
/// Initializes a new instance of the struct.
///
RenderStatsData()
: DrawCalls(0)
, DispatchCalls(0)
, Vertices(0)
, Triangles(0)
, PipelineStateChanges(0)
{
}
///
/// The global rendering stats counter.
///
static RenderStatsData Counter;
///
/// Mixes the stats with the current state. Perform operation: this = currentState - this, but without additional stack allocations.
///
/// The current state.
void Mix(const RenderStatsData& currentState)
{
#define MIX(name) name = currentState.name - name
MIX(DrawCalls);
MIX(DispatchCalls);
MIX(Vertices);
MIX(Triangles);
MIX(PipelineStateChanges);
#undef MIX
}
};
#define RENDER_STAT_DISPATCH_CALL() Platform::InterlockedIncrement(&RenderStatsData::Counter.DispatchCalls)
#define RENDER_STAT_PS_STATE_CHANGE() Platform::InterlockedIncrement(&RenderStatsData::Counter.PipelineStateChanges)
#define RENDER_STAT_DRAW_CALL(vertices, triangles) \
Platform::InterlockedIncrement(&RenderStatsData::Counter.DrawCalls); \
Platform::InterlockedAdd(&RenderStatsData::Counter.Vertices, vertices); \
Platform::InterlockedAdd(&RenderStatsData::Counter.Triangles, triangles)
#else
#define RENDER_STAT_DISPATCH_CALL()
#define RENDER_STAT_PS_STATE_CHANGE()
#define RENDER_STAT_DRAW_CALL(vertices, primitives)
#endif