Skip to content

Commit

Permalink
Add hmap transform mode for CPU and GPU to the model config (UI + ser…
Browse files Browse the repository at this point in the history
…ialization) (#241)
  • Loading branch information
otto-link committed Jan 13, 2025
1 parent b7286e4 commit b18acd3
Show file tree
Hide file tree
Showing 16 changed files with 108 additions and 23 deletions.
14 changes: 13 additions & 1 deletion Hesiod/include/hesiod/model/model_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
* this software. */
#pragma once

#include "highmap/algebra.hpp"
#include "nlohmann/json.hpp"

#include "highmap/algebra.hpp"
#include "highmap/heightmap.hpp"

namespace hesiod
{

Expand Down Expand Up @@ -45,6 +47,16 @@ struct ModelConfig
*/
float overlap = 0.5f;

/**
* @brief Heightmap default transform mode for CPU backend.
*/
hmap::TransformMode hmap_transform_mode_cpu = hmap::TransformMode::DISTRIBUTED;

/**
* @brief Heightmap default transform mode for GPU backend.
*/
hmap::TransformMode hmap_transform_mode_gpu = hmap::TransformMode::SINGLE_ARRAY;

/**
* @brief Logs debug information about the current model configuration.
*
Expand Down
71 changes: 70 additions & 1 deletion Hesiod/src/gui/widgets/model_config_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ ModelConfigWidget::ModelConfigWidget(ModelConfig *p_model_config, QWidget *paren
// --- OpenCL configuration

QLabel *label_opencl = new QLabel("Hardware acceleration (OpenCL)");
layout->addWidget(label_opencl, row, 0);
layout->addWidget(label_opencl, row, 0, 1, 3);
row++;

// get available devices
Expand Down Expand Up @@ -168,6 +168,75 @@ ModelConfigWidget::ModelConfigWidget(ModelConfig *p_model_config, QWidget *paren
}
row++;

// transform modes
{
QLabel *label = new QLabel("Node calculation mode");
layout->addWidget(label, row, 0, 1, 3);
row++;
}

{
QLabel *label = new QLabel("CPU");
layout->addWidget(label, row, 0);

QComboBox *combobox = new QComboBox();

QStringList items;
for (auto &[name, id] : hmap::transform_mode_as_string)
{
combobox->addItem(name.c_str());
if (id == (int)this->p_model_config->hmap_transform_mode_cpu)
combobox->setCurrentText(name.c_str());
}

connect(combobox,
QOverload<int>::of(&QComboBox::currentIndexChanged),
[this, combobox]()
{
std::string current_choice = combobox->currentText().toStdString();

LOG->trace("{}", current_choice);
this->p_model_config
->hmap_transform_mode_cpu = static_cast<hmap::TransformMode>(
hmap::transform_mode_as_string.at(current_choice));
});

layout->addWidget(combobox, row, 1, 1, 3);

row++;
}

{
QLabel *label = new QLabel("GPU");
layout->addWidget(label, row, 0);

QComboBox *combobox = new QComboBox();

QStringList items;
for (auto &[name, id] : hmap::transform_mode_as_string)
{
combobox->addItem(name.c_str());
if (id == (int)this->p_model_config->hmap_transform_mode_gpu)
combobox->setCurrentText(name.c_str());
}

connect(combobox,
QOverload<int>::of(&QComboBox::currentIndexChanged),
[this, combobox]()
{
std::string current_choice = combobox->currentText().toStdString();

LOG->trace("{}", current_choice);
this->p_model_config
->hmap_transform_mode_gpu = static_cast<hmap::TransformMode>(
hmap::transform_mode_as_string.at(current_choice));
});

layout->addWidget(combobox, row, 1, 1, 3);

row++;
}

// --- buttons

QDialogButtonBox *button_box = new QDialogButtonBox(QDialogButtonBox::Ok |
Expand Down
4 changes: 4 additions & 0 deletions Hesiod/src/model/model_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ void ModelConfig::json_from(nlohmann::json const &json)
this->tiling.x = json["tiling.x"];
this->tiling.y = json["tiling.y"];
this->overlap = json["overlap"];
this->hmap_transform_mode_cpu = json["hmap_transform_mode_cpu"];
this->hmap_transform_mode_gpu = json["hmap_transform_mode_gpu"];
}

nlohmann::json ModelConfig::json_to() const
Expand All @@ -32,6 +34,8 @@ nlohmann::json ModelConfig::json_to() const
json["tiling.x"] = this->tiling.x;
json["tiling.y"] = this->tiling.y;
json["overlap"] = this->overlap;
json["hmap_transform_mode_cpu"] = this->hmap_transform_mode_cpu;
json["hmap_transform_mode_gpu"] = this->hmap_transform_mode_gpu;
return json;
}

Expand Down
2 changes: 1 addition & 1 deletion Hesiod/src/model/nodes/nodes_function/gabor_wave_fbm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void compute_gabor_wave_fbm_node(BaseNode *p_node)
pa_dy,
bbox);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_gpu);

// add envelope
if (p_env)
Expand Down
2 changes: 1 addition & 1 deletion Hesiod/src/model/nodes/nodes_function/gavoronoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ void compute_gavoronoise_node(BaseNode *p_node)
pa_dy,
bbox);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_gpu);

// add envelope
if (p_env)
Expand Down
6 changes: 3 additions & 3 deletions Hesiod/src/model/nodes/nodes_function/hydraulic_particle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void compute_hydraulic_particle_node(BaseNode *p_node)
GET("evap_rate", FloatAttribute),
GET("post_filtering", BoolAttribute));
},
hmap::TransformMode::SINGLE_ARRAY);
p_node->get_config_ref()->hmap_transform_mode_gpu);
}
else
{
Expand Down Expand Up @@ -251,7 +251,7 @@ void compute_hydraulic_particle_node(BaseNode *p_node)
GET("evap_rate", FloatAttribute),
GET("post_filtering", BoolAttribute));
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_cpu);
}
else
{
Expand Down Expand Up @@ -371,7 +371,7 @@ void compute_hydraulic_particle_node(BaseNode *p_node)
hmap::gpu::smooth_cpulse(mask, 2);
hmap::gpu::smooth_cpulse(*pa_out, 32, &mask);
},
hmap::TransformMode::SINGLE_ARRAY);
p_node->get_config_ref()->hmap_transform_mode_gpu);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ void compute_mountain_range_radial_node(BaseNode *p_node)
pa_angle,
bbox);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_gpu);

// add envelope
if (p_env)
Expand Down
4 changes: 2 additions & 2 deletions Hesiod/src/model/nodes/nodes_function/noise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void compute_noise_node(BaseNode *p_node)
nullptr,
bbox);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_gpu);
}
else
{
Expand All @@ -103,7 +103,7 @@ void compute_noise_node(BaseNode *p_node)
nullptr,
bbox);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_cpu);
}

// add envelope
Expand Down
4 changes: 2 additions & 2 deletions Hesiod/src/model/nodes/nodes_function/noise_fbm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void compute_noise_fbm_node(BaseNode *p_node)
nullptr,
bbox);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_gpu);
}
else
{
Expand Down Expand Up @@ -125,7 +125,7 @@ void compute_noise_fbm_node(BaseNode *p_node)
nullptr,
bbox);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_cpu);
}

// add envelope
Expand Down
4 changes: 2 additions & 2 deletions Hesiod/src/model/nodes/nodes_function/plateau.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ void compute_plateau_node(BaseNode *p_node)

hmap::gpu::plateau(*pa_out, pa_mask, ir, GET("factor", FloatAttribute));
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_gpu);
}
else
{
Expand All @@ -77,7 +77,7 @@ void compute_plateau_node(BaseNode *p_node)

hmap::plateau(*pa_out, pa_mask, ir, GET("factor", FloatAttribute));
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_cpu);
}

p_out->smooth_overlap_buffers();
Expand Down
2 changes: 1 addition & 1 deletion Hesiod/src/model/nodes/nodes_function/recast_cracks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void compute_recast_cracks_node(BaseNode *p_node)
hmin,
hmax);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_gpu);

p_out->smooth_overlap_buffers();
}
Expand Down
4 changes: 2 additions & 2 deletions Hesiod/src/model/nodes/nodes_function/ruggedness.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ void compute_ruggedness_node(BaseNode *p_node)

*pa_out = hmap::gpu::ruggedness(*pa_in, ir);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_gpu);
}
else
{
Expand All @@ -78,7 +78,7 @@ void compute_ruggedness_node(BaseNode *p_node)

*pa_out = hmap::ruggedness(*pa_in, ir);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_cpu);
}

p_out->smooth_overlap_buffers();
Expand Down
4 changes: 2 additions & 2 deletions Hesiod/src/model/nodes/nodes_function/thermal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void compute_thermal_node(BaseNode *p_node)
nullptr, // bedrock
pa_deposition_map);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_gpu);
}
else
{
Expand All @@ -111,7 +111,7 @@ void compute_thermal_node(BaseNode *p_node)
nullptr, // bedrock
pa_deposition_map);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_cpu);
}

p_out->smooth_overlap_buffers();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void compute_thermal_auto_bedrock_node(BaseNode *p_node)
GET("iterations", IntAttribute),
pa_deposition_map);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_gpu);
}
else
{
Expand All @@ -107,7 +107,7 @@ void compute_thermal_auto_bedrock_node(BaseNode *p_node)
GET("iterations", IntAttribute),
pa_deposition_map);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_cpu);
}

p_out->smooth_overlap_buffers();
Expand Down
2 changes: 1 addition & 1 deletion Hesiod/src/model/nodes/nodes_function/thermal_flatten.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void compute_thermal_flatten_node(BaseNode *p_node)
bedrock,
GET("iterations", IntAttribute));
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_cpu);

p_out->smooth_overlap_buffers();
}
Expand Down
2 changes: 1 addition & 1 deletion Hesiod/src/model/nodes/nodes_function/voronoise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void compute_voronoise_node(BaseNode *p_node)
pa_dy,
bbox);
},
hmap::TransformMode::DISTRIBUTED);
p_node->get_config_ref()->hmap_transform_mode_gpu);

// add envelope
if (p_env)
Expand Down

0 comments on commit b18acd3

Please sign in to comment.