Commit Graph

83 Commits

Author SHA1 Message Date
Sergey Sharybin
1841b12900 Cycles: Add assert check to triangle packing
Handy for troubleshooting.
2015-01-22 14:27:13 +05:00
Sergey Sharybin
2f4aef9f3b Cycles: Avoid crash in statistics when canceling BVH build
Also add missing render_time initialization in progress.
2015-01-19 13:39:35 +05:00
Sergey Sharybin
5d5077957e Cycles; Correction to previous debug print to survive prints from multiple threads
This commit basically makes it so statistics print from different BVH trees are not
being interleaved with each other. Glog ensures this when debug print is done as a
single put to stream operator.
2015-01-16 16:39:02 +05:00
Sergey Sharybin
5684ad8072 Cycles: Report BVH statistics after build 2015-01-16 15:05:53 +05:00
Sergey Sharybin
3f60d665bb Cycles: Fix stupid typo in the previous commit 2015-01-16 02:21:35 +05:00
Sergey Sharybin
146eb7947e Cycles: Tweak to leaf creation criteria in all BVH types
Since leaf node gets split further into per-primitive type leaves old check
for number of curves became a bit ridiculous -- it might lead to two leaf nodes
each of which would contain only one curve primitive (one motion curve and one
regular curve).

This lead to quite dramatic slowdown for Victor model -- around 40%, which is
totally unacceptable.

This commit is aimed to prevent such situation and from quick render test it
seems victor is now back to normal render time. Further testing is needed tho.

There are also other ideas about splitting the node, will need to look into
them next.
2015-01-16 01:42:58 +05:00
Sergey Sharybin
e6c79b7369 Cycles: Fix QBVH refit nodes not setting primitive type properly 2015-01-14 02:17:28 +05:00
Sergey Sharybin
51779d9407 Cycles: Fix crash after recent BVH changes on empty BVH trees
It's apparently not nice to access 0th element of zero-size vector in C++.
2015-01-12 19:11:32 +05:00
Sergey Sharybin
e8730af87f Cycles: Fix compilation error on platforms without SSE support
Overview this in one of the previous BVH commits.
2015-01-12 17:14:40 +05:00
Sergey Sharybin
bc7ff3c2b4 Cycles: Enable leaf split by primitive type and adopt BVH traversal for this
This commit enables BVH leaf nodes split by the primitive type and makes it
so BVH traversal code is now aware and benefits from this.

As was mentioned in original commit, this change is crucial to be able to do
single ray to multiple triangle intersection. But it also appears to give
barely visible speedup in some scene.

In any case there should be no noticeable slowdown, and this change is what
we need to have anyway.
2015-01-12 15:04:52 +05:00
Sergey Sharybin
c707b91ce6 Cycles: Optimize leaf splitting code by avoid vector allocation
Use variables allocated in the stack and avoid heap allocation which should make
leaf splitting code a bit faster.
2015-01-12 14:49:59 +05:00
Sergey Sharybin
b56f5900dc Cycles: BVH params option to split leaf node by primitive types
The idea of this change is make it possible to split leaf nodes by primitive
type, making leaf containing primitives of the same type.

This would become handy when working on a single ray to multiple triangles
intersection code, plus with careful implementation it might give some extra
benefits on BVH traversal code by avoiding primitive type fetch and check for
each primitive in the node. But that's a bit tricky to have benefits on this
change only because depth of BVH increases.

This option is not exposed to the interface at all and not used even secretly,
the commit is only needed to help working further in this direction without
messing around with local patches and worrying of them running out of date.
2015-01-12 14:49:56 +05:00
Campbell Barton
4abe548527 cleanup: style 2015-01-02 19:29:00 +11:00
Sergey Sharybin
b11a2f7075 Cycles: Mark visibility TODO as resolved 2014-12-27 23:38:29 +05:00
Thomas Dinges
4ab821c675 Cleanup: Typo fixes for comments. 2014-12-25 02:42:06 +01:00
Sergey Sharybin
deb06c457d Cycles: Correction for node tail copy on packing BVH
This is harmless for now because tail of the node is zero in there, but better
to fix it early so in the case of extending BVH nodes this code doesn't give
issues.
2014-12-25 02:50:49 +05:00
Sergey Sharybin
03f28553ff Cycles: Implement QBVH tree traversal
This commit implements traversal for QBVH tree, which is based on the old loop
code for traversal itself and Embree for node intersection.

This commit also does some changes to the loop inspired by Embree:

- Visibility flags are only checked for primitives.

  Doing visibility check for every node cost quite reasonable amount of time
  and in most cases those checks are true-positive.

  Other idea here would be to do visibility checks for leaf nodes only, but
  this would need to be investigated further.

- For minimum hair width we extend all the nodes' bounding boxes.

  Again doing curve visibility check is quite costly for each of the nodes and
  those checks returns truth for most of the hierarchy anyway.

There are number of possible optimization still, but current state is good
enough in terms it makes rendering faster a little bit after recent watertight
commit.

Currently QBVH is only implemented for CPU with SSE2 support at least. All
other devices would need to be supported later (if that'd make sense from
performance point of view).

The code is enabled for compilation in kernel. but blender wouldn't use it
still.
2014-12-25 02:50:49 +05:00
Sergey Sharybin
788fb8321a Cycles: Store proper empty boundbox for missing child nodes in QBVH
The idea is to make sure those childs would never be intersected with a ray
in order to make it so kernel never worries about number of child nodes.
2014-12-25 02:50:49 +05:00
Sergey Sharybin
f770bc4757 Cycles: Implement watertight ray/triangle intersection
Using this paper: Sven Woop, Watertight Ray/Triangle Intersection

  http://jcgt.org/published/0002/01/05/paper.pdf

This change is expected to address quite reasonable amount of reports from the
bug tracker, plus it might help reducing the noise in some scenes.

Unfortunately, it's currently about 7% slower than the previous solution with
pre-computed triangle plane equations, but maybe with some smart tweaks to the
code (tests reshuffle, using SIMD in a nice way or so) we can avoid the speed
regression.

But perhaps smartest thing to do here would be to change single triangle / ray
intersection with multiple triangles / ray intersections. That's how Embree does
this and it's watertight single ray intersection is not any faster that this.

Currently only triangle intersection is modified accordingly to the paper, in
the future we would also want to modify the node / ray intersection.

Reviewers: brecht, juicyfruit

Subscribers: dingto, ton

Differential Revision: https://developer.blender.org/D819
2014-12-25 02:50:49 +05:00
Sergey Sharybin
57d235d9f4 Cycles: Optimize storage of QBVH node by one float4
The idea is to store visibility flags for leaf nodes only since visibility check
for inner nodes costs too much for QBVH hence it is not optimal to perform.

Leaf QBVH nodes have plenty of space to store all sort of flags, so we can make
nodes one element smaller, saving noticeable amount of memory.
2014-12-25 02:50:49 +05:00
Sergey Sharybin
144096faad Cycles: Make it more clear offsets in BVH construction
Previously offsets were calculated based on the BVH node size,
which is wrong and real PITA in cases when some extra data is
to be added into (or removed from) the node.

Now use offsets which are not calculated form the node size.
2014-12-25 02:50:49 +05:00
Sergey Sharybin
f27d87d300 Cycles: Replace magic constant in the code with actual node size 2014-12-25 02:50:49 +05:00
Sergey Sharybin
f4a959f734 Cycles: Avoid over-allocation in packing BVH instances
This solves quite an over-allocation in BVH instances packing code,
unfortunately, it's not a magic bullet to solve memory bump caused
by the recent QBVH changes.

For that we'll likely need to decouple storage for leaf and inner
nodes. However, it's not really clear for now if it's something
important since that'd still be just a fraction of memory comparing
to all the hi-res textures.
2014-12-25 02:50:49 +05:00
Sergey Sharybin
8cfac731a5 Cycles: Implement refit_nodes for QBVH
Title says it all, quite straightforward implementation.

Would only mention that there's a bit of code duplication around packing node
into pack.nodes. Trying to de-duplicate it ends up in quite hairy code (like
functions with loads of arguments some of which could be NULL in certain
circumstances etc..). Leaving solving this duplication for later.
2014-12-25 02:50:49 +05:00
Sergey Sharybin
fe4905288d Cycles: Use proper node counter to allocate QBVH nodes
Before all the nodes were counted and allocated, leading to situations when
bunch of allocated memory is not used because reasonable amount of nodes are
simply ignored.
2014-12-25 02:50:49 +05:00
Sergey Sharybin
e77b25fabb Cycles: Code cleanup, typo 2014-12-10 00:08:33 +05:00
Sergey Sharybin
9311a5be04 Cycles: Speedup BVH build for certain compilers
The issue was noticed with gcc-4.7 (used by the release build environment)
which didn't generate optimal enough code for BVH references swap. Seems it
looked up for the assign operator for each of the reference structure members
even though nothing special was required for assignment.

Forcing compiler to use simple memory copy gives speedup of like 2-3 times.

The issue doesn't happen with OSX's clang and new gcc-4.9, but since we're
gonna to stick to gcc-4.7 for official releases for quite some time still it's
nice to have performance issues resolved for all the compilers.

Didn't put the code into #ifdef so if in the future some issues appears with
alignment or assignment which need to happen as an operator we notice this
earlier.
2014-11-24 18:50:46 +05:00
Sergey Sharybin
c1149198b5 Cycles: Log time spent on the BVH build 2014-11-24 18:50:46 +05:00
Sergey Sharybin
6212b7302c Cycles: Rebuild BVH from scratch if loading cache failed
Before this Cycles used to try using the cache even so it knew for the
fact that reading it from the disk failed. This change doesn't make it
more stable if someone will try to trick Cycles and give malformed data
but it solves general cases when Blender crashed during the cache write
and will preserve rendering from crashing when trying to use that partial
cache.
2014-09-01 18:05:10 +06:00
Campbell Barton
9c3025cd26 Spelling 2014-08-02 16:53:52 +10:00
Campbell Barton
8d16869d83 Code cleanup: Add -Werror=float-conversion to Cycles 2014-05-03 07:31:46 +10:00
6974b69c61 Cycles: optimization for hair BVH build, allow max 2 hair curves per leaf.
This gives me 14% reduction in render time for koro_final.blend.
2014-04-22 17:15:41 +02:00
John Pavel
f8cd3d974d Code cleanup: add some asserts and fix a typo in BVH build.
Reviewed By: brecht

Differential Revision: https://developer.blender.org/D467
2014-04-21 14:44:36 +02:00
7ed9d1b402 Fix T39523: cycles cache BVH not working correct with deformation motion blur. 2014-04-02 20:51:29 +02:00
e2184c653e Cycles: add support for curve deformation motion blur. 2014-03-29 13:03:47 +01:00
6020d00990 Cycles: add support for mesh deformation motion blur. 2014-03-29 13:03:47 +01:00
934767cf7f Cycles code refactor: change curve key to float4 for easier storage as attribute. 2014-03-29 13:03:46 +01:00
0509553b5e Cycles code refactor: changes to make adding new primitive types easier. 2014-03-29 13:03:46 +01:00
Campbell Barton
48c1e0c0fc spelling: use American spelling for canceled 2013-10-26 01:06:19 +00:00
Brecht Van Lommel
e1a57e7858 Fix #36750: windows crash with empty cycles scene, can't do &references[0] with
MSVC when references is an empty vector.
2013-09-17 15:03:01 +00:00
Brecht Van Lommel
2228c455f9 Fix #36738: object ray visibility flags not working in cycles viewport if there
is only a single object in the scene.
2013-09-16 21:05:43 +00:00
Stuart Broadfoot
2fd11a6617 Updates for the Cycle Hair UI. With the following changes
- Removed the cycles subdivision and interpolation of hairkeys.
- Removed the parent settings.
- Removed all of the advanced settings and presets.
- This simplifies the UI to a few settings for the primitive type and a shape mode.
2013-08-18 13:41:53 +00:00
Thomas Dinges
5ce3588c6c Cycles:
* Increase the maximum amount of closures per shader from 16 to 64, so more complex closure trees can be rendered.

I measured performance on CPU and GPU (Geforce 540M) and couldn't find a performance impact, but if someone encounters a noticeable impact on his system, please report.
2013-07-30 09:26:45 +00:00
Brecht Van Lommel
484d765bd4 Cycles: attempt to fix internal compile error with some visual studio builds 2013-06-18 13:19:16 +00:00
Brecht Van Lommel
d57c6748c4 Cycles: optimization for BVH traveral on CPU's with SSE3, using code from Embree.
On the BMW scene, this gives roughly a 10% speedup overall with clang/gcc, and 30%
speedup with visual studio (2008). It turns out visual studio was optimizing the
existing code quite poorly compared to pretty good autovectorization by clang/gcc,
but hand written SSE code also gives a smaller speed boost there.

This code isn't enabled when using the hair minimum width feature yet, need to
make that work with the SSE code still.
2013-06-18 09:36:06 +00:00
Thomas Dinges
9e4914e055 Cycles:
* Revert r57203 (len() renaming)
There seems to be a problem with nVidia OpenCL after this and I haven't figured out the real cause yet. 
Better to selectively enable native length() later, after figuring out what's wrong. 

This fixes [#35612].
2013-06-04 17:20:00 +00:00
Thomas Dinges
c5ed6765b9 Cycles / Math functions:
* Rename some math functions:
len -> length
len_squared -> length_squared
normalize_len -> normalize_length

* This way OpenCL uses its inbuilt length() function, rather than our own. The other two functions have been renamed for consistency. 
* Tested CPU, CUDA and OpenCL compile, should be no functional changes.
2013-06-02 20:39:32 +00:00
Thomas Dinges
1f3bf34ccd Cycles :
* Use is_zero(a) rather than dot(a, a) == 0, saves some calculations.
2013-05-14 18:31:55 +00:00
Brecht Van Lommel
48a6fe86ca Fix #34172: cycles BVH build crashing in some rare circumstances on 32 bit linux.
The problem was (again) the x86 extended precision float register being used for
one float value while the other was rounded to lower precision. This caused the
strictly weak order requirement for std::sort to be broken.
2013-04-26 02:18:29 +00:00
Stuart Broadfoot
638b084f82 Cycles Hair: Strand Minimum Pixel Size
Code is added to restrict the pixel size of strands in cycles. It works best with ribbon primitives and a preset for these is included. It uses distance dependent expansion of the strands and then stochastic strand removal to give a fading. To prevent a slowdown for triangle mesh objects in the BVH an extra visibility flag has been added. It is also only applied for camera rays.

The strand width settings are also changed, so that the particle size is not included in the width calculation. Instead there is a separate particle system parameter for width scaling.
2013-04-15 21:38:31 +00:00