Skip to content

Commit

Permalink
merian-nodes: ImageWrite: Add system time reference and rename format…
Browse files Browse the repository at this point in the history
… args
  • Loading branch information
LDAP committed Nov 19, 2024
1 parent 4d2f3e0 commit 41c1ba7
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 12 deletions.
4 changes: 4 additions & 0 deletions include/merian-nodes/nodes/accumulate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions include/merian-nodes/nodes/image_write/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
22 changes: 16 additions & 6 deletions include/merian-nodes/nodes/image_write/image_write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,25 @@ class ImageWrite : public Node {
private:
template <typename T>
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:
Expand All @@ -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;
Expand All @@ -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;

Expand Down
21 changes: 15 additions & 6 deletions src/merian-nodes/nodes/image_write/image_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,10 @@ void ImageWrite::record(const std::chrono::nanoseconds& current_graph_time) {
iteration = 1;
last_record_time_millis = -std::numeric_limits<double>::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();
Expand All @@ -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 &&
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<fmt::format_context> 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()) {
Expand Down Expand Up @@ -317,9 +323,10 @@ ImageWrite::NodeStatusFlags ImageWrite::properties([[maybe_unused]] Properties&
"Provide a format string for the path.");
std::vector<std::string> 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<fmt::format_context> 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 {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 41c1ba7

Please sign in to comment.