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
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifndef __SESSION_H__
|
|
|
|
|
#define __SESSION_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 "device/device.h"
|
2020-03-19 09:33:03 +01:00
|
|
|
#include "render/buffers.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/shader.h"
|
2018-11-29 02:06:30 +01:00
|
|
|
#include "render/stats.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/tile.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 "util/util_progress.h"
|
|
|
|
|
#include "util/util_stats.h"
|
|
|
|
|
#include "util/util_thread.h"
|
|
|
|
|
#include "util/util_vector.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
class BufferParams;
|
2011-04-27 11:58:34 +00:00
|
|
|
class Device;
|
|
|
|
|
class DeviceScene;
|
2015-05-09 19:05:49 +05:00
|
|
|
class DeviceRequestedFeatures;
|
2011-04-27 11:58:34 +00:00
|
|
|
class DisplayBuffer;
|
|
|
|
|
class Progress;
|
|
|
|
|
class RenderBuffers;
|
|
|
|
|
class Scene;
|
|
|
|
|
|
|
|
|
|
/* Session Parameters */
|
|
|
|
|
|
|
|
|
|
class SessionParams {
|
|
|
|
|
public:
|
2012-01-04 18:06:32 +00:00
|
|
|
DeviceInfo device;
|
2011-04-27 11:58:34 +00:00
|
|
|
bool background;
|
2012-10-13 12:38:32 +00:00
|
|
|
bool progressive_refine;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool progressive;
|
2011-12-12 22:51:35 +00:00
|
|
|
bool experimental;
|
2011-09-16 13:14:02 +00:00
|
|
|
int samples;
|
2012-09-04 13:29:07 +00:00
|
|
|
int2 tile_size;
|
2013-09-03 22:39:21 +00:00
|
|
|
TileOrder tile_order;
|
2012-09-17 10:55:18 +00:00
|
|
|
int start_resolution;
|
2020-02-25 13:31:08 +01:00
|
|
|
int denoising_start_sample;
|
2017-08-15 00:11:52 +02:00
|
|
|
int pixel_size;
|
2011-08-24 10:44:04 +00:00
|
|
|
int threads;
|
2020-03-05 12:05:42 +01:00
|
|
|
bool adaptive_sampling;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-29 02:06:30 +01:00
|
|
|
bool use_profiling;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-30 23:49:38 +00:00
|
|
|
bool display_buffer_linear;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2019-02-06 12:57:10 +01:00
|
|
|
DenoiseParams denoising;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
double cancel_timeout;
|
|
|
|
|
double reset_timeout;
|
|
|
|
|
double text_timeout;
|
2015-02-21 17:29:27 +05:00
|
|
|
double progressive_update_timeout;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-16 16:43:28 +03:00
|
|
|
ShadingSystem shadingsystem;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-03-15 22:07:37 +01:00
|
|
|
function<bool(const uchar *pixels, int width, int height, int channels)> write_render_cb;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
SessionParams()
|
|
|
|
|
{
|
|
|
|
|
background = false;
|
2012-10-13 12:38:32 +00:00
|
|
|
progressive_refine = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-09-14 22:26:55 +00:00
|
|
|
progressive = false;
|
2011-12-12 22:51:35 +00:00
|
|
|
experimental = false;
|
2019-03-14 17:29:18 +01:00
|
|
|
samples = 1024;
|
2012-09-04 13:29:07 +00:00
|
|
|
tile_size = make_int2(64, 64);
|
2012-09-17 10:55:18 +00:00
|
|
|
start_resolution = INT_MAX;
|
2020-02-25 13:31:08 +01:00
|
|
|
denoising_start_sample = 0;
|
2017-08-15 00:11:52 +02:00
|
|
|
pixel_size = 1;
|
2011-08-24 10:44:04 +00:00
|
|
|
threads = 0;
|
2020-03-05 12:05:42 +01:00
|
|
|
adaptive_sampling = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2018-11-29 02:06:30 +01:00
|
|
|
use_profiling = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-08-30 23:49:38 +00:00
|
|
|
display_buffer_linear = false;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
cancel_timeout = 0.1;
|
|
|
|
|
reset_timeout = 0.1;
|
|
|
|
|
text_timeout = 1.0;
|
2015-02-21 17:29:27 +05:00
|
|
|
progressive_update_timeout = 1.0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2014-05-19 13:49:36 +03:00
|
|
|
shadingsystem = SHADINGSYSTEM_SVM;
|
2013-09-03 22:39:21 +00:00
|
|
|
tile_order = TILE_CENTER;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool modified(const SessionParams ¶ms)
|
Cycles: Refactor Device selection to allow individual GPU compute device selection
Previously, it was only possible to choose a single GPU or all of that type (CUDA or OpenCL).
Now, a toggle button is displayed for every device.
These settings are tied to the PCI Bus ID of the devices, so they're consistent across hardware addition and removal (but not when swapping/moving cards).
From the code perspective, the more important change is that now, the compute device properties are stored in the Addon preferences of the Cycles addon, instead of directly in the User Preferences.
This allows for a cleaner implementation, removing the Cycles C API functions that were called by the RNA code to specify the enum items.
Note that this change is neither backwards- nor forwards-compatible, but since it's only a User Preference no existing files are broken.
Reviewers: #cycles, brecht
Reviewed By: #cycles, brecht
Subscribers: brecht, juicyfruit, mib2berlin, Blendify
Differential Revision: https://developer.blender.org/D2338
2016-11-07 02:33:53 +01:00
|
|
|
{
|
2021-01-20 12:41:58 +01:00
|
|
|
/* Modified means we have to recreate the session, any parameter changes
|
|
|
|
|
* that can be handled by an existing Session are omitted. */
|
2011-04-27 11:58:34 +00:00
|
|
|
return !(device == params.device && background == params.background &&
|
2020-02-25 13:31:08 +01:00
|
|
|
progressive_refine == params.progressive_refine &&
|
|
|
|
|
progressive == params.progressive && experimental == params.experimental &&
|
2012-09-17 10:55:18 +00:00
|
|
|
tile_size == params.tile_size && start_resolution == params.start_resolution &&
|
2017-08-15 00:11:52 +02:00
|
|
|
pixel_size == params.pixel_size && threads == params.threads &&
|
2020-03-05 12:05:42 +01:00
|
|
|
adaptive_sampling == params.adaptive_sampling &&
|
2018-11-29 02:06:30 +01:00
|
|
|
use_profiling == params.use_profiling &&
|
2013-08-30 23:49:38 +00:00
|
|
|
display_buffer_linear == params.display_buffer_linear &&
|
2011-04-27 11:58:34 +00:00
|
|
|
cancel_timeout == params.cancel_timeout && reset_timeout == params.reset_timeout &&
|
2012-10-26 09:25:02 +00:00
|
|
|
text_timeout == params.text_timeout &&
|
2015-02-21 17:29:27 +05:00
|
|
|
progressive_update_timeout == params.progressive_update_timeout &&
|
2020-05-31 23:49:10 +02:00
|
|
|
tile_order == params.tile_order && shadingsystem == params.shadingsystem &&
|
2021-01-20 12:41:58 +01:00
|
|
|
denoising.type == params.denoising.type &&
|
|
|
|
|
(denoising.use == params.denoising.use || (device.denoisers & denoising.type)));
|
2012-10-26 09:25:02 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/* Session
|
|
|
|
|
*
|
|
|
|
|
* This is the class that contains the session thread, running the render
|
|
|
|
|
* control loop and dispatching tasks. */
|
|
|
|
|
|
|
|
|
|
class Session {
|
|
|
|
|
public:
|
|
|
|
|
Device *device;
|
|
|
|
|
Scene *scene;
|
|
|
|
|
RenderBuffers *buffers;
|
|
|
|
|
DisplayBuffer *display;
|
|
|
|
|
Progress progress;
|
|
|
|
|
SessionParams params;
|
2012-09-04 13:29:07 +00:00
|
|
|
TileManager tile_manager;
|
2012-11-05 08:04:57 +00:00
|
|
|
Stats stats;
|
2018-11-29 23:30:17 +01:00
|
|
|
Profiler profiler;
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2015-03-29 22:12:22 +02:00
|
|
|
function<void(RenderTile &)> write_render_tile_cb;
|
2017-05-07 14:40:58 +02:00
|
|
|
function<void(RenderTile &, bool)> update_render_tile_cb;
|
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
|
|
|
function<void(RenderTile &)> read_bake_tile_cb;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-05-11 16:50:10 +02:00
|
|
|
explicit Session(const SessionParams ¶ms);
|
2011-04-27 11:58:34 +00:00
|
|
|
~Session();
|
|
|
|
|
|
|
|
|
|
void start();
|
2020-11-11 18:39:46 +01:00
|
|
|
void cancel();
|
2014-03-26 14:57:30 +06:00
|
|
|
bool draw(BufferParams ¶ms, DeviceDrawParams &draw_params);
|
2011-04-27 11:58:34 +00:00
|
|
|
void wait();
|
|
|
|
|
|
|
|
|
|
bool ready_to_reset();
|
2011-12-20 12:25:37 +00:00
|
|
|
void reset(BufferParams ¶ms, int samples);
|
2011-08-29 10:21:10 +00:00
|
|
|
void set_pause(bool pause);
|
2020-02-25 13:31:08 +01:00
|
|
|
void set_samples(int samples);
|
2020-05-31 23:49:10 +02:00
|
|
|
void set_denoising(const DenoiseParams &denoising);
|
2020-02-25 13:31:08 +01:00
|
|
|
void set_denoising_start_sample(int sample);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2018-11-29 02:06:30 +01:00
|
|
|
bool update_scene();
|
2014-05-19 19:17:57 +02:00
|
|
|
|
2012-11-09 08:46:53 +00:00
|
|
|
void device_free();
|
2014-05-19 19:17:57 +02: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
|
|
|
/* Returns the rendering progress or 0 if no progress can be determined
|
|
|
|
|
* (for example, when rendering with unlimited samples). */
|
|
|
|
|
float get_progress();
|
|
|
|
|
|
2018-11-29 02:06:30 +01:00
|
|
|
void collect_statistics(RenderStats *stats);
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
protected:
|
|
|
|
|
struct DelayedReset {
|
|
|
|
|
thread_mutex mutex;
|
|
|
|
|
bool do_reset;
|
2011-12-20 12:25:37 +00:00
|
|
|
BufferParams params;
|
2011-09-16 13:14:02 +00:00
|
|
|
int samples;
|
2011-04-27 11:58:34 +00:00
|
|
|
} delayed_reset;
|
|
|
|
|
|
|
|
|
|
void run();
|
|
|
|
|
|
2021-07-06 17:23:26 +02:00
|
|
|
bool run_update_for_next_iteration();
|
|
|
|
|
bool run_wait_for_work(bool no_tiles);
|
|
|
|
|
|
2011-08-29 16:54:13 +00:00
|
|
|
void update_status_time(bool show_pause = false, bool show_done = false);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2020-04-28 20:27:03 +02:00
|
|
|
void render(bool use_denoise);
|
2020-02-11 16:30:01 +01:00
|
|
|
void copy_to_display_buffer(int sample);
|
|
|
|
|
|
2011-12-20 12:25:37 +00:00
|
|
|
void reset_(BufferParams ¶ms, int samples);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
void run_cpu();
|
2014-03-26 14:57:30 +06:00
|
|
|
bool draw_cpu(BufferParams ¶ms, DeviceDrawParams &draw_params);
|
2011-12-20 12:25:37 +00:00
|
|
|
void reset_cpu(BufferParams ¶ms, int samples);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
void run_gpu();
|
2014-03-26 14:57:30 +06:00
|
|
|
bool draw_gpu(BufferParams ¶ms, DeviceDrawParams &draw_params);
|
2011-12-20 12:25:37 +00:00
|
|
|
void reset_gpu(BufferParams ¶ms, int samples);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2020-04-28 20:27:03 +02:00
|
|
|
bool render_need_denoise(bool &delayed);
|
|
|
|
|
|
2020-09-24 00:37:23 +02:00
|
|
|
bool steal_tile(RenderTile &tile, Device *tile_device, thread_scoped_lock &tile_lock);
|
|
|
|
|
bool get_tile_stolen();
|
2020-02-26 16:30:42 +01:00
|
|
|
bool acquire_tile(RenderTile &tile, Device *tile_device, uint tile_types);
|
2012-09-04 13:29:07 +00:00
|
|
|
void update_tile_sample(RenderTile &tile);
|
2020-04-28 20:27:03 +02:00
|
|
|
void release_tile(RenderTile &tile, const bool need_denoise);
|
2012-09-04 13:29:07 +00:00
|
|
|
|
2020-07-09 20:01:22 +02:00
|
|
|
void map_neighbor_tiles(RenderTileNeighbors &neighbors, Device *tile_device);
|
|
|
|
|
void unmap_neighbor_tiles(RenderTileNeighbors &neighbors, Device *tile_device);
|
2017-05-07 14:40:58 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool device_use_gl;
|
|
|
|
|
|
|
|
|
|
thread *session_thread;
|
|
|
|
|
|
|
|
|
|
volatile bool display_outdated;
|
|
|
|
|
|
|
|
|
|
volatile bool gpu_draw_ready;
|
2019-09-05 12:47:20 +02:00
|
|
|
volatile bool gpu_need_display_buffer_update;
|
|
|
|
|
thread_condition_variable gpu_need_display_buffer_update_cond;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-08-29 10:21:10 +00:00
|
|
|
bool pause;
|
|
|
|
|
thread_condition_variable pause_cond;
|
|
|
|
|
thread_mutex pause_mutex;
|
2012-09-04 13:29:07 +00:00
|
|
|
thread_mutex tile_mutex;
|
|
|
|
|
thread_mutex buffers_mutex;
|
|
|
|
|
thread_mutex display_mutex;
|
2020-02-11 16:30:01 +01:00
|
|
|
thread_condition_variable denoising_cond;
|
2020-09-24 00:37:23 +02:00
|
|
|
thread_condition_variable tile_steal_cond;
|
2011-08-29 10:21:10 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
double reset_time;
|
2020-02-11 16:30:01 +01:00
|
|
|
double last_update_time;
|
|
|
|
|
double last_display_time;
|
2012-10-13 12:38:32 +00:00
|
|
|
|
2020-09-24 00:37:23 +02:00
|
|
|
RenderTile stolen_tile;
|
|
|
|
|
typedef enum {
|
|
|
|
|
NOT_STEALING, /* There currently is no tile stealing in progress. */
|
|
|
|
|
WAITING_FOR_TILE, /* A device is waiting for another device to release a tile. */
|
|
|
|
|
RELEASING_TILE, /* A device has releasing a stealable tile. */
|
|
|
|
|
GOT_TILE /* A device has released a stealable tile, which is now stored in stolen_tile. */
|
|
|
|
|
} TileStealingState;
|
|
|
|
|
std::atomic<TileStealingState> tile_stealing_state;
|
|
|
|
|
int stealable_tiles;
|
|
|
|
|
|
2012-10-13 12:38:32 +00:00
|
|
|
/* progressive refine */
|
|
|
|
|
bool update_progressive_refine(bool cancel);
|
2011-04-27 11:58:34 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
|
|
#endif /* __SESSION_H__ */
|