diff options
author | Brecht Van Lommel <brecht@blender.org> | 2020-03-12 17:22:18 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2020-03-12 19:28:55 +0300 |
commit | 26bea849cfa1d020150e0862002d7d5463f07817 (patch) | |
tree | 23bfbc7770dc0352dcc5378a14ffc681f7eb22ee /intern/cycles/device/opencl | |
parent | 75be60a66755f96e6d1d9b7e98bd0836784769f6 (diff) |
Cleanup: add device_texture for images, distinct from other global memory
There was too much image texture specific stuff in device_memory, and too
much code duplication between devices.
Diffstat (limited to 'intern/cycles/device/opencl')
-rw-r--r-- | intern/cycles/device/opencl/device_opencl.h | 6 | ||||
-rw-r--r-- | intern/cycles/device/opencl/device_opencl_impl.cpp | 76 |
2 files changed, 53 insertions, 29 deletions
diff --git a/intern/cycles/device/opencl/device_opencl.h b/intern/cycles/device/opencl/device_opencl.h index b761726b1ad..53017c34b2b 100644 --- a/intern/cycles/device/opencl/device_opencl.h +++ b/intern/cycles/device/opencl/device_opencl.h @@ -428,8 +428,10 @@ class OpenCLDevice : public Device { int mem_sub_ptr_alignment(); void const_copy_to(const char *name, void *host, size_t size); - void tex_alloc(device_memory &mem); - void tex_free(device_memory &mem); + void global_alloc(device_memory &mem); + void global_free(device_memory &mem); + void tex_alloc(device_texture &mem); + void tex_free(device_texture &mem); size_t global_size_round_up(int group_size, int global_size); void enqueue_kernel(cl_kernel kernel, diff --git a/intern/cycles/device/opencl/device_opencl_impl.cpp b/intern/cycles/device/opencl/device_opencl_impl.cpp index 09d3b78dd28..6b1b0e4c369 100644 --- a/intern/cycles/device/opencl/device_opencl_impl.cpp +++ b/intern/cycles/device/opencl/device_opencl_impl.cpp @@ -613,7 +613,7 @@ OpenCLDevice::OpenCLDevice(DeviceInfo &info, Stats &stats, Profiler &profiler, b kernel_programs(this), preview_programs(this), memory_manager(this), - texture_info(this, "__texture_info", MEM_TEXTURE) + texture_info(this, "__texture_info", MEM_GLOBAL) { cpPlatform = NULL; cdDevice = NULL; @@ -945,7 +945,7 @@ void OpenCLDevice::mem_alloc(device_memory &mem) cl_mem_flags mem_flag; void *mem_ptr = NULL; - if (mem.type == MEM_READ_ONLY || mem.type == MEM_TEXTURE) + if (mem.type == MEM_READ_ONLY || mem.type == MEM_TEXTURE || mem.type == MEM_GLOBAL) mem_flag = CL_MEM_READ_ONLY; else mem_flag = CL_MEM_READ_WRITE; @@ -969,9 +969,13 @@ void OpenCLDevice::mem_alloc(device_memory &mem) void OpenCLDevice::mem_copy_to(device_memory &mem) { - if (mem.type == MEM_TEXTURE) { - tex_free(mem); - tex_alloc(mem); + if (mem.type == MEM_GLOBAL) { + global_free(mem); + global_alloc(mem); + } + else if (mem.type == MEM_TEXTURE) { + tex_free((device_texture &)mem); + tex_alloc((device_texture &)mem); } else { if (!mem.device_pointer) { @@ -1077,8 +1081,11 @@ void OpenCLDevice::mem_zero(device_memory &mem) void OpenCLDevice::mem_free(device_memory &mem) { - if (mem.type == MEM_TEXTURE) { - tex_free(mem); + if (mem.type == MEM_GLOBAL) { + global_free(mem); + } + else if (mem.type == MEM_TEXTURE) { + tex_free((device_texture &)mem); } else { if (mem.device_pointer) { @@ -1101,7 +1108,7 @@ int OpenCLDevice::mem_sub_ptr_alignment() device_ptr OpenCLDevice::mem_alloc_sub_ptr(device_memory &mem, int offset, int size) { cl_mem_flags mem_flag; - if (mem.type == MEM_READ_ONLY || mem.type == MEM_TEXTURE) + if (mem.type == MEM_READ_ONLY || mem.type == MEM_TEXTURE || mem.type == MEM_GLOBAL) mem_flag = CL_MEM_READ_ONLY; else mem_flag = CL_MEM_READ_WRITE; @@ -1141,9 +1148,9 @@ void OpenCLDevice::const_copy_to(const char *name, void *host, size_t size) data->copy_to_device(); } -void OpenCLDevice::tex_alloc(device_memory &mem) +void OpenCLDevice::global_alloc(device_memory &mem) { - VLOG(1) << "Texture allocate: " << mem.name << ", " + VLOG(1) << "Global memory allocate: " << mem.name << ", " << string_human_readable_number(mem.memory_size()) << " bytes. (" << string_human_readable_size(mem.memory_size()) << ")"; @@ -1155,7 +1162,7 @@ void OpenCLDevice::tex_alloc(device_memory &mem) textures_need_update = true; } -void OpenCLDevice::tex_free(device_memory &mem) +void OpenCLDevice::global_free(device_memory &mem) { if (mem.device_pointer) { mem.device_pointer = 0; @@ -1173,6 +1180,25 @@ void OpenCLDevice::tex_free(device_memory &mem) } } +void OpenCLDevice::tex_alloc(device_texture &mem) +{ + VLOG(1) << "Texture allocate: " << mem.name << ", " + << string_human_readable_number(mem.memory_size()) << " bytes. (" + << string_human_readable_size(mem.memory_size()) << ")"; + + memory_manager.alloc(mem.name, mem); + /* Set the pointer to non-null to keep code that inspects its value from thinking its + * unallocated. */ + mem.device_pointer = 1; + textures[mem.name] = &mem; + textures_need_update = true; +} + +void OpenCLDevice::tex_free(device_texture &mem) +{ + global_free(mem); +} + size_t OpenCLDevice::global_size_round_up(int group_size, int global_size) { int r = global_size % group_size; @@ -1273,10 +1299,10 @@ void OpenCLDevice::flush_texture_buffers() foreach (TexturesMap::value_type &tex, textures) { string name = tex.first; + device_memory *mem = tex.second; - if (string_startswith(name, "__tex_image")) { - int pos = name.rfind("_"); - int id = atoi(name.data() + pos + 1); + if (mem->type == MEM_TEXTURE) { + const uint id = ((device_texture *)mem)->slot; texture_slots.push_back(texture_slot_t(name, num_data_slots + id)); num_slots = max(num_slots, num_data_slots + id + 1); } @@ -1289,24 +1315,20 @@ void OpenCLDevice::flush_texture_buffers() /* Fill in descriptors */ foreach (texture_slot_t &slot, texture_slots) { + device_memory *mem = textures[slot.name]; TextureInfo &info = texture_info[slot.slot]; MemoryManager::BufferDescriptor desc = memory_manager.get_descriptor(slot.name); - info.data = desc.offset; - info.cl_buffer = desc.device_buffer; - - if (string_startswith(slot.name, "__tex_image")) { - device_memory *mem = textures[slot.name]; - info.data_type = mem->image_data_type; - - info.width = mem->data_width; - info.height = mem->data_height; - info.depth = mem->data_depth; - - info.interpolation = mem->interpolation; - info.extension = mem->extension; + if (mem->type == MEM_TEXTURE) { + info = ((device_texture *)mem)->info; + } + else { + memset(&info, 0, sizeof(TextureInfo)); } + + info.data = desc.offset; + info.cl_buffer = desc.device_buffer; } /* Force write of descriptors. */ |