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 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <limits.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 18:39:14 +00:00
|
|
|
#include "render/buffers.h"
|
|
|
|
#include "render/camera.h"
|
|
|
|
#include "device/device.h"
|
|
|
|
#include "render/graph.h"
|
|
|
|
#include "render/integrator.h"
|
|
|
|
#include "render/mesh.h"
|
|
|
|
#include "render/object.h"
|
|
|
|
#include "render/scene.h"
|
|
|
|
#include "render/session.h"
|
|
|
|
#include "render/bake.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 18:39:14 +00:00
|
|
|
#include "util/util_foreach.h"
|
|
|
|
#include "util/util_function.h"
|
|
|
|
#include "util/util_logging.h"
|
|
|
|
#include "util/util_math.h"
|
|
|
|
#include "util/util_opengl.h"
|
|
|
|
#include "util/util_task.h"
|
|
|
|
#include "util/util_time.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2012-10-23 16:36:53 +00:00
|
|
|
/* Note about preserve_tile_device option for tile manager:
|
|
|
|
* progressive refine and viewport rendering does requires tiles to
|
|
|
|
* always be allocated for the same device
|
|
|
|
*/
|
2011-04-27 11:58:34 +00:00
|
|
|
Session::Session(const SessionParams& params_)
|
|
|
|
: params(params_),
|
2012-09-17 10:55:18 +00:00
|
|
|
tile_manager(params.progressive, params.samples, params.tile_size, params.start_resolution,
|
2013-01-07 19:55:49 +00:00
|
|
|
params.background == false || params.progressive_refine, params.background, params.tile_order,
|
2017-08-14 22:11:52 +00:00
|
|
|
max(params.device.multi_devices.size(), 1), params.pixel_size),
|
2012-11-05 08:04:57 +00:00
|
|
|
stats()
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-01-04 18:06:32 +00:00
|
|
|
device_use_gl = ((params.device.type != DEVICE_CPU) && !params.background);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
and the initial bounding/splitting is still single threaded, but recursive
splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
code from the Embree raytracer from Intel.
http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
2012-04-28 08:53:59 +00:00
|
|
|
TaskScheduler::init(params.threads);
|
|
|
|
|
2012-11-07 21:00:49 +00:00
|
|
|
device = Device::create(params.device, stats, params.background);
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2014-04-14 12:08:32 +00:00
|
|
|
if(params.background && params.output_path.empty()) {
|
2012-09-04 13:29:07 +00:00
|
|
|
buffers = NULL;
|
|
|
|
display = NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
buffers = new RenderBuffers(device);
|
2013-08-30 23:49:38 +00:00
|
|
|
display = new DisplayBuffer(device, params.display_buffer_linear);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
session_thread = NULL;
|
|
|
|
scene = NULL;
|
|
|
|
|
|
|
|
reset_time = 0.0;
|
2013-09-03 22:39:21 +00:00
|
|
|
last_update_time = 0.0;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
delayed_reset.do_reset = false;
|
2011-09-16 13:14:02 +00:00
|
|
|
delayed_reset.samples = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
display_outdated = false;
|
|
|
|
gpu_draw_ready = false;
|
|
|
|
gpu_need_tonemap = false;
|
2011-08-29 10:21:10 +00:00
|
|
|
pause = false;
|
2012-02-23 19:48:18 +00:00
|
|
|
kernels_loaded = false;
|
2015-05-09 14:15:58 +00:00
|
|
|
|
|
|
|
/* TODO(sergey): Check if it's indeed optimal value for the split kernel. */
|
|
|
|
max_closure_global = 1;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Session::~Session()
|
|
|
|
{
|
|
|
|
if(session_thread) {
|
2014-04-15 13:19:05 +00:00
|
|
|
/* wait for session thread to end */
|
2011-04-27 11:58:34 +00:00
|
|
|
progress.set_cancel("Exiting");
|
2011-08-29 16:54:13 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
gpu_need_tonemap = false;
|
|
|
|
gpu_need_tonemap_cond.notify_all();
|
2011-08-29 16:54:13 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
thread_scoped_lock pause_lock(pause_mutex);
|
|
|
|
pause = false;
|
|
|
|
}
|
|
|
|
pause_cond.notify_all();
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
wait();
|
|
|
|
}
|
|
|
|
|
2014-04-15 13:19:05 +00:00
|
|
|
if(!params.output_path.empty()) {
|
|
|
|
/* tonemap and write out image if requested */
|
|
|
|
delete display;
|
|
|
|
|
|
|
|
display = new DisplayBuffer(device, false);
|
2017-10-20 23:09:59 +00:00
|
|
|
display->reset(buffers->params);
|
2014-04-16 11:49:39 +00:00
|
|
|
tonemap(params.samples);
|
2011-09-08 18:58:07 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
progress.set_status("Writing Image", params.output_path);
|
2017-10-20 23:09:59 +00:00
|
|
|
display->write(params.output_path);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-04-15 13:19:05 +00:00
|
|
|
/* clean up */
|
2017-10-10 00:28:23 +00:00
|
|
|
tile_manager.device_free();
|
2012-10-13 12:38:32 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
delete buffers;
|
|
|
|
delete display;
|
|
|
|
delete scene;
|
|
|
|
delete device;
|
Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
and the initial bounding/splitting is still single threaded, but recursive
splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
code from the Embree raytracer from Intel.
http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
2012-04-28 08:53:59 +00:00
|
|
|
|
|
|
|
TaskScheduler::exit();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Session::start()
|
|
|
|
{
|
|
|
|
session_thread = new thread(function_bind(&Session::run, this));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Session::ready_to_reset()
|
|
|
|
{
|
|
|
|
double dt = time_dt() - reset_time;
|
|
|
|
|
|
|
|
if(!display_outdated)
|
|
|
|
return (dt > params.reset_timeout);
|
|
|
|
else
|
|
|
|
return (dt > params.cancel_timeout);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* GPU Session */
|
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
void Session::reset_gpu(BufferParams& buffer_params, int samples)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2013-02-12 13:06:52 +00:00
|
|
|
thread_scoped_lock pause_lock(pause_mutex);
|
|
|
|
|
2013-08-13 08:43:31 +00:00
|
|
|
/* block for buffer access and reset immediately. we can't do this
|
2012-06-09 17:22:52 +00:00
|
|
|
* in the thread, because we need to allocate an OpenGL buffer, and
|
|
|
|
* that only works in the main thread */
|
2012-09-04 13:29:07 +00:00
|
|
|
thread_scoped_lock display_lock(display_mutex);
|
|
|
|
thread_scoped_lock buffers_lock(buffers_mutex);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
display_outdated = true;
|
|
|
|
reset_time = time_dt();
|
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
reset_(buffer_params, samples);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
gpu_need_tonemap = false;
|
|
|
|
gpu_need_tonemap_cond.notify_all();
|
2011-08-29 10:21:10 +00:00
|
|
|
|
|
|
|
pause_cond.notify_all();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-03-26 08:57:30 +00:00
|
|
|
bool Session::draw_gpu(BufferParams& buffer_params, DeviceDrawParams& draw_params)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* block for buffer access */
|
2012-09-04 13:29:07 +00:00
|
|
|
thread_scoped_lock display_lock(display_mutex);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* first check we already rendered something */
|
|
|
|
if(gpu_draw_ready) {
|
|
|
|
/* then verify the buffers have the expected size, so we don't
|
2012-06-09 17:22:52 +00:00
|
|
|
* draw previous results in a resized window */
|
2011-12-20 12:25:37 +00:00
|
|
|
if(!buffer_params.modified(display->params)) {
|
2011-04-27 11:58:34 +00:00
|
|
|
/* for CUDA we need to do tonemapping still, since we can
|
2012-06-09 17:22:52 +00:00
|
|
|
* only access GL buffers from the main thread */
|
2011-04-27 11:58:34 +00:00
|
|
|
if(gpu_need_tonemap) {
|
2012-09-04 13:29:07 +00:00
|
|
|
thread_scoped_lock buffers_lock(buffers_mutex);
|
2014-04-16 11:49:39 +00:00
|
|
|
tonemap(tile_manager.state.sample);
|
2011-04-27 11:58:34 +00:00
|
|
|
gpu_need_tonemap = false;
|
|
|
|
gpu_need_tonemap_cond.notify_all();
|
|
|
|
}
|
|
|
|
|
2014-03-26 08:57:30 +00:00
|
|
|
display->draw(device, draw_params);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if(display_outdated && (time_dt() - reset_time) > params.text_timeout)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::run_gpu()
|
|
|
|
{
|
2012-10-13 12:38:32 +00:00
|
|
|
bool tiles_written = false;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
reset_time = time_dt();
|
2012-10-23 17:24:23 +00:00
|
|
|
last_update_time = time_dt();
|
2011-04-27 11:58:34 +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 03:22:34 +00:00
|
|
|
progress.set_render_start_time();
|
2012-01-09 16:57:46 +00:00
|
|
|
|
2011-08-28 13:55:59 +00:00
|
|
|
while(!progress.get_cancel()) {
|
2011-08-29 10:21:10 +00:00
|
|
|
/* advance to next tile */
|
2011-08-29 16:54:13 +00:00
|
|
|
bool no_tiles = !tile_manager.next();
|
2011-08-28 13:55:59 +00:00
|
|
|
|
2011-08-29 16:54:13 +00:00
|
|
|
if(params.background) {
|
|
|
|
/* if no work left and in background mode, we can stop immediately */
|
2011-10-30 10:12:34 +00:00
|
|
|
if(no_tiles) {
|
|
|
|
progress.set_status("Finished");
|
2011-08-29 10:21:10 +00:00
|
|
|
break;
|
2011-10-30 10:12:34 +00:00
|
|
|
}
|
2011-08-29 10:21:10 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-08-29 16:54:13 +00:00
|
|
|
/* if in interactive mode, and we are either paused or done for now,
|
2012-06-09 17:22:52 +00:00
|
|
|
* wait for pause condition notify to wake up again */
|
2011-08-29 10:21:10 +00:00
|
|
|
thread_scoped_lock pause_lock(pause_mutex);
|
2011-08-28 13:55:59 +00:00
|
|
|
|
2013-02-13 07:50:41 +00:00
|
|
|
if(!pause && !tile_manager.done()) {
|
|
|
|
/* reset could have happened after no_tiles was set, before this lock.
|
|
|
|
* in this case we shall not wait for pause condition
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
else if(pause || no_tiles) {
|
2011-08-29 16:54:13 +00:00
|
|
|
update_status_time(pause, no_tiles);
|
2011-08-28 13:55:59 +00:00
|
|
|
|
2011-08-29 16:54:13 +00:00
|
|
|
while(1) {
|
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 03:22:34 +00:00
|
|
|
scoped_timer pause_timer;
|
2011-08-29 16:54:13 +00:00
|
|
|
pause_cond.wait(pause_lock);
|
2017-02-23 09:50:46 +00:00
|
|
|
if(pause) {
|
|
|
|
progress.add_skip_time(pause_timer, params.background);
|
|
|
|
}
|
2012-01-09 16:57:46 +00:00
|
|
|
|
2011-08-29 16:54:13 +00:00
|
|
|
update_status_time(pause, no_tiles);
|
|
|
|
progress.set_update();
|
|
|
|
|
|
|
|
if(!pause)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(progress.get_cancel())
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!no_tiles) {
|
2011-08-29 10:21:10 +00:00
|
|
|
/* update scene */
|
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 03:22:34 +00:00
|
|
|
scoped_timer update_timer;
|
2011-08-29 10:21:10 +00:00
|
|
|
update_scene();
|
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 03:22:34 +00:00
|
|
|
progress.add_skip_time(update_timer, params.background);
|
2011-11-22 20:49:33 +00:00
|
|
|
|
2013-12-07 01:29:53 +00:00
|
|
|
if(!device->error_message().empty())
|
2014-12-05 16:17:48 +00:00
|
|
|
progress.set_error(device->error_message());
|
2011-11-22 20:49:33 +00:00
|
|
|
|
2011-08-29 10:21:10 +00:00
|
|
|
if(progress.get_cancel())
|
|
|
|
break;
|
2011-08-29 16:54:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(!no_tiles) {
|
|
|
|
/* buffers mutex is locked entirely while rendering each
|
2012-06-09 17:22:52 +00:00
|
|
|
* sample, and released/reacquired on each iteration to allow
|
|
|
|
* reset and draw in between */
|
2012-09-04 13:29:07 +00:00
|
|
|
thread_scoped_lock buffers_lock(buffers_mutex);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-08-29 10:21:10 +00:00
|
|
|
/* update status and timing */
|
|
|
|
update_status_time();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
/* render */
|
|
|
|
render();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
device->task_wait();
|
2011-11-22 20:49:33 +00:00
|
|
|
|
2013-12-07 01:29:53 +00:00
|
|
|
if(!device->error_message().empty())
|
2012-09-04 13:29:07 +00:00
|
|
|
progress.set_cancel(device->error_message());
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-08-29 10:21:10 +00:00
|
|
|
/* update status and timing */
|
|
|
|
update_status_time();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-08-29 10:21:10 +00:00
|
|
|
gpu_need_tonemap = true;
|
|
|
|
gpu_draw_ready = true;
|
|
|
|
progress.set_update();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-08-29 10:21:10 +00:00
|
|
|
/* wait for tonemap */
|
|
|
|
if(!params.background) {
|
|
|
|
while(gpu_need_tonemap) {
|
|
|
|
if(progress.get_cancel())
|
|
|
|
break;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-08-29 10:21:10 +00:00
|
|
|
gpu_need_tonemap_cond.wait(buffers_lock);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2013-12-07 01:29:53 +00:00
|
|
|
if(!device->error_message().empty())
|
2014-12-05 16:17:48 +00:00
|
|
|
progress.set_error(device->error_message());
|
2011-11-22 20:49:33 +00:00
|
|
|
|
2012-10-13 12:38:32 +00:00
|
|
|
tiles_written = update_progressive_refine(progress.get_cancel());
|
|
|
|
|
2011-08-29 10:21:10 +00:00
|
|
|
if(progress.get_cancel())
|
|
|
|
break;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2012-10-13 12:38:32 +00:00
|
|
|
|
|
|
|
if(!tiles_written)
|
|
|
|
update_progressive_refine(true);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* CPU Session */
|
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
void Session::reset_cpu(BufferParams& buffer_params, int samples)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
thread_scoped_lock reset_lock(delayed_reset.mutex);
|
2013-02-12 13:06:52 +00:00
|
|
|
thread_scoped_lock pause_lock(pause_mutex);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
display_outdated = true;
|
|
|
|
reset_time = time_dt();
|
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
delayed_reset.params = buffer_params;
|
2011-09-16 13:14:02 +00:00
|
|
|
delayed_reset.samples = samples;
|
2011-04-27 11:58:34 +00:00
|
|
|
delayed_reset.do_reset = true;
|
|
|
|
device->task_cancel();
|
2011-08-29 10:21:10 +00:00
|
|
|
|
|
|
|
pause_cond.notify_all();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-03-26 08:57:30 +00:00
|
|
|
bool Session::draw_cpu(BufferParams& buffer_params, DeviceDrawParams& draw_params)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-09-04 13:29:07 +00:00
|
|
|
thread_scoped_lock display_lock(display_mutex);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* first check we already rendered something */
|
|
|
|
if(display->draw_ready()) {
|
|
|
|
/* then verify the buffers have the expected size, so we don't
|
2012-06-09 17:22:52 +00:00
|
|
|
* draw previous results in a resized window */
|
2011-12-20 12:25:37 +00:00
|
|
|
if(!buffer_params.modified(display->params)) {
|
2014-03-26 08:57:30 +00:00
|
|
|
display->draw(device, draw_params);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if(display_outdated && (time_dt() - reset_time) > params.text_timeout)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
bool Session::acquire_tile(Device *tile_device, RenderTile& rtile)
|
|
|
|
{
|
2012-10-13 12:38:32 +00:00
|
|
|
if(progress.get_cancel()) {
|
|
|
|
if(params.progressive_refine == false) {
|
|
|
|
/* for progressive refine current sample should be finished for all tiles */
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2012-09-04 13:29:07 +00:00
|
|
|
|
|
|
|
thread_scoped_lock tile_lock(tile_mutex);
|
|
|
|
|
|
|
|
/* get next tile from manager */
|
2017-05-07 12:40:58 +00:00
|
|
|
Tile *tile;
|
2012-10-23 16:36:53 +00:00
|
|
|
int device_num = device->device_number(tile_device);
|
2012-09-04 13:29:07 +00:00
|
|
|
|
|
|
|
if(!tile_manager.next_tile(tile, device_num))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* fill render tile */
|
2017-05-07 12:40:58 +00:00
|
|
|
rtile.x = tile_manager.state.buffer.full_x + tile->x;
|
|
|
|
rtile.y = tile_manager.state.buffer.full_y + tile->y;
|
|
|
|
rtile.w = tile->w;
|
|
|
|
rtile.h = tile->h;
|
2012-09-04 13:29:07 +00:00
|
|
|
rtile.start_sample = tile_manager.state.sample;
|
|
|
|
rtile.num_samples = tile_manager.state.num_samples;
|
2012-09-17 10:55:18 +00:00
|
|
|
rtile.resolution = tile_manager.state.resolution_divider;
|
2017-05-07 12:40:58 +00:00
|
|
|
rtile.tile_index = tile->index;
|
|
|
|
rtile.task = (tile->state == Tile::DENOISE)? RenderTile::DENOISE: RenderTile::PATH_TRACE;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
|
|
|
tile_lock.unlock();
|
|
|
|
|
2013-01-01 16:15:13 +00:00
|
|
|
/* in case of a permanent buffer, return it, otherwise we will allocate
|
2012-09-04 13:29:07 +00:00
|
|
|
* a new temporary buffer */
|
2017-10-10 00:28:23 +00:00
|
|
|
if(buffers) {
|
2012-09-04 13:29:07 +00:00
|
|
|
tile_manager.state.buffer.get_offset_stride(rtile.offset, rtile.stride);
|
|
|
|
|
|
|
|
rtile.buffer = buffers->buffer.device_pointer;
|
|
|
|
rtile.buffers = buffers;
|
|
|
|
|
|
|
|
device->map_tile(tile_device, rtile);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
if(tile->buffers == NULL) {
|
|
|
|
/* fill buffer parameters */
|
|
|
|
BufferParams buffer_params = tile_manager.params;
|
|
|
|
buffer_params.full_x = rtile.x;
|
|
|
|
buffer_params.full_y = rtile.y;
|
|
|
|
buffer_params.width = rtile.w;
|
|
|
|
buffer_params.height = rtile.h;
|
|
|
|
|
|
|
|
/* allocate buffers */
|
2017-10-10 00:28:23 +00:00
|
|
|
tile->buffers = new RenderBuffers(tile_device);
|
2017-10-20 23:09:59 +00:00
|
|
|
tile->buffers->reset(buffer_params);
|
2017-05-07 12:40:58 +00:00
|
|
|
}
|
2015-05-19 07:31:37 +00:00
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
tile->buffers->params.get_offset_stride(rtile.offset, rtile.stride);
|
2012-10-13 12:38:32 +00:00
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
rtile.buffer = tile->buffers->buffer.device_pointer;
|
|
|
|
rtile.buffers = tile->buffers;
|
2017-10-10 00:28:23 +00:00
|
|
|
rtile.sample = tile_manager.state.sample;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2013-01-01 16:15:13 +00:00
|
|
|
/* this will tag tile as IN PROGRESS in blender-side render pipeline,
|
|
|
|
* which is needed to highlight currently rendering tile before first
|
|
|
|
* sample was processed for it
|
|
|
|
*/
|
|
|
|
update_tile_sample(rtile);
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::update_tile_sample(RenderTile& rtile)
|
|
|
|
{
|
|
|
|
thread_scoped_lock tile_lock(tile_mutex);
|
|
|
|
|
|
|
|
if(update_render_tile_cb) {
|
2012-10-13 12:38:32 +00:00
|
|
|
if(params.progressive_refine == false) {
|
|
|
|
/* todo: optimize this by making it thread safe and removing lock */
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
update_render_tile_cb(rtile, true);
|
2012-10-13 12:38:32 +00:00
|
|
|
}
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
update_status_time();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::release_tile(RenderTile& rtile)
|
|
|
|
{
|
|
|
|
thread_scoped_lock tile_lock(tile_mutex);
|
|
|
|
|
2017-05-19 01:27:38 +00:00
|
|
|
progress.add_finished_tile(rtile.task == RenderTile::DENOISE);
|
2017-01-18 23:39:52 +00:00
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
bool delete_tile;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
if(tile_manager.finish_tile(rtile.tile_index, delete_tile)) {
|
|
|
|
if(write_render_tile_cb && params.progressive_refine == false) {
|
|
|
|
write_render_tile_cb(rtile);
|
2017-10-10 00:28:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if(delete_tile) {
|
|
|
|
delete rtile.buffers;
|
|
|
|
tile_manager.state.tiles[rtile.tile_index].buffers = NULL;
|
2017-05-07 12:40:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(update_render_tile_cb && params.progressive_refine == false) {
|
|
|
|
update_render_tile_cb(rtile, false);
|
2012-10-13 12:38:32 +00:00
|
|
|
}
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
update_status_time();
|
|
|
|
}
|
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
void Session::map_neighbor_tiles(RenderTile *tiles, Device *tile_device)
|
|
|
|
{
|
|
|
|
thread_scoped_lock tile_lock(tile_mutex);
|
|
|
|
|
|
|
|
int center_idx = tiles[4].tile_index;
|
|
|
|
assert(tile_manager.state.tiles[center_idx].state == Tile::DENOISE);
|
|
|
|
BufferParams buffer_params = tile_manager.params;
|
|
|
|
int4 image_region = make_int4(buffer_params.full_x, buffer_params.full_y,
|
|
|
|
buffer_params.full_x + buffer_params.width, buffer_params.full_y + buffer_params.height);
|
|
|
|
|
|
|
|
for(int dy = -1, i = 0; dy <= 1; dy++) {
|
|
|
|
for(int dx = -1; dx <= 1; dx++, i++) {
|
|
|
|
int px = tiles[4].x + dx*params.tile_size.x;
|
|
|
|
int py = tiles[4].y + dy*params.tile_size.y;
|
|
|
|
if(px >= image_region.x && py >= image_region.y &&
|
|
|
|
px < image_region.z && py < image_region.w) {
|
|
|
|
int tile_index = center_idx + dy*tile_manager.state.tile_stride + dx;
|
|
|
|
Tile *tile = &tile_manager.state.tiles[tile_index];
|
|
|
|
assert(tile->buffers);
|
|
|
|
|
|
|
|
tiles[i].buffer = tile->buffers->buffer.device_pointer;
|
|
|
|
tiles[i].x = tile_manager.state.buffer.full_x + tile->x;
|
|
|
|
tiles[i].y = tile_manager.state.buffer.full_y + tile->y;
|
|
|
|
tiles[i].w = tile->w;
|
|
|
|
tiles[i].h = tile->h;
|
|
|
|
tiles[i].buffers = tile->buffers;
|
|
|
|
|
|
|
|
tile->buffers->params.get_offset_stride(tiles[i].offset, tiles[i].stride);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
tiles[i].buffer = (device_ptr)NULL;
|
|
|
|
tiles[i].buffers = NULL;
|
|
|
|
tiles[i].x = clamp(px, image_region.x, image_region.z);
|
|
|
|
tiles[i].y = clamp(py, image_region.y, image_region.w);
|
|
|
|
tiles[i].w = tiles[i].h = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(tiles[4].buffers);
|
|
|
|
device->map_neighbor_tiles(tile_device, tiles);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::unmap_neighbor_tiles(RenderTile *tiles, Device *tile_device)
|
|
|
|
{
|
|
|
|
thread_scoped_lock tile_lock(tile_mutex);
|
|
|
|
device->unmap_neighbor_tiles(tile_device, tiles);
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void Session::run_cpu()
|
|
|
|
{
|
2012-10-13 12:38:32 +00:00
|
|
|
bool tiles_written = false;
|
|
|
|
|
2012-10-23 17:24:23 +00:00
|
|
|
last_update_time = time_dt();
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* reset once to start */
|
|
|
|
thread_scoped_lock reset_lock(delayed_reset.mutex);
|
2012-09-04 13:29:07 +00:00
|
|
|
thread_scoped_lock buffers_lock(buffers_mutex);
|
|
|
|
thread_scoped_lock display_lock(display_mutex);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
reset_(delayed_reset.params, delayed_reset.samples);
|
2011-04-27 11:58:34 +00:00
|
|
|
delayed_reset.do_reset = false;
|
|
|
|
}
|
|
|
|
|
2011-08-28 13:55:59 +00:00
|
|
|
while(!progress.get_cancel()) {
|
2011-08-29 10:21:10 +00:00
|
|
|
/* advance to next tile */
|
2011-08-29 16:54:13 +00:00
|
|
|
bool no_tiles = !tile_manager.next();
|
2011-08-29 10:21:10 +00:00
|
|
|
bool need_tonemap = false;
|
2011-08-28 13:55:59 +00:00
|
|
|
|
2011-08-29 16:54:13 +00:00
|
|
|
if(params.background) {
|
|
|
|
/* if no work left and in background mode, we can stop immediately */
|
2011-10-30 10:12:34 +00:00
|
|
|
if(no_tiles) {
|
|
|
|
progress.set_status("Finished");
|
2011-08-29 10:21:10 +00:00
|
|
|
break;
|
2011-10-30 10:12:34 +00:00
|
|
|
}
|
2011-08-29 10:21:10 +00:00
|
|
|
}
|
|
|
|
else {
|
2011-08-29 16:54:13 +00:00
|
|
|
/* if in interactive mode, and we are either paused or done for now,
|
2012-06-09 17:22:52 +00:00
|
|
|
* wait for pause condition notify to wake up again */
|
2011-08-29 10:21:10 +00:00
|
|
|
thread_scoped_lock pause_lock(pause_mutex);
|
2011-08-29 16:54:13 +00:00
|
|
|
|
2013-02-12 13:06:52 +00:00
|
|
|
if(!pause && delayed_reset.do_reset) {
|
|
|
|
/* reset once to start */
|
|
|
|
thread_scoped_lock reset_lock(delayed_reset.mutex);
|
|
|
|
thread_scoped_lock buffers_lock(buffers_mutex);
|
|
|
|
thread_scoped_lock display_lock(display_mutex);
|
|
|
|
|
|
|
|
reset_(delayed_reset.params, delayed_reset.samples);
|
|
|
|
delayed_reset.do_reset = false;
|
|
|
|
}
|
|
|
|
else if(pause || no_tiles) {
|
2011-08-29 16:54:13 +00:00
|
|
|
update_status_time(pause, no_tiles);
|
|
|
|
|
|
|
|
while(1) {
|
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 03:22:34 +00:00
|
|
|
scoped_timer pause_timer;
|
2011-08-29 16:54:13 +00:00
|
|
|
pause_cond.wait(pause_lock);
|
2017-02-23 09:50:46 +00:00
|
|
|
if(pause) {
|
|
|
|
progress.add_skip_time(pause_timer, params.background);
|
|
|
|
}
|
2012-01-09 16:57:46 +00:00
|
|
|
|
2011-08-29 16:54:13 +00:00
|
|
|
update_status_time(pause, no_tiles);
|
|
|
|
progress.set_update();
|
|
|
|
|
|
|
|
if(!pause)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(progress.get_cancel())
|
|
|
|
break;
|
2011-08-29 10:21:10 +00:00
|
|
|
}
|
2011-08-28 13:55:59 +00:00
|
|
|
|
2011-08-29 16:54:13 +00:00
|
|
|
if(!no_tiles) {
|
2011-08-29 10:21:10 +00:00
|
|
|
/* buffers mutex is locked entirely while rendering each
|
2012-06-09 17:22:52 +00:00
|
|
|
* sample, and released/reacquired on each iteration to allow
|
|
|
|
* reset and draw in between */
|
2012-09-04 13:29:07 +00:00
|
|
|
thread_scoped_lock buffers_lock(buffers_mutex);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* update scene */
|
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 03:22:34 +00:00
|
|
|
scoped_timer update_timer;
|
2011-04-27 11:58:34 +00:00
|
|
|
update_scene();
|
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 03:22:34 +00:00
|
|
|
progress.add_skip_time(update_timer, params.background);
|
2011-11-22 20:49:33 +00:00
|
|
|
|
2013-12-07 01:29:53 +00:00
|
|
|
if(!device->error_message().empty())
|
2014-12-05 16:17:48 +00:00
|
|
|
progress.set_error(device->error_message());
|
2011-11-22 20:49:33 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if(progress.get_cancel())
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* update status and timing */
|
|
|
|
update_status_time();
|
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
/* render */
|
|
|
|
render();
|
2011-08-29 10:21:10 +00:00
|
|
|
|
|
|
|
/* update status and timing */
|
|
|
|
update_status_time();
|
|
|
|
|
2011-09-08 18:58:07 +00:00
|
|
|
if(!params.background)
|
|
|
|
need_tonemap = true;
|
2011-11-22 20:49:33 +00:00
|
|
|
|
2013-12-07 01:29:53 +00:00
|
|
|
if(!device->error_message().empty())
|
2014-12-05 16:17:48 +00:00
|
|
|
progress.set_error(device->error_message());
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
device->task_wait();
|
|
|
|
|
|
|
|
{
|
|
|
|
thread_scoped_lock reset_lock(delayed_reset.mutex);
|
2012-09-04 13:29:07 +00:00
|
|
|
thread_scoped_lock buffers_lock(buffers_mutex);
|
|
|
|
thread_scoped_lock display_lock(display_mutex);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if(delayed_reset.do_reset) {
|
|
|
|
/* reset rendering if request from main thread */
|
|
|
|
delayed_reset.do_reset = false;
|
2011-12-20 12:25:37 +00:00
|
|
|
reset_(delayed_reset.params, delayed_reset.samples);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2011-08-29 10:21:10 +00:00
|
|
|
else if(need_tonemap) {
|
2011-04-27 11:58:34 +00:00
|
|
|
/* tonemap only if we do not reset, we don't we don't
|
2014-04-16 11:49:39 +00:00
|
|
|
* want to show the result of an incomplete sample */
|
|
|
|
tonemap(tile_manager.state.sample);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2011-11-22 20:49:33 +00:00
|
|
|
|
2013-12-07 01:29:53 +00:00
|
|
|
if(!device->error_message().empty())
|
2014-12-05 16:17:48 +00:00
|
|
|
progress.set_error(device->error_message());
|
2012-10-13 12:38:32 +00:00
|
|
|
|
|
|
|
tiles_written = update_progressive_refine(progress.get_cancel());
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
progress.set_update();
|
|
|
|
}
|
2012-10-13 12:38:32 +00:00
|
|
|
|
|
|
|
if(!tiles_written)
|
|
|
|
update_progressive_refine(true);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2015-05-09 14:05:49 +00:00
|
|
|
DeviceRequestedFeatures Session::get_requested_device_features()
|
|
|
|
{
|
2015-06-05 17:50:22 +00:00
|
|
|
/* TODO(sergey): Consider moving this to the Scene level. */
|
2015-05-09 14:05:49 +00:00
|
|
|
DeviceRequestedFeatures requested_features;
|
|
|
|
requested_features.experimental = params.experimental;
|
2016-05-23 10:36:31 +00:00
|
|
|
|
|
|
|
requested_features.max_closure = get_max_closure_count();
|
|
|
|
scene->shader_manager->get_requested_features(
|
|
|
|
scene,
|
|
|
|
&requested_features);
|
2015-05-09 14:28:00 +00:00
|
|
|
if(!params.background) {
|
2016-05-23 10:36:31 +00:00
|
|
|
/* Avoid too much re-compilations for viewport render. */
|
2015-05-09 14:28:00 +00:00
|
|
|
requested_features.max_closure = 64;
|
2015-06-01 14:36:44 +00:00
|
|
|
requested_features.max_nodes_group = NODE_GROUP_LEVEL_MAX;
|
2015-05-09 14:28:00 +00:00
|
|
|
requested_features.nodes_features = NODE_FEATURE_ALL;
|
|
|
|
}
|
2015-06-05 17:50:22 +00:00
|
|
|
|
|
|
|
/* This features are not being tweaked as often as shaders,
|
|
|
|
* so could be done selective magic for the viewport as well.
|
|
|
|
*/
|
|
|
|
requested_features.use_hair = false;
|
|
|
|
requested_features.use_object_motion = false;
|
|
|
|
requested_features.use_camera_motion = scene->camera->use_motion;
|
|
|
|
foreach(Object *object, scene->objects) {
|
|
|
|
Mesh *mesh = object->mesh;
|
2016-05-07 22:09:08 +00:00
|
|
|
if(mesh->num_curves()) {
|
2015-06-05 17:50:22 +00:00
|
|
|
requested_features.use_hair = true;
|
|
|
|
}
|
|
|
|
requested_features.use_object_motion |= object->use_motion | mesh->use_motion_blur;
|
|
|
|
requested_features.use_camera_motion |= mesh->use_motion_blur;
|
2016-08-15 13:08:38 +00:00
|
|
|
#ifdef WITH_OPENSUBDIV
|
|
|
|
if(mesh->subdivision_type != Mesh::SUBDIVISION_NONE) {
|
|
|
|
requested_features.use_patch_evaluation = true;
|
|
|
|
}
|
|
|
|
#endif
|
2017-03-21 12:55:27 +00:00
|
|
|
if(object->is_shadow_catcher) {
|
|
|
|
requested_features.use_shadow_tricks = true;
|
|
|
|
}
|
2015-06-05 17:50:22 +00:00
|
|
|
}
|
|
|
|
|
2015-07-18 13:34:32 +00:00
|
|
|
BakeManager *bake_manager = scene->bake_manager;
|
|
|
|
requested_features.use_baking = bake_manager->get_baking();
|
2015-11-22 08:54:51 +00:00
|
|
|
requested_features.use_integrator_branched = (scene->integrator->method == Integrator::BRANCHED_PATH);
|
2017-06-09 07:11:54 +00:00
|
|
|
requested_features.use_denoising = params.use_denoising;
|
2015-07-18 13:34:32 +00:00
|
|
|
|
2015-05-09 14:05:49 +00:00
|
|
|
return requested_features;
|
|
|
|
}
|
|
|
|
|
2017-05-18 02:14:12 +00:00
|
|
|
void Session::load_kernels(bool lock_scene)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-05-18 02:14:12 +00:00
|
|
|
thread_scoped_lock scene_lock;
|
|
|
|
if(lock_scene) {
|
|
|
|
scene_lock = thread_scoped_lock(scene->mutex);
|
|
|
|
}
|
2014-05-19 17:17:57 +00:00
|
|
|
|
2017-05-18 02:14:12 +00:00
|
|
|
DeviceRequestedFeatures requested_features = get_requested_device_features();
|
|
|
|
|
|
|
|
if(!kernels_loaded || loaded_kernel_features.modified(requested_features)) {
|
2012-02-23 19:48:18 +00:00
|
|
|
progress.set_status("Loading render kernels (may take a few minutes the first time)");
|
2011-09-02 00:10:03 +00:00
|
|
|
|
2016-12-30 04:05:40 +00:00
|
|
|
scoped_timer timer;
|
|
|
|
|
2015-07-18 14:00:07 +00:00
|
|
|
VLOG(2) << "Requested features:\n" << requested_features;
|
|
|
|
if(!device->load_kernels(requested_features)) {
|
2012-02-23 19:48:18 +00:00
|
|
|
string message = device->error_message();
|
2013-12-07 01:29:53 +00:00
|
|
|
if(message.empty())
|
2012-02-23 19:48:18 +00:00
|
|
|
message = "Failed loading render kernel, see console for errors";
|
2011-11-22 20:49:33 +00:00
|
|
|
|
2014-12-05 16:17:48 +00:00
|
|
|
progress.set_error(message);
|
2012-02-23 19:48:18 +00:00
|
|
|
progress.set_status("Error", message);
|
|
|
|
progress.set_update();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-30 04:05:40 +00:00
|
|
|
progress.add_skip_time(timer, false);
|
|
|
|
VLOG(1) << "Total time spent loading kernels: " << time_dt() - timer.get_start();
|
|
|
|
|
2012-02-23 19:48:18 +00:00
|
|
|
kernels_loaded = true;
|
2017-05-18 02:14:12 +00:00
|
|
|
loaded_kernel_features = requested_features;
|
2011-09-02 00:10:03 +00:00
|
|
|
}
|
2014-05-19 17:17:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Session::run()
|
|
|
|
{
|
|
|
|
/* load kernels */
|
|
|
|
load_kernels();
|
2011-09-02 00:10:03 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* session thread loop */
|
|
|
|
progress.set_status("Waiting for render to start");
|
|
|
|
|
|
|
|
/* run */
|
|
|
|
if(!progress.get_cancel()) {
|
2012-09-04 13:29:07 +00:00
|
|
|
/* reset number of rendered samples */
|
|
|
|
progress.reset_sample();
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if(device_use_gl)
|
|
|
|
run_gpu();
|
|
|
|
else
|
|
|
|
run_cpu();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* progress update */
|
|
|
|
if(progress.get_cancel())
|
2011-11-22 20:49:33 +00:00
|
|
|
progress.set_status("Cancel", progress.get_cancel_message());
|
2011-04-27 11:58:34 +00:00
|
|
|
else
|
|
|
|
progress.set_update();
|
|
|
|
}
|
|
|
|
|
2014-03-26 08:57:30 +00:00
|
|
|
bool Session::draw(BufferParams& buffer_params, DeviceDrawParams &draw_params)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
if(device_use_gl)
|
2014-03-26 08:57:30 +00:00
|
|
|
return draw_gpu(buffer_params, draw_params);
|
2011-04-27 11:58:34 +00:00
|
|
|
else
|
2014-03-26 08:57:30 +00:00
|
|
|
return draw_cpu(buffer_params, draw_params);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
void Session::reset_(BufferParams& buffer_params, int samples)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-10-10 00:28:23 +00:00
|
|
|
if(buffers && buffer_params.modified(tile_manager.params)) {
|
|
|
|
gpu_draw_ready = false;
|
2017-10-20 23:09:59 +00:00
|
|
|
buffers->reset(buffer_params);
|
2017-10-10 00:28:23 +00:00
|
|
|
if(display) {
|
2017-10-20 23:09:59 +00:00
|
|
|
display->reset(buffer_params);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
tile_manager.reset(buffer_params, samples);
|
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 03:22:34 +00:00
|
|
|
progress.reset_sample();
|
2011-04-27 11:58:34 +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 03:22:34 +00:00
|
|
|
bool show_progress = params.background || tile_manager.get_num_effective_samples() != INT_MAX;
|
|
|
|
progress.set_total_pixel_samples(show_progress? tile_manager.state.total_pixel_samples : 0);
|
2012-01-09 16:57:46 +00:00
|
|
|
|
|
|
|
if(!params.background)
|
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 03:22:34 +00:00
|
|
|
progress.set_start_time();
|
|
|
|
progress.set_render_start_time();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
void Session::reset(BufferParams& buffer_params, int samples)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
if(device_use_gl)
|
2011-12-20 12:25:37 +00:00
|
|
|
reset_gpu(buffer_params, samples);
|
2011-04-27 11:58:34 +00:00
|
|
|
else
|
2011-12-20 12:25:37 +00:00
|
|
|
reset_cpu(buffer_params, samples);
|
2011-08-28 13:55:59 +00:00
|
|
|
}
|
|
|
|
|
2011-09-16 13:14:02 +00:00
|
|
|
void Session::set_samples(int samples)
|
2011-08-28 13:55:59 +00:00
|
|
|
{
|
2011-09-16 13:14:02 +00:00
|
|
|
if(samples != params.samples) {
|
|
|
|
params.samples = samples;
|
|
|
|
tile_manager.set_samples(samples);
|
2011-08-29 10:21:10 +00:00
|
|
|
|
2011-08-29 16:54:13 +00:00
|
|
|
{
|
|
|
|
thread_scoped_lock pause_lock(pause_mutex);
|
|
|
|
}
|
2011-08-29 10:21:10 +00:00
|
|
|
pause_cond.notify_all();
|
2011-08-28 13:55:59 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2011-08-29 10:21:10 +00:00
|
|
|
void Session::set_pause(bool pause_)
|
|
|
|
{
|
2011-08-29 16:54:13 +00:00
|
|
|
bool notify = false;
|
|
|
|
|
2011-08-29 10:21:10 +00:00
|
|
|
{
|
|
|
|
thread_scoped_lock pause_lock(pause_mutex);
|
2011-08-29 16:54:13 +00:00
|
|
|
|
|
|
|
if(pause != pause_) {
|
|
|
|
pause = pause_;
|
|
|
|
notify = true;
|
|
|
|
}
|
2011-08-29 10:21:10 +00:00
|
|
|
}
|
|
|
|
|
2011-08-29 16:54:13 +00:00
|
|
|
if(notify)
|
|
|
|
pause_cond.notify_all();
|
2011-08-29 10:21:10 +00:00
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void Session::wait()
|
|
|
|
{
|
|
|
|
session_thread->join();
|
|
|
|
delete session_thread;
|
|
|
|
|
|
|
|
session_thread = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Session::update_scene()
|
|
|
|
{
|
|
|
|
thread_scoped_lock scene_lock(scene->mutex);
|
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
/* update camera if dimensions changed for progressive render. the camera
|
2012-06-09 17:22:52 +00:00
|
|
|
* knows nothing about progressive or cropped rendering, it just gets the
|
|
|
|
* image dimensions passed in */
|
2011-04-27 11:58:34 +00:00
|
|
|
Camera *cam = scene->camera;
|
2011-12-21 13:48:35 +00:00
|
|
|
int width = tile_manager.state.buffer.full_width;
|
|
|
|
int height = tile_manager.state.buffer.full_height;
|
2013-04-15 21:38:31 +00:00
|
|
|
int resolution = tile_manager.state.resolution_divider;
|
2011-12-20 12:25:37 +00:00
|
|
|
|
|
|
|
if(width != cam->width || height != cam->height) {
|
|
|
|
cam->width = width;
|
|
|
|
cam->height = height;
|
2013-04-15 21:38:31 +00:00
|
|
|
cam->resolution = resolution;
|
2011-04-27 11:58:34 +00:00
|
|
|
cam->tag_update();
|
|
|
|
}
|
|
|
|
|
2014-01-02 21:05:07 +00:00
|
|
|
/* number of samples is needed by multi jittered
|
|
|
|
* sampling pattern and by baking */
|
2013-06-07 16:06:22 +00:00
|
|
|
Integrator *integrator = scene->integrator;
|
2014-01-02 21:05:07 +00:00
|
|
|
BakeManager *bake_manager = scene->bake_manager;
|
2013-06-07 16:06:22 +00:00
|
|
|
|
2014-01-02 21:05:07 +00:00
|
|
|
if(integrator->sampling_pattern == SAMPLING_PATTERN_CMJ ||
|
|
|
|
bake_manager->get_baking())
|
|
|
|
{
|
2013-06-07 16:06:22 +00:00
|
|
|
int aa_samples = tile_manager.num_samples;
|
|
|
|
|
|
|
|
if(aa_samples != integrator->aa_samples) {
|
|
|
|
integrator->aa_samples = aa_samples;
|
|
|
|
integrator->tag_update(scene);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* update scene */
|
2012-09-04 13:29:07 +00:00
|
|
|
if(scene->need_update()) {
|
2017-05-18 02:14:12 +00:00
|
|
|
load_kernels(false);
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
progress.set_status("Updating Scene");
|
Cycles: Stop rendering when bad_alloc happens
This is an attempt to gracefully handle out-of-memory events
and stop rendering with an error message instead of a crash.
It uses bad_alloc exception, and usually i'm not really fond
of exceptions, but for such limited use for errors from which
we can't recover it should be fine.
Ideally we'll need to stop full Cycles Session, so viewport
render and persistent images frees all the memory, but that
we can support later, since it'll mainly related on telling
Blender what to do.
General rules are:
- Use as less exception handles as possible, try to find a
most geenric pace where to handle those.
For example, ccl::Session.
- Threads needs own handling, exception trap from one thread
will not catch exceptions from other threads.
That's why BVH build needs own thing.
Reviewers: brecht, juicyfruit, dingto, lukasstockner97
Differential Revision: https://developer.blender.org/D1898
2016-04-20 14:15:11 +00:00
|
|
|
MEM_GUARDED_CALL(&progress, scene->device_update, device, progress);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2011-08-29 16:54:13 +00:00
|
|
|
void Session::update_status_time(bool show_pause, bool show_done)
|
2011-04-27 11:58:34 +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 03:22:34 +00:00
|
|
|
int progressive_sample = tile_manager.state.sample;
|
|
|
|
int num_samples = tile_manager.get_num_effective_samples();
|
|
|
|
|
2017-05-19 01:27:38 +00:00
|
|
|
int tile = progress.get_rendered_tiles();
|
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 03:22:34 +00:00
|
|
|
int num_tiles = tile_manager.state.num_tiles;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* update status */
|
2011-08-29 16:54:13 +00:00
|
|
|
string status, substatus;
|
|
|
|
|
2012-09-04 13:29:07 +00:00
|
|
|
if(!params.progressive) {
|
2015-06-18 14:15:37 +00:00
|
|
|
const bool is_cpu = params.device.type == DEVICE_CPU;
|
2017-05-19 01:27:38 +00:00
|
|
|
const bool rendering_finished = (tile == num_tiles);
|
2017-01-18 23:41:55 +00:00
|
|
|
const bool is_last_tile = (tile + 1) == num_tiles;
|
2012-11-05 08:04:41 +00:00
|
|
|
|
2017-09-27 23:59:11 +00:00
|
|
|
substatus = string_printf("Rendered %d/%d Tiles", tile, num_tiles);
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2017-05-19 01:27:38 +00:00
|
|
|
if(!rendering_finished && (device->show_samples() || (is_cpu && is_last_tile))) {
|
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 03:22:34 +00:00
|
|
|
/* Some devices automatically support showing the sample number:
|
|
|
|
* - CUDADevice
|
2017-01-13 14:24:56 +00:00
|
|
|
* - OpenCLDevice when using the megakernel (the split kernel renders multiple
|
|
|
|
* samples at the same time, so the current sample isn't really defined)
|
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 03:22:34 +00:00
|
|
|
* - CPUDevice when using one thread
|
|
|
|
* For these devices, the current sample is always shown.
|
|
|
|
*
|
|
|
|
* The other option is when the last tile is currently being rendered by the CPU.
|
Cycles: OpenCL kernel split
This commit contains all the work related on the AMD megakernel split work
which was mainly done by Varun Sundar, George Kyriazis and Lenny Wang, plus
some help from Sergey Sharybin, Martijn Berger, Thomas Dinges and likely
someone else which we're forgetting to mention.
Currently only AMD cards are enabled for the new split kernel, but it is
possible to force split opencl kernel to be used by setting the following
environment variable: CYCLES_OPENCL_SPLIT_KERNEL_TEST=1.
Not all the features are supported yet, and that being said no motion blur,
camera blur, SSS and volumetrics for now. Also transparent shadows are
disabled on AMD device because of some compiler bug.
This kernel is also only implements regular path tracing and supporting
branched one will take a bit. Branched path tracing is exposed to the
interface still, which is a bit misleading and will be hidden there soon.
More feature will be enabled once they're ported to the split kernel and
tested.
Neither regular CPU nor CUDA has any difference, they're generating the
same exact code, which means no regressions/improvements there.
Based on the research paper:
https://research.nvidia.com/sites/default/files/publications/laine2013hpg_paper.pdf
Here's the documentation:
https://docs.google.com/document/d/1LuXW-CV-sVJkQaEGZlMJ86jZ8FmoPfecaMdR-oiWbUY/edit
Design discussion of the patch:
https://developer.blender.org/T44197
Differential Revision: https://developer.blender.org/D1200
2015-05-09 14:34:30 +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 03:22:34 +00:00
|
|
|
substatus += string_printf(", Sample %d/%d", progress.get_current_sample(), num_samples);
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
2017-05-19 01:27:38 +00:00
|
|
|
if(params.use_denoising) {
|
|
|
|
substatus += string_printf(", Denoised %d tiles", progress.get_denoised_tiles());
|
|
|
|
}
|
2012-09-04 13:29:07 +00:00
|
|
|
}
|
2016-03-11 20:33:56 +00:00
|
|
|
else if(tile_manager.num_samples == INT_MAX)
|
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 03:22:34 +00:00
|
|
|
substatus = string_printf("Path Tracing Sample %d", progressive_sample+1);
|
2011-04-27 11:58:34 +00:00
|
|
|
else
|
2016-04-19 10:54:29 +00:00
|
|
|
substatus = string_printf("Path Tracing Sample %d/%d",
|
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 03:22:34 +00:00
|
|
|
progressive_sample+1,
|
|
|
|
num_samples);
|
2011-08-29 16:54:13 +00:00
|
|
|
|
2013-06-24 22:41:24 +00:00
|
|
|
if(show_pause) {
|
2011-08-29 16:54:13 +00:00
|
|
|
status = "Paused";
|
2013-06-24 22:41:24 +00:00
|
|
|
}
|
|
|
|
else if(show_done) {
|
2011-08-29 16:54:13 +00:00
|
|
|
status = "Done";
|
2017-07-24 23:35:33 +00:00
|
|
|
progress.set_end_time(); /* Save end time so that further calls to get_time are accurate. */
|
2013-06-24 22:41:24 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
status = substatus;
|
2013-12-07 01:29:53 +00:00
|
|
|
substatus.clear();
|
2013-06-24 22:41:24 +00:00
|
|
|
}
|
2011-08-29 16:54:13 +00:00
|
|
|
|
|
|
|
progress.set_status(status, substatus);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
void Session::render()
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2017-09-27 01:53:03 +00:00
|
|
|
/* Clear buffers. */
|
2017-10-21 18:57:31 +00:00
|
|
|
if(buffers && tile_manager.state.sample == tile_manager.range_start_sample) {
|
2017-10-20 23:09:59 +00:00
|
|
|
buffers->zero();
|
2017-09-27 01:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add path trace task. */
|
2017-05-07 12:40:58 +00:00
|
|
|
DeviceTask task(DeviceTask::RENDER);
|
2012-09-04 13:29:07 +00:00
|
|
|
|
|
|
|
task.acquire_tile = function_bind(&Session::acquire_tile, this, _1, _2);
|
|
|
|
task.release_tile = function_bind(&Session::release_tile, this, _1);
|
2017-05-07 12:40:58 +00:00
|
|
|
task.map_neighbor_tiles = function_bind(&Session::map_neighbor_tiles, this, _1, _2);
|
|
|
|
task.unmap_neighbor_tiles = function_bind(&Session::unmap_neighbor_tiles, this, _1, _2);
|
2012-09-04 13:29:07 +00:00
|
|
|
task.get_cancel = function_bind(&Progress::get_cancel, &this->progress);
|
|
|
|
task.update_tile_sample = function_bind(&Session::update_tile_sample, this, _1);
|
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 03:22:34 +00:00
|
|
|
task.update_progress_sample = function_bind(&Progress::add_samples, &this->progress, _1, _2);
|
2012-10-13 12:38:32 +00:00
|
|
|
task.need_finish_queue = params.progressive_refine;
|
2013-08-23 14:34:34 +00:00
|
|
|
task.integrator_branched = scene->integrator->method == Integrator::BRANCHED_PATH;
|
2015-05-09 14:09:07 +00:00
|
|
|
task.requested_tile_size = params.tile_size;
|
2017-01-20 08:05:32 +00:00
|
|
|
task.passes_size = tile_manager.params.get_passes_size();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2017-05-07 12:40:58 +00:00
|
|
|
if(params.use_denoising) {
|
|
|
|
task.denoising_radius = params.denoising_radius;
|
|
|
|
task.denoising_strength = params.denoising_strength;
|
|
|
|
task.denoising_feature_strength = params.denoising_feature_strength;
|
|
|
|
task.denoising_relative_pca = params.denoising_relative_pca;
|
|
|
|
|
|
|
|
assert(!scene->film->need_update);
|
|
|
|
task.pass_stride = scene->film->pass_stride;
|
|
|
|
task.pass_denoising_data = scene->film->denoising_data_offset;
|
|
|
|
task.pass_denoising_clean = scene->film->denoising_clean_offset;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
device->task_add(task);
|
|
|
|
}
|
|
|
|
|
2014-04-16 11:49:39 +00:00
|
|
|
void Session::tonemap(int sample)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
/* add tonemap task */
|
2013-08-30 23:49:38 +00:00
|
|
|
DeviceTask task(DeviceTask::FILM_CONVERT);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-12-21 13:48:35 +00:00
|
|
|
task.x = tile_manager.state.buffer.full_x;
|
|
|
|
task.y = tile_manager.state.buffer.full_y;
|
|
|
|
task.w = tile_manager.state.buffer.width;
|
|
|
|
task.h = tile_manager.state.buffer.height;
|
2013-08-30 23:49:38 +00:00
|
|
|
task.rgba_byte = display->rgba_byte.device_pointer;
|
|
|
|
task.rgba_half = display->rgba_half.device_pointer;
|
2011-04-27 11:58:34 +00:00
|
|
|
task.buffer = buffers->buffer.device_pointer;
|
2014-04-16 11:49:39 +00:00
|
|
|
task.sample = sample;
|
2011-12-21 13:48:35 +00:00
|
|
|
tile_manager.state.buffer.get_offset_stride(task.offset, task.stride);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-08-29 11:47:03 +00:00
|
|
|
if(task.w > 0 && task.h > 0) {
|
|
|
|
device->task_add(task);
|
|
|
|
device->task_wait();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-08-29 11:47:03 +00:00
|
|
|
/* set display to new size */
|
|
|
|
display->draw_set(task.w, task.h);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
display_outdated = false;
|
|
|
|
}
|
|
|
|
|
2012-10-13 12:38:32 +00:00
|
|
|
bool Session::update_progressive_refine(bool cancel)
|
|
|
|
{
|
|
|
|
int sample = tile_manager.state.sample + 1;
|
2013-04-05 17:57:26 +00:00
|
|
|
bool write = sample == tile_manager.num_samples || cancel;
|
2012-10-23 17:24:23 +00:00
|
|
|
|
|
|
|
double current_time = time_dt();
|
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
if(current_time - last_update_time < params.progressive_update_timeout) {
|
2012-10-23 17:24:23 +00:00
|
|
|
/* if last sample was processed, we need to write buffers anyway */
|
2015-04-06 14:28:25 +00:00
|
|
|
if(!write && sample != 1)
|
2012-10-23 17:24:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
2012-10-13 12:38:32 +00:00
|
|
|
|
|
|
|
if(params.progressive_refine) {
|
2017-10-10 00:28:23 +00:00
|
|
|
foreach(Tile& tile, tile_manager.state.tiles) {
|
|
|
|
if(!tile.buffers) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
RenderTile rtile;
|
|
|
|
rtile.x = tile_manager.state.buffer.full_x + tile.x;
|
|
|
|
rtile.y = tile_manager.state.buffer.full_y + tile.y;
|
|
|
|
rtile.w = tile.w;
|
|
|
|
rtile.h = tile.h;
|
2012-10-13 12:38:32 +00:00
|
|
|
rtile.sample = sample;
|
2017-10-10 00:28:23 +00:00
|
|
|
rtile.buffers = tile.buffers;
|
2012-10-13 12:38:32 +00:00
|
|
|
|
2015-05-19 07:28:49 +00:00
|
|
|
if(write) {
|
|
|
|
if(write_render_tile_cb)
|
|
|
|
write_render_tile_cb(rtile);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(update_render_tile_cb)
|
2017-05-07 12:40:58 +00:00
|
|
|
update_render_tile_cb(rtile, true);
|
2015-05-19 07:28:49 +00:00
|
|
|
}
|
2012-10-13 12:38:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-23 17:24:23 +00:00
|
|
|
last_update_time = current_time;
|
|
|
|
|
|
|
|
return write;
|
2012-10-13 12:38:32 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-11-09 08:46:53 +00:00
|
|
|
void Session::device_free()
|
|
|
|
{
|
|
|
|
scene->device_free();
|
|
|
|
|
2017-10-10 00:28:23 +00:00
|
|
|
tile_manager.device_free();
|
2012-11-09 08:46:53 +00:00
|
|
|
|
|
|
|
/* used from background render only, so no need to
|
|
|
|
* re-create render/display buffers here
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
2015-05-09 14:15:58 +00:00
|
|
|
int Session::get_max_closure_count()
|
|
|
|
{
|
|
|
|
int max_closures = 0;
|
|
|
|
for(int i = 0; i < scene->shaders.size(); i++) {
|
|
|
|
int num_closures = scene->shaders[i]->graph->get_num_closures();
|
|
|
|
max_closures = max(max_closures, num_closures);
|
|
|
|
}
|
|
|
|
max_closure_global = max(max_closure_global, max_closures);
|
|
|
|
return max_closure_global;
|
|
|
|
}
|
|
|
|
|
2012-10-13 12:38:32 +00:00
|
|
|
CCL_NAMESPACE_END
|