[Bf-blender-cvs] [9f4e5581d18] soc-2018-cycles-volumes: OpenVDB import to padded sparse grids.
Commit: 9f4e5581d18899d665d61e93ae7c6933c5a3e770 Author: Geraldine Chua Date: Sun Aug 12 23:33:52 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB9f4e5581d18899d665d61e93ae7c6933c5a3e770 OpenVDB import to padded sparse grids. === M intern/cycles/render/image.cpp M intern/cycles/render/openvdb.cpp M intern/cycles/render/openvdb.h === diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp index 4c987957bb4..97302095e33 100644 --- a/intern/cycles/render/image.cpp +++ b/intern/cycles/render/image.cpp @@ -702,19 +702,28 @@ void ImageManager::file_load_extern_vdb(Device *device, return; } + const bool use_pad = (device->info.type == DEVICE_CUDA); int sparse_size = -1; vector sparse_offsets; openvdb_load_preprocess(img->filename, img->grid_name, img->isovalue, - _offsets, sparse_size); + use_pad, _offsets, sparse_size); /* Allocate space for image. */ float *pixels; { thread_scoped_lock device_lock(device_mutex); - if(sparse_size > -1) { + if(use_pad && sparse_size > -1) { + tex_img->grid_type = IMAGE_GRID_TYPE_SPARSE_PAD; + int width = sparse_size / (PADDED_TILE * PADDED_TILE * + (type == IMAGE_DATA_TYPE_FLOAT4 ? 4 : 1)); + pixels = (float*)tex_img->alloc(width, PADDED_TILE, PADDED_TILE); + } + else if(sparse_size > -1) { + tex_img->grid_type = IMAGE_GRID_TYPE_SPARSE; pixels = (float*)tex_img->alloc(sparse_size); } else { + tex_img->grid_type = IMAGE_GRID_TYPE_DEFAULT; pixels = (float*)tex_img->alloc(img->metadata.width, img->metadata.height, img->metadata.depth); @@ -728,21 +737,17 @@ void ImageManager::file_load_extern_vdb(Device *device, } /* Load image. */ - openvdb_load_image(img->filename, img->grid_name, pixels, _offsets); + openvdb_load_image(img->filename, img->grid_name, _offsets, + sparse_size, use_pad, pixels); /* Allocate space for sparse_index if it exists. */ if(sparse_size > -1) { - tex_img->grid_type = IMAGE_GRID_TYPE_SPARSE; - if(!allocate_grid_info(device, (device_memory*)tex_img, _offsets)) { /* Could be that we've run out of memory. */ file_load_failed(img, type, tex_img); return; } } - else { - tex_img->grid_type = IMAGE_GRID_TYPE_DEFAULT; - } /* Set metadata and copy. */ tex_img->dense_width = img->metadata.width; diff --git a/intern/cycles/render/openvdb.cpp b/intern/cycles/render/openvdb.cpp index a3dba94c6b3..a3b6330a891 100644 --- a/intern/cycles/render/openvdb.cpp +++ b/intern/cycles/render/openvdb.cpp @@ -244,7 +244,7 @@ bool validate_and_process_grid(typename GridType::Ptr , return true; } -/* Load OpenVDB grid to texture. */ +/* Load OpenVDB grid to texture. Based on util/util_sparse_grid.h */ template void image_load_preprocess(openvdb::GridBase::Ptr grid_base, @@ -252,6 +252,7 @@ void image_load_preprocess(openvdb::GridBase::Ptr grid_base, const openvdb::math::Coord min_bound, const int channels, const float threshold, + const bool use_pad, vector *sparse_indexes, int _size) { @@ -269,6 +270,8 @@ void image_load_preprocess(openvdb::GridBase::Ptr grid_base, } const int tile_count = coord_product(tiled_res); + + /* Initial prepass to find active tiles. */ sparse_indexes->resize(tile_count, -1); /* 0 if active, -1 if inactive. */ int voxel_count = 0; @@ -280,21 +283,51 @@ void image_load_preprocess(openvdb::GridBase::Ptr grid_base, if(gte_any(data[i], threshold)) { const math::Coord tile_start = leaf->getNodeBoundingBox().getStart(); sparse_indexes->at(get_tile_index(tile_start, tiled_res)) = voxel_count; - /* Calculate how many voxels are in this tile. */ - voxel_count += coord_product(g
[Bf-blender-cvs] [57beb92ccec] soc-2018-cycles-volumes: Minor bug-fixes and optimizations.
Commit: 57beb92ccec7d4952636231fc54b106aacb17d55 Author: Geraldine Chua Date: Sun Aug 12 17:14:29 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB57beb92ccec7d4952636231fc54b106aacb17d55 Minor bug-fixes and optimizations. * Change most instances of division and modulo with TILE_SIZE to bit shifting. Much more efficient since TILE_SIZE should be a power of 2. * Added intialization for some Mesh members. Previously had motion blur randomly toggle on and off otherwise. * Fixed issue where voxel to tile correspondence is different between external VDBs and internal sparse grids. The fix requires generating a new VDB grid which may be too memory intensive. Better method would be translating grids in place. * Fixed misc OpenVDB to grid conversion issues. === M intern/cycles/blender/blender_object.cpp M intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h M intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h M intern/cycles/kernel/kernels/opencl/kernel_opencl_image.h M intern/cycles/render/mesh.cpp M intern/cycles/render/openvdb.cpp M intern/cycles/util/util_sparse_grid.h M intern/cycles/util/util_texture.h === diff --git a/intern/cycles/blender/blender_object.cpp b/intern/cycles/blender/blender_object.cpp index 99f233524a4..6374c18d6fb 100644 --- a/intern/cycles/blender/blender_object.cpp +++ b/intern/cycles/blender/blender_object.cpp @@ -437,10 +437,6 @@ Object *BlenderSync::sync_object(BL::Depsgraph& b_depsgraph, Scene::MotionType need_motion = scene->need_motion(); if(need_motion != Scene::MOTION_NONE && object->mesh) { Mesh *mesh = object->mesh; - mesh->motion_steps = 0; - mesh->use_motion_blur = false; - mesh->use_volume_motion_blur = false; - uint motion_steps; if(scene->need_motion() == Scene::MOTION_BLUR) { diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h index bd5594b60f9..82f04300127 100644 --- a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h +++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h @@ -92,18 +92,18 @@ struct TextureInterpolator { const int *offsets, int x, int y, int z) { - int tix = x / TILE_SIZE, itix = x % TILE_SIZE, - tiy = y / TILE_SIZE, itiy = y % TILE_SIZE, - tiz = z / TILE_SIZE, itiz = z % TILE_SIZE; - int tile_index = tix + s_info.tiled_w * (tiy + tiz * s_info.tiled_h); - int sparse_index = offsets[tile_index]; - if(sparse_index < 0) { + int tile_start = offsets[(x >> TILE_INDEX_SHIFT) ++ s_info.tiled_w +* ((y >> TILE_INDEX_SHIFT) + + (z >> TILE_INDEX_SHIFT) + * s_info.tiled_h)]; + if(tile_start < 0) { return make_float4(0.0f); } - int itiw = (x > s_info.div_w) ? s_info.remain_w : TILE_SIZE; - int itih = (y > s_info.div_h) ? s_info.remain_h : TILE_SIZE; - int in_tile_index = itix + itiw * (itiy + itiz * itih); - return read(data[sparse_index + in_tile_index]); + return read(data[tile_start + (x & TILE_INDEX_MASK) + + ((x > s_info.div_w) ? s_info.remain_w : TILE_SIZE) + * ((y & TILE_INDEX_MASK) + (z & TILE_INDEX_MASK) + * ((y > s_info.div_h) ? s_info.remain_h : TILE_SIZE))]); } static ccl_always_inline float4 read_data(const T *data, diff --git a/intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h b/intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h index c1c302de598..097c984d63f 100644 --- a/intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h +++ b/intern/cycles/kernel/kernels/cuda/kernel_cuda_image.h @@ -67,22 +67,21 @@ ccl_device bool sparse_coordinates(const SparseTextureInfo *s_info, float , f modff(fy, ); modff(fz, ); int x = int(ix), y = int(iy), z = int(iz); - int tix = x / TILE_SIZE, sx = (x % TILE_SIZE) + SPARSE_PAD, - tiy = y / TILE_SIZE, sy = (y % TILE_SIZE) + SPARSE_PAD, - tiz = z / TILE_SIZE, sz = (z % TILE_SIZE) + SPARSE_PAD; - int tile = tix + s_info->tiled_w * (tiy + tiz * s_info->tiled_h); + int tile = (x >> TILE_INDEX_SHIFT) + s_info->tiled_w + * ((y >&g
[Bf-blender-cvs] [aa20e7b88f0] soc-2018-cycles-volumes: Merge remote-tracking branch 'origin/blender2.8' into soc-2018-cycles-volumes
Commit: aa20e7b88f02544458467868423f48e878034e52 Author: Geraldine Chua Date: Fri Aug 10 13:27:40 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rBaa20e7b88f02544458467868423f48e878034e52 Merge remote-tracking branch 'origin/blender2.8' into soc-2018-cycles-volumes === === diff --cc intern/cycles/blender/addon/properties.py index 1b911747899,7f0cb7e875f..54b02a62682 --- a/intern/cycles/blender/addon/properties.py +++ b/intern/cycles/blender/addon/properties.py @@@ -1070,75 -1073,68 +1073,74 @@@ class CyclesObjectSettings(bpy.types.Pr @classmethod def register(cls): bpy.types.Object.cycles = PointerProperty( - name="Cycles Object Settings", - description="Cycles object settings", - type=cls, - ) + name="Cycles Object Settings", + description="Cycles object settings", + type=cls, + ) cls.use_motion_blur = BoolProperty( - name="Use Motion Blur", - description="Use motion blur for this object", - default=True, - ) + name="Use Motion Blur", + description="Use motion blur for this object", + default=True, + ) cls.use_deform_motion = BoolProperty( - name="Use Deformation Motion", - description="Use deformation motion blur for this object", - default=True, - ) + name="Use Deformation Motion", + description="Use deformation motion blur for this object", + default=True, + ) +cls.use_volume_motion = BoolProperty( - name="Use Volume Motion", - description="Use volume motion blur for this object", - default=False, - ) ++name="Use Volume Motion", ++description="Use volume motion blur for this object", ++default=False, ++) + cls.motion_steps = IntProperty( - name="Motion Steps", - description="Control accuracy of motion blur, more steps gives more memory usage (actual number of steps is 2^(steps - 1))", - min=1, soft_max=8, - default=1, - ) + name="Motion Steps", + description="Control accuracy of motion blur, more steps gives more memory usage (actual number of steps is 2^(steps - 1))", + min=1, soft_max=8, + default=1, + ) cls.use_camera_cull = BoolProperty( - name="Use Camera Cull", - description="Allow this object and its duplicators to be culled by camera space culling", - default=False, - ) + name="Use Camera Cull", + description="Allow this object and its duplicators to be culled by camera space culling", + default=False, + ) cls.use_distance_cull = BoolProperty( - name="Use Distance Cull", - description="Allow this object and its duplicators to be culled by distance from camera", - default=False, - ) + name="Use Distance Cull", + description="Allow this object and its duplicators to be culled by distance from camera", + default=False, + ) cls.use_adaptive_subdivision = BoolProperty( - name="Use Adaptive Subdivision", - description="Use adaptive render time subdivision", - default=False, - ) + name="Use Adaptive Subdivision", + description="Use adaptive render time subdivision", + default=False, + ) cls.dicing_rate = FloatProperty( - name="Dicing Scale", - description="Multiplier for scene dicing rate (located in the Geometry Panel)", - min=0.1, max=1000.0, soft_min=0.5, - default=1.0, - ) + name="Dicing Scale", + description="Multiplier for scene dicing rate (located in the Geometry Panel)", + min=0.1, max=1000.0, soft_min=0.5, + default=1.0, + ) cls.is_shadow_catcher = BoolProperty( - name="Shadow Catcher", -
[Bf-blender-cvs] [c8baf8cb39a] soc-2018-cycles-volumes: Updates to OpenVDB import and volume motion blur.
Commit: c8baf8cb39a427e94c4a8c88be2ee2ddd41bc88d Author: Geraldine Chua Date: Wed Aug 8 11:27:11 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rBc8baf8cb39a427e94c4a8c88be2ee2ddd41bc88d Updates to OpenVDB import and volume motion blur. * Separated option for Volume Motion Blur in object UI. Unlike deformation motion, it is disabled by default. * Added multiple frame import and preview simplying for imported VDBs. * Fixed a couple of bugs with VDBs in the viewport. === M intern/cycles/blender/addon/properties.py M intern/cycles/blender/addon/ui.py M intern/cycles/blender/blender_mesh.cpp M intern/cycles/blender/blender_object.cpp M intern/cycles/blender/blender_util.h M intern/cycles/render/mesh.cpp M intern/cycles/render/mesh.h M intern/openvdb/intern/openvdb_dense_convert.h M intern/openvdb/openvdb_capi.cc M intern/openvdb/openvdb_capi.h M release/scripts/startup/bl_ui/properties_physics_smoke.py M source/blender/blenkernel/BKE_pointcache.h M source/blender/blenkernel/intern/pointcache.c M source/blender/editors/io/io_openvdb.c M source/blender/makesdna/DNA_smoke_types.h M source/blender/makesrna/intern/rna_smoke.c === diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py index 1141973efd3..1b911747899 100644 --- a/intern/cycles/blender/addon/properties.py +++ b/intern/cycles/blender/addon/properties.py @@ -1083,10 +1083,16 @@ class CyclesObjectSettings(bpy.types.PropertyGroup): cls.use_deform_motion = BoolProperty( name="Use Deformation Motion", -description="Use deformation motion blur for this object. If object is a volume, use volume motion blur", +description="Use deformation motion blur for this object", default=True, ) +cls.use_volume_motion = BoolProperty( +name="Use Volume Motion", +description="Use volume motion blur for this object", +default=False, +) + cls.motion_steps = IntProperty( name="Motion Steps", description="Control accuracy of motion blur, more steps gives more memory usage (actual number of steps is 2^(steps - 1))", diff --git a/intern/cycles/blender/addon/ui.py b/intern/cycles/blender/addon/ui.py index 707f8756f6f..101f8f45b51 100644 --- a/intern/cycles/blender/addon/ui.py +++ b/intern/cycles/blender/addon/ui.py @@ -845,6 +845,10 @@ class CYCLES_OBJECT_PT_motion_blur(CyclesButtonsPanel, Panel): row.prop(cob, "use_deform_motion", text="Deformation") row.prop(cob, "motion_steps", text="Steps") +row = layout.row() +if ob.type != 'CAMERA': +row.prop(cob, "use_volume_motion", text="Volume") + class CYCLES_OBJECT_PT_cycles_settings(CyclesButtonsPanel, Panel): bl_label = "Cycles Settings" diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index 7486eba2d48..0281ef0a249 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -31,10 +31,6 @@ #include "util/util_logging.h" #include "util/util_math.h" -#ifdef WITH_OPENVDB -#include "render/openvdb.h" -#endif - #include "mikktspace.h" CCL_NAMESPACE_BEGIN @@ -376,23 +372,15 @@ static void create_mesh_volume_attributes(Scene *scene, return; string filename; - void *builtin_data; - - if(b_domain.use_volume_file()) { - BL::ID b_id = b_ob.data(); - filename = blender_absolute_path(b_data, b_id, -b_domain.volume_filepath()); + void *builtin_data = NULL; - if(string_endswith(filename, ".vdb") && - !scene->params.intialized_openvdb) - { - openvdb_initialize(); - scene->params.intialized_openvdb = true; + if(volume_get_frame_file(b_data, b_ob, b_domain, (int)frame, filename)) { + if(string_endswith(filename, ".vdb")) { + init_openvdb_in_scene(scene->params.intialized_openvdb); } - - builtin_data = NULL; } else { + filename = string(); builtin_data = b_ob.ptr.data; } @@ -408,7 +396,7 @@ static void create_mesh_volume_attributes(Scene *scene, create_mesh_volume_attribute(mesh, scene->image_manager, ATTR_STD_VOLUM
[Bf-blender-cvs] [0552d61a121] soc-2018-cycles-volumes: Several minor fixes and variable name changes.
Commit: 0552d61a1216de5455a024b6ba6a2c618293a16c Author: Geraldine Chua Date: Thu Aug 2 23:55:50 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB0552d61a1216de5455a024b6ba6a2c618293a16c Several minor fixes and variable name changes. Notable changes: * P_v moved to correct location in ShaderData struct and shader init. * Volume motion blur now also checks if the Deformation Blur box in the Object panel is checked. * Changed OpenVDB variable names to refer to generic volumes. === M intern/cycles/blender/addon/properties.py M intern/cycles/blender/blender_mesh.cpp M intern/cycles/kernel/geom/geom_volume.h M intern/cycles/kernel/kernel_shader.h M intern/cycles/kernel/kernel_types.h M intern/cycles/render/image.cpp M intern/cycles/render/image.h M intern/cycles/render/mesh.cpp M release/scripts/startup/bl_ui/properties_physics_smoke.py M source/blender/blenkernel/intern/pointcache.c M source/blender/editors/io/io_openvdb.c M source/blender/editors/space_file/filelist.c M source/blender/editors/space_file/filesel.c M source/blender/makesdna/DNA_smoke_types.h M source/blender/makesdna/DNA_space_types.h M source/blender/makesrna/intern/rna_smoke.c M source/blender/windowmanager/intern/wm_operator_props.c === diff --git a/intern/cycles/blender/addon/properties.py b/intern/cycles/blender/addon/properties.py index 8dbd80f3747..1141973efd3 100644 --- a/intern/cycles/blender/addon/properties.py +++ b/intern/cycles/blender/addon/properties.py @@ -1083,7 +1083,7 @@ class CyclesObjectSettings(bpy.types.PropertyGroup): cls.use_deform_motion = BoolProperty( name="Use Deformation Motion", -description="Use deformation motion blur for this object", +description="Use deformation motion blur for this object. If object is a volume, use volume motion blur", default=True, ) diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index 77a82ae4a19..7486eba2d48 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -378,15 +378,18 @@ static void create_mesh_volume_attributes(Scene *scene, string filename; void *builtin_data; - if(b_domain.is_openvdb()) { - if(!scene->params.intialized_openvdb) { + if(b_domain.use_volume_file()) { + BL::ID b_id = b_ob.data(); + filename = blender_absolute_path(b_data, b_id, +b_domain.volume_filepath()); + + if(string_endswith(filename, ".vdb") && + !scene->params.intialized_openvdb) + { openvdb_initialize(); scene->params.intialized_openvdb = true; } - BL::ID b_id = b_ob.data(); - filename = blender_absolute_path(b_data, b_id, -b_domain.openvdb_filepath()); builtin_data = NULL; } else { diff --git a/intern/cycles/kernel/geom/geom_volume.h b/intern/cycles/kernel/geom/geom_volume.h index 51a7efc1457..dd093a881cc 100644 --- a/intern/cycles/kernel/geom/geom_volume.h +++ b/intern/cycles/kernel/geom/geom_volume.h @@ -55,6 +55,7 @@ ccl_device_inline float3 volume_get_position(KernelGlobals *kg, { float3 P = volume_normalized_position(kg, sd, sd->P); +#ifdef __OBJECT_MOTION__ /* Eulerian motion blur. */ if(kernel_data.cam.shuttertime != -1.0f) { AttributeDescriptor v_desc = find_attribute(kg, sd, ATTR_STD_VOLUME_VELOCITY); @@ -73,6 +74,7 @@ ccl_device_inline float3 volume_get_position(KernelGlobals *kg, P = volume_normalized_position(kg, sd, sd->P + velocity * sd->time); } } +#endif return P; } diff --git a/intern/cycles/kernel/kernel_shader.h b/intern/cycles/kernel/kernel_shader.h index 64b1e070982..4c4598accce 100644 --- a/intern/cycles/kernel/kernel_shader.h +++ b/intern/cycles/kernel/kernel_shader.h @@ -1211,10 +1211,10 @@ ccl_device_inline void shader_eval_volume(KernelGlobals *kg, /* todo: this is inefficient for motion blur, we should be * caching matrices instead of recomputing them each step */ shader_setup_object_transforms(kg, sd, sd->time); +#endif /* Cache volume P. */ sd->P_v = volume_get_position(kg, sd); -#endif } /* evaluate shader */ diff --git a/intern/cycles/kernel/kernel_types
[Bf-blender-cvs] [ac21e600ee8] soc-2018-cycles-volumes: Remove Cycles dependency on intern/openvdb.
Commit: ac21e600ee877333840813c8314b7248ea4e2d33 Author: Geraldine Chua Date: Thu Aug 2 23:39:28 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rBac21e600ee877333840813c8314b7248ea4e2d33 Remove Cycles dependency on intern/openvdb. For this, several functions from intern now have simplified copies in Cycles, since the dependency is otherwise difficult to maintain. === M intern/cycles/CMakeLists.txt M intern/cycles/blender/blender_mesh.cpp M intern/cycles/render/openvdb.cpp M intern/cycles/render/openvdb.h M intern/cycles/render/scene.h === diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt index 13538caf54c..8d9f7300563 100644 --- a/intern/cycles/CMakeLists.txt +++ b/intern/cycles/CMakeLists.txt @@ -279,7 +279,6 @@ if(WITH_OPENVDB) include_directories( SYSTEM ${OPENVDB_INCLUDE_DIRS} - ../openvdb ) endif() diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index e78aab9dc54..77a82ae4a19 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -31,6 +31,10 @@ #include "util/util_logging.h" #include "util/util_math.h" +#ifdef WITH_OPENVDB +#include "render/openvdb.h" +#endif + #include "mikktspace.h" CCL_NAMESPACE_BEGIN @@ -375,9 +379,13 @@ static void create_mesh_volume_attributes(Scene *scene, void *builtin_data; if(b_domain.is_openvdb()) { + if(!scene->params.intialized_openvdb) { + openvdb_initialize(); + scene->params.intialized_openvdb = true; + } + BL::ID b_id = b_ob.data(); - filename = blender_absolute_path(b_data, -b_id, + filename = blender_absolute_path(b_data, b_id, b_domain.openvdb_filepath()); builtin_data = NULL; } diff --git a/intern/cycles/render/openvdb.cpp b/intern/cycles/render/openvdb.cpp index 1f58f3783c7..0beb64ba6fa 100644 --- a/intern/cycles/render/openvdb.cpp +++ b/intern/cycles/render/openvdb.cpp @@ -2,12 +2,9 @@ #include #include +#include "render/attribute.h" #include "render/openvdb.h" -#include "intern/openvdb_reader.h" -#include "intern/openvdb_dense_convert.h" -#include "openvdb_capi.h" - #include "util/util_logging.h" #include "util/util_path.h" #include "util/util_sparse_grid.h" @@ -18,22 +15,86 @@ struct OpenVDBReader; CCL_NAMESPACE_BEGIN +namespace { + /* Misc internal helper functions. */ -static bool operator >=(const openvdb::math::Vec3s , const float ) +bool operator >=(const openvdb::math::Vec3s , const float ) { return a.x() >= b || a.y() >= b || a.z() >= b; } -static const int tile_index(openvdb::math::Coord start, const int tiled_res[3]) +void copy(float *des, const float *src) +{ + *des = *src; +} + +void copy(float *des, const openvdb::math::Vec3s *src) { - return compute_index(start.x() / TILE_SIZE, start.y() / TILE_SIZE, -start.z() / TILE_SIZE, tiled_res[0], tiled_res[1]); + *(des + 0) = src->x(); + *(des + 1) = src->y(); + *(des + 2) = src->z(); + *(des + 3) = 1.0f; +} + +const int get_tile_index(const openvdb::math::Coord , + const openvdb::math::Coord _res) +{ + return compute_index(start.x() / TILE_SIZE, +start.y() / TILE_SIZE, +start.z() / TILE_SIZE, +tiled_res.x(), +tiled_res.y()); +} + +const int coord_product(const openvdb::math::Coord ) +{ + return c.x() * c.y() * c.z(); +} + +const openvdb::math::Coord get_tile_dim(const openvdb::math::Coord _min_bound, +const openvdb::math::Coord _res, +const openvdb::math::Coord ) +{ + openvdb::math::Coord tile_dim; + for(int i = 0; i < 3; ++i) { + tile_dim[i] = (tile_min_bound[i] + TILE_SIZE > image_res[i]) ? remainder[i] : TILE_SIZE; + } + return tile_dim; +} + +void expand_bbox(openvdb::io::File *vdb_file, + openvdb::math::CoordBBox *bbox, + AttributeStandard std) +{ + const char *grid_name = Attribute::standard_name(std); + if(vdb_file->hasGrid(grid_name)) { + bbox->expand(vdb_file->readGrid(grid_name)->evalActiveVoxelBoundingBox()); + } +} + +void get_bounds(openvdb::io::Fil
[Bf-blender-cvs] [44d541a6476] soc-2018-cycles-volumes: Initial fix for CUDA, OpenCL sparse grid sampling.
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
[Bf-blender-cvs] [368c4f08666] soc-2018-cycles-volumes: Cycles support for importing common grid types.
Commit: 368c4f08666ce39aae14756a10da143663130626 Author: Geraldine Chua Date: Thu Aug 2 23:44:24 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB368c4f08666ce39aae14756a10da143663130626 Cycles support for importing common grid types. Most common grid types that can easily convert to float are now supported. These will immediately be stored as float arrays. It is also easy to add new types of grids in the future if needed. === M intern/cycles/render/image.cpp M intern/cycles/render/openvdb.cpp M intern/cycles/render/openvdb.h === diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp index f383c66b241..6bba328145e 100644 --- a/intern/cycles/render/image.cpp +++ b/intern/cycles/render/image.cpp @@ -687,8 +687,8 @@ void ImageManager::file_load_extern_vdb(Device *device, int sparse_size = -1; vector sparse_index; - openvdb_load_preprocess(img->filename, img->grid_name, components, - img->isovalue, _index, sparse_size); + openvdb_load_preprocess(img->filename, img->grid_name, img->isovalue, + _index, sparse_size); /* Allocate space for image. */ float *pixels; @@ -709,7 +709,7 @@ void ImageManager::file_load_extern_vdb(Device *device, } /* Load image. */ - openvdb_load_image(img->filename, img->grid_name, components, pixels, _index); + openvdb_load_image(img->filename, img->grid_name, pixels, _index); /* Allocate space for sparse_index if it exists. */ if(sparse_size > -1) { diff --git a/intern/cycles/render/openvdb.cpp b/intern/cycles/render/openvdb.cpp index 0beb64ba6fa..855bed59956 100644 --- a/intern/cycles/render/openvdb.cpp +++ b/intern/cycles/render/openvdb.cpp @@ -19,21 +19,40 @@ namespace { /* Misc internal helper functions. */ -bool operator >=(const openvdb::math::Vec3s , const float ) +template bool gte_any(const T , const float ) { return float(a) > b; } +template <> bool gte_any(const openvdb::math::Vec3d , const float ) { - return a.x() >= b || a.y() >= b || a.z() >= b; + return float(a.x()) >= b || float(a.y()) >= b || float(a.z()) >= b; } - -void copy(float *des, const float *src) +template <> bool gte_any(const openvdb::math::Vec3i , const float ) +{ + return float(a.x()) >= b || float(a.y()) >= b || float(a.z()) >= b; +} +template <> bool gte_any(const openvdb::math::Vec3s , const float ) { - *des = *src; + return float(a.x()) >= b || float(a.y()) >= b || float(a.z()) >= b; } -void copy(float *des, const openvdb::math::Vec3s *src) +template void copy(float *des, const T *src) { *des = float(*src); } +template <> void copy(float *des, const openvdb::math::Vec3d *src) +{ + *(des + 0) = float(src->x()); + *(des + 1) = float(src->y()); + *(des + 2) = float(src->z()); + *(des + 3) = 1.0f; +} +template <> void copy(float *des, const openvdb::math::Vec3i *src) { - *(des + 0) = src->x(); - *(des + 1) = src->y(); - *(des + 2) = src->z(); + *(des + 0) = float(src->x()); + *(des + 1) = float(src->y()); + *(des + 2) = float(src->z()); + *(des + 3) = 1.0f; +} +template <> void copy(float *des, const openvdb::math::Vec3s *src) +{ + *(des + 0) = float(src->x()); + *(des + 1) = float(src->y()); + *(des + 2) = float(src->z()); *(des + 3) = 1.0f; } @@ -92,32 +111,6 @@ void get_bounds(openvdb::io::File *vdb_file, min_bound = bbox.getStart(); } -/* Simple range shift for grids with non-zero background values. May have - * strange results depending on the grid. */ -void shift_range(openvdb::Vec3SGrid::Ptr grid) -{ - using namespace openvdb; - const math::Vec3s background_value = grid->background(); - if(background_value != math::Vec3s(0.0f, 0.0f, 0.0f)) { - for (Vec3SGrid::ValueOnIter iter = grid->beginValueOn(); iter; ++iter) { - iter.setValue(iter.getValue() - background_value); - } - tools::changeBackground(grid->tree(), math::Vec3s(0.0f, 0.0f, 0.0f)); - } -} - -void shift_range(openvdb::FloatGrid::Ptr grid) -{ - using namespace openvdb; - const float background_value = grid->background(); - if(background_value != 0.0f) { - for (FloatGrid::ValueOnIter iter = grid->beginValueOn(); iter; ++iter) { - iter.setValue(iter.getValue() - background_value); - } - tools::changeBackground(grid->tree(), 0.0f); - } -} - /* File and Grid IO */ void cleanup_fi
[Bf-blender-cvs] [0a9c1e51f56] soc-2018-cycles-volumes: Create SparseTextureInfo.
Commit: 0a9c1e51f56dfdf75c7f88972ff609ea0a5b71ca Author: Geraldine Chua Date: Thu Aug 2 23:32:32 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB0a9c1e51f56dfdf75c7f88972ff609ea0a5b71ca Create SparseTextureInfo. Will be used for better organization of info used to convert dense to sparse coordinates in volumes. Also added back tricubic interpolation of sparse grids. === M intern/cycles/device/device_cpu.cpp M intern/cycles/kernel/kernels/cpu/kernel_cpu_image.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 f2c643f5202..47ef95cb59f 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -417,27 +417,25 @@ public: info.cl_buffer = 0; info.interpolation = mem.interpolation; info.extension = mem.extension; - info.grid_type = mem.grid_type; info.width = mem.real_width; info.height = mem.real_height; info.depth = mem.real_depth; - switch(mem.grid_type) { - case IMAGE_GRID_TYPE_SPARSE: - info.util = (uint64_t)sparse_mem->host_pointer; - info.tiled_width = get_tile_res(info.width); - info.tiled_height = get_tile_res(info.height); - info.even_width = info.width - (info.width % TILE_SIZE); - info.even_height = info.height - (info.height % TILE_SIZE); - info.last_tile_dim = 0; - info.last_tile_dim |= ((info.width % TILE_SIZE) << LAST_TILE_WIDTH_MASK); - info.last_tile_dim |= ((info.height % TILE_SIZE) << LAST_TILE_HEIGHT_MASK); - break; - case IMAGE_GRID_TYPE_OPENVDB: - case IMAGE_GRID_TYPE_DEFAULT: - default: - info.util = 0; + 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.sparse_info = sparse_info; + need_texture_info = true; } diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h index 08f79278cf1..02ca18f97bb 100644 --- a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h +++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h @@ -74,40 +74,38 @@ struct TextureInterpolator { return read(data[y * width + x]); } - /* Default grid voxel access. */ - static ccl_always_inline float4 read_data(const T *data, - const void */*util*/, - int x, int y, int z, - int width, int height, - int /*tiw*/, int /*tih*/, - int /*evw*/, int /*evh*/, - int /*ltw*/, int /*lth*/) - { - return read(data[x + width * (y + z * height)]); - } - /* Sparse grid voxel access. */ static ccl_always_inline float4 read_data(const T *data, - const int *sparse_indexes, - int x, int y, int z, - int /*width*/, int /*height*/, - int tiw, int tih, - int evw, int evh, -
[Bf-blender-cvs] [fdf4c4f80cd] soc-2018-cycles-volumes: Fixed incorrect preview of imported OpenVDB files.
Commit: fdf4c4f80cd6822849c2cbbff6b042ec6becbea9 Author: Geraldine Chua Date: Thu Aug 2 23:15:49 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rBfdf4c4f80cd6822849c2cbbff6b042ec6becbea9 Fixed incorrect preview of imported OpenVDB files. Error was caused by not taking into account minumum bound of the volume. Also changed dense array to VDB grid converter in Cycles to use the exporter in intern/openvdb. === M intern/cycles/render/openvdb.cpp M intern/cycles/render/openvdb.h M intern/openvdb/intern/openvdb_dense_convert.cc M intern/openvdb/intern/openvdb_dense_convert.h M intern/openvdb/openvdb_capi.cc === diff --git a/intern/cycles/render/openvdb.cpp b/intern/cycles/render/openvdb.cpp index d863ae42233..cda4b1563e9 100644 --- a/intern/cycles/render/openvdb.cpp +++ b/intern/cycles/render/openvdb.cpp @@ -393,34 +393,58 @@ void openvdb_load_image(const string& filepath, static device_memory *openvdb_load_device_intern_vec(Device *device, const float *data, const int3 resolution, + const string& grid_name, + const float clipping, const string& mem_name, const InterpolationType& interpolation, const ExtensionType& extension) { using namespace openvdb; - Vec3SGrid::Ptr grid = Vec3SGrid::create(); - Vec3SGrid::Accessor accessor = grid->getAccessor(); + /* Split data into 3 separate arrays. */ + size_t data_size = resolution.x * resolution.y * resolution.z; - tools::changeBackground(grid->tree(), math::Vec3s(0.0f, 0.0f, 0.0f)); + float *data_x = new float[data_size]; + float *data_y = new float[data_size]; + float *data_z = new float[data_size]; - openvdb::math::Coord xyz; - int = xyz[0], = xyz[1], = xyz[2]; + for(int i = 0; i < data_size; ++i) { + data_x[i] = data[i * 4 + 0]; + data_y[i] = data[i * 4 + 1]; + data_z[i] = data[i * 4 + 2]; + } - for (z = 0; z < resolution.z; ++z) { - for (y = 0; y < resolution.y; ++y) { - for (x = 0; x < resolution.x; ++x) { - int index = (x + resolution.x * (y + z * resolution.y)) * 4; - openvdb::math::Vec3s val(data[index + 0], data[index + 1], data[index + 2]); - accessor.setValue(xyz, val); - } - } + GridBase::Ptr base_grid = internal::OpenVDB_export_vector_grid( + NULL, grid_name.c_str(), data_x, data_y, + data_z, (int*), NULL, + openvdb::VEC_INVARIANT, (grid_name == "color"), + clipping, NULL); + + delete data_x; + delete data_y; + delete data_z; + + Vec3SGrid::Ptr grid = gridPtrCast(base_grid); + + /* Check memory savings. */ + const int dense_mem_use = resolution.x * resolution.y * resolution.z * 4 * sizeof(float); + + if(grid->memUsage() < dense_mem_use) { + VLOG(1) << "Memory of " << grid_name << " decreased from " + << string_human_readable_size(dense_mem_use) << " to " + << string_human_readable_size(grid->memUsage()); + } + else { + VLOG(1) << "Memory of " << grid_name << " increased from " + << string_human_readable_size(dense_mem_use) << " to " + << string_human_readable_size(grid->memUsage()) + << ", not using VDB grid"; + return NULL; } - Vec3SGrid::ConstAccessor c_accessor = grid->getConstAccessor(); device_openvdb *tex_img = new device_openvdb(device, mem_name.c_str(), MEM_TEXTURE, - grid, c_accessor, resolution); + grid, grid->getConstAccessor(), resolution); tex_img->interpolation = interpolation; tex_img->extension = extension; @@ -433,33 +457,36 @@ static device_memory *openvdb_load_device_intern_vec(Device *device
[Bf-blender-cvs] [6a7af7273de] soc-2018-cycles-volumes: Remove most VDB grid as texture storage functions.
Commit: 6a7af7273de37ce7e3b72dd5cb33b2fabc8ad6e9 Author: Geraldine Chua Date: Thu Aug 2 23:27:28 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB6a7af7273de37ce7e3b72dd5cb33b2fabc8ad6e9 Remove most VDB grid as texture storage functions. === M intern/cycles/device/CMakeLists.txt M intern/cycles/device/device_cpu.cpp D intern/cycles/device/device_memory_openvdb.h M intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h M intern/cycles/render/image.cpp M intern/cycles/render/mesh_volume.cpp M intern/cycles/render/openvdb.cpp M intern/cycles/render/openvdb.h === diff --git a/intern/cycles/device/CMakeLists.txt b/intern/cycles/device/CMakeLists.txt index 8e3494a814c..75e78e038ea 100644 --- a/intern/cycles/device/CMakeLists.txt +++ b/intern/cycles/device/CMakeLists.txt @@ -60,10 +60,6 @@ set(SRC_HEADERS device_task.h ) -if(WITH_OPENVDB) - list(APPEND SRC_HEADERS device_memory_openvdb.h) -endif() - add_definitions(${GL_DEFINITIONS}) if(WITH_CYCLES_NETWORK) add_definitions(-DWITH_NETWORK) diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp index 0b8e95c03c9..f2c643f5202 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -423,9 +423,6 @@ public: info.depth = mem.real_depth; switch(mem.grid_type) { - case IMAGE_GRID_TYPE_OPENVDB: - info.util = (uint64_t)mem.grid_info; - break; case IMAGE_GRID_TYPE_SPARSE: info.util = (uint64_t)sparse_mem->host_pointer; info.tiled_width = get_tile_res(info.width); @@ -436,6 +433,7 @@ public: info.last_tile_dim |= ((info.width % TILE_SIZE) << LAST_TILE_WIDTH_MASK); info.last_tile_dim |= ((info.height % TILE_SIZE) << LAST_TILE_HEIGHT_MASK); break; + case IMAGE_GRID_TYPE_OPENVDB: case IMAGE_GRID_TYPE_DEFAULT: default: info.util = 0; diff --git a/intern/cycles/device/device_memory_openvdb.h b/intern/cycles/device/device_memory_openvdb.h deleted file mode 100644 index ee655318b61..000 --- a/intern/cycles/device/device_memory_openvdb.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef __DEVICE_MEMORY_OPENVDB_H__ -#define __DEVICE_MEMORY_OPENVDB_H__ - -/* OpenVDB Memory - * - * - */ -#include -#include "device/device_memory.h" - -CCL_NAMESPACE_BEGIN - -template<> struct device_type_traits { - static const DataType data_type = TYPE_FLOAT; - static const int num_elements = 4; -}; - -template<> struct device_type_traits { - static const DataType data_type = TYPE_FLOAT; - static const int num_elements = 1; -}; - -template -class device_openvdb : public device_memory -{ -public: - device_openvdb(Device *device, - const char *name, - MemoryType type, - typename GridType::Ptr grid, - typename GridType::ConstAccessor accessor, - int3 resolution) - : device_memory(device, name, type), - vdb_grid(grid), - vdb_acc(accessor) - { - using namespace openvdb; - - data_type = device_type_traits::data_type; - data_elements = device_type_traits::num_elements; - - assert(data_elements > 0); - - host_pointer = static_cast(_grid); - grid_info = static_cast(_acc); - - data_width = real_width = resolution.x; - data_height = real_height = resolution.y; - data_depth = real_depth = resolution.z; - - assert((vdb_grid->memUsage() % (data_elements * datatype_size(data_type))) == 0); - - data_size = vdb_grid->memUsage() / (data_elements * datatype_size(data_type)); - } - - typename GridType::Ptr vdb_grid; - typename GridType::ConstAccessor vdb_acc; - - void copy_to_device() - { - device_copy_to(); - } - -protected: - size_t size(size_t width, size_t height, size_t depth) - { - return width * ((height == 0)? 1: height) * ((depth == 0)? 1: depth); - } -}; - -CCL_NAMESPACE_END - -#endif /* __DEVICE_MEMORY_OPENVDB_H__ */ diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h index 0b05dac544b.
[Bf-blender-cvs] [9eaa1a732ce] soc-2018-cycles-volumes: Move VDB functions from Cycles to intern/openvdb.
Commit: 9eaa1a732cea21b5789b5026871faf39fb8de451 Author: Geraldine Chua Date: Thu Aug 2 23:06:52 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB9eaa1a732cea21b5789b5026871faf39fb8de451 Move VDB functions from Cycles to intern/openvdb. So they can be used on Blender side. Changed variable names and types to be more consistent between Cycles and intern/openvdb. === M intern/cycles/render/openvdb.cpp M intern/cycles/util/util_sparse_grid.h M intern/openvdb/intern/openvdb_dense_convert.cc M intern/openvdb/intern/openvdb_dense_convert.h M intern/openvdb/openvdb_capi.cc M intern/openvdb/openvdb_capi.h M source/blender/blenkernel/intern/pointcache.c === diff --git a/intern/cycles/render/openvdb.cpp b/intern/cycles/render/openvdb.cpp index 68f2cfa4af0..d863ae42233 100644 --- a/intern/cycles/render/openvdb.cpp +++ b/intern/cycles/render/openvdb.cpp @@ -1,9 +1,12 @@ #include #include + +#include "render/openvdb.h" + #include "intern/openvdb_reader.h" +#include "intern/openvdb_dense_convert.h" #include "openvdb_capi.h" -#include "render/openvdb.h" #include "util/util_logging.h" #include "util/util_path.h" @@ -24,23 +27,10 @@ static bool operator >=(const openvdb::math::Vec3s , const float ) return a.x() >= b || a.y() >= b || a.z() >= b; } -static void copy(float *des, const openvdb::math::Vec3s *src) -{ - *(des + 0) = src->x(); - *(des + 1) = src->y(); - *(des + 2) = src->z(); - *(des + 3) = 1.0f; -} - -static void copy(float *des, const float *src) -{ - *des = *src; -} - -static const int tile_index(openvdb::math::Coord start, int3 tiled_res) +static const int tile_index(openvdb::math::Coord start, const int tiled_res[3]) { return compute_index(start.x() / TILE_SIZE, start.y() / TILE_SIZE, -start.z() / TILE_SIZE, tiled_res.x, tiled_res.y); +start.z() / TILE_SIZE, tiled_res[0], tiled_res[1]); } /* Simple range shift for grids with non-zero background values. May have @@ -48,24 +38,19 @@ static const int tile_index(openvdb::math::Coord start, int3 tiled_res) static void shift_range(openvdb::Vec3SGrid::Ptr grid) { using namespace openvdb; - - const math::Vec3s z(0.0f, 0.0f, 0.0f); const math::Vec3s background_value = grid->background(); - - if(background_value != z) { + if(background_value != math::Vec3s(0.0f, 0.0f, 0.0f)) { for (Vec3SGrid::ValueOnIter iter = grid->beginValueOn(); iter; ++iter) { iter.setValue(iter.getValue() - background_value); } - tools::changeBackground(grid->tree(), z); + tools::changeBackground(grid->tree(), math::Vec3s(0.0f, 0.0f, 0.0f)); } } static void shift_range(openvdb::FloatGrid::Ptr grid) { using namespace openvdb; - const float background_value = grid->background(); - if(background_value != 0.0f) { for (FloatGrid::ValueOnIter iter = grid->beginValueOn(); iter; ++iter) { iter.setValue(iter.getValue() - background_value); @@ -78,8 +63,8 @@ template static bool get_grid(const string& filepath, const string& grid_name, typename GridType::Ptr& grid, - int3 *resolution, - openvdb::math::Coord *minimum_bound) + int resolution[3], + int min_bound[3]) { using namespace openvdb; @@ -115,15 +100,8 @@ static bool get_grid(const string& filepath, * voxels below background value. */ shift_range(grid); - int min_bound[3], res[3]; - OpenVDBReader_get_bounds(reader, min_bound, NULL, res, NULL, NULL, NULL); - - if(resolution) { - *resolution = make_int3(res[0], res[1], res[2]); - } - if(minimum_bound) { - *minimum_bound = math::Coord(min_bound[0], min_bound[1], min_bound[2]); - } + /* Retrieve bound data. */ + OpenVDBReader_get_bounds(reader, min_bound, NULL, resolution, NULL, NULL, NULL); OpenVDBReader_free(reader); return true; @@ -159,12 +137,12 @@ int3 openvdb_get_resolution(const string& filepath) return make_int3(res[0], res[1], res[2]); } -/* For now, since there is no official OpenVDB interpolation implementations +/* For now, since there is no official OpenVDB accessor implementations * for CUDA or OpenCL, OpenVDB grids can only be saved for CPU rendering. * Otherwise, we convert the OpenVDB grids to arrays. */ /* Direct load external OpenVDB grid to device. - * Thread must be locked befo
[Bf-blender-cvs] [27c70e50f78] soc-2018-cycles-volumes: Clean up. Change VDB iteration method in Cycles to leaf iterators rather than accessors.
Commit: 27c70e50f783909fc46ac04fdfa955a6f0bbd76d Author: Geraldine Chua Date: Sun Jul 29 00:01:48 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB27c70e50f783909fc46ac04fdfa955a6f0bbd76d Clean up. Change VDB iteration method in Cycles to leaf iterators rather than accessors. === M intern/cycles/device/device_cpu.cpp M intern/cycles/device/device_memory.cpp M intern/cycles/device/device_memory.h M intern/cycles/device/device_memory_openvdb.h M intern/cycles/render/image.cpp M intern/cycles/render/image.h M intern/cycles/render/mesh_volume.cpp M intern/cycles/render/openvdb.cpp M intern/cycles/render/openvdb.h M intern/cycles/util/util_sparse_grid.h === diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp index f29b54ff237..0b8e95c03c9 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -377,9 +377,11 @@ public: void tex_alloc(device_memory& mem) { size_t total_memory = mem.memory_size(); - device_memory *grid_info = mem.grid_info; - if(grid_info) { - total_memory += grid_info->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 << ", " @@ -420,16 +422,12 @@ public: info.height = mem.real_height; info.depth = mem.real_depth; - /* For OpenVDB textures, the kernel will retrieve the accessor from -* util, but there must be some value stored in data or the texture -* will not be used. As a stopgap, the accessor pointer will just -* be stored in both data and util. */ switch(mem.grid_type) { case IMAGE_GRID_TYPE_OPENVDB: - info.util = info.data; + info.util = (uint64_t)mem.grid_info; break; case IMAGE_GRID_TYPE_SPARSE: - info.util = (uint64_t)grid_info->host_pointer; + info.util = (uint64_t)sparse_mem->host_pointer; info.tiled_width = get_tile_res(info.width); info.tiled_height = get_tile_res(info.height); info.even_width = info.width - (info.width % TILE_SIZE); @@ -449,18 +447,19 @@ public: mem.device_size = mem.memory_size(); stats.mem_alloc(mem.device_size); - if(grid_info) { - grid_info->device_pointer = (device_ptr)grid_info->host_pointer; - grid_info->device_size = grid_info->memory_size(); - stats.mem_alloc(grid_info->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) { if(mem.device_pointer) { - if(mem.grid_info) { - tex_free(*mem.grid_info); + if(mem.grid_info && mem.grid_type == IMAGE_GRID_TYPE_SPARSE) { + device_memory *grid_info = (device_memory*)mem.grid_info; + tex_free(*grid_info); } mem.device_pointer = 0; stats.mem_free(mem.device_size); diff --git a/intern/cycles/device/device_memory.cpp b/intern/cycles/device/device_memory.cpp index c6248fcf88b..6e5ded19699 100644 --- a/intern/cycles/device/device_memory.cpp +++ b/intern/cycles/device/device_memory.cpp @@ -36,7 +36,8 @@ device_memory::device_memory(Device *device, const char *name, MemoryType type) device(device), device_pointer(0), host_pointer(0), - shared_pointer(0) + shared_pointer(0), + grid_info(0) { } diff --git a/intern/cycles/device/device_memory.h b/intern/cycles/device/device_memory.h index e21636009ee..5d4fb130ca2 100644 --- a/intern/cycles/device/d
[Bf-blender-cvs] [cba412fba18] soc-2018-cycles-volumes: Intial commit for volume motion blur.
Commit: cba412fba184959ed008a2f54d22dda8d973634b Author: Geraldine Chua Date: Thu Jul 26 21:09:06 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rBcba412fba184959ed008a2f54d22dda8d973634b Intial commit for volume motion blur. === M intern/cycles/blender/blender_mesh.cpp M intern/cycles/kernel/geom/geom_volume.h M intern/cycles/kernel/kernel_shader.h M intern/cycles/kernel/kernel_types.h M intern/cycles/render/mesh.cpp === diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index 8ed0e5232dc..e78aab9dc54 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -397,7 +397,7 @@ static void create_mesh_volume_attributes(Scene *scene, create_mesh_volume_attribute(mesh, scene->image_manager, ATTR_STD_VOLUME_HEAT, filename, builtin_data, frame); if(mesh->need_attribute(scene, ATTR_STD_VOLUME_TEMPERATURE)) create_mesh_volume_attribute(mesh, scene->image_manager, ATTR_STD_VOLUME_TEMPERATURE, filename, builtin_data, frame); - if(mesh->need_attribute(scene, ATTR_STD_VOLUME_VELOCITY)) + if(mesh->need_attribute(scene, ATTR_STD_VOLUME_VELOCITY) || scene->need_motion() == Scene::MOTION_BLUR) create_mesh_volume_attribute(mesh, scene->image_manager, ATTR_STD_VOLUME_VELOCITY, filename, builtin_data, frame); } diff --git a/intern/cycles/kernel/geom/geom_volume.h b/intern/cycles/kernel/geom/geom_volume.h index 346f228e961..51a7efc1457 100644 --- a/intern/cycles/kernel/geom/geom_volume.h +++ b/intern/cycles/kernel/geom/geom_volume.h @@ -47,11 +47,40 @@ ccl_device_inline float3 volume_normalized_position(KernelGlobals *kg, return P; } -ccl_device float volume_attribute_float(KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor desc, float *dx, float *dy) +/* Returns normalized P. + * If motion blur is enabled, returns normalized and advected P. */ + +ccl_device_inline float3 volume_get_position(KernelGlobals *kg, + const ShaderData *sd) { float3 P = volume_normalized_position(kg, sd, sd->P); + + /* Eulerian motion blur. */ + if(kernel_data.cam.shuttertime != -1.0f) { + AttributeDescriptor v_desc = find_attribute(kg, sd, ATTR_STD_VOLUME_VELOCITY); + + if (v_desc.offset != ATTR_STD_NOT_FOUND) { + InterpolationType interp = (sd->flag & SD_VOLUME_CUBIC)? INTERPOLATION_CUBIC: INTERPOLATION_NONE; + + /* Find velocity. */ + float3 velocity = float4_to_float3(kernel_tex_image_interp_3d(kg, v_desc.offset, P.x, P.y, P.z, interp)); + + /* Find advected velocity. */ + P = volume_normalized_position(kg, sd, sd->P + velocity * sd->time); + velocity = float4_to_float3(kernel_tex_image_interp_3d(kg, v_desc.offset, P.x, P.y, P.z, interp)); + + /* Find advected P. */ + P = volume_normalized_position(kg, sd, sd->P + velocity * sd->time); + } + } + + return P; +} + +ccl_device float volume_attribute_float(KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor desc, float *dx, float *dy) +{ InterpolationType interp = (sd->flag & SD_VOLUME_CUBIC)? INTERPOLATION_CUBIC: INTERPOLATION_NONE; - float4 r = kernel_tex_image_interp_3d(kg, desc.offset, P.x, P.y, P.z, interp); + float4 r = kernel_tex_image_interp_3d(kg, desc.offset, sd->P_v.x, sd->P_v.y, sd->P_v.z, interp); if(dx) *dx = 0.0f; if(dy) *dy = 0.0f; @@ -61,9 +90,8 @@ ccl_device float volume_attribute_float(KernelGlobals *kg, const ShaderData *sd, ccl_device float3 volume_attribute_float3(KernelGlobals *kg, const ShaderData *sd, const AttributeDescriptor desc, float3 *dx, float3 *dy) { - float3 P = volume_normalized_position(kg, sd, sd->P); InterpolationType interp = (sd->flag & SD_VOLUME_CUBIC)? INTERPOLATION_CUBIC: INTERPOLATION_NONE; - float4 r = kernel_tex_image_interp_3d(kg, desc.offset, P.x, P.y, P.z, interp); + float4 r = kernel_tex_image_interp_3d(kg, desc.offset, sd->P_v.x, sd->P_v.y, sd->P_v.z, interp); if(dx) *dx = make_float3(0.0f, 0.0f, 0.0f); if(dy) *dy = make_float3(0.0f, 0.0f, 0.0f); diff --git a/intern/cycles/kernel/kernel_shader.h b/intern/cycles/kernel/kernel_shader.h index 937a50cba8b..64b1e070982 100644 --- a/intern/cycles/kernel/kernel_shader.h +++ b/intern/cycles/kernel/kernel_shader.h @@ -1211,6 +1211,9 @@ ccl_device_inline void shader_eval_volume(KernelGlobals *kg, /* todo: this is ineffici
[Bf-blender-cvs] [98a620707f3] soc-2018-cycles-volumes: Cleanup; fix some bugs causing crashes.
Commit: 98a620707f3f57189d96b2b4abdb645c9e179ea5 Author: Geraldine Chua Date: Thu Jul 26 21:03:58 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB98a620707f3f57189d96b2b4abdb645c9e179ea5 Cleanup; fix some bugs causing crashes. === M intern/cycles/blender/blender_mesh.cpp M intern/cycles/render/image.cpp M intern/cycles/render/image.h M intern/cycles/render/openvdb.cpp M intern/cycles/render/openvdb.h M intern/cycles/util/util_image_impl.h M intern/cycles/util/util_sparse_grid.h M intern/openvdb/openvdb_capi.cc === diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index d8261d7d86d..8ed0e5232dc 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -324,29 +324,55 @@ static void mikk_compute_tangents(const BL::Mesh& b_mesh, /* Create Volume Attribute */ -static void create_mesh_volume_attribute(BL::BlendData& b_data, - BL::Object& b_ob, - Mesh *mesh, +static void create_mesh_volume_attribute(Mesh *mesh, ImageManager *image_manager, AttributeStandard std, + string filename, + void *builtin_data, float frame) { - BL::SmokeDomainSettings b_domain = object_smoke_domain_find(b_ob); - - if(!b_domain) - return; + ImageMetaData metadata; - mesh->volume_isovalue = b_domain.clipping(); + if(filename.empty()) { + /* Built-in smoke. */ + filename = Attribute::standard_name(std); + } + else { + /* External VDB. */ + metadata.grid_name = Attribute::standard_name(std); + } Attribute *attr = mesh->attributes.add(std); VoxelAttribute *volume_data = attr->data_voxel(); - bool animated = false; - bool use_alpha = true; - bool make_sparse = true; + + volume_data->manager = image_manager; + volume_data->slot = image_manager->add_image( + filename, + builtin_data, + false, + frame, + INTERPOLATION_LINEAR, + EXTENSION_CLIP, + true, + true, + mesh->volume_isovalue, + metadata); +} + +static void create_mesh_volume_attributes(Scene *scene, + BL::BlendData& b_data, + BL::Object& b_ob, + Mesh *mesh, + float frame) +{ + /* for smoke volume rendering */ + BL::SmokeDomainSettings b_domain = object_smoke_domain_find(b_ob); + + if(!b_domain) + return; string filename; void *builtin_data; - ImageMetaData metadata; if(b_domain.is_openvdb()) { BL::ID b_id = b_ob.data(); @@ -354,46 +380,25 @@ static void create_mesh_volume_attribute(BL::BlendData& b_data, b_id, b_domain.openvdb_filepath()); builtin_data = NULL; - metadata.grid_name = Attribute::standard_name(std); } else { - filename = Attribute::standard_name(std); builtin_data = b_ob.ptr.data; } - volume_data->manager = image_manager; - volume_data->slot = image_manager->add_image( - filename, - builtin_data, - animated, - frame, - INTERPOLATION_LINEAR, - EXTENSION_CLIP, - use_alpha, - make_sparse, - mesh->volume_isovalue, - metadata); -} + mesh->volume_isovalue = b_domain.clipping(); -static void create_mesh_volume_attributes(Scene *scene, - BL::BlendData& b_data, - BL::Object& b_ob, - Mesh *mesh, - float frame) -{ - /* for smoke volume rendering */ if(mesh->need_attribute(scene, ATTR_STD_VOLUME_DENSITY)) - create_mesh_volume_attribute(b_data, b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_DENSITY, frame); + create_mesh_volume_attribute(mesh, scene->image_manag
[Bf-blender-cvs] [c987ad81b68] soc-2018-cycles-volumes: Cleanup and bug fixes.
Commit: c987ad81b684f4f0b361ff11325786d268c603c1 Author: Geraldine Chua Date: Mon Jul 16 20:57:55 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rBc987ad81b684f4f0b361ff11325786d268c603c1 Cleanup and bug fixes. === M intern/cycles/blender/blender_mesh.cpp M intern/cycles/blender/blender_session.cpp M intern/cycles/blender/blender_shader.cpp M intern/cycles/device/device_cpu.cpp M intern/cycles/device/device_memory_openvdb.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/render/mesh_volume.cpp M intern/cycles/render/nodes.cpp M intern/cycles/render/openvdb.cpp M intern/cycles/render/openvdb.h M intern/cycles/util/util_sparse_grid.h M intern/cycles/util/util_texture.h M intern/openvdb/openvdb_capi.cc M intern/openvdb/openvdb_capi.h M source/blender/blenkernel/intern/pointcache.c === diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index f70e859ba8a..d8261d7d86d 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -324,7 +324,8 @@ static void mikk_compute_tangents(const BL::Mesh& b_mesh, /* Create Volume Attribute */ -static void create_mesh_volume_attribute(BL::Object& b_ob, +static void create_mesh_volume_attribute(BL::BlendData& b_data, + BL::Object& b_ob, Mesh *mesh, ImageManager *image_manager, AttributeStandard std, @@ -339,15 +340,31 @@ static void create_mesh_volume_attribute(BL::Object& b_ob, Attribute *attr = mesh->attributes.add(std); VoxelAttribute *volume_data = attr->data_voxel(); - ImageMetaData metadata; bool animated = false; bool use_alpha = true; bool make_sparse = true; + string filename; + void *builtin_data; + ImageMetaData metadata; + + if(b_domain.is_openvdb()) { + BL::ID b_id = b_ob.data(); + filename = blender_absolute_path(b_data, +b_id, +b_domain.openvdb_filepath()); + builtin_data = NULL; + metadata.grid_name = Attribute::standard_name(std); + } + else { + filename = Attribute::standard_name(std); + builtin_data = b_ob.ptr.data; + } + volume_data->manager = image_manager; volume_data->slot = image_manager->add_image( - Attribute::standard_name(std), - b_ob.ptr.data, + filename, + builtin_data, animated, frame, INTERPOLATION_LINEAR, @@ -359,23 +376,24 @@ static void create_mesh_volume_attribute(BL::Object& b_ob, } static void create_mesh_volume_attributes(Scene *scene, + BL::BlendData& b_data, BL::Object& b_ob, Mesh *mesh, float frame) { /* for smoke volume rendering */ if(mesh->need_attribute(scene, ATTR_STD_VOLUME_DENSITY)) - create_mesh_volume_attribute(b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_DENSITY, frame); + create_mesh_volume_attribute(b_data, b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_DENSITY, frame); if(mesh->need_attribute(scene, ATTR_STD_VOLUME_COLOR)) - create_mesh_volume_attribute(b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_COLOR, frame); + create_mesh_volume_attribute(b_data, b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_COLOR, frame); if(mesh->need_attribute(scene, ATTR_STD_VOLUME_FLAME)) - create_mesh_volume_attribute(b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_FLAME, frame); + create_mesh_volume_attribute(b_data, b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_FLAME, frame); if(mesh->need_attribute(scene, ATTR_STD_VOLUME_HEAT)) - create_mesh_volume_attribute(b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_HEAT, frame); + create_mesh_volume_attribute(b_data, b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_HEAT, frame); if(mesh->need_attribute(scene, ATTR_STD_VOLUME_TEMPERATURE)) - create_mesh_volume_attribute(b_ob, mesh, scene->image_manager, ATTR_STD_VOLUME_TEMPERATURE, frame
[Bf-blender-cvs] [028f648753c] soc-2018-cycles-volumes: Revert "Morton ordering for sparse grids."
Commit: 028f648753c893639f5c1732360e4cf6eb551e71 Author: Geraldine Chua Date: Tue Jul 10 15:42:52 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB028f648753c893639f5c1732360e4cf6eb551e71 Revert "Morton ordering for sparse grids." This reverts commit a93a9fb09bcfd6211f063255ccb11cfc15e013d1. === M intern/cycles/device/device_cpu.cpp M intern/cycles/kernel/kernels/cpu/kernel_cpu_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 36904951df6..04578eec954 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -421,9 +421,8 @@ public: info.grid_info = 0; if(grid_info) { info.grid_info = (uint64_t)grid_info->host_pointer; - info.bit_count = compute_bit_count(info.width, - info.height, - info.depth); + info.tiled_width = get_tile_res(info.width); + info.tiled_height = get_tile_res(info.height); info.last_tile_width = info.width % TILE_SIZE; info.last_tile_height = info.height % TILE_SIZE; } diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h index 64367b7fb84..a0d6b54245b 100644 --- a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h +++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h @@ -82,12 +82,12 @@ template struct TextureInterpolator { static ccl_always_inline float4 read(const T *data, const int *grid_info, int x, int y, int z, -int bit_count, int ltw, int lth) +int tiw, int tih, int ltw, int lth) { int tix = x / TILE_SIZE, itix = x % TILE_SIZE, tiy = y / TILE_SIZE, itiy = y % TILE_SIZE, tiz = z / TILE_SIZE, itiz = z % TILE_SIZE; - int dense_index = compute_morton(tix, tiy, tiz, bit_count) * 2; + int dense_index = flatten(tix, tiy, tiz, tiw, tih) * 2; int sparse_index = grid_info[dense_index]; int dims = grid_info[dense_index + 1]; if(sparse_index < 0) { @@ -101,12 +101,12 @@ template struct TextureInterpolator { static ccl_always_inline float4 read(const T *data, const int *grid_info, int index, int width, int height, int /*depth*/, -int bit_count, int ltw, int lth) +int tiw, int tih, int ltw, int lth) { int x = index % width; int y = (index / width) % height; int z = index / (width * height); - return read(data, grid_info, x, y, z, bit_count, ltw, lth); + return read(data, grid_info, x, y, z, tiw, tih, ltw, lth); } static ccl_always_inline int wrap_periodic(int x, int width) @@ -319,7 +319,8 @@ template struct TextureInterpolator { const int *grid_info = (const int*)info.grid_info; if(grid_info) { - return read(data, grid_info, ix, iy, iz, info.bit_count, + return read(data, grid_info, ix, iy, iz, + info.tiled_width, info.tiled_height, info.last_tile_width, info.last_tile_height); } return read(data[flatten(ix, iy, iz, width, height)]); @@ -374,17 +375,18 @@ template struct TextureInterpolator { const int *gi = (const int*)info.grid_info; if(gi) { - int bc = info.bit_count; + int tiw = info.tiled_width; + int tih = info.tiled_height; int ltw = info.last_tile_width; int lth = info.last_tile_height; - r = (1.0f - tz)*(1.0f - ty)*(1.0f - tx) * read(data, gi, ix, iy, iz, bc, ltw, lth); - r += (1.0f - tz)*(1.0f - ty)*tx * read(data, gi, nix, iy, iz, bc, ltw, lth); - r += (1.0f - tz)*ty*(1.0f - tx) * read(data, gi, ix, niy, iz, bc, ltw, lth); - r += (1.0f - tz)*ty*tx
[Bf-blender-cvs] [281db895f33] soc-2018-cycles-volumes: Simple OpenVDB import GUI.
Commit: 281db895f33a3481d1a5b7689cb2e5c914613261 Author: Geraldine Chua Date: Tue Jul 10 15:56:23 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB281db895f33a3481d1a5b7689cb2e5c914613261 Simple OpenVDB import GUI. === M release/scripts/startup/bl_ui/space_info.py M source/blender/blenkernel/BKE_pointcache.h M source/blender/blenkernel/intern/pointcache.c M source/blender/editors/io/CMakeLists.txt A source/blender/editors/io/io_openvdb.c A source/blender/editors/io/io_openvdb.h M source/blender/editors/io/io_ops.c M source/blender/editors/space_file/filelist.c M source/blender/editors/space_file/filesel.c M source/blender/makesdna/DNA_space_types.h M source/blender/windowmanager/intern/wm_operator_props.c === diff --git a/release/scripts/startup/bl_ui/space_info.py b/release/scripts/startup/bl_ui/space_info.py index 180e48af386..64477d56e55 100644 --- a/release/scripts/startup/bl_ui/space_info.py +++ b/release/scripts/startup/bl_ui/space_info.py @@ -173,6 +173,8 @@ class INFO_MT_file_import(Menu): self.layout.operator("wm.collada_import", text="Collada (Default) (.dae)") if bpy.app.build_options.alembic: self.layout.operator("wm.alembic_import", text="Alembic (.abc)") +if bpy.app.build_options.openvdb: +self.layout.operator("wm.openvdb_import", text="OpenVDB (.vdb)") class INFO_MT_file_export(Menu): diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h index cc60df1b2d6..8873b70f992 100644 --- a/source/blender/blenkernel/BKE_pointcache.h +++ b/source/blender/blenkernel/BKE_pointcache.h @@ -125,6 +125,7 @@ typedef struct PTCacheFile { enum { PTCACHE_FILE_PTCACHE = 0, PTCACHE_FILE_OPENVDB = 1, + PTCACHE_FILE_OPENVDB_EXTERN = 2, }; typedef struct PTCacheID { diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c index 3d1cdba1cdd..a8b63e131a2 100644 --- a/source/blender/blenkernel/intern/pointcache.c +++ b/source/blender/blenkernel/intern/pointcache.c @@ -1156,6 +1156,96 @@ static int ptcache_smoke_openvdb_read(struct OpenVDBReader *reader, void *smoke_ return 1; } + +static int ptcache_smoke_openvdb_extern_read(struct OpenVDBReader *reader, void *smoke_v) +{ + SmokeModifierData *smd = (SmokeModifierData *)smoke_v; + + if (!smd) { + return 0; + } + + SmokeDomainSettings *sds = smd->domain; + + int fluid_fields = smoke_get_data_flags(sds); + int cache_fields = 0; + bool reallocate = false; + int res[3], res_min[3], res_max[3]; + + if (!OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_DENSITY) && + !OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_FLAME)) + { + return 0; + } + + if (!OpenVDBReader_get_detailed_bounds(reader, res_min, res_max, res, + sds->p0, sds->p1, sds->cell_size)) + { + modifier_setError((ModifierData *)smd, "Imported OpenVDB grids have different transformations"); + } + + sds->res_min[0] = sds->res_min[1] = sds->res_min[2] = 0; + VECSUB(sds->res_max, res_max, res_min); + sub_v3_v3v3(sds->global_size, sds->p1, sds->p0); + + if (sds->res[0] != res[0] || sds->res[1] != res[1] || sds->res[2] != res[2]) + { + reallocate = true; + VECCOPY(sds->res, res); + } + + /* check if active fields have changed */ + if (OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_HEAT) || + OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_TEMPERATURE)) { + cache_fields |= SM_ACTIVE_HEAT; + } + if (OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_FLAME)) { + cache_fields |= SM_ACTIVE_FIRE; + } + if (OpenVDBReader_has_smoke_grid(reader, VDB_SMOKE_COLOR)) { + cache_fields |= SM_ACTIVE_COLORS; + } + + reallocate = (reallocate || ((fluid_fields == cache_fields) && (sds->active_fields == cache_fields))); + + /* reallocate fluid if needed */ + if (reallocate) { + sds->active_fields = cache_fields; + sds->maxres = MAX3(sds->base_res[0], sds->base_res[1], sds->base_res[2]); + sds->dx = 1.0f / sds->maxres; + smoke_reallocate_fluid(sds, sds->dx, sds->res, 1); + sds->total_cells = sds->res[0] * sds->res[1] * sds->res[2]; + } + + if (sds->fluid) { +
[Bf-blender-cvs] [7fc47f83fc9] soc-2018-cycles-volumes: Initial commit for Cycles OpenVDB import.
Commit: 7fc47f83fc90edfb5404f468124afee605f81fe0 Author: Geraldine Chua Date: Tue Jul 10 15:49:51 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB7fc47f83fc90edfb5404f468124afee605f81fe0 Initial commit for Cycles OpenVDB import. === M intern/cycles/CMakeLists.txt M intern/cycles/blender/blender_session.cpp M intern/cycles/device/CMakeLists.txt M intern/cycles/device/device_cpu.cpp M intern/cycles/device/device_memory.h A intern/cycles/device/device_memory_openvdb.h M intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h M intern/cycles/render/CMakeLists.txt M intern/cycles/render/image.cpp M intern/cycles/render/image.h M intern/cycles/render/mesh_volume.cpp A intern/cycles/render/mesh_volume.h A intern/cycles/render/openvdb.cpp A intern/cycles/render/openvdb.h M intern/cycles/util/util_texture.h M intern/openvdb/intern/openvdb_reader.cc M intern/openvdb/intern/openvdb_reader.h M intern/openvdb/openvdb_capi.cc M intern/openvdb/openvdb_capi.h M release/scripts/startup/bl_ui/properties_physics_smoke.py M source/blender/makesdna/DNA_smoke_types.h M source/blender/makesrna/intern/rna_smoke.c === diff --git a/intern/cycles/CMakeLists.txt b/intern/cycles/CMakeLists.txt index 100a52625d1..13538caf54c 100644 --- a/intern/cycles/CMakeLists.txt +++ b/intern/cycles/CMakeLists.txt @@ -261,6 +261,28 @@ if(WITH_CYCLES_LOGGING) ) endif() +if(WITH_OPENVDB) + add_definitions(-DWITH_OPENVDB) + + if(WITH_OPENVDB_3_ABI_COMPATIBLE) + add_definitions( + -DOPENVDB_3_ABI_COMPATIBLE + ) + endif() + + if(WITH_OPENVDB_BLOSC) + add_definitions( + -DWITH_OPENVDB_BLOSC + ) + endif() + + include_directories( + SYSTEM + ${OPENVDB_INCLUDE_DIRS} + ../openvdb + ) +endif() + # Debugging capabilities (debug passes etc). if(WITH_CYCLES_DEBUG) add_definitions(-DWITH_CYCLES_DEBUG) diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index 00d23b9095e..481057e308c 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -1082,6 +1082,11 @@ void BlenderSession::builtin_image_info(const string _name, metadata.width = resolution.x * amplify; metadata.height = resolution.y * amplify; metadata.depth = resolution.z * amplify; + + if(b_domain.is_openvdb()) { + metadata.openvdb_filepath = blender_absolute_path(b_data, b_id, + b_domain.openvdb_filepath()); + } } else { /* TODO(sergey): Check we're indeed in shader node tree. */ diff --git a/intern/cycles/device/CMakeLists.txt b/intern/cycles/device/CMakeLists.txt index 75e78e038ea..8e3494a814c 100644 --- a/intern/cycles/device/CMakeLists.txt +++ b/intern/cycles/device/CMakeLists.txt @@ -60,6 +60,10 @@ set(SRC_HEADERS device_task.h ) +if(WITH_OPENVDB) + list(APPEND SRC_HEADERS device_memory_openvdb.h) +endif() + add_definitions(${GL_DEFINITIONS}) if(WITH_CYCLES_NETWORK) add_definitions(-DWITH_NETWORK) diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp index 04578eec954..f38225f867a 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -415,16 +415,28 @@ public: info.cl_buffer = 0; info.interpolation = mem.interpolation; info.extension = mem.extension; + info.grid_type = mem.grid_type; info.width = mem.real_width; info.height = mem.real_height; info.depth = mem.real_depth; - info.grid_info = 0; - if(grid_info) { - info.grid_info = (uint64_t)grid_info->host_pointer; - info.tiled_width = get_tile_res(info.width); - info.tiled_height = get_tile_res(info.height); - info.last_tile_width = info.width % TILE_SIZE; - info.last_tile_height = info.height % TILE_SIZE; + + /* For OpenVDB textures, the kernel will retrieve the accessor from +* util, but there must be some value stored in data or the texture +* will not be used. As a stopgap, the accessor pointer will j
[Bf-blender-cvs] [a93a9fb09bc] soc-2018-cycles-volumes: Morton ordering for sparse grids.
Commit: a93a9fb09bcfd6211f063255ccb11cfc15e013d1 Author: Geraldine Chua Date: Sat Jun 16 19:49:18 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rBa93a9fb09bcfd6211f063255ccb11cfc15e013d1 Morton ordering for sparse grids. === M intern/cycles/device/device_cpu.cpp M intern/cycles/kernel/kernels/cpu/kernel_cpu_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 04578eec954..36904951df6 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -421,8 +421,9 @@ public: info.grid_info = 0; if(grid_info) { info.grid_info = (uint64_t)grid_info->host_pointer; - info.tiled_width = get_tile_res(info.width); - info.tiled_height = get_tile_res(info.height); + info.bit_count = compute_bit_count(info.width, + info.height, + info.depth); info.last_tile_width = info.width % TILE_SIZE; info.last_tile_height = info.height % TILE_SIZE; } diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h index a0d6b54245b..64367b7fb84 100644 --- a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h +++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h @@ -82,12 +82,12 @@ template struct TextureInterpolator { static ccl_always_inline float4 read(const T *data, const int *grid_info, int x, int y, int z, -int tiw, int tih, int ltw, int lth) +int bit_count, int ltw, int lth) { int tix = x / TILE_SIZE, itix = x % TILE_SIZE, tiy = y / TILE_SIZE, itiy = y % TILE_SIZE, tiz = z / TILE_SIZE, itiz = z % TILE_SIZE; - int dense_index = flatten(tix, tiy, tiz, tiw, tih) * 2; + int dense_index = compute_morton(tix, tiy, tiz, bit_count) * 2; int sparse_index = grid_info[dense_index]; int dims = grid_info[dense_index + 1]; if(sparse_index < 0) { @@ -101,12 +101,12 @@ template struct TextureInterpolator { static ccl_always_inline float4 read(const T *data, const int *grid_info, int index, int width, int height, int /*depth*/, -int tiw, int tih, int ltw, int lth) +int bit_count, int ltw, int lth) { int x = index % width; int y = (index / width) % height; int z = index / (width * height); - return read(data, grid_info, x, y, z, tiw, tih, ltw, lth); + return read(data, grid_info, x, y, z, bit_count, ltw, lth); } static ccl_always_inline int wrap_periodic(int x, int width) @@ -319,8 +319,7 @@ template struct TextureInterpolator { const int *grid_info = (const int*)info.grid_info; if(grid_info) { - return read(data, grid_info, ix, iy, iz, - info.tiled_width, info.tiled_height, + return read(data, grid_info, ix, iy, iz, info.bit_count, info.last_tile_width, info.last_tile_height); } return read(data[flatten(ix, iy, iz, width, height)]); @@ -375,18 +374,17 @@ template struct TextureInterpolator { const int *gi = (const int*)info.grid_info; if(gi) { - int tiw = info.tiled_width; - int tih = info.tiled_height; + int bc = info.bit_count; int ltw = info.last_tile_width; int lth = info.last_tile_height; - r = (1.0f - tz)*(1.0f - ty)*(1.0f - tx) * read(data, gi, ix, iy, iz, tiw, tih, ltw, lth); - r += (1.0f - tz)*(1.0f - ty)*tx * read(data, gi, nix, iy, iz, tiw, tih, ltw, lth); - r += (1.0f - tz)*ty*(1.0f - tx) * read(data, gi, ix, niy, iz, tiw, tih, ltw, lth); - r += (1.0f - tz)*ty*tx * read(data, gi, nix, niy, iz, tiw, tih, lt
[Bf-blender-cvs] [4e94a6f576d] soc-2018-cycles-volumes: Minor sparse tile fixes.
Commit: 4e94a6f576de76d670b5ed3dd69500fd8c539e67 Author: Geraldine Chua Date: Mon Jun 11 22:57:59 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB4e94a6f576de76d670b5ed3dd69500fd8c539e67 Minor sparse tile fixes. Fixed some really obvious errors with CUDA sampling, and moved the coordinates to index calculation back into kernel, saving a small perecentage of time. === M intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h 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/mesh_volume.cpp M intern/cycles/util/util_sparse_grid.h === diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h index c43b94db7e0..a0d6b54245b 100644 --- a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h +++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h @@ -30,6 +30,11 @@ template struct TextureInterpolator { u[3] = (1.0f / 6.0f) * t * t * t; \ } (void)0 + static ccl_always_inline int flatten(int x, int y, int z, int width, int height) + { + return x + width * (y + z * height); + } + static ccl_always_inline float4 read(float4 r) { return r; @@ -82,7 +87,7 @@ template struct TextureInterpolator { int tix = x / TILE_SIZE, itix = x % TILE_SIZE, tiy = y / TILE_SIZE, itiy = y % TILE_SIZE, tiz = z / TILE_SIZE, itiz = z % TILE_SIZE; - int dense_index = compute_index_fast(tix, tiy, tiz, tiw, tih) * 2; + int dense_index = flatten(tix, tiy, tiz, tiw, tih) * 2; int sparse_index = grid_info[dense_index]; int dims = grid_info[dense_index + 1]; if(sparse_index < 0) { @@ -90,7 +95,7 @@ template struct TextureInterpolator { } int itiw = dims & (1 << ST_SHIFT_TRUNCATE_WIDTH) ? ltw : TILE_SIZE; int itih = dims & (1 << ST_SHIFT_TRUNCATE_HEIGHT) ? lth : TILE_SIZE; - int in_tile_index = compute_index_fast(itix, itiy, itiz, itiw, itih); + int in_tile_index = flatten(itix, itiy, itiz, itiw, itih); return read(data[sparse_index + in_tile_index]); } @@ -318,7 +323,7 @@ template struct TextureInterpolator { info.tiled_width, info.tiled_height, info.last_tile_width, info.last_tile_height); } - return read(data[compute_index_fast(ix, iy, iz, width, height)]); + return read(data[flatten(ix, iy, iz, width, height)]); } static ccl_always_inline float4 interp_3d_linear(const TextureInfo& info, @@ -384,14 +389,14 @@ template struct TextureInterpolator { r += tz*ty*tx* read(data, gi, nix, niy, niz, tiw, tih, ltw, lth); } else { - r = (1.0f - tz)*(1.0f - ty)*(1.0f - tx) * read(data[compute_index_fast(ix, iy, iz, width, height)]); - r += (1.0f - tz)*(1.0f - ty)*tx * read(data[compute_index_fast(nix, iy, iz, width, height)]); - r += (1.0f - tz)*ty*(1.0f - tx) * read(data[compute_index_fast(ix, niy, iz, width, height)]); - r += (1.0f - tz)*ty*tx * read(data[compute_index_fast(nix, niy, iz, width, height)]); - r += tz*(1.0f - ty)*(1.0f - tx) * read(data[compute_index_fast(ix, iy, niz, width, height)]); - r += tz*(1.0f - ty)*tx * read(data[compute_index_fast(nix, iy, niz, width, height)]); - r += tz*ty*(1.0f - tx) * read(data[compute_index_fast(ix, niy, niz, width, height)]); - r += tz*ty*tx * read(data[compute_index_fast(nix, niy, niz, width, height)]); + r = (1.0f - tz)*(1.0f - ty)*(1.0f - tx) * read(data[flatten(ix, iy, iz, width, height)]); + r += (1.0f - tz)*(1.0f - ty)*tx * read(data[flatten(nix, iy, iz, width, height)]); + r += (1.0f - tz)*ty*(1.0f - tx) * read(data[flatten(ix, niy, iz, width, height)]); + r += (1.0f - tz)*ty*tx * read(data[flatten(nix, niy, iz, width, height)]); + r += tz*(1.0f - ty)*(1.0f - tx)
[Bf-blender-cvs] [22f243d379f] soc-2018-cycles-volumes: Reduce sparse grid memory usage and minor fixes.
Commit: 22f243d379ffd1bd7101dd1955b2efe0062ed651 Author: Geraldine Chua Date: Fri Jun 8 18:11:03 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB22f243d379ffd1bd7101dd1955b2efe0062ed651 Reduce sparse grid memory usage and minor fixes. Sparse grids originally padded out an image to dimensions divisible by TILE_SIZE, which resulted in many empty voxels in large volumes. Now, border tiles are taken into account when calculating voxel indexes. Aside from that, made some other minor fixes throughout the files. === 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/render/mesh_volume.cpp M intern/cycles/util/util_sparse_grid.h === diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp index a21884de6d6..4e1fa05e168 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -378,8 +378,9 @@ public: { size_t total_memory = mem.memory_size(); device_memory *offsets = mem.offsets; - if(offsets != NULL) + if(offsets) { total_memory += offsets->memory_size(); + } VLOG(1) << "Texture allocate: " << mem.name << ", " << string_human_readable_number(total_memory) << " bytes. (" @@ -414,21 +415,10 @@ public: info.cl_buffer = 0; info.interpolation = mem.interpolation; info.extension = mem.extension; - 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; - } + info.width = mem.real_width; + info.height = mem.real_height; + info.depth = mem.real_depth; + info.offsets = (uint64_t)(offsets ? offsets->host_pointer : 0); need_texture_info = true; } @@ -436,7 +426,7 @@ public: mem.device_size = mem.memory_size(); stats.mem_alloc(mem.device_size); - if(offsets != NULL) { + if(offsets) { offsets->device_pointer = (device_ptr)offsets->host_pointer; offsets->device_size = offsets->memory_size(); stats.mem_alloc(offsets->device_size); @@ -447,6 +437,9 @@ public: void tex_free(device_memory& mem) { if(mem.device_pointer) { + if(mem.offsets) { + tex_free(*mem.offsets); + } mem.device_pointer = 0; stats.mem_free(mem.device_size); mem.device_size = 0; diff --git a/intern/cycles/device/device_memory.h b/intern/cycles/device/device_memory.h index dd7f72ce102..a230d3928ca 100644 --- a/intern/cycles/device/device_memory.h +++ b/intern/cycles/device/device_memory.h @@ -187,6 +187,12 @@ 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; MemoryType type; const char *name; InterpolationType interpolation; @@ -318,9 +324,9 @@ public: } data_size = new_size; - data_width = width; - data_height = height; - data_depth = depth; + data_width = real_width = width; + data_height = rea
[Bf-blender-cvs] [e0ea53ae77c] soc-2018-cycles-volumes: Updates to volume kernel tiling function.
Commit: e0ea53ae77c193ef08bb0b9215c5b3ffd84e7c11 Author: Geraldine Chua Date: Sun Jun 10 23:15:29 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rBe0ea53ae77c193ef08bb0b9215c5b3ffd84e7c11 Updates to volume kernel tiling function. 1. OpenCL and CUDA support (mostly untested). 2. Change name of offsets to grid_info since it needs to keep track of other info as well. 3. Several speed and memory optimizations. === 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/cpu/kernel_cpu_image.h 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/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 4e1fa05e168..04578eec954 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -377,9 +377,9 @@ public: void tex_alloc(device_memory& mem) { size_t total_memory = mem.memory_size(); - device_memory *offsets = mem.offsets; - if(offsets) { - total_memory += offsets->memory_size(); + device_memory *grid_info = mem.grid_info; + if(grid_info) { + total_memory += grid_info->memory_size(); } VLOG(1) << "Texture allocate: " << mem.name << ", " @@ -418,7 +418,14 @@ public: info.width = mem.real_width; info.height = mem.real_height; info.depth = mem.real_depth; - info.offsets = (uint64_t)(offsets ? offsets->host_pointer : 0); + info.grid_info = 0; + if(grid_info) { + info.grid_info = (uint64_t)grid_info->host_pointer; + info.tiled_width = get_tile_res(info.width); + info.tiled_height = get_tile_res(info.height); + info.last_tile_width = info.width % TILE_SIZE; + info.last_tile_height = info.height % TILE_SIZE; + } need_texture_info = true; } @@ -426,10 +433,10 @@ public: mem.device_size = mem.memory_size(); stats.mem_alloc(mem.device_size); - if(offsets) { - offsets->device_pointer = (device_ptr)offsets->host_pointer; - offsets->device_size = offsets->memory_size(); - stats.mem_alloc(offsets->device_size); + if(grid_info) { + grid_info->device_pointer = (device_ptr)grid_info->host_pointer; + grid_info->device_size = grid_info->memory_size(); + stats.mem_alloc(grid_info->device_size); } } @@ -437,8 +444,8 @@ public: void tex_free(device_memory& mem) { if(mem.device_pointer) { - if(mem.offsets) { - tex_free(*mem.offsets); + if(mem.grid_info) { + tex_free(*mem.grid_info); } mem.device_pointer = 0; stats.mem_free(mem.device_size); diff --git a/intern/cycles/device/device_cuda.cpp b/intern/cycles/device/device_cuda.cpp index b4529feffa7..d9f146339d2 100644 --- a/intern/cycles/device/device_cuda.cpp +++ b/intern/cycles/device/device_cuda.cpp @@ -1020,6 +1020,9 @@ 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) { diff --git a/intern/cycles/device/device_memory.h b/intern/cycles/device/device_memory.h index a230d3928ca..0f3843b90e5 100644 --- a/intern/cycles/device/device_memory.h +++ b/intern/cycles/device/device_memory.h @@ -203,7 +203,7 @@ public: device_ptr device_pointer; void *host_pointer; void *shared_pointer; - device_memory *offsets = NULL; + device_memory *grid_info = NULL;
[Bf-blender-cvs] [75bff3c0137] soc-2018-cycles-volumes: Threshold sparse grid with volume mesh isovalue and optimize tile copying during grid generation.
Commit: 75bff3c0137e18a00bc9318549e6c3da8b7ae5ac Author: Geraldine Chua Date: Thu Jun 7 23:14:33 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB75bff3c0137e18a00bc9318549e6c3da8b7ae5ac Threshold sparse grid with volume mesh isovalue and optimize tile copying during grid generation. === M intern/cycles/blender/blender_mesh.cpp M intern/cycles/render/image.cpp M intern/cycles/render/image.h M intern/cycles/render/nodes.cpp M intern/cycles/util/util_sparse_grid.h === diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index 8bf3f66dff6..f70e859ba8a 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -354,6 +354,7 @@ static void create_mesh_volume_attribute(BL::Object& b_ob, EXTENSION_CLIP, use_alpha, make_sparse, + mesh->volume_isovalue, metadata); } diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp index bef1419d178..61394700886 100644 --- a/intern/cycles/render/image.cpp +++ b/intern/cycles/render/image.cpp @@ -262,6 +262,7 @@ int ImageManager::add_image(const string& filename, ExtensionType extension, bool use_alpha, bool make_sparse, +float isovalue, ImageMetaData& metadata) { Image *img; @@ -340,6 +341,7 @@ int ImageManager::add_image(const string& filename, img->users = 1; img->use_alpha = use_alpha; img->make_sparse = make_sparse; + img->isovalue = isovalue; img->mem = NULL; images[type][slot] = img; @@ -743,6 +745,7 @@ bool ImageManager::file_make_image_sparse(Device *device, tex_img->data_width, tex_img->data_height, tex_img->data_depth, +img->isovalue, _grid, ); diff --git a/intern/cycles/render/image.h b/intern/cycles/render/image.h index 7ef9cfb5ba5..7f4810968b2 100644 --- a/intern/cycles/render/image.h +++ b/intern/cycles/render/image.h @@ -57,6 +57,7 @@ public: ExtensionType extension, bool use_alpha, bool make_sparse, + float isovalue, ImageMetaData& metadata); void remove_image(int flat_slot); void remove_image(const string& filename, @@ -117,6 +118,7 @@ public: bool need_load; bool animated; bool make_sparse; + float isovalue; float frame; InterpolationType interpolation; ExtensionType extension; diff --git a/intern/cycles/render/nodes.cpp b/intern/cycles/render/nodes.cpp index 71b1d42b25e..09201421813 100644 --- a/intern/cycles/render/nodes.cpp +++ b/intern/cycles/render/nodes.cpp @@ -308,6 +308,7 @@ void ImageTextureNode::compile(SVMCompiler& compiler) extension, use_alpha, false, + 0.0f, metadata); is_float = metadata.is_float; is_linear = metadata.is_linear; @@ -374,6 +375,7 @@ void ImageTextureNode::compile(OSLCompiler& compiler) extension, use_alpha, false, + 0.0f, metadata); } is_float = metadata.is_float; @@ -505,6 +507,7 @@ void EnvironmentTextureNode::compile(SVMCompiler& compiler) EXTENSION_REPEAT, use_alpha, false, + 0.0f, metadata); is_float = metadata.is_float; is_linear = metadata.is_linear; @@ -562,6 +565,7 @@ void EnvironmentTextureNode::compile(OSLCompiler& compiler)
[Bf-blender-cvs] [998d1b091a9] soc-2018-cycles-volumes: Added sparse grid lookup to mesh volume generator.
Commit: 998d1b091a90454cdc65ed8ea8101f28984298e4 Author: Geraldine Chua Date: Wed Jun 6 23:51:56 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB998d1b091a90454cdc65ed8ea8101f28984298e4 Added sparse grid lookup to mesh volume generator. Also made some minor operator additions/changes. === M intern/cycles/render/mesh_volume.cpp M intern/cycles/util/util_math_float4.h M intern/cycles/util/util_math_int4.h M intern/cycles/util/util_sparse_grid.h === diff --git a/intern/cycles/render/mesh_volume.cpp b/intern/cycles/render/mesh_volume.cpp index d1c49b456ff..8a55b89abcc 100644 --- a/intern/cycles/render/mesh_volume.cpp +++ b/intern/cycles/render/mesh_volume.cpp @@ -21,27 +21,11 @@ #include "util/util_foreach.h" #include "util/util_logging.h" #include "util/util_progress.h" +#include "util/util_sparse_grid.h" #include "util/util_types.h" CCL_NAMESPACE_BEGIN -static size_t compute_voxel_index(const int3 , size_t x, size_t y, size_t z) -{ - if(x == -1 || x >= resolution.x) { - return -1; - } - - if(y == -1 || y >= resolution.y) { - return -1; - } - - if(z == -1 || z >= resolution.z) { - return -1; - } - - return x + y*resolution.x + z*resolution.x*resolution.y; -} - struct QuadData { int v0, v1, v2, v3; @@ -200,7 +184,7 @@ void VolumeMeshBuilder::add_node(int x, int y, int z) assert((index_x >= 0) && (index_y >= 0) && (index_z >= 0)); - const size_t index = compute_voxel_index(res, index_x, index_y, index_z); + const size_t index = compute_index(index_x, index_y, index_z, res); /* We already have a node here. */ if(grid[index] == 1) { @@ -253,7 +237,7 @@ void VolumeMeshBuilder::generate_vertices_and_quads( for(int z = 0; z < res.z; ++z) { for(int y = 0; y < res.y; ++y) { for(int x = 0; x < res.x; ++x) { - size_t voxel_index = compute_voxel_index(res, x, y, z); + size_t voxel_index = compute_index(x, y, z, res); if(grid[voxel_index] == 0) { continue; } @@ -281,32 +265,32 @@ void VolumeMeshBuilder::generate_vertices_and_quads( * an inactive node. */ - voxel_index = compute_voxel_index(res, x - 1, y, z); + voxel_index = compute_index(x - 1, y, z, res); if(voxel_index == -1 || grid[voxel_index] == 0) { create_quad(corners, vertices_is, quads, QUAD_X_MIN); } - voxel_index = compute_voxel_index(res, x + 1, y, z); + voxel_index = compute_index(x + 1, y, z, res); if(voxel_index == -1 || grid[voxel_index] == 0) { create_quad(corners, vertices_is, quads, QUAD_X_MAX); } - voxel_index = compute_voxel_index(res, x, y - 1, z); + voxel_index = compute_index(x, y - 1, z, res); if(voxel_index == -1 || grid[voxel_index] == 0) { create_quad(corners, vertices_is, quads, QUAD_Y_MIN); } - voxel_index = compute_voxel_index(res, x, y + 1, z); + voxel_index = compute_index(x, y + 1, z, res); if(voxel_index == -1 || grid[voxel_index] == 0) { create_quad(corners, vertices_is, quads, QUAD_Y_MAX); } - voxel_index = compute_voxel_index(res, x, y, z - 1); + voxel_index = compute_index(x, y, z - 1, res); if(voxel_index == -1 || grid[voxel_index] == 0) { create_quad(corners, vertices_is, quads, QUAD_Z_MIN); } - voxel_index = compute_voxel_index(res, x, y, z + 1); + voxel_index = compute_index(x, y, z + 1, res); if(voxel_index == -1 || grid[voxel_index] == 0) { create_quad(corners, vertices_is, quads, QUAD_Z_MAX);
[Bf-blender-cvs] [fd64e214cbc] soc-2018-cycles-volumes: Remove SparseTile; support CPU tricubic interp.
Commit: fd64e214cbceefd09c863e6ee0c3aac1db2428b0 Author: Geraldine Chua Date: Thu Jun 7 17:03:24 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rBfd64e214cbceefd09c863e6ee0c3aac1db2428b0 Remove SparseTile; support CPU tricubic interp. Sparse grids now use their normal types instead of a specific struct. Also added support for tricubic interpolation of sparse grids for CPU rendering. === M intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h M intern/cycles/render/image.cpp M intern/cycles/render/mesh_volume.cpp M intern/cycles/util/util_sparse_grid.h === diff --git a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h index 3435bcab70a..93aa6117f58 100644 --- a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h +++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h @@ -75,6 +75,21 @@ template struct TextureInterpolator { return read(data[y * width + x]); } + static ccl_always_inline float4 read(const T *data, const int *offsets, +int x, int y, int z, +int tiw, int tih, int tid) + { + int index = compute_index(offsets, x, y, z, tiw, tih, tid); + return index < 0 ? make_float4(0.0f) : read(data[index]); + } + + static ccl_always_inline float4 read(const T *data, const int *offsets, +int idx, int width, int height, int depth) + { + int index = compute_index(offsets, idx, width, height, depth); + return index < 0 ? make_float4(0.0f) : read(data[index]); + } + static ccl_always_inline int wrap_periodic(int x, int width) { x %= width; @@ -281,18 +296,14 @@ template struct TextureInterpolator { return make_float4(0.0f); } + const T *data = (const T*)info.data; const int *ofs = (const int*)info.offsets; + if(ofs) { - const SparseTile *data = (const SparseTile*)info.data; - return read(get_value(data, ofs, ix, iy, iz, -compute_tile_resolution(width), - compute_tile_resolution(height), - compute_tile_resolution(depth))); - } - else { - const T *data = (const T*)info.data; - return read(data[compute_index(ix, iy, iz, width, height, depth)]); + return read(data, ofs, ix, iy, iz, get_tile_res(width), + get_tile_res(height), get_tile_res(depth)); } + return read(data[compute_index(ix, iy, iz, width, height, depth)]); } static ccl_always_inline float4 interp_3d_linear(const TextureInfo& info, @@ -340,29 +351,26 @@ template struct TextureInterpolator { } float4 r; + const T *data = (const T*)info.data; const int *ofs = (const int*)info.offsets; if(ofs) { - const SparseTile *data = (const SparseTile*)info.data; - int tiw = compute_tile_resolution(width); - int tih = compute_tile_resolution(height); - int tid = compute_tile_resolution(depth); + int tiw = get_tile_res(width), tih = get_tile_res(height), tid = get_tile_res(depth); /* Initial check if either voxel is in an active tile. */ if(!tile_is_active(ofs, ix, iy, iz, tiw, tih, tid) && !tile_is_active(ofs, nix, niy, niz, tiw, tih, tid)) { return make_float4(0.0f); } - r = (1.0f - tz)*(1.0f - ty)*(1.0f - tx) * read(get_value(data, ofs, ix, iy, iz, tiw, tih, tid)); - r += (1.0f - tz)*(1.0f - ty)*tx * read(get_value(data, ofs, nix, iy, iz, tiw, tih, tid)); - r += (1.0f - tz)*ty*(1.0f - tx) * read(get_value(data, ofs, ix, niy, iz, tiw, tih, tid)); - r += (1.0f - tz)*ty*tx * read(get_value(data, ofs, nix, niy, iz, tiw, tih, tid)); - r += tz*(1.0f - ty)*(1.0f - tx) * read(get_value(data, ofs, ix, iy, niz, tiw, tih, tid)); - r += tz*(1.0f - ty)*tx * read(get_value(data, ofs, nix, iy,
[Bf-blender-cvs] [e1db45c41a9] soc-2018-cycles-volumes: Updates to tiling function.
Commit: e1db45c41a9acb9dadbb40183e1037d441a15035 Author: Geraldine Chua Date: Tue Jun 5 21:35:24 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rBe1db45c41a9acb9dadbb40183e1037d441a15035 Updates to tiling function. 1. Supports all data types (or at least the ones enumerated in ImageDataType). 2. Will tile all volume attributes. 3. Changed method of activating tiling to a bool member of Image. === M intern/cycles/blender/blender_mesh.cpp M intern/cycles/blender/blender_session.cpp 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/render/nodes.cpp M intern/cycles/util/CMakeLists.txt M intern/cycles/util/util_image_impl.h D intern/cycles/util/util_sparse_grid.cpp M intern/cycles/util/util_sparse_grid.h M intern/cycles/util/util_texture.h === diff --git a/intern/cycles/blender/blender_mesh.cpp b/intern/cycles/blender/blender_mesh.cpp index 7d6ca18b074..8bf3f66dff6 100644 --- a/intern/cycles/blender/blender_mesh.cpp +++ b/intern/cycles/blender/blender_mesh.cpp @@ -342,6 +342,7 @@ static void create_mesh_volume_attribute(BL::Object& b_ob, ImageMetaData metadata; bool animated = false; bool use_alpha = true; + bool make_sparse = true; volume_data->manager = image_manager; volume_data->slot = image_manager->add_image( @@ -352,6 +353,7 @@ static void create_mesh_volume_attribute(BL::Object& b_ob, INTERPOLATION_LINEAR, EXTENSION_CLIP, use_alpha, + make_sparse, metadata); } diff --git a/intern/cycles/blender/blender_session.cpp b/intern/cycles/blender/blender_session.cpp index 649d6edc679..00d23b9095e 100644 --- a/intern/cycles/blender/blender_session.cpp +++ b/intern/cycles/blender/blender_session.cpp @@ -1051,7 +1051,6 @@ void BlenderSession::builtin_image_info(const string _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; @@ -1061,19 +1060,14 @@ void BlenderSession::builtin_image_info(const string _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; - metadata.is_volume = true; - } - else if(builtin_name == Attribute::standard_name(ATTR_STD_VOLUME_VELOCITY)) { + 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/kernel/kernels/cpu/kernel_cpu_image.h b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h index 3c18b08d5b8..3435bcab70a 100644 --- a/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h +++ b/intern/cycles/kernel/kernels/cpu/kernel_cpu_image.h @@ -21,8 +21,7 @@ CCL_NAMESPACE_BEGIN -template -struct TextureInterpolator { +template 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); \ @@ -282,10 +281,13 @@ struct TextureInterpolator { return make_float4(0.0f); } - 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)); + const int *ofs = (const int*)info.offsets; + if(ofs) { + const SparseTile *data = (const SparseTile*)info.data; + return read(get_value(data
[Bf-blender-cvs] [ae177e799c1] soc-2018-cycles-volumes: Created init functions for uchar4 and half4.
Commit: ae177e799c121f4135d2f32aa0c23cf36992afaf Author: Geraldine Chua Date: Tue Jun 5 21:32:24 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rBae177e799c121f4135d2f32aa0c23cf36992afaf Created init functions for uchar4 and half4. === M intern/cycles/util/util_half.h M intern/cycles/util/util_types_uchar4.h M intern/cycles/util/util_types_uchar4_impl.h === diff --git a/intern/cycles/util/util_half.h b/intern/cycles/util/util_half.h index 612228dd1c1..b21c773a773 100644 --- a/intern/cycles/util/util_half.h +++ b/intern/cycles/util/util_half.h @@ -32,12 +32,12 @@ CCL_NAMESPACE_BEGIN #define float4_store_half(h, f, scale) vstore_half4(f * (scale), 0, h); -#else +#else /* __KERNEL_OPENCL__ */ /* CUDA has its own half data type, no need to define then */ #ifndef __KERNEL_CUDA__ typedef unsigned short half; -#endif +#endif /* __KERNEL_CUDA__ */ struct half4 { half x, y, z, w; }; @@ -51,7 +51,7 @@ ccl_device_inline void float4_store_half(half *h, float4 f, float scale) h[3] = __float2half(f.w * scale); } -#else +#else /* __KERNEL_CUDA__ */ ccl_device_inline void float4_store_half(half *h, float4 f, float scale) { @@ -71,23 +71,23 @@ ccl_device_inline void float4_store_half(half *h, float4 f, float scale) h[i] = (rshift & 0x7FFF); } -#else +#else /*__KERNEL_SSE2__ */ /* same as above with SSE */ ssef fscale = load4f(f) * scale; ssef x = min(max(fscale, 0.0f), 65504.0f); #ifdef __KERNEL_AVX2__ ssei rpack = _mm_cvtps_ph(x, 0); -#else +#else /* __KERNEL_AVX2__ */ ssei absolute = cast(x) & 0x7FFF; ssei Z = absolute + 0xC800; ssei result = andnot(absolute < 0x3880, Z); ssei rshift = (result >> 13) & 0x7FFF; ssei rpack = _mm_packs_epi32(rshift, rshift); -#endif +#endif /* __KERNEL_AVX2__ */ _mm_storel_pi((__m64*)h, _mm_castsi128_ps(rpack)); -#endif +#endif /*__KERNEL_SSE2__ */ } ccl_device_inline float half_to_float(half h) @@ -133,11 +133,22 @@ ccl_device_inline half float_to_half(float f) return (value_bits | sign_bit); } -#endif +ccl_device_inline half4 make_half4(half h) +{ + half4 a = {h, h, h, h}; + return a; +} -#endif +ccl_device_inline half4 make_half4(half x, half y, half z, half w) +{ + half4 a = {x, y, z, w}; + return a; +} + +#endif /* __KERNEL_CUDA__ */ + +#endif /* __KERNEL_OPENCL__ */ CCL_NAMESPACE_END #endif /* __UTIL_HALF_H__ */ - diff --git a/intern/cycles/util/util_types_uchar4.h b/intern/cycles/util/util_types_uchar4.h index 3802cebbfb9..d9d7cc6f35e 100644 --- a/intern/cycles/util/util_types_uchar4.h +++ b/intern/cycles/util/util_types_uchar4.h @@ -31,6 +31,7 @@ struct uchar4 { __forceinline uchar& operator[](int i); }; +ccl_device_inline uchar4 make_uchar4(uchar u); ccl_device_inline uchar4 make_uchar4(uchar x, uchar y, uchar z, uchar w); #endif /* __KERNEL_GPU__ */ diff --git a/intern/cycles/util/util_types_uchar4_impl.h b/intern/cycles/util/util_types_uchar4_impl.h index 03039f60c54..0594ca4fc43 100644 --- a/intern/cycles/util/util_types_uchar4_impl.h +++ b/intern/cycles/util/util_types_uchar4_impl.h @@ -38,6 +38,12 @@ uchar& uchar4::operator[](int i) return *( + i); } +ccl_device_inline uchar4 make_uchar4(uchar u) +{ + uchar4 a = {u, u, u, u}; + return a; +} + ccl_device_inline uchar4 make_uchar4(uchar x, uchar y, uchar z, uchar w) { uchar4 a = {x, y, z, w}; ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [6998ecec2a9] soc-2018-cycles-volumes: Initial working implementation of tiling for sparse grids.
Commit: 6998ecec2a9ca5541eb93803f3233c5e9ab23eb5 Author: Geraldine Chua Date: Thu May 31 21:09:25 2018 +0800 Branches: soc-2018-cycles-volumes https://developer.blender.org/rB6998ecec2a9ca5541eb93803f3233c5e9ab23eb5 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 _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 _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; -
[Bf-blender-cvs] [45830999d9e] soc-2018-volumes: Merge branch 'soc-2018-volumes' of git.blender.org:blender into soc-2018-volumes
Commit: 45830999d9e8b62288edc97d98ba6b6f69c051a3 Author: Geraldine Chua Date: Thu May 31 01:21:21 2018 +0800 Branches: soc-2018-volumes https://developer.blender.org/rB45830999d9e8b62288edc97d98ba6b6f69c051a3 Merge branch 'soc-2018-volumes' of git.blender.org:blender into soc-2018-volumes === === diff --cc intern/cycles/render/image.cpp index 756807d0642,c37d7e02d43..f7e2f6488a1 --- a/intern/cycles/render/image.cpp +++ b/intern/cycles/render/image.cpp @@@ -699,52 -698,45 +699,54 @@@ template& tex_img, - device_vector& tex_helper) + device_vector& tex_img, + device_vector& tex_offsets) { - device_vector *tex_img_raw + device_vector *tex_img_dense = new device_vector(NULL, img->mem_name.c_str(), MEM_TEXTURE); - if(!file_load_image(img, type, texture_limit, *tex_img_raw)) { - return false; + if(!file_load_image(img, + type, + texture_limit, + *tex_img_dense)) + { + /* Release temporary pointer. */ + delete tex_img_dense; + tex_img_dense = NULL; + return false; + } + + DeviceType *data = tex_img_dense->data(); + size_t tile_width = compute_tile_resolution(tex_img_dense->data_width); + size_t tile_height = compute_tile_resolution(tex_img_dense->data_height); + size_t tile_depth = compute_tile_resolution(tex_img_dense->data_depth); + + vector sparse_grid; + vector offsets; - int active_tile_count = create_sparse_grid(data, ++ /* Sample threshold value for now. */ ++ float4 threshold = make_float4(0.0f); ++ int active_tile_count = create_sparse_grid(data, threshold, + tex_img_dense->data_width, + tex_img_dense->data_height, + tex_img_dense->data_depth, + _grid, ); + + if(active_tile_count < 1) { + /* to-do (gchua): handle this. */ } - VLOG(1) << "Memory usage of raw volume texture: " - << string_human_readable_size(tex_img_raw->memory_size()); - - DeviceType *data = tex_img_raw->data(); - size_t tile_width = compute_tile_resolution(tex_img_raw->data_width); - size_t tile_height = compute_tile_resolution(tex_img_raw->data_height); - size_t tile_depth = compute_tile_resolution(tex_img_raw->data_depth); - - vector sparse_grid; - vector indexes; - create_sparse_grid(data, - tex_img_raw->data_width, - tex_img_raw->data_height, - tex_img_raw->data_depth, - sparse_grid, - indexes); - - VolumeTile *texture_pixels; - int *texture_indexes; + SparseTile *texture_pixels; + int *texture_offsets; { /* Since only active tiles are stored in tex_img, its - * allocated memory will be less than the actual resolution + * allocated memory will be <= the actual resolution * of the volume. We store the true resolution (in tiles) in the - * tex_helper instead, since it needs to be allocated enough + * tex_offsets instead, since it needs to be allocated enough * space to track all tiles anyway. */ thread_scoped_lock device_lock(device_mutex); - texture_pixels = (VolumeTile*)tex_img.alloc(sparse_grid.size()); - texture_indexes = (int*)tex_helper.alloc(tile_width, + texture_pixels = (SparseTile*)tex_img.alloc(active_tile_count); + texture_offsets = (int*)tex_offsets.alloc(tile_width, tile_height, tile_depth); } @@@ -959,44 -944,18 +961,44 @@@ void ImageManager::device_load_image(De type,
[Bf-blender-cvs] [56c834dacd6] soc-2018-volumes: Initial working implementation of tiling for sparse grids.
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 _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 _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; -
[Bf-blender-cvs] [d7aab52c4d2] soc-2018-volumes: Merge branch 'master' into soc-2018-volumes
Commit: d7aab52c4d216a69af826289d926cd0b67bf2f4d Author: Geraldine Chua Date: Tue May 29 11:44:03 2018 +0800 Branches: soc-2018-volumes https://developer.blender.org/rBd7aab52c4d216a69af826289d926cd0b67bf2f4d Merge branch 'master' into soc-2018-volumes === === ___ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org https://lists.blender.org/mailman/listinfo/bf-blender-cvs
[Bf-blender-cvs] [5f3b3554772] soc-2018-volumes: sparse volumes initial commit
Commit: 5f3b35547725159bb33e383a81dc93dc92f4ad4f Author: Geraldine Chua Date: Tue May 29 01:33:47 2018 +0800 Branches: soc-2018-volumes https://developer.blender.org/rB5f3b35547725159bb33e383a81dc93dc92f4ad4f sparse volumes initial commit === M intern/cycles/device/device_cpu.cpp M intern/cycles/device/device_memory.h M intern/cycles/device/opencl/opencl.h M intern/cycles/render/image.cpp M intern/cycles/render/image.h M intern/cycles/render/mesh_volume.cpp M intern/cycles/util/CMakeLists.txt M intern/cycles/util/util_texture.h A intern/cycles/util/util_volume.cpp A intern/cycles/util/util_volume.h === diff --git a/intern/cycles/device/device_cpu.cpp b/intern/cycles/device/device_cpu.cpp index 6be60f8bbb6..e9898cba20d 100644 --- a/intern/cycles/device/device_cpu.cpp +++ b/intern/cycles/device/device_cpu.cpp @@ -52,6 +52,8 @@ #include "util/util_progress.h" #include "util/util_system.h" #include "util/util_thread.h" +/* gchua: fix later */ +#include "util/util_volume.h" CCL_NAMESPACE_BEGIN @@ -375,9 +377,14 @@ public: void tex_alloc(device_memory& mem) { + size_t total_memory = mem.memory_size(); + if(mem.helper != NULL) { + total_memory += mem.helper->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. */ @@ -408,16 +415,38 @@ 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(mem.helper != NULL) { + /* If mem is a sparse volume, its real (tile) dimensions +* are stored in the helper texture. */ + info.width = mem.helper->data_width * CUBE_SIZE; + info.height = mem.helper->data_height * CUBE_SIZE; + info.depth = mem.helper->data_depth * CUBE_SIZE; + info.indexes = (uint64_t)mem.helper->host_pointer; + } + else { + info.width = mem.data_width; + info.height = mem.data_height; + info.depth = mem.data_depth; + /* todo (gchua): what if the valid host pointer is 0 */ + info.indexes = (uint64_t)0; + } + VLOG(1) << "Texture width: " << mem.data_width << ", " << info.width; + VLOG(1) << "Texture height: " << mem.data_height << ", " << info.height; + VLOG(1) << "Texture depth: " << mem.data_depth << ", " << info.depth; + VLOG(1) << "Texture helper: " << info.indexes; 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(mem.helper != NULL) { + mem.helper->device_pointer = (device_ptr)mem.helper->host_pointer; + mem.helper->device_size = mem.helper->memory_size(); + stats.mem_alloc(mem.helper->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..cfe95b5b0c5 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 *hel