2011-04-27 11:58:34 +00:00
|
|
|
/*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Copyright 2011-2013 Blender Foundation
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-04-27 11:58:34 +00:00
|
|
|
*
|
2013-08-18 14:16:15 +00:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
2014-12-25 01:50:24 +00:00
|
|
|
* limitations under the License.
|
2011-04-27 11:58:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bvh.h"
|
|
|
|
#include "bvh_build.h"
|
|
|
|
|
2012-10-17 17:27:30 +00:00
|
|
|
#include "camera.h"
|
2014-03-29 12:03:46 +00:00
|
|
|
#include "curves.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "device.h"
|
2015-04-02 15:37:57 +00:00
|
|
|
#include "graph.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "shader.h"
|
2011-09-12 13:13:56 +00:00
|
|
|
#include "light.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "mesh.h"
|
2015-04-02 15:37:57 +00:00
|
|
|
#include "nodes.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "object.h"
|
|
|
|
#include "scene.h"
|
|
|
|
|
|
|
|
#include "osl_globals.h"
|
|
|
|
|
2016-08-14 16:41:45 +00:00
|
|
|
#include "subd_split.h"
|
2016-07-17 02:57:06 +00:00
|
|
|
#include "subd_patch_table.h"
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "util_foreach.h"
|
2014-12-24 19:53:26 +00:00
|
|
|
#include "util_logging.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
#include "util_progress.h"
|
|
|
|
#include "util_set.h"
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
2014-03-29 12:03:46 +00:00
|
|
|
/* Triangle */
|
|
|
|
|
|
|
|
void Mesh::Triangle::bounds_grow(const float3 *verts, BoundBox& bounds) const
|
|
|
|
{
|
|
|
|
bounds.grow(verts[v[0]]);
|
|
|
|
bounds.grow(verts[v[1]]);
|
|
|
|
bounds.grow(verts[v[2]]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Curve */
|
|
|
|
|
2016-05-07 22:09:08 +00:00
|
|
|
void Mesh::Curve::bounds_grow(const int k, const float3 *curve_keys, const float *curve_radius, BoundBox& bounds) const
|
2014-03-29 12:03:46 +00:00
|
|
|
{
|
|
|
|
float3 P[4];
|
|
|
|
|
2016-05-07 22:09:08 +00:00
|
|
|
P[0] = curve_keys[max(first_key + k - 1,first_key)];
|
|
|
|
P[1] = curve_keys[first_key + k];
|
|
|
|
P[2] = curve_keys[first_key + k + 1];
|
|
|
|
P[3] = curve_keys[min(first_key + k + 2, first_key + num_keys - 1)];
|
2014-03-29 12:03:46 +00:00
|
|
|
|
|
|
|
float3 lower;
|
|
|
|
float3 upper;
|
|
|
|
|
|
|
|
curvebounds(&lower.x, &upper.x, P, 0);
|
|
|
|
curvebounds(&lower.y, &upper.y, P, 1);
|
|
|
|
curvebounds(&lower.z, &upper.z, P, 2);
|
|
|
|
|
2016-05-07 22:09:08 +00:00
|
|
|
float mr = max(curve_radius[first_key + k], curve_radius[first_key + k + 1]);
|
2014-03-29 12:03:46 +00:00
|
|
|
|
|
|
|
bounds.grow(lower, mr);
|
|
|
|
bounds.grow(upper, mr);
|
|
|
|
}
|
|
|
|
|
2016-07-07 10:18:57 +00:00
|
|
|
void Mesh::Curve::bounds_grow(const int k,
|
|
|
|
const float3 *curve_keys,
|
|
|
|
const float *curve_radius,
|
|
|
|
const Transform& aligned_space,
|
|
|
|
BoundBox& bounds) const
|
|
|
|
{
|
|
|
|
float3 P[4];
|
|
|
|
|
|
|
|
P[0] = curve_keys[max(first_key + k - 1,first_key)];
|
|
|
|
P[1] = curve_keys[first_key + k];
|
|
|
|
P[2] = curve_keys[first_key + k + 1];
|
|
|
|
P[3] = curve_keys[min(first_key + k + 2, first_key + num_keys - 1)];
|
|
|
|
|
|
|
|
P[0] = transform_point(&aligned_space, P[0]);
|
|
|
|
P[1] = transform_point(&aligned_space, P[1]);
|
|
|
|
P[2] = transform_point(&aligned_space, P[2]);
|
|
|
|
P[3] = transform_point(&aligned_space, P[3]);
|
|
|
|
|
|
|
|
float3 lower;
|
|
|
|
float3 upper;
|
|
|
|
|
|
|
|
curvebounds(&lower.x, &upper.x, P, 0);
|
|
|
|
curvebounds(&lower.y, &upper.y, P, 1);
|
|
|
|
curvebounds(&lower.z, &upper.z, P, 2);
|
|
|
|
|
|
|
|
float mr = max(curve_radius[first_key + k], curve_radius[first_key + k + 1]);
|
|
|
|
|
|
|
|
bounds.grow(lower, mr);
|
|
|
|
bounds.grow(upper, mr);
|
|
|
|
}
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
/* SubdFace */
|
|
|
|
|
|
|
|
float3 Mesh::SubdFace::normal(const Mesh *mesh) const
|
|
|
|
{
|
|
|
|
float3 v0 = mesh->verts[mesh->subd_face_corners[start_corner+0]];
|
|
|
|
float3 v1 = mesh->verts[mesh->subd_face_corners[start_corner+1]];
|
|
|
|
float3 v2 = mesh->verts[mesh->subd_face_corners[start_corner+2]];
|
|
|
|
|
|
|
|
return safe_normalize(cross(v1 - v0, v2 - v0));
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Mesh */
|
|
|
|
|
2016-05-07 19:44:17 +00:00
|
|
|
NODE_DEFINE(Mesh)
|
|
|
|
{
|
|
|
|
NodeType* type = NodeType::add("mesh", create);
|
|
|
|
|
2016-06-12 15:12:25 +00:00
|
|
|
SOCKET_UINT(motion_steps, "Motion Steps", 3);
|
2016-05-07 19:44:17 +00:00
|
|
|
SOCKET_BOOLEAN(use_motion_blur, "Use Motion Blur", false);
|
|
|
|
|
|
|
|
SOCKET_INT_ARRAY(triangles, "Triangles", array<int>());
|
|
|
|
SOCKET_POINT_ARRAY(verts, "Vertices", array<float3>());
|
|
|
|
SOCKET_INT_ARRAY(shader, "Shader", array<int>());
|
|
|
|
SOCKET_BOOLEAN_ARRAY(smooth, "Smooth", array<bool>());
|
|
|
|
|
|
|
|
SOCKET_POINT_ARRAY(curve_keys, "Curve Keys", array<float3>());
|
|
|
|
SOCKET_FLOAT_ARRAY(curve_radius, "Curve Radius", array<float>());
|
|
|
|
SOCKET_INT_ARRAY(curve_first_key, "Curve First Key", array<int>());
|
|
|
|
SOCKET_INT_ARRAY(curve_shader, "Curve Shader", array<int>());
|
|
|
|
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
Mesh::Mesh()
|
2016-05-07 19:44:17 +00:00
|
|
|
: Node(node_type)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
need_update = true;
|
2013-09-03 22:39:21 +00:00
|
|
|
need_update_rebuild = false;
|
2011-04-27 11:58:34 +00:00
|
|
|
transform_applied = false;
|
2011-11-12 14:29:52 +00:00
|
|
|
transform_negative_scaled = false;
|
2013-01-15 16:35:05 +00:00
|
|
|
transform_normal = transform_identity();
|
Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
and the initial bounding/splitting is still single threaded, but recursive
splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
code from the Embree raytracer from Intel.
http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
2012-04-28 08:53:59 +00:00
|
|
|
bounds = BoundBox::empty;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
bvh = NULL;
|
|
|
|
|
|
|
|
tri_offset = 0;
|
|
|
|
vert_offset = 0;
|
2012-02-28 16:45:01 +00:00
|
|
|
|
2013-01-03 12:09:09 +00:00
|
|
|
curve_offset = 0;
|
2012-12-28 14:21:30 +00:00
|
|
|
curvekey_offset = 0;
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
patch_offset = 0;
|
|
|
|
face_offset = 0;
|
|
|
|
corner_offset = 0;
|
|
|
|
|
|
|
|
num_subd_verts = 0;
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
attributes.triangle_mesh = this;
|
|
|
|
curve_attributes.curve_mesh = this;
|
2016-07-16 23:42:28 +00:00
|
|
|
subd_attributes.subd_mesh = this;
|
2014-10-17 08:56:36 +00:00
|
|
|
|
2016-05-07 22:09:08 +00:00
|
|
|
geometry_flags = GEOMETRY_NONE;
|
|
|
|
|
2014-10-17 08:56:36 +00:00
|
|
|
has_volume = false;
|
2016-02-25 14:12:11 +00:00
|
|
|
has_surface_bssrdf = false;
|
2016-07-16 23:42:28 +00:00
|
|
|
|
|
|
|
num_ngons = 0;
|
2016-07-16 23:56:45 +00:00
|
|
|
|
|
|
|
subdivision_type = SUBDIVISION_NONE;
|
2016-08-14 16:41:45 +00:00
|
|
|
subd_params = NULL;
|
2016-07-17 02:57:06 +00:00
|
|
|
|
|
|
|
patch_table = NULL;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Mesh::~Mesh()
|
|
|
|
{
|
|
|
|
delete bvh;
|
2016-07-17 02:57:06 +00:00
|
|
|
delete patch_table;
|
2016-08-14 16:41:45 +00:00
|
|
|
delete subd_params;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-05-07 22:09:08 +00:00
|
|
|
void Mesh::resize_mesh(int numverts, int numtris)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
verts.resize(numverts);
|
2016-05-07 22:09:08 +00:00
|
|
|
triangles.resize(numtris * 3);
|
2011-04-27 11:58:34 +00:00
|
|
|
shader.resize(numtris);
|
|
|
|
smooth.resize(numtris);
|
2016-04-11 21:46:00 +00:00
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
if(subd_faces.size()) {
|
|
|
|
triangle_patch.resize(numtris);
|
|
|
|
vert_patch_uv.resize(numverts);
|
|
|
|
}
|
2016-04-11 21:46:00 +00:00
|
|
|
|
2016-05-07 22:09:08 +00:00
|
|
|
attributes.resize();
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2016-05-07 22:09:08 +00:00
|
|
|
void Mesh::reserve_mesh(int numverts, int numtris)
|
|
|
|
{
|
|
|
|
/* reserve space to add verts and triangles later */
|
|
|
|
verts.reserve(numverts);
|
|
|
|
triangles.reserve(numtris * 3);
|
|
|
|
shader.reserve(numtris);
|
|
|
|
smooth.reserve(numtris);
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
if(subd_faces.size()) {
|
|
|
|
triangle_patch.reserve(numtris);
|
|
|
|
vert_patch_uv.reserve(numverts);
|
|
|
|
}
|
2016-05-07 22:09:08 +00:00
|
|
|
|
|
|
|
attributes.resize(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mesh::resize_curves(int numcurves, int numkeys)
|
|
|
|
{
|
|
|
|
curve_keys.resize(numkeys);
|
|
|
|
curve_radius.resize(numkeys);
|
|
|
|
curve_first_key.resize(numcurves);
|
|
|
|
curve_shader.resize(numcurves);
|
|
|
|
|
|
|
|
curve_attributes.resize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mesh::reserve_curves(int numcurves, int numkeys)
|
|
|
|
{
|
|
|
|
curve_keys.reserve(numkeys);
|
|
|
|
curve_radius.reserve(numkeys);
|
|
|
|
curve_first_key.reserve(numcurves);
|
|
|
|
curve_shader.reserve(numcurves);
|
|
|
|
|
|
|
|
curve_attributes.resize(true);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
void Mesh::resize_subd_faces(int numfaces, int num_ngons_, int numcorners)
|
|
|
|
{
|
|
|
|
subd_faces.resize(numfaces);
|
|
|
|
subd_face_corners.resize(numcorners);
|
|
|
|
num_ngons = num_ngons_;
|
|
|
|
|
|
|
|
subd_attributes.resize();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Mesh::reserve_subd_faces(int numfaces, int num_ngons_, int numcorners)
|
|
|
|
{
|
|
|
|
subd_faces.reserve(numfaces);
|
|
|
|
subd_face_corners.reserve(numcorners);
|
|
|
|
num_ngons = num_ngons_;
|
|
|
|
|
|
|
|
subd_attributes.resize(true);
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void Mesh::clear()
|
|
|
|
{
|
|
|
|
/* clear all verts and triangles */
|
|
|
|
verts.clear();
|
|
|
|
triangles.clear();
|
|
|
|
shader.clear();
|
|
|
|
smooth.clear();
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
triangle_patch.clear();
|
|
|
|
vert_patch_uv.clear();
|
2016-04-11 21:46:00 +00:00
|
|
|
|
2012-12-28 14:21:30 +00:00
|
|
|
curve_keys.clear();
|
2016-05-07 22:09:08 +00:00
|
|
|
curve_radius.clear();
|
|
|
|
curve_first_key.clear();
|
|
|
|
curve_shader.clear();
|
2012-12-28 14:21:30 +00:00
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
subd_faces.clear();
|
|
|
|
subd_face_corners.clear();
|
|
|
|
|
|
|
|
num_subd_verts = 0;
|
|
|
|
|
2016-07-17 02:57:06 +00:00
|
|
|
subd_creases.clear();
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
attributes.clear();
|
2013-01-03 12:08:54 +00:00
|
|
|
curve_attributes.clear();
|
2016-07-16 23:42:28 +00:00
|
|
|
subd_attributes.clear();
|
2011-04-27 11:58:34 +00:00
|
|
|
used_shaders.clear();
|
2011-11-12 14:29:52 +00:00
|
|
|
|
|
|
|
transform_applied = false;
|
|
|
|
transform_negative_scaled = false;
|
2013-01-15 16:35:05 +00:00
|
|
|
transform_normal = transform_identity();
|
2015-04-09 16:21:48 +00:00
|
|
|
geometry_flags = GEOMETRY_NONE;
|
2016-07-17 02:57:06 +00:00
|
|
|
|
|
|
|
delete patch_table;
|
|
|
|
patch_table = NULL;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-04-13 10:51:06 +00:00
|
|
|
int Mesh::split_vertex(int vertex)
|
|
|
|
{
|
|
|
|
/* copy vertex location and vertex attributes */
|
2016-05-31 13:32:31 +00:00
|
|
|
add_vertex_slow(verts[vertex]);
|
2014-04-13 10:51:06 +00:00
|
|
|
|
|
|
|
foreach(Attribute& attr, attributes.attributes) {
|
|
|
|
if(attr.element == ATTR_ELEMENT_VERTEX) {
|
2016-08-17 21:49:55 +00:00
|
|
|
array<char> tmp(attr.data_sizeof());
|
|
|
|
memcpy(tmp.data(), attr.data() + tmp.size()*vertex, tmp.size());
|
|
|
|
attr.add(tmp.data());
|
2014-04-13 10:51:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
foreach(Attribute& attr, subd_attributes.attributes) {
|
|
|
|
if(attr.element == ATTR_ELEMENT_VERTEX) {
|
2016-08-17 21:49:55 +00:00
|
|
|
array<char> tmp(attr.data_sizeof());
|
|
|
|
memcpy(tmp.data(), attr.data() + tmp.size()*vertex, tmp.size());
|
|
|
|
attr.add(tmp.data());
|
2016-07-16 23:42:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-13 10:51:06 +00:00
|
|
|
return verts.size() - 1;
|
|
|
|
}
|
|
|
|
|
2016-05-07 22:09:08 +00:00
|
|
|
void Mesh::add_vertex(float3 P)
|
2013-07-14 12:51:41 +00:00
|
|
|
{
|
2016-05-07 22:09:08 +00:00
|
|
|
verts.push_back_reserved(P);
|
2016-07-16 23:42:28 +00:00
|
|
|
|
|
|
|
if(subd_faces.size()) {
|
|
|
|
vert_patch_uv.push_back_reserved(make_float2(0.0f, 0.0f));
|
|
|
|
}
|
2013-07-14 12:51:41 +00:00
|
|
|
}
|
|
|
|
|
2016-05-31 13:32:31 +00:00
|
|
|
void Mesh::add_vertex_slow(float3 P)
|
|
|
|
{
|
|
|
|
verts.push_back_slow(P);
|
2016-07-16 23:42:28 +00:00
|
|
|
|
|
|
|
if(subd_faces.size()) {
|
|
|
|
vert_patch_uv.push_back_slow(make_float2(0.0f, 0.0f));
|
|
|
|
}
|
2016-05-31 13:32:31 +00:00
|
|
|
}
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
void Mesh::add_triangle(int v0, int v1, int v2, int shader_, bool smooth_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-05-07 22:09:08 +00:00
|
|
|
triangles.push_back_reserved(v0);
|
|
|
|
triangles.push_back_reserved(v1);
|
|
|
|
triangles.push_back_reserved(v2);
|
|
|
|
shader.push_back_reserved(shader_);
|
|
|
|
smooth.push_back_reserved(smooth_);
|
2016-07-16 23:42:28 +00:00
|
|
|
|
|
|
|
if(subd_faces.size()) {
|
|
|
|
triangle_patch.push_back_reserved(-1);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
void Mesh::add_curve_key(float3 co, float radius)
|
2012-12-28 14:21:30 +00:00
|
|
|
{
|
2016-05-07 22:09:08 +00:00
|
|
|
curve_keys.push_back_reserved(co);
|
|
|
|
curve_radius.push_back_reserved(radius);
|
2012-12-28 14:21:30 +00:00
|
|
|
}
|
|
|
|
|
2016-05-30 20:44:17 +00:00
|
|
|
void Mesh::add_curve(int first_key, int shader)
|
2012-12-28 14:21:30 +00:00
|
|
|
{
|
2016-05-07 22:09:08 +00:00
|
|
|
curve_first_key.push_back_reserved(first_key);
|
|
|
|
curve_shader.push_back_reserved(shader);
|
2012-12-28 14:21:30 +00:00
|
|
|
}
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
void Mesh::add_subd_face(int* corners, int num_corners, int shader_, bool smooth_)
|
|
|
|
{
|
2016-07-29 08:00:37 +00:00
|
|
|
int start_corner = subd_face_corners.size();
|
2016-07-16 23:42:28 +00:00
|
|
|
|
|
|
|
for(int i = 0; i < num_corners; i++) {
|
|
|
|
subd_face_corners.push_back_reserved(corners[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
int ptex_offset = 0;
|
|
|
|
|
|
|
|
if(subd_faces.size()) {
|
|
|
|
SubdFace& s = subd_faces[subd_faces.size()-1];
|
|
|
|
ptex_offset = s.ptex_offset + s.num_ptex_faces();
|
|
|
|
}
|
|
|
|
|
|
|
|
SubdFace face = {start_corner, num_corners, shader_, smooth_, ptex_offset};
|
|
|
|
subd_faces.push_back_reserved(face);
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void Mesh::compute_bounds()
|
|
|
|
{
|
Cycles: merging features from tomato branch.
=== BVH build time optimizations ===
* BVH building was multithreaded. Not all building is multithreaded, packing
and the initial bounding/splitting is still single threaded, but recursive
splitting is, which was the main bottleneck.
* Object splitting now uses binning rather than sorting of all elements, using
code from the Embree raytracer from Intel.
http://software.intel.com/en-us/articles/embree-photo-realistic-ray-tracing-kernels/
* Other small changes to avoid allocations, pack memory more tightly, avoid
some unnecessary operations, ...
These optimizations do not work yet when Spatial Splits are enabled, for that
more work is needed. There's also other optimizations still needed, in
particular for the case of many low poly objects, the packing step and node
memory allocation.
BVH raytracing time should remain about the same, but BVH build time should be
significantly reduced, test here show speedup of about 5x to 10x on a dual core
and 5x to 25x on an 8-core machine, depending on the scene.
=== Threads ===
Centralized task scheduler for multithreading, which is basically the
CPU device threading code wrapped into something reusable.
Basic idea is that there is a single TaskScheduler that keeps a pool of threads,
one for each core. Other places in the code can then create a TaskPool that they
can drop Tasks in to be executed by the scheduler, and wait for them to complete
or cancel them early.
=== Normal ====
Added a Normal output to the texture coordinate node. This currently
gives the object space normal, which is the same under object animation.
In the future this might become a "generated" normal so it's also stable for
deforming objects, but for now it's already useful for non-deforming objects.
=== Render Layers ===
Per render layer Samples control, leaving it to 0 will use the common scene
setting.
Environment pass will now render environment even if film is set to transparent.
Exclude Layers" added. Scene layers (all object that influence the render,
directly or indirectly) are shared between all render layers. However sometimes
it's useful to leave out some object influence for a particular render layer.
That's what this option allows you to do.
=== Filter Glossy ===
When using a value higher than 0.0, this will blur glossy reflections after
blurry bounces, to reduce noise at the cost of accuracy. 1.0 is a good
starting value to tweak.
Some light paths have a low probability of being found while contributing much
light to the pixel. As a result these light paths will be found in some pixels
and not in others, causing fireflies. An example of such a difficult path might
be a small light that is causing a small specular highlight on a sharp glossy
material, which we are seeing through a rough glossy material. With path tracing
it is difficult to find the specular highlight, but if we increase the roughness
on the material the highlight gets bigger and softer, and so easier to find.
Often this blurring will be hardly noticeable, because we are seeing it through
a blurry material anyway, but there are also cases where this will lead to a
loss of detail in lighting.
2012-04-28 08:53:59 +00:00
|
|
|
BoundBox bnds = BoundBox::empty;
|
2011-04-27 11:58:34 +00:00
|
|
|
size_t verts_size = verts.size();
|
2012-12-28 14:21:30 +00:00
|
|
|
size_t curve_keys_size = curve_keys.size();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-04-09 20:48:53 +00:00
|
|
|
if(verts_size + curve_keys_size > 0) {
|
|
|
|
for(size_t i = 0; i < verts_size; i++)
|
|
|
|
bnds.grow(verts[i]);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-04-09 20:48:53 +00:00
|
|
|
for(size_t i = 0; i < curve_keys_size; i++)
|
2016-05-07 22:09:08 +00:00
|
|
|
bnds.grow(curve_keys[i], curve_radius[i]);
|
2014-03-29 12:03:47 +00:00
|
|
|
|
2014-03-29 12:03:46 +00:00
|
|
|
Attribute *attr = attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
|
2015-03-27 19:15:15 +00:00
|
|
|
if(use_motion_blur && attr) {
|
2014-03-29 12:03:46 +00:00
|
|
|
size_t steps_size = verts.size() * (motion_steps - 1);
|
|
|
|
float3 *vert_steps = attr->data_float3();
|
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
for(size_t i = 0; i < steps_size; i++)
|
2014-03-29 12:03:46 +00:00
|
|
|
bnds.grow(vert_steps[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
Attribute *curve_attr = curve_attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
|
2014-03-29 12:03:47 +00:00
|
|
|
if(use_motion_blur && curve_attr) {
|
2014-03-29 12:03:46 +00:00
|
|
|
size_t steps_size = curve_keys.size() * (motion_steps - 1);
|
|
|
|
float3 *key_steps = curve_attr->data_float3();
|
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
for(size_t i = 0; i < steps_size; i++)
|
2014-03-29 12:03:46 +00:00
|
|
|
bnds.grow(key_steps[i]);
|
|
|
|
}
|
2012-12-28 14:21:30 +00:00
|
|
|
|
2013-04-09 20:48:53 +00:00
|
|
|
if(!bnds.valid()) {
|
|
|
|
bnds = BoundBox::empty;
|
|
|
|
|
|
|
|
/* skip nan or inf coordinates */
|
|
|
|
for(size_t i = 0; i < verts_size; i++)
|
|
|
|
bnds.grow_safe(verts[i]);
|
|
|
|
|
|
|
|
for(size_t i = 0; i < curve_keys_size; i++)
|
2016-05-07 22:09:08 +00:00
|
|
|
bnds.grow_safe(curve_keys[i], curve_radius[i]);
|
2014-03-29 12:03:46 +00:00
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
if(use_motion_blur && attr) {
|
2014-03-29 12:03:46 +00:00
|
|
|
size_t steps_size = verts.size() * (motion_steps - 1);
|
|
|
|
float3 *vert_steps = attr->data_float3();
|
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
for(size_t i = 0; i < steps_size; i++)
|
2014-03-29 12:03:46 +00:00
|
|
|
bnds.grow_safe(vert_steps[i]);
|
|
|
|
}
|
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
if(use_motion_blur && curve_attr) {
|
2014-03-29 12:03:46 +00:00
|
|
|
size_t steps_size = curve_keys.size() * (motion_steps - 1);
|
|
|
|
float3 *key_steps = curve_attr->data_float3();
|
|
|
|
|
2015-03-27 19:15:15 +00:00
|
|
|
for(size_t i = 0; i < steps_size; i++)
|
2014-03-29 12:03:46 +00:00
|
|
|
bnds.grow_safe(key_steps[i]);
|
|
|
|
}
|
2013-04-09 20:48:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(!bnds.valid()) {
|
|
|
|
/* empty mesh */
|
2011-04-27 11:58:34 +00:00
|
|
|
bnds.grow(make_float3(0.0f, 0.0f, 0.0f));
|
2013-04-09 20:48:53 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
bounds = bnds;
|
|
|
|
}
|
|
|
|
|
2014-03-29 12:03:46 +00:00
|
|
|
static float3 compute_face_normal(const Mesh::Triangle& t, float3 *verts)
|
|
|
|
{
|
|
|
|
float3 v0 = verts[t.v[0]];
|
|
|
|
float3 v1 = verts[t.v[1]];
|
|
|
|
float3 v2 = verts[t.v[2]];
|
|
|
|
|
|
|
|
float3 norm = cross(v1 - v0, v2 - v0);
|
|
|
|
float normlen = len(norm);
|
|
|
|
|
|
|
|
if(normlen == 0.0f)
|
2016-05-23 11:27:46 +00:00
|
|
|
return make_float3(1.0f, 0.0f, 0.0f);
|
2014-03-29 12:03:46 +00:00
|
|
|
|
|
|
|
return norm / normlen;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void Mesh::add_face_normals()
|
|
|
|
{
|
|
|
|
/* don't compute if already there */
|
2012-04-30 12:49:26 +00:00
|
|
|
if(attributes.find(ATTR_STD_FACE_NORMAL))
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
2013-01-15 16:35:05 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* get attributes */
|
2012-04-30 12:49:26 +00:00
|
|
|
Attribute *attr_fN = attributes.add(ATTR_STD_FACE_NORMAL);
|
2011-04-27 11:58:34 +00:00
|
|
|
float3 *fN = attr_fN->data_float3();
|
|
|
|
|
|
|
|
/* compute face normals */
|
2016-05-07 22:09:08 +00:00
|
|
|
size_t triangles_size = num_triangles();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2011-10-03 15:31:45 +00:00
|
|
|
if(triangles_size) {
|
2016-08-17 21:49:55 +00:00
|
|
|
float3 *verts_ptr = verts.data();
|
2011-10-03 15:31:45 +00:00
|
|
|
|
|
|
|
for(size_t i = 0; i < triangles_size; i++) {
|
2016-05-07 22:09:08 +00:00
|
|
|
fN[i] = compute_face_normal(get_triangle(i), verts_ptr);
|
2011-10-03 15:31:45 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2013-01-15 16:35:05 +00:00
|
|
|
|
|
|
|
/* expected to be in local space */
|
|
|
|
if(transform_applied) {
|
|
|
|
Transform ntfm = transform_inverse(transform_normal);
|
|
|
|
|
|
|
|
for(size_t i = 0; i < triangles_size; i++)
|
|
|
|
fN[i] = normalize(transform_direction(&ntfm, fN[i]));
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mesh::add_vertex_normals()
|
|
|
|
{
|
2014-03-29 12:03:46 +00:00
|
|
|
bool flip = transform_negative_scaled;
|
|
|
|
size_t verts_size = verts.size();
|
2016-05-07 22:09:08 +00:00
|
|
|
size_t triangles_size = num_triangles();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-03-29 12:03:46 +00:00
|
|
|
/* static vertex normals */
|
2016-08-23 17:57:45 +00:00
|
|
|
if(!attributes.find(ATTR_STD_VERTEX_NORMAL) && triangles_size) {
|
2014-03-29 12:03:46 +00:00
|
|
|
/* get attributes */
|
|
|
|
Attribute *attr_fN = attributes.find(ATTR_STD_FACE_NORMAL);
|
|
|
|
Attribute *attr_vN = attributes.add(ATTR_STD_VERTEX_NORMAL);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-03-29 12:03:46 +00:00
|
|
|
float3 *fN = attr_fN->data_float3();
|
|
|
|
float3 *vN = attr_vN->data_float3();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-03-29 12:03:46 +00:00
|
|
|
/* compute vertex normals */
|
|
|
|
memset(vN, 0, verts.size()*sizeof(float3));
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-08-25 14:45:48 +00:00
|
|
|
for(size_t i = 0; i < triangles_size; i++) {
|
|
|
|
for(size_t j = 0; j < 3; j++) {
|
|
|
|
vN[get_triangle(i).v[j]] += fN[i];
|
|
|
|
}
|
2014-03-29 12:03:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for(size_t i = 0; i < verts_size; i++) {
|
|
|
|
vN[i] = normalize(vN[i]);
|
2016-08-25 14:45:48 +00:00
|
|
|
if(flip) {
|
2014-03-29 12:03:46 +00:00
|
|
|
vN[i] = -vN[i];
|
2016-08-25 14:45:48 +00:00
|
|
|
}
|
2014-03-29 12:03:46 +00:00
|
|
|
}
|
2011-10-03 15:31:45 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-03-29 12:03:46 +00:00
|
|
|
/* motion vertex normals */
|
|
|
|
Attribute *attr_mP = attributes.find(ATTR_STD_MOTION_VERTEX_POSITION);
|
|
|
|
Attribute *attr_mN = attributes.find(ATTR_STD_MOTION_VERTEX_NORMAL);
|
|
|
|
|
2016-08-23 17:57:45 +00:00
|
|
|
if(has_motion_blur() && attr_mP && !attr_mN && triangles_size) {
|
2014-03-29 12:03:46 +00:00
|
|
|
/* create attribute */
|
|
|
|
attr_mN = attributes.add(ATTR_STD_MOTION_VERTEX_NORMAL);
|
|
|
|
|
|
|
|
for(int step = 0; step < motion_steps - 1; step++) {
|
|
|
|
float3 *mP = attr_mP->data_float3() + step*verts.size();
|
|
|
|
float3 *mN = attr_mN->data_float3() + step*verts.size();
|
|
|
|
|
|
|
|
/* compute */
|
|
|
|
memset(mN, 0, verts.size()*sizeof(float3));
|
|
|
|
|
2016-08-25 14:45:48 +00:00
|
|
|
for(size_t i = 0; i < triangles_size; i++) {
|
|
|
|
for(size_t j = 0; j < 3; j++) {
|
|
|
|
float3 fN = compute_face_normal(get_triangle(i), mP);
|
|
|
|
mN[get_triangle(i).v[j]] += fN;
|
2014-03-29 12:03:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(size_t i = 0; i < verts_size; i++) {
|
|
|
|
mN[i] = normalize(mN[i]);
|
2016-08-25 14:45:48 +00:00
|
|
|
if(flip) {
|
2014-03-29 12:03:46 +00:00
|
|
|
mN[i] = -mN[i];
|
2016-08-25 14:45:48 +00:00
|
|
|
}
|
2014-03-29 12:03:46 +00:00
|
|
|
}
|
|
|
|
}
|
2011-11-12 14:29:52 +00:00
|
|
|
}
|
2016-08-23 17:57:45 +00:00
|
|
|
|
|
|
|
/* subd vertex normals */
|
|
|
|
if(!subd_attributes.find(ATTR_STD_VERTEX_NORMAL) && subd_faces.size()) {
|
|
|
|
/* get attributes */
|
|
|
|
Attribute *attr_vN = subd_attributes.add(ATTR_STD_VERTEX_NORMAL);
|
|
|
|
float3 *vN = attr_vN->data_float3();
|
|
|
|
|
|
|
|
/* compute vertex normals */
|
|
|
|
memset(vN, 0, verts.size()*sizeof(float3));
|
|
|
|
|
|
|
|
for(size_t i = 0; i < subd_faces.size(); i++) {
|
|
|
|
SubdFace& face = subd_faces[i];
|
2016-08-30 16:22:50 +00:00
|
|
|
float3 fN = face.normal(this);
|
2016-08-23 17:57:45 +00:00
|
|
|
|
|
|
|
for(size_t j = 0; j < face.num_corners; j++) {
|
|
|
|
size_t corner = subd_face_corners[face.start_corner+j];
|
2016-08-30 16:22:50 +00:00
|
|
|
vN[corner] += fN;
|
2016-08-23 17:57:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(size_t i = 0; i < verts_size; i++) {
|
|
|
|
vN[i] = normalize(vN[i]);
|
|
|
|
if(flip) {
|
|
|
|
vN[i] = -vN[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2016-08-13 16:27:17 +00:00
|
|
|
void Mesh::add_undisplaced()
|
|
|
|
{
|
|
|
|
AttributeSet& attrs = (subdivision_type == SUBDIVISION_NONE) ? attributes : subd_attributes;
|
|
|
|
|
|
|
|
/* don't compute if already there */
|
|
|
|
if(attrs.find(ATTR_STD_POSITION_UNDISPLACED)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* get attribute */
|
|
|
|
Attribute *attr = attrs.add(ATTR_STD_POSITION_UNDISPLACED);
|
|
|
|
attr->flags |= ATTR_SUBDIVIDED;
|
|
|
|
|
|
|
|
float3 *data = attr->data_float3();
|
|
|
|
|
|
|
|
/* copy verts */
|
|
|
|
size_t size = attr->buffer_size(this, (subdivision_type == SUBDIVISION_NONE) ? ATTR_PRIM_TRIANGLE : ATTR_PRIM_SUBD);
|
2016-09-22 21:34:14 +00:00
|
|
|
|
|
|
|
/* Center points for ngons aren't stored in Mesh::verts but are included in size since they will be
|
|
|
|
* calculated later, we subtract them from size here so we don't have an overflow while copying.
|
|
|
|
*/
|
|
|
|
size -= num_ngons * attr->data_sizeof();
|
|
|
|
|
2016-08-13 16:27:17 +00:00
|
|
|
if(size) {
|
|
|
|
memcpy(data, verts.data(), size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-24 11:34:28 +00:00
|
|
|
void Mesh::pack_normals(Scene *scene, uint *tri_shader, float4 *vnormal)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-04-30 12:49:26 +00:00
|
|
|
Attribute *attr_vN = attributes.find(ATTR_STD_VERTEX_NORMAL);
|
2016-08-25 09:31:36 +00:00
|
|
|
if(attr_vN == NULL) {
|
|
|
|
/* Happens on objects with just hair. */
|
|
|
|
return;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
float3 *vN = attr_vN->data_float3();
|
2014-09-24 11:34:28 +00:00
|
|
|
uint shader_id = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
uint last_shader = -1;
|
|
|
|
bool last_smooth = false;
|
|
|
|
|
2016-05-07 22:09:08 +00:00
|
|
|
size_t triangles_size = num_triangles();
|
2016-08-17 21:49:55 +00:00
|
|
|
int *shader_ptr = shader.data();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-01-15 16:35:05 +00:00
|
|
|
bool do_transform = transform_applied;
|
|
|
|
Transform ntfm = transform_normal;
|
|
|
|
|
2014-06-13 19:27:21 +00:00
|
|
|
/* save shader */
|
2011-04-27 11:58:34 +00:00
|
|
|
for(size_t i = 0; i < triangles_size; i++) {
|
|
|
|
if(shader_ptr[i] != last_shader || last_smooth != smooth[i]) {
|
|
|
|
last_shader = shader_ptr[i];
|
|
|
|
last_smooth = smooth[i];
|
2016-05-14 12:50:03 +00:00
|
|
|
Shader *shader = (last_shader < used_shaders.size()) ?
|
|
|
|
used_shaders[last_shader] : scene->default_surface;
|
2016-08-16 23:42:08 +00:00
|
|
|
shader_id = scene->shader_manager->get_shader_id(shader, last_smooth);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 11:34:28 +00:00
|
|
|
tri_shader[i] = shader_id;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t verts_size = verts.size();
|
|
|
|
|
2013-01-15 16:35:05 +00:00
|
|
|
for(size_t i = 0; i < verts_size; i++) {
|
|
|
|
float3 vNi = vN[i];
|
|
|
|
|
|
|
|
if(do_transform)
|
|
|
|
vNi = normalize(transform_direction(&ntfm, vNi));
|
|
|
|
|
|
|
|
vnormal[i] = make_float4(vNi.x, vNi.y, vNi.z, 0.0f);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
void Mesh::pack_verts(const vector<uint>& tri_prim_index,
|
|
|
|
uint4 *tri_vindex,
|
2016-07-16 23:42:28 +00:00
|
|
|
uint *tri_patch,
|
|
|
|
float2 *tri_patch_uv,
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
size_t vert_offset,
|
|
|
|
size_t tri_offset)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-07-16 23:42:28 +00:00
|
|
|
size_t verts_size = verts.size();
|
|
|
|
|
|
|
|
if(verts_size && subd_faces.size()) {
|
2016-08-17 21:49:55 +00:00
|
|
|
float2 *vert_patch_uv_ptr = vert_patch_uv.data();
|
2016-07-16 23:42:28 +00:00
|
|
|
|
|
|
|
for(size_t i = 0; i < verts_size; i++) {
|
|
|
|
tri_patch_uv[i] = vert_patch_uv_ptr[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t triangles_size = num_triangles();
|
|
|
|
|
2016-08-25 14:45:48 +00:00
|
|
|
for(size_t i = 0; i < triangles_size; i++) {
|
|
|
|
Triangle t = get_triangle(i);
|
|
|
|
tri_vindex[i] = make_uint4(t.v[0] + vert_offset,
|
|
|
|
t.v[1] + vert_offset,
|
|
|
|
t.v[2] + vert_offset,
|
|
|
|
tri_prim_index[i + tri_offset]);
|
2016-07-16 23:42:28 +00:00
|
|
|
|
2016-08-25 14:45:48 +00:00
|
|
|
tri_patch[i] = (!subd_faces.size()) ? -1 : (triangle_patch[i]*8 + patch_offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-03 12:09:09 +00:00
|
|
|
void Mesh::pack_curves(Scene *scene, float4 *curve_key_co, float4 *curve_data, size_t curvekey_offset)
|
2012-12-28 14:21:30 +00:00
|
|
|
{
|
|
|
|
size_t curve_keys_size = curve_keys.size();
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
/* pack curve keys */
|
2012-12-28 14:21:30 +00:00
|
|
|
if(curve_keys_size) {
|
2016-08-17 21:49:55 +00:00
|
|
|
float3 *keys_ptr = curve_keys.data();
|
|
|
|
float *radius_ptr = curve_radius.data();
|
2012-12-28 14:21:30 +00:00
|
|
|
|
2014-03-29 12:03:46 +00:00
|
|
|
for(size_t i = 0; i < curve_keys_size; i++)
|
2016-05-07 22:09:08 +00:00
|
|
|
curve_key_co[i] = make_float4(keys_ptr[i].x, keys_ptr[i].y, keys_ptr[i].z, radius_ptr[i]);
|
2012-12-28 14:21:30 +00:00
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
/* pack curve segments */
|
2016-05-07 22:09:08 +00:00
|
|
|
size_t curve_num = num_curves();
|
2012-12-28 14:21:30 +00:00
|
|
|
|
2016-08-25 14:45:48 +00:00
|
|
|
for(size_t i = 0; i < curve_num; i++) {
|
|
|
|
Curve curve = get_curve(i);
|
|
|
|
int shader_id = curve_shader[i];
|
|
|
|
Shader *shader = (shader_id < used_shaders.size()) ?
|
|
|
|
used_shaders[shader_id] : scene->default_surface;
|
2016-08-16 23:42:08 +00:00
|
|
|
shader_id = scene->shader_manager->get_shader_id(shader, false);
|
2016-08-25 14:45:48 +00:00
|
|
|
|
|
|
|
curve_data[i] = make_float4(
|
|
|
|
__int_as_float(curve.first_key + curvekey_offset),
|
|
|
|
__int_as_float(curve.num_keys),
|
|
|
|
__int_as_float(shader_id),
|
|
|
|
0.0f);
|
2012-12-28 14:21:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
void Mesh::pack_patches(uint *patch_data, uint vert_offset, uint face_offset, uint corner_offset)
|
|
|
|
{
|
|
|
|
size_t num_faces = subd_faces.size();
|
|
|
|
int ngons = 0;
|
|
|
|
|
2016-08-25 14:45:48 +00:00
|
|
|
for(size_t f = 0; f < num_faces; f++) {
|
|
|
|
SubdFace face = subd_faces[f];
|
|
|
|
|
|
|
|
if(face.is_quad()) {
|
|
|
|
int c[4];
|
|
|
|
memcpy(c, &subd_face_corners[face.start_corner], sizeof(int)*4);
|
2016-07-16 23:42:28 +00:00
|
|
|
|
2016-08-25 14:45:48 +00:00
|
|
|
*(patch_data++) = c[0] + vert_offset;
|
|
|
|
*(patch_data++) = c[1] + vert_offset;
|
|
|
|
*(patch_data++) = c[2] + vert_offset;
|
|
|
|
*(patch_data++) = c[3] + vert_offset;
|
|
|
|
|
|
|
|
*(patch_data++) = f+face_offset;
|
|
|
|
*(patch_data++) = face.num_corners;
|
|
|
|
*(patch_data++) = face.start_corner + corner_offset;
|
|
|
|
*(patch_data++) = 0;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
for(int i = 0; i < face.num_corners; i++) {
|
2016-07-16 23:42:28 +00:00
|
|
|
int c[4];
|
2016-08-25 14:45:48 +00:00
|
|
|
c[0] = subd_face_corners[face.start_corner + mod(i + 0, face.num_corners)];
|
|
|
|
c[1] = subd_face_corners[face.start_corner + mod(i + 1, face.num_corners)];
|
|
|
|
c[2] = verts.size() - num_subd_verts + ngons;
|
|
|
|
c[3] = subd_face_corners[face.start_corner + mod(i - 1, face.num_corners)];
|
2016-07-16 23:42:28 +00:00
|
|
|
|
|
|
|
*(patch_data++) = c[0] + vert_offset;
|
|
|
|
*(patch_data++) = c[1] + vert_offset;
|
|
|
|
*(patch_data++) = c[2] + vert_offset;
|
|
|
|
*(patch_data++) = c[3] + vert_offset;
|
|
|
|
|
|
|
|
*(patch_data++) = f+face_offset;
|
2016-08-25 14:45:48 +00:00
|
|
|
*(patch_data++) = face.num_corners | (i << 16);
|
2016-07-16 23:42:28 +00:00
|
|
|
*(patch_data++) = face.start_corner + corner_offset;
|
2016-08-25 14:45:48 +00:00
|
|
|
*(patch_data++) = subd_face_corners.size() + ngons + corner_offset;
|
2016-07-16 23:42:28 +00:00
|
|
|
}
|
|
|
|
|
2016-08-25 14:45:48 +00:00
|
|
|
ngons++;
|
2016-07-16 23:42:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Cycles: Enable unaligned BVH builder for scenes with hair
This commit enables new unaligned BVH builder and traversal for scenes
with hair. This happens automatically, no need of manual control over
this.
There are some possible optimization still to happen here and there,
but overall there's already nice speedup:
Master Hair BVH
bunny.blend 8:06.54 5:57.14
victor.blend 16:07.44 15:37.35
Unfortunately, such more complexity is not really coming for free,
so there's some downsides, but those are within acceptable range:
Master Hair BVH
classroom.blend 5:31.79 5:35.11
barcelona.blend 4:38.58 4:44.51
Memory usage is also somewhat bigger for hairy scenes, but speed
benefit pays well for that. Additionally as was mentioned in one
of previous commits we can add an option to disable hair BVH and
have similar render time but have memory saving.
Reviewers: brecht, dingto, lukasstockner97, juicyfruit, maiself
Differential Revision: https://developer.blender.org/D2086
2016-07-07 10:41:45 +00:00
|
|
|
void Mesh::compute_bvh(DeviceScene *dscene,
|
2016-07-07 10:18:57 +00:00
|
|
|
SceneParams *params,
|
|
|
|
Progress *progress,
|
|
|
|
int n,
|
|
|
|
int total)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2012-05-05 19:44:33 +00:00
|
|
|
if(progress->get_cancel())
|
|
|
|
return;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-05-05 19:44:33 +00:00
|
|
|
compute_bounds();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-02-25 14:12:11 +00:00
|
|
|
if(need_build_bvh()) {
|
2012-05-05 19:44:33 +00:00
|
|
|
string msg = "Updating Mesh BVH ";
|
|
|
|
if(name == "")
|
|
|
|
msg += string_printf("%u/%u", (uint)(n+1), (uint)total);
|
|
|
|
else
|
|
|
|
msg += string_printf("%s %u/%u", name.c_str(), (uint)(n+1), (uint)total);
|
|
|
|
|
|
|
|
Object object;
|
|
|
|
object.mesh = this;
|
|
|
|
|
|
|
|
vector<Object*> objects;
|
|
|
|
objects.push_back(&object);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-05-05 19:44:33 +00:00
|
|
|
if(bvh && !need_update_rebuild) {
|
|
|
|
progress->set_status(msg, "Refitting BVH");
|
|
|
|
bvh->objects = objects;
|
|
|
|
bvh->refit(*progress);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
progress->set_status(msg, "Building BVH");
|
|
|
|
|
|
|
|
BVHParams bparams;
|
|
|
|
bparams.use_spatial_split = params->use_bvh_spatial_split;
|
|
|
|
bparams.use_qbvh = params->use_qbvh;
|
2016-07-07 16:04:16 +00:00
|
|
|
bparams.use_unaligned_nodes = dscene->data.bvh.have_curves &&
|
|
|
|
params->use_bvh_unaligned_nodes;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-05-05 19:44:33 +00:00
|
|
|
delete bvh;
|
|
|
|
bvh = BVH::create(bparams, objects);
|
Cycles: Stop rendering when bad_alloc happens
This is an attempt to gracefully handle out-of-memory events
and stop rendering with an error message instead of a crash.
It uses bad_alloc exception, and usually i'm not really fond
of exceptions, but for such limited use for errors from which
we can't recover it should be fine.
Ideally we'll need to stop full Cycles Session, so viewport
render and persistent images frees all the memory, but that
we can support later, since it'll mainly related on telling
Blender what to do.
General rules are:
- Use as less exception handles as possible, try to find a
most geenric pace where to handle those.
For example, ccl::Session.
- Threads needs own handling, exception trap from one thread
will not catch exceptions from other threads.
That's why BVH build needs own thing.
Reviewers: brecht, juicyfruit, dingto, lukasstockner97
Differential Revision: https://developer.blender.org/D1898
2016-04-20 14:15:11 +00:00
|
|
|
MEM_GUARDED_CALL(progress, bvh->build, *progress);
|
2012-05-05 19:44:33 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2012-05-05 19:44:33 +00:00
|
|
|
|
|
|
|
need_update = false;
|
|
|
|
need_update_rebuild = false;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Mesh::tag_update(Scene *scene, bool rebuild)
|
|
|
|
{
|
|
|
|
need_update = true;
|
2011-12-08 21:55:35 +00:00
|
|
|
|
|
|
|
if(rebuild) {
|
2011-04-27 11:58:34 +00:00
|
|
|
need_update_rebuild = true;
|
2011-12-08 21:55:35 +00:00
|
|
|
scene->light_manager->need_update = true;
|
|
|
|
}
|
|
|
|
else {
|
2016-05-14 12:50:03 +00:00
|
|
|
foreach(Shader *shader, used_shaders)
|
|
|
|
if(shader->has_surface_emission)
|
2011-12-08 21:55:35 +00:00
|
|
|
scene->light_manager->need_update = true;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
scene->mesh_manager->need_update = true;
|
|
|
|
scene->object_manager->need_update = true;
|
|
|
|
}
|
|
|
|
|
2014-03-29 12:03:47 +00:00
|
|
|
bool Mesh::has_motion_blur() const
|
|
|
|
{
|
2014-03-29 12:03:47 +00:00
|
|
|
return (use_motion_blur &&
|
|
|
|
(attributes.find(ATTR_STD_MOTION_VERTEX_POSITION) ||
|
2014-05-04 16:19:08 +00:00
|
|
|
curve_attributes.find(ATTR_STD_MOTION_VERTEX_POSITION)));
|
2014-03-29 12:03:47 +00:00
|
|
|
}
|
|
|
|
|
2016-08-02 09:13:58 +00:00
|
|
|
bool Mesh::has_true_displacement() const
|
|
|
|
{
|
|
|
|
foreach(Shader *shader, used_shaders) {
|
|
|
|
if(shader->has_displacement && shader->displacement_method != DISPLACE_BUMP) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-25 14:12:11 +00:00
|
|
|
bool Mesh::need_build_bvh() const
|
|
|
|
{
|
|
|
|
return !transform_applied || has_surface_bssrdf;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Mesh::is_instanced() const
|
|
|
|
{
|
|
|
|
/* Currently we treat subsurface objects as instanced.
|
|
|
|
*
|
|
|
|
* While it might be not very optimal for ray traversal, it avoids having
|
|
|
|
* duplicated BVH in the memory, saving quite some space.
|
|
|
|
*/
|
|
|
|
return !transform_applied || has_surface_bssrdf;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Mesh Manager */
|
|
|
|
|
|
|
|
MeshManager::MeshManager()
|
|
|
|
{
|
|
|
|
bvh = NULL;
|
|
|
|
need_update = true;
|
2015-01-19 14:08:58 +00:00
|
|
|
need_flags_update = true;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
MeshManager::~MeshManager()
|
|
|
|
{
|
|
|
|
delete bvh;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MeshManager::update_osl_attributes(Device *device, Scene *scene, vector<AttributeRequestSet>& mesh_attributes)
|
|
|
|
{
|
|
|
|
#ifdef WITH_OSL
|
|
|
|
/* for OSL, a hash map is used to lookup the attribute by name. */
|
|
|
|
OSLGlobals *og = (OSLGlobals*)device->osl_memory();
|
|
|
|
|
|
|
|
og->object_name_map.clear();
|
|
|
|
og->attribute_map.clear();
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
og->object_names.clear();
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
og->attribute_map.resize(scene->objects.size()*ATTR_PRIM_TYPES);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
for(size_t i = 0; i < scene->objects.size(); i++) {
|
|
|
|
/* set object name to object index map */
|
|
|
|
Object *object = scene->objects[i];
|
|
|
|
og->object_name_map[object->name] = i;
|
Cycles OSL: support for the trace(point pos, vector dir, ...) function, to trace
rays from the OSL shader. The "shade" parameter is not supported currently, but
attributes can be retrieved from the object that was hit using the
getmessage("trace", ..) function.
As mentioned in the OSL specification, this function can't be used instead of
lighting, the main purpose is to allow shaders to "probe" nearby geometry, for
example to apply a projected texture that can be blocked by geometry, apply
more “wear” to exposed geometry, or make other ambient occlusion-like effects.
http://wiki.blender.org/index.php/Doc:2.6/Manual/Render/Cycles/Nodes/OSL#Trace
Example .blend and render:
http://www.pasteall.org/blend/17347
http://www.pasteall.org/pic/show.php?id=40066
2012-11-06 19:59:10 +00:00
|
|
|
og->object_names.push_back(object->name);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* set object attributes */
|
|
|
|
foreach(ParamValue& attr, object->attributes) {
|
|
|
|
OSLGlobals::Attribute osl_attr;
|
|
|
|
|
|
|
|
osl_attr.type = attr.type();
|
2016-07-01 21:36:27 +00:00
|
|
|
osl_attr.desc.element = ATTR_ELEMENT_OBJECT;
|
2011-04-27 11:58:34 +00:00
|
|
|
osl_attr.value = attr;
|
2016-07-01 21:36:27 +00:00
|
|
|
osl_attr.desc.offset = 0;
|
2016-07-17 02:57:06 +00:00
|
|
|
osl_attr.desc.flags = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_TRIANGLE][attr.name()] = osl_attr;
|
2013-01-03 12:08:54 +00:00
|
|
|
og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_CURVE][attr.name()] = osl_attr;
|
2016-07-16 23:42:28 +00:00
|
|
|
og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_SUBD][attr.name()] = osl_attr;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* find mesh attributes */
|
|
|
|
size_t j;
|
|
|
|
|
|
|
|
for(j = 0; j < scene->meshes.size(); j++)
|
|
|
|
if(scene->meshes[j] == object->mesh)
|
|
|
|
break;
|
|
|
|
|
|
|
|
AttributeRequestSet& attributes = mesh_attributes[j];
|
|
|
|
|
|
|
|
/* set object attributes */
|
|
|
|
foreach(AttributeRequest& req, attributes.requests) {
|
|
|
|
OSLGlobals::Attribute osl_attr;
|
|
|
|
|
2016-07-01 21:36:27 +00:00
|
|
|
if(req.triangle_desc.element != ATTR_ELEMENT_NONE) {
|
|
|
|
osl_attr.desc = req.triangle_desc;
|
2013-01-03 12:08:54 +00:00
|
|
|
|
|
|
|
if(req.triangle_type == TypeDesc::TypeFloat)
|
|
|
|
osl_attr.type = TypeDesc::TypeFloat;
|
2013-12-31 16:33:55 +00:00
|
|
|
else if(req.triangle_type == TypeDesc::TypeMatrix)
|
|
|
|
osl_attr.type = TypeDesc::TypeMatrix;
|
2013-01-03 12:08:54 +00:00
|
|
|
else
|
|
|
|
osl_attr.type = TypeDesc::TypeColor;
|
|
|
|
|
|
|
|
if(req.std != ATTR_STD_NONE) {
|
|
|
|
/* if standard attribute, add lookup by geom: name convention */
|
|
|
|
ustring stdname(string("geom:") + string(Attribute::standard_name(req.std)));
|
2016-07-16 23:42:28 +00:00
|
|
|
og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_TRIANGLE][stdname] = osl_attr;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
else if(req.name != ustring()) {
|
|
|
|
/* add lookup by mesh attribute name */
|
2016-07-16 23:42:28 +00:00
|
|
|
og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_TRIANGLE][req.name] = osl_attr;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2016-07-01 21:36:27 +00:00
|
|
|
if(req.curve_desc.element != ATTR_ELEMENT_NONE) {
|
|
|
|
osl_attr.desc = req.curve_desc;
|
2013-01-03 12:08:54 +00:00
|
|
|
|
|
|
|
if(req.curve_type == TypeDesc::TypeFloat)
|
|
|
|
osl_attr.type = TypeDesc::TypeFloat;
|
2013-12-31 16:33:55 +00:00
|
|
|
else if(req.curve_type == TypeDesc::TypeMatrix)
|
|
|
|
osl_attr.type = TypeDesc::TypeMatrix;
|
2013-01-03 12:08:54 +00:00
|
|
|
else
|
|
|
|
osl_attr.type = TypeDesc::TypeColor;
|
|
|
|
|
|
|
|
if(req.std != ATTR_STD_NONE) {
|
|
|
|
/* if standard attribute, add lookup by geom: name convention */
|
|
|
|
ustring stdname(string("geom:") + string(Attribute::standard_name(req.std)));
|
|
|
|
og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_CURVE][stdname] = osl_attr;
|
|
|
|
}
|
|
|
|
else if(req.name != ustring()) {
|
|
|
|
/* add lookup by mesh attribute name */
|
|
|
|
og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_CURVE][req.name] = osl_attr;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2016-07-16 23:42:28 +00:00
|
|
|
|
2016-07-01 21:36:27 +00:00
|
|
|
if(req.subd_desc.element != ATTR_ELEMENT_NONE) {
|
|
|
|
osl_attr.desc = req.subd_desc;
|
2016-07-16 23:42:28 +00:00
|
|
|
|
|
|
|
if(req.subd_type == TypeDesc::TypeFloat)
|
|
|
|
osl_attr.type = TypeDesc::TypeFloat;
|
|
|
|
else if(req.subd_type == TypeDesc::TypeMatrix)
|
|
|
|
osl_attr.type = TypeDesc::TypeMatrix;
|
|
|
|
else
|
|
|
|
osl_attr.type = TypeDesc::TypeColor;
|
|
|
|
|
|
|
|
if(req.std != ATTR_STD_NONE) {
|
|
|
|
/* if standard attribute, add lookup by geom: name convention */
|
|
|
|
ustring stdname(string("geom:") + string(Attribute::standard_name(req.std)));
|
|
|
|
og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_SUBD][stdname] = osl_attr;
|
|
|
|
}
|
|
|
|
else if(req.name != ustring()) {
|
|
|
|
/* add lookup by mesh attribute name */
|
|
|
|
og->attribute_map[i*ATTR_PRIM_TYPES + ATTR_PRIM_SUBD][req.name] = osl_attr;
|
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
2015-03-27 14:09:41 +00:00
|
|
|
#else
|
|
|
|
(void)device;
|
|
|
|
(void)scene;
|
|
|
|
(void)mesh_attributes;
|
2011-04-27 11:58:34 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void MeshManager::update_svm_attributes(Device *device, DeviceScene *dscene, Scene *scene, vector<AttributeRequestSet>& mesh_attributes)
|
|
|
|
{
|
|
|
|
/* for SVM, the attributes_map table is used to lookup the offset of an
|
|
|
|
* attribute, based on a unique shader attribute id. */
|
|
|
|
|
|
|
|
/* compute array stride */
|
|
|
|
int attr_map_stride = 0;
|
|
|
|
|
|
|
|
for(size_t i = 0; i < scene->meshes.size(); i++)
|
2013-01-03 12:08:54 +00:00
|
|
|
attr_map_stride = max(attr_map_stride, (mesh_attributes[i].size() + 1)*ATTR_PRIM_TYPES);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if(attr_map_stride == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* create attribute map */
|
|
|
|
uint4 *attr_map = dscene->attributes_map.resize(attr_map_stride*scene->objects.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];
|
2013-01-03 12:08:54 +00:00
|
|
|
Mesh *mesh = object->mesh;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
/* find mesh attributes */
|
|
|
|
size_t j;
|
|
|
|
|
|
|
|
for(j = 0; j < scene->meshes.size(); j++)
|
2013-01-03 12:08:54 +00:00
|
|
|
if(scene->meshes[j] == mesh)
|
2011-04-27 11:58:34 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
AttributeRequestSet& attributes = mesh_attributes[j];
|
|
|
|
|
|
|
|
/* set object attributes */
|
2012-04-30 12:49:26 +00:00
|
|
|
int index = i*attr_map_stride;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
foreach(AttributeRequest& req, attributes.requests) {
|
|
|
|
uint id;
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
if(req.std == ATTR_STD_NONE)
|
2011-04-27 11:58:34 +00:00
|
|
|
id = scene->shader_manager->get_attribute_id(req.name);
|
|
|
|
else
|
|
|
|
id = scene->shader_manager->get_attribute_id(req.std);
|
|
|
|
|
2016-05-07 22:09:08 +00:00
|
|
|
if(mesh->num_triangles()) {
|
2013-01-03 12:08:54 +00:00
|
|
|
attr_map[index].x = id;
|
2016-07-01 21:36:27 +00:00
|
|
|
attr_map[index].y = req.triangle_desc.element;
|
|
|
|
attr_map[index].z = as_uint(req.triangle_desc.offset);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
if(req.triangle_type == TypeDesc::TypeFloat)
|
|
|
|
attr_map[index].w = NODE_ATTR_FLOAT;
|
2013-12-31 16:33:55 +00:00
|
|
|
else if(req.triangle_type == TypeDesc::TypeMatrix)
|
|
|
|
attr_map[index].w = NODE_ATTR_MATRIX;
|
2013-01-03 12:08:54 +00:00
|
|
|
else
|
|
|
|
attr_map[index].w = NODE_ATTR_FLOAT3;
|
2016-07-17 02:57:06 +00:00
|
|
|
|
|
|
|
attr_map[index].w |= req.triangle_desc.flags << 8;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
index++;
|
|
|
|
|
2016-05-07 22:09:08 +00:00
|
|
|
if(mesh->num_curves()) {
|
2013-01-03 12:08:54 +00:00
|
|
|
attr_map[index].x = id;
|
2016-07-01 21:36:27 +00:00
|
|
|
attr_map[index].y = req.curve_desc.element;
|
|
|
|
attr_map[index].z = as_uint(req.curve_desc.offset);
|
2013-01-03 12:08:54 +00:00
|
|
|
|
|
|
|
if(req.curve_type == TypeDesc::TypeFloat)
|
|
|
|
attr_map[index].w = NODE_ATTR_FLOAT;
|
2013-12-31 16:33:55 +00:00
|
|
|
else if(req.curve_type == TypeDesc::TypeMatrix)
|
|
|
|
attr_map[index].w = NODE_ATTR_MATRIX;
|
2013-01-03 12:08:54 +00:00
|
|
|
else
|
|
|
|
attr_map[index].w = NODE_ATTR_FLOAT3;
|
2016-07-17 02:57:06 +00:00
|
|
|
|
|
|
|
attr_map[index].w |= req.curve_desc.flags << 8;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
index++;
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
if(mesh->subd_faces.size()) {
|
|
|
|
attr_map[index].x = id;
|
2016-07-01 21:36:27 +00:00
|
|
|
attr_map[index].y = req.subd_desc.element;
|
|
|
|
attr_map[index].z = as_uint(req.subd_desc.offset);
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
if(req.subd_type == TypeDesc::TypeFloat)
|
|
|
|
attr_map[index].w = NODE_ATTR_FLOAT;
|
|
|
|
else if(req.subd_type == TypeDesc::TypeMatrix)
|
|
|
|
attr_map[index].w = NODE_ATTR_MATRIX;
|
|
|
|
else
|
|
|
|
attr_map[index].w = NODE_ATTR_FLOAT3;
|
2016-07-17 02:57:06 +00:00
|
|
|
|
|
|
|
attr_map[index].w |= req.subd_desc.flags << 8;
|
2016-07-16 23:42:28 +00:00
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
index++;
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
/* terminator */
|
|
|
|
for(int i = 0; i < ATTR_PRIM_TYPES; i++) {
|
|
|
|
attr_map[index].x = ATTR_STD_NONE;
|
|
|
|
attr_map[index].y = 0;
|
|
|
|
attr_map[index].z = 0;
|
|
|
|
attr_map[index].w = 0;
|
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* copy to device */
|
|
|
|
dscene->data.bvh.attributes_map_stride = attr_map_stride;
|
|
|
|
device->tex_alloc("__attributes_map", dscene->attributes_map);
|
|
|
|
}
|
|
|
|
|
2015-02-14 15:23:08 +00:00
|
|
|
static void update_attribute_element_size(Mesh *mesh,
|
|
|
|
Attribute *mattr,
|
2016-07-16 23:42:28 +00:00
|
|
|
AttributePrimitive prim,
|
2015-02-14 15:23:08 +00:00
|
|
|
size_t *attr_float_size,
|
|
|
|
size_t *attr_float3_size,
|
|
|
|
size_t *attr_uchar4_size)
|
|
|
|
{
|
|
|
|
if(mattr) {
|
2016-07-16 23:42:28 +00:00
|
|
|
size_t size = mattr->element_size(mesh, prim);
|
2015-02-14 15:23:08 +00:00
|
|
|
|
|
|
|
if(mattr->element == ATTR_ELEMENT_VOXEL) {
|
|
|
|
/* pass */
|
|
|
|
}
|
|
|
|
else if(mattr->element == ATTR_ELEMENT_CORNER_BYTE) {
|
|
|
|
*attr_uchar4_size += size;
|
|
|
|
}
|
|
|
|
else if(mattr->type == TypeDesc::TypeFloat) {
|
|
|
|
*attr_float_size += size;
|
|
|
|
}
|
|
|
|
else if(mattr->type == TypeDesc::TypeMatrix) {
|
|
|
|
*attr_float3_size += size * 4;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
*attr_float3_size += size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_attribute_element_offset(Mesh *mesh,
|
|
|
|
vector<float>& attr_float,
|
|
|
|
size_t& attr_float_offset,
|
|
|
|
vector<float4>& attr_float3,
|
|
|
|
size_t& attr_float3_offset,
|
|
|
|
vector<uchar4>& attr_uchar4,
|
|
|
|
size_t& attr_uchar4_offset,
|
|
|
|
Attribute *mattr,
|
2016-07-16 23:42:28 +00:00
|
|
|
AttributePrimitive prim,
|
2015-02-14 15:23:08 +00:00
|
|
|
TypeDesc& type,
|
2016-07-01 21:36:27 +00:00
|
|
|
AttributeDescriptor& desc)
|
2013-01-03 12:08:54 +00:00
|
|
|
{
|
|
|
|
if(mattr) {
|
|
|
|
/* store element and type */
|
2016-07-01 21:36:27 +00:00
|
|
|
desc.element = mattr->element;
|
2016-07-17 02:57:06 +00:00
|
|
|
desc.flags = mattr->flags;
|
2013-01-03 12:08:54 +00:00
|
|
|
type = mattr->type;
|
|
|
|
|
|
|
|
/* store attribute data in arrays */
|
2016-07-16 23:42:28 +00:00
|
|
|
size_t size = mattr->element_size(mesh, prim);
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2016-07-01 21:36:27 +00:00
|
|
|
AttributeElement& element = desc.element;
|
|
|
|
int& offset = desc.offset;
|
|
|
|
|
2014-03-29 12:03:48 +00:00
|
|
|
if(mattr->element == ATTR_ELEMENT_VOXEL) {
|
|
|
|
/* store slot in offset value */
|
|
|
|
VoxelAttribute *voxel_data = mattr->data_voxel();
|
|
|
|
offset = voxel_data->slot;
|
|
|
|
}
|
2014-06-27 19:19:26 +00:00
|
|
|
else if(mattr->element == ATTR_ELEMENT_CORNER_BYTE) {
|
2014-06-13 21:40:39 +00:00
|
|
|
uchar4 *data = mattr->data_uchar4();
|
2015-02-14 15:23:08 +00:00
|
|
|
offset = attr_uchar4_offset;
|
2014-06-13 21:40:39 +00:00
|
|
|
|
2015-02-14 15:23:08 +00:00
|
|
|
assert(attr_uchar4.capacity() >= offset + size);
|
|
|
|
for(size_t k = 0; k < size; k++) {
|
2014-06-13 21:40:39 +00:00
|
|
|
attr_uchar4[offset+k] = data[k];
|
2015-02-14 15:23:08 +00:00
|
|
|
}
|
|
|
|
attr_uchar4_offset += size;
|
2014-06-13 21:40:39 +00:00
|
|
|
}
|
2014-03-29 12:03:48 +00:00
|
|
|
else if(mattr->type == TypeDesc::TypeFloat) {
|
2013-01-03 12:08:54 +00:00
|
|
|
float *data = mattr->data_float();
|
2015-02-14 15:23:08 +00:00
|
|
|
offset = attr_float_offset;
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2015-02-14 15:23:08 +00:00
|
|
|
assert(attr_float.capacity() >= offset + size);
|
|
|
|
for(size_t k = 0; k < size; k++) {
|
2013-01-03 12:08:54 +00:00
|
|
|
attr_float[offset+k] = data[k];
|
2015-02-14 15:23:08 +00:00
|
|
|
}
|
|
|
|
attr_float_offset += size;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
2013-12-31 16:33:55 +00:00
|
|
|
else if(mattr->type == TypeDesc::TypeMatrix) {
|
|
|
|
Transform *tfm = mattr->data_transform();
|
2015-02-14 15:23:08 +00:00
|
|
|
offset = attr_float3_offset;
|
2013-12-31 16:33:55 +00:00
|
|
|
|
2015-02-14 15:23:08 +00:00
|
|
|
assert(attr_float3.capacity() >= offset + size * 4);
|
|
|
|
for(size_t k = 0; k < size*4; k++) {
|
2013-12-31 16:33:55 +00:00
|
|
|
attr_float3[offset+k] = (&tfm->x)[k];
|
2015-02-14 15:23:08 +00:00
|
|
|
}
|
|
|
|
attr_float3_offset += size * 4;
|
2013-12-31 16:33:55 +00:00
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
else {
|
2014-03-29 12:03:46 +00:00
|
|
|
float4 *data = mattr->data_float4();
|
2015-02-14 15:23:08 +00:00
|
|
|
offset = attr_float3_offset;
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2015-02-14 15:23:08 +00:00
|
|
|
assert(attr_float3.capacity() >= offset + size);
|
|
|
|
for(size_t k = 0; k < size; k++) {
|
2014-03-29 12:03:46 +00:00
|
|
|
attr_float3[offset+k] = data[k];
|
2015-02-14 15:23:08 +00:00
|
|
|
}
|
|
|
|
attr_float3_offset += size;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* mesh vertex/curve index is global, not per object, so we sneak
|
|
|
|
* a correction for that in here */
|
2016-07-17 02:57:06 +00:00
|
|
|
if(mesh->subdivision_type == Mesh::SUBDIVISION_CATMULL_CLARK && desc.flags & ATTR_SUBDIVIDED) {
|
|
|
|
/* indices for subdivided attributes are retrieved
|
|
|
|
* from patch table so no need for correction here*/
|
|
|
|
}
|
|
|
|
else if(element == ATTR_ELEMENT_VERTEX)
|
2013-01-03 12:08:54 +00:00
|
|
|
offset -= mesh->vert_offset;
|
2014-03-29 12:03:46 +00:00
|
|
|
else if(element == ATTR_ELEMENT_VERTEX_MOTION)
|
|
|
|
offset -= mesh->vert_offset;
|
2016-07-16 23:42:28 +00:00
|
|
|
else if(element == ATTR_ELEMENT_FACE) {
|
|
|
|
if(prim == ATTR_PRIM_TRIANGLE)
|
|
|
|
offset -= mesh->tri_offset;
|
|
|
|
else
|
|
|
|
offset -= mesh->face_offset;
|
|
|
|
}
|
|
|
|
else if(element == ATTR_ELEMENT_CORNER || element == ATTR_ELEMENT_CORNER_BYTE) {
|
|
|
|
if(prim == ATTR_PRIM_TRIANGLE)
|
|
|
|
offset -= 3*mesh->tri_offset;
|
|
|
|
else
|
|
|
|
offset -= mesh->corner_offset;
|
|
|
|
}
|
2013-01-03 12:09:09 +00:00
|
|
|
else if(element == ATTR_ELEMENT_CURVE)
|
|
|
|
offset -= mesh->curve_offset;
|
2013-01-03 12:08:54 +00:00
|
|
|
else if(element == ATTR_ELEMENT_CURVE_KEY)
|
|
|
|
offset -= mesh->curvekey_offset;
|
2014-03-29 12:03:46 +00:00
|
|
|
else if(element == ATTR_ELEMENT_CURVE_KEY_MOTION)
|
|
|
|
offset -= mesh->curvekey_offset;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* attribute not found */
|
2016-07-01 21:36:27 +00:00
|
|
|
desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
desc.offset = 0;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void MeshManager::device_update_attributes(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
|
|
|
|
{
|
|
|
|
progress.set_status("Updating Mesh", "Computing attributes");
|
|
|
|
|
|
|
|
/* gather per mesh requested attributes. as meshes may have multiple
|
2011-08-28 13:55:59 +00:00
|
|
|
* shaders assigned, this merges the requested attributes that have
|
2011-04-27 11:58:34 +00:00
|
|
|
* been set per shader by the shader manager */
|
|
|
|
vector<AttributeRequestSet> mesh_attributes(scene->meshes.size());
|
|
|
|
|
|
|
|
for(size_t i = 0; i < scene->meshes.size(); i++) {
|
|
|
|
Mesh *mesh = scene->meshes[i];
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
scene->need_global_attributes(mesh_attributes[i]);
|
|
|
|
|
2016-05-14 12:50:03 +00:00
|
|
|
foreach(Shader *shader, mesh->used_shaders) {
|
2011-04-27 11:58:34 +00:00
|
|
|
mesh_attributes[i].add(shader->attributes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* mesh attribute are stored in a single array per data type. here we fill
|
|
|
|
* those arrays, and set the offset and element type to create attribute
|
|
|
|
* maps next */
|
|
|
|
|
2015-02-14 15:23:08 +00:00
|
|
|
/* Pre-allocate attributes to avoid arrays re-allocation which would
|
|
|
|
* take 2x of overall attribute memory usage.
|
|
|
|
*/
|
|
|
|
size_t attr_float_size = 0;
|
|
|
|
size_t attr_float3_size = 0;
|
|
|
|
size_t attr_uchar4_size = 0;
|
|
|
|
for(size_t i = 0; i < scene->meshes.size(); i++) {
|
|
|
|
Mesh *mesh = scene->meshes[i];
|
|
|
|
AttributeRequestSet& attributes = mesh_attributes[i];
|
|
|
|
foreach(AttributeRequest& req, attributes.requests) {
|
|
|
|
Attribute *triangle_mattr = mesh->attributes.find(req);
|
|
|
|
Attribute *curve_mattr = mesh->curve_attributes.find(req);
|
2016-07-16 23:42:28 +00:00
|
|
|
Attribute *subd_mattr = mesh->subd_attributes.find(req);
|
2015-02-14 21:55:18 +00:00
|
|
|
|
2015-02-14 15:23:08 +00:00
|
|
|
update_attribute_element_size(mesh,
|
|
|
|
triangle_mattr,
|
2016-07-16 23:42:28 +00:00
|
|
|
ATTR_PRIM_TRIANGLE,
|
2015-02-14 15:23:08 +00:00
|
|
|
&attr_float_size,
|
|
|
|
&attr_float3_size,
|
|
|
|
&attr_uchar4_size);
|
|
|
|
update_attribute_element_size(mesh,
|
|
|
|
curve_mattr,
|
2016-07-16 23:42:28 +00:00
|
|
|
ATTR_PRIM_CURVE,
|
|
|
|
&attr_float_size,
|
|
|
|
&attr_float3_size,
|
|
|
|
&attr_uchar4_size);
|
|
|
|
update_attribute_element_size(mesh,
|
|
|
|
subd_mattr,
|
|
|
|
ATTR_PRIM_SUBD,
|
2015-02-14 15:23:08 +00:00
|
|
|
&attr_float_size,
|
|
|
|
&attr_float3_size,
|
|
|
|
&attr_uchar4_size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
vector<float> attr_float(attr_float_size);
|
|
|
|
vector<float4> attr_float3(attr_float3_size);
|
|
|
|
vector<uchar4> attr_uchar4(attr_uchar4_size);
|
|
|
|
|
|
|
|
size_t attr_float_offset = 0;
|
|
|
|
size_t attr_float3_offset = 0;
|
|
|
|
size_t attr_uchar4_offset = 0;
|
|
|
|
|
|
|
|
/* Fill in attributes. */
|
2011-04-27 11:58:34 +00:00
|
|
|
for(size_t i = 0; i < scene->meshes.size(); i++) {
|
|
|
|
Mesh *mesh = scene->meshes[i];
|
|
|
|
AttributeRequestSet& attributes = mesh_attributes[i];
|
|
|
|
|
|
|
|
/* todo: we now store std and name attributes from requests even if
|
2012-06-09 17:22:52 +00:00
|
|
|
* they actually refer to the same mesh attributes, optimize */
|
2011-04-27 11:58:34 +00:00
|
|
|
foreach(AttributeRequest& req, attributes.requests) {
|
2013-01-03 12:08:54 +00:00
|
|
|
Attribute *triangle_mattr = mesh->attributes.find(req);
|
|
|
|
Attribute *curve_mattr = mesh->curve_attributes.find(req);
|
2016-07-16 23:42:28 +00:00
|
|
|
Attribute *subd_mattr = mesh->subd_attributes.find(req);
|
2013-01-03 12:08:54 +00:00
|
|
|
|
2015-02-14 15:23:08 +00:00
|
|
|
update_attribute_element_offset(mesh,
|
|
|
|
attr_float, attr_float_offset,
|
|
|
|
attr_float3, attr_float3_offset,
|
|
|
|
attr_uchar4, attr_uchar4_offset,
|
|
|
|
triangle_mattr,
|
2016-07-16 23:42:28 +00:00
|
|
|
ATTR_PRIM_TRIANGLE,
|
2015-02-14 15:23:08 +00:00
|
|
|
req.triangle_type,
|
2016-07-01 21:36:27 +00:00
|
|
|
req.triangle_desc);
|
2015-02-14 15:23:08 +00:00
|
|
|
|
|
|
|
update_attribute_element_offset(mesh,
|
|
|
|
attr_float, attr_float_offset,
|
|
|
|
attr_float3, attr_float3_offset,
|
|
|
|
attr_uchar4, attr_uchar4_offset,
|
|
|
|
curve_mattr,
|
2016-07-16 23:42:28 +00:00
|
|
|
ATTR_PRIM_CURVE,
|
2015-02-14 15:23:08 +00:00
|
|
|
req.curve_type,
|
2016-07-01 21:36:27 +00:00
|
|
|
req.curve_desc);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
update_attribute_element_offset(mesh,
|
|
|
|
attr_float, attr_float_offset,
|
|
|
|
attr_float3, attr_float3_offset,
|
|
|
|
attr_uchar4, attr_uchar4_offset,
|
|
|
|
subd_mattr,
|
|
|
|
ATTR_PRIM_SUBD,
|
|
|
|
req.subd_type,
|
2016-07-01 21:36:27 +00:00
|
|
|
req.subd_desc);
|
2016-07-16 23:42:28 +00:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* create attribute lookup maps */
|
2012-12-04 07:48:09 +00:00
|
|
|
if(scene->shader_manager->use_osl())
|
2011-04-27 11:58:34 +00:00
|
|
|
update_osl_attributes(device, scene, mesh_attributes);
|
2014-03-29 12:03:46 +00:00
|
|
|
|
|
|
|
update_svm_attributes(device, dscene, scene, mesh_attributes);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
|
|
|
/* copy to device */
|
|
|
|
progress.set_status("Updating Mesh", "Copying Attributes to device");
|
|
|
|
|
|
|
|
if(attr_float.size()) {
|
|
|
|
dscene->attributes_float.copy(&attr_float[0], attr_float.size());
|
|
|
|
device->tex_alloc("__attributes_float", dscene->attributes_float);
|
|
|
|
}
|
|
|
|
if(attr_float3.size()) {
|
|
|
|
dscene->attributes_float3.copy(&attr_float3[0], attr_float3.size());
|
|
|
|
device->tex_alloc("__attributes_float3", dscene->attributes_float3);
|
|
|
|
}
|
2014-06-13 21:40:39 +00:00
|
|
|
if(attr_uchar4.size()) {
|
|
|
|
dscene->attributes_uchar4.copy(&attr_uchar4[0], attr_uchar4.size());
|
|
|
|
device->tex_alloc("__attributes_uchar4", dscene->attributes_uchar4);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
void MeshManager::mesh_calc_offset(Scene *scene)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
size_t vert_size = 0;
|
|
|
|
size_t tri_size = 0;
|
2016-07-16 23:42:28 +00:00
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
size_t curve_key_size = 0;
|
2013-01-03 12:09:09 +00:00
|
|
|
size_t curve_size = 0;
|
2012-12-28 14:21:30 +00:00
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
size_t patch_size = 0;
|
|
|
|
size_t face_size = 0;
|
|
|
|
size_t corner_size = 0;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
|
|
|
mesh->vert_offset = vert_size;
|
|
|
|
mesh->tri_offset = tri_size;
|
2016-07-16 23:42:28 +00:00
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
mesh->curvekey_offset = curve_key_size;
|
2013-01-03 12:09:09 +00:00
|
|
|
mesh->curve_offset = curve_size;
|
2012-12-28 14:21:30 +00:00
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
mesh->patch_offset = patch_size;
|
|
|
|
mesh->face_offset = face_size;
|
|
|
|
mesh->corner_offset = corner_size;
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
vert_size += mesh->verts.size();
|
2016-05-07 22:09:08 +00:00
|
|
|
tri_size += mesh->num_triangles();
|
2016-07-16 23:42:28 +00:00
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
curve_key_size += mesh->curve_keys.size();
|
2016-05-07 22:09:08 +00:00
|
|
|
curve_size += mesh->num_curves();
|
2016-07-16 23:42:28 +00:00
|
|
|
|
|
|
|
if(mesh->subd_faces.size()) {
|
|
|
|
Mesh::SubdFace& last = mesh->subd_faces[mesh->subd_faces.size()-1];
|
|
|
|
patch_size += (last.ptex_offset + last.num_ptex_faces()) * 8;
|
2016-07-17 02:57:06 +00:00
|
|
|
|
|
|
|
/* patch tables are stored in same array so include them in patch_size */
|
|
|
|
if(mesh->patch_table) {
|
|
|
|
mesh->patch_table_offset = patch_size;
|
|
|
|
patch_size += mesh->patch_table->total_size();
|
|
|
|
}
|
2016-07-16 23:42:28 +00:00
|
|
|
}
|
|
|
|
face_size += mesh->subd_faces.size();
|
|
|
|
corner_size += mesh->subd_face_corners.size();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
void MeshManager::device_update_mesh(Device *device,
|
|
|
|
DeviceScene *dscene,
|
|
|
|
Scene *scene,
|
|
|
|
bool for_displacement,
|
|
|
|
Progress& progress)
|
|
|
|
{
|
|
|
|
/* Count. */
|
|
|
|
size_t vert_size = 0;
|
|
|
|
size_t tri_size = 0;
|
2016-07-16 23:42:28 +00:00
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
size_t curve_key_size = 0;
|
|
|
|
size_t curve_size = 0;
|
2016-07-16 23:42:28 +00:00
|
|
|
|
|
|
|
size_t patch_size = 0;
|
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
|
|
|
vert_size += mesh->verts.size();
|
|
|
|
tri_size += mesh->num_triangles();
|
2016-07-16 23:42:28 +00:00
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
curve_key_size += mesh->curve_keys.size();
|
|
|
|
curve_size += mesh->num_curves();
|
2016-07-16 23:42:28 +00:00
|
|
|
|
|
|
|
if(mesh->subd_faces.size()) {
|
|
|
|
Mesh::SubdFace& last = mesh->subd_faces[mesh->subd_faces.size()-1];
|
|
|
|
patch_size += (last.ptex_offset + last.num_ptex_faces()) * 8;
|
2016-07-17 02:57:06 +00:00
|
|
|
|
|
|
|
/* patch tables are stored in same array so include them in patch_size */
|
|
|
|
if(mesh->patch_table) {
|
|
|
|
mesh->patch_table_offset = patch_size;
|
|
|
|
patch_size += mesh->patch_table->total_size();
|
|
|
|
}
|
2016-07-16 23:42:28 +00:00
|
|
|
}
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
}
|
2016-07-16 23:42:28 +00:00
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
/* Create mapping from triangle to primitive triangle array. */
|
|
|
|
vector<uint> tri_prim_index(tri_size);
|
|
|
|
if(for_displacement) {
|
|
|
|
/* For displacement kernels we do some trickery to make them believe
|
|
|
|
* we've got all required data ready. However, that data is different
|
|
|
|
* from final render kernels since we don't have BVH yet, so can't
|
|
|
|
* really use same semantic of arrays.
|
|
|
|
*/
|
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
|
|
|
for(size_t i = 0; i < mesh->num_triangles(); ++i) {
|
|
|
|
tri_prim_index[i + mesh->tri_offset] = 3 * (i + mesh->tri_offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PackedBVH& pack = bvh->pack;
|
|
|
|
for(size_t i = 0; i < pack.prim_index.size(); ++i) {
|
2016-10-24 10:26:12 +00:00
|
|
|
if((pack.prim_type[i] & PRIMITIVE_ALL_TRIANGLE) != 0) {
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
tri_prim_index[pack.prim_index[i]] = pack.prim_tri_index[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-07-16 23:42:28 +00:00
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
/* Fill in all the arrays. */
|
2012-12-28 14:21:30 +00:00
|
|
|
if(tri_size != 0) {
|
|
|
|
/* normals */
|
|
|
|
progress.set_status("Updating Mesh", "Computing normals");
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2014-09-24 11:34:28 +00:00
|
|
|
uint *tri_shader = dscene->tri_shader.resize(tri_size);
|
2012-12-28 14:21:30 +00:00
|
|
|
float4 *vnormal = dscene->tri_vnormal.resize(vert_size);
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
uint4 *tri_vindex = dscene->tri_vindex.resize(tri_size);
|
2016-07-16 23:42:28 +00:00
|
|
|
uint *tri_patch = dscene->tri_patch.resize(tri_size);
|
|
|
|
float2 *tri_patch_uv = dscene->tri_patch_uv.resize(vert_size);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-12-28 14:21:30 +00:00
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
mesh->pack_normals(scene,
|
|
|
|
&tri_shader[mesh->tri_offset],
|
|
|
|
&vnormal[mesh->vert_offset]);
|
|
|
|
mesh->pack_verts(tri_prim_index,
|
|
|
|
&tri_vindex[mesh->tri_offset],
|
2016-07-16 23:42:28 +00:00
|
|
|
&tri_patch[mesh->tri_offset],
|
|
|
|
&tri_patch_uv[mesh->vert_offset],
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
mesh->vert_offset,
|
|
|
|
mesh->tri_offset);
|
2012-12-28 14:21:30 +00:00
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-12-28 14:21:30 +00:00
|
|
|
/* vertex coordinates */
|
|
|
|
progress.set_status("Updating Mesh", "Copying Mesh to device");
|
|
|
|
|
2014-06-13 19:27:21 +00:00
|
|
|
device->tex_alloc("__tri_shader", dscene->tri_shader);
|
2012-12-28 14:21:30 +00:00
|
|
|
device->tex_alloc("__tri_vnormal", dscene->tri_vnormal);
|
|
|
|
device->tex_alloc("__tri_vindex", dscene->tri_vindex);
|
2016-07-16 23:42:28 +00:00
|
|
|
device->tex_alloc("__tri_patch", dscene->tri_patch);
|
|
|
|
device->tex_alloc("__tri_patch_uv", dscene->tri_patch_uv);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2016-07-16 23:42:28 +00:00
|
|
|
|
2013-01-03 12:09:09 +00:00
|
|
|
if(curve_size != 0) {
|
2012-12-28 14:21:30 +00:00
|
|
|
progress.set_status("Updating Mesh", "Copying Strands to device");
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
float4 *curve_keys = dscene->curve_keys.resize(curve_key_size);
|
2013-01-03 12:09:09 +00:00
|
|
|
float4 *curves = dscene->curves.resize(curve_size);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-12-28 14:21:30 +00:00
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
2013-01-03 12:09:09 +00:00
|
|
|
mesh->pack_curves(scene, &curve_keys[mesh->curvekey_offset], &curves[mesh->curve_offset], mesh->curvekey_offset);
|
2012-12-28 14:21:30 +00:00
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
}
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
device->tex_alloc("__curve_keys", dscene->curve_keys);
|
2013-01-03 12:09:09 +00:00
|
|
|
device->tex_alloc("__curves", dscene->curves);
|
2012-12-28 14:21:30 +00:00
|
|
|
}
|
2016-07-16 23:42:28 +00:00
|
|
|
|
|
|
|
if(patch_size != 0) {
|
|
|
|
progress.set_status("Updating Mesh", "Copying Patches to device");
|
|
|
|
|
|
|
|
uint *patch_data = dscene->patches.resize(patch_size);
|
|
|
|
|
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
|
|
|
mesh->pack_patches(&patch_data[mesh->patch_offset], mesh->vert_offset, mesh->face_offset, mesh->corner_offset);
|
2016-07-17 02:57:06 +00:00
|
|
|
|
|
|
|
if(mesh->patch_table) {
|
|
|
|
mesh->patch_table->copy_adjusting_offsets(&patch_data[mesh->patch_table_offset], mesh->patch_table_offset);
|
|
|
|
}
|
|
|
|
|
2016-07-16 23:42:28 +00:00
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
}
|
|
|
|
|
|
|
|
device->tex_alloc("__patches", dscene->patches);
|
|
|
|
}
|
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
if(for_displacement) {
|
|
|
|
float4 *prim_tri_verts = dscene->prim_tri_verts.resize(tri_size * 3);
|
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
|
|
|
for(size_t i = 0; i < mesh->num_triangles(); ++i) {
|
|
|
|
Mesh::Triangle t = mesh->get_triangle(i);
|
|
|
|
size_t offset = 3 * (i + mesh->tri_offset);
|
|
|
|
prim_tri_verts[offset + 0] = float3_to_float4(mesh->verts[t.v[0]]);
|
|
|
|
prim_tri_verts[offset + 1] = float3_to_float4(mesh->verts[t.v[1]]);
|
|
|
|
prim_tri_verts[offset + 2] = float3_to_float4(mesh->verts[t.v[2]]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
device->tex_alloc("__prim_tri_verts", dscene->prim_tri_verts);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MeshManager::device_update_bvh(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
|
|
|
|
{
|
|
|
|
/* bvh build */
|
|
|
|
progress.set_status("Updating Scene BVH", "Building");
|
|
|
|
|
2014-12-24 19:53:26 +00:00
|
|
|
VLOG(1) << (scene->params.use_qbvh ? "Using QBVH optimization structure"
|
|
|
|
: "Using regular BVH optimization structure");
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
BVHParams bparams;
|
|
|
|
bparams.top_level = true;
|
|
|
|
bparams.use_qbvh = scene->params.use_qbvh;
|
|
|
|
bparams.use_spatial_split = scene->params.use_bvh_spatial_split;
|
2016-07-07 16:04:16 +00:00
|
|
|
bparams.use_unaligned_nodes = dscene->data.bvh.have_curves &&
|
|
|
|
scene->params.use_bvh_unaligned_nodes;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
delete bvh;
|
|
|
|
bvh = BVH::create(bparams, scene->objects);
|
|
|
|
bvh->build(progress);
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
|
|
|
/* copy to device */
|
|
|
|
progress.set_status("Updating Scene BVH", "Copying BVH to device");
|
|
|
|
|
|
|
|
PackedBVH& pack = bvh->pack;
|
|
|
|
|
|
|
|
if(pack.nodes.size()) {
|
|
|
|
dscene->bvh_nodes.reference((float4*)&pack.nodes[0], pack.nodes.size());
|
|
|
|
device->tex_alloc("__bvh_nodes", dscene->bvh_nodes);
|
|
|
|
}
|
2015-04-13 18:05:09 +00:00
|
|
|
if(pack.leaf_nodes.size()) {
|
|
|
|
dscene->bvh_leaf_nodes.reference((float4*)&pack.leaf_nodes[0], pack.leaf_nodes.size());
|
|
|
|
device->tex_alloc("__bvh_leaf_nodes", dscene->bvh_leaf_nodes);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
if(pack.object_node.size()) {
|
|
|
|
dscene->object_node.reference((uint*)&pack.object_node[0], pack.object_node.size());
|
|
|
|
device->tex_alloc("__object_node", dscene->object_node);
|
|
|
|
}
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
if(pack.prim_tri_index.size()) {
|
|
|
|
dscene->prim_tri_index.reference((uint*)&pack.prim_tri_index[0], pack.prim_tri_index.size());
|
|
|
|
device->tex_alloc("__prim_tri_index", dscene->prim_tri_index);
|
|
|
|
}
|
|
|
|
if(pack.prim_tri_verts.size()) {
|
|
|
|
dscene->prim_tri_verts.reference((float4*)&pack.prim_tri_verts[0], pack.prim_tri_verts.size());
|
|
|
|
device->tex_alloc("__prim_tri_verts", dscene->prim_tri_verts);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
2014-03-29 12:03:46 +00:00
|
|
|
if(pack.prim_type.size()) {
|
|
|
|
dscene->prim_type.reference((uint*)&pack.prim_type[0], pack.prim_type.size());
|
|
|
|
device->tex_alloc("__prim_type", dscene->prim_type);
|
2012-12-28 14:21:30 +00:00
|
|
|
}
|
2011-09-01 15:53:36 +00:00
|
|
|
if(pack.prim_visibility.size()) {
|
|
|
|
dscene->prim_visibility.reference((uint*)&pack.prim_visibility[0], pack.prim_visibility.size());
|
|
|
|
device->tex_alloc("__prim_visibility", dscene->prim_visibility);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
if(pack.prim_index.size()) {
|
|
|
|
dscene->prim_index.reference((uint*)&pack.prim_index[0], pack.prim_index.size());
|
|
|
|
device->tex_alloc("__prim_index", dscene->prim_index);
|
|
|
|
}
|
|
|
|
if(pack.prim_object.size()) {
|
|
|
|
dscene->prim_object.reference((uint*)&pack.prim_object[0], pack.prim_object.size());
|
|
|
|
device->tex_alloc("__prim_object", dscene->prim_object);
|
|
|
|
}
|
|
|
|
|
|
|
|
dscene->data.bvh.root = pack.root_index;
|
2014-12-16 15:11:37 +00:00
|
|
|
dscene->data.bvh.use_qbvh = scene->params.use_qbvh;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 10:47:55 +00:00
|
|
|
void MeshManager::device_update_flags(Device * /*device*/,
|
|
|
|
DeviceScene * /*dscene*/,
|
|
|
|
Scene * scene,
|
|
|
|
Progress& /*progress*/)
|
2015-01-19 14:08:58 +00:00
|
|
|
{
|
|
|
|
if(!need_update && !need_flags_update) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* update flags */
|
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
|
|
|
mesh->has_volume = false;
|
2016-05-14 12:50:03 +00:00
|
|
|
foreach(const Shader *shader, mesh->used_shaders) {
|
2016-02-25 14:12:11 +00:00
|
|
|
if(shader->has_volume) {
|
2015-01-19 14:08:58 +00:00
|
|
|
mesh->has_volume = true;
|
|
|
|
}
|
2016-02-25 14:12:11 +00:00
|
|
|
if(shader->has_surface_bssrdf) {
|
|
|
|
mesh->has_surface_bssrdf = true;
|
|
|
|
}
|
2015-01-19 14:08:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
need_flags_update = false;
|
|
|
|
}
|
|
|
|
|
2015-04-02 15:37:57 +00:00
|
|
|
void MeshManager::device_update_displacement_images(Device *device,
|
|
|
|
DeviceScene *dscene,
|
|
|
|
Scene *scene,
|
|
|
|
Progress& progress)
|
|
|
|
{
|
|
|
|
progress.set_status("Updating Displacement Images");
|
|
|
|
TaskPool pool;
|
|
|
|
ImageManager *image_manager = scene->image_manager;
|
|
|
|
set<int> bump_images;
|
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
|
|
|
if(mesh->need_update) {
|
2016-05-14 12:50:03 +00:00
|
|
|
foreach(Shader *shader, mesh->used_shaders) {
|
2016-09-05 16:51:30 +00:00
|
|
|
if(!shader->has_displacement || shader->displacement_method == DISPLACE_BUMP) {
|
2015-04-02 15:37:57 +00:00
|
|
|
continue;
|
|
|
|
}
|
2016-09-05 16:51:30 +00:00
|
|
|
foreach(ShaderNode* node, shader->graph->nodes) {
|
2015-04-02 15:37:57 +00:00
|
|
|
if(node->special_type != SHADER_SPECIAL_TYPE_IMAGE_SLOT) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if(device->info.pack_images) {
|
|
|
|
/* If device requires packed images we need to update all
|
|
|
|
* images now, even if they're not used for displacement.
|
|
|
|
*/
|
|
|
|
image_manager->device_update(device,
|
|
|
|
dscene,
|
|
|
|
progress);
|
|
|
|
return;
|
|
|
|
}
|
2016-05-01 22:05:16 +00:00
|
|
|
ImageSlotTextureNode *image_node = static_cast<ImageSlotTextureNode*>(node);
|
2015-04-02 15:37:57 +00:00
|
|
|
int slot = image_node->slot;
|
|
|
|
if(slot != -1) {
|
|
|
|
bump_images.insert(slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach(int slot, bump_images) {
|
|
|
|
pool.push(function_bind(&ImageManager::device_update_slot,
|
|
|
|
image_manager,
|
|
|
|
device,
|
|
|
|
dscene,
|
|
|
|
slot,
|
|
|
|
&progress));
|
|
|
|
}
|
|
|
|
pool.wait_work();
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
void MeshManager::device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress)
|
|
|
|
{
|
|
|
|
if(!need_update)
|
|
|
|
return;
|
|
|
|
|
2016-04-22 08:55:26 +00:00
|
|
|
VLOG(1) << "Total " << scene->meshes.size() << " meshes.";
|
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
/* Update normals. */
|
2011-04-27 11:58:34 +00:00
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
2016-05-14 12:50:03 +00:00
|
|
|
foreach(Shader *shader, mesh->used_shaders) {
|
|
|
|
if(shader->need_update_attributes)
|
2011-04-27 11:58:34 +00:00
|
|
|
mesh->need_update = true;
|
2014-10-02 18:37:05 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if(mesh->need_update) {
|
|
|
|
mesh->add_face_normals();
|
|
|
|
mesh->add_vertex_normals();
|
|
|
|
|
2016-08-13 16:27:17 +00:00
|
|
|
if(mesh->need_attribute(scene, ATTR_STD_POSITION_UNDISPLACED)) {
|
|
|
|
mesh->add_undisplaced();
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-14 16:41:45 +00:00
|
|
|
/* Tessellate meshes that are using subdivision */
|
|
|
|
size_t total_tess_needed = 0;
|
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
|
|
|
if(mesh->need_update &&
|
|
|
|
mesh->subdivision_type != Mesh::SUBDIVISION_NONE &&
|
|
|
|
mesh->num_subd_verts == 0 &&
|
|
|
|
mesh->subd_params)
|
|
|
|
{
|
|
|
|
total_tess_needed++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t i = 0;
|
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
|
|
|
if(mesh->need_update &&
|
|
|
|
mesh->subdivision_type != Mesh::SUBDIVISION_NONE &&
|
|
|
|
mesh->num_subd_verts == 0 &&
|
|
|
|
mesh->subd_params)
|
|
|
|
{
|
|
|
|
string msg = "Tessellating ";
|
|
|
|
if(mesh->name == "")
|
|
|
|
msg += string_printf("%u/%u", (uint)(i+1), (uint)total_tess_needed);
|
|
|
|
else
|
|
|
|
msg += string_printf("%s %u/%u", mesh->name.c_str(), (uint)(i+1), (uint)total_tess_needed);
|
|
|
|
|
|
|
|
progress.set_status("Updating Mesh", msg);
|
|
|
|
|
|
|
|
DiagSplit dsplit(*mesh->subd_params);
|
|
|
|
mesh->tessellate(&dsplit);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-04-02 15:37:57 +00:00
|
|
|
/* Update images needed for true displacement. */
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
bool true_displacement_used = false;
|
2015-06-01 18:59:23 +00:00
|
|
|
bool old_need_object_flags_update = false;
|
2015-04-02 15:37:57 +00:00
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
|
|
|
if(mesh->need_update &&
|
2016-08-02 09:13:58 +00:00
|
|
|
mesh->has_true_displacement())
|
2015-04-02 15:37:57 +00:00
|
|
|
{
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
true_displacement_used = true;
|
2015-04-02 15:37:57 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
if(true_displacement_used) {
|
2015-04-02 15:37:57 +00:00
|
|
|
VLOG(1) << "Updating images used for true displacement.";
|
|
|
|
device_update_displacement_images(device, dscene, scene, progress);
|
2015-06-01 18:59:23 +00:00
|
|
|
old_need_object_flags_update = scene->object_manager->need_flags_update;
|
|
|
|
scene->object_manager->device_update_flags(device,
|
|
|
|
dscene,
|
|
|
|
scene,
|
|
|
|
progress,
|
|
|
|
false);
|
2015-04-02 15:37:57 +00:00
|
|
|
}
|
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
/* Device update. */
|
2011-04-27 11:58:34 +00:00
|
|
|
device_free(device, dscene);
|
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
mesh_calc_offset(scene);
|
|
|
|
if(true_displacement_used) {
|
|
|
|
device_update_mesh(device, dscene, scene, true, progress);
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
2016-07-17 02:57:06 +00:00
|
|
|
/* 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);
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
device_update_attributes(device, dscene, scene, progress);
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
/* Update displacement. */
|
2011-04-27 11:58:34 +00:00
|
|
|
bool displacement_done = false;
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
|
|
|
if(mesh->need_update &&
|
|
|
|
displace(device, dscene, scene, mesh, progress))
|
|
|
|
{
|
2011-04-27 11:58:34 +00:00
|
|
|
displacement_done = true;
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
}
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
/* TODO: properly handle cancel halfway displacement */
|
2011-04-27 11:58:34 +00:00
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
/* Device re-update after displacement. */
|
2011-04-27 11:58:34 +00:00
|
|
|
if(displacement_done) {
|
|
|
|
device_free(device, dscene);
|
|
|
|
|
|
|
|
device_update_attributes(device, dscene, scene, progress);
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
}
|
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
/* Update bvh. */
|
2016-08-14 16:41:45 +00:00
|
|
|
size_t num_bvh = 0;
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
|
|
|
if(mesh->need_update && mesh->need_build_bvh()) {
|
2012-05-05 19:44:33 +00:00
|
|
|
num_bvh++;
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-16 23:42:28 +00:00
|
|
|
|
2012-05-05 19:44:33 +00:00
|
|
|
TaskPool pool;
|
2016-07-16 23:42:28 +00:00
|
|
|
|
2016-08-14 16:41:45 +00:00
|
|
|
i = 0;
|
2011-04-27 11:58:34 +00:00
|
|
|
foreach(Mesh *mesh, scene->meshes) {
|
|
|
|
if(mesh->need_update) {
|
2014-12-16 15:11:37 +00:00
|
|
|
pool.push(function_bind(&Mesh::compute_bvh,
|
|
|
|
mesh,
|
2016-07-07 10:18:57 +00:00
|
|
|
dscene,
|
2014-12-16 15:11:37 +00:00
|
|
|
&scene->params,
|
|
|
|
&progress,
|
|
|
|
i,
|
|
|
|
num_bvh));
|
2016-02-25 14:12:11 +00:00
|
|
|
if(mesh->need_build_bvh()) {
|
2015-04-09 17:23:59 +00:00
|
|
|
i++;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
}
|
2016-07-16 23:42:28 +00:00
|
|
|
|
2016-04-04 11:43:19 +00:00
|
|
|
TaskPool::Summary summary;
|
|
|
|
pool.wait_work(&summary);
|
|
|
|
VLOG(2) << "Objects BVH build pool statistics:\n"
|
|
|
|
<< summary.full_report();
|
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
foreach(Shader *shader, scene->shaders) {
|
2011-04-27 11:58:34 +00:00
|
|
|
shader->need_update_attributes = false;
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-10-09 18:37:14 +00:00
|
|
|
#ifdef __OBJECT_MOTION__
|
2012-10-15 21:12:58 +00:00
|
|
|
Scene::MotionType need_motion = scene->need_motion(device->info.advanced_shading);
|
|
|
|
bool motion_blur = need_motion == Scene::MOTION_BLUR;
|
2012-10-09 18:37:14 +00:00
|
|
|
#else
|
|
|
|
bool motion_blur = false;
|
|
|
|
#endif
|
2012-04-30 12:49:26 +00:00
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
/* Update objects. */
|
2014-10-03 08:52:04 +00:00
|
|
|
vector<Object *> volume_objects;
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
foreach(Object *object, scene->objects) {
|
2014-03-29 12:03:46 +00:00
|
|
|
object->compute_bounds(motion_blur);
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
|
|
|
device_update_bvh(device, dscene, scene, progress);
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
if(progress.get_cancel()) return;
|
|
|
|
|
|
|
|
device_update_mesh(device, dscene, scene, false, progress);
|
|
|
|
if(progress.get_cancel()) return;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
need_update = false;
|
2015-06-01 18:59:23 +00:00
|
|
|
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
if(true_displacement_used) {
|
2015-06-01 18:59:23 +00:00
|
|
|
/* Re-tag flags for update, so they're re-evaluated
|
|
|
|
* for meshes with correct bounding boxes.
|
|
|
|
*
|
|
|
|
* This wouldn't cause wrong results, just true
|
|
|
|
* displacement might be less optimal ot calculate.
|
|
|
|
*/
|
|
|
|
scene->object_manager->need_flags_update = old_need_object_flags_update;
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MeshManager::device_free(Device *device, DeviceScene *dscene)
|
|
|
|
{
|
|
|
|
device->tex_free(dscene->bvh_nodes);
|
2015-04-13 18:05:09 +00:00
|
|
|
device->tex_free(dscene->bvh_leaf_nodes);
|
2011-04-27 11:58:34 +00:00
|
|
|
device->tex_free(dscene->object_node);
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
device->tex_free(dscene->prim_tri_verts);
|
|
|
|
device->tex_free(dscene->prim_tri_index);
|
2014-03-29 12:03:46 +00:00
|
|
|
device->tex_free(dscene->prim_type);
|
2011-09-01 15:53:36 +00:00
|
|
|
device->tex_free(dscene->prim_visibility);
|
2011-04-27 11:58:34 +00:00
|
|
|
device->tex_free(dscene->prim_index);
|
|
|
|
device->tex_free(dscene->prim_object);
|
2014-06-13 19:27:21 +00:00
|
|
|
device->tex_free(dscene->tri_shader);
|
2011-04-27 11:58:34 +00:00
|
|
|
device->tex_free(dscene->tri_vnormal);
|
|
|
|
device->tex_free(dscene->tri_vindex);
|
2016-07-16 23:42:28 +00:00
|
|
|
device->tex_free(dscene->tri_patch);
|
|
|
|
device->tex_free(dscene->tri_patch_uv);
|
2013-01-03 12:09:09 +00:00
|
|
|
device->tex_free(dscene->curves);
|
2013-01-03 12:08:54 +00:00
|
|
|
device->tex_free(dscene->curve_keys);
|
2016-07-16 23:42:28 +00:00
|
|
|
device->tex_free(dscene->patches);
|
2011-04-27 11:58:34 +00:00
|
|
|
device->tex_free(dscene->attributes_map);
|
|
|
|
device->tex_free(dscene->attributes_float);
|
|
|
|
device->tex_free(dscene->attributes_float3);
|
2014-06-27 06:56:57 +00:00
|
|
|
device->tex_free(dscene->attributes_uchar4);
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
dscene->bvh_nodes.clear();
|
|
|
|
dscene->object_node.clear();
|
Cycles: Reduce memory usage by de-duplicating triangle storage
There are several internal changes for this:
First idea is to make __tri_verts to behave similar to __tri_storage,
meaning, __tri_verts array now contains all vertices of all triangles
instead of just mesh vertices. This saves some lookup when reading
triangle coordinates in functions like triangle_normal().
In order to make it efficient needed to store global triangle offset
somewhere. So no __tri_vindex.w contains a global triangle index which
can be used to read triangle vertices.
Additionally, the order of vertices in that array is aligned with
primitives from BVH. This is needed to keep cache as much coherent as
possible for BVH traversal. This causes some extra tricks needed to
fill the array in and deal with True Displacement but those trickery
is fully required to prevent noticeable slowdown.
Next idea was to use this __tri_verts instead of __tri_storage in
intersection code. Unfortunately, this is quite tricky to do without
noticeable speed loss. Mainly this loss is caused by extra lookup
happening to access vertex coordinate.
Fortunately, tricks here and there (i,e, some types changes to avoid
casts which are not really coming for free) reduces those losses to
an acceptable level. So now they are within couple of percent only,
On a positive site we've achieved:
- Few percent of memory save with triangle-only scenes. Actual save
in this case is close to size of all vertices.
On a more fine-subdivided scenes this benefit might become more
obvious.
- Huge memory save of hairy scenes. For example, on koro.blend
there is about 20% memory save. Similar figure for bunny.blend.
This memory save was the main goal of this commit to move forward
with Hair BVH which required more memory per BVH node. So while
this sounds exciting, this memory optimization will become invisible
by upcoming Hair BVH work.
But again on a positive side, we can add an option to NOT use Hair
BVH and then we'll have same-ish render times as we've got currently
but will have this 20% memory benefit on hairy scenes.
2016-06-10 14:13:50 +00:00
|
|
|
dscene->prim_tri_verts.clear();
|
|
|
|
dscene->prim_tri_index.clear();
|
2014-03-29 12:03:46 +00:00
|
|
|
dscene->prim_type.clear();
|
2011-09-01 15:53:36 +00:00
|
|
|
dscene->prim_visibility.clear();
|
2011-04-27 11:58:34 +00:00
|
|
|
dscene->prim_index.clear();
|
|
|
|
dscene->prim_object.clear();
|
2014-06-13 19:27:21 +00:00
|
|
|
dscene->tri_shader.clear();
|
2011-04-27 11:58:34 +00:00
|
|
|
dscene->tri_vnormal.clear();
|
|
|
|
dscene->tri_vindex.clear();
|
2016-07-16 23:42:28 +00:00
|
|
|
dscene->tri_patch.clear();
|
|
|
|
dscene->tri_patch_uv.clear();
|
2013-01-03 12:09:09 +00:00
|
|
|
dscene->curves.clear();
|
2013-01-03 12:08:54 +00:00
|
|
|
dscene->curve_keys.clear();
|
2016-07-16 23:42:28 +00:00
|
|
|
dscene->patches.clear();
|
2011-04-27 11:58:34 +00:00
|
|
|
dscene->attributes_map.clear();
|
|
|
|
dscene->attributes_float.clear();
|
|
|
|
dscene->attributes_float3.clear();
|
2014-06-27 06:56:57 +00:00
|
|
|
dscene->attributes_uchar4.clear();
|
2013-02-14 16:11:47 +00:00
|
|
|
|
2013-02-14 19:30:25 +00:00
|
|
|
#ifdef WITH_OSL
|
2013-02-14 16:11:47 +00:00
|
|
|
OSLGlobals *og = (OSLGlobals*)device->osl_memory();
|
|
|
|
|
|
|
|
if(og) {
|
|
|
|
og->object_name_map.clear();
|
|
|
|
og->attribute_map.clear();
|
|
|
|
og->object_names.clear();
|
|
|
|
}
|
2013-02-14 19:30:25 +00:00
|
|
|
#endif
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void MeshManager::tag_update(Scene *scene)
|
|
|
|
{
|
|
|
|
need_update = true;
|
|
|
|
scene->object_manager->need_update = true;
|
|
|
|
}
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
bool Mesh::need_attribute(Scene *scene, AttributeStandard std)
|
|
|
|
{
|
|
|
|
if(std == ATTR_STD_NONE)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if(scene->need_global_attribute(std))
|
|
|
|
return true;
|
|
|
|
|
2016-05-14 12:50:03 +00:00
|
|
|
foreach(Shader *shader, used_shaders)
|
|
|
|
if(shader->attributes.find(std))
|
2012-04-30 12:49:26 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-05-18 07:12:47 +00:00
|
|
|
bool Mesh::need_attribute(Scene * /*scene*/, ustring name)
|
2012-04-30 12:49:26 +00:00
|
|
|
{
|
|
|
|
if(name == ustring())
|
|
|
|
return false;
|
|
|
|
|
2016-05-14 12:50:03 +00:00
|
|
|
foreach(Shader *shader, used_shaders)
|
|
|
|
if(shader->attributes.find(name))
|
2012-04-30 12:49:26 +00:00
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
CCL_NAMESPACE_END
|
|
|
|
|