Blender V4.3
session/tile.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
2 *
3 * SPDX-License-Identifier: Apache-2.0 */
4
5#pragma once
6
7#include "session/buffers.h"
8#include "util/image.h"
9#include "util/string.h"
10#include "util/unique_ptr.h"
11
13
14class DenoiseParams;
15class Scene;
16
17/* --------------------------------------------------------------------
18 * Tile.
19 */
20
21class Tile {
22 public:
23 int x = 0, y = 0;
24 int width = 0, height = 0;
25
26 int window_x = 0, window_y = 0;
28
29 Tile() {}
30};
31
32/* --------------------------------------------------------------------
33 * Tile Manager.
34 */
35
37 public:
38 /* This callback is invoked by whenever on-dist tiles storage file is closed after writing. */
39 function<void(string_view)> full_buffer_written_cb;
40
43
44 TileManager(const TileManager &other) = delete;
45 TileManager(TileManager &&other) noexcept = delete;
46 TileManager &operator=(const TileManager &other) = delete;
47 TileManager &operator=(TileManager &&other) = delete;
48
49 /* Reset current progress and start new rendering of the full-frame parameters in tiles of the
50 * given size.
51 * Only touches scheduling-related state of the tile manager. */
52 /* TODO(sergey): Consider using tile area instead of exact size to help dealing with extreme
53 * cases of stretched renders. */
54 void reset_scheduling(const BufferParams &params, int2 tile_size);
55
56 /* Update for the known buffer passes and scene parameters.
57 * Will store all parameters needed for buffers access outside of the scene graph. */
58 void update(const BufferParams &params, const Scene *scene);
59
60 void set_temp_dir(const string &temp_dir);
61
62 inline int get_num_tiles() const
63 {
64 return tile_state_.num_tiles;
65 }
66
67 inline bool has_multiple_tiles() const
68 {
69 return tile_state_.num_tiles > 1;
70 }
71
72 inline int get_tile_overscan() const
73 {
74 return overscan_;
75 }
76
77 bool next();
78 bool done();
79
80 const Tile &get_current_tile() const;
81 const int2 get_size() const;
82
83 /* Write render buffer of a tile to a file on disk.
84 *
85 * Opens file for write when first tile is written.
86 *
87 * Returns true on success. */
88 bool write_tile(const RenderBuffers &tile_buffers);
89
90 /* Inform the tile manager that no more tiles will be written to disk.
91 * The file will be considered final, all handles to it will be closed. */
92 void finish_write_tiles();
93
94 /* Check whether any tile has been written to disk. */
95 inline bool has_written_tiles() const
96 {
97 return write_state_.num_tiles_written != 0;
98 }
99
100 /* Read full frame render buffer from tiles file on disk.
101 *
102 * Returns true on success. */
103 bool read_full_buffer_from_disk(string_view filename,
105 DenoiseParams *denoise_params);
106
107 /* Compute valid tile size compatible with image saving. */
108 int compute_render_tile_size(const int suggested_tile_size) const;
109
110 /* Tile size in the image file. */
111 static const int IMAGE_TILE_SIZE = 128;
112
113 /* Maximum supported tile size.
114 * Needs to be safe from allocation on a GPU point of view: the display driver needs to be able
115 * to allocate texture with the side size of this value.
116 * Use conservative value which is safe for most of OpenGL drivers and GPUs. */
117 static const int MAX_TILE_SIZE = 8192;
118
119 protected:
120 /* Get tile configuration for its index.
121 * The tile index must be within [0, state_.tile_state_). */
122 Tile get_tile_for_index(int index) const;
123
124 bool open_tile_output();
125 bool close_tile_output();
126
127 string temp_dir_;
128
129 /* Part of an on-disk tile file name which avoids conflicts between several Cycles instances or
130 * several sessions. */
132
134
135 /* Number of extra pixels around the actual tile to render. */
136 int overscan_ = 0;
137
139
140 /* Tile scheduling state. */
141 struct {
142 int num_tiles_x = 0;
143 int num_tiles_y = 0;
144 int num_tiles = 0;
145
147
150
151 /* State of tiles writing to a file on disk. */
152 struct {
153 /* Index of a tile file used during the current session.
154 * This number is used for the file name construction, making it possible to render several
155 * scenes throughout duration of the session and keep all results available for later read
156 * access. */
158
159 string filename;
160
161 /* Specification of the tile image which corresponds to the buffer parameters.
162 * Contains channels configured according to the passes configuration in the path traces.
163 *
164 * Output images are saved using this specification, input images are expected to have matched
165 * specification. */
166 ImageSpec image_spec;
167
168 /* Output handle for the tile file.
169 *
170 * This file can not be closed until all tiles has been provided, so the handle is stored in
171 * the state and is created whenever writing is requested. */
172 unique_ptr<ImageOutput> tile_out;
173
176};
177
BufferParams buffer_params_
void set_temp_dir(const string &temp_dir)
function< void(string_view)> full_buffer_written_cb
string temp_dir_
int num_tiles_written
TileManager & operator=(const TileManager &other)=delete
bool close_tile_output()
struct TileManager::@1465 tile_state_
void reset_scheduling(const BufferParams &params, int2 tile_size)
int compute_render_tile_size(const int suggested_tile_size) const
bool has_multiple_tiles() const
TileManager(TileManager &&other) noexcept=delete
Tile get_tile_for_index(int index) const
bool has_written_tiles() const
void update(const BufferParams &params, const Scene *scene)
const int2 get_size() const
const Tile & get_current_tile() const
string filename
int get_num_tiles() const
unique_ptr< ImageOutput > tile_out
bool open_tile_output()
bool write_tile(const RenderBuffers &tile_buffers)
TileManager & operator=(TileManager &&other)=delete
struct TileManager::@1466 write_state_
bool read_full_buffer_from_disk(string_view filename, RenderBuffers *buffers, DenoiseParams *denoise_params)
ImageSpec image_spec
TileManager(const TileManager &other)=delete
static const int MAX_TILE_SIZE
string tile_file_unique_part_
void finish_write_tiles()
int get_tile_overscan() const
static const int IMAGE_TILE_SIZE
int height
int window_y
int window_height
int window_x
int window_width
int width
#define CCL_NAMESPACE_END
ccl_device_forceinline int2 make_int2(const int x, const int y)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
char * buffers[2]