diff options
author | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-11-05 19:40:36 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@gmail.com> | 2017-11-05 20:00:48 +0300 |
commit | cac3d4d16691d77e8e01f158be07d182e56e9755 (patch) | |
tree | 455a4d3669f48bfdd1064490082a7a51f9593090 /intern/cycles/render/mesh.cpp | |
parent | 5801ef71e40bc932c69e67f06076cd8b41132e52 (diff) |
Cycles: fix inefficient attribute map storage, saves 615MB in victor scene.
Diffstat (limited to 'intern/cycles/render/mesh.cpp')
-rw-r--r-- | intern/cycles/render/mesh.cpp | 43 |
1 files changed, 20 insertions, 23 deletions
diff --git a/intern/cycles/render/mesh.cpp b/intern/cycles/render/mesh.cpp index 75bdf71616f..189ba80ad2a 100644 --- a/intern/cycles/render/mesh.cpp +++ b/intern/cycles/render/mesh.cpp @@ -436,6 +436,8 @@ Mesh::Mesh() face_offset = 0; corner_offset = 0; + attr_map_offset = 0; + num_subd_verts = 0; attributes.triangle_mesh = this; @@ -1258,33 +1260,27 @@ void MeshManager::update_svm_attributes(Device *, DeviceScene *dscene, Scene *sc * attribute, based on a unique shader attribute id. */ /* compute array stride */ - int attr_map_stride = 0; + int attr_map_size = 0; - for(size_t i = 0; i < scene->meshes.size(); i++) - attr_map_stride = max(attr_map_stride, (mesh_attributes[i].size() + 1)*ATTR_PRIM_TYPES); + for(size_t i = 0; i < scene->meshes.size(); i++) { + Mesh *mesh = scene->meshes[i]; + mesh->attr_map_offset = attr_map_size; + attr_map_size += (mesh_attributes[i].size() + 1)*ATTR_PRIM_TYPES; + } - if(attr_map_stride == 0) + if(attr_map_size == 0) return; /* create attribute map */ - uint4 *attr_map = dscene->attributes_map.alloc(attr_map_stride*scene->objects.size()); + uint4 *attr_map = dscene->attributes_map.alloc(attr_map_size*scene->meshes.size()); memset(attr_map, 0, dscene->attributes_map.size()*sizeof(uint)); - for(size_t i = 0; i < scene->objects.size(); i++) { - Object *object = scene->objects[i]; - Mesh *mesh = object->mesh; - - /* find mesh attributes */ - size_t j; - - for(j = 0; j < scene->meshes.size(); j++) - if(scene->meshes[j] == mesh) - break; - - AttributeRequestSet& attributes = mesh_attributes[j]; + for(size_t i = 0; i < scene->meshes.size(); i++) { + Mesh *mesh = scene->meshes[i]; + AttributeRequestSet& attributes = mesh_attributes[i]; /* set object attributes */ - int index = i*attr_map_stride; + int index = mesh->attr_map_offset; foreach(AttributeRequest& req, attributes.requests) { uint id; @@ -1358,7 +1354,6 @@ void MeshManager::update_svm_attributes(Device *, DeviceScene *dscene, Scene *sc } /* copy to device */ - dscene->data.bvh.attributes_map_stride = attr_map_stride; dscene->attributes_map.copy_to_device(); } @@ -1625,6 +1620,12 @@ void MeshManager::device_update_attributes(Device *device, DeviceScene *dscene, if(dscene->attributes_uchar4.size()) { dscene->attributes_uchar4.copy_to_device(); } + + if(progress.get_cancel()) return; + + /* After mesh attributes and patch tables have been copied to device memory, + * we need to update offsets in the objects. */ + scene->object_manager->device_update_mesh_offsets(device, dscene, scene); } void MeshManager::mesh_calc_offset(Scene *scene) @@ -2042,10 +2043,6 @@ void MeshManager::device_update(Device *device, DeviceScene *dscene, Scene *scen } if(progress.get_cancel()) return; - /* after mesh data has been copied to device memory we need to update - * offsets for patch tables as this can't be known before hand */ - scene->object_manager->device_update_patch_map_offsets(device, dscene, scene); - device_update_attributes(device, dscene, scene, progress); if(progress.get_cancel()) return; |