Files
Renderive/Core/execution/Render_Executor.h
T
2026-08-02 19:26:50 +08:00

63 lines
2.1 KiB
C++

#pragma once
#include "../architecture/Render_Config.h"
#include "../architecture/global.h"
#include "../base/Task.h"
#include <cstdint>
#include <functional>
#include <memory>
namespace renderive {
struct Render_Task_Graph_Node {
std::uint32_t index = UINT32_MAX;
explicit operator bool() const noexcept {
return index != UINT32_MAX;
}
};
class LIB_DECL Render_Task_Subflow {
public:
explicit Render_Task_Subflow(void* impl) noexcept;
[[nodiscard]] Render_Task_Graph_Node emplace(Render_Task_Kind kind, Task work);
void precede(Render_Task_Graph_Node before, Render_Task_Graph_Node after);
void join();
private:
void* impl{};
bool joined{};
};
class LIB_DECL Render_Task_Graph {
public:
using Subflow_Builder = std::function<void(Render_Task_Subflow&)>;
explicit Render_Task_Graph(void* impl) noexcept;
[[nodiscard]] Render_Task_Graph_Node emplace(Render_Task_Kind kind, Task work);
[[nodiscard]] Render_Task_Graph_Node emplace_subflow(Render_Task_Kind kind, Subflow_Builder builder);
void precede(Render_Task_Graph_Node before, Render_Task_Graph_Node after);
private:
void* impl{};
};
struct Render_Executor_Task {
using Graph_Builder = std::function<void(Render_Task_Graph&, Render_Task_Graph_Node, Render_Task_Graph_Node)>;
Plot_Execution_Id plot_id{};
std::uint64_t frame_id{};
Render_Task_Kind kind = Render_Task_Kind::Primitive;
Task work;
Graph_Builder build_graph;
Task completion;
std::shared_ptr<Frame_Worker_Stats> frame_stat;
bool frame_job{};
};
class Render_Executor_Private;
class LIB_DECL Render_Executor {
public:
explicit Render_Executor(Render_Runtime_Config config = {});
Render_Executor(const Render_Executor&) = delete;
Render_Executor& operator=(const Render_Executor&) = delete;
~Render_Executor();
bool try_submit(Render_Executor_Task task);
void shutdown();
[[nodiscard]] Render_Executor_Snapshot snapshot() const;
[[nodiscard]] std::size_t worker_count() const;
private:
std::unique_ptr<Render_Executor_Private> d;
};
std::size_t resolve_render_worker_count(std::size_t configured_count);
} // namespace renderive