Refactor: Cycles: Replace std::bind by lambdas
Pull Request: https://projects.blender.org/blender/blender/pulls/132361
This commit is contained in:
@@ -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 */
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0 */
|
||||
|
||||
#include <functional>
|
||||
|
||||
#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<void(const string &)> LogFunction;
|
||||
using LogFunction = std::function<void(const string &)>;
|
||||
|
||||
OIIOOutputDriver(const string_view filepath, const string_view pass, LogFunction log);
|
||||
virtual ~OIIOOutputDriver();
|
||||
|
||||
@@ -17,8 +17,8 @@ CCL_NAMESPACE_BEGIN
|
||||
* OpenGLDisplayDriver.
|
||||
*/
|
||||
|
||||
OpenGLDisplayDriver::OpenGLDisplayDriver(const function<bool()> &gl_context_enable,
|
||||
const function<void()> &gl_context_disable)
|
||||
OpenGLDisplayDriver::OpenGLDisplayDriver(const std::function<bool()> &gl_context_enable,
|
||||
const std::function<void()> &gl_context_disable)
|
||||
: gl_context_enable_(gl_context_enable), gl_context_disable_(gl_context_disable)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -5,12 +5,12 @@
|
||||
#pragma once
|
||||
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
|
||||
#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<bool()> &gl_context_enable,
|
||||
const function<void()> &gl_context_disable);
|
||||
OpenGLDisplayDriver(const std::function<bool()> &gl_context_enable,
|
||||
const std::function<void()> &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<bool()> gl_context_enable_ = nullptr;
|
||||
function<void()> gl_context_disable_ = nullptr;
|
||||
std::function<bool()> gl_context_enable_ = nullptr;
|
||||
std::function<void()> gl_context_disable_ = nullptr;
|
||||
};
|
||||
|
||||
CCL_NAMESPACE_END
|
||||
|
||||
@@ -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. */
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
#ifndef __DEVICE_H__
|
||||
#define __DEVICE_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
|
||||
#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<void(Device *)> &callback)
|
||||
virtual void foreach_device(const std::function<void(Device *)> &callback)
|
||||
{
|
||||
callback(this);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
#include "device/multi/device.h"
|
||||
|
||||
#include <sstream>
|
||||
#include <stdlib.h>
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
|
||||
#include "bvh/multi.h"
|
||||
|
||||
@@ -459,7 +459,7 @@ class MultiDevice : public Device {
|
||||
return -1;
|
||||
}
|
||||
|
||||
virtual void foreach_device(const function<void(Device *)> &callback) override
|
||||
void foreach_device(const std::function<void(Device *)> &callback) override
|
||||
{
|
||||
foreach (SubDevice &sub, devices) {
|
||||
sub.device->foreach_device(callback);
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 <functional>
|
||||
|
||||
#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<bool(void)> is_cancelled_cb;
|
||||
std::function<bool(void)> is_cancelled_cb;
|
||||
|
||||
bool is_cancelled() const
|
||||
{
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#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<void(void)> progress_update_cb;
|
||||
std::function<void(void)> progress_update_cb;
|
||||
|
||||
protected:
|
||||
/* Actual implementation of the rendering pipeline.
|
||||
|
||||
@@ -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<int(device_vector<KernelShaderEvalInput> &)> &fill_input,
|
||||
const function<void(device_vector<float> &)> &read_output)
|
||||
const std::function<int(device_vector<KernelShaderEvalInput> &)> &fill_input,
|
||||
const std::function<void(device_vector<float> &)> &read_output)
|
||||
{
|
||||
bool first_device = true;
|
||||
bool success = true;
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#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<int(device_vector<KernelShaderEvalInput> &)> &fill_input,
|
||||
const function<void(device_vector<float> &)> &read_output);
|
||||
const std::function<int(device_vector<KernelShaderEvalInput> &)> &fill_input,
|
||||
const std::function<void(device_vector<float> &)> &read_output);
|
||||
|
||||
protected:
|
||||
bool eval_cpu(Device *device,
|
||||
|
||||
@@ -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<float> 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;
|
||||
}
|
||||
|
||||
@@ -73,12 +73,13 @@ static vector<float> 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;
|
||||
}
|
||||
|
||||
@@ -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++;
|
||||
}
|
||||
|
||||
@@ -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<KernelShaderEvalInput> &d_input) {
|
||||
return fill_shader_input(this, object_index, d_input);
|
||||
},
|
||||
[attr_data, &is_fully_opaque](const device_vector<float> &d_output) {
|
||||
read_shader_output(attr_data, is_fully_opaque, d_output);
|
||||
});
|
||||
|
||||
if (is_fully_opaque) {
|
||||
attributes.remove(attr);
|
||||
|
||||
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -180,7 +180,7 @@ class ImageManager {
|
||||
ImageHandle add_image(const vector<ImageLoader *> &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<TypeDesc::BASETYPE FileFormat, typename StorageType>
|
||||
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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -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<KernelShaderEvalInput> &d_input) {
|
||||
return fill_shader_input(scene, mesh, object_index, d_input);
|
||||
},
|
||||
[scene, mesh](const device_vector<float> &d_output) {
|
||||
read_shader_output(scene, mesh, d_output);
|
||||
}))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
|
||||
@@ -31,10 +31,10 @@ void SVMShaderManager::reset(Scene * /*scene*/) {}
|
||||
|
||||
void SVMShaderManager::device_update_shader(Scene *scene,
|
||||
Shader *shader,
|
||||
Progress *progress,
|
||||
Progress &progress,
|
||||
array<int4> *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<array<int4>> 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();
|
||||
|
||||
|
||||
@@ -43,7 +43,7 @@ class SVMShaderManager : public ShaderManager {
|
||||
protected:
|
||||
void device_update_shader(Scene *scene,
|
||||
Shader *shader,
|
||||
Progress *progress,
|
||||
Progress &progress,
|
||||
array<int4> *svm_nodes);
|
||||
};
|
||||
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#ifndef __SESSION_H__
|
||||
#define __SESSION_H__
|
||||
|
||||
#include <functional>
|
||||
|
||||
#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<void(string_view)> full_buffer_written_cb;
|
||||
std::function<void(string_view)> full_buffer_written_cb;
|
||||
|
||||
explicit Session(const SessionParams ¶ms, const SceneParams &scene_params);
|
||||
~Session();
|
||||
|
||||
@@ -4,7 +4,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <functional>
|
||||
|
||||
#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<void(string_view)> full_buffer_written_cb;
|
||||
std::function<void(string_view)> full_buffer_written_cb;
|
||||
|
||||
TileManager();
|
||||
~TileManager();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -49,7 +49,6 @@ set(SRC_HEADERS
|
||||
disjoint_set.h
|
||||
guarded_allocator.cpp
|
||||
foreach.h
|
||||
function.h
|
||||
guarded_allocator.h
|
||||
guiding.h
|
||||
half.h
|
||||
|
||||
@@ -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 <functional>
|
||||
|
||||
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__ */
|
||||
@@ -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()
|
||||
|
||||
@@ -5,13 +5,14 @@
|
||||
#ifndef __UTIL_PROGRESS_H__
|
||||
#define __UTIL_PROGRESS_H__
|
||||
|
||||
#include <functional>
|
||||
|
||||
/* 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<void()> function)
|
||||
void set_cancel_callback(std::function<void()> function)
|
||||
{
|
||||
cancel_cb = function;
|
||||
}
|
||||
@@ -326,7 +327,7 @@ class Progress {
|
||||
}
|
||||
}
|
||||
|
||||
void set_update_callback(function<void()> function)
|
||||
void set_update_callback(std::function<void()> function)
|
||||
{
|
||||
update_cb = function;
|
||||
}
|
||||
@@ -334,8 +335,8 @@ class Progress {
|
||||
protected:
|
||||
mutable thread_mutex progress_mutex;
|
||||
mutable thread_mutex update_mutex;
|
||||
function<void()> update_cb;
|
||||
function<void()> cancel_cb;
|
||||
std::function<void()> update_cb = nullptr;
|
||||
std::function<void()> 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.
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -16,7 +16,7 @@ CCL_NAMESPACE_BEGIN
|
||||
class TaskPool;
|
||||
class TaskScheduler;
|
||||
|
||||
typedef function<void(void)> TaskRunFunction;
|
||||
using TaskRunFunction = std::function<void()>;
|
||||
|
||||
/* 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:
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
|
||||
thread::thread(function<void()> run_cb) : run_cb_(run_cb), joined_(false)
|
||||
thread::thread(std::function<void()> 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
|
||||
|
||||
@@ -21,8 +21,6 @@
|
||||
* functionality requires RTTI, which is disabled for OSL kernel. */
|
||||
#include <tbb/spin_mutex.h>
|
||||
|
||||
#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<void()> run_cb);
|
||||
thread(std::function<void()> run_cb);
|
||||
~thread();
|
||||
|
||||
static void *run(void *arg);
|
||||
bool join();
|
||||
|
||||
protected:
|
||||
function<void()> run_cb_;
|
||||
std::function<void()> run_cb_;
|
||||
#if defined(__APPLE__) || defined(__linux__) && !defined(__GLIBC__)
|
||||
pthread_t pthread_id;
|
||||
#else
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
#ifndef __UTIL_TIME_H__
|
||||
#define __UTIL_TIME_H__
|
||||
|
||||
#include "util/function.h"
|
||||
#include <functional>
|
||||
|
||||
#include "util/string.h"
|
||||
|
||||
CCL_NAMESPACE_BEGIN
|
||||
@@ -51,7 +52,7 @@ class scoped_timer {
|
||||
|
||||
class scoped_callback_timer {
|
||||
public:
|
||||
using callback_type = function<void(double)>;
|
||||
using callback_type = std::function<void(double)>;
|
||||
|
||||
explicit scoped_callback_timer(callback_type cb) : cb(cb) {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user