From 41c1ba7de9534ed941dbde8c452b41f208cb080e Mon Sep 17 00:00:00 2001 From: Lucas Alber Date: Tue, 19 Nov 2024 14:15:59 +0100 Subject: [PATCH] merian-nodes: ImageWrite: Add system time reference and rename format args --- .../merian-nodes/nodes/accumulate/README.md | 4 ++++ .../merian-nodes/nodes/image_write/README.md | 6 +++++ .../nodes/image_write/image_write.hpp | 22 ++++++++++++++----- .../nodes/image_write/image_write.cpp | 21 +++++++++++++----- 4 files changed, 41 insertions(+), 12 deletions(-) diff --git a/include/merian-nodes/nodes/accumulate/README.md b/include/merian-nodes/nodes/accumulate/README.md index 2208729b..1171e6a2 100644 --- a/include/merian-nodes/nodes/accumulate/README.md +++ b/include/merian-nodes/nodes/accumulate/README.md @@ -35,3 +35,7 @@ Outputs: |------------|---------------|-------------------------------------------------------------|-----------------------------|------------| | VkImageOut | out_irr | exp average of irradiance in `rgb`, history length in `a` | user defined or like irr | no | | VkImageOut | out_moments | exp average of moments in `rg` | like moments_in | no | + +Events: + +- `clear`: Sent in `process` if the accumulation buffer is reset diff --git a/include/merian-nodes/nodes/image_write/README.md b/include/merian-nodes/nodes/image_write/README.md index baa1d85c..f3e4eda6 100644 --- a/include/merian-nodes/nodes/image_write/README.md +++ b/include/merian-nodes/nodes/image_write/README.md @@ -7,3 +7,9 @@ Inputs: | Type | Input ID | Input name | Description | Delay | |-------|----------|------------|-----------------|-------| | Image | 0 | src | the src image | no | + +Events: + +- `capture`: Sent in `process` if the current input was captured +- `start`: Sent in `pre_process` if recording started +- `stop`: Sent in `pre_process` if recording stopped diff --git a/include/merian-nodes/nodes/image_write/image_write.hpp b/include/merian-nodes/nodes/image_write/image_write.hpp index 12342d42..b721d913 100644 --- a/include/merian-nodes/nodes/image_write/image_write.hpp +++ b/include/merian-nodes/nodes/image_write/image_write.hpp @@ -45,17 +45,25 @@ class ImageWrite : public Node { private: template void get_format_args(const T& consumer, - const vk::Extent3D& extent, + const vk::Extent3D& output_extent, const uint64_t run_iteration, - const std::chrono::nanoseconds& time_since_record) { + const std::chrono::nanoseconds& graph_time_since_record, + const std::chrono::nanoseconds& graph_time, + const std::chrono::nanoseconds& system_time_since_record) { consumer(fmt::arg("record_iteration", iteration)); consumer(fmt::arg("image_index_total", num_captures_since_init)); consumer(fmt::arg("image_index_record", num_captures_since_record)); consumer(fmt::arg("run_iteration", run_iteration)); - consumer(fmt::arg("time", to_milliseconds(time_since_record))); - consumer(fmt::arg("width", extent.width)); - consumer(fmt::arg("height", extent.height)); + consumer(fmt::arg("graph_time", to_seconds(graph_time))); + consumer(fmt::arg("graph_time_since_record", to_seconds(graph_time_since_record))); + consumer(fmt::arg("system_time_since_record", to_seconds(system_time_since_record))); + consumer(fmt::arg("output_width", output_extent.width)); + consumer(fmt::arg("output_height", output_extent.height)); consumer(fmt::arg("random", rand())); + // backward compat + consumer(fmt::arg("time", to_seconds(graph_time_since_record))); + consumer(fmt::arg("width", output_extent.width)); + consumer(fmt::arg("height", output_extent.height)); } private: @@ -76,7 +84,8 @@ class ImageWrite : public Node { float scale = 1; int64_t iteration = 0; uint32_t num_captures_since_init = 0; - std::chrono::nanoseconds record_time_point; + std::chrono::nanoseconds record_graph_time_point; + Stopwatch record_time_point; double last_record_time_millis; double last_frame_time_millis; @@ -93,6 +102,7 @@ class ImageWrite : public Node { int num_captures_since_record = 0; bool reset_record_iteration_at_stop = true; + int time_reference = 0; // system, graph float record_framerate = 30; float record_frametime_millis = 1000.f / 30.f; diff --git a/src/merian-nodes/nodes/image_write/image_write.cpp b/src/merian-nodes/nodes/image_write/image_write.cpp index be07b00c..a705e886 100644 --- a/src/merian-nodes/nodes/image_write/image_write.cpp +++ b/src/merian-nodes/nodes/image_write/image_write.cpp @@ -35,9 +35,10 @@ void ImageWrite::record(const std::chrono::nanoseconds& current_graph_time) { iteration = 1; last_record_time_millis = -std::numeric_limits::infinity(); last_frame_time_millis = 0; - record_time_point = current_graph_time; + record_graph_time_point = current_graph_time; num_captures_since_record = 0; record_iteration_at_start = record_iteration; + record_time_point.reset(); if (callback_on_record && callback) callback(); @@ -53,7 +54,7 @@ ImageWrite::NodeStatusFlags ImageWrite::pre_process(GraphRun& run, } const std::chrono::nanoseconds time_since_record = - run.get_elapsed_duration() - record_time_point; + run.get_elapsed_duration() - record_graph_time_point; // STOP TRIGGER if (record_enable && @@ -97,8 +98,13 @@ void ImageWrite::process(GraphRun& run, iteration++; }; + const std::chrono::nanoseconds system_time_since_record = record_time_point.duration(); + const std::chrono::nanoseconds& graph_time = run.get_elapsed_duration(); + const std::chrono::nanoseconds graph_time_since_record = graph_time - record_graph_time_point; + + assert(time_reference == 0 || time_reference == 1); const std::chrono::nanoseconds time_since_record = - run.get_elapsed_duration() - record_time_point; + time_reference == 0 ? system_time_since_record : graph_time_since_record; //--------- RECORD TRIGGER // RECORD TRIGGER 0: Iteration @@ -131,7 +137,7 @@ void ImageWrite::process(GraphRun& run, vk::Extent3D scaled = max(multiply(src->get_extent(), scale), {1, 1, 1}); fmt::dynamic_format_arg_store arg_store; get_format_args([&](const auto& arg) { arg_store.push_back(arg); }, scaled, run.get_iteration(), - time_since_record); + graph_time_since_record, graph_time, system_time_since_record); std::filesystem::path path; try { if (filename_format.empty()) { @@ -317,9 +323,10 @@ ImageWrite::NodeStatusFlags ImageWrite::properties([[maybe_unused]] Properties& "Provide a format string for the path."); std::vector variables; get_format_args([&](const auto& arg) { variables.push_back(arg.name); }, {1920, 1080, 1}, 1, - 1000ns); + 1000ns, 1000ns, 1000ns); fmt::dynamic_format_arg_store arg_store; - get_format_args([&](const auto& arg) { arg_store.push_back(arg); }, {1920, 1080, 1}, 1, 1000ns); + get_format_args([&](const auto& arg) { arg_store.push_back(arg); }, {1920, 1080, 1}, 1, 1000ns, + 1000ns, 1000ns); std::filesystem::path abs_path; try { @@ -362,6 +369,8 @@ ImageWrite::NodeStatusFlags ImageWrite::properties([[maybe_unused]] Properties& config.output_text("note: Iterations are 1-indexed"); } if (trigger == 1) { + config.config_options("time reference", time_reference, {"system", "graph"}, + Properties::OptionsStyle::COMBO); config.config_float("framerate", record_framerate, "", 0.01); record_frametime_millis = 1000 / record_framerate; config.config_float("frametime", record_frametime_millis, "", 0.01);