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