Blender  V2.93
tile.h
Go to the documentation of this file.
1 /*
2  * Copyright 2011-2013 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef __TILE_H__
18 #define __TILE_H__
19 
20 #include <limits.h>
21 
22 #include "render/buffers.h"
23 #include "util/util_list.h"
24 
26 
27 /* Tile */
28 
29 class Tile {
30  public:
31  int index;
32  int x, y, w, h;
33  int device;
34  /* RENDER: The tile has to be rendered.
35  * RENDERED: The tile has been rendered, but can't be denoised yet (waiting for neighbors).
36  * DENOISE: The tile can be denoised now.
37  * DENOISED: The tile has been denoised, but can't be freed yet (waiting for neighbors).
38  * DONE: The tile is finished and has been freed. */
39  typedef enum { RENDER = 0, RENDERED, DENOISE, DENOISED, DONE } State;
42 
43  Tile()
44  {
45  }
46 
47  Tile(int index_, int x_, int y_, int w_, int h_, int device_, State state_ = RENDER)
48  : index(index_), x(x_), y(y_), w(w_), h(h_), device(device_), state(state_), buffers(NULL)
49  {
50  }
51 };
52 
53 /* Tile order */
54 
55 /* Note: this should match enum_tile_order in properties.py */
56 enum TileOrder {
63 };
64 
65 /* Tile Manager */
66 
67 class TileManager {
68  public:
70 
71  struct State {
75  int sample;
78  int num_tiles;
79 
80  /* Total samples over all pixels: Generally num_samples*num_pixels,
81  * but can be higher due to the initial resolution division for previews. */
83 
84  /* These lists contain the indices of the tiles to be rendered/denoised and are used
85  * when acquiring a new tile for the device.
86  * Each list in each vector is for one logical device. */
89  } state;
90 
93 
95  int num_samples,
97  int start_resolution,
99  bool background,
101  int num_devices = 1,
102  int pixel_size = 1);
103  ~TileManager();
104 
105  void device_free();
106  void reset(BufferParams &params, int num_samples);
107  void set_samples(int num_samples);
108  bool next();
109  bool next_tile(Tile *&tile, int device, uint tile_types);
110  bool finish_tile(const int index, const bool need_denoise, bool &delete_tile);
111  bool done();
112  bool has_tiles();
113 
114  void set_tile_order(TileOrder tile_order_)
115  {
116  tile_order = tile_order_;
117  }
118 
119  int get_neighbor_index(int index, int neighbor);
120  bool check_neighbor_state(int index, Tile::State state);
121 
122  /* ** Sample range rendering. ** */
123 
124  /* Start sample in the range. */
126 
127  /* Number to samples in the rendering range. */
129 
130  /* Get number of actual samples to render. */
132 
133  /* Schedule tiles for denoising after they've been rendered. */
135 
136  protected:
137  void set_tiles();
138 
145 
146  /* in some cases it is important that the same tile will be returned for the same
147  * device it was originally generated for (i.e. viewport rendering when buffer is
148  * allocating once for tile and then always used by it)
149  *
150  * in other cases any tile could be handled by any device (i.e. final rendering
151  * without progressive refine)
152  */
154 
155  /* for background render tiles should exactly match render parts generated from
156  * blender side, which means image first gets split into tiles and then tiles are
157  * assigning to render devices
158  *
159  * however viewport rendering expects tiles to be allocated in a special way,
160  * meaning image is being sliced horizontally first and every device handles
161  * its own slice
162  */
164 
165  /* Generate tile list, return number of tiles. */
166  int gen_tiles(bool sliced);
167  void gen_render_tiles();
168 };
169 
171 
172 #endif /* __TILE_H__ */
unsigned int uint
Definition: BLI_sys_types.h:83
int range_start_sample
Definition: tile.h:125
TileOrder tile_order
Definition: tile.h:141
int start_resolution
Definition: tile.h:142
int range_num_samples
Definition: tile.h:128
void device_free()
Definition: tile.cpp:122
void set_tile_order(TileOrder tile_order_)
Definition: tile.h:114
void reset(BufferParams &params, int num_samples)
Definition: tile.cpp:148
int get_neighbor_index(int index, int neighbor)
Definition: tile.cpp:394
bool next_tile(Tile *&tile, int device, uint tile_types)
Definition: tile.cpp:498
bool done()
Definition: tile.cpp:559
int slice_overlap
Definition: tile.h:92
bool check_neighbor_state(int index, Tile::State state)
Definition: tile.cpp:426
bool next()
Definition: tile.cpp:577
bool finish_tile(const int index, const bool need_denoise, bool &delete_tile)
Definition: tile.cpp:444
bool progressive
Definition: tile.h:139
bool has_tiles()
Definition: tile.cpp:567
void set_tiles()
Definition: tile.cpp:377
bool background
Definition: tile.h:163
~TileManager()
Definition: tile.cpp:118
struct TileManager::State state
bool preserve_tile_device
Definition: tile.h:153
int get_num_effective_samples()
Definition: tile.cpp:611
int2 tile_size
Definition: tile.h:140
int gen_tiles(bool sliced)
Definition: tile.cpp:198
TileManager(bool progressive, int num_samples, int2 tile_size, int start_resolution, bool preserve_tile_device, bool background, TileOrder tile_order, int num_devices=1, int pixel_size=1)
Definition: tile.cpp:89
void gen_render_tiles()
Definition: tile.cpp:368
int pixel_size
Definition: tile.h:143
int num_samples
Definition: tile.h:91
bool schedule_denoising
Definition: tile.h:134
int num_devices
Definition: tile.h:144
void set_samples(int num_samples)
Definition: tile.cpp:164
BufferParams params
Definition: tile.h:69
Definition: tile.h:29
int index
Definition: tile.h:31
RenderBuffers * buffers
Definition: tile.h:41
int y
Definition: tile.h:32
int x
Definition: tile.h:32
State state
Definition: tile.h:40
int device
Definition: tile.h:33
int h
Definition: tile.h:32
State
Definition: tile.h:39
@ DONE
Definition: tile.h:39
@ DENOISED
Definition: tile.h:39
@ RENDERED
Definition: tile.h:39
@ RENDER
Definition: tile.h:39
@ DENOISE
Definition: tile.h:39
int w
Definition: tile.h:32
Tile(int index_, int x_, int y_, int w_, int h_, int device_, State state_=RENDER)
Definition: tile.h:47
Tile()
Definition: tile.h:43
const Mat y_
Definition: fundamental.cc:447
const Mat x_
Definition: fundamental.cc:446
#define CCL_NAMESPACE_END
unsigned __int64 uint64_t
Definition: stdint.h:93
int tile_stride
Definition: tile.h:73
vector< list< int > > denoising_tiles
Definition: tile.h:88
BufferParams buffer
Definition: tile.h:74
vector< list< int > > render_tiles
Definition: tile.h:87
int resolution_divider
Definition: tile.h:77
uint64_t total_pixel_samples
Definition: tile.h:82
int num_samples
Definition: tile.h:76
vector< Tile > tiles
Definition: tile.h:72
TileOrder
Definition: tile.h:56
@ TILE_CENTER
Definition: tile.h:57
@ TILE_TOP_TO_BOTTOM
Definition: tile.h:60
@ TILE_BOTTOM_TO_TOP
Definition: tile.h:61
@ TILE_HILBERT_SPIRAL
Definition: tile.h:62
@ TILE_RIGHT_TO_LEFT
Definition: tile.h:58
@ TILE_LEFT_TO_RIGHT
Definition: tile.h:59