diff --git a/Hesiod/include/hesiod/model/model_config.hpp b/Hesiod/include/hesiod/model/model_config.hpp index f5940f33..8b9e0c99 100644 --- a/Hesiod/include/hesiod/model/model_config.hpp +++ b/Hesiod/include/hesiod/model/model_config.hpp @@ -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 { @@ -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. * diff --git a/Hesiod/src/gui/widgets/model_config_widget.cpp b/Hesiod/src/gui/widgets/model_config_widget.cpp index 1bb75e44..8426e931 100644 --- a/Hesiod/src/gui/widgets/model_config_widget.cpp +++ b/Hesiod/src/gui/widgets/model_config_widget.cpp @@ -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 @@ -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::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::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::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::transform_mode_as_string.at(current_choice)); + }); + + layout->addWidget(combobox, row, 1, 1, 3); + + row++; + } + // --- buttons QDialogButtonBox *button_box = new QDialogButtonBox(QDialogButtonBox::Ok | diff --git a/Hesiod/src/model/model_config.cpp b/Hesiod/src/model/model_config.cpp index f76479c3..9dbab65f 100644 --- a/Hesiod/src/model/model_config.cpp +++ b/Hesiod/src/model/model_config.cpp @@ -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 @@ -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; } diff --git a/Hesiod/src/model/nodes/nodes_function/gabor_wave_fbm.cpp b/Hesiod/src/model/nodes/nodes_function/gabor_wave_fbm.cpp index 536bc1a9..8c19b512 100644 --- a/Hesiod/src/model/nodes/nodes_function/gabor_wave_fbm.cpp +++ b/Hesiod/src/model/nodes/nodes_function/gabor_wave_fbm.cpp @@ -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) diff --git a/Hesiod/src/model/nodes/nodes_function/gavoronoise.cpp b/Hesiod/src/model/nodes/nodes_function/gavoronoise.cpp index 9000ca46..160b5e68 100644 --- a/Hesiod/src/model/nodes/nodes_function/gavoronoise.cpp +++ b/Hesiod/src/model/nodes/nodes_function/gavoronoise.cpp @@ -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) diff --git a/Hesiod/src/model/nodes/nodes_function/hydraulic_particle.cpp b/Hesiod/src/model/nodes/nodes_function/hydraulic_particle.cpp index 228cc308..c8c1b3cd 100644 --- a/Hesiod/src/model/nodes/nodes_function/hydraulic_particle.cpp +++ b/Hesiod/src/model/nodes/nodes_function/hydraulic_particle.cpp @@ -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 { @@ -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 { @@ -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); } } diff --git a/Hesiod/src/model/nodes/nodes_function/mountain_range_radial.cpp b/Hesiod/src/model/nodes/nodes_function/mountain_range_radial.cpp index 9fd9e083..50d7d2b3 100644 --- a/Hesiod/src/model/nodes/nodes_function/mountain_range_radial.cpp +++ b/Hesiod/src/model/nodes/nodes_function/mountain_range_radial.cpp @@ -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) diff --git a/Hesiod/src/model/nodes/nodes_function/noise.cpp b/Hesiod/src/model/nodes/nodes_function/noise.cpp index 852fa880..8c48063a 100644 --- a/Hesiod/src/model/nodes/nodes_function/noise.cpp +++ b/Hesiod/src/model/nodes/nodes_function/noise.cpp @@ -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 { @@ -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 diff --git a/Hesiod/src/model/nodes/nodes_function/noise_fbm.cpp b/Hesiod/src/model/nodes/nodes_function/noise_fbm.cpp index 56e9efaa..e34365d0 100644 --- a/Hesiod/src/model/nodes/nodes_function/noise_fbm.cpp +++ b/Hesiod/src/model/nodes/nodes_function/noise_fbm.cpp @@ -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 { @@ -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 diff --git a/Hesiod/src/model/nodes/nodes_function/plateau.cpp b/Hesiod/src/model/nodes/nodes_function/plateau.cpp index fefc21d2..bdc37653 100644 --- a/Hesiod/src/model/nodes/nodes_function/plateau.cpp +++ b/Hesiod/src/model/nodes/nodes_function/plateau.cpp @@ -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 { @@ -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(); diff --git a/Hesiod/src/model/nodes/nodes_function/recast_cracks.cpp b/Hesiod/src/model/nodes/nodes_function/recast_cracks.cpp index 510c5e64..c967506f 100644 --- a/Hesiod/src/model/nodes/nodes_function/recast_cracks.cpp +++ b/Hesiod/src/model/nodes/nodes_function/recast_cracks.cpp @@ -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(); } diff --git a/Hesiod/src/model/nodes/nodes_function/ruggedness.cpp b/Hesiod/src/model/nodes/nodes_function/ruggedness.cpp index 99891346..de68184a 100644 --- a/Hesiod/src/model/nodes/nodes_function/ruggedness.cpp +++ b/Hesiod/src/model/nodes/nodes_function/ruggedness.cpp @@ -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 { @@ -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(); diff --git a/Hesiod/src/model/nodes/nodes_function/thermal.cpp b/Hesiod/src/model/nodes/nodes_function/thermal.cpp index 53b7521e..868487fd 100644 --- a/Hesiod/src/model/nodes/nodes_function/thermal.cpp +++ b/Hesiod/src/model/nodes/nodes_function/thermal.cpp @@ -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 { @@ -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(); diff --git a/Hesiod/src/model/nodes/nodes_function/thermal_auto_bedrock.cpp b/Hesiod/src/model/nodes/nodes_function/thermal_auto_bedrock.cpp index 730fb7b5..353193a4 100644 --- a/Hesiod/src/model/nodes/nodes_function/thermal_auto_bedrock.cpp +++ b/Hesiod/src/model/nodes/nodes_function/thermal_auto_bedrock.cpp @@ -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 { @@ -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(); diff --git a/Hesiod/src/model/nodes/nodes_function/thermal_flatten.cpp b/Hesiod/src/model/nodes/nodes_function/thermal_flatten.cpp index e44aa4b9..9e15b359 100644 --- a/Hesiod/src/model/nodes/nodes_function/thermal_flatten.cpp +++ b/Hesiod/src/model/nodes/nodes_function/thermal_flatten.cpp @@ -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(); } diff --git a/Hesiod/src/model/nodes/nodes_function/voronoise.cpp b/Hesiod/src/model/nodes/nodes_function/voronoise.cpp index 6b2d95c0..63cac78b 100644 --- a/Hesiod/src/model/nodes/nodes_function/voronoise.cpp +++ b/Hesiod/src/model/nodes/nodes_function/voronoise.cpp @@ -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)