Cycles: Only calculate global size of split kernel once to avoid changes
authorMai Lavelle <mai.lavelle@gmail.com>
Tue, 11 Apr 2017 07:02:43 +0000 (03:02 -0400)
committerMai Lavelle <mai.lavelle@gmail.com>
Tue, 11 Apr 2017 07:26:18 +0000 (03:26 -0400)
Global size depends on memory usage which might change during rendering.
Havent seen it happen but seems possible that this could cause the global
size to be different than what was used for allocating buffers.

intern/cycles/device/device_split_kernel.cpp
intern/cycles/device/device_split_kernel.h

index fa641161c0508b29eb1e9c88b5476b3921b1239f..981ec74fe56039233607e3f7bedc173405e500e1 100644 (file)
@@ -128,26 +128,27 @@ bool DeviceSplitKernel::path_trace(DeviceTask *task,
                local_size[1] = lsize[1];
        }
 
-       /* Set gloabl size */
-       size_t global_size[2];
-       {
-               int2 gsize = split_kernel_global_size(kgbuffer, kernel_data, task);
-
-               /* Make sure that set work size is a multiple of local
-                * work size dimensions.
-                */
-               global_size[0] = round_up(gsize[0], local_size[0]);
-               global_size[1] = round_up(gsize[1], local_size[1]);
-       }
-
        /* Number of elements in the global state buffer */
        int num_global_elements = global_size[0] * global_size[1];
-       assert(num_global_elements % WORK_POOL_SIZE == 0);
 
        /* Allocate all required global memory once. */
        if(first_tile) {
                first_tile = false;
 
+               /* Set gloabl size */
+               {
+                       int2 gsize = split_kernel_global_size(kgbuffer, kernel_data, task);
+
+                       /* Make sure that set work size is a multiple of local
+                        * work size dimensions.
+                        */
+                       global_size[0] = round_up(gsize[0], local_size[0]);
+                       global_size[1] = round_up(gsize[1], local_size[1]);
+               }
+
+               num_global_elements = global_size[0] * global_size[1];
+               assert(num_global_elements % WORK_POOL_SIZE == 0);
+
                /* Calculate max groups */
 
                /* Denotes the maximum work groups possible w.r.t. current requested tile size. */
index 15a94953a11419a65ecbe3902b9928f371e7cc9b..55548122c0c84d965caf139185e3c545c827cfbe 100644 (file)
@@ -95,6 +95,9 @@ private:
        /* Marked True in constructor and marked false at the end of path_trace(). */
        bool first_tile;
 
+       /* Cached global size */
+       size_t global_size[2];
+
 public:
        explicit DeviceSplitKernel(Device* device);
        virtual ~DeviceSplitKernel();