Changeset View
Changeset View
Standalone View
Standalone View
intern/cycles/render/session.h
| Show All 12 Lines | |||||
| * See the License for the specific language governing permissions and | * See the License for the specific language governing permissions and | ||||
| * limitations under the License. | * limitations under the License. | ||||
| */ | */ | ||||
| #ifndef __SESSION_H__ | #ifndef __SESSION_H__ | ||||
| #define __SESSION_H__ | #define __SESSION_H__ | ||||
| #include "device/device.h" | #include "device/device.h" | ||||
| #include "integrator/render_scheduler.h" | |||||
| #include "render/buffers.h" | #include "render/buffers.h" | ||||
| #include "render/shader.h" | #include "render/shader.h" | ||||
| #include "render/stats.h" | #include "render/stats.h" | ||||
| #include "render/tile.h" | #include "render/tile.h" | ||||
| #include "util/util_progress.h" | #include "util/util_progress.h" | ||||
| #include "util/util_stats.h" | #include "util/util_stats.h" | ||||
| #include "util/util_thread.h" | #include "util/util_thread.h" | ||||
| #include "util/util_unique_ptr.h" | |||||
| #include "util/util_vector.h" | #include "util/util_vector.h" | ||||
| CCL_NAMESPACE_BEGIN | CCL_NAMESPACE_BEGIN | ||||
| class BufferParams; | class BufferParams; | ||||
| class Device; | class Device; | ||||
| class DeviceScene; | class DeviceScene; | ||||
| class DeviceRequestedFeatures; | class PathTrace; | ||||
| class DisplayBuffer; | |||||
| class Progress; | class Progress; | ||||
| class GPUDisplay; | |||||
| class RenderBuffers; | class RenderBuffers; | ||||
| class Scene; | class Scene; | ||||
| class SceneParams; | |||||
| /* Session Parameters */ | /* Session Parameters */ | ||||
| class SessionParams { | class SessionParams { | ||||
| public: | public: | ||||
| DeviceInfo device; | DeviceInfo device; | ||||
| bool headless; | |||||
| bool background; | bool background; | ||||
| bool progressive_refine; | |||||
| bool progressive; | |||||
| bool experimental; | bool experimental; | ||||
| int samples; | int samples; | ||||
| int2 tile_size; | |||||
| TileOrder tile_order; | |||||
| int start_resolution; | |||||
| int denoising_start_sample; | |||||
| int pixel_size; | int pixel_size; | ||||
| int threads; | int threads; | ||||
| bool adaptive_sampling; | |||||
| bool use_profiling; | |||||
| bool display_buffer_linear; | |||||
| DenoiseParams denoising; | /* Limit in seconds for how long path tracing is allowed to happen. | ||||
| * Zero means no limit is applied. */ | |||||
| double time_limit; | |||||
| double cancel_timeout; | bool use_profiling; | ||||
| double reset_timeout; | |||||
| double text_timeout; | |||||
| double progressive_update_timeout; | |||||
| ShadingSystem shadingsystem; | ShadingSystem shadingsystem; | ||||
| function<bool(const uchar *pixels, int width, int height, int channels)> write_render_cb; | function<bool(const uchar *pixels, int width, int height, int channels)> write_render_cb; | ||||
| SessionParams() | SessionParams() | ||||
| { | { | ||||
| headless = false; | |||||
| background = false; | background = false; | ||||
| progressive_refine = false; | |||||
| progressive = false; | |||||
| experimental = false; | experimental = false; | ||||
| samples = 1024; | samples = 1024; | ||||
| tile_size = make_int2(64, 64); | |||||
| start_resolution = INT_MAX; | |||||
| denoising_start_sample = 0; | |||||
| pixel_size = 1; | pixel_size = 1; | ||||
| threads = 0; | threads = 0; | ||||
| adaptive_sampling = false; | time_limit = 0.0; | ||||
| use_profiling = false; | use_profiling = false; | ||||
| display_buffer_linear = false; | |||||
| cancel_timeout = 0.1; | |||||
| reset_timeout = 0.1; | |||||
| text_timeout = 1.0; | |||||
| progressive_update_timeout = 1.0; | |||||
| shadingsystem = SHADINGSYSTEM_SVM; | shadingsystem = SHADINGSYSTEM_SVM; | ||||
| tile_order = TILE_CENTER; | |||||
| } | } | ||||
| bool modified(const SessionParams ¶ms) | bool modified(const SessionParams ¶ms) const | ||||
| { | { | ||||
| /* Modified means we have to recreate the session, any parameter changes | /* Modified means we have to recreate the session, any parameter changes | ||||
| * that can be handled by an existing Session are omitted. */ | * that can be handled by an existing Session are omitted. */ | ||||
| return !(device == params.device && background == params.background && | return !(device == params.device && headless == params.headless && | ||||
| progressive_refine == params.progressive_refine && | background == params.background && experimental == params.experimental && | ||||
| progressive == params.progressive && experimental == params.experimental && | |||||
| tile_size == params.tile_size && start_resolution == params.start_resolution && | |||||
| pixel_size == params.pixel_size && threads == params.threads && | pixel_size == params.pixel_size && threads == params.threads && | ||||
| adaptive_sampling == params.adaptive_sampling && | use_profiling == params.use_profiling && shadingsystem == params.shadingsystem); | ||||
| use_profiling == params.use_profiling && | |||||
| display_buffer_linear == params.display_buffer_linear && | |||||
| cancel_timeout == params.cancel_timeout && reset_timeout == params.reset_timeout && | |||||
| text_timeout == params.text_timeout && | |||||
| progressive_update_timeout == params.progressive_update_timeout && | |||||
| tile_order == params.tile_order && shadingsystem == params.shadingsystem && | |||||
| denoising.type == params.denoising.type && | |||||
| (denoising.use == params.denoising.use || (device.denoisers & denoising.type))); | |||||
| } | } | ||||
| }; | }; | ||||
| /* Session | /* Session | ||||
| * | * | ||||
| * This is the class that contains the session thread, running the render | * This is the class that contains the session thread, running the render | ||||
| * control loop and dispatching tasks. */ | * control loop and dispatching tasks. */ | ||||
| class Session { | class Session { | ||||
| public: | public: | ||||
| Device *device; | Device *device; | ||||
| Scene *scene; | Scene *scene; | ||||
| RenderBuffers *buffers; | |||||
| DisplayBuffer *display; | |||||
| Progress progress; | Progress progress; | ||||
| SessionParams params; | SessionParams params; | ||||
| TileManager tile_manager; | |||||
| Stats stats; | Stats stats; | ||||
| Profiler profiler; | Profiler profiler; | ||||
| function<void(RenderTile &)> write_render_tile_cb; | function<void(void)> write_render_tile_cb; | ||||
| function<void(RenderTile &, bool)> update_render_tile_cb; | function<void(void)> update_render_tile_cb; | ||||
| function<void(RenderTile &)> read_bake_tile_cb; | function<void(void)> read_render_tile_cb; | ||||
| explicit Session(const SessionParams ¶ms); | explicit Session(const SessionParams ¶ms, const SceneParams &scene_params); | ||||
| ~Session(); | ~Session(); | ||||
| void start(); | void start(); | ||||
| void cancel(); | |||||
| bool draw(BufferParams ¶ms, DeviceDrawParams &draw_params); | /* When quick cancel is requested path tracing is cancelles as soon as possible, without waiting | ||||
| * for the buffer to be uniformly sampled. */ | |||||
| void cancel(bool quick = false); | |||||
| void draw(); | |||||
| void wait(); | void wait(); | ||||
| bool ready_to_reset(); | bool ready_to_reset(); | ||||
| void reset(BufferParams ¶ms, int samples); | void reset(BufferParams ¶ms, int samples); | ||||
| void set_pause(bool pause); | void set_pause(bool pause); | ||||
| void set_samples(int samples); | void set_samples(int samples); | ||||
| void set_denoising(const DenoiseParams &denoising); | void set_time_limit(double time_limit); | ||||
| void set_denoising_start_sample(int sample); | |||||
| bool update_scene(); | void set_gpu_display(unique_ptr<GPUDisplay> gpu_display); | ||||
| void device_free(); | void device_free(); | ||||
| /* Returns the rendering progress or 0 if no progress can be determined | /* Returns the rendering progress or 0 if no progress can be determined | ||||
| * (for example, when rendering with unlimited samples). */ | * (for example, when rendering with unlimited samples). */ | ||||
| float get_progress(); | float get_progress(); | ||||
| void collect_statistics(RenderStats *stats); | void collect_statistics(RenderStats *stats); | ||||
| /* -------------------------------------------------------------------- | |||||
| * Tile and tile pixels aceess. | |||||
| */ | |||||
| /* Get size and offset (relative to the buffer's full x/y) of the currently rendering tile. */ | |||||
| int2 get_render_tile_size() const; | |||||
| int2 get_render_tile_offset() const; | |||||
| bool copy_render_tile_from_device(); | |||||
| bool get_render_tile_pixels(const string &pass_name, int num_components, float *pixels); | |||||
| bool set_render_tile_pixels(const string &pass_name, int num_components, const float *pixels); | |||||
| protected: | protected: | ||||
| struct DelayedReset { | struct DelayedReset { | ||||
| thread_mutex mutex; | thread_mutex mutex; | ||||
| bool do_reset; | bool do_reset; | ||||
| BufferParams params; | BufferParams params; | ||||
| int samples; | int samples; | ||||
| } delayed_reset_; | } delayed_reset_; | ||||
| void run(); | void run(); | ||||
| bool run_update_for_next_iteration(); | /* Update for the new iteration of the main loop in run implementation (run_cpu and run_gpu). | ||||
| bool run_wait_for_work(bool no_tiles); | * | ||||
| * Will take care of the following things: | |||||
| void update_status_time(bool show_pause = false, bool show_done = false); | * - Delayed reset | ||||
| * - Scene update | |||||
| void render(bool use_denoise); | * - Tile manager advance | ||||
| void copy_to_display_buffer(int sample); | * - Render scheduler work request | ||||
| * | |||||
| void reset_(BufferParams ¶ms, int samples); | * The updates are done in a proper order with proper locking around them, which guarantees | ||||
| * that the device side of scene and render buffers are always in a consistent state. | |||||
| void run_cpu(); | * | ||||
| bool draw_cpu(BufferParams ¶ms, DeviceDrawParams &draw_params); | * Returns render work which is to be rendered next. */ | ||||
| void reset_cpu(BufferParams ¶ms, int samples); | RenderWork run_update_for_next_iteration(); | ||||
| void run_gpu(); | /* Wait for rendering to be unpaused, or for new tiles for render to arrive. | ||||
| bool draw_gpu(BufferParams ¶ms, DeviceDrawParams &draw_params); | * Returns true if new main render loop iteration is required after this function call. | ||||
| void reset_gpu(BufferParams ¶ms, int samples); | * | ||||
| * The `render_work` is the work which was scheduled by the render scheduler right before | |||||
| * checking the pause. */ | |||||
| bool run_wait_for_work(const RenderWork &render_work); | |||||
| bool render_need_denoise(bool &delayed); | void run_main_render_loop(); | ||||
| bool steal_tile(RenderTile &tile, Device *tile_device, thread_scoped_lock &tile_lock); | bool update_scene(int width, int height); | ||||
| bool get_tile_stolen(); | |||||
| bool acquire_tile(RenderTile &tile, Device *tile_device, uint tile_types); | |||||
| void update_tile_sample(RenderTile &tile); | |||||
| void release_tile(RenderTile &tile, const bool need_denoise); | |||||
| void map_neighbor_tiles(RenderTileNeighbors &neighbors, Device *tile_device); | void update_status_time(bool show_pause = false, bool show_done = false); | ||||
| void unmap_neighbor_tiles(RenderTileNeighbors &neighbors, Device *tile_device); | |||||
| bool device_use_gl_; | void do_delayed_reset(); | ||||
| thread *session_thread_; | thread *session_thread_; | ||||
| volatile bool display_outdated_; | bool pause_ = false; | ||||
| bool cancel_ = false; | |||||
| volatile bool gpu_draw_ready_; | bool new_work_added_ = false; | ||||
| volatile bool gpu_need_display_buffer_update_; | |||||
| thread_condition_variable gpu_need_display_buffer_update_cond_; | |||||
| bool pause_; | |||||
| bool cancel_; | |||||
| bool new_work_added_; | |||||
| thread_condition_variable pause_cond_; | thread_condition_variable pause_cond_; | ||||
| thread_mutex pause_mutex_; | thread_mutex pause_mutex_; | ||||
| thread_mutex tile_mutex_; | thread_mutex tile_mutex_; | ||||
| thread_mutex buffers_mutex_; | thread_mutex buffers_mutex_; | ||||
| thread_mutex display_mutex_; | |||||
| thread_condition_variable denoising_cond_; | |||||
| thread_condition_variable tile_steal_cond_; | |||||
| double reset_time_; | |||||
| double last_update_time_; | |||||
| double last_display_time_; | |||||
| 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_; | |||||
| /* progressive refine */ | TileManager tile_manager_; | ||||
| bool update_progressive_refine(bool cancel); | BufferParams buffer_params_; | ||||
| /* Render scheduler is used to get work to be rendered with the current big tile. */ | |||||
| RenderScheduler render_scheduler_; | |||||
| /* Path tracer object. | |||||
| * | |||||
| * Is a single full-frame path tracer for interactive viewport rendering. | |||||
| * A path tracer for the current big-tile for an offline rendering. */ | |||||
| unique_ptr<PathTrace> path_trace_; | |||||
| }; | }; | ||||
| CCL_NAMESPACE_END | CCL_NAMESPACE_END | ||||
| #endif /* __SESSION_H__ */ | #endif /* __SESSION_H__ */ | ||||