/// A class for calculating optimal spin values to trick OSes into not powering down GPUs while waiting for readbacks
classReadbackSpinManager
{
public:
structEvent
{
s64size;
u32begin;
u32end;
};
private:
doublem_spins_per_unit_time=0;
doublem_total_spin_time=0;
doublem_total_spin_cycles=0;
std::vector<Event>m_frames[3];
u32m_current_frame=0;
u32m_reference_frame=0;
u32m_reference_frame_idx=0;
public:
structDrawSubmittedReturn
{
u32id;
u32recommended_spin;
};
/// Call when a readback is requested
voidReadbackRequested();
/// Call at the end of a frame
voidNextFrame();
/// Call when a command buffer is submitted to the GPU
/// `size` is used to attempt to find patterns in submissions, and can be any metric that approximates the amount of work in a submission (draw calls, command encoders, etc)
/// Returns an id to be passed to `DrawCompleted`, and the recommended number of spin cycles to perform on the GPU in order to keep it busy
DrawSubmittedReturnDrawSubmitted(u64size);
/// Call once a draw has been finished by the GPU and you have begin/end data for it
/// `begin_time` and `end_time` can be in any unit as long as it's consistent. It's okay if they roll over, as long as it happens less than once every few frames.