[Bf-blender-cvs] [44d541a6476] soc-2018-cycles-volumes: Initial fix for CUDA, OpenCL sparse grid sampling.
Geraldine Chua
noreply at git.blender.org
Thu Aug 2 18:10:17 CEST 2018
Commit: 44d541a6476d3a3f15d6a6fd227a488768dbb86d
Author: Geraldine Chua
Date: Fri Aug 3 00:07:58 2018 +0800
Branches: soc-2018-cycles-volumes
https://developer.blender.org/rB44d541a6476d3a3f15d6a6fd227a488768dbb86d
Initial fix for CUDA, OpenCL sparse grid sampling.
===================================================================
M intern/cycles/device/device_cpu.cpp
M intern/cycles/device/device_cuda.cpp
M intern/cycles/device/device_memory.h
M intern/cycles/device/opencl/opencl_base.cpp
M intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h
M intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h
M intern/cycles/render/image.cpp
M intern/cycles/render/image.h
M intern/cycles/render/mesh_volume.cpp
M intern/cycles/util/util_sparse_grid.h
M intern/cycles/util/util_texture.h
===================================================================
diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp
index 47ef95cb59f..aa016e2a12b 100644
--- a/intern/cycles/device/device_cpu.cpp
+++ b/intern/cycles/device/device_cpu.cpp
@@ -52,7 +52,6 @@
#include "util/util_progress.h"
#include "util/util_system.h"
#include "util/util_thread.h"
-#include "util/util_sparse_grid.h"
CCL_NAMESPACE_BEGIN
@@ -376,17 +375,9 @@ public:
void tex_alloc(device_memory& mem)
{
- size_t total_memory = mem.memory_size();
- device_memory *sparse_mem = NULL;
-
- if(mem.grid_info && mem.grid_type == IMAGE_GRID_TYPE_SPARSE) {
- sparse_mem = (device_memory*)mem.grid_info;
- total_memory += sparse_mem->memory_size();
- }
-
VLOG(1) << "Texture allocate: " << mem.name << ", "
- << string_human_readable_number(total_memory) << " bytes. ("
- << string_human_readable_size(total_memory) << ")";
+ << string_human_readable_number(mem.memory_size()) << " bytes. ("
+ << string_human_readable_size(mem.memory_size()) << ")";
if(mem.interpolation == INTERPOLATION_NONE) {
/* Data texture. */
@@ -417,24 +408,34 @@ public:
info.cl_buffer = 0;
info.interpolation = mem.interpolation;
info.extension = mem.extension;
- info.width = mem.real_width;
- info.height = mem.real_height;
- info.depth = mem.real_depth;
-
- SparseTextureInfo sparse_info;
- if(mem.grid_type == IMAGE_GRID_TYPE_SPARSE) {
- sparse_info.offsets = (uint64_t)sparse_mem->host_pointer;
- sparse_info.tiled_w = get_tile_res(info.width);
- sparse_info.tiled_h = get_tile_res(info.height);
- sparse_info.remain_w = info.width % TILE_SIZE;
- sparse_info.remain_h = info.height % TILE_SIZE;
- sparse_info.div_w = info.width - sparse_info.remain_w;
- sparse_info.div_h = info.height - sparse_info.remain_h;
- }
- else {
- sparse_info.offsets = 0;
+ info.width = mem.dense_width;
+ info.height = mem.dense_height;
+ info.depth = mem.dense_depth;
+
+ SparseTextureInfo s_info;
+ s_info.offsets = 0;
+
+ /* If image is sparse, cache info needed for index calculation. */
+ if(mem.grid_info && mem.grid_type == IMAGE_GRID_TYPE_SPARSE) {
+ device_memory *sparse_mem = (device_memory*)mem.grid_info;
+ s_info.offsets = (uint64_t)sparse_mem->host_pointer;
+ s_info.remain_w = info.width % TILE_SIZE;
+ s_info.remain_h = info.height % TILE_SIZE;
+ s_info.tiled_w = info.width / TILE_SIZE + (s_info.remain_w != 0);
+ s_info.tiled_h = info.height / TILE_SIZE + (s_info.remain_h != 0);
+ s_info.div_w = info.width - s_info.remain_w;
+ s_info.div_h = info.height - s_info.remain_h;
+
+ VLOG(1) << "Allocate: " << sparse_mem->name << ", "
+ << string_human_readable_number(sparse_mem->memory_size()) << " bytes. ("
+ << string_human_readable_size(sparse_mem->memory_size()) << ")";
+
+ sparse_mem->device_pointer = (device_ptr)sparse_mem->host_pointer;
+ sparse_mem->device_size = sparse_mem->memory_size();
+ stats.mem_alloc(sparse_mem->device_size);
}
- info.sparse_info = sparse_info;
+
+ info.sparse_info = s_info;
need_texture_info = true;
}
@@ -442,12 +443,6 @@ public:
mem.device_pointer = (device_ptr)mem.host_pointer;
mem.device_size = mem.memory_size();
stats.mem_alloc(mem.device_size);
-
- if(sparse_mem) {
- sparse_mem->device_pointer = (device_ptr)sparse_mem->host_pointer;
- sparse_mem->device_size = sparse_mem->memory_size();
- stats.mem_alloc(sparse_mem->device_size);
- }
}
void tex_free(device_memory& mem)
diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp
index d9f146339d2..363d41877f6 100644
--- a/intern/cycles/device/device_cuda.cpp
+++ b/intern/cycles/device/device_cuda.cpp
@@ -1020,9 +1020,6 @@ public:
string bind_name = mem.name;
size_t dsize = datatype_size(mem.data_type);
size_t size = mem.memory_size();
- if(mem.grid_info) {
- size += mem.grid_info->memory_size();
- }
CUaddress_mode address_mode = CU_TR_ADDRESS_MODE_WRAP;
switch(mem.extension) {
@@ -1225,6 +1222,26 @@ public:
info.width = mem.data_width;
info.height = mem.data_height;
info.depth = mem.data_depth;
+ info.sparse_info.offsets = 0;
+
+ /* If image is sparse, cache info needed for index calculation. */
+ if(mem.grid_info && mem.grid_type == IMAGE_GRID_TYPE_SPARSE_PAD) {
+ device_memory *sparse_mem = (device_memory*)mem.grid_info;
+ info.sparse_info.offsets = (uint64_t)sparse_mem->host_pointer;
+ info.sparse_info.tiled_w = (mem.dense_width / TILE_SIZE) +
+ (mem.dense_width % TILE_SIZE != 0);
+ info.sparse_info.tiled_h = (mem.dense_height / TILE_SIZE) +
+ (mem.dense_height % TILE_SIZE != 0);
+
+ VLOG(1) << "Allocate: " << sparse_mem->name << ", "
+ << string_human_readable_number(sparse_mem->memory_size()) << " bytes. ("
+ << string_human_readable_size(sparse_mem->memory_size()) << ")";
+
+ sparse_mem->device_pointer = (device_ptr)sparse_mem->host_pointer;
+ sparse_mem->device_size = sparse_mem->memory_size();
+ stats.mem_alloc(sparse_mem->device_size);
+ }
+
need_texture_info = true;
}
@@ -1252,6 +1269,15 @@ public:
generic_free(mem);
}
}
+
+ if(mem.grid_info && mem.grid_type == IMAGE_GRID_TYPE_SPARSE) {
+ device_memory *grid_info = (device_memory*)mem.grid_info;
+ if(grid_info->device_pointer) {
+ stats.mem_free(grid_info->device_size);
+ grid_info->device_pointer = 0;
+ grid_info->device_size = 0;
+ }
+ }
}
bool denoising_set_tiles(device_ptr *buffers, DenoisingTask *task)
diff --git a/intern/cycles/device/device_memory.h b/intern/cycles/device/device_memory.h
index 5d4fb130ca2..492b1503891 100644
--- a/intern/cycles/device/device_memory.h
+++ b/intern/cycles/device/device_memory.h
@@ -190,12 +190,11 @@ public:
size_t data_width;
size_t data_height;
size_t data_depth;
- /* For normal images, data_* = real_*. For sparse images,
- * real_* refers to the real voxel resolution of the image,
- * since sparse images are stored as a long 1D array. */
- size_t real_width;
- size_t real_height;
- size_t real_depth;
+ /* data_* stores actual dimensions, while dense_* stores image dimensions
+ * before compression. */
+ size_t dense_width;
+ size_t dense_height;
+ size_t dense_depth;
MemoryType type;
const char *name;
InterpolationType interpolation;
@@ -328,9 +327,9 @@ public:
}
data_size = new_size;
- data_width = real_width = width;
- data_height = real_height = height;
- data_depth = real_depth = depth;
+ data_width = dense_width = width;
+ data_height = dense_height = height;
+ data_depth = dense_depth = depth;
return data();
}
diff --git a/intern/cycles/device/opencl/opencl_base.cpp b/intern/cycles/device/opencl/opencl_base.cpp
index 0f4a80025b5..5c6c4cd6c20 100644
--- a/intern/cycles/device/opencl/opencl_base.cpp
+++ b/intern/cycles/device/opencl/opencl_base.cpp
@@ -526,14 +526,9 @@ void OpenCLDeviceBase::const_copy_to(const char *name, void *host, size_t size)
void OpenCLDeviceBase::tex_alloc(device_memory& mem)
{
- size_t total_memory = mem.memory_size();
- if(mem.grid_info) {
- total_memory += mem.grid_info->memory_size();
- }
-
VLOG(1) << "Texture allocate: " << mem.name << ", "
- << string_human_readable_number(total_memory) << " bytes. ("
- << string_human_readable_size(total_memory) << ")";
+ << 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. */
@@ -558,6 +553,15 @@ void OpenCLDeviceBase::tex_free(device_memory& mem)
}
}
}
+
+ if(mem.grid_info && mem.grid_type == IMAGE_GRID_TYPE_SPARSE) {
+ device_memory *grid_info = (device_memory*)mem.grid_info;
+ if(grid_info->device_pointer) {
+ stats.mem_free(grid_info->device_size);
+ grid_info->device_pointer = 0;
+ grid_info->device_size = 0;
+ }
+ }
}
size_t OpenCLDeviceBase::global_size_round_up(int group_size, int global_size)
@@ -691,6 +695,31 @@ void OpenCLDeviceBase::flush_texture_buffers()
info.interpolation = mem->interpolation;
info.extension = mem->extension;
+
+ SparseTextureInfo s_info;
+ s_info.offsets = 0;
+
+ /* If image is sparse, cache info needed for index calculation. */
+ if(mem->grid_info && mem->grid_type == IMAGE_GRID_TYPE_SPARSE) {
+ device_memory *sparse_mem = (device_memory*)mem->grid_info;
+ s_info.offsets = (uint64_t)sparse_mem->host_pointer;
+ s_info.remain_w = info.width % TILE_SIZE;
+ s_info.remain_h = info.height % TILE_SIZE;
+ s_info.tiled_w = info.width / TILE_SIZE + (s_info.remain_w != 0);
+ s_info.tiled_h = info.height / TILE_SIZE + (s_info.remain_h != 0);
+ s_info.div_w = info.width - s_info.remain_w;
+ s_info.div_h = info.height - s_info.remain_h;
+
+ VLOG(1) << "Allocate: " << sparse_mem->name << ", "
+ << string_human_readable_number(sparse_mem->memory_size()) << " bytes. ("
+ << string_human_readable_size(sparse_mem->memory_size()) << ")";
+
+ sparse_mem->device_pointer = (device_ptr)sparse_mem->host_pointer;
+ sparse_mem->device_size = sparse_mem->memory_size();
+ stats.mem_alloc(sparse_mem->device_size);
+ }
+
+ info.sparse_info = s_info;
}
}
diff --git a/intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h b/intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h
index f73f5cdbb3a..7724b0dc3f1 100644
--- a/intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h
+++ b/intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h
@@ -59,27 +59,30 @@ ccl_device float cubic_h1(float a)
}
/* Converts coordinates from normal volume textures dense to sparse ones. */
-ccl_device bool compute_sparse_coordinates(const TextureInfo *info, float &fx, float &fy, float &fz)
+ccl_device bool sparse_coordinates(const SparseTextureInfo *s_info, float &fx, float &fy, float &fz)
{
- float *ix, *iy, *iz;
- modff(fx, *ix);
- modff(fy, *iy);
- modff(fz, *iz);
- int x = *ix, y = *iy, z = *iz;
- int tix = x / TILE_SIZE, itix = x %
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list