Code refactor: use device_only_memory and device_vector in more places.

This commit is contained in:
Brecht Van Lommel 2017-10-23 19:32:59 +02:00
parent 7ad9333fad
commit aa8b4c5d81
9 changed files with 23 additions and 28 deletions

View File

@ -745,7 +745,7 @@ public:
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 {

View File

@ -1728,7 +1728,7 @@ public:
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 {

View File

@ -28,7 +28,7 @@ static const double alpha = 0.1; /* alpha for rolling average */
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"),

View File

@ -79,7 +79,7 @@ private:
* 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. */

View File

@ -73,9 +73,8 @@ void MemoryManager::DeviceBuffer::update_device_memory(OpenCLDeviceBase *device)
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);
@ -167,9 +166,8 @@ MemoryManager::MemoryManager(OpenCLDeviceBase *device)
: 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");
}
}

View File

@ -56,7 +56,7 @@ private:
};
struct DeviceBuffer {
device_memory *buffer;
device_only_memory<uchar> *buffer;
vector<Allocation*> allocations;
size_t size; /* Size of all allocations. */

View 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)
@ -543,9 +548,7 @@ private:
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;

View File

@ -138,11 +138,9 @@ OpenCLDeviceBase::OpenCLDeviceBase(DeviceInfo& info, Stats &stats, bool backgrou
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_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;
@ -647,13 +645,9 @@ void OpenCLDeviceBase::flush_texture_buffers()
}
/* Realloc texture descriptors buffer. */
memory_manager.free(texture_info_buffer);
memory_manager.free(texture_info);
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) {
@ -676,8 +670,8 @@ void OpenCLDeviceBase::flush_texture_buffers()
}
/* 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)

View File

@ -127,8 +127,8 @@ public:
} 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. */