Code refactor: use device_only_memory and device_vector in more places.
authorBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 23 Oct 2017 17:32:59 +0000 (19:32 +0200)
committerBrecht Van Lommel <brechtvanlommel@gmail.com>
Mon, 23 Oct 2017 23:25:13 +0000 (01:25 +0200)
intern/cycles/device/device_cpu.cpp
intern/cycles/device/device_cuda.cpp
intern/cycles/device/device_split_kernel.cpp
intern/cycles/device/device_split_kernel.h
intern/cycles/device/opencl/memory_manager.cpp
intern/cycles/device/opencl/memory_manager.h
intern/cycles/device/opencl/opencl.h
intern/cycles/device/opencl/opencl_base.cpp
intern/cycles/device/opencl/opencl_split.cpp

index 60c06462d4def6b650b31e33738035dee39a133f..b4398f210144ed533eb5c27ace72950a63421dbe 100644 (file)
@@ -745,7 +745,7 @@ public:
                while(task.acquire_tile(this, tile)) {
                        if(tile.task == RenderTile::PATH_TRACE) {
                                if(use_split_kernel) {
                while(task.acquire_tile(this, tile)) {
                        if(tile.task == RenderTile::PATH_TRACE) {
                                if(use_split_kernel) {
-                                       device_memory void_buffer(this, "void_buffer", MEM_READ_ONLY);
+                                       device_only_memory<uchar> void_buffer(this, "void_buffer");
                                        split_kernel->path_trace(&task, tile, kgbuffer, void_buffer);
                                }
                                else {
                                        split_kernel->path_trace(&task, tile, kgbuffer, void_buffer);
                                }
                                else {
index 1295ec86355e0a54170d634e5bb99b386d2a600d..be606a92434b3ad9f8491d92de2b66d980ff66ca 100644 (file)
@@ -1728,7 +1728,7 @@ public:
                        while(task->acquire_tile(this, tile)) {
                                if(tile.task == RenderTile::PATH_TRACE) {
                                        if(use_split_kernel()) {
                        while(task->acquire_tile(this, tile)) {
                                if(tile.task == RenderTile::PATH_TRACE) {
                                        if(use_split_kernel()) {
-                                               device_memory void_buffer(this, "void_buffer", MEM_READ_ONLY);
+                                               device_only_memory<uchar> void_buffer(this, "void_buffer");
                                                split_kernel->path_trace(task, tile, void_buffer, void_buffer);
                                        }
                                        else {
                                                split_kernel->path_trace(task, tile, void_buffer, void_buffer);
                                        }
                                        else {
index 5283bd60bd5420d465662a8bd1c73ebd6ea1c9f6..6c8befa89bead042d6ccc380e46f12831729446a 100644 (file)
@@ -28,7 +28,7 @@ static const double alpha = 0.1; /* alpha for rolling average */
 
 DeviceSplitKernel::DeviceSplitKernel(Device *device)
 : device(device),
 
 DeviceSplitKernel::DeviceSplitKernel(Device *device)
 : device(device),
-  split_data(device, "split_data", MEM_READ_WRITE),
+  split_data(device, "split_data"),
   ray_state(device, "ray_state", MEM_READ_WRITE),
   queue_index(device, "queue_index"),
   use_queues_flag(device, "use_queues_flag"),
   ray_state(device, "ray_state", MEM_READ_WRITE),
   queue_index(device, "queue_index"),
   use_queues_flag(device, "use_queues_flag"),
index 9c42cb5852025effc03059f029bd25531d475f53..0647c66444749ea10f12d35ca5ff84d2dc736cb2 100644 (file)
@@ -79,7 +79,7 @@ private:
         * kernel will be available to another kernel via this global
         * memory.
         */
         * kernel will be available to another kernel via this global
         * memory.
         */
-       device_memory split_data;
+       device_only_memory<uchar> split_data;
        device_vector<uchar> ray_state;
        device_only_memory<int> queue_index; /* Array of size num_queues that tracks the size of each queue. */
 
        device_vector<uchar> ray_state;
        device_only_memory<int> queue_index; /* Array of size num_queues that tracks the size of each queue. */
 
index 6deed4e3f0d0f3335859242d300e434579aee5c4..e48367b8987d1189a20d1fdd87737715f19c1f09 100644 (file)
@@ -73,9 +73,8 @@ void MemoryManager::DeviceBuffer::update_device_memory(OpenCLDeviceBase *device)
                        return;
                }
 
                        return;
                }
 
-               device_memory *new_buffer = new device_memory(device,
-                                                             "memory manager buffer",
-                                                             MEM_READ_ONLY);
+               device_only_memory<uchar> *new_buffer =
+                       new device_only_memory<uchar>(device, "memory manager buffer");
 
                new_buffer->resize(total_size);
                device->mem_alloc(*new_buffer);
 
                new_buffer->resize(total_size);
                device->mem_alloc(*new_buffer);
@@ -167,9 +166,8 @@ MemoryManager::MemoryManager(OpenCLDeviceBase *device)
 : device(device), need_update(false)
 {
        foreach(DeviceBuffer& device_buffer, device_buffers) {
 : device(device), need_update(false)
 {
        foreach(DeviceBuffer& device_buffer, device_buffers) {
-               device_buffer.buffer = new device_memory(device,
-                                                        "memory manager buffer",
-                                                        MEM_READ_ONLY);
+               device_buffer.buffer =
+                       new device_only_memory<uchar>(device, "memory manager buffer");
        }
 }
 
        }
 }
 
index 7ef74a79834ebba263d97e1450b5d439db0cd3af..b3d861275f06efb1ce4357ffa0d5b41b0dacb005 100644 (file)
@@ -56,7 +56,7 @@ private:
        };
 
        struct DeviceBuffer {
        };
 
        struct DeviceBuffer {
-               device_memory *buffer;
+               device_only_memory<uchar> *buffer;
                vector<Allocation*> allocations;
                size_t size; /* Size of all allocations. */
 
                vector<Allocation*> allocations;
                size_t size; /* Size of all allocations. */
 
index 1dd4ad7df7f19179114e10928deea2b662b5c12b..55848c8112da0ec63b22daa0cb827256c07a1c74 100644 (file)
@@ -457,6 +457,11 @@ protected:
                {
                }
 
                {
                }
 
+               template<typename T>
+               ArgumentWrapper(device_only_memory<T>& argument) : size(sizeof(void*)),
+                                                                  pointer((void*)(&argument.device_pointer))
+               {
+               }
                template<typename T>
                ArgumentWrapper(T& argument) : size(sizeof(argument)),
                                               pointer(&argument)
                template<typename T>
                ArgumentWrapper(T& argument) : size(sizeof(argument)),
                                               pointer(&argument)
@@ -543,9 +548,7 @@ private:
        friend class MemoryManager;
 
        static_assert_align(TextureInfo, 16);
        friend class MemoryManager;
 
        static_assert_align(TextureInfo, 16);
-
-       vector<TextureInfo> texture_info;
-       device_memory texture_info_buffer;
+       device_vector<TextureInfo> texture_info;
 
        typedef map<string, device_memory*> TexturesMap;
        TexturesMap textures;
 
        typedef map<string, device_memory*> TexturesMap;
        TexturesMap textures;
index 89ab1a43e68e72ed80f4e7161abe0931573d91af..90f461b4c988269e26b14fe9ec41bc89a94c296e 100644 (file)
@@ -138,11 +138,9 @@ OpenCLDeviceBase::OpenCLDeviceBase(DeviceInfo& info, Stats &stats, bool backgrou
                return;
        }
 
                return;
        }
 
-       /* Allocate this right away so that texture_info_buffer is placed at offset 0 in the device memory buffers */
+       /* Allocate this right away so that texture_info is placed at offset 0 in the device memory buffers */
        texture_info.resize(1);
        texture_info.resize(1);
-       texture_info_buffer.resize(1);
-       texture_info_buffer.data_pointer = (device_ptr)&texture_info[0];
-       memory_manager.alloc("texture_info", texture_info_buffer);
+       memory_manager.alloc("texture_info", texture_info);
 
        fprintf(stderr, "Device init success\n");
        device_initialized = true;
 
        fprintf(stderr, "Device init success\n");
        device_initialized = true;
@@ -647,13 +645,9 @@ void OpenCLDeviceBase::flush_texture_buffers()
        }
 
        /* Realloc texture descriptors buffer. */
        }
 
        /* Realloc texture descriptors buffer. */
-       memory_manager.free(texture_info_buffer);
-
+       memory_manager.free(texture_info);
        texture_info.resize(num_slots);
        texture_info.resize(num_slots);
-       texture_info_buffer.resize(num_slots * sizeof(TextureInfo));
-       texture_info_buffer.data_pointer = (device_ptr)&texture_info[0];
-
-       memory_manager.alloc("texture_info", texture_info_buffer);
+       memory_manager.alloc("texture_info", texture_info);
 
        /* Fill in descriptors */
        foreach(texture_slot_t& slot, texture_slots) {
 
        /* Fill in descriptors */
        foreach(texture_slot_t& slot, texture_slots) {
@@ -676,8 +670,8 @@ void OpenCLDeviceBase::flush_texture_buffers()
        }
 
        /* Force write of descriptors. */
        }
 
        /* Force write of descriptors. */
-       memory_manager.free(texture_info_buffer);
-       memory_manager.alloc("texture_info", texture_info_buffer);
+       memory_manager.free(texture_info);
+       memory_manager.alloc("texture_info", texture_info);
 }
 
 void OpenCLDeviceBase::film_convert(DeviceTask& task, device_ptr buffer, device_ptr rgba_byte, device_ptr rgba_half)
 }
 
 void OpenCLDeviceBase::film_convert(DeviceTask& task, device_ptr buffer, device_ptr rgba_byte, device_ptr rgba_half)
index 3edb2442070911959bd3a123afd30a4cee0a8b70..c966ebe0c5ea403a21bd1b22ba15bd49abaa8d26 100644 (file)
@@ -127,8 +127,8 @@ public:
                        } KernelGlobals;
 
                        /* Allocate buffer for kernel globals */
                        } KernelGlobals;
 
                        /* Allocate buffer for kernel globals */
-                       device_memory kgbuffer(this, "kernel_globals", MEM_READ_WRITE);
-                       kgbuffer.resize(sizeof(KernelGlobals));
+                       device_only_memory<KernelGlobals> kgbuffer(this, "kernel_globals");
+                       kgbuffer.resize(1);
                        mem_alloc(kgbuffer);
 
                        /* Keep rendering tiles until done. */
                        mem_alloc(kgbuffer);
 
                        /* Keep rendering tiles until done. */