Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'intern/cycles/device/device_cpu.cpp')
-rw-r--r--intern/cycles/device/device_cpu.cpp111
1 files changed, 65 insertions, 46 deletions
diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp
index 0ba00da16a6..32ab18fe164 100644
--- a/intern/cycles/device/device_cpu.cpp
+++ b/intern/cycles/device/device_cpu.cpp
@@ -209,6 +209,7 @@ public:
CPUDevice(DeviceInfo& info_, Stats &stats_, bool background_)
: Device(info_, stats_, background_),
+ texture_info(this, "__texture_info", MEM_TEXTURE),
#define REGISTER_KERNEL(name) name ## _kernel(KERNEL_FUNCTIONS(name))
REGISTER_KERNEL(path_trace),
REGISTER_KERNEL(convert_to_half_float),
@@ -268,7 +269,7 @@ public:
~CPUDevice()
{
task_pool.stop();
- tex_free(texture_info);
+ texture_info.free();
}
virtual bool show_samples() const
@@ -279,33 +280,50 @@ public:
void load_texture_info()
{
if(need_texture_info) {
- tex_free(texture_info);
- tex_alloc("__texture_info", texture_info, INTERPOLATION_NONE, EXTENSION_REPEAT);
+ texture_info.copy_to_device();
need_texture_info = false;
}
}
- void mem_alloc(const char *name, device_memory& mem, MemoryType /*type*/)
+ void mem_alloc(device_memory& mem)
{
- if(name) {
- VLOG(1) << "Buffer allocate: " << name << ", "
- << string_human_readable_number(mem.memory_size()) << " bytes. ("
- << string_human_readable_size(mem.memory_size()) << ")";
+ if(mem.type == MEM_TEXTURE) {
+ assert(!"mem_alloc not supported for textures.");
}
+ else {
+ if(mem.name) {
+ VLOG(1) << "Buffer allocate: " << mem.name << ", "
+ << string_human_readable_number(mem.memory_size()) << " bytes. ("
+ << string_human_readable_size(mem.memory_size()) << ")";
+ }
- mem.device_pointer = mem.data_pointer;
+ mem.device_pointer = mem.data_pointer;
- if(!mem.device_pointer) {
- mem.device_pointer = (device_ptr)malloc(mem.memory_size());
- }
+ if(!mem.device_pointer) {
+ mem.device_pointer = (device_ptr)malloc(mem.memory_size());
+ }
- mem.device_size = mem.memory_size();
- stats.mem_alloc(mem.device_size);
+ mem.device_size = mem.memory_size();
+ stats.mem_alloc(mem.device_size);
+ }
}
- void mem_copy_to(device_memory& /*mem*/)
+ void mem_copy_to(device_memory& mem)
{
- /* no-op */
+ if(mem.type == MEM_TEXTURE) {
+ tex_free(mem);
+ tex_alloc(mem);
+ }
+ else if(mem.type == MEM_PIXELS) {
+ assert(!"mem_copy_to not supported for pixels.");
+ }
+ else {
+ if(!mem.device_pointer) {
+ mem_alloc(mem);
+ }
+
+ /* copy is no-op */
+ }
}
void mem_copy_from(device_memory& /*mem*/,
@@ -317,12 +335,21 @@ public:
void mem_zero(device_memory& mem)
{
- memset((void*)mem.device_pointer, 0, mem.memory_size());
+ if(!mem.device_pointer) {
+ mem_alloc(mem);
+ }
+
+ if(mem.device_pointer) {
+ memset((void*)mem.device_pointer, 0, mem.memory_size());
+ }
}
void mem_free(device_memory& mem)
{
- if(mem.device_pointer) {
+ if(mem.type == MEM_TEXTURE) {
+ tex_free(mem);
+ }
+ else if(mem.device_pointer) {
if(!mem.data_pointer) {
free((void*)mem.device_pointer);
}
@@ -332,7 +359,7 @@ public:
}
}
- virtual device_ptr mem_alloc_sub_ptr(device_memory& mem, int offset, int /*size*/, MemoryType /*type*/)
+ virtual device_ptr mem_alloc_sub_ptr(device_memory& mem, int offset, int /*size*/)
{
return (device_ptr) (((char*) mem.device_pointer) + mem.memory_elements_size(offset));
}
@@ -342,32 +369,25 @@ public:
kernel_const_copy(&kernel_globals, name, host, size);
}
- void tex_alloc(const char *name,
- device_memory& mem,
- InterpolationType interpolation,
- ExtensionType extension)
+ void tex_alloc(device_memory& mem)
{
- VLOG(1) << "Texture allocate: " << name << ", "
+ VLOG(1) << "Texture allocate: " << mem.name << ", "
<< string_human_readable_number(mem.memory_size()) << " bytes. ("
<< string_human_readable_size(mem.memory_size()) << ")";
- if(interpolation == INTERPOLATION_NONE) {
+ if(mem.interpolation == INTERPOLATION_NONE) {
/* Data texture. */
kernel_tex_copy(&kernel_globals,
- name,
+ mem.name,
mem.data_pointer,
- mem.data_width,
- mem.data_height,
- mem.data_depth,
- interpolation,
- extension);
+ mem.data_size);
}
else {
/* Image Texture. */
int flat_slot = 0;
- if(string_startswith(name, "__tex_image")) {
- int pos = string(name).rfind("_");
- flat_slot = atoi(name + pos + 1);
+ if(string_startswith(mem.name, "__tex_image")) {
+ int pos = string(mem.name).rfind("_");
+ flat_slot = atoi(mem.name + pos + 1);
}
else {
assert(0);
@@ -382,8 +402,8 @@ public:
TextureInfo& info = texture_info[flat_slot];
info.data = (uint64_t)mem.data_pointer;
info.cl_buffer = 0;
- info.interpolation = interpolation;
- info.extension = extension;
+ info.interpolation = mem.interpolation;
+ info.extension = mem.extension;
info.width = mem.data_width;
info.height = mem.data_height;
info.depth = mem.data_depth;
@@ -437,13 +457,13 @@ public:
bool denoising_set_tiles(device_ptr *buffers, DenoisingTask *task)
{
- mem_alloc("Denoising Tile Info", task->tiles_mem, MEM_READ_ONLY);
-
TilesInfo *tiles = (TilesInfo*) task->tiles_mem.data_pointer;
for(int i = 0; i < 9; i++) {
tiles->buffers[i] = buffers[i];
}
+ task->tiles_mem.copy_to_device();
+
return true;
}
@@ -728,9 +748,8 @@ public:
}
/* allocate buffer for kernel globals */
- device_only_memory<KernelGlobals> kgbuffer;
- kgbuffer.resize(1);
- mem_alloc("kernel_globals", kgbuffer, MEM_READ_WRITE);
+ device_only_memory<KernelGlobals> kgbuffer(this, "kernel_globals");
+ kgbuffer.alloc_to_device(1);
KernelGlobals *kg = new ((void*) kgbuffer.device_pointer) KernelGlobals(thread_kernel_globals_init());
@@ -740,8 +759,7 @@ public:
requested_features.max_closure = MAX_CLOSURE;
if(!split_kernel->load_kernels(requested_features)) {
thread_kernel_globals_free((KernelGlobals*)kgbuffer.device_pointer);
- mem_free(kgbuffer);
-
+ kgbuffer.free();
delete split_kernel;
return;
}
@@ -751,8 +769,8 @@ public:
while(task.acquire_tile(this, tile)) {
if(tile.task == RenderTile::PATH_TRACE) {
if(use_split_kernel) {
- device_memory data;
- split_kernel->path_trace(&task, tile, kgbuffer, data);
+ device_only_memory<uchar> void_buffer(this, "void_buffer");
+ split_kernel->path_trace(&task, tile, kgbuffer, void_buffer);
}
else {
path_trace(task, tile, kg);
@@ -772,7 +790,7 @@ public:
thread_kernel_globals_free((KernelGlobals*)kgbuffer.device_pointer);
kg->~KernelGlobals();
- mem_free(kgbuffer);
+ kgbuffer.free();
delete split_kernel;
}
@@ -1028,6 +1046,7 @@ void device_cpu_info(vector<DeviceInfo>& devices)
info.advanced_shading = true;
info.has_qbvh = system_cpu_support_sse2();
info.has_volume_decoupled = true;
+ info.has_osl = true;
devices.insert(devices.begin(), info);
}