Code refactor: add WorkTile struct for passing work to kernel.
[blender-staging.git] / intern / cycles / kernel / split / kernel_buffer_update.h
index c9e7deddafa310833ef91941f2364b284607dcd9..e854776748055807fb2f4aaf8d1dcffbf1abc987 100644 (file)
@@ -75,8 +75,6 @@ ccl_device void kernel_buffer_update(KernelGlobals *kg,
        if(ray_index != QUEUE_EMPTY_SLOT) {
 #endif
 
-       int stride = kernel_split_params.stride;
-
        ccl_global char *ray_state = kernel_split_state.ray_state;
        ccl_global PathState *state = &kernel_split_state.path_state[ray_index];
        PathRadiance *L = &kernel_split_state.path_radiance[ray_index];
@@ -86,7 +84,7 @@ ccl_device void kernel_buffer_update(KernelGlobals *kg,
        if(IS_STATE(ray_state, ray_index, RAY_UPDATE_BUFFER)) {
                uint sample = state->sample;
                uint buffer_offset = kernel_split_state.buffer_offset[ray_index];
-               ccl_global float *buffer = kernel_split_params.buffer + buffer_offset;
+               ccl_global float *buffer = kernel_split_params.tile.buffer + buffer_offset;
 
                /* accumulate result in output buffer */
                kernel_write_result(kg, buffer, sample, L);
@@ -96,22 +94,27 @@ ccl_device void kernel_buffer_update(KernelGlobals *kg,
 
        if(IS_STATE(ray_state, ray_index, RAY_TO_REGENERATE)) {
                /* We have completed current work; So get next work */
+               ccl_global uint *work_pools = kernel_split_params.work_pools;
+               uint total_work_size = kernel_split_params.total_work_size;
                uint work_index;
-               if(!get_next_work(kg, ray_index, &work_index)) {
+
+               if(!get_next_work(kg, work_pools, total_work_size, ray_index, &work_index)) {
                        /* If work is invalid, this means no more work is available and the thread may exit */
                        ASSIGN_RAY_STATE(ray_state, ray_index, RAY_INACTIVE);
                }
 
                if(IS_STATE(ray_state, ray_index, RAY_TO_REGENERATE)) {
+                       ccl_global WorkTile *tile = &kernel_split_params.tile;
                        uint x, y, sample;
-                       get_work_pixel(kg, work_index, &x, &y, &sample);
+                       get_work_pixel(tile, work_index, &x, &y, &sample);
 
                        /* Remap rng_state to current pixel. */
-                       ccl_global uint *rng_state = kernel_split_params.rng_state;
-                       rng_state += kernel_split_params.offset + x + y*stride;
+                       ccl_global uint *rng_state = kernel_split_params.tile.rng_state;
+                       rng_state += tile->offset + x + y*tile->stride;
 
                        /* Store buffer offset for writing to passes. */
-                       uint buffer_offset = (kernel_split_params.offset + x + y*stride) * kernel_data.film.pass_stride;
+                       uint buffer_offset = (tile->offset + x + y*tile->stride) * kernel_data.film.pass_stride;
+                       ccl_global float *buffer = tile->buffer + buffer_offset;
                        kernel_split_state.buffer_offset[ray_index] = buffer_offset;
 
                        /* Initialize random numbers and ray. */
@@ -135,7 +138,6 @@ ccl_device void kernel_buffer_update(KernelGlobals *kg,
                                /* These rays do not participate in path-iteration. */
                                float4 L_rad = make_float4(0.0f, 0.0f, 0.0f, 0.0f);
                                /* Accumulate result in output buffer. */
-                               ccl_global float *buffer = kernel_split_params.buffer + buffer_offset;
                                kernel_write_pass_float4(buffer, sample, L_rad);
 
                                ASSIGN_RAY_STATE(ray_state, ray_index, RAY_TO_REGENERATE);