From 9e97e15d7119f145d95439caa0795761111b08da Mon Sep 17 00:00:00 2001 From: Lucas Alber Date: Sun, 17 Nov 2024 18:48:41 +0100 Subject: [PATCH] merian-nodes: exposure: Use graph time --- .../merian-nodes/nodes/exposure/exposure.hpp | 11 +++----- .../nodes/image_write/image_write.hpp | 1 - src/merian-nodes/nodes/exposure/exposure.cpp | 27 +++++++++---------- 3 files changed, 16 insertions(+), 23 deletions(-) diff --git a/include/merian-nodes/nodes/exposure/exposure.hpp b/include/merian-nodes/nodes/exposure/exposure.hpp index 25b2e96..7653c5d 100644 --- a/include/merian-nodes/nodes/exposure/exposure.hpp +++ b/include/merian-nodes/nodes/exposure/exposure.hpp @@ -4,7 +4,6 @@ #include "merian-nodes/connectors/managed_vk_image_in.hpp" #include "merian-nodes/graph/node.hpp" -#include "merian/utils/stopwatch.hpp" #include "merian/vk/pipeline/pipeline.hpp" #include "merian/vk/shader/shader_module.hpp" @@ -13,11 +12,11 @@ namespace merian_nodes { class AutoExposure : public Node { private: // Histogram uses local_size_x * local_size_y bins; - static constexpr uint32_t local_size_x = 16; - static constexpr uint32_t local_size_y = 16; + static constexpr uint32_t LOCAL_SIZE_X = 16; + static constexpr uint32_t LOCAL_SIZE_Y = 16; struct PushConstant { - int automatic = 0; + int automatic = VK_FALSE; float iso = 100.0; float q = 0.65; @@ -40,7 +39,7 @@ class AutoExposure : public Node { }; public: - AutoExposure(const ContextHandle context); + AutoExposure(const ContextHandle& context); virtual ~AutoExposure(); @@ -76,8 +75,6 @@ class AutoExposure : public Node { PipelineHandle histogram; PipelineHandle luminance; PipelineHandle exposure; - - Stopwatch sw; }; } // namespace merian_nodes diff --git a/include/merian-nodes/nodes/image_write/image_write.hpp b/include/merian-nodes/nodes/image_write/image_write.hpp index ca12096..4e35fac 100644 --- a/include/merian-nodes/nodes/image_write/image_write.hpp +++ b/include/merian-nodes/nodes/image_write/image_write.hpp @@ -2,7 +2,6 @@ #include "merian-nodes/connectors/managed_vk_image_in.hpp" #include "merian-nodes/graph/node.hpp" -#include "merian/utils/stopwatch.hpp" #include "merian/vk/memory/resource_allocator.hpp" namespace merian_nodes { diff --git a/src/merian-nodes/nodes/exposure/exposure.cpp b/src/merian-nodes/nodes/exposure/exposure.cpp index 833f67e..735969f 100644 --- a/src/merian-nodes/nodes/exposure/exposure.cpp +++ b/src/merian-nodes/nodes/exposure/exposure.cpp @@ -10,7 +10,7 @@ namespace merian_nodes { -AutoExposure::AutoExposure(const ContextHandle context) : Node(), context(context) { +AutoExposure::AutoExposure(const ContextHandle& context) : Node(), context(context) { histogram_module = std::make_shared(context, merian_histogram_comp_spv_size(), merian_histogram_comp_spv()); @@ -37,9 +37,9 @@ std::vector AutoExposure::describe_outputs(const NodeIOLa vk::AccessFlagBits2::eTransferWrite, vk::PipelineStageFlagBits2::eComputeShader | vk::PipelineStageFlagBits2::eTransfer, vk::ShaderStageFlagBits::eCompute, - vk::BufferCreateInfo({}, local_size_x * local_size_y * sizeof(uint32_t) + sizeof(uint32_t), - vk::BufferUsageFlagBits::eStorageBuffer | - vk::BufferUsageFlagBits::eTransferDst)); + vk::BufferCreateInfo( + {}, (vk::DeviceSize)LOCAL_SIZE_X * LOCAL_SIZE_Y * sizeof(uint32_t) + sizeof(uint32_t), + vk::BufferUsageFlagBits::eStorageBuffer | vk::BufferUsageFlagBits::eTransferDst)); con_luminance = std::make_shared( "avg_luminance", vk::AccessFlagBits2::eShaderRead | vk::AccessFlagBits2::eShaderWrite, vk::PipelineStageFlagBits2::eComputeShader, vk::ShaderStageFlagBits::eCompute, @@ -57,7 +57,7 @@ AutoExposure::on_connected([[maybe_unused]] const NodeIOLayout& io_layout, .add_push_constant() .build_pipeline_layout(); auto spec_builder = SpecializationInfoBuilder(); - spec_builder.add_entry(local_size_x, local_size_y); + spec_builder.add_entry(LOCAL_SIZE_X, LOCAL_SIZE_Y); SpecializationInfoHandle spec = spec_builder.build(); histogram = std::make_shared(pipe_layout, histogram_module, spec); @@ -72,13 +72,12 @@ void AutoExposure::process(GraphRun& run, const vk::CommandBuffer& cmd, const DescriptorSetHandle& descriptor_set, const NodeIO& io) { - const auto group_count_x = (io[con_out]->get_extent().width + local_size_x - 1) / local_size_x; - const auto group_count_y = (io[con_out]->get_extent().height + local_size_y - 1) / local_size_y; + const auto group_count_x = (io[con_out]->get_extent().width + LOCAL_SIZE_X - 1) / LOCAL_SIZE_X; + const auto group_count_y = (io[con_out]->get_extent().height + LOCAL_SIZE_Y - 1) / LOCAL_SIZE_Y; - if (pc.automatic) { - pc.reset = run.get_iteration() == 0; - pc.timediff = sw.seconds(); - sw.reset(); + if (pc.automatic == VK_TRUE) { + pc.reset = run.get_iteration() == 0 ? VK_TRUE : VK_FALSE; + pc.timediff = static_cast(run.get_time_delta()); auto bar = io[con_hist]->buffer_barrier(vk::AccessFlagBits::eShaderRead | vk::AccessFlagBits::eShaderWrite, @@ -123,9 +122,7 @@ void AutoExposure::process(GraphRun& run, AutoExposure::NodeStatusFlags AutoExposure::properties(Properties& config) { config.st_separate("General"); - bool autoexposure = pc.automatic; - config.config_bool("autoexposure", autoexposure); - pc.automatic = autoexposure; + config.config_bool("autoexposure", pc.automatic); config.config_float("q", pc.q, "Lens and vignetting attenuation", 0.01); config.config_float("min exposure", pc.min_exposure, "", 0.1); pc.min_exposure = std::max(pc.min_exposure, 0.f); @@ -145,7 +142,7 @@ AutoExposure::NodeStatusFlags AutoExposure::properties(Properties& config) { config.st_separate("Manual"); config.config_float("ISO", pc.iso, "Sensor sensitivity/gain (ISO)"); - float shutter_time = pc.shutter_time * 1000.0; + float shutter_time = pc.shutter_time * 1000.0f; config.config_float("shutter time (ms)", shutter_time); pc.shutter_time = std::max(0.f, shutter_time / 1000); config.config_float("aperature", pc.aperature, "", .01);