2016-09-14 23:47:54 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright 2011-2013 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#ifdef WITH_OPENCL
|
|
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "device/opencl/opencl.h"
|
2016-09-14 23:47:54 +02:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "render/buffers.h"
|
2016-09-14 23:47:54 +02:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "kernel/kernel_types.h"
|
2016-09-14 23:47:54 +02:00
|
|
|
|
Cycles: Make all #include statements relative to cycles source directory
The idea is to make include statements more explicit and obvious where the
file is coming from, additionally reducing chance of wrong header being
picked up.
For example, it was not obvious whether bvh.h was refferring to builder
or traversal, whenter node.h is a generic graph node or a shader node
and cases like that.
Surely this might look obvious for the active developers, but after some
time of not touching the code it becomes less obvious where file is coming
from.
This was briefly mentioned in T50824 and seems @brecht is fine with such
explicitness, but need to agree with all active developers before committing
this.
Please note that this patch is lacking changes related on GPU/OpenCL
support. This will be solved if/when we all agree this is a good idea to move
forward.
Reviewers: brecht, lukasstockner97, maiself, nirved, dingto, juicyfruit, swerner
Reviewed By: lukasstockner97, maiself, nirved, dingto
Subscribers: brecht
Differential Revision: https://developer.blender.org/D2586
2017-03-28 20:39:14 +02:00
|
|
|
#include "util/util_md5.h"
|
|
|
|
|
#include "util/util_path.h"
|
|
|
|
|
#include "util/util_time.h"
|
2016-09-14 23:47:54 +02:00
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
class OpenCLDeviceMegaKernel : public OpenCLDeviceBase
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
OpenCLProgram path_trace_program;
|
|
|
|
|
|
|
|
|
|
OpenCLDeviceMegaKernel(DeviceInfo& info, Stats &stats, bool background_)
|
|
|
|
|
: OpenCLDeviceBase(info, stats, background_),
|
|
|
|
|
path_trace_program(this, "megakernel", "kernel.cl", "-D__COMPILE_ONLY_MEGAKERNEL__ ")
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
Cycles: Refactor Progress system to provide better estimates
The Progress system in Cycles had two limitations so far:
- It just counted tiles, but ignored their size. For example, when rendering a 600x500 image with 512x512 tiles, the right 88x500 tile would count for 50% of the progress, although it only covers 15% of the image.
- Scene update time was incorrectly counted as rendering time - therefore, the remaining time started very long and gradually decreased.
This patch fixes both problems:
First of all, the Progress now has a function to ignore time spans, and that is used to ignore scene update time.
The larger change is the tile size: Instead of counting samples per tile, so that the final value is num_samples*num_tiles, the code now counts every sample for every pixel, so that the final value is num_samples*num_pixels.
Along with that, some unused variables were removed from the Progress and Session classes.
Reviewers: brecht, sergey, #cycles
Subscribers: brecht, candreacchio, sergey
Differential Revision: https://developer.blender.org/D2214
2016-11-26 04:22:34 +01:00
|
|
|
virtual bool show_samples() const {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-22 08:10:02 -05:00
|
|
|
virtual bool load_kernels(const DeviceRequestedFeatures& /*requested_features*/,
|
2016-09-14 23:47:54 +02:00
|
|
|
vector<OpenCLProgram*> &programs)
|
|
|
|
|
{
|
|
|
|
|
path_trace_program.add_kernel(ustring("path_trace"));
|
|
|
|
|
programs.push_back(&path_trace_program);
|
2017-02-22 08:10:02 -05:00
|
|
|
return true;
|
2016-09-14 23:47:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~OpenCLDeviceMegaKernel()
|
|
|
|
|
{
|
|
|
|
|
task_pool.stop();
|
|
|
|
|
path_trace_program.release();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void path_trace(RenderTile& rtile, int sample)
|
|
|
|
|
{
|
2017-11-17 14:23:48 +01:00
|
|
|
scoped_timer timer(&rtile.buffers->render_time);
|
|
|
|
|
|
2016-09-14 23:47:54 +02:00
|
|
|
/* Cast arguments to cl types. */
|
|
|
|
|
cl_mem d_data = CL_MEM_PTR(const_mem_map["__data"]->device_pointer);
|
|
|
|
|
cl_mem d_buffer = CL_MEM_PTR(rtile.buffer);
|
|
|
|
|
cl_int d_x = rtile.x;
|
|
|
|
|
cl_int d_y = rtile.y;
|
|
|
|
|
cl_int d_w = rtile.w;
|
|
|
|
|
cl_int d_h = rtile.h;
|
|
|
|
|
cl_int d_offset = rtile.offset;
|
|
|
|
|
cl_int d_stride = rtile.stride;
|
|
|
|
|
|
|
|
|
|
/* Sample arguments. */
|
|
|
|
|
cl_int d_sample = sample;
|
|
|
|
|
|
|
|
|
|
cl_kernel ckPathTraceKernel = path_trace_program(ustring("path_trace"));
|
|
|
|
|
|
|
|
|
|
cl_uint start_arg_index =
|
|
|
|
|
kernel_set_args(ckPathTraceKernel,
|
|
|
|
|
0,
|
|
|
|
|
d_data,
|
2017-09-27 00:39:53 +02:00
|
|
|
d_buffer);
|
2016-09-14 23:47:54 +02:00
|
|
|
|
2017-08-08 07:12:04 -04:00
|
|
|
set_kernel_arg_buffers(ckPathTraceKernel, &start_arg_index);
|
2016-09-14 23:47:54 +02:00
|
|
|
|
|
|
|
|
start_arg_index += kernel_set_args(ckPathTraceKernel,
|
|
|
|
|
start_arg_index,
|
|
|
|
|
d_sample,
|
|
|
|
|
d_x,
|
|
|
|
|
d_y,
|
|
|
|
|
d_w,
|
|
|
|
|
d_h,
|
|
|
|
|
d_offset,
|
|
|
|
|
d_stride);
|
|
|
|
|
|
|
|
|
|
enqueue_kernel(ckPathTraceKernel, d_w, d_h);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void thread_run(DeviceTask *task)
|
|
|
|
|
{
|
|
|
|
|
if(task->type == DeviceTask::FILM_CONVERT) {
|
|
|
|
|
film_convert(*task, task->buffer, task->rgba_byte, task->rgba_half);
|
|
|
|
|
}
|
|
|
|
|
else if(task->type == DeviceTask::SHADER) {
|
|
|
|
|
shader(*task);
|
|
|
|
|
}
|
2017-05-07 14:40:58 +02:00
|
|
|
else if(task->type == DeviceTask::RENDER) {
|
2016-09-14 23:47:54 +02:00
|
|
|
RenderTile tile;
|
2017-11-08 20:15:38 +01:00
|
|
|
DenoisingTask denoising(this);
|
|
|
|
|
|
2016-09-14 23:47:54 +02:00
|
|
|
/* Keep rendering tiles until done. */
|
|
|
|
|
while(task->acquire_tile(this, tile)) {
|
2017-05-07 14:40:58 +02:00
|
|
|
if(tile.task == RenderTile::PATH_TRACE) {
|
|
|
|
|
int start_sample = tile.start_sample;
|
|
|
|
|
int end_sample = tile.start_sample + tile.num_samples;
|
2016-09-14 23:47:54 +02:00
|
|
|
|
2017-05-07 14:40:58 +02:00
|
|
|
for(int sample = start_sample; sample < end_sample; sample++) {
|
|
|
|
|
if(task->get_cancel()) {
|
|
|
|
|
if(task->need_finish_queue == false)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
path_trace(tile, sample);
|
2016-09-14 23:47:54 +02:00
|
|
|
|
2017-05-07 14:40:58 +02:00
|
|
|
tile.sample = sample + 1;
|
2016-09-14 23:47:54 +02:00
|
|
|
|
2017-05-07 14:40:58 +02:00
|
|
|
task->update_progress(&tile, tile.w*tile.h);
|
|
|
|
|
}
|
2016-09-14 23:47:54 +02:00
|
|
|
|
2017-05-07 14:40:58 +02:00
|
|
|
/* Complete kernel execution before release tile */
|
|
|
|
|
/* This helps in multi-device render;
|
|
|
|
|
* The device that reaches the critical-section function
|
|
|
|
|
* release_tile waits (stalling other devices from entering
|
|
|
|
|
* release_tile) for all kernels to complete. If device1 (a
|
|
|
|
|
* slow-render device) reaches release_tile first then it would
|
|
|
|
|
* stall device2 (a fast-render device) from proceeding to render
|
|
|
|
|
* next tile.
|
|
|
|
|
*/
|
|
|
|
|
clFinish(cqCommandQueue);
|
|
|
|
|
}
|
|
|
|
|
else if(tile.task == RenderTile::DENOISE) {
|
|
|
|
|
tile.sample = tile.start_sample + tile.num_samples;
|
2017-11-08 20:15:38 +01:00
|
|
|
denoise(tile, denoising, *task);
|
Cycles: Refactor Progress system to provide better estimates
The Progress system in Cycles had two limitations so far:
- It just counted tiles, but ignored their size. For example, when rendering a 600x500 image with 512x512 tiles, the right 88x500 tile would count for 50% of the progress, although it only covers 15% of the image.
- Scene update time was incorrectly counted as rendering time - therefore, the remaining time started very long and gradually decreased.
This patch fixes both problems:
First of all, the Progress now has a function to ignore time spans, and that is used to ignore scene update time.
The larger change is the tile size: Instead of counting samples per tile, so that the final value is num_samples*num_tiles, the code now counts every sample for every pixel, so that the final value is num_samples*num_pixels.
Along with that, some unused variables were removed from the Progress and Session classes.
Reviewers: brecht, sergey, #cycles
Subscribers: brecht, candreacchio, sergey
Differential Revision: https://developer.blender.org/D2214
2016-11-26 04:22:34 +01:00
|
|
|
task->update_progress(&tile, tile.w*tile.h);
|
2016-09-14 23:47:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
task->release_tile(tile);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-05-07 14:40:58 +02:00
|
|
|
|
|
|
|
|
bool is_split_kernel()
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2016-09-14 23:47:54 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Device *opencl_create_mega_device(DeviceInfo& info, Stats& stats, bool background)
|
|
|
|
|
{
|
|
|
|
|
return new OpenCLDeviceMegaKernel(info, stats, background);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|
|
|
|
|
|
#endif
|