diff options
author | Geraldine Chua <chua.gsk@gmail.com> | 2018-06-07 12:03:24 +0300 |
---|---|---|
committer | Geraldine Chua <chua.gsk@gmail.com> | 2018-06-07 12:03:24 +0300 |
commit | fd64e214cbceefd09c863e6ee0c3aac1db2428b0 (patch) | |
tree | e961ca4f5712f55929ab06fc2995d68c2618a59b /intern/cycles/render | |
parent | 998d1b091a90454cdc65ed8ea8101f28984298e4 (diff) |
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.
Diffstat (limited to 'intern/cycles/render')
-rw-r--r-- | intern/cycles/render/image.cpp | 76 | ||||
-rw-r--r-- | intern/cycles/render/mesh_volume.cpp | 82 |
2 files changed, 58 insertions, 100 deletions
diff --git a/intern/cycles/render/image.cpp b/intern/cycles/render/image.cpp index c1caea34619..bef1419d178 100644 --- a/intern/cycles/render/image.cpp +++ b/intern/cycles/render/image.cpp @@ -730,52 +730,49 @@ void ImageManager::file_load_failed(device_vector<DeviceType> *tex_img, template<typename DeviceType> bool ImageManager::file_make_image_sparse(Device *device, Image *img, - device_vector<DeviceType> *tex_dense) + device_vector<DeviceType> *tex_img) { - device_vector<SparseTile<DeviceType>> *tex_sparse - = new device_vector<SparseTile<DeviceType>>(device, - (img->mem_name).c_str(), - MEM_TEXTURE); device_vector<int> *tex_offsets = new device_vector<int>(device, (img->mem_name + "_offsets").c_str(), MEM_TEXTURE); - vector<SparseTile<DeviceType>> sparse_grid; + vector<DeviceType> sparse_grid; vector<int> offsets; - int active_tile_count = create_sparse_grid<DeviceType>( - tex_dense->data(), - tex_dense->data_width, - tex_dense->data_height, - tex_dense->data_depth, - &sparse_grid, - &offsets); - - if(active_tile_count < 1) { + int voxel_count = create_sparse_grid<DeviceType>(tex_img->data(), + tex_img->data_width, + tex_img->data_height, + tex_img->data_depth, + &sparse_grid, + &offsets); + + if(voxel_count < 1) { VLOG(1) << "Could not make sparse grid for " << path_filename(img->filename) << " (" << img->mem_name << ")" << ", no active tiles"; - delete tex_sparse; delete tex_offsets; - tex_sparse = NULL; tex_offsets = NULL; return false; } - SparseTile<DeviceType> *texture_pixels; + VLOG(1) << "Original memory usage of '" + << path_filename(img->filename) << "' (" << img->mem_name << "): " + << string_human_readable_size(tex_img->memory_size()); + + DeviceType *texture_pixels; int *texture_offsets; - int tiw = compute_tile_resolution(tex_dense->data_width); - int tih = compute_tile_resolution(tex_dense->data_height); - int tid = compute_tile_resolution(tex_dense->data_depth); + int tiw = get_tile_res(tex_img->data_width); + int tih = get_tile_res(tex_img->data_height); + int tid = get_tile_res(tex_img->data_depth); { - /* Since only active tiles are stored in tex_sparse, its + /* Since only active tiles are stored in tex_img, its * allocated memory will be <= the actual resolution * of the volume. We store the true resolution (in tiles) in the * 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 = (SparseTile<DeviceType>*)tex_sparse->alloc(active_tile_count); + texture_pixels = (DeviceType*)tex_img->alloc(voxel_count); texture_offsets = (int*)tex_offsets->alloc(tiw, tih, tid); } @@ -784,20 +781,9 @@ bool ImageManager::file_make_image_sparse(Device *device, offsets.size() * sizeof(int)); memcpy(&texture_pixels[0], &sparse_grid[0], - active_tile_count * sizeof(SparseTile<DeviceType>)); - - img->mem = tex_sparse; - img->mem->interpolation = img->interpolation; - img->mem->extension = img->extension; - img->mem->offsets = tex_offsets; - - thread_scoped_lock device_lock(device_mutex); - tex_sparse->copy_to_device(); - - VLOG(1) << "Original memory usage of '" - << path_filename(img->filename) << "' (" << img->mem_name << "): " - << string_human_readable_size(tex_dense->memory_size()); + voxel_count * sizeof(DeviceType)); + tex_img->offsets = tex_offsets; return true; } @@ -824,19 +810,17 @@ void ImageManager::load_image(Device *device, } if(img->make_sparse) { - if(file_make_image_sparse<DeviceType>(device, img, tex_img)) { - delete tex_img; - tex_img = NULL; + if(!file_make_image_sparse<DeviceType>(device, img, tex_img)) { + file_load_failed<StorageType, DeviceType>(tex_img, type); } } - if(tex_img) { - img->mem = tex_img; - img->mem->interpolation = img->interpolation; - img->mem->extension = img->extension; - thread_scoped_lock device_lock(device_mutex); - tex_img->copy_to_device(); - } + img->mem = tex_img; + img->mem->interpolation = img->interpolation; + img->mem->extension = img->extension; + + thread_scoped_lock device_lock(device_mutex); + tex_img->copy_to_device(); } void ImageManager::device_load_image(Device *device, diff --git a/intern/cycles/render/mesh_volume.cpp b/intern/cycles/render/mesh_volume.cpp index 8a55b89abcc..db8b8797165 100644 --- a/intern/cycles/render/mesh_volume.cpp +++ b/intern/cycles/render/mesh_volume.cpp @@ -378,7 +378,7 @@ void VolumeMeshBuilder::convert_quads_to_tris(const vector<QuadData> &quads, /* ************************************************************************** */ struct VoxelAttributeGrid { - void *data; + float *data; int *offsets = NULL; int channels; }; @@ -410,7 +410,7 @@ void MeshManager::create_volume_mesh(Scene *scene, offsets->data_height * TILE_SIZE, offsets->data_depth * TILE_SIZE); } - else{ + else { resolution = make_int3(image_memory->data_width, image_memory->data_height, image_memory->data_depth); @@ -425,7 +425,7 @@ void MeshManager::create_volume_mesh(Scene *scene, } VoxelAttributeGrid voxel_grid; - voxel_grid.data = image_memory->host_pointer; + voxel_grid.data = static_cast<float*>(image_memory->host_pointer); voxel_grid.channels = image_memory->data_elements; if(offsets) { voxel_grid.offsets = static_cast<int*>(offsets->host_pointer); @@ -469,9 +469,9 @@ void MeshManager::create_volume_mesh(Scene *scene, float3 cell_size = make_float3(1.0f/resolution.x, 1.0f/resolution.y, 1.0f/resolution.z); - const int3 tile_res = make_int3(compute_tile_resolution(resolution.x), - compute_tile_resolution(resolution.y), - compute_tile_resolution(resolution.z)); + const int3 tile_res = make_int3(get_tile_res(resolution.x), + get_tile_res(resolution.y), + get_tile_res(resolution.z)); if(attr) { const Transform *tfm = attr->data_transform(); @@ -488,57 +488,31 @@ void MeshManager::create_volume_mesh(Scene *scene, VolumeMeshBuilder builder(&volume_params); const float isovalue = mesh->volume_isovalue; - for(size_t i = 0; i < voxel_grids.size(); ++i) { - const VoxelAttributeGrid &voxel_grid = voxel_grids[i]; - const int channels = voxel_grid.channels; - - if(channels > 1 && voxel_grid.offsets) { - SparseTile<float4> *data = (SparseTile<float4>*)voxel_grid.data; - for(int z = 0; z < resolution.z; ++z) { - for(int y = 0; y < resolution.y; ++y) { - for(int x = 0; x < resolution.x; ++x) { - float4 val = get_value<float4>(data, - voxel_grid.offsets, - x, y, z, - tile_res.x, - tile_res.y, - tile_res.z); - if(any(isovalue < val)) { - builder.add_node_with_padding(x, y, z); + for(int z = 0; z < resolution.z; ++z) { + for(int y = 0; y < resolution.y; ++y) { + for(int x = 0; x < resolution.x; ++x) { + int voxel_index = compute_index(x, y, z, resolution); + + for(size_t i = 0; i < voxel_grids.size(); ++i) { + const VoxelAttributeGrid &voxel_grid = voxel_grids[i]; + const int channels = voxel_grid.channels; + const int *offsets = voxel_grid.offsets; + + if(offsets) { + voxel_index = compute_index(offsets, x, y, z, + tile_res.x, + tile_res.y, + tile_res.z); + if(voxel_index < 0) { + continue; } } - } - } - } - else if(voxel_grid.offsets) { - SparseTile<float> *data = (SparseTile<float>*)voxel_grid.data; - for(int z = 0; z < resolution.z; ++z) { - for(int y = 0; y < resolution.y; ++y) { - for(int x = 0; x < resolution.x; ++x) { - float val = get_value<float>(data, - voxel_grid.offsets, - x, y, z, - tile_res.x, - tile_res.y, - tile_res.z); - if(val >= isovalue) { + + voxel_index *= channels; + for(int c = 0; c < channels; c++) { + if(voxel_grid.data[voxel_index + c] >= isovalue) { builder.add_node_with_padding(x, y, z); - } - } - } - } - } - else { - float *data = (float*)(voxel_grid.data); - for(int z = 0; z < resolution.z; ++z) { - for(int y = 0; y < resolution.y; ++y) { - for(int x = 0; x < resolution.x; ++x) { - size_t voxel_index = compute_index(x, y, z, resolution) * channels; - for(int c = 0 ; c < channels; ++c) { - if(data[voxel_index + c] >= isovalue) { - builder.add_node_with_padding(x, y, z); - break; - } + break; } } } |