Skip to content

Commit

Permalink
merian: desc pool, merian-nodes: accum, image write: clang tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
LDAP committed Nov 13, 2024
1 parent 49a93ef commit af77c91
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 37 deletions.
16 changes: 8 additions & 8 deletions include/merian-nodes/nodes/accumulate/accumulate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Accumulate : public Node {
};

struct FilterPushConstant {
int32_t firefly_filter_enable = 0;
VkBool32 firefly_filter_enable = 0;
float firefly_bias = 0.2;
float firefly_ipr_factor = 50;

Expand All @@ -33,7 +33,7 @@ class Accumulate : public Node {
float accum_max_hist = INFINITY;
float normal_reject_cos = 0.8;
float depth_reject_percent = 0.02;
int32_t clear = 0;
VkBool32 clear = 0;

float adaptive_alpha_reduction = 0.0;
float adaptive_alpha_ipr_factor = 1.5;
Expand All @@ -42,8 +42,8 @@ class Accumulate : public Node {
};

public:
Accumulate(const ContextHandle context,
const ResourceAllocatorHandle allocator,
Accumulate(const ContextHandle& context,
const ResourceAllocatorHandle& allocator,
const std::optional<vk::Format> format = vk::Format::eR32G32B32A32Sfloat);

~Accumulate();
Expand All @@ -70,10 +70,10 @@ class Accumulate : public Node {
const ResourceAllocatorHandle allocator;
const std::optional<vk::Format> format;

static constexpr uint32_t percentile_local_size_x = 8;
static constexpr uint32_t percentile_local_size_y = 8;
static constexpr uint32_t filter_local_size_x = 16;
static constexpr uint32_t filter_local_size_y = 16;
static constexpr uint32_t PERCENTILE_LOCAL_SIZE_X = 8;
static constexpr uint32_t PERCENTILE_LOCAL_SIZE_Y = 8;
static constexpr uint32_t FILTER_LOCAL_SIZE_X = 16;
static constexpr uint32_t FILTER_LOCAL_SIZE_Y = 16;

// Graph IO
ManagedVkImageInHandle con_prev_accum = ManagedVkImageIn::compute_read("prev_accum", 1);
Expand Down
10 changes: 5 additions & 5 deletions include/merian-nodes/nodes/image_write/image_write.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class ImageWrite : public Node {
/**
* @brief Constructs a new instance.
*
* @param allocator The allocator used to create copies of the input to be able to
* @param allocator The allocator used to create copies of the input.
*/
ImageWrite(const ContextHandle context,
const ResourceAllocatorHandle allocator,
const std::string& base_filename =
ImageWrite(const ContextHandle& context,
const ResourceAllocatorHandle& allocator,
const std::string& filename_format =
"image_{record_iteration:06}_{image_index:06}_{run_iteration:06}");

virtual ~ImageWrite();
Expand All @@ -39,7 +39,7 @@ class ImageWrite : public Node {
virtual NodeStatusFlags properties(Properties& config) override;

// Set a callback that can be called on capture or record.
void set_callback(const std::function<void()> callback);
void set_callback(const std::function<void()>& callback);

void record();

Expand Down
10 changes: 5 additions & 5 deletions include/merian/vk/descriptors/descriptor_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,23 +33,23 @@ class DescriptorPool : public std::enable_shared_from_this<DescriptorPool> {
context->device.destroyDescriptorPool(pool);
}

operator const vk::DescriptorPool() const {
operator const vk::DescriptorPool&() const {
return pool;
}

const vk::DescriptorPool& get_pool() const {
return pool;
}

const std::shared_ptr<DescriptorSetLayout> get_layout() const {
const std::shared_ptr<DescriptorSetLayout>& get_layout() const {
return layout;
}

const ContextHandle get_context() const {
const ContextHandle& get_context() const {
return context;
}

const vk::DescriptorPoolCreateFlags get_create_flags() {
vk::DescriptorPoolCreateFlags get_create_flags() {
return flags;
}

Expand Down Expand Up @@ -78,7 +78,7 @@ class DescriptorPool : public std::enable_shared_from_this<DescriptorPool> {
std::vector<vk::DescriptorPoolSize> sizes;
std::map<vk::DescriptorType, uint32_t> type_to_index;

for (auto& binding : bindings) {
for (const auto& binding : bindings) {
if (!type_to_index.contains(binding.descriptorType)) {
vk::DescriptorPoolSize size_for_type{binding.descriptorType,
binding.descriptorCount * set_count};
Expand Down
25 changes: 13 additions & 12 deletions src/merian-nodes/nodes/accumulate/accumulate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

namespace merian_nodes {

Accumulate::Accumulate(const ContextHandle context,
const ResourceAllocatorHandle allocator,
Accumulate::Accumulate(const ContextHandle& context,
const ResourceAllocatorHandle& allocator,
const std::optional<vk::Format> format)
: Node(), context(context), allocator(allocator), format(format) {
percentile_module =
Expand Down Expand Up @@ -64,13 +64,13 @@ Accumulate::on_connected([[maybe_unused]] const NodeIOLayout& io_layout,
}

percentile_group_count_x =
(irr_create_info.extent.width + percentile_local_size_x - 1) / percentile_local_size_x;
(irr_create_info.extent.width + PERCENTILE_LOCAL_SIZE_X - 1) / PERCENTILE_LOCAL_SIZE_X;
percentile_group_count_y =
(irr_create_info.extent.height + percentile_local_size_y - 1) / percentile_local_size_y;
(irr_create_info.extent.height + PERCENTILE_LOCAL_SIZE_Y - 1) / PERCENTILE_LOCAL_SIZE_Y;
filter_group_count_x =
(irr_create_info.extent.width + filter_local_size_x - 1) / filter_local_size_x;
(irr_create_info.extent.width + FILTER_LOCAL_SIZE_X - 1) / FILTER_LOCAL_SIZE_X;
filter_group_count_y =
(irr_create_info.extent.height + filter_local_size_y - 1) / filter_local_size_y;
(irr_create_info.extent.height + FILTER_LOCAL_SIZE_Y - 1) / FILTER_LOCAL_SIZE_Y;

vk::ImageCreateInfo quartile_image_create_info = irr_create_info;
quartile_image_create_info.usage |= vk::ImageUsageFlagBits::eSampled;
Expand Down Expand Up @@ -99,7 +99,7 @@ Accumulate::on_connected([[maybe_unused]] const NodeIOLayout& io_layout,
.build_pipeline_layout();

auto quartile_spec_builder = SpecializationInfoBuilder();
quartile_spec_builder.add_entry(percentile_local_size_x, percentile_local_size_y);
quartile_spec_builder.add_entry(PERCENTILE_LOCAL_SIZE_X, PERCENTILE_LOCAL_SIZE_Y);
auto quartile_spec = quartile_spec_builder.build();
calculate_percentiles =
std::make_shared<ComputePipeline>(quartile_pipe_layout, percentile_module, quartile_spec);
Expand All @@ -110,9 +110,9 @@ Accumulate::on_connected([[maybe_unused]] const NodeIOLayout& io_layout,
.add_push_constant<FilterPushConstant>()
.build_pipeline_layout();
auto filter_spec_builder = SpecializationInfoBuilder();
const uint32_t wg_rounded_irr_size_x = percentile_group_count_x * percentile_local_size_x;
const uint32_t wg_rounded_irr_size_y = percentile_group_count_y * percentile_local_size_y;
filter_spec_builder.add_entry(filter_local_size_x, filter_local_size_y, wg_rounded_irr_size_x,
const uint32_t wg_rounded_irr_size_x = percentile_group_count_x * PERCENTILE_LOCAL_SIZE_X;
const uint32_t wg_rounded_irr_size_y = percentile_group_count_y * PERCENTILE_LOCAL_SIZE_Y;
filter_spec_builder.add_entry(FILTER_LOCAL_SIZE_X, FILTER_LOCAL_SIZE_Y, wg_rounded_irr_size_x,
wg_rounded_irr_size_y, filter_mode, extended_search,
reuse_border);
auto filter_spec = filter_spec_builder.build();
Expand All @@ -128,7 +128,8 @@ void Accumulate::process(GraphRun& run,
[[maybe_unused]] const NodeIO& io) {
accumulate_pc.iteration = run.get_total_iteration();

if (accumulate_pc.firefly_filter_enable || accumulate_pc.adaptive_alpha_reduction > 0.0f) {
if (accumulate_pc.firefly_filter_enable == VK_TRUE ||
accumulate_pc.adaptive_alpha_reduction > 0.0f) {
MERIAN_PROFILE_SCOPE_GPU(run.get_profiler(), cmd, "compute percentiles");
auto bar = percentile_texture->get_image()->barrier(
vk::ImageLayout::eGeneral, vk::AccessFlagBits::eShaderRead,
Expand All @@ -152,7 +153,7 @@ void Accumulate::process(GraphRun& run,
vk::PipelineStageFlagBits::eComputeShader, {}, {}, {}, bar);

{
accumulate_pc.clear = run.get_iteration() == 0 || clear;
accumulate_pc.clear = static_cast<int32_t>(run.get_iteration() == 0 || clear);
clear = false;

MERIAN_PROFILE_SCOPE_GPU(run.get_profiler(), cmd, "accumulate");
Expand Down
17 changes: 10 additions & 7 deletions src/merian-nodes/nodes/image_write/image_write.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@ namespace merian_nodes {
#define FORMAT_JPG 1
#define FORMAT_HDR 2

static std::unordered_map<uint32_t, std::string> FILE_EXTENSIONS = {
static const std::unordered_map<uint32_t, std::string> FILE_EXTENSIONS = {
{FORMAT_PNG, ".png"}, {FORMAT_JPG, ".jpg"}, {FORMAT_HDR, ".hdr"}};

ImageWrite::ImageWrite(const ContextHandle context,
const ResourceAllocatorHandle allocator,
ImageWrite::ImageWrite(const ContextHandle& context,
const ResourceAllocatorHandle& allocator,
const std::string& filename_format)
: Node(), context(context), allocator(allocator), filename_format(filename_format) {}

ImageWrite::~ImageWrite() {}

std::vector<InputConnectorHandle> ImageWrite::describe_inputs() {
estimated_frametime_millis = 0;

return {con_src};
}

Expand Down Expand Up @@ -121,7 +123,7 @@ void ImageWrite::process(GraphRun& run,
throw fmt::format_error{"empty filename"};
}
path = std::filesystem::absolute(fmt::vformat(this->filename_format, arg_store) +
FILE_EXTENSIONS[this->format]);
FILE_EXTENSIONS.at(this->format));
} catch (const std::exception& e) {
// catch std::filesystem::filesystem_error and fmt::format_error
record_enable = false;
Expand Down Expand Up @@ -228,6 +230,7 @@ void ImageWrite::process(GraphRun& run,
TimelineSemaphoreHandle image_ready = std::make_shared<TimelineSemaphore>(context, 0);
run.add_signal_semaphore(image_ready, 1);

// Pause execution if to many tasks are queued to allow the write threads to keep up.
std::unique_lock lk(mutex_concurrent);
cv_concurrent.wait(lk, [&] { return concurrent_tasks < max_concurrent_tasks; });
concurrent_tasks++;
Expand All @@ -240,7 +243,7 @@ void ImageWrite::process(GraphRun& run,
const std::function<void()> write_task =
([this, image_ready, linear_image, path, tmp_filename]() {
image_ready->wait(1);
void* mem = linear_image->get_memory()->map();
float* mem = linear_image->get_memory()->map_as<float>();

switch (this->format) {
case FORMAT_PNG: {
Expand All @@ -256,7 +259,7 @@ void ImageWrite::process(GraphRun& run,
}
case FORMAT_HDR: {
stbi_write_hdr(tmp_filename.c_str(), linear_image->get_extent().width,
linear_image->get_extent().height, 4, static_cast<float*>(mem));
linear_image->get_extent().height, 4, mem);
break;
}
}
Expand Down Expand Up @@ -396,7 +399,7 @@ ImageWrite::NodeStatusFlags ImageWrite::properties([[maybe_unused]] Properties&
return {};
}

void ImageWrite::set_callback(const std::function<void()> callback) {
void ImageWrite::set_callback(const std::function<void()>& callback) {
this->callback = callback;
}

Expand Down

0 comments on commit af77c91

Please sign in to comment.