Commit Graph

286 Commits

Author SHA1 Message Date
Brecht Van Lommel
d7d40745fa Cycles: changes to source code folders structure
* Split render/ into scene/ and session/. The scene/ folder now contains the
  scene and its nodes. The session/ folder contains the render session and
  associated data structures like drivers and render buffers.
* Move top level kernel headers into new folders kernel/camera/, kernel/film/,
  kernel/light/, kernel/sample/, kernel/util/
* Move integrator related kernel headers into kernel/integrator/
* Move OSL shaders from kernel/shaders/ to kernel/osl/shaders/

For patches and branches, git merge and rebase should be able to detect the
renames and move over code to the right file.
2021-10-26 15:36:39 +02:00
Brecht Van Lommel
fd77a28031 Cycles: bake transparent shadows for hair
These transparent shadows can be expansive to evaluate. Especially on the
GPU they can lead to poor occupancy when only some pixels require many kernel
launches to trace and evaluate many layers of transparency.

Baked transparency allows tracing a single ray in many cases by accumulating
the throughput directly in the intersection program without recording hits
or evaluating shaders. Transparency is baked at curve vertices and
interpolated, for most shaders this will look practically the same as actual
shader evaluation.

Fixes T91428, performance regression with spring demo file due to transparent
hair, and makes it render significantly faster than Blender 2.93.

Differential Revision: https://developer.blender.org/D12880
2021-10-19 15:11:09 +02:00
Brecht Van Lommel
1df3b51988 Cycles: replace integrator state argument macros
* Rename struct KernelGlobals to struct KernelGlobalsCPU
* Add KernelGlobals, IntegratorState and ConstIntegratorState typedefs
  that every device can define in its own way.
* Remove INTEGRATOR_STATE_ARGS and INTEGRATOR_STATE_PASS macros and
  replace with these new typedefs.
* Add explicit state argument to INTEGRATOR_STATE and similar macros

In preparation for decoupling main and shadow paths.

Differential Revision: https://developer.blender.org/D12888
2021-10-18 19:02:10 +02:00
Brecht Van Lommel
5d565062ed Cleanup: refactor OptiX shadow intersection for upcoming changes 2021-10-15 15:42:44 +02:00
Campbell Barton
c1c6c11ca6 Cleanup: spelling in comments 2021-10-12 17:55:02 +11:00
Brecht Van Lommel
23791db145 Fix Cycles random walk SSS differences between CPU and GPU
The Embree logic did not match the GPU.
2021-10-07 21:35:24 +02:00
Brecht Van Lommel
04857cc8ef Cycles: fully decouple triangle and curve primitive storage from BVH2
Previously the storage here was optimized to avoid indirections in BVH2
traversal. This helps improve performance a bit, but makes performance
and memory usage of Embree and OptiX BVHs a bit worse also. It also adds
code complexity in other parts of the code.

Now decouple triangle and curve primitive storage from BVH2.
* Reduced peak memory usage on all devices
* Bit better performance for OptiX and Embree
* Bit worse performance for CUDA
* Simplified code:
** Intersection.prim/object now matches ShaderData.prim/object
** No more offset manipulation for mesh displacement before a BVH is built
** Remove primitive packing code and flags for Embree and OptiX
** Curve segments are now stored in a KernelCurve struct
* Also happens to fix a bug in baking with incorrect prim/object

Fixes T91968, T91770, T91902

Differential Revision: https://developer.blender.org/D12766
2021-10-06 17:52:04 +02:00
Brecht Van Lommel
18c6314e26 Cleanup: don't detect duplicate intersections in Embree
It's unclear why this code was added in the first place, but it seems
unnecessary, it can be restored if we find this breaks something.

The Embree docs mention that the same primitive may be hit multiple times, but
my understanding is that about e.g. curves where both the frontside and backside
may be hit. However those hits would be at different distances.

The context for this change is that we want to add an optimization where we
can immediately update throughput for transparent shadows instead of recording
intersections, and avoid duplicate would require extra work. However there is
an Embree example that does something similar without worrying about duplicate
hits either.
2021-10-06 14:21:11 +02:00
Campbell Barton
6d2b486e43 Cleanup: spelling in comments 2021-10-06 09:28:00 +11:00
Brecht Van Lommel
367775ac6a Fix Cycles use of uninitialized value in volume stack intersection on CPU
Could cause an actual bug but probability is low in practice.
2021-09-29 16:37:32 +02:00
Brecht Van Lommel
0803119725 Cycles: merge of cycles-x branch, a major update to the renderer
This includes much improved GPU rendering performance, viewport interactivity,
new shadow catcher, revamped sampling settings, subsurface scattering anisotropy,
new GPU volume sampling, improved PMJ sampling pattern, and more.

Some features have also been removed or changed, breaking backwards compatibility.
Including the removal of the OpenCL backend, for which alternatives are under
development.

Release notes and code docs:
https://wiki.blender.org/wiki/Reference/Release_Notes/3.0/Cycles
https://wiki.blender.org/wiki/Source/Render/Cycles

Credits:
* Sergey Sharybin
* Brecht Van Lommel
* Patrick Mours (OptiX backend)
* Christophe Hery (subsurface scattering anisotropy)
* William Leeson (PMJ sampling pattern)
* Alaska (various fixes and tweaks)
* Thomas Dinges (various fixes)

For the full commit history, see the cycles-x branch. This squashes together
all the changes since intermediate changes would often fail building or tests.

Ref T87839, T87837, T87836
Fixes T90734, T89353, T80267, T80267, T77185, T69800
2021-09-21 14:55:54 +02:00
Campbell Barton
1d8648b13a Cleanup: repeated terms in code comments & error messages 2021-06-28 15:46:08 +10:00
Campbell Barton
f1e4903854 Cleanup: full sentences in comments, improve comment formatting 2021-06-26 21:50:48 +10:00
Campbell Barton
4b9ff3cd42 Cleanup: comment blocks, trailing space in comments 2021-06-24 15:59:34 +10:00
Brecht Van Lommel
0456223cde Fix T87793: Cycles OptiX crash hiding objects in viewport render 2021-05-19 18:30:43 +02:00
Patrick Mours
f4f8b6dde3 Cycles: Change device-only memory to actually only allocate on the device
This patch changes the `MEM_DEVICE_ONLY` type to only allocate on the device and fail if
that is not possible anymore because out-of-memory (since OptiX acceleration structures may
not be allocated in host memory). It also fixes high peak memory usage during OptiX
acceleration structure building.

Reviewed By: brecht

Maniphest Tasks: T85985

Differential Revision: https://developer.blender.org/D10535
2021-03-11 14:12:35 +01:00
Brecht Van Lommel
5da418d4e6 Fix Cycles build error without Embree on Windows
Don't use ssize_t, it's not available in MSVC.
2021-03-01 16:33:31 +01:00
Brecht Van Lommel
68dd7617d7 Cycles: add utility functions for zero float2/float3/float4/transform
Ref D8237, T78710
2021-02-17 16:26:24 +01:00
Brecht Van Lommel
8119f0aad2 Cycles: refactor intrinsic functions implementation
* Add processor independent fallbacks
* Use uint32_t and uint64_t types
* Remove unused functions
* Better comments and less indentation

Ref D8237, T78710
2021-02-17 16:26:24 +01:00
Brecht Van Lommel
4ce57f6eb8 macOS: fix Cycles not detecting 64 bit and failing to build with Embree
Contributed by Apple

Ref D9527, T78710
2021-02-15 20:22:34 +01:00
Campbell Barton
17e1e2bfd8 Cleanup: correct spelling in comments 2021-02-05 16:23:34 +11:00
Patrick Mours
166c0db3f9 Fix T83915: Subdivision Surface modifier causes visual artifacts in Cycles rendered viewport - CPU and OptiX
Changing the geometry in the current scene caused the primitive offsets for all geometry to
change, but the values would not be updated in all bottom-level BVH structures. Rendering
artifacts and crashes where the result. This fixes that by ensuring all BVH structures are
updated when the primitive offsets change.
2021-01-05 17:59:38 +01:00
Patrick Mours
bfb6fce659 Cycles: Add CPU+GPU rendering support with OptiX
Adds support for building multiple BVH types in order to support using both CPU and OptiX
devices for rendering simultaneously. Primitive packing for Embree and OptiX is now
standalone, so it only needs to be run once and can be shared between the two. Additionally,
BVH building was made a device call, so that each device backend can decide how to
perform the building. The multi-device for instance creates a special multi-BVH that holds
references to several sub-BVHs, one for each sub-device.

Reviewed By: brecht, kevindietrich

Differential Revision: https://developer.blender.org/D9718
2020-12-11 13:24:29 +01:00
Kévin Dietrich
31a620b942 Cycles API: encapsulate Node socket members
This encapsulates Node socket members behind a set of specific methods;
as such it is no longer possible to directly access Node class members
from exporters and parts of Cycles.

The methods are defined via the NODE_SOCKET_API macros in `graph/
node.h`, and are for getting or setting a specific socket's value, as
well as querying or modifying the state of its update flag.

The setters will check whether the value has changed and tag the socket
as modified appropriately. This will let us know how a Node has changed
and what to update, which is the first concrete step toward a more
granular scene update system.

Since the setters will tag the Node sockets as modified when passed
different data, this patch also removes the various modified methods
on Nodes in favor of Node::is_modified which checks the sockets'
update flags status.

Reviewed By: brecht

Maniphest Tasks: T79174

Differential Revision: https://developer.blender.org/D8544
2020-11-04 13:03:33 +01:00
Kévin Dietrich
57d1aea64f Cycles: add support for BVH refit in OptiX
This avoids recomputing the BVH for geometries that do not have changes in topology but whose vertices are modified (like a simple character animation), and gives up to 40% speedup for BVH building.

This is only available for viewport renders at the moment.

Reviewed By: pmoursnv, brecht

Differential Revision: https://developer.blender.org/D9353
2020-11-03 18:05:29 +01:00
Dalai Felinto
4a8146eb8f Cycles: silence unused variable warning 2020-10-29 18:33:29 +01:00
Brecht Van Lommel
6d8e03ddd9 Fix T81102: Cycles crashes in interactive 3D viewport rendering after Embree
Don't allocate a new buffer for refitting meshes, but update the existing one.
It's not clear from the API docs if this is required, but it appears to solve
the issue and should be more efficient.
2020-10-23 18:32:22 +02:00
Harley Acheson
3a7fd309fc Spelling: It's Versus Its
Corrects incorrect usage of contraction for 'it is', when possessive 'its' was required.

Differential Revision: https://developer.blender.org/D9250

Reviewed by Campbell Barton
2020-10-19 08:12:33 -07:00
Brecht Van Lommel
f04260d8c6 CMake: refresh building and external library handling of Cycles standalone
* Support precompiled libraries on Linux
* Add license headers
* Refactoring to deduplicate code

Includes work by Ray Molenkamp and Grische for precompiled libraries.

Ref D8769
2020-09-04 17:10:50 +02:00
Stefan Werner
009971ba7a Cycles: Separate Embree device for each CPU Device.
Before, Cycles was using a shared Embree device across all instances.
This could result in crashes when viewport rendering and material
preview were using Cycles simultaneously.

Fixes issue T80042

Maniphest Tasks: T80042

Differential Revision: https://developer.blender.org/D8772
2020-09-01 21:00:55 +02:00
Kévin Dietrich
aa1e4baa22 Cycles : add a Volume Geometry Node
This splits the volume related data (properties for rendering and attributes) of the Mesh node
into a new `Volume` node type.

This `Volume` node derives from the `Mesh` class since we generate a mesh for the bounds of the
volume, as such we can safely work on `Volumes` as if they were `Meshes`, e.g. for BVH creation.
However such code should still check for the geometry type of the object to be `MESH` or `VOLUME`
which may be bug prone if this is forgotten.

This is part of T79131.

Reviewed By: brecht

Maniphest Tasks: T79131

Differential Revision: https://developer.blender.org/D8538
2020-08-19 15:47:09 +02:00
Stefan Werner
d88721879b Cycles: Fix local intersections in Embree for non-instancd geometry.
Embree's occlusion filter was checking against the wrong object ID
and not exiting correctly in case of a mismatch.

Fixes T79723
2020-08-17 16:04:01 +02:00
Brecht Van Lommel
2c41c8e94f Cycles: internal refactoring to make thick/ribbon curve separate primitives
Also removing the curve system manager which only stored a few curve intersection
settings. These are all changes towards making shape and subdivision settings
per-object instead of per-scene, but there is more work to do here.

Ref T73778

Depends on D8013

Maniphest Tasks: T73778

Differential Revision: https://developer.blender.org/D8014
2020-06-22 13:28:01 +02:00
Brecht Van Lommel
d1ef5146d7 Cycles: remove SIMD BVH optimizations, to be replaced by Embree
Ref T73778

Depends on D8011

Maniphest Tasks: T73778

Differential Revision: https://developer.blender.org/D8012
2020-06-22 13:28:01 +02:00
Brecht Van Lommel
fed101a7be Cycles: always perform backface culling for curve, remove option
The hair BSDFs are already designed to assume this, and disabling backface
culling would break them in some cases.

Ref T73778

Depends on D8009

Maniphest Tasks: T73778

Differential Revision: https://developer.blender.org/D8010
2020-06-22 13:28:01 +02:00
Brecht Van Lommel
c7d940278b Cycles: remove support for rendering hair as triangle and lines
Triangles were very memory intensive. The only reason they were not removed yet
is that they gave more accurate results, but there will be an accurate 3D curve
primitive added for this.

Line rendering was always poor quality since the ends do not match up. To keep CPU
and GPU compatibility we just remove them entirely. They could be brought back if
an Embree compatible implementation is added, but it's not clear to me that there
is a use case for these that we'd consider important.

Ref T73778

Reviewers: #cycles

Subscribers:
2020-06-22 13:28:01 +02:00
Brecht Van Lommel
e50f1ddc65 Cycles: use TBB for task pools and task scheduler
No significant performance improvement is expected, but it means we have a
single thread pool throughout Blender. And it should make adding more
parallellization in the future easier.

After previous refactoring commits this is basically a drop-in replacement.
One difference is that the task pool had a mechanism for scheduling tasks to
the front of the queue to minimize memory usage. TBB has a smarter algorithm
to balance depth-first and breadth-first scheduling of tasks and we assume that
removes the need to manually provide hints to the scheduler.

Fixes T77533
2020-06-22 13:27:37 +02:00
Brecht Van Lommel
b10b7cdb43 Cleanup: use lambdas instead of functors for task pools, remove threadid 2020-06-22 13:06:47 +02:00
Brecht Van Lommel
d8c2092b15 Cycles: make TBB a required library dependency, and use in a few places
Now that the rest of Blender also relies on TBB, no point in maintaining custom
code for paraller_for and thread local storage.
2020-06-22 13:06:47 +02:00
Brecht Van Lommel
ace3268482 Cleanup: minor refactoring around DeviceTask 2020-06-22 13:06:47 +02:00
41866070d3 Cleanup: remove unused flag 2020-06-04 14:37:20 +02:00
Stefan Werner
ecc15c55d4 Cycles: Upgraded Embree to version 3.10.0
Enabled round linear hair in Embree.

Differential Revision: https://developer.blender.org/D7623
2020-05-27 10:10:18 +02:00
Patrick Mours
f5237f7704 Fix long OptiX BVH build times in Cycles with many objects
Looping over all primitives for every object is really slow, so this patch avoids that by moving
the necessary assignments inline with the primitive merging done for every geometry.
2020-04-30 17:57:01 +02:00
Dalai Felinto
2d1cce8331 Cleanup: make format after SortedIncludes change 2020-03-19 09:33:58 +01:00
Brecht Van Lommel
5a169ae2f3 Cleanup: remove foreach include from header, conflicts with OpenVDB 2020-03-11 20:35:38 +01:00
Giovanni Remigi
19b46b2fca Fix Cycles crash in BVH8 build due to out of bounds memory access
Differential Revision: https://developer.blender.org/D7114
2020-03-11 17:35:11 +01:00
f61f26b033 Fix Cycles Embree hair + motion blur failing after recent Catmull-Rom change
Ref T73778
2020-02-24 20:29:36 +01:00
Stefan Werner
b4ae962447 Cycles: Switched Embree to use Catmull-Rom curves.
The latest versions of Embree support Catmull-Rom splines
which use less memory than the previously used Hermite splines.
The representation is also much closer to Cycles own data structures
and can hopefully be unified in the future for more memory savings.

Memory savings using Victor benchmark scene:
Compared to previous Embree: ~400MB
Compared to Cycles' native BVH: ~1GB
2020-02-20 13:05:27 +01:00
Brecht Van Lommel
cef4d344f9 Fix Embree failing on objects with a very high number of motion steps
Set the limit to 129 to match Embree. This applies to all devices for
consistent render results.

Ref T73778
2020-02-18 15:38:11 +01:00
Brecht Van Lommel
1761d65b25 Fix Cycles Embree test failures with shadow catcher
Ref T73778
2020-02-18 00:45:30 +01:00