[Bf-blender-cvs] [56c834dacd6] soc-2018-volumes: Initial working implementation of tiling for sparse grids.
Geraldine Chua
noreply at git.blender.org
Wed May 30 19:21:57 CEST 2018
Commit: 56c834dacd604ccff6c947f02c91688d9ed3f845
Author: Geraldine Chua
Date: Tue May 29 01:33:47 2018 +0800
Branches: soc-2018-volumes
https://developer.blender.org/rB56c834dacd604ccff6c947f02c91688d9ed3f845
Initial working implementation of tiling for sparse grids.
===================================================================
M intern/cycles/blender/blender_session.cpp
M intern/cycles/device/device_cpu.cpp
M intern/cycles/device/device_memory.h
M intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
M intern/cycles/render/image.cpp
M intern/cycles/render/image.h
M intern/cycles/util/CMakeLists.txt
M intern/cycles/util/util_math_int4.h
A intern/cycles/util/util_sparse_grid.cpp
A intern/cycles/util/util_sparse_grid.h
M intern/cycles/util/util_texture.h
===================================================================
diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp
index 00d23b9095e..649d6edc679 100644
--- a/intern/cycles/blender/blender_session.cpp
+++ b/intern/cycles/blender/blender_session.cpp
@@ -1051,6 +1051,7 @@ void BlenderSession::builtin_image_info(const string &builtin_name,
BL::SmokeDomainSettings b_domain = object_smoke_domain_find(b_ob);
metadata.is_float = true;
+ metadata.is_volume = false;
metadata.depth = 1;
metadata.channels = 1;
@@ -1060,14 +1061,19 @@ void BlenderSession::builtin_image_info(const string &builtin_name,
if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_DENSITY) ||
builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_FLAME) ||
builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_HEAT) ||
- builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_TEMPERATURE))
+ builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_TEMPERATURE)) {
metadata.channels = 1;
- else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_COLOR))
+ }
+ else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_COLOR)) {
metadata.channels = 4;
- else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_VELOCITY))
+ metadata.is_volume = true;
+ }
+ else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_VELOCITY)) {
metadata.channels = 3;
- else
+ }
+ else {
return;
+ }
int3 resolution = get_int3(b_domain.domain_resolution());
int amplify = (b_domain.use_high_resolution())? b_domain.amplify() + 1: 1;
diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp
index 6be60f8bbb6..a21884de6d6 100644
--- a/intern/cycles/device/device_cpu.cpp
+++ b/intern/cycles/device/device_cpu.cpp
@@ -52,6 +52,7 @@
#include "util/util_progress.h"
#include "util/util_system.h"
#include "util/util_thread.h"
+#include "util/util_sparse_grid.h"
CCL_NAMESPACE_BEGIN
@@ -375,9 +376,14 @@ public:
void tex_alloc(device_memory& mem)
{
+ size_t total_memory = mem.memory_size();
+ device_memory *offsets = mem.offsets;
+ if(offsets != NULL)
+ total_memory += offsets->memory_size();
+
VLOG(1) << "Texture allocate: " << mem.name << ", "
- << string_human_readable_number(mem.memory_size()) << " bytes. ("
- << string_human_readable_size(mem.memory_size()) << ")";
+ << string_human_readable_number(total_memory) << " bytes. ("
+ << string_human_readable_size(total_memory) << ")";
if(mem.interpolation == INTERPOLATION_NONE) {
/* Data texture. */
@@ -390,7 +396,7 @@ public:
/* Image Texture. */
int flat_slot = 0;
if(string_startswith(mem.name, "__tex_image")) {
- int pos = string(mem.name).rfind("_");
+ int pos = string(mem.name).rfind("_");
flat_slot = atoi(mem.name + pos + 1);
}
else {
@@ -408,16 +414,34 @@ public:
info.cl_buffer = 0;
info.interpolation = mem.interpolation;
info.extension = mem.extension;
- info.width = mem.data_width;
- info.height = mem.data_height;
- info.depth = mem.data_depth;
-
+ if(offsets != NULL) {
+ /* If mem is a sparse volume, its real (tile)
+ * dimensions are stored in the offsets texture.
+ * Here, we store the pixel resolution. */
+ info.width = offsets->data_width * TILE_SIZE;
+ info.height = offsets->data_height * TILE_SIZE;
+ info.depth = offsets->data_depth * TILE_SIZE;
+ info.offsets = (uint64_t)offsets->host_pointer;
+ }
+ else {
+ info.width = mem.data_width;
+ info.height = mem.data_height;
+ info.depth = mem.data_depth;
+ info.offsets = (uint64_t)0;
+ }
need_texture_info = true;
}
mem.device_pointer = (device_ptr)mem.host_pointer;
mem.device_size = mem.memory_size();
stats.mem_alloc(mem.device_size);
+
+ if(offsets != NULL) {
+ offsets->device_pointer = (device_ptr)offsets->host_pointer;
+ offsets->device_size = offsets->memory_size();
+ stats.mem_alloc(offsets->device_size);
+ }
+
}
void tex_free(device_memory& mem)
diff --git a/intern/cycles/device/device_memory.h b/intern/cycles/device/device_memory.h
index d8fe41e78bb..dd7f72ce102 100644
--- a/intern/cycles/device/device_memory.h
+++ b/intern/cycles/device/device_memory.h
@@ -197,6 +197,7 @@ public:
device_ptr device_pointer;
void *host_pointer;
void *shared_pointer;
+ device_memory *offsets = NULL;
virtual ~device_memory();
diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
index 7bf833eadbc..3c18b08d5b8 100644
--- a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
+++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h
@@ -17,9 +17,12 @@
#ifndef __KERNEL_CPU_IMAGE_H__
#define __KERNEL_CPU_IMAGE_H__
+#include "util/util_sparse_grid.h"
+
CCL_NAMESPACE_BEGIN
-template<typename T> struct TextureInterpolator {
+template<typename T, bool is_tile = false>
+struct TextureInterpolator {
#define SET_CUBIC_SPLINE_WEIGHTS(u, t) \
{ \
u[0] = (((-1.0f/6.0f)* t + 0.5f) * t - 0.5f) * t + (1.0f/6.0f); \
@@ -68,7 +71,7 @@ template<typename T> struct TextureInterpolator {
int width, int height)
{
if(x < 0 || y < 0 || x >= width || y >= height) {
- return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ return make_float4(0.0f);
}
return read(data[y * width + x]);
}
@@ -111,7 +114,7 @@ template<typename T> struct TextureInterpolator {
break;
case EXTENSION_CLIP:
if(x < 0.0f || y < 0.0f || x > 1.0f || y > 1.0f) {
- return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ return make_float4(0.0f);
}
ATTR_FALLTHROUGH;
case EXTENSION_EXTEND:
@@ -120,7 +123,7 @@ template<typename T> struct TextureInterpolator {
break;
default:
kernel_assert(0);
- return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ return make_float4(0.0f);
}
return read(data[ix + iy*width]);
}
@@ -153,7 +156,7 @@ template<typename T> struct TextureInterpolator {
break;
default:
kernel_assert(0);
- return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ return make_float4(0.0f);
}
return (1.0f - ty) * (1.0f - tx) * read(data, ix, iy, width, height) +
(1.0f - ty) * tx * read(data, nix, iy, width, height) +
@@ -202,7 +205,7 @@ template<typename T> struct TextureInterpolator {
break;
default:
kernel_assert(0);
- return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ return make_float4(0.0f);
}
const int xc[4] = {pix, ix, nix, nnix};
const int yc[4] = {piy, iy, niy, nniy};
@@ -230,7 +233,7 @@ template<typename T> struct TextureInterpolator {
float x, float y)
{
if(UNLIKELY(!info.data)) {
- return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ return make_float4(0.0f);
}
switch(info.interpolation) {
case INTERPOLATION_CLOSEST:
@@ -266,7 +269,7 @@ template<typename T> struct TextureInterpolator {
if(x < 0.0f || y < 0.0f || z < 0.0f ||
x > 1.0f || y > 1.0f || z > 1.0f)
{
- return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ return make_float4(0.0f);
}
ATTR_FALLTHROUGH;
case EXTENSION_EXTEND:
@@ -276,11 +279,18 @@ template<typename T> struct TextureInterpolator {
break;
default:
kernel_assert(0);
- return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ return make_float4(0.0f);
}
- const T *data = (const T*)info.data;
- return read(data[ix + iy*width + iz*width*height]);
+ if(is_tile) {
+ const SparseTile *data = (const SparseTile*)info.data;
+ const int *ofs = (const int*)info.offsets;
+ return read(get_value(data, ofs, ix, iy, iz, width, height, depth));
+ }
+ else {
+ const T *data = (const T*)info.data;
+ return read(data[compute_index(ix, iy, iz, width, height, depth)]);
+ }
}
static ccl_always_inline float4 interp_3d_linear(const TextureInfo& info,
@@ -310,7 +320,7 @@ template<typename T> struct TextureInterpolator {
if(x < 0.0f || y < 0.0f || z < 0.0f ||
x > 1.0f || y > 1.0f || z > 1.0f)
{
- return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ return make_float4(0.0f);
}
ATTR_FALLTHROUGH;
case EXTENSION_EXTEND:
@@ -324,21 +334,39 @@ template<typename T> struct TextureInterpolator {
break;
default:
kernel_assert(0);
- return make_float4(0.0f, 0.0f, 0.0f, 0.0f);
+ return make_float4(0.0f);
}
- const T *data = (const T*)info.data;
float4 r;
- r = (1.0f - tz)*(1.0f - ty)*(1.0f - tx)*read(data[ix + iy*width + iz*width*height]);
- r += (1.0f - tz)*(1.0f - ty)*tx*read(data[nix + iy*width + iz*width*height]);
- r += (1.0f - tz)*ty*(1.0f - tx)*read(data[ix + niy*width + iz*width*height]);
- r += (1.0f - tz)*ty*tx*read(data[nix + niy*width + iz*width*height]);
-
- r += tz*(1.0f - ty)*(1.0f - tx)*read(data[ix + iy*width + niz*width*height]);
- r += tz*(1.0f - ty)*tx*read(data[nix + iy*width + niz*width*height]);
- r += tz*ty*(1.0f - tx)*read(data[ix + niy*width + niz*width*height]);
- r += tz*ty*tx*read(data[nix + niy*width + niz*width*height]);
+ if(is_tile) {
+ const SparseTile *data = (const SparseTile*)info.data;
+ const int *ofs = (const int*)info.offsets;
+ /* Initial check if either voxel is in an active tile. */
+ if(!is_active(ofs, ix, iy, iz, width, height, depth) &&
+ !is_active(ofs, nix, niy, niz, width, height, depth)) {
+ return make_float4(0.0f);
+ }
+ r = (1.0f - tz)*(1.0f - ty)*(1.0f - tx) * read(get_value(data, ofs, ix, iy, iz, width, height, depth));
+ r += (1.0f - tz)*(1.0f - ty)*tx * read(get_value(data, ofs, nix, iy, iz, width, height, depth));
+ r += (1.0f - tz)*ty*(1.0f - tx) * read(get_value(data, ofs, ix, niy, iz, width, height, depth));
+ r += (1.0f - tz)*ty*tx * read(get_value(data, ofs, nix, niy, iz, width, height, depth));
+ r += tz*(1.0f - ty)*(1.0f - tx) * read(get_value(data, ofs, ix, iy, niz, width, height, depth));
+ r += tz*(1.0f - ty)*tx * read(get_value(data, ofs, nix, iy, niz, width, height, depth));
+ r += tz*ty*(1.0f - tx) * read(get_value(data, ofs, ix, niy, niz, width, height, depth));
+ r += tz*ty*tx * read(get_value(d
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list