Skip to content

Commit

Permalink
merian-nodes: Graph: Rename ring_size -> iterations_in_flight
Browse files Browse the repository at this point in the history
  • Loading branch information
LDAP committed Aug 28, 2024
1 parent 60c1178 commit f285b66
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 21 deletions.
24 changes: 12 additions & 12 deletions include/merian-nodes/graph/graph.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,8 @@ using namespace std::literals::chrono_literals;
*
* @tparam RING_SIZE Controls the amount of in-flight processing (frames-in-flight).
*/
template <uint32_t RING_SIZE = 2>
class Graph : public std::enable_shared_from_this<Graph<RING_SIZE>> {
template <uint32_t ITERATIONS_IN_FLIGHT = 2>
class Graph : public std::enable_shared_from_this<Graph<ITERATIONS_IN_FLIGHT>> {
// Data that is stored for every iteration in flight.
// Created for each iteration in flight in Graph::Graph.
struct InFlightData {
Expand All @@ -193,7 +193,7 @@ class Graph : public std::enable_shared_from_this<Graph<RING_SIZE>> {
// to device local memory has finished.
merian::StagingMemoryManager::SetID staging_set_id{};
// The graph run, holds semaphores and such.
GraphRun graph_run{RING_SIZE};
GraphRun graph_run{ITERATIONS_IN_FLIGHT};
// Query pools for the profiler
QueryPoolHandle<vk::QueryType::eTimestamp> profiler_query_pool;
// Tasks that should be run in the current iteration after acquiring the fence.
Expand All @@ -208,7 +208,7 @@ class Graph : public std::enable_shared_from_this<Graph<RING_SIZE>> {
Graph(const ContextHandle& context, const ResourceAllocatorHandle& resource_allocator)
: context(context), resource_allocator(resource_allocator), queue(context->get_queue_GCT()),
registry(context, resource_allocator), ring_fences(context) {
for (uint32_t i = 0; i < RING_SIZE; i++) {
for (uint32_t i = 0; i < ITERATIONS_IN_FLIGHT; i++) {
InFlightData& in_flight_data = ring_fences.get(i).user_data;
in_flight_data.command_pool = std::make_shared<CommandPool>(queue);
in_flight_data.profiler_query_pool =
Expand Down Expand Up @@ -331,7 +331,7 @@ class Graph : public std::enable_shared_from_this<Graph<RING_SIZE>> {
const std::string node_identifier = data.identifier;
node_data.erase(node);
node_for_identifier.erase(identifier);
for (uint32_t i = 0; i < RING_SIZE; i++) {
for (uint32_t i = 0; i < ITERATIONS_IN_FLIGHT; i++) {
InFlightData& in_flight_data = ring_fences.get(i).user_data;
in_flight_data.in_flight_data.erase(node);
}
Expand Down Expand Up @@ -440,7 +440,7 @@ class Graph : public std::enable_shared_from_this<Graph<RING_SIZE>> {
node->on_connected(io_layout, data.descriptor_set_layout);
needs_reconnect |= flags & Node::NodeStatusFlagBits::NEEDS_RECONNECT;
if ((flags & Node::NodeStatusFlagBits::RESET_IN_FLIGHT_DATA) != 0u) {
for (uint32_t i = 0; i < RING_SIZE; i++) {
for (uint32_t i = 0; i < ITERATIONS_IN_FLIGHT; i++) {
ring_fences.get(i).user_data.in_flight_data.at(node).reset();
}
}
Expand Down Expand Up @@ -520,7 +520,7 @@ class Graph : public std::enable_shared_from_this<Graph<RING_SIZE>> {
}
time_delta = duration_elapsed - last_elapsed_ns;

run.reset(run_iteration, run_iteration % RING_SIZE, profiler, cmd_pool,
run.reset(run_iteration, run_iteration % ITERATIONS_IN_FLIGHT, profiler, cmd_pool,
resource_allocator, time_delta, duration_elapsed,
duration_elapsed_since_connect, total_iteration);

Expand Down Expand Up @@ -609,7 +609,7 @@ class Graph : public std::enable_shared_from_this<Graph<RING_SIZE>> {

node_data.clear();
node_for_identifier.clear();
for (uint32_t i = 0; i < RING_SIZE; i++) {
for (uint32_t i = 0; i < ITERATIONS_IN_FLIGHT; i++) {
InFlightData& in_flight_data = ring_fences.get(i).user_data;
in_flight_data.in_flight_data.clear();
}
Expand Down Expand Up @@ -1742,7 +1742,7 @@ class Graph : public std::enable_shared_from_this<Graph<RING_SIZE>> {
for (uint32_t i = 0; i <= max_delay; i++) {
const GraphResourceHandle res =
output->create_resource(per_output_info.inputs, resource_allocator,
resource_allocator, i, RING_SIZE);
resource_allocator, i, ITERATIONS_IN_FLIGHT);
per_output_info.resources.emplace_back(res);
}
}
Expand Down Expand Up @@ -1803,10 +1803,10 @@ class Graph : public std::enable_shared_from_this<Graph<RING_SIZE>> {
num_resources.push_back(per_output_info.resources.size());
}

uint32_t num_sets = std::max(lcm(num_resources), RING_SIZE);
uint32_t num_sets = std::max(lcm(num_resources), ITERATIONS_IN_FLIGHT);
// make sure it is at least RING_SIZE to allow updates while iterations are in-flight
// solve k * num_sets >= RING_SIZE
const uint32_t k = (RING_SIZE + num_sets - 1) / num_sets;
const uint32_t k = (ITERATIONS_IN_FLIGHT + num_sets - 1) / num_sets;
num_sets *= k;

SPDLOG_DEBUG("needing {} descriptor sets for node {} ({})", num_sets,
Expand Down Expand Up @@ -1928,7 +1928,7 @@ class Graph : public std::enable_shared_from_this<Graph<RING_SIZE>> {
// clang-format on

// Per-iteration data management
merian::RingFences<RING_SIZE, InFlightData> ring_fences;
merian::RingFences<ITERATIONS_IN_FLIGHT, InFlightData> ring_fences;

// State
bool needs_reconnect = false;
Expand Down
18 changes: 9 additions & 9 deletions include/merian-nodes/graph/graph_run.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class GraphRun {
template <uint32_t> friend class Graph;

public:
GraphRun(const uint32_t ring_size) : ring_size(ring_size) {}
GraphRun(const uint32_t iterations_in_flight) : iterations_in_flight(iterations_in_flight) {}

void add_wait_semaphore(const BinarySemaphoreHandle& wait_semaphore,
const vk::PipelineStageFlags& wait_stage_flags) noexcept {
Expand Down Expand Up @@ -57,29 +57,29 @@ class GraphRun {

// Number of iterations since connect.
// Use get_total_iteration() for iterations since graph initialization.
//
//
// Iterations are 0-indexed.
const uint64_t& get_iteration() const noexcept {
return iteration;
}

// Number of iterations since graph initialization.
// Use get_iteration() for iterations since connect.
//
//
// Iterations are 0-indexed.
const uint64_t& get_total_iteration() const noexcept {
return total_iteration;
}

// returns the current in-flight index i, with 0 <= i < get_ring_size().
// returns the current in-flight index i, with 0 <= i < get_iterations_in_flight().
// It is guaranteed that processing of the last iteration with that index has finished.
const uint32_t& get_in_flight_index() const noexcept {
return in_flight_index;
}

// returns the number of iterations that might be in flight at a certain time.
const uint32_t& get_ring_size() const noexcept {
return ring_size;
const uint32_t& get_iterations_in_flight() const noexcept {
return iterations_in_flight;
}

const CommandPoolHandle& get_cmd_pool() noexcept {
Expand Down Expand Up @@ -122,7 +122,7 @@ class GraphRun {
}

// Returns the profiler that is attached to this run.
//
//
// Can be nullptr if profiling is disabled!
const ProfilerHandle& get_profiler() const {
return profiler;
Expand Down Expand Up @@ -173,7 +173,7 @@ class GraphRun {
private:
void reset(const uint64_t iteration,
const uint32_t in_flight_index,
const ProfilerHandle profiler,
const ProfilerHandle& profiler,
const CommandPoolHandle& cmd_pool,
const ResourceAllocatorHandle& allocator,
const std::chrono::nanoseconds time_delta,
Expand Down Expand Up @@ -201,7 +201,7 @@ class GraphRun {
}

private:
const uint32_t ring_size;
const uint32_t iterations_in_flight;

std::vector<vk::Semaphore> wait_semaphores;
std::vector<uint64_t> wait_values;
Expand Down

0 comments on commit f285b66

Please sign in to comment.