CI / build (push) Successful in 32s
The pacer counted only its own frames, so the client's 30 came on top (60 gave about 80), and it added no frames at all when the rate was out of reach. It now asks for a window's next frame once the interval since its last frame began has passed, and the client has had a third of a frame's time idle: all frames within the rate, and as many as the client can draw when it can't reach it. The engine's stats also break a frame's time down: sending to the renderer process, bytes sent, buffer updates. Co-Authored-By: Claude Opus 5.5 <[email protected]>
80 lines
3.1 KiB
C++
80 lines
3.1 KiB
C++
#pragma once
|
|
// Records what the client draws as commands (include/t5de/protocol/commands.hpp) and sends them to the renderer
|
|
// process. Shared by an engine and the resources it creates (which can outlive it); once the renderer process is
|
|
// gone, it records nothing.
|
|
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <span>
|
|
#include <utility>
|
|
|
|
#include "renderer_process.hpp"
|
|
#include "t5de/imvu/types.hpp"
|
|
#include "t5de/protocol/commands.hpp"
|
|
|
|
namespace t5de {
|
|
|
|
class Recorder {
|
|
public:
|
|
explicit Recorder(std::unique_ptr<RendererProcess> process);
|
|
|
|
[[nodiscard]] bool active() const { return process_ && process_->alive(); }
|
|
|
|
// Whether the renderer process draws the whole 3D view, so the client's renderer needn't.
|
|
[[nodiscard]] bool covering() const { return process_ && process_->covering(); }
|
|
|
|
// Records a command (if active); returns its payload to fill, or null.
|
|
template <class Body>
|
|
std::byte* add(protocol::Op op, const Body& body, std::size_t payloadSize = 0)
|
|
{
|
|
if (!active()) {
|
|
return nullptr;
|
|
}
|
|
std::byte* payload = writer_.add(op, body, payloadSize);
|
|
return payload;
|
|
}
|
|
|
|
// Sends what's recorded: at the end of each frame, and between frames when a lot is waiting (resources).
|
|
void flush(bool endsFrame);
|
|
void flushIfLarge();
|
|
|
|
std::uint32_t createTexture(const imvu::Pixmap& pixmap, std::uint32_t flags);
|
|
// Destroyed with destroyTexture.
|
|
std::uint32_t createRenderTarget(std::uint32_t width, std::uint32_t height);
|
|
// After flushing a frame that reads its render target back: its pixels (RendererProcess::readBack).
|
|
std::span<const std::byte> readBack();
|
|
void updateTexture(std::uint32_t id, const imvu::Pixmap& pixmap);
|
|
void destroyTexture(std::uint32_t id);
|
|
|
|
// Copies count elements of elementSize bytes, stride bytes apart (0: packed), from data (null: none yet).
|
|
std::uint32_t createBuffer(protocol::BufferKind kind, const void* data, std::uint32_t stride,
|
|
std::uint32_t elementSize, std::uint32_t count);
|
|
void updateBuffer(std::uint32_t id, const void* data, std::uint32_t stride, std::uint32_t elementSize,
|
|
std::uint32_t count);
|
|
void destroyBuffer(std::uint32_t id);
|
|
|
|
// Diagnostics: what's been sent, and the time spent sending (waiting for the renderer process to take it).
|
|
struct Counters {
|
|
std::uint64_t bytes = 0;
|
|
double sendSeconds = 0;
|
|
std::uint32_t bufferUpdates = 0;
|
|
std::uint64_t bufferBytes = 0;
|
|
};
|
|
// Returns the counters since the last call.
|
|
Counters takeCounters() { return std::exchange(counters_, {}); }
|
|
|
|
private:
|
|
void addPixels(protocol::Op op, std::uint32_t id, const imvu::Pixmap& pixmap, std::uint32_t flags);
|
|
|
|
std::unique_ptr<RendererProcess> process_;
|
|
protocol::Writer writer_;
|
|
std::uint32_t nextId_ = 1;
|
|
Counters counters_;
|
|
};
|
|
|
|
// Copies count elements of elementSize bytes, stride bytes apart (0: packed), into destination, packed.
|
|
void pack(std::byte* destination, const void* source, std::uint32_t stride, std::uint32_t elementSize,
|
|
std::uint32_t count);
|
|
|
|
} // namespace t5de
|