Cycles Denoising: Cleanup: Rename tiles to tile_info
[blender.git] / intern / cycles / device / device_denoising.cpp
index 4d2ba508aeca543c52eb0674b2a5914885df4b09..318b14ab49991b48771e4e7005a8f6b72f63ac9e 100644 (file)
@@ -21,7 +21,7 @@
 CCL_NAMESPACE_BEGIN
 
 DenoisingTask::DenoisingTask(Device *device, const DeviceTask &task)
-: tiles_mem(device, "denoising tiles_mem", MEM_READ_WRITE),
+: tile_info_mem(device, "denoising tile info mem", MEM_READ_WRITE),
   storage(device),
   buffer(device),
   device(device)
@@ -36,8 +36,13 @@ DenoisingTask::DenoisingTask(Device *device, const DeviceTask &task)
        }
 
        render_buffer.pass_stride = task.pass_stride;
-       render_buffer.denoising_data_offset = task.pass_denoising_data;
-       render_buffer.denoising_clean_offset = task.pass_denoising_clean;
+       render_buffer.offset = task.pass_denoising_data;
+
+       target_buffer.pass_stride = task.pass_stride;
+       target_buffer.denoising_clean_offset = task.pass_denoising_clean;
+
+       functions.map_neighbor_tiles = function_bind(task.map_neighbor_tiles, _1, device);
+       functions.unmap_neighbor_tiles = function_bind(task.unmap_neighbor_tiles, _1, device);
 }
 
 DenoisingTask::~DenoisingTask()
@@ -50,34 +55,33 @@ DenoisingTask::~DenoisingTask()
        storage.temporary_2.free();
        storage.temporary_color.free();
        buffer.mem.free();
-       tiles_mem.free();
+       tile_info_mem.free();
 }
 
-
-void DenoisingTask::tiles_from_rendertiles(RenderTile *rtiles)
+void DenoisingTask::set_render_buffer(RenderTile *rtiles)
 {
-       tiles = (TilesInfo*) tiles_mem.alloc(sizeof(TilesInfo)/sizeof(int));
+       tile_info = (TileInfo*) tile_info_mem.alloc(sizeof(TileInfo)/sizeof(int));
 
        device_ptr buffers[9];
        for(int i = 0; i < 9; i++) {
                buffers[i] = rtiles[i].buffer;
-               tiles->offsets[i] = rtiles[i].offset;
-               tiles->strides[i] = rtiles[i].stride;
+               tile_info->offsets[i] = rtiles[i].offset;
+               tile_info->strides[i] = rtiles[i].stride;
        }
-       tiles->x[0] = rtiles[3].x;
-       tiles->x[1] = rtiles[4].x;
-       tiles->x[2] = rtiles[5].x;
-       tiles->x[3] = rtiles[5].x + rtiles[5].w;
-       tiles->y[0] = rtiles[1].y;
-       tiles->y[1] = rtiles[4].y;
-       tiles->y[2] = rtiles[7].y;
-       tiles->y[3] = rtiles[7].y + rtiles[7].h;
-
-       render_buffer.offset = rtiles[4].offset;
-       render_buffer.stride = rtiles[4].stride;
-       render_buffer.ptr    = rtiles[4].buffer;
-
-       functions.set_tiles(buffers);
+       tile_info->x[0] = rtiles[3].x;
+       tile_info->x[1] = rtiles[4].x;
+       tile_info->x[2] = rtiles[5].x;
+       tile_info->x[3] = rtiles[5].x + rtiles[5].w;
+       tile_info->y[0] = rtiles[1].y;
+       tile_info->y[1] = rtiles[4].y;
+       tile_info->y[2] = rtiles[7].y;
+       tile_info->y[3] = rtiles[7].y + rtiles[7].h;
+
+       target_buffer.offset = rtiles[9].offset;
+       target_buffer.stride = rtiles[9].stride;
+       target_buffer.ptr    = rtiles[9].buffer;
+
+       functions.set_tile_info(buffers);
 }
 
 void DenoisingTask::setup_denoising_buffer()
@@ -85,7 +89,7 @@ void DenoisingTask::setup_denoising_buffer()
        /* Expand filter_area by radius pixels and clamp the result to the extent of the neighboring tiles */
        rect = rect_from_shape(filter_area.x, filter_area.y, filter_area.z, filter_area.w);
        rect = rect_expand(rect, radius);
-       rect = rect_clip(rect, make_int4(tiles->x[0], tiles->y[0], tiles->x[3], tiles->y[3]));
+       rect = rect_clip(rect, make_int4(tile_info->x[0], tile_info->y[0], tile_info->x[3], tile_info->y[3]));
 
        buffer.passes = 14;
        buffer.width = rect.z - rect.x;
@@ -228,21 +232,26 @@ void DenoisingTask::reconstruct()
        storage.XtWY.alloc_to_device(storage.w*storage.h*XTWY_SIZE, false);
 
        reconstruction_state.filter_window = rect_from_shape(filter_area.x-rect.x, filter_area.y-rect.y, storage.w, storage.h);
-       int tile_coordinate_offset = filter_area.y*render_buffer.stride + filter_area.x;
-       reconstruction_state.buffer_params = make_int4(render_buffer.offset + tile_coordinate_offset,
-                                                      render_buffer.stride,
-                                                      render_buffer.pass_stride,
-                                                      render_buffer.denoising_clean_offset);
+       int tile_coordinate_offset = filter_area.y*target_buffer.stride + filter_area.x;
+       reconstruction_state.buffer_params = make_int4(target_buffer.offset + tile_coordinate_offset,
+                                                      target_buffer.stride,
+                                                      target_buffer.pass_stride,
+                                                      target_buffer.denoising_clean_offset);
        reconstruction_state.source_w = rect.z-rect.x;
        reconstruction_state.source_h = rect.w-rect.y;
 
        device_sub_ptr color_ptr    (buffer.mem,  8*buffer.pass_stride, 3*buffer.pass_stride);
        device_sub_ptr color_var_ptr(buffer.mem, 11*buffer.pass_stride, 3*buffer.pass_stride);
-       functions.reconstruct(*color_ptr, *color_var_ptr, render_buffer.ptr);
+       functions.reconstruct(*color_ptr, *color_var_ptr, target_buffer.ptr);
 }
 
-void DenoisingTask::run_denoising()
+void DenoisingTask::run_denoising(RenderTile *tile)
 {
+       RenderTile rtiles[10];
+       rtiles[4] = *tile;
+       functions.map_neighbor_tiles(rtiles);
+       set_render_buffer(rtiles);
+
        setup_denoising_buffer();
 
        prefilter_shadowing();
@@ -252,6 +261,7 @@ void DenoisingTask::run_denoising()
        construct_transform();
        reconstruct();
 
+       functions.unmap_neighbor_tiles(rtiles);
 }
 
 CCL_NAMESPACE_END