Blender  V2.93
device_task.cpp
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 #include <stdlib.h>
18 #include <string.h>
19 
20 #include "device/device_task.h"
21 
22 #include "render/buffers.h"
23 
24 #include "util/util_algorithm.h"
25 #include "util/util_time.h"
26 
28 
29 /* Device Task */
30 
32  : type(type_),
33  x(0),
34  y(0),
35  w(0),
36  h(0),
37  rgba_byte(0),
38  rgba_half(0),
39  buffer(0),
40  sample(0),
41  num_samples(1),
42  shader_input(0),
43  shader_output(0),
44  shader_eval_type(0),
45  shader_filter(0),
46  shader_x(0),
47  shader_w(0),
48  buffers(nullptr),
49  tile_types(0),
50  denoising_from_render(false),
51  pass_stride(0),
52  frame_stride(0),
53  target_pass_stride(0),
54  pass_denoising_data(0),
55  pass_denoising_clean(0),
56  need_finish_queue(false),
57  integrator_branched(false)
58 {
60 }
61 
62 int DeviceTask::get_subtask_count(int num, int max_size) const
63 {
64  if (max_size != 0) {
65  int max_size_num;
66 
67  if (type == SHADER) {
68  max_size_num = (shader_w + max_size - 1) / max_size;
69  }
70  else {
71  max_size = max(1, max_size / w);
72  max_size_num = (h + max_size - 1) / max_size;
73  }
74 
75  num = max(max_size_num, num);
76  }
77 
78  if (type == SHADER) {
79  num = min(shader_w, num);
80  }
81  else if (type == RENDER) {
82  }
83  else {
84  num = min(h, num);
85  }
86 
87  return num;
88 }
89 
90 void DeviceTask::split(list<DeviceTask> &tasks, int num, int max_size) const
91 {
92  num = get_subtask_count(num, max_size);
93 
94  if (type == SHADER) {
95  for (int i = 0; i < num; i++) {
96  int tx = shader_x + (shader_w / num) * i;
97  int tw = (i == num - 1) ? shader_w - i * (shader_w / num) : shader_w / num;
98 
99  DeviceTask task = *this;
100 
101  task.shader_x = tx;
102  task.shader_w = tw;
103 
104  tasks.push_back(task);
105  }
106  }
107  else if (type == RENDER) {
108  for (int i = 0; i < num; i++)
109  tasks.push_back(*this);
110  }
111  else {
112  for (int i = 0; i < num; i++) {
113  int ty = y + (h / num) * i;
114  int th = (i == num - 1) ? h - i * (h / num) : h / num;
115 
116  DeviceTask task = *this;
117 
118  task.y = ty;
119  task.h = th;
120 
121  tasks.push_back(task);
122  }
123  }
124 }
125 
126 void DeviceTask::update_progress(RenderTile *rtile, int pixel_samples)
127 {
128  if (type == FILM_CONVERT)
129  return;
130 
132  if (pixel_samples == -1) {
133  pixel_samples = shader_w;
134  }
135  update_progress_sample(pixel_samples, rtile ? rtile->sample : 0);
136  }
137 
138  if (update_tile_sample) {
139  double current_time = time_dt();
140 
141  if (current_time - last_update_time >= 1.0) {
142  update_tile_sample(*rtile);
143 
144  last_update_time = current_time;
145  }
146  }
147 }
148 
149 /* Adaptive Sampling */
150 
151 AdaptiveSampling::AdaptiveSampling() : use(true), adaptive_step(0), min_samples(0)
152 {
153 }
154 
155 /* Render samples in steps that align with the adaptive filtering. */
156 int AdaptiveSampling::align_samples(int sample, int num_samples) const
157 {
158  int end_sample = sample + num_samples;
159 
160  /* Round down end sample to the nearest sample that needs filtering. */
161  end_sample &= ~(adaptive_step - 1);
162 
163  if (end_sample <= sample) {
164  /* In order to reach the next sample that needs filtering, we'd need
165  * to increase num_samples. We don't do that in this function, so
166  * just keep it as is and don't filter this time around. */
167  return num_samples;
168  }
169  return end_sample - sample;
170 }
171 
173 {
174  if (sample > min_samples) {
175  return (sample & (adaptive_step - 1)) == (adaptive_step - 1);
176  }
177  else {
178  return false;
179  }
180 }
181 
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum type
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint y
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
Definition: btQuadWord.h:119
int align_samples(int sample, int num_samples) const
bool need_filter(int sample) const
void update_progress(RenderTile *rtile, int pixel_samples=-1)
function< void(long, int)> update_progress_sample
Definition: device_task.h:159
DeviceTask(Type type=RENDER)
Definition: device_task.cpp:31
function< void(RenderTile &)> update_tile_sample
Definition: device_task.h:160
void split(list< DeviceTask > &tasks, int num, int max_size=0) const
Definition: device_task.cpp:90
double last_update_time
Definition: device_task.h:183
int get_subtask_count(int num, int max_size=0) const
Definition: device_task.cpp:62
int sample
Definition: buffers.h:140
#define CCL_NAMESPACE_END
__kernel void ccl_constant KernelData ccl_global void ccl_global char ccl_global int ccl_global char ccl_global unsigned int ccl_global float * buffer
static void sample(SocketReader *reader, int x, int y, float color[4])
struct blender::compositor::@172::@174 task
#define min(a, b)
Definition: sort.c:51
float max
CCL_NAMESPACE_BEGIN double time_dt()
Definition: util_time.cpp:48