From 4e777476b50dd6ad38c2684e5256953edd2fdd7f Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 26 Dec 2024 17:53:55 +0100 Subject: [PATCH] Refactor: Cycles: Replace std::bind by lambdas Pull Request: https://projects.blender.org/blender/blender/pulls/132361 --- intern/cycles/app/cycles_standalone.cpp | 8 +++--- intern/cycles/app/oiio_output_driver.h | 5 ++-- intern/cycles/app/opengl/display_driver.cpp | 4 +-- intern/cycles/app/opengl/display_driver.h | 10 ++++---- intern/cycles/blender/session.cpp | 10 +++----- intern/cycles/blender/shader.cpp | 2 +- intern/cycles/bvh/sort.cpp | 5 ++-- intern/cycles/device/cpu/device_impl.cpp | 1 - intern/cycles/device/device.h | 6 ++--- intern/cycles/device/multi/device.cpp | 6 ++--- intern/cycles/device/optix/device_impl.cpp | 5 ++-- intern/cycles/integrator/denoiser.h | 5 ++-- intern/cycles/integrator/path_trace.h | 5 ++-- intern/cycles/integrator/shader_eval.cpp | 4 +-- intern/cycles/integrator/shader_eval.h | 8 +++--- intern/cycles/scene/camera.cpp | 14 +++++------ intern/cycles/scene/film.cpp | 13 +++++----- intern/cycles/scene/geometry.cpp | 15 +++++++----- intern/cycles/scene/hair.cpp | 15 ++++++++---- intern/cycles/scene/image.cpp | 18 ++++++++------ intern/cycles/scene/image.h | 4 +-- intern/cycles/scene/integrator.cpp | 4 ++- intern/cycles/scene/mesh_displace.cpp | 15 ++++++++---- intern/cycles/scene/osl.cpp | 2 +- intern/cycles/scene/svm.cpp | 13 ++++------ intern/cycles/scene/svm.h | 2 +- intern/cycles/session/session.cpp | 3 +-- intern/cycles/session/session.h | 4 ++- intern/cycles/session/tile.h | 5 +++- intern/cycles/test/util_task_test.cpp | 4 +-- intern/cycles/util/CMakeLists.txt | 1 - intern/cycles/util/function.h | 27 --------------------- intern/cycles/util/profiling.cpp | 2 +- intern/cycles/util/progress.h | 15 ++++++------ intern/cycles/util/task.cpp | 2 +- intern/cycles/util/task.h | 5 ++-- intern/cycles/util/thread.cpp | 2 +- intern/cycles/util/thread.h | 6 ++--- intern/cycles/util/time.h | 5 ++-- 39 files changed, 136 insertions(+), 144 deletions(-) delete mode 100644 intern/cycles/util/function.h diff --git a/intern/cycles/app/cycles_standalone.cpp b/intern/cycles/app/cycles_standalone.cpp index bc4ac344879..18186410770 100644 --- a/intern/cycles/app/cycles_standalone.cpp +++ b/intern/cycles/app/cycles_standalone.cpp @@ -13,7 +13,6 @@ #include "util/args.h" #include "util/foreach.h" -#include "util/function.h" #include "util/image.h" #include "util/log.h" #include "util/path.h" @@ -144,11 +143,12 @@ static void session_init() } if (options.session_params.background && !options.quiet) { - options.session->progress.set_update_callback(function_bind(&session_print_status)); + options.session->progress.set_update_callback([] { session_print_status(); }); } #ifdef WITH_CYCLES_STANDALONE_GUI - else - options.session->progress.set_update_callback(function_bind(&window_redraw)); + else { + options.session->progress.set_update_callback([] { window_redraw(); }); + } #endif /* load scene */ diff --git a/intern/cycles/app/oiio_output_driver.h b/intern/cycles/app/oiio_output_driver.h index 54eb6f16395..f7d4f98379a 100644 --- a/intern/cycles/app/oiio_output_driver.h +++ b/intern/cycles/app/oiio_output_driver.h @@ -2,9 +2,10 @@ * * SPDX-License-Identifier: Apache-2.0 */ +#include + #include "session/output_driver.h" -#include "util/function.h" #include "util/image.h" #include "util/string.h" #include "util/unique_ptr.h" @@ -14,7 +15,7 @@ CCL_NAMESPACE_BEGIN class OIIOOutputDriver : public OutputDriver { public: - typedef function LogFunction; + using LogFunction = std::function; OIIOOutputDriver(const string_view filepath, const string_view pass, LogFunction log); virtual ~OIIOOutputDriver(); diff --git a/intern/cycles/app/opengl/display_driver.cpp b/intern/cycles/app/opengl/display_driver.cpp index c016c29edd2..555836bc689 100644 --- a/intern/cycles/app/opengl/display_driver.cpp +++ b/intern/cycles/app/opengl/display_driver.cpp @@ -17,8 +17,8 @@ CCL_NAMESPACE_BEGIN * OpenGLDisplayDriver. */ -OpenGLDisplayDriver::OpenGLDisplayDriver(const function &gl_context_enable, - const function &gl_context_disable) +OpenGLDisplayDriver::OpenGLDisplayDriver(const std::function &gl_context_enable, + const std::function &gl_context_disable) : gl_context_enable_(gl_context_enable), gl_context_disable_(gl_context_disable) { } diff --git a/intern/cycles/app/opengl/display_driver.h b/intern/cycles/app/opengl/display_driver.h index f0cb05c987a..333171334fc 100644 --- a/intern/cycles/app/opengl/display_driver.h +++ b/intern/cycles/app/opengl/display_driver.h @@ -5,12 +5,12 @@ #pragma once #include +#include #include "app/opengl/shader.h" #include "session/display_driver.h" -#include "util/function.h" #include "util/unique_ptr.h" CCL_NAMESPACE_BEGIN @@ -19,8 +19,8 @@ class OpenGLDisplayDriver : public DisplayDriver { public: /* Callbacks for enabling and disabling the OpenGL context. Must be provided to support enabling * the context on the Cycles render thread independent of the main thread. */ - OpenGLDisplayDriver(const function &gl_context_enable, - const function &gl_context_disable); + OpenGLDisplayDriver(const std::function &gl_context_enable, + const std::function &gl_context_disable); ~OpenGLDisplayDriver(); virtual void graphics_interop_activate() override; @@ -111,8 +111,8 @@ class OpenGLDisplayDriver : public DisplayDriver { float2 zoom_ = make_float2(1.0f, 1.0f); - function gl_context_enable_ = nullptr; - function gl_context_disable_ = nullptr; + std::function gl_context_enable_ = nullptr; + std::function gl_context_disable_ = nullptr; }; CCL_NAMESPACE_END diff --git a/intern/cycles/blender/session.cpp b/intern/cycles/blender/session.cpp index 57ea30f3f07..f07845e1317 100644 --- a/intern/cycles/blender/session.cpp +++ b/intern/cycles/blender/session.cpp @@ -22,7 +22,6 @@ #include "util/algorithm.h" #include "util/color.h" #include "util/foreach.h" -#include "util/function.h" #include "util/hash.h" #include "util/log.h" #include "util/murmurhash.h" @@ -124,8 +123,8 @@ void BlenderSession::create_session() /* create session */ session = new Session(session_params, scene_params); - session->progress.set_update_callback(function_bind(&BlenderSession::tag_redraw, this)); - session->progress.set_cancel_callback(function_bind(&BlenderSession::test_cancel, this)); + session->progress.set_update_callback([this] { tag_redraw(); }); + session->progress.set_cancel_callback([this] { test_cancel(); }); session->set_pause(session_pause); /* create scene */ @@ -509,7 +508,7 @@ void BlenderSession::render_frame_finish() /* Clear output driver. */ session->set_output_driver(nullptr); - session->full_buffer_written_cb = function_null; + session->full_buffer_written_cb = nullptr; /* The display driver is the source of drawing context for both drawing and possible graphics * interoperability objects in the path trace. Once the frame is finished the OpenGL context @@ -755,8 +754,7 @@ void BlenderSession::bake(BL::Depsgraph &b_depsgraph_, /* Update session. */ session->reset(session_params, buffer_params); - session->progress.set_update_callback( - function_bind(&BlenderSession::update_bake_progress, this)); + session->progress.set_update_callback([this] { update_bake_progress(); }); } /* Perform bake. Check cancel to avoid crash with incomplete scene data. */ diff --git a/intern/cycles/blender/shader.cpp b/intern/cycles/blender/shader.cpp index 3b88df5ace4..9fe8276ad95 100644 --- a/intern/cycles/blender/shader.cpp +++ b/intern/cycles/blender/shader.cpp @@ -1614,7 +1614,7 @@ void BlenderSync::sync_materials(BL::Depsgraph &b_depsgraph, bool update_all) * right before compiling. */ if (!preview) { - pool.push(function_bind(&ShaderGraph::simplify, graph, scene)); + pool.push([graph, scene = scene] { graph->simplify(scene); }); /* NOTE: Update shaders out of the threads since those routines * are accessing and writing to a global context. */ diff --git a/intern/cycles/bvh/sort.cpp b/intern/cycles/bvh/sort.cpp index 0aca07bd3c2..44759178cae 100644 --- a/intern/cycles/bvh/sort.cpp +++ b/intern/cycles/bvh/sort.cpp @@ -144,8 +144,9 @@ static void bvh_reference_sort_threaded(TaskPool *task_pool, have_work = false; if (left < end) { if (start < right) { - task_pool->push( - function_bind(bvh_reference_sort_threaded, task_pool, data, left, end, compare)); + task_pool->push([task_pool, data, left, end, compare] { + bvh_reference_sort_threaded(task_pool, data, left, end, compare); + }); } else { start = left; diff --git a/intern/cycles/device/cpu/device_impl.cpp b/intern/cycles/device/cpu/device_impl.cpp index 22cf014de92..195239eaac2 100644 --- a/intern/cycles/device/cpu/device_impl.cpp +++ b/intern/cycles/device/cpu/device_impl.cpp @@ -42,7 +42,6 @@ #include "util/debug.h" #include "util/foreach.h" -#include "util/function.h" #include "util/guiding.h" #include "util/log.h" #include "util/map.h" diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h index 9aee1928d7e..1369db5b31a 100644 --- a/intern/cycles/device/device.h +++ b/intern/cycles/device/device.h @@ -5,14 +5,14 @@ #ifndef __DEVICE_H__ #define __DEVICE_H__ -#include +#include +#include #include "bvh/params.h" #include "device/denoise.h" #include "device/memory.h" -#include "util/function.h" #include "util/list.h" #include "util/log.h" #include "util/stats.h" @@ -280,7 +280,7 @@ class Device { /* Run given callback for every individual device which will be handling rendering. * For the single device the callback is called for the device itself. For the multi-device the * callback is only called for the sub-devices. */ - virtual void foreach_device(const function &callback) + virtual void foreach_device(const std::function &callback) { callback(this); } diff --git a/intern/cycles/device/multi/device.cpp b/intern/cycles/device/multi/device.cpp index 0a8808388b6..69d1a81aec5 100644 --- a/intern/cycles/device/multi/device.cpp +++ b/intern/cycles/device/multi/device.cpp @@ -4,8 +4,8 @@ #include "device/multi/device.h" -#include -#include +#include +#include #include "bvh/multi.h" @@ -459,7 +459,7 @@ class MultiDevice : public Device { return -1; } - virtual void foreach_device(const function &callback) override + void foreach_device(const std::function &callback) override { foreach (SubDevice &sub, devices) { sub.device->foreach_device(callback); diff --git a/intern/cycles/device/optix/device_impl.cpp b/intern/cycles/device/optix/device_impl.cpp index ff13358d270..c11a0dde78a 100644 --- a/intern/cycles/device/optix/device_impl.cpp +++ b/intern/cycles/device/optix/device_impl.cpp @@ -40,8 +40,9 @@ static void execute_optix_task(TaskPool &pool, OptixTask task, OptixResult &fail const OptixResult result = optixTaskExecute(task, additional_tasks, 16, &num_additional_tasks); if (result == OPTIX_SUCCESS) { for (unsigned int i = 0; i < num_additional_tasks; ++i) { - pool.push(function_bind( - &execute_optix_task, std::ref(pool), additional_tasks[i], std::ref(failure_reason))); + pool.push([&pool, additional_task = additional_tasks[i], &failure_reason] { + execute_optix_task(pool, additional_task, failure_reason); + }); } } else { diff --git a/intern/cycles/integrator/denoiser.h b/intern/cycles/integrator/denoiser.h index e209e62a59f..f93f864f406 100644 --- a/intern/cycles/integrator/denoiser.h +++ b/intern/cycles/integrator/denoiser.h @@ -7,9 +7,10 @@ /* TODO(sergey): The integrator folder might not be the best. Is easy to move files around if the * better place is figured out. */ +#include + #include "device/denoise.h" #include "device/device.h" -#include "util/function.h" #include "util/unique_ptr.h" CCL_NAMESPACE_BEGIN @@ -101,7 +102,7 @@ class Denoiser { * and access to this device happen. */ Device *get_denoiser_device() const; - function is_cancelled_cb; + std::function is_cancelled_cb; bool is_cancelled() const { diff --git a/intern/cycles/integrator/path_trace.h b/intern/cycles/integrator/path_trace.h index 0c880509c84..740a06554a4 100644 --- a/intern/cycles/integrator/path_trace.h +++ b/intern/cycles/integrator/path_trace.h @@ -4,6 +4,8 @@ #pragma once +#include + #include "integrator/denoiser.h" #include "integrator/guiding.h" #include "integrator/pass_accessor.h" @@ -12,7 +14,6 @@ #include "session/buffers.h" -#include "util/function.h" #include "util/guiding.h" #include "util/thread.h" #include "util/unique_ptr.h" @@ -181,7 +182,7 @@ class PathTrace { * It is supposed to be cheaper than buffer update/write, hence can be called more often. * Additionally, it might be called form the middle of wavefront (meaning, it is not guaranteed * that the buffer is "uniformly" sampled at the moment of this callback). */ - function progress_update_cb; + std::function progress_update_cb; protected: /* Actual implementation of the rendering pipeline. diff --git a/intern/cycles/integrator/shader_eval.cpp b/intern/cycles/integrator/shader_eval.cpp index bf82296eb90..91d61d97944 100644 --- a/intern/cycles/integrator/shader_eval.cpp +++ b/intern/cycles/integrator/shader_eval.cpp @@ -24,8 +24,8 @@ ShaderEval::ShaderEval(Device *device, Progress &progress) : device_(device), pr bool ShaderEval::eval(const ShaderEvalType type, const int max_num_inputs, const int num_channels, - const function &)> &fill_input, - const function &)> &read_output) + const std::function &)> &fill_input, + const std::function &)> &read_output) { bool first_device = true; bool success = true; diff --git a/intern/cycles/integrator/shader_eval.h b/intern/cycles/integrator/shader_eval.h index 859ec1d8bf6..d18d25eb60f 100644 --- a/intern/cycles/integrator/shader_eval.h +++ b/intern/cycles/integrator/shader_eval.h @@ -4,12 +4,12 @@ #pragma once +#include + #include "device/memory.h" #include "kernel/types.h" -#include "util/function.h" - CCL_NAMESPACE_BEGIN class Device; @@ -31,8 +31,8 @@ class ShaderEval { bool eval(const ShaderEvalType type, const int max_num_inputs, const int num_channels, - const function &)> &fill_input, - const function &)> &read_output); + const std::function &)> &fill_input, + const std::function &)> &read_output); protected: bool eval_cpu(Device *device, diff --git a/intern/cycles/scene/camera.cpp b/intern/cycles/scene/camera.cpp index ab9d423b14d..3001779ebba 100644 --- a/intern/cycles/scene/camera.cpp +++ b/intern/cycles/scene/camera.cpp @@ -12,7 +12,6 @@ #include "device/device.h" #include "util/foreach.h" -#include "util/function.h" #include "util/log.h" #include "util/math_cdf.h" #include "util/task.h" @@ -506,12 +505,13 @@ void Camera::device_update(Device * /*device*/, DeviceScene *dscene, Scene *scen scene->lookup_tables->remove_table(&shutter_table_offset); if (kernel_camera.shuttertime != -1.0f) { vector shutter_table; - util_cdf_inverted(SHUTTER_TABLE_SIZE, - 0.0f, - 1.0f, - function_bind(shutter_curve_eval, _1, shutter_curve), - false, - shutter_table); + util_cdf_inverted( + SHUTTER_TABLE_SIZE, + 0.0f, + 1.0f, + [this](float x) { return shutter_curve_eval(x, shutter_curve); }, + false, + shutter_table); shutter_table_offset = scene->lookup_tables->add_table(dscene, shutter_table); kernel_camera.shutter_table_offset = (int)shutter_table_offset; } diff --git a/intern/cycles/scene/film.cpp b/intern/cycles/scene/film.cpp index caa930e5850..f84a5cccbf8 100644 --- a/intern/cycles/scene/film.cpp +++ b/intern/cycles/scene/film.cpp @@ -73,12 +73,13 @@ static vector filter_table(FilterType type, float width) * consider either making FILTER_TABLE_SIZE odd value or sample full filter. */ - util_cdf_inverted(FILTER_TABLE_SIZE, - 0.0f, - width * 0.5f, - function_bind(filter_func, _1, width), - true, - filter_table); + util_cdf_inverted( + FILTER_TABLE_SIZE, + 0.0f, + width * 0.5f, + [filter_func, width](float x) { return filter_func(x, width); }, + true, + filter_table); return filter_table; } diff --git a/intern/cycles/scene/geometry.cpp b/intern/cycles/scene/geometry.cpp index f4e28873afe..17b9edfd1b4 100644 --- a/intern/cycles/scene/geometry.cpp +++ b/intern/cycles/scene/geometry.cpp @@ -665,8 +665,9 @@ void GeometryManager::device_update_displacement_images(Device *device, #endif foreach (int slot, bump_images) { - pool.push(function_bind( - &ImageManager::device_update_slot, image_manager, device, scene, slot, &progress)); + pool.push([image_manager, device, scene, slot, &progress] { + image_manager->device_update_slot(device, scene, slot, progress); + }); } pool.wait_work(); } @@ -701,8 +702,9 @@ void GeometryManager::device_update_volume_images(Device *device, Scene *scene, } foreach (int slot, volume_images) { - pool.push(function_bind( - &ImageManager::device_update_slot, image_manager, device, scene, slot, &progress)); + pool.push([image_manager, device, scene, slot, &progress] { + image_manager->device_update_slot(device, scene, slot, progress); + }); } pool.wait_work(); } @@ -954,8 +956,9 @@ void GeometryManager::device_update(Device *device, foreach (Geometry *geom, scene->geometry) { if (geom->is_modified() || geom->need_update_bvh_for_offset) { need_update_scene_bvh = true; - pool.push(function_bind( - &Geometry::compute_bvh, geom, device, dscene, &scene->params, &progress, i, num_bvh)); + pool.push([geom, device, dscene, scene, &progress, i, num_bvh] { + geom->compute_bvh(device, dscene, &scene->params, &progress, i, num_bvh); + }); if (geom->need_build_bvh(bvh_layout)) { i++; } diff --git a/intern/cycles/scene/hair.cpp b/intern/cycles/scene/hair.cpp index fe98f6dcca5..e1b2fe3408c 100644 --- a/intern/cycles/scene/hair.cpp +++ b/intern/cycles/scene/hair.cpp @@ -628,11 +628,16 @@ bool Hair::update_shadow_transparency(Device *device, Scene *scene, Progress &pr /* Evaluate shader on device. */ ShaderEval shader_eval(device, progress); bool is_fully_opaque = false; - shader_eval.eval(SHADER_EVAL_CURVE_SHADOW_TRANSPARENCY, - num_keys(), - 1, - function_bind(&fill_shader_input, this, object_index, _1), - function_bind(&read_shader_output, attr_data, is_fully_opaque, _1)); + shader_eval.eval( + SHADER_EVAL_CURVE_SHADOW_TRANSPARENCY, + num_keys(), + 1, + [this, object_index](device_vector &d_input) { + return fill_shader_input(this, object_index, d_input); + }, + [attr_data, &is_fully_opaque](const device_vector &d_output) { + read_shader_output(attr_data, is_fully_opaque, d_output); + }); if (is_fully_opaque) { attributes.remove(attr); diff --git a/intern/cycles/scene/image.cpp b/intern/cycles/scene/image.cpp index 1f4d129950d..f563f44dfb2 100644 --- a/intern/cycles/scene/image.cpp +++ b/intern/cycles/scene/image.cpp @@ -675,15 +675,15 @@ bool ImageManager::file_load_image(Image *img, int texture_limit) return true; } -void ImageManager::device_load_image(Device *device, Scene *scene, size_t slot, Progress *progress) +void ImageManager::device_load_image(Device *device, Scene *scene, size_t slot, Progress &progress) { - if (progress->get_cancel()) { + if (progress.get_cancel()) { return; } Image *img = images[slot]; - progress->set_status("Updating Images", "Loading " + img->loader->name()); + progress.set_status("Updating Images", "Loading " + img->loader->name()); const int texture_limit = scene->params.texture_limit; @@ -858,8 +858,9 @@ void ImageManager::device_update(Device *device, Scene *scene, Progress &progres device_free_image(device, slot); } else if (img && img->need_load) { - pool.push( - function_bind(&ImageManager::device_load_image, this, device, scene, slot, &progress)); + pool.push([this, device, scene, slot, &progress] { + device_load_image(device, scene, slot, progress); + }); } } @@ -871,7 +872,7 @@ void ImageManager::device_update(Device *device, Scene *scene, Progress &progres void ImageManager::device_update_slot(Device *device, Scene *scene, size_t slot, - Progress *progress) + Progress &progress) { Image *img = images[slot]; assert(img != NULL); @@ -896,8 +897,9 @@ void ImageManager::device_load_builtin(Device *device, Scene *scene, Progress &p for (size_t slot = 0; slot < images.size(); slot++) { Image *img = images[slot]; if (img && img->need_load && img->builtin) { - pool.push( - function_bind(&ImageManager::device_load_image, this, device, scene, slot, &progress)); + pool.push([this, device, scene, slot, &progress] { + device_load_image(device, scene, slot, progress); + }); } } diff --git a/intern/cycles/scene/image.h b/intern/cycles/scene/image.h index ee919aaa769..b43a6eaf725 100644 --- a/intern/cycles/scene/image.h +++ b/intern/cycles/scene/image.h @@ -180,7 +180,7 @@ class ImageManager { ImageHandle add_image(const vector &loaders, const ImageParams ¶ms); void device_update(Device *device, Scene *scene, Progress &progress); - void device_update_slot(Device *device, Scene *scene, size_t slot, Progress *progress); + void device_update_slot(Device *device, Scene *scene, size_t slot, Progress &progress); void device_free(Device *device); void device_load_builtin(Device *device, Scene *scene, Progress &progress); @@ -233,7 +233,7 @@ class ImageManager { template bool file_load_image(Image *img, int texture_limit); - void device_load_image(Device *device, Scene *scene, size_t slot, Progress *progress); + void device_load_image(Device *device, Scene *scene, size_t slot, Progress &progress); void device_free_image(Device *device, size_t slot); friend class ImageHandle; diff --git a/intern/cycles/scene/integrator.cpp b/intern/cycles/scene/integrator.cpp index 8825d4bf90b..98bf7e90182 100644 --- a/intern/cycles/scene/integrator.cpp +++ b/intern/cycles/scene/integrator.cpp @@ -323,7 +323,9 @@ void Integrator::device_update(Device *device, DeviceScene *dscene, Scene *scene TaskPool pool; for (int j = 0; j < NUM_TAB_SOBOL_PATTERNS; ++j) { float4 *sequence = directions + j * sequence_size; - pool.push(function_bind(&tabulated_sobol_generate_4D, sequence, sequence_size, j)); + pool.push([sequence, sequence_size, j] { + tabulated_sobol_generate_4D(sequence, sequence_size, j); + }); } pool.wait_work(); diff --git a/intern/cycles/scene/mesh_displace.cpp b/intern/cycles/scene/mesh_displace.cpp index 324cd9ef887..0707b030f10 100644 --- a/intern/cycles/scene/mesh_displace.cpp +++ b/intern/cycles/scene/mesh_displace.cpp @@ -182,11 +182,16 @@ bool GeometryManager::displace(Device *device, Scene *scene, Mesh *mesh, Progres /* Evaluate shader on device. */ ShaderEval shader_eval(device, progress); - if (!shader_eval.eval(SHADER_EVAL_DISPLACE, - num_verts, - 3, - function_bind(&fill_shader_input, scene, mesh, object_index, _1), - function_bind(&read_shader_output, scene, mesh, _1))) + if (!shader_eval.eval( + SHADER_EVAL_DISPLACE, + num_verts, + 3, + [scene, mesh, object_index](device_vector &d_input) { + return fill_shader_input(scene, mesh, object_index, d_input); + }, + [scene, mesh](const device_vector &d_output) { + read_shader_output(scene, mesh, d_output); + })) { return false; } diff --git a/intern/cycles/scene/osl.cpp b/intern/cycles/scene/osl.cpp index 726943012e1..5fa61c9225f 100644 --- a/intern/cycles/scene/osl.cpp +++ b/intern/cycles/scene/osl.cpp @@ -130,7 +130,7 @@ void OSLShaderManager::device_update_specific(Device *device, compiler.compile(shader); }; - task_pool.push(function_bind(&Device::foreach_device, device, compile)); + task_pool.push([device, compile] { device->foreach_device(compile); }); } task_pool.wait_work(); diff --git a/intern/cycles/scene/svm.cpp b/intern/cycles/scene/svm.cpp index 88855c503c3..5243a0b8f79 100644 --- a/intern/cycles/scene/svm.cpp +++ b/intern/cycles/scene/svm.cpp @@ -31,10 +31,10 @@ void SVMShaderManager::reset(Scene * /*scene*/) {} void SVMShaderManager::device_update_shader(Scene *scene, Shader *shader, - Progress *progress, + Progress &progress, array *svm_nodes) { - if (progress->get_cancel()) { + if (progress.get_cancel()) { return; } assert(shader->graph); @@ -77,12 +77,9 @@ void SVMShaderManager::device_update_specific(Device *device, TaskPool task_pool; vector> shader_svm_nodes(num_shaders); for (int i = 0; i < num_shaders; i++) { - task_pool.push(function_bind(&SVMShaderManager::device_update_shader, - this, - scene, - scene->shaders[i], - &progress, - &shader_svm_nodes[i])); + task_pool.push([this, scene, &progress, &shader_svm_nodes, i] { + device_update_shader(scene, scene->shaders[i], progress, &shader_svm_nodes[i]); + }); } task_pool.wait_work(); diff --git a/intern/cycles/scene/svm.h b/intern/cycles/scene/svm.h index 986018a59ad..887e0e0c689 100644 --- a/intern/cycles/scene/svm.h +++ b/intern/cycles/scene/svm.h @@ -43,7 +43,7 @@ class SVMShaderManager : public ShaderManager { protected: void device_update_shader(Scene *scene, Shader *shader, - Progress *progress, + Progress &progress, array *svm_nodes); }; diff --git a/intern/cycles/session/session.cpp b/intern/cycles/session/session.cpp index f49d98dd9c8..422159a7bcf 100644 --- a/intern/cycles/session/session.cpp +++ b/intern/cycles/session/session.cpp @@ -24,7 +24,6 @@ #include "session/session.h" #include "util/foreach.h" -#include "util/function.h" #include "util/log.h" #include "util/math.h" #include "util/task.h" @@ -75,7 +74,7 @@ Session::Session(const SessionParams ¶ms_, const SceneParams &scene_params) }; /* Create session thread. */ - session_thread_ = new thread(function_bind(&Session::thread_run, this)); + session_thread_ = new thread([this] { thread_run(); }); } Session::~Session() diff --git a/intern/cycles/session/session.h b/intern/cycles/session/session.h index 2b53521d788..d975a8f741e 100644 --- a/intern/cycles/session/session.h +++ b/intern/cycles/session/session.h @@ -5,6 +5,8 @@ #ifndef __SESSION_H__ #define __SESSION_H__ +#include + #include "device/device.h" #include "integrator/render_scheduler.h" #include "scene/shader.h" @@ -119,7 +121,7 @@ class Session { /* Callback is invoked by tile manager whenever on-dist tiles storage file is closed after * writing. Allows an engine integration to keep track of those files without worry about * transferring the information when it needs to re-create session during rendering. */ - function full_buffer_written_cb; + std::function full_buffer_written_cb; explicit Session(const SessionParams ¶ms, const SceneParams &scene_params); ~Session(); diff --git a/intern/cycles/session/tile.h b/intern/cycles/session/tile.h index 2193c4c98d8..a5015a09ab7 100644 --- a/intern/cycles/session/tile.h +++ b/intern/cycles/session/tile.h @@ -4,7 +4,10 @@ #pragma once +#include + #include "session/buffers.h" + #include "util/image.h" #include "util/string.h" #include "util/unique_ptr.h" @@ -36,7 +39,7 @@ class Tile { class TileManager { public: /* This callback is invoked by whenever on-dist tiles storage file is closed after writing. */ - function full_buffer_written_cb; + std::function full_buffer_written_cb; TileManager(); ~TileManager(); diff --git a/intern/cycles/test/util_task_test.cpp b/intern/cycles/test/util_task_test.cpp index 8e75f21b3ee..1bc6021738a 100644 --- a/intern/cycles/test/util_task_test.cpp +++ b/intern/cycles/test/util_task_test.cpp @@ -19,7 +19,7 @@ TEST(util_task, basic) TaskScheduler::init(0); TaskPool pool; for (int i = 0; i < 100; ++i) { - pool.push(function_bind(task_run)); + pool.push([] { return task_run(); }); } TaskPool::Summary summary; pool.wait_work(&summary); @@ -33,7 +33,7 @@ TEST(util_task, multiple_times) TaskScheduler::init(0); TaskPool pool; for (int i = 0; i < 100; ++i) { - pool.push(function_bind(task_run)); + pool.push([] { return task_run(); }); } TaskPool::Summary summary; pool.wait_work(&summary); diff --git a/intern/cycles/util/CMakeLists.txt b/intern/cycles/util/CMakeLists.txt index 259552c6b4e..c7288b078f9 100644 --- a/intern/cycles/util/CMakeLists.txt +++ b/intern/cycles/util/CMakeLists.txt @@ -49,7 +49,6 @@ set(SRC_HEADERS disjoint_set.h guarded_allocator.cpp foreach.h - function.h guarded_allocator.h guiding.h half.h diff --git a/intern/cycles/util/function.h b/intern/cycles/util/function.h deleted file mode 100644 index ef41d80c1e1..00000000000 --- a/intern/cycles/util/function.h +++ /dev/null @@ -1,27 +0,0 @@ -/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation - * - * SPDX-License-Identifier: Apache-2.0 */ - -#ifndef __UTIL_FUNCTION_H__ -#define __UTIL_FUNCTION_H__ - -#include - -CCL_NAMESPACE_BEGIN - -#define function_bind std::bind -#define function_null nullptr -using std::function; -using std::placeholders::_1; -using std::placeholders::_2; -using std::placeholders::_3; -using std::placeholders::_4; -using std::placeholders::_5; -using std::placeholders::_6; -using std::placeholders::_7; -using std::placeholders::_8; -using std::placeholders::_9; - -CCL_NAMESPACE_END - -#endif /* __UTIL_FUNCTION_H__ */ diff --git a/intern/cycles/util/profiling.cpp b/intern/cycles/util/profiling.cpp index 54be0fcd1d1..0834095c4ce 100644 --- a/intern/cycles/util/profiling.cpp +++ b/intern/cycles/util/profiling.cpp @@ -76,7 +76,7 @@ void Profiler::start() { assert(worker == NULL); do_stop_worker = false; - worker = new thread(function_bind(&Profiler::run, this)); + worker = new thread([this] { run(); }); } void Profiler::stop() diff --git a/intern/cycles/util/progress.h b/intern/cycles/util/progress.h index b956434fe06..c9ed1fd39f6 100644 --- a/intern/cycles/util/progress.h +++ b/intern/cycles/util/progress.h @@ -5,13 +5,14 @@ #ifndef __UTIL_PROGRESS_H__ #define __UTIL_PROGRESS_H__ +#include + /* Progress * * Simple class to communicate progress status messages, timing information, * update notifications from a job running in another thread. All methods * except for the constructor/destructor are thread safe. */ -#include "util/function.h" #include "util/string.h" #include "util/thread.h" #include "util/time.h" @@ -35,12 +36,12 @@ class Progress { substatus = ""; sync_status = ""; sync_substatus = ""; - update_cb = function_null; + update_cb = nullptr; cancel = false; cancel_message = ""; error = false; error_message = ""; - cancel_cb = function_null; + cancel_cb = nullptr; } Progress(Progress &progress) @@ -104,7 +105,7 @@ class Progress { return cancel_message; } - void set_cancel_callback(function function) + void set_cancel_callback(std::function function) { cancel_cb = function; } @@ -326,7 +327,7 @@ class Progress { } } - void set_update_callback(function function) + void set_update_callback(std::function function) { update_cb = function; } @@ -334,8 +335,8 @@ class Progress { protected: mutable thread_mutex progress_mutex; mutable thread_mutex update_mutex; - function update_cb; - function cancel_cb; + std::function update_cb = nullptr; + std::function cancel_cb = nullptr; /* pixel_samples counts how many samples have been rendered over all pixel, not just per pixel. * This makes the progress estimate more accurate when tiles with different sizes are used. diff --git a/intern/cycles/util/task.cpp b/intern/cycles/util/task.cpp index 9d2247631ba..1af0796632c 100644 --- a/intern/cycles/util/task.cpp +++ b/intern/cycles/util/task.cpp @@ -109,7 +109,7 @@ DedicatedTaskPool::DedicatedTaskPool() do_exit = false; num = 0; - worker_thread = new thread(function_bind(&DedicatedTaskPool::thread_run, this)); + worker_thread = new thread([this] { thread_run(); }); } DedicatedTaskPool::~DedicatedTaskPool() diff --git a/intern/cycles/util/task.h b/intern/cycles/util/task.h index 7db0c9fe601..4506eac606c 100644 --- a/intern/cycles/util/task.h +++ b/intern/cycles/util/task.h @@ -16,7 +16,7 @@ CCL_NAMESPACE_BEGIN class TaskPool; class TaskScheduler; -typedef function TaskRunFunction; +using TaskRunFunction = std::function; /* Task Pool * @@ -93,8 +93,7 @@ class TaskScheduler { * * Like a TaskPool, but will launch one dedicated thread to execute all tasks. * - * The run callback that actually executes the task may be created like this: - * function_bind(&MyClass::task_execute, this, _1, _2) */ + * The run callback can be a lambda without arguments. */ class DedicatedTaskPool { public: diff --git a/intern/cycles/util/thread.cpp b/intern/cycles/util/thread.cpp index 1fd52186550..1eda6620744 100644 --- a/intern/cycles/util/thread.cpp +++ b/intern/cycles/util/thread.cpp @@ -11,7 +11,7 @@ CCL_NAMESPACE_BEGIN -thread::thread(function run_cb) : run_cb_(run_cb), joined_(false) +thread::thread(std::function run_cb) : run_cb_(run_cb), joined_(false) { #if defined(__APPLE__) || defined(__linux__) && !defined(__GLIBC__) /* Set the stack size to 2MB to match GLIBC. The default 512KB on macOS is diff --git a/intern/cycles/util/thread.h b/intern/cycles/util/thread.h index 1a32a13610a..5b744eec0c1 100644 --- a/intern/cycles/util/thread.h +++ b/intern/cycles/util/thread.h @@ -21,8 +21,6 @@ * functionality requires RTTI, which is disabled for OSL kernel. */ #include -#include "util/function.h" - CCL_NAMESPACE_BEGIN typedef std::mutex thread_mutex; @@ -35,14 +33,14 @@ typedef std::condition_variable thread_condition_variable; */ class thread { public: - thread(function run_cb); + thread(std::function run_cb); ~thread(); static void *run(void *arg); bool join(); protected: - function run_cb_; + std::function run_cb_; #if defined(__APPLE__) || defined(__linux__) && !defined(__GLIBC__) pthread_t pthread_id; #else diff --git a/intern/cycles/util/time.h b/intern/cycles/util/time.h index e2316a9ce40..c712a117ae6 100644 --- a/intern/cycles/util/time.h +++ b/intern/cycles/util/time.h @@ -5,7 +5,8 @@ #ifndef __UTIL_TIME_H__ #define __UTIL_TIME_H__ -#include "util/function.h" +#include + #include "util/string.h" CCL_NAMESPACE_BEGIN @@ -51,7 +52,7 @@ class scoped_timer { class scoped_callback_timer { public: - using callback_type = function; + using callback_type = std::function; explicit scoped_callback_timer(callback_type cb) : cb(cb) {}