2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 02:50:24 +01:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
2014-01-02 19:05:07 -02:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
2019-05-02 15:45:31 +02:00
|
|
|
#include "device/device.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "render/background.h"
|
|
|
|
|
#include "render/buffers.h"
|
|
|
|
|
#include "render/camera.h"
|
2019-05-02 15:45:31 +02:00
|
|
|
#include "render/colorspace.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "render/film.h"
|
2019-05-02 15:45:31 +02:00
|
|
|
#include "render/integrator.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "render/light.h"
|
|
|
|
|
#include "render/mesh.h"
|
|
|
|
|
#include "render/object.h"
|
|
|
|
|
#include "render/scene.h"
|
|
|
|
|
#include "render/session.h"
|
|
|
|
|
#include "render/shader.h"
|
2018-07-27 15:46:13 +02:00
|
|
|
#include "render/stats.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2019-01-29 18:08:12 +01:00
|
|
|
#include "util/util_algorithm.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "util/util_color.h"
|
|
|
|
|
#include "util/util_foreach.h"
|
|
|
|
|
#include "util/util_function.h"
|
|
|
|
|
#include "util/util_hash.h"
|
|
|
|
|
#include "util/util_logging.h"
|
2018-11-07 04:05:47 +01:00
|
|
|
#include "util/util_murmurhash.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "util/util_progress.h"
|
|
|
|
|
#include "util/util_time.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "blender/blender_session.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "blender/blender_sync.h"
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "blender/blender_util.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2020-10-02 00:48:01 +02:00
|
|
|
DeviceTypeMask BlenderSession::device_override = DEVICE_MASK_ALL;
|
2015-02-18 21:16:52 +05:00
|
|
|
bool BlenderSession::headless = false;
|
2016-03-30 15:55:12 +02:00
|
|
|
int BlenderSession::num_resumable_chunks = 0;
|
|
|
|
|
int BlenderSession::current_resumable_chunk = 0;
|
2017-03-15 15:52:27 +01:00
|
|
|
int BlenderSession::start_resumable_chunk = 0;
|
|
|
|
|
int BlenderSession::end_resumable_chunk = 0;
|
2018-07-27 15:46:13 +02:00
|
|
|
bool BlenderSession::print_render_stats = false;
|
2015-02-18 21:16:52 +05:00
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
BlenderSession::BlenderSession(BL::RenderEngine &b_engine,
|
2018-12-21 12:47:44 +11:00
|
|
|
BL::Preferences &b_userpref,
|
2016-01-30 14:18:29 +01:00
|
|
|
BL::BlendData &b_data,
|
2018-05-23 12:13:21 +02:00
|
|
|
bool preview_osl)
|
|
|
|
|
: session(NULL),
|
2020-08-06 18:34:41 +02:00
|
|
|
scene(NULL),
|
2018-06-25 17:01:24 +02:00
|
|
|
sync(NULL),
|
2018-05-23 12:13:21 +02:00
|
|
|
b_engine(b_engine),
|
2016-01-30 14:18:29 +01:00
|
|
|
b_userpref(b_userpref),
|
|
|
|
|
b_data(b_data),
|
|
|
|
|
b_render(b_engine.render()),
|
2018-04-21 19:35:12 +02:00
|
|
|
b_depsgraph(PointerRNA_NULL),
|
2018-05-23 12:13:21 +02:00
|
|
|
b_scene(PointerRNA_NULL),
|
2016-01-30 14:18:29 +01:00
|
|
|
b_v3d(PointerRNA_NULL),
|
|
|
|
|
b_rv3d(PointerRNA_NULL),
|
2018-05-23 12:13:21 +02:00
|
|
|
width(0),
|
|
|
|
|
height(0),
|
|
|
|
|
preview_osl(preview_osl),
|
2016-01-30 14:18:29 +01:00
|
|
|
python_thread_state(NULL)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
|
/* offline render */
|
|
|
|
|
background = true;
|
2013-04-24 20:12:12 +00:00
|
|
|
last_redraw_time = 0.0;
|
|
|
|
|
start_resize_time = 0.0;
|
2017-01-19 00:41:55 +01:00
|
|
|
last_status_time = 0.0;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
BlenderSession::BlenderSession(BL::RenderEngine &b_engine,
|
2018-12-21 12:47:44 +11:00
|
|
|
BL::Preferences &b_userpref,
|
2016-01-30 14:18:29 +01:00
|
|
|
BL::BlendData &b_data,
|
|
|
|
|
BL::SpaceView3D &b_v3d,
|
|
|
|
|
BL::RegionView3D &b_rv3d,
|
|
|
|
|
int width,
|
|
|
|
|
int height)
|
2018-05-23 12:13:21 +02:00
|
|
|
: session(NULL),
|
2020-08-06 18:34:41 +02:00
|
|
|
scene(NULL),
|
2018-06-25 17:01:24 +02:00
|
|
|
sync(NULL),
|
2018-05-23 12:13:21 +02:00
|
|
|
b_engine(b_engine),
|
2016-01-30 14:18:29 +01:00
|
|
|
b_userpref(b_userpref),
|
|
|
|
|
b_data(b_data),
|
2018-05-23 12:13:21 +02:00
|
|
|
b_render(b_engine.render()),
|
2018-04-21 19:35:12 +02:00
|
|
|
b_depsgraph(PointerRNA_NULL),
|
2018-05-23 12:13:21 +02:00
|
|
|
b_scene(PointerRNA_NULL),
|
2016-01-30 14:18:29 +01:00
|
|
|
b_v3d(b_v3d),
|
|
|
|
|
b_rv3d(b_rv3d),
|
|
|
|
|
width(width),
|
|
|
|
|
height(height),
|
2018-05-23 12:13:21 +02:00
|
|
|
preview_osl(false),
|
2016-01-30 14:18:29 +01:00
|
|
|
python_thread_state(NULL)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
|
/* 3d view render */
|
|
|
|
|
background = false;
|
2013-04-24 20:12:12 +00:00
|
|
|
last_redraw_time = 0.0;
|
|
|
|
|
start_resize_time = 0.0;
|
2017-01-19 00:41:55 +01:00
|
|
|
last_status_time = 0.0;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
BlenderSession::~BlenderSession()
|
|
|
|
|
{
|
|
|
|
|
free_session();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlenderSession::create_session()
|
|
|
|
|
{
|
2015-02-18 21:16:52 +05:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(
|
|
|
|
|
b_engine, b_userpref, b_scene, background);
|
2017-10-08 04:32:25 +02:00
|
|
|
SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background);
|
2014-08-01 16:39:05 +06:00
|
|
|
bool session_pause = BlenderSync::get_session_pause(b_scene, background);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-10-30 10:12:34 +00:00
|
|
|
/* reset status/progress */
|
2012-06-09 18:56:12 +00:00
|
|
|
last_status = "";
|
2014-12-05 21:27:52 +05:00
|
|
|
last_error = "";
|
2012-06-09 18:56:12 +00:00
|
|
|
last_progress = -1.0f;
|
2013-04-24 20:12:12 +00:00
|
|
|
start_resize_time = 0.0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-10-20 05:08:26 +02:00
|
|
|
/* create session */
|
|
|
|
|
session = new Session(session_params);
|
|
|
|
|
session->scene = scene;
|
|
|
|
|
session->progress.set_update_callback(function_bind(&BlenderSession::tag_redraw, this));
|
|
|
|
|
session->progress.set_cancel_callback(function_bind(&BlenderSession::test_cancel, this));
|
|
|
|
|
session->set_pause(session_pause);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* create scene */
|
2017-10-20 05:08:26 +02:00
|
|
|
scene = new Scene(scene_params, session->device);
|
2018-11-09 16:04:53 +01:00
|
|
|
scene->name = b_scene.name();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
session->scene = scene;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* create sync */
|
2018-02-26 16:46:48 +01:00
|
|
|
sync = new BlenderSync(b_engine, b_data, b_scene, scene, !background, session->progress);
|
2016-01-30 14:18:29 +01:00
|
|
|
BL::Object b_camera_override(b_engine.camera_override());
|
2013-06-09 11:57:51 +00:00
|
|
|
if (b_v3d) {
|
2018-02-26 16:46:48 +01:00
|
|
|
sync->sync_view(b_v3d, b_rv3d, width, height);
|
2013-06-09 11:57:51 +00:00
|
|
|
}
|
2013-06-11 14:15:46 +00:00
|
|
|
else {
|
2016-03-11 12:57:02 +05:00
|
|
|
sync->sync_camera(b_render, b_camera_override, width, height, "");
|
2013-06-11 14:15:46 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-12-21 20:51:55 +00:00
|
|
|
/* set buffer parameters */
|
2020-06-24 17:08:01 +02:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(
|
2021-05-31 16:21:24 +02:00
|
|
|
b_v3d, b_rv3d, scene->camera, width, height, session_params.denoising.use);
|
2011-12-20 12:25:37 +00:00
|
|
|
session->reset(buffer_params, session_params.samples);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-01 16:15:13 +00:00
|
|
|
b_engine.use_highlight_tiles(session_params.progressive_refine == false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-03-30 15:55:12 +02:00
|
|
|
update_resumable_tile_manager(session_params.samples);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2018-05-23 12:13:21 +02:00
|
|
|
void BlenderSession::reset_session(BL::BlendData &b_data, BL::Depsgraph &b_depsgraph)
|
2012-11-09 08:46:53 +00:00
|
|
|
{
|
2020-05-27 18:00:59 +02:00
|
|
|
/* Update data, scene and depsgraph pointers. These can change after undo. */
|
2018-05-23 12:13:21 +02:00
|
|
|
this->b_data = b_data;
|
|
|
|
|
this->b_depsgraph = b_depsgraph;
|
|
|
|
|
this->b_scene = b_depsgraph.scene_eval();
|
2020-05-27 18:00:59 +02:00
|
|
|
if (sync) {
|
|
|
|
|
sync->reset(this->b_data, this->b_scene);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-15 17:19:26 +01:00
|
|
|
if (preview_osl) {
|
2018-05-23 12:13:21 +02:00
|
|
|
PointerRNA cscene = RNA_pointer_get(&b_scene.ptr, "cycles");
|
|
|
|
|
RNA_boolean_set(&cscene, "shading_system", preview_osl);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-15 17:19:26 +01:00
|
|
|
if (b_v3d) {
|
2018-05-23 12:13:21 +02:00
|
|
|
this->b_render = b_scene.render();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
this->b_render = b_engine.render();
|
|
|
|
|
width = render_resolution_x(b_render);
|
|
|
|
|
height = render_resolution_y(b_render);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-08-26 17:09:26 +02:00
|
|
|
bool is_new_session = (session == NULL);
|
|
|
|
|
if (is_new_session) {
|
|
|
|
|
/* Initialize session and remember it was just created so not to
|
|
|
|
|
* re-create it below.
|
|
|
|
|
*/
|
|
|
|
|
create_session();
|
2018-05-23 12:13:21 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-15 17:19:26 +01:00
|
|
|
if (b_v3d) {
|
2018-05-23 12:13:21 +02:00
|
|
|
/* NOTE: We need to create session, but all the code from below
|
|
|
|
|
* will make viewport render to stuck on initialization.
|
|
|
|
|
*/
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-02-18 21:16:52 +05:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(
|
|
|
|
|
b_engine, b_userpref, b_scene, background);
|
2017-10-08 04:32:25 +02:00
|
|
|
SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-02-14 16:48:43 +00:00
|
|
|
if (scene->params.modified(scene_params) || session->params.modified(session_params) ||
|
Render: faster animation and re-rendering with Persistent Data
For Cycles, when enabling the Persistent Data option, the full render data
will be preserved from frame-to-frame in animation renders and between
re-renders of the scene. This means that any modifier evaluation, BVH
building, OpenGL vertex buffer uploads, etc, can be done only once for
unchanged objects. This comes at an increased memory cost.
Previously there option was named Persistent Images and had a more limited
impact on render time and memory.
When using multiple view layers, only data from a single view layer is
preserved to keep memory usage somewhat under control. However objects
shared between view layers are preserved, and so this can speedup such
renders as well, even single frame renders.
For Eevee and Workbench this option is not available, however these engines
will now always reuse the depsgraph for animation and multiple view layers.
This can significantly speed up rendering.
These engines do not support sharing the depsgraph between re-renders, due
to technical issues regarding OpenGL contexts. Support for this could be added
if those are solved, see the code comments for details.
2021-04-04 23:51:24 +02:00
|
|
|
!this->b_render.use_persistent_data()) {
|
2012-11-09 08:46:53 +00:00
|
|
|
/* if scene or session parameters changed, it's easier to simply re-create
|
|
|
|
|
* them rather than trying to distinguish which settings need to be updated
|
|
|
|
|
*/
|
2019-08-26 17:09:26 +02:00
|
|
|
if (!is_new_session) {
|
|
|
|
|
free_session();
|
|
|
|
|
create_session();
|
|
|
|
|
}
|
2012-11-09 08:46:53 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-09 08:46:53 +00:00
|
|
|
session->progress.reset();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-08 16:56:04 +00:00
|
|
|
session->tile_manager.set_tile_order(session_params.tile_order);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-11-09 08:46:53 +00:00
|
|
|
/* peak memory usage should show current render peak, not peak for all renders
|
|
|
|
|
* made by this render session
|
|
|
|
|
*/
|
|
|
|
|
session->stats.mem_peak = session->stats.mem_used;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Render: faster animation and re-rendering with Persistent Data
For Cycles, when enabling the Persistent Data option, the full render data
will be preserved from frame-to-frame in animation renders and between
re-renders of the scene. This means that any modifier evaluation, BVH
building, OpenGL vertex buffer uploads, etc, can be done only once for
unchanged objects. This comes at an increased memory cost.
Previously there option was named Persistent Images and had a more limited
impact on render time and memory.
When using multiple view layers, only data from a single view layer is
preserved to keep memory usage somewhat under control. However objects
shared between view layers are preserved, and so this can speedup such
renders as well, even single frame renders.
For Eevee and Workbench this option is not available, however these engines
will now always reuse the depsgraph for animation and multiple view layers.
This can significantly speed up rendering.
These engines do not support sharing the depsgraph between re-renders, due
to technical issues regarding OpenGL contexts. Support for this could be added
if those are solved, see the code comments for details.
2021-04-04 23:51:24 +02:00
|
|
|
if (is_new_session) {
|
|
|
|
|
/* Sync object should be re-created for new scene. */
|
|
|
|
|
delete sync;
|
|
|
|
|
sync = new BlenderSync(b_engine, b_data, b_scene, scene, !background, session->progress);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Sync recalculations to do just the required updates. */
|
|
|
|
|
sync->sync_recalc(b_depsgraph, b_v3d);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2021-05-03 20:11:34 +02:00
|
|
|
BL::Object b_camera_override(b_engine.camera_override());
|
|
|
|
|
sync->sync_camera(b_render, b_camera_override, width, height, "");
|
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
BL::SpaceView3D b_null_space_view3d(PointerRNA_NULL);
|
|
|
|
|
BL::RegionView3D b_null_region_view3d(PointerRNA_NULL);
|
2021-05-31 16:21:24 +02:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(b_null_space_view3d,
|
2020-05-31 23:49:10 +02:00
|
|
|
b_null_region_view3d,
|
|
|
|
|
scene->camera,
|
|
|
|
|
width,
|
|
|
|
|
height,
|
|
|
|
|
session_params.denoising.use);
|
2012-11-09 08:46:53 +00:00
|
|
|
session->reset(buffer_params, session_params.samples);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-01 16:15:13 +00:00
|
|
|
b_engine.use_highlight_tiles(session_params.progressive_refine == false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-24 20:12:12 +00:00
|
|
|
/* reset time */
|
|
|
|
|
start_resize_time = 0.0;
|
2012-11-09 08:46:53 +00:00
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void BlenderSession::free_session()
|
|
|
|
|
{
|
2020-11-11 18:39:46 +01:00
|
|
|
session->cancel();
|
|
|
|
|
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
delete sync;
|
2011-04-27 11:58:34 +00:00
|
|
|
delete session;
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-02 19:05:07 -02:00
|
|
|
static ShaderEvalType get_shader_type(const string &pass_type)
|
|
|
|
|
{
|
|
|
|
|
const char *shader_type = pass_type.c_str();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-01-02 19:05:07 -02:00
|
|
|
/* data passes */
|
|
|
|
|
if (strcmp(shader_type, "NORMAL") == 0)
|
|
|
|
|
return SHADER_EVAL_NORMAL;
|
|
|
|
|
else if (strcmp(shader_type, "UV") == 0)
|
|
|
|
|
return SHADER_EVAL_UV;
|
2018-03-10 18:18:05 +01:00
|
|
|
else if (strcmp(shader_type, "ROUGHNESS") == 0)
|
|
|
|
|
return SHADER_EVAL_ROUGHNESS;
|
2014-01-02 19:05:07 -02:00
|
|
|
else if (strcmp(shader_type, "DIFFUSE_COLOR") == 0)
|
|
|
|
|
return SHADER_EVAL_DIFFUSE_COLOR;
|
|
|
|
|
else if (strcmp(shader_type, "GLOSSY_COLOR") == 0)
|
|
|
|
|
return SHADER_EVAL_GLOSSY_COLOR;
|
|
|
|
|
else if (strcmp(shader_type, "TRANSMISSION_COLOR") == 0)
|
|
|
|
|
return SHADER_EVAL_TRANSMISSION_COLOR;
|
|
|
|
|
else if (strcmp(shader_type, "EMIT") == 0)
|
|
|
|
|
return SHADER_EVAL_EMISSION;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-01-02 19:05:07 -02:00
|
|
|
/* light passes */
|
|
|
|
|
else if (strcmp(shader_type, "AO") == 0)
|
|
|
|
|
return SHADER_EVAL_AO;
|
|
|
|
|
else if (strcmp(shader_type, "COMBINED") == 0)
|
|
|
|
|
return SHADER_EVAL_COMBINED;
|
|
|
|
|
else if (strcmp(shader_type, "SHADOW") == 0)
|
|
|
|
|
return SHADER_EVAL_SHADOW;
|
2016-01-15 13:00:56 -02:00
|
|
|
else if (strcmp(shader_type, "DIFFUSE") == 0)
|
|
|
|
|
return SHADER_EVAL_DIFFUSE;
|
|
|
|
|
else if (strcmp(shader_type, "GLOSSY") == 0)
|
|
|
|
|
return SHADER_EVAL_GLOSSY;
|
|
|
|
|
else if (strcmp(shader_type, "TRANSMISSION") == 0)
|
|
|
|
|
return SHADER_EVAL_TRANSMISSION;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-01-02 19:05:07 -02:00
|
|
|
/* extra */
|
|
|
|
|
else if (strcmp(shader_type, "ENVIRONMENT") == 0)
|
|
|
|
|
return SHADER_EVAL_ENVIRONMENT;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-01-02 19:05:07 -02:00
|
|
|
else
|
|
|
|
|
return SHADER_EVAL_BAKE;
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
static BL::RenderResult begin_render_result(BL::RenderEngine &b_engine,
|
|
|
|
|
int x,
|
|
|
|
|
int y,
|
|
|
|
|
int w,
|
|
|
|
|
int h,
|
|
|
|
|
const char *layername,
|
|
|
|
|
const char *viewname)
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
2015-04-06 10:40:12 -03:00
|
|
|
return b_engine.begin_result(x, y, w, h, layername, viewname);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
static void end_render_result(BL::RenderEngine &b_engine,
|
|
|
|
|
BL::RenderResult &b_rr,
|
|
|
|
|
bool cancel,
|
2017-05-07 14:40:58 +02:00
|
|
|
bool highlight,
|
2016-01-30 14:18:29 +01:00
|
|
|
bool do_merge_results)
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
2017-05-07 14:40:58 +02:00
|
|
|
b_engine.end_result(b_rr, (int)cancel, (int)highlight, (int)do_merge_results);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-07 14:40:58 +02:00
|
|
|
void BlenderSession::do_write_update_render_tile(RenderTile &rtile,
|
|
|
|
|
bool do_update_only,
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
bool do_read_only,
|
2017-05-07 14:40:58 +02:00
|
|
|
bool highlight)
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
2017-10-10 02:28:23 +02:00
|
|
|
int x = rtile.x - session->tile_manager.params.full_x;
|
|
|
|
|
int y = rtile.y - session->tile_manager.params.full_y;
|
|
|
|
|
int w = rtile.w;
|
|
|
|
|
int h = rtile.h;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* get render result */
|
2015-04-06 10:40:12 -03:00
|
|
|
BL::RenderResult b_rr = begin_render_result(
|
|
|
|
|
b_engine, x, y, w, h, b_rlay_name.c_str(), b_rview_name.c_str());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* can happen if the intersected rectangle gives 0 width or height */
|
2015-03-28 00:15:15 +05:00
|
|
|
if (b_rr.ptr.data == NULL) {
|
2012-09-04 13:29:07 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
BL::RenderResult::layers_iterator b_single_rlay;
|
|
|
|
|
b_rr.layers.begin(b_single_rlay);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-07-29 15:32:24 +00:00
|
|
|
/* layer will be missing if it was disabled in the UI */
|
|
|
|
|
if (b_single_rlay == b_rr.layers.end())
|
|
|
|
|
return;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
BL::RenderLayer b_rlay = *b_single_rlay;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
if (do_read_only) {
|
|
|
|
|
/* copy each pass */
|
2021-01-25 16:20:10 +01:00
|
|
|
for (BL::RenderPass &b_pass : b_rlay.passes) {
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
/* find matching pass type */
|
|
|
|
|
PassType pass_type = BlenderSync::get_pass_type(b_pass);
|
|
|
|
|
int components = b_pass.channels();
|
|
|
|
|
|
2020-08-25 15:53:57 +02:00
|
|
|
rtile.buffers->set_pass_rect(
|
|
|
|
|
pass_type, components, (float *)b_pass.rect(), rtile.num_samples);
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
end_render_result(b_engine, b_rr, false, false, false);
|
|
|
|
|
}
|
|
|
|
|
else if (do_update_only) {
|
2017-11-02 15:05:57 +01:00
|
|
|
/* Sample would be zero at initial tile update, which is only needed
|
|
|
|
|
* to tag tile form blender side as IN PROGRESS for proper highlight
|
|
|
|
|
* no buffers should be sent to blender yet. For denoise we also
|
|
|
|
|
* keep showing the noisy buffers until denoise is done. */
|
|
|
|
|
bool merge = (rtile.sample != 0) && (rtile.task != RenderTile::DENOISE);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-11-02 15:05:57 +01:00
|
|
|
if (merge) {
|
2019-06-24 14:42:20 +02:00
|
|
|
update_render_result(b_rlay, rtile);
|
2013-01-01 16:15:13 +00:00
|
|
|
}
|
2019-06-24 13:34:31 +02:00
|
|
|
|
|
|
|
|
end_render_result(b_engine, b_rr, true, highlight, merge);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
else {
|
2017-11-02 15:05:57 +01:00
|
|
|
/* Write final render result. */
|
2019-06-24 14:42:20 +02:00
|
|
|
write_render_result(b_rlay, rtile);
|
2017-05-07 14:40:58 +02:00
|
|
|
end_render_result(b_engine, b_rr, false, false, true);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
void BlenderSession::read_render_tile(RenderTile &rtile)
|
|
|
|
|
{
|
|
|
|
|
do_write_update_render_tile(rtile, false, true, false);
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
void BlenderSession::write_render_tile(RenderTile &rtile)
|
|
|
|
|
{
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
do_write_update_render_tile(rtile, false, false, false);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
2017-05-07 14:40:58 +02:00
|
|
|
void BlenderSession::update_render_tile(RenderTile &rtile, bool highlight)
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
2013-01-28 17:37:51 +00:00
|
|
|
/* use final write for preview renders, otherwise render result wouldn't be
|
|
|
|
|
* be updated in blender side
|
|
|
|
|
* would need to be investigated a bit further, but for now shall be fine
|
|
|
|
|
*/
|
2015-03-28 00:15:15 +05:00
|
|
|
if (!b_engine.is_preview())
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
do_write_update_render_tile(rtile, true, false, highlight);
|
2013-01-28 17:37:51 +00:00
|
|
|
else
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
do_write_update_render_tile(rtile, false, false, false);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
2018-11-07 04:05:47 +01:00
|
|
|
static void add_cryptomatte_layer(BL::RenderResult &b_rr, string name, string manifest)
|
|
|
|
|
{
|
|
|
|
|
string identifier = string_printf("%08x", util_murmur_hash3(name.c_str(), name.length(), 0));
|
|
|
|
|
string prefix = "cryptomatte/" + identifier.substr(0, 7) + "/";
|
|
|
|
|
|
|
|
|
|
render_add_metadata(b_rr, prefix + "name", name);
|
|
|
|
|
render_add_metadata(b_rr, prefix + "hash", "MurmurHash3_32");
|
|
|
|
|
render_add_metadata(b_rr, prefix + "conversion", "uint32_to_float32");
|
|
|
|
|
render_add_metadata(b_rr, prefix + "manifest", manifest);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-13 14:33:29 +01:00
|
|
|
void BlenderSession::stamp_view_layer_metadata(Scene *scene, const string &view_layer_name)
|
2019-02-06 11:49:41 +01:00
|
|
|
{
|
|
|
|
|
BL::RenderResult b_rr = b_engine.get_result();
|
2019-02-13 14:33:29 +01:00
|
|
|
string prefix = "cycles." + view_layer_name + ".";
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 11:49:41 +01:00
|
|
|
/* Configured number of samples for the view layer. */
|
2019-02-13 14:33:29 +01:00
|
|
|
b_rr.stamp_data_add_field((prefix + "samples").c_str(),
|
|
|
|
|
to_string(session->params.samples).c_str());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 11:49:41 +01:00
|
|
|
/* Store ranged samples information. */
|
|
|
|
|
if (session->tile_manager.range_num_samples != -1) {
|
|
|
|
|
b_rr.stamp_data_add_field((prefix + "range_start_sample").c_str(),
|
|
|
|
|
to_string(session->tile_manager.range_start_sample).c_str());
|
|
|
|
|
b_rr.stamp_data_add_field((prefix + "range_num_samples").c_str(),
|
|
|
|
|
to_string(session->tile_manager.range_num_samples).c_str());
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-13 14:33:29 +01:00
|
|
|
/* Write cryptomatte metadata. */
|
2020-11-04 11:17:38 +01:00
|
|
|
if (scene->film->get_cryptomatte_passes() & CRYPT_OBJECT) {
|
2019-02-13 14:33:29 +01:00
|
|
|
add_cryptomatte_layer(b_rr,
|
|
|
|
|
view_layer_name + ".CryptoObject",
|
2019-03-04 09:51:36 +01:00
|
|
|
scene->object_manager->get_cryptomatte_objects(scene));
|
2019-02-13 14:33:29 +01:00
|
|
|
}
|
2020-11-04 11:17:38 +01:00
|
|
|
if (scene->film->get_cryptomatte_passes() & CRYPT_MATERIAL) {
|
2019-02-13 14:33:29 +01:00
|
|
|
add_cryptomatte_layer(b_rr,
|
|
|
|
|
view_layer_name + ".CryptoMaterial",
|
2019-03-04 09:51:36 +01:00
|
|
|
scene->shader_manager->get_cryptomatte_materials(scene));
|
2019-02-13 14:33:29 +01:00
|
|
|
}
|
2020-11-04 11:17:38 +01:00
|
|
|
if (scene->film->get_cryptomatte_passes() & CRYPT_ASSET) {
|
2019-02-13 14:33:29 +01:00
|
|
|
add_cryptomatte_layer(b_rr,
|
|
|
|
|
view_layer_name + ".CryptoAsset",
|
2019-03-04 09:51:36 +01:00
|
|
|
scene->object_manager->get_cryptomatte_assets(scene));
|
2019-02-13 14:33:29 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-03-04 11:31:20 +01:00
|
|
|
/* Store synchronization and bare-render times. */
|
|
|
|
|
double total_time, render_time;
|
|
|
|
|
session->progress.get_time(total_time, render_time);
|
|
|
|
|
b_rr.stamp_data_add_field((prefix + "total_time").c_str(),
|
2019-03-19 18:54:17 +01:00
|
|
|
time_human_readable_from_seconds(total_time).c_str());
|
2019-03-04 11:31:20 +01:00
|
|
|
b_rr.stamp_data_add_field((prefix + "render_time").c_str(),
|
2019-03-19 18:54:17 +01:00
|
|
|
time_human_readable_from_seconds(render_time).c_str());
|
2019-03-04 11:31:20 +01:00
|
|
|
b_rr.stamp_data_add_field((prefix + "synchronization_time").c_str(),
|
2019-03-19 18:54:17 +01:00
|
|
|
time_human_readable_from_seconds(total_time - render_time).c_str());
|
2019-02-06 11:49:41 +01:00
|
|
|
}
|
|
|
|
|
|
2018-04-21 19:35:12 +02:00
|
|
|
void BlenderSession::render(BL::Depsgraph &b_depsgraph_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2018-04-21 19:35:12 +02:00
|
|
|
b_depsgraph = b_depsgraph_;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-10-28 19:55:41 +01:00
|
|
|
if (session->progress.get_cancel()) {
|
|
|
|
|
update_status_progress();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* set callback to write out render results */
|
|
|
|
|
session->write_render_tile_cb = function_bind(&BlenderSession::write_render_tile, this, _1);
|
2017-05-07 14:40:58 +02:00
|
|
|
session->update_render_tile_cb = function_bind(
|
|
|
|
|
&BlenderSession::update_render_tile, this, _1, _2);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-05-31 23:49:10 +02:00
|
|
|
BL::ViewLayer b_view_layer = b_depsgraph.view_layer_eval();
|
|
|
|
|
|
2011-12-21 20:51:55 +00:00
|
|
|
/* get buffer parameters */
|
2015-02-18 21:16:52 +05:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(
|
2020-05-31 23:49:10 +02:00
|
|
|
b_engine, b_userpref, b_scene, background, b_view_layer);
|
2020-06-24 17:08:01 +02:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(
|
2021-05-31 16:21:24 +02:00
|
|
|
b_v3d, b_rv3d, scene->camera, width, height, session_params.denoising.use);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
/* temporary render result to find needed passes and views */
|
|
|
|
|
BL::RenderResult b_rr = begin_render_result(
|
|
|
|
|
b_engine, 0, 0, 1, 1, b_view_layer.name().c_str(), NULL);
|
|
|
|
|
BL::RenderResult::layers_iterator b_single_rlay;
|
|
|
|
|
b_rr.layers.begin(b_single_rlay);
|
|
|
|
|
BL::RenderLayer b_rlay = *b_single_rlay;
|
2018-11-08 15:13:43 +01:00
|
|
|
b_rlay_name = b_view_layer.name();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-05-31 23:49:10 +02:00
|
|
|
/* Update denoising parameters. */
|
|
|
|
|
session->set_denoising(session_params.denoising);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-07-28 13:01:31 +02:00
|
|
|
/* Compute render passes and film settings. */
|
2020-05-31 23:49:10 +02:00
|
|
|
vector<Pass> passes = sync->sync_render_passes(
|
2021-04-12 19:52:01 +02:00
|
|
|
b_scene, b_rlay, b_view_layer, session_params.adaptive_sampling, session_params.denoising);
|
2020-05-31 23:49:10 +02:00
|
|
|
|
2020-07-28 13:01:31 +02:00
|
|
|
/* Set buffer params, using film settings from sync_render_passes. */
|
|
|
|
|
buffer_params.passes = passes;
|
2020-11-04 11:17:38 +01:00
|
|
|
buffer_params.denoising_data_pass = scene->film->get_denoising_data_pass();
|
|
|
|
|
buffer_params.denoising_clean_pass = scene->film->get_denoising_clean_pass();
|
|
|
|
|
buffer_params.denoising_prefiltered_pass = scene->film->get_denoising_prefiltered_pass();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
BL::RenderResult::views_iterator b_view_iter;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-25 11:05:04 -02:00
|
|
|
int num_views = 0;
|
|
|
|
|
for (b_rr.views.begin(b_view_iter); b_view_iter != b_rr.views.end(); ++b_view_iter) {
|
|
|
|
|
num_views++;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
int view_index = 0;
|
|
|
|
|
for (b_rr.views.begin(b_view_iter); b_view_iter != b_rr.views.end();
|
|
|
|
|
++b_view_iter, ++view_index) {
|
|
|
|
|
b_rview_name = b_view_iter->name();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
/* set the current view */
|
|
|
|
|
b_engine.active_view_set(b_rview_name.c_str());
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
/* update scene */
|
|
|
|
|
BL::Object b_camera_override(b_engine.camera_override());
|
|
|
|
|
sync->sync_camera(b_render, b_camera_override, width, height, b_rview_name.c_str());
|
|
|
|
|
sync->sync_data(
|
2018-06-25 12:39:30 +02:00
|
|
|
b_render, b_depsgraph, b_v3d, b_camera_override, width, height, &python_thread_state);
|
2018-06-11 16:29:49 +02:00
|
|
|
builtin_images_load();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-09 16:14:15 +01:00
|
|
|
/* Attempt to free all data which is held by Blender side, since at this
|
2019-08-02 12:00:07 +10:00
|
|
|
* point we know that we've got everything to render current view layer.
|
2018-11-09 16:14:15 +01:00
|
|
|
*/
|
2019-05-01 21:14:11 +10:00
|
|
|
/* At the moment we only free if we are not doing multi-view
|
|
|
|
|
* (or if we are rendering the last view). See T58142/D4239 for discussion.
|
2019-01-25 11:05:04 -02:00
|
|
|
*/
|
|
|
|
|
if (view_index == num_views - 1) {
|
|
|
|
|
free_blender_memory_if_possible();
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-05-01 21:14:11 +10:00
|
|
|
/* Make sure all views have different noise patterns. - hardcoded value just to make it random
|
|
|
|
|
*/
|
2018-02-26 16:46:48 +01:00
|
|
|
if (view_index != 0) {
|
2020-11-04 11:17:38 +01:00
|
|
|
int seed = scene->integrator->get_seed();
|
|
|
|
|
seed += hash_uint2(seed, hash_uint2(view_index * 0xdeadbeef, 0));
|
|
|
|
|
scene->integrator->set_seed(seed);
|
2018-02-26 16:46:48 +01:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-12-28 18:37:05 +01:00
|
|
|
/* Update number of samples per layer. */
|
|
|
|
|
int samples = sync->get_layer_samples();
|
|
|
|
|
bool bound_samples = sync->get_layer_bound_samples();
|
|
|
|
|
int effective_layer_samples;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
if (samples != 0 && (!bound_samples || (samples < session_params.samples)))
|
|
|
|
|
effective_layer_samples = samples;
|
2018-12-28 18:37:05 +01:00
|
|
|
else
|
|
|
|
|
effective_layer_samples = session_params.samples;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
/* Update tile manager if we're doing resumable render. */
|
|
|
|
|
update_resumable_tile_manager(effective_layer_samples);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
/* Update session itself. */
|
|
|
|
|
session->reset(buffer_params, effective_layer_samples);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
/* render */
|
2020-10-01 23:16:01 +02:00
|
|
|
if (!b_engine.is_preview() && background && print_render_stats) {
|
|
|
|
|
scene->enable_update_stats();
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
session->start();
|
|
|
|
|
session->wait();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-07-27 15:46:13 +02:00
|
|
|
if (!b_engine.is_preview() && background && print_render_stats) {
|
|
|
|
|
RenderStats stats;
|
2018-11-29 02:06:30 +01:00
|
|
|
session->collect_statistics(&stats);
|
2018-07-27 15:46:13 +02:00
|
|
|
printf("Render statistics:\n%s\n", stats.full_report().c_str());
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-12-21 20:51:55 +00:00
|
|
|
if (session->progress.get_cancel())
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-13 14:33:29 +01:00
|
|
|
/* add metadata */
|
|
|
|
|
stamp_view_layer_metadata(scene, b_rlay_name);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-02-26 16:46:48 +01:00
|
|
|
/* free result without merging */
|
|
|
|
|
end_render_result(b_engine, b_rr, true, true, false);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-06-17 11:56:19 +02:00
|
|
|
double total_time, render_time;
|
|
|
|
|
session->progress.get_time(total_time, render_time);
|
|
|
|
|
VLOG(1) << "Total render time: " << total_time;
|
|
|
|
|
VLOG(1) << "Render time (without synchronization): " << render_time;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
/* clear callback */
|
2015-03-30 15:06:20 +05:00
|
|
|
session->write_render_tile_cb = function_null;
|
|
|
|
|
session->update_render_tile_cb = function_null;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2016-01-15 13:00:56 -02:00
|
|
|
static int bake_pass_filter_get(const int pass_filter)
|
|
|
|
|
{
|
|
|
|
|
int flag = BAKE_FILTER_NONE;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-01-15 13:00:56 -02:00
|
|
|
if ((pass_filter & BL::BakeSettings::pass_filter_DIRECT) != 0)
|
|
|
|
|
flag |= BAKE_FILTER_DIRECT;
|
|
|
|
|
if ((pass_filter & BL::BakeSettings::pass_filter_INDIRECT) != 0)
|
|
|
|
|
flag |= BAKE_FILTER_INDIRECT;
|
|
|
|
|
if ((pass_filter & BL::BakeSettings::pass_filter_COLOR) != 0)
|
|
|
|
|
flag |= BAKE_FILTER_COLOR;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-01-15 13:00:56 -02:00
|
|
|
if ((pass_filter & BL::BakeSettings::pass_filter_DIFFUSE) != 0)
|
|
|
|
|
flag |= BAKE_FILTER_DIFFUSE;
|
|
|
|
|
if ((pass_filter & BL::BakeSettings::pass_filter_GLOSSY) != 0)
|
|
|
|
|
flag |= BAKE_FILTER_GLOSSY;
|
|
|
|
|
if ((pass_filter & BL::BakeSettings::pass_filter_TRANSMISSION) != 0)
|
|
|
|
|
flag |= BAKE_FILTER_TRANSMISSION;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-01-15 13:00:56 -02:00
|
|
|
if ((pass_filter & BL::BakeSettings::pass_filter_EMIT) != 0)
|
|
|
|
|
flag |= BAKE_FILTER_EMISSION;
|
|
|
|
|
if ((pass_filter & BL::BakeSettings::pass_filter_AO) != 0)
|
|
|
|
|
flag |= BAKE_FILTER_AO;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-01-15 13:00:56 -02:00
|
|
|
return flag;
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-21 19:35:12 +02:00
|
|
|
void BlenderSession::bake(BL::Depsgraph &b_depsgraph_,
|
2018-02-26 16:46:48 +01:00
|
|
|
BL::Object &b_object,
|
2016-01-15 13:00:56 -02:00
|
|
|
const string &pass_type,
|
|
|
|
|
const int pass_filter,
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
const int bake_width,
|
|
|
|
|
const int bake_height)
|
2014-01-02 19:05:07 -02:00
|
|
|
{
|
2018-04-21 19:35:12 +02:00
|
|
|
b_depsgraph = b_depsgraph_;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-01-02 19:05:07 -02:00
|
|
|
ShaderEvalType shader_type = get_shader_type(pass_type);
|
2016-02-06 20:35:36 +01:00
|
|
|
int bake_pass_filter = bake_pass_filter_get(pass_filter);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
/* Initialize bake manager, before we load the baking kernels. */
|
|
|
|
|
scene->bake_manager->set(scene, b_object.name(), shader_type, bake_pass_filter);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
/* Passes are identified by name, so in order to return the combined pass we need to set the
|
|
|
|
|
* name. */
|
2020-08-18 12:15:46 +02:00
|
|
|
Pass::add(PASS_COMBINED, scene->passes, "Combined");
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
|
|
|
|
|
session->read_bake_tile_cb = function_bind(&BlenderSession::read_render_tile, this, _1);
|
|
|
|
|
session->write_render_tile_cb = function_bind(&BlenderSession::write_render_tile, this, _1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-13 07:09:22 +02:00
|
|
|
if (!session->progress.get_cancel()) {
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
/* Sync scene. */
|
2017-05-13 07:09:22 +02:00
|
|
|
BL::Object b_camera_override(b_engine.camera_override());
|
|
|
|
|
sync->sync_camera(b_render, b_camera_override, width, height, "");
|
|
|
|
|
sync->sync_data(
|
2018-06-25 12:39:30 +02:00
|
|
|
b_render, b_depsgraph, b_v3d, b_camera_override, width, height, &python_thread_state);
|
2018-06-11 16:29:49 +02:00
|
|
|
builtin_images_load();
|
2017-05-13 07:09:22 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
/* Object might have been disabled for rendering or excluded in some
|
|
|
|
|
* other way, in that case Blender will report a warning afterwards. */
|
|
|
|
|
bool object_found = false;
|
|
|
|
|
foreach (Object *ob, scene->objects) {
|
|
|
|
|
if (ob->name == b_object.name()) {
|
|
|
|
|
object_found = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
if (object_found && !session->progress.get_cancel()) {
|
|
|
|
|
/* Get session and buffer parameters. */
|
2017-05-13 07:09:22 +02:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(
|
|
|
|
|
b_engine, b_userpref, b_scene, background);
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
session_params.progressive_refine = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
BufferParams buffer_params;
|
|
|
|
|
buffer_params.width = bake_width;
|
|
|
|
|
buffer_params.height = bake_height;
|
2020-08-18 12:15:46 +02:00
|
|
|
buffer_params.passes = scene->passes;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
/* Update session. */
|
2017-05-13 07:09:22 +02:00
|
|
|
session->tile_manager.set_samples(session_params.samples);
|
|
|
|
|
session->reset(buffer_params, session_params.samples);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-13 07:09:22 +02:00
|
|
|
session->progress.set_update_callback(
|
|
|
|
|
function_bind(&BlenderSession::update_bake_progress, this));
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-05-13 07:09:22 +02:00
|
|
|
/* Perform bake. Check cancel to avoid crash with incomplete scene data. */
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
if (object_found && !session->progress.get_cancel()) {
|
|
|
|
|
session->start();
|
|
|
|
|
session->wait();
|
2017-05-13 07:09:22 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: code refactor to bake using regular render session and tiles
There should be no user visible change from this, except that tile size
now affects performance. The goal here is to simplify bake denoising in
D3099, letting it reuse more denoising tiles and pass code.
A lot of code is now shared with regular rendering, with the two main
differences being that we read some render result passes from the bake API
when starting to render a tile, and call the bake kernel instead of the
path trace kernel.
With this kind of design where Cycles asks for tiles from the bake API,
it should eventually be easier to reduce memory usage, show tiles as
they are baked, or bake multiple passes at once, though there's still
quite some work needed for that.
Reviewers: #cycles
Subscribers: monio, wmatyjewicz, lukasstockner97, michaelknubben
Differential Revision: https://developer.blender.org/D3108
2019-05-10 21:39:58 +02:00
|
|
|
session->read_bake_tile_cb = function_null;
|
|
|
|
|
session->write_render_tile_cb = function_null;
|
2014-01-02 19:05:07 -02:00
|
|
|
}
|
|
|
|
|
|
2019-06-24 14:42:20 +02:00
|
|
|
void BlenderSession::do_write_update_render_result(BL::RenderLayer &b_rlay,
|
2016-01-30 14:18:29 +01:00
|
|
|
RenderTile &rtile,
|
|
|
|
|
bool do_update_only)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-09-04 13:29:07 +00:00
|
|
|
RenderBuffers *buffers = rtile.buffers;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
/* copy data from device */
|
|
|
|
|
if (!buffers->copy_from_device())
|
|
|
|
|
return;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
float exposure = scene->film->get_exposure();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-10-10 02:28:23 +02:00
|
|
|
vector<float> pixels(rtile.w * rtile.h * 4);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-03-30 15:55:12 +02:00
|
|
|
/* Adjust absolute sample number to the range. */
|
|
|
|
|
int sample = rtile.sample;
|
|
|
|
|
const int range_start_sample = session->tile_manager.range_start_sample;
|
|
|
|
|
if (range_start_sample != -1) {
|
|
|
|
|
sample -= range_start_sample;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (!do_update_only) {
|
2012-09-04 13:29:07 +00:00
|
|
|
/* copy each pass */
|
2021-01-25 16:20:10 +01:00
|
|
|
for (BL::RenderPass &b_pass : b_rlay.passes) {
|
2012-09-04 13:29:07 +00:00
|
|
|
int components = b_pass.channels();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-12-04 19:57:28 +01:00
|
|
|
/* Copy pixels from regular render passes. */
|
|
|
|
|
bool read = buffers->get_pass_rect(b_pass.name(), exposure, sample, components, &pixels[0]);
|
|
|
|
|
|
|
|
|
|
/* If denoising pass, */
|
|
|
|
|
if (!read) {
|
2017-05-07 14:40:58 +02:00
|
|
|
int denoising_offset = BlenderSync::get_denoising_pass(b_pass);
|
|
|
|
|
if (denoising_offset >= 0) {
|
|
|
|
|
read = buffers->get_denoising_pass_rect(
|
|
|
|
|
denoising_offset, exposure, sample, components, &pixels[0]);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
|
Render API/Cycles: Identify Render Passes by their name instead of a type flag
Previously, every RenderPass would have a bitfield that specified its type. That limits the number of passes to 32, which was reached a while ago.
However, most of the code already supported arbitrary RenderPasses since they were also used to store Multilayer EXR images.
Therefore, this commit completely removes the passflag from RenderPass and changes all code to use the unique pass name for identification.
Since Blender Internal relies on hardcoded passes and to preserve compatibility, 32 pass names are reserved for the old hardcoded passes.
To support these arbitrary passes, the Render Result compositor node now adds dynamic sockets. For compatibility, the old hardcoded sockets are always stored and just hidden when the corresponding pass isn't available.
To use these changes, the Render Engine API now includes a function that allows render engines to add arbitrary passes to the render result. To be able to add options for these passes, addons can now add their own properties to SceneRenderLayers.
To keep the compositor input node updated, render engine plugins have to implement a callback that registers all the passes that will be generated.
From a user perspective, nothing should change with this commit.
Differential Revision: https://developer.blender.org/D2443
Differential Revision: https://developer.blender.org/D2444
2017-05-03 00:21:18 +02:00
|
|
|
if (!read) {
|
2013-02-10 18:02:59 +00:00
|
|
|
memset(&pixels[0], 0, pixels.size() * sizeof(float));
|
Render API/Cycles: Identify Render Passes by their name instead of a type flag
Previously, every RenderPass would have a bitfield that specified its type. That limits the number of passes to 32, which was reached a while ago.
However, most of the code already supported arbitrary RenderPasses since they were also used to store Multilayer EXR images.
Therefore, this commit completely removes the passflag from RenderPass and changes all code to use the unique pass name for identification.
Since Blender Internal relies on hardcoded passes and to preserve compatibility, 32 pass names are reserved for the old hardcoded passes.
To support these arbitrary passes, the Render Result compositor node now adds dynamic sockets. For compatibility, the old hardcoded sockets are always stored and just hidden when the corresponding pass isn't available.
To use these changes, the Render Engine API now includes a function that allows render engines to add arbitrary passes to the render result. To be able to add options for these passes, addons can now add their own properties to SceneRenderLayers.
To keep the compositor input node updated, render engine plugins have to implement a callback that registers all the passes that will be generated.
From a user perspective, nothing should change with this commit.
Differential Revision: https://developer.blender.org/D2443
Differential Revision: https://developer.blender.org/D2444
2017-05-03 00:21:18 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-02-10 18:02:59 +00:00
|
|
|
b_pass.rect(&pixels[0]);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
Cycles: Render Passes
Currently supported passes:
* Combined, Z, Normal, Object Index, Material Index, Emission, Environment,
Diffuse/Glossy/Transmission x Direct/Indirect/Color
Not supported yet:
* UV, Vector, Mist
Only enabled for CPU devices at the moment, will do GPU tweaks tommorrow,
also for environment importance sampling.
Documentation:
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Passes
2012-01-25 17:23:52 +00:00
|
|
|
}
|
2015-04-06 10:40:12 -03:00
|
|
|
else {
|
|
|
|
|
/* copy combined pass */
|
Render API/Cycles: Identify Render Passes by their name instead of a type flag
Previously, every RenderPass would have a bitfield that specified its type. That limits the number of passes to 32, which was reached a while ago.
However, most of the code already supported arbitrary RenderPasses since they were also used to store Multilayer EXR images.
Therefore, this commit completely removes the passflag from RenderPass and changes all code to use the unique pass name for identification.
Since Blender Internal relies on hardcoded passes and to preserve compatibility, 32 pass names are reserved for the old hardcoded passes.
To support these arbitrary passes, the Render Result compositor node now adds dynamic sockets. For compatibility, the old hardcoded sockets are always stored and just hidden when the corresponding pass isn't available.
To use these changes, the Render Engine API now includes a function that allows render engines to add arbitrary passes to the render result. To be able to add options for these passes, addons can now add their own properties to SceneRenderLayers.
To keep the compositor input node updated, render engine plugins have to implement a callback that registers all the passes that will be generated.
From a user perspective, nothing should change with this commit.
Differential Revision: https://developer.blender.org/D2443
Differential Revision: https://developer.blender.org/D2444
2017-05-03 00:21:18 +02:00
|
|
|
BL::RenderPass b_combined_pass(b_rlay.passes.find_by_name("Combined", b_rview_name.c_str()));
|
2019-12-04 19:57:28 +01:00
|
|
|
if (buffers->get_pass_rect("Combined", exposure, sample, 4, &pixels[0]))
|
2015-04-06 10:40:12 -03:00
|
|
|
b_combined_pass.rect(&pixels[0]);
|
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2019-06-24 14:42:20 +02:00
|
|
|
void BlenderSession::write_render_result(BL::RenderLayer &b_rlay, RenderTile &rtile)
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
2019-06-24 14:42:20 +02:00
|
|
|
do_write_update_render_result(b_rlay, rtile, false);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
2019-06-24 14:42:20 +02:00
|
|
|
void BlenderSession::update_render_result(BL::RenderLayer &b_rlay, RenderTile &rtile)
|
2012-09-04 13:29:07 +00:00
|
|
|
{
|
2019-06-24 14:42:20 +02:00
|
|
|
do_write_update_render_result(b_rlay, rtile, true);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
2018-04-21 19:35:12 +02:00
|
|
|
void BlenderSession::synchronize(BL::Depsgraph &b_depsgraph_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-06-09 11:57:51 +00:00
|
|
|
/* only used for viewport render */
|
|
|
|
|
if (!b_v3d)
|
|
|
|
|
return;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* on session/scene parameter changes, we recreate session entirely */
|
2015-02-18 21:16:52 +05:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(
|
|
|
|
|
b_engine, b_userpref, b_scene, background);
|
2017-10-08 04:32:25 +02:00
|
|
|
SceneParams scene_params = BlenderSync::get_scene_params(b_scene, background);
|
2014-08-01 16:39:05 +06:00
|
|
|
bool session_pause = BlenderSync::get_session_pause(b_scene, background);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (session->params.modified(session_params) || scene->params.modified(scene_params)) {
|
|
|
|
|
free_session();
|
|
|
|
|
create_session();
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-09-16 13:14:02 +00:00
|
|
|
/* increase samples, but never decrease */
|
|
|
|
|
session->set_samples(session_params.samples);
|
2020-05-31 23:49:10 +02:00
|
|
|
session->set_denoising_start_sample(session_params.denoising.start_sample);
|
2014-08-01 16:39:05 +06:00
|
|
|
session->set_pause(session_pause);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* copy recalc flags, outside of mutex so we can decide to do the real
|
2012-06-09 17:22:52 +00:00
|
|
|
* synchronization at a later time to not block on running updates */
|
2019-08-27 15:47:30 +02:00
|
|
|
sync->sync_recalc(b_depsgraph_, b_v3d);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-01 16:39:05 +06:00
|
|
|
/* don't do synchronization if on pause */
|
|
|
|
|
if (session_pause) {
|
|
|
|
|
tag_update();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* try to acquire mutex. if we don't want to or can't, come back later */
|
|
|
|
|
if (!session->ready_to_reset() || !session->scene->mutex.try_lock()) {
|
|
|
|
|
tag_update();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* data and camera synchronize */
|
2018-04-21 19:35:12 +02:00
|
|
|
b_depsgraph = b_depsgraph_;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-01-30 14:18:29 +01:00
|
|
|
BL::Object b_camera_override(b_engine.camera_override());
|
2015-07-21 15:36:35 +02:00
|
|
|
sync->sync_data(
|
2018-02-26 16:46:48 +01:00
|
|
|
b_render, b_depsgraph, b_v3d, b_camera_override, width, height, &python_thread_state);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if (b_rv3d)
|
|
|
|
|
sync->sync_view(b_v3d, b_rv3d, width, height);
|
|
|
|
|
else
|
Multi-View: Cycles - Spherical Stereo support (VR Panoramas)
This is a new option for panorama cameras to render
stereo that can be used in virtual reality devices
The option is available under the camera panel when Multi-View is enabled (Views option in the Render Layers panel)
Known limitations:
------------------
* Parallel convergence is not supported (you need to set a convergence distance really high to simulate this effect).
* Pivot was not supposed to affect the render but it does, this has to be looked at, but for now set it to CENTER
* Derivatives in perspective camera need to be pre-computed or we shuld get rid of kcam->dx/dy (Sergey words, I don't fully grasp the implication shere)
* This works in perspective mode and in panorama mode. However, for fully benefit from this effect in perspective mode you need to render a cube map. (there is an addon for this, developed separately, perhaps we could include it in master).
* We have no support for "neck distance" at the moment. This is supposed to help with objects at short distances.
* We have no support to rotate the "Up Axis" of the stereo plane. Meaning, we hardcode 0,0,1 as UP, and create the stereo pair related to that. (although we could take the camera local UP when rendering panoramas, this wouldn't work for perspective cameras.
* We have no support for interocular distance attenuation based on the proximity of the poles (which helps to reduce the pole rotation effect/artifact).
THIS NEEDS DOCS - both in 2.78 release log and the Blender manual.
Meanwhile you can read about it here: http://code.blender.org/2015/03/1451
This patch specifically dates from March 2015, as you can see in the code.blender.org post. Many thanks to all the reviewers, testers and minor sponsors who helped me maintain spherical-stereo for 1 year.
All that said, have fun with this. This feature was what got me started with Multi-View development (at the time what I was looking for was Fulldome stereo support, but the implementation is the same). In order to make this into Blender I had to make it aiming at a less-specic user-case Thus Multi-View started. (this was December 2012, during Siggraph Asia and a chat I had with Paul Bourke during the conference). I don't have the original patch anymore, but you can find a re-based version of it from March 2013, right before I start with the Multi-View project https://developer.blender.org/P332
Reviewers: sergey, dingto
Subscribers: #cycles
Differential Revision: https://developer.blender.org/D1223
2016-03-10 09:28:29 -03:00
|
|
|
sync->sync_camera(b_render, b_camera_override, width, height, "");
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-11 16:30:01 +01:00
|
|
|
/* get buffer parameters */
|
2020-06-24 17:08:01 +02:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(
|
2021-05-31 16:21:24 +02:00
|
|
|
b_v3d, b_rv3d, scene->camera, width, height, session_params.denoising.use);
|
2020-02-11 16:30:01 +01:00
|
|
|
|
2020-05-31 23:49:10 +02:00
|
|
|
if (!buffer_params.denoising_data_pass) {
|
|
|
|
|
session_params.denoising.use = false;
|
2020-02-11 16:30:01 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-31 23:49:10 +02:00
|
|
|
session->set_denoising(session_params.denoising);
|
|
|
|
|
|
|
|
|
|
/* Update film if denoising data was enabled or disabled. */
|
2020-11-04 11:17:38 +01:00
|
|
|
scene->film->set_denoising_data_pass(buffer_params.denoising_data_pass);
|
2020-02-11 16:30:01 +01:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* reset if needed */
|
2011-12-20 12:25:37 +00:00
|
|
|
if (scene->need_reset()) {
|
|
|
|
|
session->reset(buffer_params, session_params.samples);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-06-07 21:02:57 +02:00
|
|
|
/* After session reset, so device is not accessing image data anymore. */
|
|
|
|
|
builtin_images_load();
|
|
|
|
|
|
2013-04-24 20:12:12 +00:00
|
|
|
/* reset time */
|
|
|
|
|
start_resize_time = 0.0;
|
2011-12-20 12:25:37 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-06-07 21:02:57 +02:00
|
|
|
/* unlock */
|
|
|
|
|
session->scene->mutex.unlock();
|
|
|
|
|
|
2019-01-09 16:57:01 +01:00
|
|
|
/* Start rendering thread, if it's not running already. Do this
|
|
|
|
|
* after all scene data has been synced at least once. */
|
|
|
|
|
session->start();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BlenderSession::draw(int w, int h)
|
|
|
|
|
{
|
2013-04-28 12:31:24 +00:00
|
|
|
/* pause in redraw in case update is not being called due to final render */
|
|
|
|
|
session->set_pause(BlenderSync::get_session_pause(b_scene, background));
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* before drawing, we verify camera and viewport size changes, because
|
2012-06-09 17:22:52 +00:00
|
|
|
* we do not get update callbacks for those, we must detect them here */
|
2011-04-27 11:58:34 +00:00
|
|
|
if (session->ready_to_reset()) {
|
|
|
|
|
bool reset = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-24 20:12:12 +00:00
|
|
|
/* if dimensions changed, reset */
|
|
|
|
|
if (width != w || height != h) {
|
|
|
|
|
if (start_resize_time == 0.0) {
|
|
|
|
|
/* don't react immediately to resizes to avoid flickery resizing
|
|
|
|
|
* of the viewport, and some window managers changing the window
|
|
|
|
|
* size temporarily on unminimize */
|
|
|
|
|
start_resize_time = time_dt();
|
|
|
|
|
tag_redraw();
|
|
|
|
|
}
|
2013-05-16 17:20:56 +00:00
|
|
|
else if (time_dt() - start_resize_time < 0.2) {
|
2013-04-24 20:12:12 +00:00
|
|
|
tag_redraw();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
width = w;
|
|
|
|
|
height = h;
|
|
|
|
|
reset = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
2013-04-24 20:12:12 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* try to acquire mutex. if we can't, come back later */
|
|
|
|
|
if (!session->scene->mutex.try_lock()) {
|
|
|
|
|
tag_update();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* update camera from 3d view */
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-24 20:12:12 +00:00
|
|
|
sync->sync_view(b_v3d, b_rv3d, width, height);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
if (scene->camera->is_modified())
|
2011-04-27 11:58:34 +00:00
|
|
|
reset = true;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
session->scene->mutex.unlock();
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* reset if requested */
|
2011-08-28 13:55:59 +00:00
|
|
|
if (reset) {
|
2015-02-18 21:16:52 +05:00
|
|
|
SessionParams session_params = BlenderSync::get_session_params(
|
|
|
|
|
b_engine, b_userpref, b_scene, background);
|
2020-06-24 17:08:01 +02:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(
|
2021-05-31 16:21:24 +02:00
|
|
|
b_v3d, b_rv3d, scene->camera, width, height, session_params.denoising.use);
|
2014-08-01 16:39:05 +06:00
|
|
|
bool session_pause = BlenderSync::get_session_pause(b_scene, background);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-08-01 16:39:05 +06:00
|
|
|
if (session_pause == false) {
|
|
|
|
|
session->reset(buffer_params, session_params.samples);
|
|
|
|
|
start_resize_time = 0.0;
|
2019-04-17 06:17:24 +02:00
|
|
|
}
|
|
|
|
|
}
|
2014-08-01 16:39:05 +06:00
|
|
|
}
|
2013-02-15 09:15:14 +00:00
|
|
|
else {
|
|
|
|
|
tag_update();
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-23 12:20:11 +00:00
|
|
|
/* update status and progress for 3d view draw */
|
|
|
|
|
update_status_progress();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-23 12:20:11 +00:00
|
|
|
/* draw */
|
2020-06-24 17:08:01 +02:00
|
|
|
BufferParams buffer_params = BlenderSync::get_buffer_params(
|
2021-05-31 16:21:24 +02:00
|
|
|
b_v3d, b_rv3d, scene->camera, width, height, session->params.denoising.use);
|
2014-03-26 14:57:30 +06:00
|
|
|
DeviceDrawParams draw_params;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-26 14:57:30 +06:00
|
|
|
if (session->params.display_buffer_linear) {
|
|
|
|
|
draw_params.bind_display_space_shader_cb = function_bind(
|
|
|
|
|
&BL::RenderEngine::bind_display_space_shader, &b_engine, b_scene);
|
|
|
|
|
draw_params.unbind_display_space_shader_cb = function_bind(
|
|
|
|
|
&BL::RenderEngine::unbind_display_space_shader, &b_engine);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-03-26 14:57:30 +06:00
|
|
|
return !session->draw(buffer_params, draw_params);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlenderSession::get_status(string &status, string &substatus)
|
|
|
|
|
{
|
|
|
|
|
session->progress.get_status(status, substatus);
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-13 12:31:48 +01:00
|
|
|
void BlenderSession::get_kernel_status(string &kernel_status)
|
|
|
|
|
{
|
|
|
|
|
session->progress.get_kernel_status(kernel_status);
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-14 23:06:10 +05:00
|
|
|
void BlenderSession::get_progress(float &progress, double &total_time, double &render_time)
|
2011-08-22 13:17:43 +00:00
|
|
|
{
|
Cycles: Refactor Progress system to provide better estimates
The Progress system in Cycles had two limitations so far:
- It just counted tiles, but ignored their size. For example, when rendering a 600x500 image with 512x512 tiles, the right 88x500 tile would count for 50% of the progress, although it only covers 15% of the image.
- Scene update time was incorrectly counted as rendering time - therefore, the remaining time started very long and gradually decreased.
This patch fixes both problems:
First of all, the Progress now has a function to ignore time spans, and that is used to ignore scene update time.
The larger change is the tile size: Instead of counting samples per tile, so that the final value is num_samples*num_tiles, the code now counts every sample for every pixel, so that the final value is num_samples*num_pixels.
Along with that, some unused variables were removed from the Progress and Session classes.
Reviewers: brecht, sergey, #cycles
Subscribers: brecht, candreacchio, sergey
Differential Revision: https://developer.blender.org/D2214
2016-11-26 04:22:34 +01:00
|
|
|
session->progress.get_time(total_time, render_time);
|
|
|
|
|
progress = session->progress.get_progress();
|
2011-08-22 13:17:43 +00:00
|
|
|
}
|
|
|
|
|
|
2014-07-22 18:41:01 -03:00
|
|
|
void BlenderSession::update_bake_progress()
|
|
|
|
|
{
|
Cycles: Refactor Progress system to provide better estimates
The Progress system in Cycles had two limitations so far:
- It just counted tiles, but ignored their size. For example, when rendering a 600x500 image with 512x512 tiles, the right 88x500 tile would count for 50% of the progress, although it only covers 15% of the image.
- Scene update time was incorrectly counted as rendering time - therefore, the remaining time started very long and gradually decreased.
This patch fixes both problems:
First of all, the Progress now has a function to ignore time spans, and that is used to ignore scene update time.
The larger change is the tile size: Instead of counting samples per tile, so that the final value is num_samples*num_tiles, the code now counts every sample for every pixel, so that the final value is num_samples*num_pixels.
Along with that, some unused variables were removed from the Progress and Session classes.
Reviewers: brecht, sergey, #cycles
Subscribers: brecht, candreacchio, sergey
Differential Revision: https://developer.blender.org/D2214
2016-11-26 04:22:34 +01:00
|
|
|
float progress = session->progress.get_progress();
|
2014-07-22 18:41:01 -03:00
|
|
|
|
|
|
|
|
if (progress != last_progress) {
|
|
|
|
|
b_engine.update_progress(progress);
|
|
|
|
|
last_progress = progress;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-08-23 12:20:11 +00:00
|
|
|
void BlenderSession::update_status_progress()
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2019-03-13 12:31:48 +01:00
|
|
|
string timestatus, status, substatus, kernel_status;
|
2018-11-09 16:04:53 +01:00
|
|
|
string scene_status = "";
|
2011-08-22 13:17:43 +00:00
|
|
|
float progress;
|
2015-01-14 23:06:10 +05:00
|
|
|
double total_time, remaining_time = 0, render_time;
|
2012-11-05 08:04:57 +00:00
|
|
|
float mem_used = (float)session->stats.mem_used / 1024.0f / 1024.0f;
|
|
|
|
|
float mem_peak = (float)session->stats.mem_peak / 1024.0f / 1024.0f;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-22 13:17:43 +00:00
|
|
|
get_status(status, substatus);
|
2019-03-13 12:31:48 +01:00
|
|
|
get_kernel_status(kernel_status);
|
2015-01-14 23:06:10 +05:00
|
|
|
get_progress(progress, total_time, render_time);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-14 23:06:10 +05:00
|
|
|
if (progress > 0)
|
|
|
|
|
remaining_time = (1.0 - (double)progress) * (render_time / (double)progress);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-01-14 23:06:10 +05:00
|
|
|
if (background) {
|
2020-08-06 18:34:41 +02:00
|
|
|
if (scene)
|
|
|
|
|
scene_status += " | " + scene->name;
|
2013-06-24 22:41:24 +00:00
|
|
|
if (b_rlay_name != "")
|
2018-11-09 16:04:53 +01:00
|
|
|
scene_status += ", " + b_rlay_name;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-04-06 10:40:12 -03:00
|
|
|
if (b_rview_name != "")
|
2018-11-09 16:04:53 +01:00
|
|
|
scene_status += ", " + b_rview_name;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-10-25 11:47:37 +02:00
|
|
|
if (remaining_time > 0) {
|
2019-03-19 18:54:17 +01:00
|
|
|
timestatus += "Remaining:" + time_human_readable_from_seconds(remaining_time) + " | ";
|
2018-10-25 11:47:37 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-10-25 11:47:37 +02:00
|
|
|
timestatus += string_printf("Mem:%.2fM, Peak:%.2fM", (double)mem_used, (double)mem_peak);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-10-25 11:47:37 +02:00
|
|
|
if (status.size() > 0)
|
|
|
|
|
status = " | " + status;
|
|
|
|
|
if (substatus.size() > 0)
|
|
|
|
|
status += " | " + substatus;
|
2019-03-15 16:28:33 +01:00
|
|
|
if (kernel_status.size() > 0)
|
|
|
|
|
status += " | " + kernel_status;
|
2018-10-25 11:47:37 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-01-19 00:41:55 +01:00
|
|
|
double current_time = time_dt();
|
2019-05-01 21:14:11 +10:00
|
|
|
/* When rendering in a window, redraw the status at least once per second to keep the elapsed and
|
|
|
|
|
* remaining time up-to-date. For headless rendering, only report when something significant
|
|
|
|
|
* changes to keep the console output readable. */
|
2017-01-19 00:41:55 +01:00
|
|
|
if (status != last_status || (!headless && (current_time - last_status_time) > 1.0)) {
|
2018-11-09 16:04:53 +01:00
|
|
|
b_engine.update_stats("", (timestatus + scene_status + status).c_str());
|
2012-11-05 08:04:57 +00:00
|
|
|
b_engine.update_memory_stats(mem_used, mem_peak);
|
2011-10-30 10:12:34 +00:00
|
|
|
last_status = status;
|
2017-01-19 00:41:55 +01:00
|
|
|
last_status_time = current_time;
|
2011-10-30 10:12:34 +00:00
|
|
|
}
|
|
|
|
|
if (progress != last_progress) {
|
2012-10-22 17:34:16 +00:00
|
|
|
b_engine.update_progress(progress);
|
2011-10-30 10:12:34 +00:00
|
|
|
last_progress = progress;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2015-03-28 00:15:15 +05:00
|
|
|
if (session->progress.get_error()) {
|
2014-12-05 21:27:52 +05:00
|
|
|
string error = session->progress.get_error_message();
|
|
|
|
|
if (error != last_error) {
|
|
|
|
|
/* TODO(sergey): Currently C++ RNA API doesn't let us to
|
|
|
|
|
* use mnemonic name for the variable. Would be nice to
|
|
|
|
|
* have this figured out.
|
|
|
|
|
*
|
|
|
|
|
* For until then, 1 << 5 means RPT_ERROR.
|
|
|
|
|
*/
|
|
|
|
|
b_engine.report(1 << 5, error.c_str());
|
2014-12-05 22:00:39 +05:00
|
|
|
b_engine.error_set(error.c_str());
|
2014-12-05 21:27:52 +05:00
|
|
|
last_error = error;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-08-23 12:20:11 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-08-23 12:20:11 +00:00
|
|
|
void BlenderSession::tag_update()
|
|
|
|
|
{
|
|
|
|
|
/* tell blender that we want to get another update callback */
|
2012-10-22 17:34:16 +00:00
|
|
|
b_engine.tag_update();
|
2011-08-23 12:20:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlenderSession::tag_redraw()
|
|
|
|
|
{
|
2011-08-22 13:17:43 +00:00
|
|
|
if (background) {
|
2011-08-23 12:20:11 +00:00
|
|
|
/* update stats and progress, only for background here because
|
2012-06-09 17:22:52 +00:00
|
|
|
* in 3d view we do it in draw for thread safety reasons */
|
2011-08-23 12:20:11 +00:00
|
|
|
update_status_progress();
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-08-22 13:17:43 +00:00
|
|
|
/* offline render, redraw if timeout passed */
|
2012-06-09 17:45:22 +00:00
|
|
|
if (time_dt() - last_redraw_time > 1.0) {
|
2012-10-22 17:34:16 +00:00
|
|
|
b_engine.tag_redraw();
|
2011-04-27 11:58:34 +00:00
|
|
|
last_redraw_time = time_dt();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* tell blender that we want to redraw */
|
2012-10-22 17:34:16 +00:00
|
|
|
b_engine.tag_redraw();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void BlenderSession::test_cancel()
|
|
|
|
|
{
|
|
|
|
|
/* test if we need to cancel rendering */
|
|
|
|
|
if (background)
|
2012-10-22 17:34:16 +00:00
|
|
|
if (b_engine.test_break())
|
2011-04-27 11:58:34 +00:00
|
|
|
session->progress.set_cancel("Cancelled");
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 15:55:12 +02:00
|
|
|
void BlenderSession::update_resumable_tile_manager(int num_samples)
|
|
|
|
|
{
|
|
|
|
|
const int num_resumable_chunks = BlenderSession::num_resumable_chunks,
|
|
|
|
|
current_resumable_chunk = BlenderSession::current_resumable_chunk;
|
|
|
|
|
if (num_resumable_chunks == 0) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-29 18:08:12 +01:00
|
|
|
if (num_resumable_chunks > num_samples) {
|
|
|
|
|
fprintf(stderr,
|
|
|
|
|
"Cycles warning: more sample chunks (%d) than samples (%d), "
|
|
|
|
|
"this will cause some samples to be included in multiple chunks.\n",
|
|
|
|
|
num_resumable_chunks,
|
|
|
|
|
num_samples);
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-29 18:08:12 +01:00
|
|
|
const float num_samples_per_chunk = (float)num_samples / num_resumable_chunks;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-29 18:08:12 +01:00
|
|
|
float range_start_sample, range_num_samples;
|
2017-03-15 15:52:27 +01:00
|
|
|
if (current_resumable_chunk != 0) {
|
|
|
|
|
/* Single chunk rendering. */
|
|
|
|
|
range_start_sample = num_samples_per_chunk * (current_resumable_chunk - 1);
|
|
|
|
|
range_num_samples = num_samples_per_chunk;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
/* Ranged-chunks. */
|
|
|
|
|
const int num_chunks = end_resumable_chunk - start_resumable_chunk + 1;
|
|
|
|
|
range_start_sample = num_samples_per_chunk * (start_resumable_chunk - 1);
|
|
|
|
|
range_num_samples = num_chunks * num_samples_per_chunk;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-01-29 18:08:12 +01:00
|
|
|
/* Round after doing the multiplications with num_chunks and num_samples_per_chunk
|
|
|
|
|
* to allow for many small chunks. */
|
Shading: Add more operators to Vector Math node.
Add Multiply, Divide, Project, Reflect, Distance, Length, Scale, Snap,
Floor, Ceil, Modulo, Fraction, Absolute, Minimum, and Maximum operators
to the Vector Math node. The Value output has been removed from operators
whose output is a vector, and the other way around. All of those removals
has been handled properly in versioning code.
The patch doesn't include tests for the new operators. Tests will be added
in a later patch.
Reviewers: brecht, JacquesLucke
Differential Revision: https://developer.blender.org/D5523
2019-08-21 19:36:33 +02:00
|
|
|
int rounded_range_start_sample = (int)floorf(range_start_sample + 0.5f);
|
|
|
|
|
int rounded_range_num_samples = max((int)floorf(range_num_samples + 0.5f), 1);
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2017-03-15 15:52:27 +01:00
|
|
|
/* Make sure we don't overshoot. */
|
2019-01-29 18:08:12 +01:00
|
|
|
if (rounded_range_start_sample + rounded_range_num_samples > num_samples) {
|
|
|
|
|
rounded_range_num_samples = num_samples - rounded_range_num_samples;
|
2016-03-30 15:55:12 +02:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2016-03-30 15:55:12 +02:00
|
|
|
VLOG(1) << "Samples range start is " << range_start_sample << ", "
|
|
|
|
|
<< "number of samples to render is " << range_num_samples;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-11-04 11:17:38 +01:00
|
|
|
scene->integrator->set_start_sample(rounded_range_start_sample);
|
|
|
|
|
|
2019-01-29 18:08:12 +01:00
|
|
|
session->tile_manager.range_start_sample = rounded_range_start_sample;
|
|
|
|
|
session->tile_manager.range_num_samples = rounded_range_num_samples;
|
2016-03-30 15:55:12 +02:00
|
|
|
}
|
|
|
|
|
|
2018-11-09 16:14:15 +01:00
|
|
|
void BlenderSession::free_blender_memory_if_possible()
|
|
|
|
|
{
|
2018-11-15 17:19:26 +01:00
|
|
|
if (!background) {
|
2018-11-09 16:14:15 +01:00
|
|
|
/* During interactive render we can not free anything: attempts to save
|
|
|
|
|
* memory would cause things to be allocated and evaluated for every
|
|
|
|
|
* updated sample.
|
|
|
|
|
*/
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
b_engine.free_blender_memory();
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-30 15:55:12 +02:00
|
|
|
CCL_NAMESPACE_END
|