Merge branch 'master' into blender2.8

This commit is contained in:
Sybren A. Stüvel
2017-08-09 15:08:06 +02:00
12 changed files with 128 additions and 68 deletions

View File

@@ -519,20 +519,26 @@ void OpenCLDeviceBase::tex_alloc(const char *name,
<< string_human_readable_size(mem.memory_size()) << ")"; << string_human_readable_size(mem.memory_size()) << ")";
memory_manager.alloc(name, mem); memory_manager.alloc(name, mem);
/* Set the pointer to non-null to keep code that inspects its value from thinking its unallocated. */
mem.device_pointer = 1;
textures[name] = Texture(&mem, interpolation, extension); textures[name] = Texture(&mem, interpolation, extension);
textures_need_update = true; textures_need_update = true;
} }
void OpenCLDeviceBase::tex_free(device_memory& mem) void OpenCLDeviceBase::tex_free(device_memory& mem)
{ {
if(memory_manager.free(mem)) { if(mem.device_pointer) {
textures_need_update = true; mem.device_pointer = 0;
}
foreach(TexturesMap::value_type& value, textures) { if(memory_manager.free(mem)) {
if(value.second.mem == &mem) { textures_need_update = true;
textures.erase(value.first); }
break;
foreach(TexturesMap::value_type& value, textures) {
if(value.second.mem == &mem) {
textures.erase(value.first);
break;
}
} }
} }
} }

View File

@@ -119,7 +119,7 @@ public:
typedef struct _tex_info_t { typedef struct _tex_info_t {
uint buffer, padding; uint buffer, padding;
ulong offset; uint64_t offset;
uint width, height, depth, options; uint width, height, depth, options;
} _tex_info_t; } _tex_info_t;

View File

@@ -119,7 +119,7 @@ typedef type name##_t;
typedef struct tex_info_t { typedef struct tex_info_t {
uint buffer, padding; uint buffer, padding;
ulong offset; uint64_t offset;
uint width, height, depth, options; uint width, height, depth, options;
} tex_info_t; } tex_info_t;

View File

@@ -178,7 +178,7 @@ __kernel void kernel_ocl_convert_to_half_float(
kernel_film_convert_to_half_float(kg, rgba, buffer, sample_scale, x, y, offset, stride); kernel_film_convert_to_half_float(kg, rgba, buffer, sample_scale, x, y, offset, stride);
} }
__kernel void kernel_ocl_zero_buffer(ccl_global float4 *buffer, ulong size, ulong offset) __kernel void kernel_ocl_zero_buffer(ccl_global float4 *buffer, uint64_t size, uint64_t offset)
{ {
size_t i = ccl_global_id(0) + ccl_global_id(1) * ccl_global_size(0); size_t i = ccl_global_id(0) + ccl_global_id(1) * ccl_global_size(0);

View File

@@ -716,7 +716,12 @@ void ImageManager::device_load_image(Device *device,
if(dscene->tex_float4_image[slot] == NULL) if(dscene->tex_float4_image[slot] == NULL)
dscene->tex_float4_image[slot] = new device_vector<float4>(); dscene->tex_float4_image[slot] = new device_vector<float4>();
device_vector<float4>& tex_img = *dscene->tex_float4_image[slot]; device_vector<float4>& tex_img = *dscene->tex_float4_image[slot];
device_tex_free_safe(device, tex_img);
if(tex_img.device_pointer) {
thread_scoped_lock device_lock(device_mutex);
device->tex_free(tex_img);
}
if(!file_load_image<TypeDesc::FLOAT, float>(img, if(!file_load_image<TypeDesc::FLOAT, float>(img,
type, type,
texture_limit, texture_limit,
@@ -743,7 +748,12 @@ void ImageManager::device_load_image(Device *device,
if(dscene->tex_float_image[slot] == NULL) if(dscene->tex_float_image[slot] == NULL)
dscene->tex_float_image[slot] = new device_vector<float>(); dscene->tex_float_image[slot] = new device_vector<float>();
device_vector<float>& tex_img = *dscene->tex_float_image[slot]; device_vector<float>& tex_img = *dscene->tex_float_image[slot];
device_tex_free_safe(device, tex_img);
if(tex_img.device_pointer) {
thread_scoped_lock device_lock(device_mutex);
device->tex_free(tex_img);
}
if(!file_load_image<TypeDesc::FLOAT, float>(img, if(!file_load_image<TypeDesc::FLOAT, float>(img,
type, type,
texture_limit, texture_limit,
@@ -767,7 +777,12 @@ void ImageManager::device_load_image(Device *device,
if(dscene->tex_byte4_image[slot] == NULL) if(dscene->tex_byte4_image[slot] == NULL)
dscene->tex_byte4_image[slot] = new device_vector<uchar4>(); dscene->tex_byte4_image[slot] = new device_vector<uchar4>();
device_vector<uchar4>& tex_img = *dscene->tex_byte4_image[slot]; device_vector<uchar4>& tex_img = *dscene->tex_byte4_image[slot];
device_tex_free_safe(device, tex_img);
if(tex_img.device_pointer) {
thread_scoped_lock device_lock(device_mutex);
device->tex_free(tex_img);
}
if(!file_load_image<TypeDesc::UINT8, uchar>(img, if(!file_load_image<TypeDesc::UINT8, uchar>(img,
type, type,
texture_limit, texture_limit,
@@ -794,7 +809,12 @@ void ImageManager::device_load_image(Device *device,
if(dscene->tex_byte_image[slot] == NULL) if(dscene->tex_byte_image[slot] == NULL)
dscene->tex_byte_image[slot] = new device_vector<uchar>(); dscene->tex_byte_image[slot] = new device_vector<uchar>();
device_vector<uchar>& tex_img = *dscene->tex_byte_image[slot]; device_vector<uchar>& tex_img = *dscene->tex_byte_image[slot];
device_tex_free_safe(device, tex_img);
if(tex_img.device_pointer) {
thread_scoped_lock device_lock(device_mutex);
device->tex_free(tex_img);
}
if(!file_load_image<TypeDesc::UINT8, uchar>(img, if(!file_load_image<TypeDesc::UINT8, uchar>(img,
type, type,
texture_limit, texture_limit,
@@ -817,7 +837,12 @@ void ImageManager::device_load_image(Device *device,
if(dscene->tex_half4_image[slot] == NULL) if(dscene->tex_half4_image[slot] == NULL)
dscene->tex_half4_image[slot] = new device_vector<half4>(); dscene->tex_half4_image[slot] = new device_vector<half4>();
device_vector<half4>& tex_img = *dscene->tex_half4_image[slot]; device_vector<half4>& tex_img = *dscene->tex_half4_image[slot];
device_tex_free_safe(device, tex_img);
if(tex_img.device_pointer) {
thread_scoped_lock device_lock(device_mutex);
device->tex_free(tex_img);
}
if(!file_load_image<TypeDesc::HALF, half>(img, if(!file_load_image<TypeDesc::HALF, half>(img,
type, type,
texture_limit, texture_limit,
@@ -843,7 +868,12 @@ void ImageManager::device_load_image(Device *device,
if(dscene->tex_half_image[slot] == NULL) if(dscene->tex_half_image[slot] == NULL)
dscene->tex_half_image[slot] = new device_vector<half>(); dscene->tex_half_image[slot] = new device_vector<half>();
device_vector<half>& tex_img = *dscene->tex_half_image[slot]; device_vector<half>& tex_img = *dscene->tex_half_image[slot];
device_tex_free_safe(device, tex_img);
if(tex_img.device_pointer) {
thread_scoped_lock device_lock(device_mutex);
device->tex_free(tex_img);
}
if(!file_load_image<TypeDesc::HALF, half>(img, if(!file_load_image<TypeDesc::HALF, half>(img,
type, type,
texture_limit, texture_limit,
@@ -927,7 +957,11 @@ void ImageManager::device_free_image(Device *device, DeviceScene *dscene, ImageD
tex_img = NULL; tex_img = NULL;
} }
if(tex_img) { if(tex_img) {
device_tex_free_safe(device, *tex_img); if(tex_img->device_pointer) {
thread_scoped_lock device_lock(device_mutex);
device->tex_free(*tex_img);
}
delete tex_img; delete tex_img;
} }
} }
@@ -1063,16 +1097,5 @@ void ImageManager::device_free(Device *device, DeviceScene *dscene)
dscene->tex_half_image.clear(); dscene->tex_half_image.clear();
} }
void ImageManager::device_tex_free_safe(Device *device, device_memory& mem)
{
if(mem.device_pointer) {
thread_scoped_lock device_lock(device_mutex);
device->tex_free(mem);
}
else {
device->tex_free(mem);
}
}
CCL_NAMESPACE_END CCL_NAMESPACE_END

View File

@@ -160,11 +160,6 @@ private:
DeviceScene *dscene, DeviceScene *dscene,
ImageDataType type, ImageDataType type,
int slot); int slot);
/* Will do locking when needed and make sure possible memory manager from
* the device implementation is aware of freed texture.
*/
void device_tex_free_safe(Device *device, device_memory& mem);
}; };
CCL_NAMESPACE_END CCL_NAMESPACE_END

View File

@@ -681,17 +681,17 @@ static void assign_materials(Main *bmain, Object *ob, const std::map<std::string
std::string mat_name = it->first; std::string mat_name = it->first;
mat_iter = mat_map.find(mat_name.c_str()); mat_iter = mat_map.find(mat_name.c_str());
Material *assigned_name; Material *assigned_mat;
if (mat_iter == mat_map.end()) { if (mat_iter == mat_map.end()) {
assigned_name = BKE_material_add(bmain, mat_name.c_str()); assigned_mat = BKE_material_add(bmain, mat_name.c_str());
mat_map[mat_name] = assigned_name; mat_map[mat_name] = assigned_mat;
} }
else { else {
assigned_name = mat_iter->second; assigned_mat = mat_iter->second;
} }
assign_material(ob, assigned_name, it->second, BKE_MAT_ASSIGN_OBDATA); assign_material(ob, assigned_mat, it->second, BKE_MAT_ASSIGN_OBDATA);
} }
} }
} }
@@ -977,8 +977,6 @@ static void read_mesh_sample(ImportSettings *settings,
if ((settings->read_flag & (MOD_MESHSEQ_READ_UV | MOD_MESHSEQ_READ_COLOR)) != 0) { if ((settings->read_flag & (MOD_MESHSEQ_READ_UV | MOD_MESHSEQ_READ_COLOR)) != 0) {
read_custom_data(schema.getArbGeomParams(), config, selector); read_custom_data(schema.getArbGeomParams(), config, selector);
} }
/* TODO: face sets */
} }
CDStreamConfig get_config(DerivedMesh *dm) CDStreamConfig get_config(DerivedMesh *dm)
@@ -1117,6 +1115,16 @@ DerivedMesh *AbcMeshReader::read_derivedmesh(DerivedMesh *dm,
CDDM_calc_normals(new_dm); CDDM_calc_normals(new_dm);
CDDM_calc_edges(new_dm); CDDM_calc_edges(new_dm);
/* Here we assume that the number of materials doesn't change, i.e. that
* the material slots that were created when the object was loaded from
* Alembic are still valid now. */
size_t num_polys = new_dm->getNumPolys(new_dm);
if (num_polys > 0) {
MPoly *dmpolies = new_dm->getPolyArray(new_dm);
std::map<std::string, int> mat_map;
assign_facesets_to_mpoly(sample_sel, 0, dmpolies, num_polys, mat_map);
}
return new_dm; return new_dm;
} }
@@ -1127,8 +1135,11 @@ DerivedMesh *AbcMeshReader::read_derivedmesh(DerivedMesh *dm,
return dm; return dm;
} }
void AbcMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, size_t poly_start, void AbcMeshReader::assign_facesets_to_mpoly(
const ISampleSelector &sample_sel) const ISampleSelector &sample_sel,
size_t poly_start,
MPoly *mpoly, int totpoly,
std::map<std::string, int> & r_mat_map)
{ {
std::vector<std::string> face_sets; std::vector<std::string> face_sets;
m_schema.getFaceSetNames(face_sets); m_schema.getFaceSetNames(face_sets);
@@ -1137,21 +1148,21 @@ void AbcMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, size_t poly_star
return; return;
} }
std::map<std::string, int> mat_map;
int current_mat = 0; int current_mat = 0;
for (int i = 0; i < face_sets.size(); ++i) { for (int i = 0; i < face_sets.size(); ++i) {
const std::string &grp_name = face_sets[i]; const std::string &grp_name = face_sets[i];
if (mat_map.find(grp_name) == mat_map.end()) { if (r_mat_map.find(grp_name) == r_mat_map.end()) {
mat_map[grp_name] = 1 + current_mat++; r_mat_map[grp_name] = 1 + current_mat++;
} }
const int assigned_mat = mat_map[grp_name]; const int assigned_mat = r_mat_map[grp_name];
const IFaceSet faceset = m_schema.getFaceSet(grp_name); const IFaceSet faceset = m_schema.getFaceSet(grp_name);
if (!faceset.valid()) { if (!faceset.valid()) {
std::cerr << " Face set " << grp_name << " invalid for " << m_object_name << "\n";
continue; continue;
} }
@@ -1163,16 +1174,25 @@ void AbcMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, size_t poly_star
for (size_t l = 0; l < num_group_faces; l++) { for (size_t l = 0; l < num_group_faces; l++) {
size_t pos = (*group_faces)[l] + poly_start; size_t pos = (*group_faces)[l] + poly_start;
if (pos >= mesh->totpoly) { if (pos >= totpoly) {
std::cerr << "Faceset overflow on " << faceset.getName() << '\n'; std::cerr << "Faceset overflow on " << faceset.getName() << '\n';
break; break;
} }
MPoly &poly = mesh->mpoly[pos]; MPoly &poly = mpoly[pos];
poly.mat_nr = assigned_mat - 1; poly.mat_nr = assigned_mat - 1;
} }
} }
}
void AbcMeshReader::readFaceSetsSample(Main *bmain, Mesh *mesh, size_t poly_start,
const ISampleSelector &sample_sel)
{
std::map<std::string, int> mat_map;
assign_facesets_to_mpoly(sample_sel,
poly_start, mesh->mpoly, mesh->totpoly,
mat_map);
utils::assign_materials(bmain, m_object, mat_map); utils::assign_materials(bmain, m_object, mat_map);
} }
@@ -1228,8 +1248,6 @@ static void read_subd_sample(ImportSettings *settings,
if ((settings->read_flag & (MOD_MESHSEQ_READ_UV | MOD_MESHSEQ_READ_COLOR)) != 0) { if ((settings->read_flag & (MOD_MESHSEQ_READ_UV | MOD_MESHSEQ_READ_COLOR)) != 0) {
read_custom_data(schema.getArbGeomParams(), config, selector); read_custom_data(schema.getArbGeomParams(), config, selector);
} }
/* TODO: face sets */
} }
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -113,6 +113,11 @@ public:
private: private:
void readFaceSetsSample(Main *bmain, Mesh *mesh, size_t poly_start, void readFaceSetsSample(Main *bmain, Mesh *mesh, size_t poly_start,
const Alembic::AbcGeom::ISampleSelector &sample_sel); const Alembic::AbcGeom::ISampleSelector &sample_sel);
void assign_facesets_to_mpoly(const Alembic::Abc::ISampleSelector &sample_sel,
size_t poly_start,
MPoly *mpoly, int totpoly,
std::map<std::string, int> & r_mat_map);
}; };
/* ************************************************************************** */ /* ************************************************************************** */

View File

@@ -2053,7 +2053,9 @@ void ED_object_single_users(Main *bmain, Scene *scene, const bool full, const bo
IDP_RelinkProperty(scene->gpd->id.properties); IDP_RelinkProperty(scene->gpd->id.properties);
} }
IDP_RelinkProperty(scene->world->id.properties); if (scene->world) {
IDP_RelinkProperty(scene->world->id.properties);
}
if (scene->clip) { if (scene->clip) {
IDP_RelinkProperty(scene->clip->id.properties); IDP_RelinkProperty(scene->clip->id.properties);

View File

@@ -101,7 +101,7 @@ static DerivedMesh *applyModifier(ModifierData *md, struct EvaluationContext *UN
#ifdef WITH_ALEMBIC #ifdef WITH_ALEMBIC
MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *) md; MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *) md;
/* Only used to check wehther we are operating on org data or not... */ /* Only used to check whether we are operating on org data or not... */
Mesh *me = (ob->type == OB_MESH) ? ob->data : NULL; Mesh *me = (ob->type == OB_MESH) ? ob->data : NULL;
DerivedMesh *org_dm = dm; DerivedMesh *org_dm = dm;

View File

@@ -179,22 +179,24 @@ class SimpleImportTest(AbstractAlembicTest):
res = bpy.ops.wm.alembic_import(filepath=str(abc), as_background_job=False) res = bpy.ops.wm.alembic_import(filepath=str(abc), as_background_job=False)
self.assertEqual({'FINISHED'}, res) self.assertEqual({'FINISHED'}, res)
cube = bpy.context.active_object plane = bpy.context.active_object
# Check that the file loaded ok. # Check that the file loaded ok.
bpy.context.scene.frame_set(6) bpy.context.scene.frame_set(6)
self.assertAlmostEqual(-1, cube.data.vertices[0].co.x) mesh = plane.to_mesh(bpy.context.scene, True, 'RENDER')
self.assertAlmostEqual(-1, cube.data.vertices[0].co.y) self.assertAlmostEqual(-1, mesh.vertices[0].co.x)
self.assertAlmostEqual(0.5905638933181763, cube.data.vertices[0].co.z) self.assertAlmostEqual(-1, mesh.vertices[0].co.y)
self.assertAlmostEqual(0.5905638933181763, mesh.vertices[0].co.z)
# Change path from absolute to relative. This should not break the animation. # Change path from absolute to relative. This should not break the animation.
bpy.context.scene.frame_set(1) bpy.context.scene.frame_set(1)
bpy.data.cache_files[fname].filepath = relpath bpy.data.cache_files[fname].filepath = relpath
bpy.context.scene.frame_set(6) bpy.context.scene.frame_set(6)
self.assertAlmostEqual(1, cube.data.vertices[3].co.x) mesh = plane.to_mesh(bpy.context.scene, True, 'RENDER')
self.assertAlmostEqual(1, cube.data.vertices[3].co.y) self.assertAlmostEqual(1, mesh.vertices[3].co.x)
self.assertAlmostEqual(0.5905638933181763, cube.data.vertices[3].co.z) self.assertAlmostEqual(1, mesh.vertices[3].co.y)
self.assertAlmostEqual(0.5905638933181763, mesh.vertices[3].co.z)
def test_import_long_names(self): def test_import_long_names(self):
# This file contains very long names. The longest name is 4047 chars. # This file contains very long names. The longest name is 4047 chars.

View File

@@ -123,6 +123,8 @@ def load_addons():
def load_modules(): def load_modules():
VERBOSE = os.environ.get("BLENDER_VERBOSE") is not None
modules = [] modules = []
module_paths = [] module_paths = []
@@ -161,6 +163,14 @@ def load_modules():
module_names[mod] = mod_dir, mod_full module_names[mod] = mod_dir, mod_full
del module_names del module_names
#
# test we tested all files except for presets and templates
ignore_paths = [
os.sep + "presets" + os.sep,
os.sep + "templates" + os.sep,
] + ([(os.sep + f + os.sep) for f in BLACKLIST] +
[(os.sep + f + ".py") for f in BLACKLIST])
# #
# now submodules # now submodules
for m in modules: for m in modules:
@@ -199,7 +209,14 @@ def load_modules():
# import failure. # import failure.
# - We want to catch all failures of this script instead of stopping on # - We want to catch all failures of this script instead of stopping on
# a first big failure. # a first big failure.
traceback.print_exc() do_print = True
if not VERBOSE:
for ignore in ignore_paths:
if ignore in submod_full:
do_print = False
break
if do_print:
traceback.print_exc()
# #
# check which filepaths we didn't load # check which filepaths we didn't load
@@ -218,14 +235,6 @@ def load_modules():
for f in loaded_files: for f in loaded_files:
source_files.remove(f) source_files.remove(f)
#
# test we tested all files except for presets and templates
ignore_paths = [
os.sep + "presets" + os.sep,
os.sep + "templates" + os.sep,
] + ([(os.sep + f + os.sep) for f in BLACKLIST] +
[(os.sep + f + ".py") for f in BLACKLIST])
for f in source_files: for f in source_files:
for ignore in ignore_paths: for ignore in ignore_paths:
if ignore in f: if ignore in f: