Commit: b5765104acf8e9d5a5726022ac2fd612aa937bc6
Author: Mai Lavelle
Date:   Thu Oct 27 18:23:18 2016 +0200
Branches: cycles_split_kernel
https://developer.blender.org/rBb5765104acf8e9d5a5726022ac2fd612aa937bc6

Cycles: Add functions to allocate kernel globals for split kernel

CPU device needs to allocate and free thread specific data, these functions
are used to do that.

===================================================================

M       intern/cycles/device/device.h
M       intern/cycles/device/device_cpu.cpp
M       intern/cycles/device/device_split_kernel.cpp
M       intern/cycles/device/opencl/opencl_split.cpp

===================================================================

diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h
index 7857e5f..71e9a02 100644
--- a/intern/cycles/device/device.h
+++ b/intern/cycles/device/device.h
@@ -318,10 +318,14 @@ public:
                return NULL;
        }
 
-       virtual size_t sizeof_KernelGlobals()
+       virtual void alloc_kernel_globals(device_memory& /*mem*/)
+       {
+               assert(!"not implemented for this device");
+       }
+
+       virtual void free_kernel_globals(device_memory& /*mem*/)
        {
                assert(!"not implemented for this device");
-               return 0;
        }
 
        /* tasks */
diff --git a/intern/cycles/device/device_cpu.cpp 
b/intern/cycles/device/device_cpu.cpp
index e3f36ae..1955952 100644
--- a/intern/cycles/device/device_cpu.cpp
+++ b/intern/cycles/device/device_cpu.cpp
@@ -223,6 +223,8 @@ public:
                task_pool.stop();
        }
 
+       using Device::mem_alloc;
+
        void mem_alloc(device_memory& mem, MemoryType /*type*/)
        {
                mem.device_pointer = mem.data_pointer;
@@ -422,7 +424,6 @@ public:
                                return;
                }
 
-               KernelGlobals kg = thread_kernel_globals_init();
                RenderTile tile;
 
                DeviceSplitKernel split_kernel(this);
@@ -444,8 +445,6 @@ public:
                                        break;
                        }
                }
-
-               thread_kernel_globals_free(&kg);
        }
 
        void thread_film_convert(DeviceTask& task)
@@ -702,9 +701,17 @@ protected:
                return kernel;
        }
 
-       virtual size_t sizeof_KernelGlobals()
+       virtual void alloc_kernel_globals(device_memory& mem)
+       {
+               mem_alloc(mem, sizeof(KernelGlobals));
+
+               KernelGlobals *kg = (KernelGlobals*)mem.device_pointer;
+               *kg = thread_kernel_globals_init();
+       }
+
+       virtual void free_kernel_globals(device_memory& mem)
        {
-               return sizeof(KernelGlobals);
+               thread_kernel_globals_free((KernelGlobals*)mem.device_pointer);
        }
 };
 
diff --git a/intern/cycles/device/device_split_kernel.cpp 
b/intern/cycles/device/device_split_kernel.cpp
index afbb01b..b9cec54 100644
--- a/intern/cycles/device/device_split_kernel.cpp
+++ b/intern/cycles/device/device_split_kernel.cpp
@@ -32,7 +32,7 @@ DeviceSplitKernel::DeviceSplitKernel(Device *device) : 
device(device)
 
 DeviceSplitKernel::~DeviceSplitKernel()
 {
-       device->mem_free(kgbuffer);
+       device->free_kernel_globals(kgbuffer);
        device->mem_free(split_data);
        device->mem_free(ray_state);
        device->mem_free(use_queues_flag);
@@ -177,7 +177,7 @@ bool DeviceSplitKernel::path_trace(DeviceTask *task,
 
                device->mem_alloc(queue_index, NUM_QUEUES * sizeof(int));
                device->mem_alloc(use_queues_flag, sizeof(char));
-               device->mem_alloc(kgbuffer, device->sizeof_KernelGlobals());
+               device->alloc_kernel_globals(kgbuffer);
 
                ray_state.resize(num_global_elements);
                device->mem_alloc(ray_state, MEM_READ_WRITE);
diff --git a/intern/cycles/device/opencl/opencl_split.cpp 
b/intern/cycles/device/opencl/opencl_split.cpp
index 4387b62..7f50968 100644
--- a/intern/cycles/device/opencl/opencl_split.cpp
+++ b/intern/cycles/device/opencl/opencl_split.cpp
@@ -82,8 +82,7 @@ public:
                background = background_;
        }
 
-       /* Returns size of KernelGlobals structure associated with OpenCL. */
-       size_t sizeof_KernelGlobals()
+       virtual void alloc_kernel_globals(device_memory& mem)
        {
                /* Copy dummy KernelGlobals related to OpenCL from 
kernel_globals.h to
                 * fetch its size.
@@ -100,7 +99,12 @@ public:
                        SplitParams split_param_data;
                } KernelGlobals;
 
-               return sizeof(KernelGlobals);
+               mem_alloc(mem, sizeof(KernelGlobals));
+       }
+
+       virtual void free_kernel_globals(device_memory& mem)
+       {
+               mem_free(mem);
        }
 
        string get_build_options(const DeviceRequestedFeatures& 
requested_features)

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to