mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-02 18:39:14 +01:00
Add SSBO and compute shader support to gl wrappers
This commit is contained in:
32
gl/query.h
32
gl/query.h
@@ -1,5 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <optional>
|
||||
|
||||
#include "object.h"
|
||||
|
||||
namespace gl
|
||||
@@ -33,4 +36,33 @@ public:
|
||||
|
||||
std::optional<int64_t> result();
|
||||
};
|
||||
|
||||
// gpu time of a section of commands, from a pair of GL_TIMESTAMP queries. unlike GL_TIME_ELAPSED, timestamps
|
||||
// can be taken while another time query runs (e.g. the whole-frame query of the renderer). results are read
|
||||
// a few frames later without stalling; if the gpu falls further behind, the measurement is skipped
|
||||
class gpu_timer
|
||||
{
|
||||
public:
|
||||
gpu_timer() = default;
|
||||
~gpu_timer();
|
||||
gpu_timer(const gpu_timer &) = delete;
|
||||
gpu_timer &operator=(const gpu_timer &) = delete;
|
||||
|
||||
void begin();
|
||||
void end();
|
||||
// duration of the most recent finished measurement, in nanoseconds
|
||||
std::optional<uint64_t> result();
|
||||
|
||||
private:
|
||||
void collect();
|
||||
|
||||
static constexpr size_t SLOTS = 4;
|
||||
// start and end timestamp per slot, created on first use
|
||||
std::array<GLuint, SLOTS * 2> m_queries{};
|
||||
std::array<bool, SLOTS> m_pending{};
|
||||
// slot written by the next begin(), also the oldest one still pending
|
||||
size_t m_slot = 0;
|
||||
bool m_active = false;
|
||||
std::optional<uint64_t> m_last;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user