Skip to content

Commit

Permalink
merian-nodes: exposure: Use graph time
Browse files Browse the repository at this point in the history
  • Loading branch information
LDAP committed Nov 17, 2024
1 parent f775d58 commit 9e97e15
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
11 changes: 4 additions & 7 deletions include/merian-nodes/nodes/exposure/exposure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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;
Expand All @@ -40,7 +39,7 @@ class AutoExposure : public Node {
};

public:
AutoExposure(const ContextHandle context);
AutoExposure(const ContextHandle& context);

virtual ~AutoExposure();

Expand Down Expand Up @@ -76,8 +75,6 @@ class AutoExposure : public Node {
PipelineHandle histogram;
PipelineHandle luminance;
PipelineHandle exposure;

Stopwatch sw;
};

} // namespace merian_nodes
1 change: 0 additions & 1 deletion include/merian-nodes/nodes/image_write/image_write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
27 changes: 12 additions & 15 deletions src/merian-nodes/nodes/exposure/exposure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<ShaderModule>(context, merian_histogram_comp_spv_size(),
merian_histogram_comp_spv());
Expand All @@ -37,9 +37,9 @@ std::vector<OutputConnectorHandle> 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<ManagedVkBufferOut>(
"avg_luminance", vk::AccessFlagBits2::eShaderRead | vk::AccessFlagBits2::eShaderWrite,
vk::PipelineStageFlagBits2::eComputeShader, vk::ShaderStageFlagBits::eCompute,
Expand All @@ -57,7 +57,7 @@ AutoExposure::on_connected([[maybe_unused]] const NodeIOLayout& io_layout,
.add_push_constant<PushConstant>()
.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<ComputePipeline>(pipe_layout, histogram_module, spec);
Expand All @@ -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<float>(run.get_time_delta());

auto bar = io[con_hist]->buffer_barrier(vk::AccessFlagBits::eShaderRead |
vk::AccessFlagBits::eShaderWrite,
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down

0 comments on commit 9e97e15

Please sign in to comment.