[Bf-blender-cvs] [7ad9333fad2] master: Code refactor: store device/interp/extension/type in each device_memory.
Brecht Van Lommel
noreply at git.blender.org
Tue Oct 24 02:12:06 CEST 2017
Commit: 7ad9333fad25b9a7cabea0d659eaf724f89912c8
Author: Brecht Van Lommel
Date: Fri Oct 20 23:31:13 2017 +0200
Branches: master
https://developer.blender.org/rB7ad9333fad25b9a7cabea0d659eaf724f89912c8
Code refactor: store device/interp/extension/type in each device_memory.
===================================================================
M intern/cycles/device/CMakeLists.txt
M intern/cycles/device/device.cpp
M intern/cycles/device/device.h
M intern/cycles/device/device_cpu.cpp
M intern/cycles/device/device_cuda.cpp
M intern/cycles/device/device_denoising.cpp
M intern/cycles/device/device_denoising.h
A intern/cycles/device/device_memory.cpp
M intern/cycles/device/device_memory.h
M intern/cycles/device/device_multi.cpp
M intern/cycles/device/device_network.cpp
M intern/cycles/device/device_network.h
M intern/cycles/device/device_split_kernel.cpp
M intern/cycles/device/opencl/memory_manager.cpp
M intern/cycles/device/opencl/memory_manager.h
M intern/cycles/device/opencl/opencl.h
M intern/cycles/device/opencl/opencl_base.cpp
M intern/cycles/device/opencl/opencl_split.cpp
M intern/cycles/kernel/kernel.h
M intern/cycles/kernel/kernels/cpu/kernel.cpp
M intern/cycles/render/bake.cpp
M intern/cycles/render/buffers.cpp
M intern/cycles/render/image.cpp
M intern/cycles/render/integrator.cpp
M intern/cycles/render/light.cpp
M intern/cycles/render/mesh.cpp
M intern/cycles/render/mesh_displace.cpp
M intern/cycles/render/object.cpp
M intern/cycles/render/particles.cpp
M intern/cycles/render/scene.cpp
M intern/cycles/render/scene.h
M intern/cycles/render/shader.cpp
M intern/cycles/render/svm.cpp
M intern/cycles/render/tables.cpp
===================================================================
diff --git a/intern/cycles/device/CMakeLists.txt b/intern/cycles/device/CMakeLists.txt
index 3c632160fbd..959c0aa97c9 100644
--- a/intern/cycles/device/CMakeLists.txt
+++ b/intern/cycles/device/CMakeLists.txt
@@ -26,6 +26,7 @@ set(SRC
device_cpu.cpp
device_cuda.cpp
device_denoising.cpp
+ device_memory.cpp
device_multi.cpp
device_opencl.cpp
device_split_kernel.cpp
diff --git a/intern/cycles/device/device.cpp b/intern/cycles/device/device.cpp
index 16c027e2cb5..9de10c184fb 100644
--- a/intern/cycles/device/device.cpp
+++ b/intern/cycles/device/device.cpp
@@ -87,7 +87,7 @@ Device::~Device()
void Device::pixels_alloc(device_memory& mem)
{
- mem_alloc("pixels", mem, MEM_READ_WRITE);
+ mem_alloc(mem);
}
void Device::pixels_copy_from(device_memory& mem, int y, int w, int h)
@@ -429,16 +429,4 @@ void Device::free_memory()
devices.free_memory();
}
-
-device_sub_ptr::device_sub_ptr(Device *device, device_memory& mem, int offset, int size, MemoryType type)
- : device(device)
-{
- ptr = device->mem_alloc_sub_ptr(mem, offset, size, type);
-}
-
-device_sub_ptr::~device_sub_ptr()
-{
- device->mem_free_sub_ptr(ptr);
-}
-
CCL_NAMESPACE_END
diff --git a/intern/cycles/device/device.h b/intern/cycles/device/device.h
index 4bf88f75932..6bb65cde2a3 100644
--- a/intern/cycles/device/device.h
+++ b/intern/cycles/device/device.h
@@ -253,7 +253,7 @@ protected:
/* used for real time display */
unsigned int vertex_buffer;
- 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*/)
{
/* Only required for devices that implement denoising. */
assert(false);
@@ -282,7 +282,7 @@ public:
Stats &stats;
/* regular memory */
- virtual void mem_alloc(const char *name, device_memory& mem, MemoryType type) = 0;
+ virtual void mem_alloc(device_memory& mem) = 0;
virtual void mem_copy_to(device_memory& mem) = 0;
virtual void mem_copy_from(device_memory& mem,
int y, int w, int h, int elem) = 0;
@@ -295,15 +295,7 @@ public:
virtual void const_copy_to(const char *name, void *host, size_t size) = 0;
/* texture memory */
- virtual void tex_alloc(const char * /*name*/,
- device_memory& /*mem*/,
- InterpolationType interpolation = INTERPOLATION_NONE,
- ExtensionType extension = EXTENSION_REPEAT)
- {
- (void)interpolation; /* Ignored. */
- (void)extension; /* Ignored. */
- };
-
+ virtual void tex_alloc(device_memory& /*mem*/) {};
virtual void tex_free(device_memory& /*mem*/) {};
/* pixel memory */
diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp
index b05f24659ee..60c06462d4d 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"),
#define REGISTER_KERNEL(name) name ## _kernel(KERNEL_FUNCTIONS(name))
REGISTER_KERNEL(path_trace),
REGISTER_KERNEL(convert_to_half_float),
@@ -280,15 +281,15 @@ public:
{
if(need_texture_info) {
tex_free(texture_info);
- tex_alloc("__texture_info", texture_info, INTERPOLATION_NONE, EXTENSION_REPEAT);
+ tex_alloc(texture_info);
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 << ", "
+ if(mem.name) {
+ VLOG(1) << "Buffer allocate: " << mem.name << ", "
<< string_human_readable_number(mem.memory_size()) << " bytes. ("
<< string_human_readable_size(mem.memory_size()) << ")";
}
@@ -332,7 +333,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 +343,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_width);
}
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 +376,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,7 +431,7 @@ public:
bool denoising_set_tiles(device_ptr *buffers, DenoisingTask *task)
{
- mem_alloc("Denoising Tile Info", task->tiles_mem, MEM_READ_ONLY);
+ mem_alloc(task->tiles_mem);
TilesInfo *tiles = (TilesInfo*) task->tiles_mem.data_pointer;
for(int i = 0; i < 9; i++) {
@@ -728,9 +722,9 @@ public:
}
/* allocate buffer for kernel globals */
- device_only_memory<KernelGlobals> kgbuffer;
+ device_only_memory<KernelGlobals> kgbuffer(this, "kernel_globals");
kgbuffer.resize(1);
- mem_alloc("kernel_globals", kgbuffer, MEM_READ_WRITE);
+ mem_alloc(kgbuffer);
KernelGlobals *kg = new ((void*) kgbuffer.device_pointer) KernelGlobals(thread_kernel_globals_init());
@@ -751,8 +745,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_memory void_buffer(this, "void_buffer", MEM_READ_ONLY);
+ split_kernel->path_trace(&task, tile, kgbuffer, void_buffer);
}
else {
path_trace(task, tile, kg);
diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp
index 0f17b67c8c6..1295ec86355 100644
--- a/intern/cycles/device/device_cuda.cpp
+++ b/intern/cycles/device/device_cuda.cpp
@@ -217,7 +217,8 @@ public:
}
CUDADevice(DeviceInfo& info, Stats &stats, bool background_)
- : Device(info, stats, background_)
+ : Device(info, stats, background_),
+ texture_info(this, "__texture_info")
{
first_error = true;
background = background_;
@@ -548,17 +549,17 @@ public:
{
if(info.has_bindless_textures && need_texture_info) {
tex_free(texture_info);
- tex_alloc("__texture_info", texture_info, INTERPOLATION_NONE, EXTENSION_REPEAT);
+ tex_alloc(texture_info);
need_texture_info = false;
}
}
- void mem_alloc(const char *name, device_memory& mem, MemoryType /*type*/)
+ void mem_alloc(device_memory& mem)
{
CUDAContextScope scope(this);
- if(name) {
- VLOG(1) << "Buffer allocate: " << name << ", "
+ if(mem.name) {
+ VLOG(1) << "Buffer allocate: " << mem.name << ", "
<< string_human_readable_number(mem.memory_size()) << " bytes. ("
<< string_human_readable_size(mem.memory_size()) << ")";
}
@@ -619,7 +620,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));
}
@@ -635,14 +636,11 @@ public:
cuda_assert(cuMemcpyHtoD(mem, host, size));
}
- void tex_alloc(const char *name,
- device_memory& mem,
- InterpolationType interpolation,
- ExtensionType extension)
+ void tex_alloc(device_memory& mem)
{
CUDAContextScope scope(this);
- 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()) << ")";
@@ -650,12 +648,12 @@ public:
bool has_bindless_textures = info.has_bindless_textures;
/* General variables for both architectures */
- string bind_name = name;
+ string bind_name = mem.name;
size_t dsize = datatype_size(mem.data_type);
size_t size = mem.memory_size();
CUaddress_mode address_mode = CU_TR_ADDRESS_MODE_WRAP;
- switch(extension) {
+ switch(mem.extension) {
case EXTENSION_REPEAT:
address_mode = CU_TR_ADDRESS_MODE_WRAP;
break;
@@ -671,7 +669,7 @@ public:
}
CUfilter_mode filter_mode;
- if(interpolation == INTERPOLATION_CLOSEST) {
+ if(mem.interpolation == INTERPOLATION_CLOSEST) {
filter_mode = CU_TR_FILTER_MODE_POINT;
}
else {
@@ -681,13 +679,13 @@ public:
/* General variables for Fermi */
CUtexref texref = NULL;
- if(!has_bindless_textures && interpolation != INTERPOLATION_NONE) {
+ if(!has_bindless_textures && mem.interpolation != INTERPOLATION_NONE) {
if(mem.data_depth > 1) {
/* Kernel uses different bind names for 2d and 3d float textures,
* so we have to adjust couple of things here.
*/
vector<string> tokens;
- string
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list