├── .clang-format ├── .github └── workflows │ └── ci.yaml ├── .gitignore ├── AUTHORS ├── BUILDING.md ├── CMakeLists.txt ├── DockerfileHIP ├── DockerfileOneAPI ├── GNUmakefile ├── LICENSE ├── README.md ├── build_cycles_for_rhino.ps1 ├── examples ├── objects │ ├── cube.xml │ ├── sphere.xml │ └── suzanne.xml ├── osl │ └── stripes.osl ├── scene_cube_surface.xml ├── scene_cube_volume.xml ├── scene_monkey.xml ├── scene_osl_stripes.xml ├── scene_sphere_bump.xml └── scene_world_volume.xml ├── make.bat ├── make_hip.sh ├── make_oneapi.sh ├── make_rhino.bat ├── src ├── CMakeLists.txt ├── app │ ├── CMakeLists.txt │ ├── cycles_standalone.cpp │ ├── cycles_xml.cpp │ ├── cycles_xml.h │ ├── io_export_cycles_xml.py │ ├── oiio_output_driver.cpp │ ├── oiio_output_driver.h │ └── opengl │ │ ├── display_driver.cpp │ │ ├── display_driver.h │ │ ├── shader.cpp │ │ ├── shader.h │ │ ├── window.cpp │ │ └── window.h ├── bvh │ ├── CMakeLists.txt │ ├── binning.cpp │ ├── binning.h │ ├── build.cpp │ ├── build.h │ ├── bvh.cpp │ ├── bvh.h │ ├── bvh2.cpp │ ├── bvh2.h │ ├── embree.cpp │ ├── embree.h │ ├── metal.h │ ├── metal.mm │ ├── multi.cpp │ ├── multi.h │ ├── node.cpp │ ├── node.h │ ├── optix.cpp │ ├── optix.h │ ├── params.h │ ├── sort.cpp │ ├── sort.h │ ├── split.cpp │ ├── split.h │ ├── unaligned.cpp │ └── unaligned.h ├── ccycles │ ├── .clang-format │ ├── CMakeLists.txt │ ├── background.cpp │ ├── camera.cpp │ ├── ccsession.cpp │ ├── ccycles.cpp │ ├── ccycles.h │ ├── ccycles_version.rc │ ├── device.cpp │ ├── film.cpp │ ├── fshader.h │ ├── integrator.cpp │ ├── internal_types.h │ ├── license.txt │ ├── light.cpp │ ├── mesh.cpp │ ├── mikktspace.c │ ├── mikktspace.h │ ├── object.cpp │ ├── scene.cpp │ ├── scene_parameters.cpp │ ├── session_parameters.cpp │ ├── shader.cpp │ ├── transform.cpp │ ├── version.h │ └── vshader.h ├── cmake │ ├── Modules │ │ ├── FindAlembic.cmake │ │ ├── FindBlosc.cmake │ │ ├── FindClang.cmake │ │ ├── FindEmbree.cmake │ │ ├── FindEpoxy.cmake │ │ ├── FindGLEW.cmake │ │ ├── FindGflags.cmake │ │ ├── FindGlog.cmake │ │ ├── FindHIP.cmake │ │ ├── FindLLVM.cmake │ │ ├── FindLevelZero.cmake │ │ ├── FindLibEpoxy.cmake │ │ ├── FindNanoVDB.cmake │ │ ├── FindOSL.cmake │ │ ├── FindOpenColorIO.cmake │ │ ├── FindOpenEXR.cmake │ │ ├── FindOpenImageDenoise.cmake │ │ ├── FindOpenImageIO.cmake │ │ ├── FindOpenJPEG.cmake │ │ ├── FindOpenSubdiv.cmake │ │ ├── FindOpenVDB.cmake │ │ ├── FindOptiX.cmake │ │ ├── FindPugiXML.cmake │ │ ├── FindPythonLibsUnix.cmake │ │ ├── FindSDL2.cmake │ │ ├── FindSYCL.cmake │ │ ├── FindTBB.cmake │ │ ├── FindUSD.cmake │ │ ├── FindUSDHoudini.cmake │ │ ├── FindUSDPixar.cmake │ │ ├── FindWebP.cmake │ │ └── Findsse2neon.cmake │ ├── compiler_utils.cmake │ ├── configure_build.cmake │ ├── detect_platform.cmake │ ├── external_libs.cmake │ ├── macros.cmake │ ├── make_format.py │ ├── make_update.py │ ├── make_utils.py │ └── msvc_arch_flags.c ├── device │ ├── CMakeLists.txt │ ├── cpu │ │ ├── device.cpp │ │ ├── device.h │ │ ├── device_impl.cpp │ │ ├── device_impl.h │ │ ├── kernel.cpp │ │ ├── kernel.h │ │ ├── kernel_function.h │ │ ├── kernel_thread_globals.cpp │ │ └── kernel_thread_globals.h │ ├── cuda │ │ ├── device.cpp │ │ ├── device.h │ │ ├── device_impl.cpp │ │ ├── device_impl.h │ │ ├── graphics_interop.cpp │ │ ├── graphics_interop.h │ │ ├── kernel.cpp │ │ ├── kernel.h │ │ ├── queue.cpp │ │ ├── queue.h │ │ ├── util.cpp │ │ └── util.h │ ├── denoise.cpp │ ├── denoise.h │ ├── device.cpp │ ├── device.h │ ├── dummy │ │ ├── device.cpp │ │ └── device.h │ ├── graphics_interop.cpp │ ├── graphics_interop.h │ ├── hip │ │ ├── device.cpp │ │ ├── device.h │ │ ├── device_impl.cpp │ │ ├── device_impl.h │ │ ├── graphics_interop.cpp │ │ ├── graphics_interop.h │ │ ├── kernel.cpp │ │ ├── kernel.h │ │ ├── queue.cpp │ │ ├── queue.h │ │ ├── util.cpp │ │ └── util.h │ ├── kernel.cpp │ ├── kernel.h │ ├── memory.cpp │ ├── memory.h │ ├── metal │ │ ├── bvh.h │ │ ├── bvh.mm │ │ ├── device.h │ │ ├── device.mm │ │ ├── device_impl.h │ │ ├── device_impl.mm │ │ ├── kernel.h │ │ ├── kernel.mm │ │ ├── queue.h │ │ ├── queue.mm │ │ ├── util.h │ │ └── util.mm │ ├── multi │ │ ├── device.cpp │ │ └── device.h │ ├── oneapi │ │ ├── device.cpp │ │ ├── device.h │ │ ├── device_impl.cpp │ │ ├── device_impl.h │ │ ├── queue.cpp │ │ └── queue.h │ ├── optix │ │ ├── device.cpp │ │ ├── device.h │ │ ├── device_impl.cpp │ │ ├── device_impl.h │ │ ├── queue.cpp │ │ ├── queue.h │ │ └── util.h │ ├── queue.cpp │ └── queue.h ├── doc │ ├── CMakeLists.txt │ └── license │ │ ├── Apache2-license.txt │ │ ├── BSD-3-Clause-license.txt │ │ ├── CMakeLists.txt │ │ ├── MIT-license.txt │ │ ├── SPDX-license-identifiers.txt │ │ ├── Zlib-license.txt │ │ └── readme.txt ├── graph │ ├── CMakeLists.txt │ ├── node.cpp │ ├── node.h │ ├── node_enum.h │ ├── node_type.cpp │ ├── node_type.h │ ├── node_xml.cpp │ └── node_xml.h ├── hydra │ ├── CMakeLists.txt │ ├── attribute.cpp │ ├── attribute.h │ ├── camera.cpp │ ├── camera.h │ ├── config.h │ ├── curves.cpp │ ├── curves.h │ ├── display_driver.cpp │ ├── display_driver.h │ ├── field.cpp │ ├── field.h │ ├── file_reader.cpp │ ├── file_reader.h │ ├── geometry.h │ ├── geometry.inl │ ├── instancer.cpp │ ├── instancer.h │ ├── light.cpp │ ├── light.h │ ├── material.cpp │ ├── material.h │ ├── mesh.cpp │ ├── mesh.h │ ├── node_util.cpp │ ├── node_util.h │ ├── output_driver.cpp │ ├── output_driver.h │ ├── plugInfo.json │ ├── plugin.cpp │ ├── plugin.h │ ├── pointcloud.cpp │ ├── pointcloud.h │ ├── render_buffer.cpp │ ├── render_buffer.h │ ├── render_delegate.cpp │ ├── render_delegate.h │ ├── render_pass.cpp │ ├── render_pass.h │ ├── resources │ │ ├── apple_symbols.map │ │ ├── cycles.json │ │ ├── linux_symbols.map │ │ └── plugInfo.json │ ├── session.cpp │ ├── session.h │ ├── volume.cpp │ └── volume.h ├── integrator │ ├── CMakeLists.txt │ ├── adaptive_sampling.cpp │ ├── adaptive_sampling.h │ ├── denoiser.cpp │ ├── denoiser.h │ ├── denoiser_gpu.cpp │ ├── denoiser_gpu.h │ ├── denoiser_oidn.cpp │ ├── denoiser_oidn.h │ ├── denoiser_optix.cpp │ ├── denoiser_optix.h │ ├── guiding.h │ ├── pass_accessor.cpp │ ├── pass_accessor.h │ ├── pass_accessor_cpu.cpp │ ├── pass_accessor_cpu.h │ ├── pass_accessor_gpu.cpp │ ├── pass_accessor_gpu.h │ ├── path_trace.cpp │ ├── path_trace.h │ ├── path_trace_display.cpp │ ├── path_trace_display.h │ ├── path_trace_tile.cpp │ ├── path_trace_tile.h │ ├── path_trace_work.cpp │ ├── path_trace_work.h │ ├── path_trace_work_cpu.cpp │ ├── path_trace_work_cpu.h │ ├── path_trace_work_gpu.cpp │ ├── path_trace_work_gpu.h │ ├── render_scheduler.cpp │ ├── render_scheduler.h │ ├── shader_eval.cpp │ ├── shader_eval.h │ ├── tile.cpp │ ├── tile.h │ ├── work_balancer.cpp │ ├── work_balancer.h │ ├── work_tile_scheduler.cpp │ └── work_tile_scheduler.h ├── kernel │ ├── CMakeLists.txt │ ├── bake │ │ └── bake.h │ ├── bvh │ │ ├── bvh.h │ │ ├── local.h │ │ ├── nodes.h │ │ ├── shadow_all.h │ │ ├── traversal.h │ │ ├── types.h │ │ ├── util.h │ │ ├── volume.h │ │ └── volume_all.h │ ├── camera │ │ ├── camera.h │ │ └── projection.h │ ├── closure │ │ ├── alloc.h │ │ ├── bsdf.h │ │ ├── bsdf_ashikhmin_shirley.h │ │ ├── bsdf_ashikhmin_velvet.h │ │ ├── bsdf_diffuse.h │ │ ├── bsdf_diffuse_ramp.h │ │ ├── bsdf_hair.h │ │ ├── bsdf_hair_principled.h │ │ ├── bsdf_microfacet.h │ │ ├── bsdf_microfacet_multi.h │ │ ├── bsdf_microfacet_multi_impl.h │ │ ├── bsdf_oren_nayar.h │ │ ├── bsdf_phong_ramp.h │ │ ├── bsdf_principled_diffuse.h │ │ ├── bsdf_principled_sheen.h │ │ ├── bsdf_reflection.h │ │ ├── bsdf_refraction.h │ │ ├── bsdf_toon.h │ │ ├── bsdf_transparent.h │ │ ├── bsdf_util.h │ │ ├── bssrdf.h │ │ ├── emissive.h │ │ └── volume.h │ ├── data_arrays.h │ ├── data_template.h │ ├── device │ │ ├── cpu │ │ │ ├── bvh.h │ │ │ ├── compat.h │ │ │ ├── globals.h │ │ │ ├── image.h │ │ │ ├── kernel.cpp │ │ │ ├── kernel.h │ │ │ ├── kernel_arch.h │ │ │ ├── kernel_arch_impl.h │ │ │ ├── kernel_avx2.cpp │ │ │ ├── kernel_sse2.cpp │ │ │ └── kernel_sse41.cpp │ │ ├── cuda │ │ │ ├── compat.h │ │ │ ├── config.h │ │ │ ├── globals.h │ │ │ └── kernel.cu │ │ ├── gpu │ │ │ ├── image.h │ │ │ ├── kernel.h │ │ │ ├── parallel_active_index.h │ │ │ ├── parallel_prefix_sum.h │ │ │ ├── parallel_sorted_index.h │ │ │ └── work_stealing.h │ │ ├── hip │ │ │ ├── compat.h │ │ │ ├── config.h │ │ │ ├── globals.h │ │ │ └── kernel.cpp │ │ ├── metal │ │ │ ├── bvh.h │ │ │ ├── compat.h │ │ │ ├── context_begin.h │ │ │ ├── context_end.h │ │ │ ├── function_constants.h │ │ │ ├── globals.h │ │ │ └── kernel.metal │ │ ├── oneapi │ │ │ ├── compat.h │ │ │ ├── context_begin.h │ │ │ ├── context_end.h │ │ │ ├── globals.h │ │ │ ├── image.h │ │ │ ├── kernel.cpp │ │ │ ├── kernel.h │ │ │ └── kernel_templates.h │ │ └── optix │ │ │ ├── bvh.h │ │ │ ├── compat.h │ │ │ ├── globals.h │ │ │ ├── kernel.cu │ │ │ ├── kernel_osl.cu │ │ │ └── kernel_shader_raytrace.cu │ ├── film │ │ ├── adaptive_sampling.h │ │ ├── aov_passes.h │ │ ├── cryptomatte_passes.h │ │ ├── data_passes.h │ │ ├── denoising_passes.h │ │ ├── light_passes.h │ │ ├── read.h │ │ └── write.h │ ├── geom │ │ ├── attribute.h │ │ ├── curve.h │ │ ├── curve_intersect.h │ │ ├── geom.h │ │ ├── motion_curve.h │ │ ├── motion_point.h │ │ ├── motion_triangle.h │ │ ├── motion_triangle_intersect.h │ │ ├── motion_triangle_shader.h │ │ ├── object.h │ │ ├── patch.h │ │ ├── point.h │ │ ├── point_intersect.h │ │ ├── primitive.h │ │ ├── shader_data.h │ │ ├── subd_triangle.h │ │ ├── triangle.h │ │ ├── triangle_intersect.h │ │ └── volume.h │ ├── integrator │ │ ├── displacement_shader.h │ │ ├── guiding.h │ │ ├── init_from_bake.h │ │ ├── init_from_camera.h │ │ ├── intersect_closest.h │ │ ├── intersect_shadow.h │ │ ├── intersect_subsurface.h │ │ ├── intersect_volume_stack.h │ │ ├── megakernel.h │ │ ├── mnee.h │ │ ├── path_state.h │ │ ├── shade_background.h │ │ ├── shade_light.h │ │ ├── shade_shadow.h │ │ ├── shade_surface.h │ │ ├── shade_volume.h │ │ ├── shadow_catcher.h │ │ ├── shadow_state_template.h │ │ ├── state.h │ │ ├── state_flow.h │ │ ├── state_template.h │ │ ├── state_util.h │ │ ├── subsurface.h │ │ ├── subsurface_disk.h │ │ ├── subsurface_random_walk.h │ │ ├── surface_shader.h │ │ ├── volume_shader.h │ │ └── volume_stack.h │ ├── light │ │ ├── area.h │ │ ├── background.h │ │ ├── common.h │ │ ├── distant.h │ │ ├── distribution.h │ │ ├── light.h │ │ ├── point.h │ │ ├── sample.h │ │ ├── spot.h │ │ ├── tree.h │ │ └── triangle.h │ ├── osl │ │ ├── CMakeLists.txt │ │ ├── closures.cpp │ │ ├── closures_setup.h │ │ ├── closures_template.h │ │ ├── globals.cpp │ │ ├── globals.h │ │ ├── osl.h │ │ ├── services.cpp │ │ ├── services.h │ │ ├── services_gpu.h │ │ ├── services_optix.cu │ │ ├── shaders │ │ │ ├── CMakeLists.txt │ │ │ ├── node_absorption_volume.osl │ │ │ ├── node_add_closure.osl │ │ │ ├── node_ambient_occlusion.osl │ │ │ ├── node_anisotropic_bsdf.osl │ │ │ ├── node_attribute.osl │ │ │ ├── node_background.osl │ │ │ ├── node_bevel.osl │ │ │ ├── node_blackbody.osl │ │ │ ├── node_brick_texture.osl │ │ │ ├── node_brightness.osl │ │ │ ├── node_bump.osl │ │ │ ├── node_camera.osl │ │ │ ├── node_checker_texture.osl │ │ │ ├── node_clamp.osl │ │ │ ├── node_color.h │ │ │ ├── node_color_blend.h │ │ │ ├── node_combine_color.osl │ │ │ ├── node_combine_hsv.osl │ │ │ ├── node_combine_rgb.osl │ │ │ ├── node_combine_xyz.osl │ │ │ ├── node_convert_from_color.osl │ │ │ ├── node_convert_from_float.osl │ │ │ ├── node_convert_from_int.osl │ │ │ ├── node_convert_from_normal.osl │ │ │ ├── node_convert_from_point.osl │ │ │ ├── node_convert_from_string.osl │ │ │ ├── node_convert_from_vector.osl │ │ │ ├── node_diffuse_bsdf.osl │ │ │ ├── node_displacement.osl │ │ │ ├── node_emission.osl │ │ │ ├── node_environment_texture.osl │ │ │ ├── node_float_curve.osl │ │ │ ├── node_fresnel.h │ │ │ ├── node_fresnel.osl │ │ │ ├── node_gamma.osl │ │ │ ├── node_geometry.osl │ │ │ ├── node_glass_bsdf.osl │ │ │ ├── node_glossy_bsdf.osl │ │ │ ├── node_gradient_texture.osl │ │ │ ├── node_hair_bsdf.osl │ │ │ ├── node_hair_info.osl │ │ │ ├── node_hash.h │ │ │ ├── node_holdout.osl │ │ │ ├── node_hsv.osl │ │ │ ├── node_ies_light.osl │ │ │ ├── node_image_texture.osl │ │ │ ├── node_invert.osl │ │ │ ├── node_layer_weight.osl │ │ │ ├── node_light_falloff.osl │ │ │ ├── node_light_path.osl │ │ │ ├── node_magic_texture.osl │ │ │ ├── node_map_range.osl │ │ │ ├── node_mapping.osl │ │ │ ├── node_math.h │ │ │ ├── node_math.osl │ │ │ ├── node_mix.osl │ │ │ ├── node_mix_closure.osl │ │ │ ├── node_mix_color.osl │ │ │ ├── node_mix_float.osl │ │ │ ├── node_mix_vector.osl │ │ │ ├── node_mix_vector_non_uniform.osl │ │ │ ├── node_musgrave_texture.osl │ │ │ ├── node_noise.h │ │ │ ├── node_noise_texture.osl │ │ │ ├── node_normal.osl │ │ │ ├── node_normal_map.osl │ │ │ ├── node_object_info.osl │ │ │ ├── node_output_displacement.osl │ │ │ ├── node_output_surface.osl │ │ │ ├── node_output_volume.osl │ │ │ ├── node_particle_info.osl │ │ │ ├── node_point_info.osl │ │ │ ├── node_principled_bsdf.osl │ │ │ ├── node_principled_hair_bsdf.osl │ │ │ ├── node_principled_volume.osl │ │ │ ├── node_ramp_util.h │ │ │ ├── node_refraction_bsdf.osl │ │ │ ├── node_rgb_curves.osl │ │ │ ├── node_rgb_ramp.osl │ │ │ ├── node_rgb_to_bw.osl │ │ │ ├── node_scatter_volume.osl │ │ │ ├── node_separate_color.osl │ │ │ ├── node_separate_hsv.osl │ │ │ ├── node_separate_rgb.osl │ │ │ ├── node_separate_xyz.osl │ │ │ ├── node_set_normal.osl │ │ │ ├── node_sky_texture.osl │ │ │ ├── node_subsurface_scattering.osl │ │ │ ├── node_tangent.osl │ │ │ ├── node_texture_coordinate.osl │ │ │ ├── node_toon_bsdf.osl │ │ │ ├── node_translucent_bsdf.osl │ │ │ ├── node_transparent_bsdf.osl │ │ │ ├── node_uv_map.osl │ │ │ ├── node_value.osl │ │ │ ├── node_vector_curves.osl │ │ │ ├── node_vector_displacement.osl │ │ │ ├── node_vector_map_range.osl │ │ │ ├── node_vector_math.osl │ │ │ ├── node_vector_rotate.osl │ │ │ ├── node_vector_transform.osl │ │ │ ├── node_velvet_bsdf.osl │ │ │ ├── node_vertex_color.osl │ │ │ ├── node_voronoi_texture.osl │ │ │ ├── node_voxel_texture.osl │ │ │ ├── node_wave_texture.osl │ │ │ ├── node_wavelength.osl │ │ │ ├── node_white_noise_texture.osl │ │ │ ├── node_wireframe.osl │ │ │ └── stdcycles.h │ │ └── types.h │ ├── sample │ │ ├── lcg.h │ │ ├── mapping.h │ │ ├── mis.h │ │ ├── pattern.h │ │ ├── sobol_burley.h │ │ ├── tabulated_sobol.h │ │ └── util.h │ ├── svm │ │ ├── ao.h │ │ ├── aov.h │ │ ├── attribute.h │ │ ├── bevel.h │ │ ├── blackbody.h │ │ ├── brick.h │ │ ├── brightness.h │ │ ├── bump.h │ │ ├── camera.h │ │ ├── checker.h │ │ ├── clamp.h │ │ ├── closure.h │ │ ├── color_util.h │ │ ├── convert.h │ │ ├── displace.h │ │ ├── fractal_noise.h │ │ ├── fresnel.h │ │ ├── gamma.h │ │ ├── geometry.h │ │ ├── gradient.h │ │ ├── hsv.h │ │ ├── ies.h │ │ ├── image.h │ │ ├── invert.h │ │ ├── light_path.h │ │ ├── magic.h │ │ ├── map_range.h │ │ ├── mapping.h │ │ ├── mapping_util.h │ │ ├── math.h │ │ ├── math_util.h │ │ ├── mix.h │ │ ├── musgrave.h │ │ ├── node_types_template.h │ │ ├── noise.h │ │ ├── noisetex.h │ │ ├── normal.h │ │ ├── ramp.h │ │ ├── ramp_util.h │ │ ├── sepcomb_color.h │ │ ├── sepcomb_hsv.h │ │ ├── sepcomb_vector.h │ │ ├── sky.h │ │ ├── svm.h │ │ ├── svm_rhino_azimuth_altitude_transform.h │ │ ├── svm_rhino_matrix_math.h │ │ ├── svm_rhino_procedurals.h │ │ ├── svm_rhino_types.h │ │ ├── tex_coord.h │ │ ├── types.h │ │ ├── value.h │ │ ├── vector_rotate.h │ │ ├── vector_transform.h │ │ ├── vertex_color.h │ │ ├── voronoi.h │ │ ├── voxel.h │ │ ├── wave.h │ │ ├── wavelength.h │ │ ├── white_noise.h │ │ └── wireframe.h │ ├── tables.h │ ├── types.h │ └── util │ │ ├── color.h │ │ ├── differential.h │ │ ├── lookup_table.h │ │ └── profiling.h ├── scene │ ├── CMakeLists.txt │ ├── alembic.cpp │ ├── alembic.h │ ├── alembic_read.cpp │ ├── alembic_read.h │ ├── attribute.cpp │ ├── attribute.h │ ├── background.cpp │ ├── background.h │ ├── bake.cpp │ ├── bake.h │ ├── camera.cpp │ ├── camera.h │ ├── colorspace.cpp │ ├── colorspace.h │ ├── constant_fold.cpp │ ├── constant_fold.h │ ├── curves.cpp │ ├── curves.h │ ├── film.cpp │ ├── film.h │ ├── geometry.cpp │ ├── geometry.h │ ├── hair.cpp │ ├── hair.h │ ├── image.cpp │ ├── image.h │ ├── image_oiio.cpp │ ├── image_oiio.h │ ├── image_sky.cpp │ ├── image_sky.h │ ├── image_vdb.cpp │ ├── image_vdb.h │ ├── integrator.cpp │ ├── integrator.h │ ├── light.cpp │ ├── light.h │ ├── light_tree.cpp │ ├── light_tree.h │ ├── mesh.cpp │ ├── mesh.h │ ├── mesh_displace.cpp │ ├── mesh_subdivision.cpp │ ├── object.cpp │ ├── object.h │ ├── osl.cpp │ ├── osl.h │ ├── particles.cpp │ ├── particles.h │ ├── pass.cpp │ ├── pass.h │ ├── pointcloud.cpp │ ├── pointcloud.h │ ├── procedural.cpp │ ├── procedural.h │ ├── rhino_shader_nodes.cpp │ ├── rhino_shader_nodes.h │ ├── scene.cpp │ ├── scene.h │ ├── shader.cpp │ ├── shader.h │ ├── shader_graph.cpp │ ├── shader_graph.h │ ├── shader_nodes.cpp │ ├── shader_nodes.h │ ├── stats.cpp │ ├── stats.h │ ├── svm.cpp │ ├── svm.h │ ├── tables.cpp │ ├── tables.h │ ├── tabulated_sobol.cpp │ ├── tabulated_sobol.h │ ├── volume.cpp │ └── volume.h ├── session │ ├── CMakeLists.txt │ ├── buffers.cpp │ ├── buffers.h │ ├── denoising.cpp │ ├── denoising.h │ ├── display_driver.h │ ├── merge.cpp │ ├── merge.h │ ├── output_driver.h │ ├── session.cpp │ ├── session.h │ ├── tile.cpp │ └── tile.h ├── subd │ ├── CMakeLists.txt │ ├── dice.cpp │ ├── dice.h │ ├── patch.cpp │ ├── patch.h │ ├── patch_table.cpp │ ├── patch_table.h │ ├── split.cpp │ ├── split.h │ └── subpatch.h ├── test │ ├── CMakeLists.txt │ ├── integrator_adaptive_sampling_test.cpp │ ├── integrator_render_scheduler_test.cpp │ ├── integrator_tile_test.cpp │ ├── render_graph_finalize_test.cpp │ ├── util_aligned_malloc_test.cpp │ ├── util_float8_avx2_test.cpp │ ├── util_float8_avx_test.cpp │ ├── util_float8_sse2_test.cpp │ ├── util_float8_test.h │ ├── util_math_test.cpp │ ├── util_md5_test.cpp │ ├── util_path_test.cpp │ ├── util_string_test.cpp │ ├── util_task_test.cpp │ ├── util_time_test.cpp │ └── util_transform_test.cpp └── util │ ├── CMakeLists.txt │ ├── algorithm.h │ ├── aligned_malloc.cpp │ ├── aligned_malloc.h │ ├── args.h │ ├── array.h │ ├── atomic.h │ ├── boundbox.h │ ├── color.h │ ├── debug.cpp │ ├── debug.h │ ├── defines.h │ ├── deque.h │ ├── disjoint_set.h │ ├── foreach.h │ ├── function.h │ ├── guarded_allocator.cpp │ ├── guarded_allocator.h │ ├── guiding.h │ ├── half.h │ ├── hash.h │ ├── ies.cpp │ ├── ies.h │ ├── image.h │ ├── image_impl.h │ ├── list.h │ ├── log.cpp │ ├── log.h │ ├── map.h │ ├── math.h │ ├── math_cdf.cpp │ ├── math_cdf.h │ ├── math_fast.h │ ├── math_float2.h │ ├── math_float3.h │ ├── math_float4.h │ ├── math_float8.h │ ├── math_int2.h │ ├── math_int3.h │ ├── math_int4.h │ ├── math_int8.h │ ├── math_intersect.h │ ├── math_matrix.h │ ├── md5.cpp │ ├── md5.h │ ├── murmurhash.cpp │ ├── murmurhash.h │ ├── openimagedenoise.h │ ├── openvdb.h │ ├── optimization.h │ ├── param.h │ ├── path.cpp │ ├── path.h │ ├── profiling.cpp │ ├── profiling.h │ ├── progress.h │ ├── projection.h │ ├── queue.h │ ├── rect.h │ ├── semaphore.h │ ├── set.h │ ├── simd.cpp │ ├── simd.h │ ├── stack_allocator.h │ ├── static_assert.h │ ├── stats.h │ ├── string.cpp │ ├── string.h │ ├── system.cpp │ ├── system.h │ ├── task.cpp │ ├── task.h │ ├── tbb.h │ ├── texture.h │ ├── thread.cpp │ ├── thread.h │ ├── time.cpp │ ├── time.h │ ├── transform.cpp │ ├── transform.h │ ├── transform_avx2.cpp │ ├── transform_inverse.h │ ├── transform_sse41.cpp │ ├── types.h │ ├── types_float2.h │ ├── types_float2_impl.h │ ├── types_float3.h │ ├── types_float3_impl.h │ ├── types_float4.h │ ├── types_float4_impl.h │ ├── types_float8.h │ ├── types_float8_impl.h │ ├── types_int2.h │ ├── types_int2_impl.h │ ├── types_int3.h │ ├── types_int3_impl.h │ ├── types_int4.h │ ├── types_int4_impl.h │ ├── types_int8.h │ ├── types_int8_impl.h │ ├── types_spectrum.h │ ├── types_uchar2.h │ ├── types_uchar2_impl.h │ ├── types_uchar3.h │ ├── types_uchar3_impl.h │ ├── types_uchar4.h │ ├── types_uchar4_impl.h │ ├── types_uint2.h │ ├── types_uint2_impl.h │ ├── types_uint3.h │ ├── types_uint3_impl.h │ ├── types_uint4.h │ ├── types_uint4_impl.h │ ├── types_ushort4.h │ ├── unique_ptr.h │ ├── vector.h │ ├── version.h │ ├── windows.cpp │ ├── windows.h │ └── xml.h ├── third_party ├── CMakeLists.txt ├── atomic │ ├── atomic_ops.h │ └── intern │ │ ├── atomic_ops_ext.h │ │ ├── atomic_ops_msvc.h │ │ ├── atomic_ops_unix.h │ │ └── atomic_ops_utils.h ├── cuew │ ├── CMakeLists.txt │ ├── LICENSE │ ├── README │ ├── auto │ │ ├── cuda_errors.py │ │ ├── cuda_extra.py │ │ ├── cuew.template.c │ │ ├── cuew.template.h │ │ ├── cuew_gen.py │ │ ├── cuew_gen.sh │ │ ├── stdint.h │ │ └── stdlib.h │ ├── include │ │ └── cuew.h │ └── src │ │ └── cuew.c ├── hipew │ ├── CMakeLists.txt │ ├── LICENSE │ ├── README │ ├── include │ │ └── hipew.h │ └── src │ │ └── hipew.c ├── libc_compat │ ├── CMakeLists.txt │ └── libc_compat.c ├── mikktspace │ ├── README.md │ ├── mikk_atomic_hash_set.hh │ ├── mikk_float3.hh │ ├── mikk_util.hh │ └── mikktspace.hh └── sky │ ├── CMakeLists.txt │ ├── include │ └── sky_model.h │ └── source │ ├── sky_float3.h │ ├── sky_model.cpp │ ├── sky_model_data.h │ └── sky_nishita.cpp └── web ├── config.toml ├── content ├── _index.md ├── development.md └── features.md ├── static └── CNAME └── themes └── custom ├── layouts ├── 404.html ├── _default │ ├── baseof.html │ ├── list.html │ └── single.html ├── index.html ├── partials │ ├── footer.html │ ├── head.html │ └── header.html └── shortcodes │ ├── figure.html │ ├── gallery.html │ └── load-photoswipe.html ├── static ├── css │ ├── photoswipe-gallery.css │ └── style.css └── js │ └── load-photoswipe.js └── theme.toml /.gitignore: -------------------------------------------------------------------------------- 1 | # Generic files to ignore 2 | .* 3 | .*.swp 4 | 5 | # Python cache 6 | __pycache__/ 7 | 8 | # Editors 9 | *~ 10 | *.swp 11 | *.swo 12 | *# 13 | 14 | # QtCreator 15 | CMakeLists.txt.user 16 | 17 | # ms-windows 18 | Thumbs.db 19 | ehthumbs.db 20 | Desktop.ini 21 | 22 | # Local patches 23 | /*.patch 24 | /*.diff 25 | 26 | # Build folders 27 | bin-dbg 28 | bin-opt 29 | build*/ 30 | install*/ 31 | 32 | # OSL compiled examples 33 | examples/osl/*.oso 34 | -------------------------------------------------------------------------------- /DockerfileOneAPI: -------------------------------------------------------------------------------- 1 | # This Dockerfile will build Intel OneAPI binaries 2 | # All you need to do is the following: 3 | # On Windows: 4 | # * Install Docker Desktop 5 | # * Follow instructions on how to install WSL2 6 | # * Make sure Docker Desktop is running 7 | # * Use a terminal to build a Docker image: 'docker build -f DockerfileOneAPI -t ubuntu-cycles-oneapi-build .' 8 | # * After that, run the Docker image in a container while mounting your Rhino repository root: 9 | # 'docker run -it -v D:/dev/mcneel/rhino-8.x:/rhino/rhino-8.x ubuntu-cycles-oneapi-build' 10 | 11 | FROM ubuntu:latest 12 | 13 | RUN apt-get update 14 | RUN apt-get install -y cmake 15 | RUN apt-get install -y g++ 16 | RUN apt-get install -y subversion 17 | RUN apt-get install -y git 18 | RUN apt-get install -y python3 19 | RUN apt-get install -y xorg-dev 20 | 21 | CMD ["bash", "-c", "cd /rhino/rhino-8.x/src4/rhino4/Plug-ins/RDK/cycles/cycles && ./make_oneapi.sh Debug"] 22 | 23 | # && ./make_oneapi.sh Debug -------------------------------------------------------------------------------- /examples/objects/cube.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /examples/osl/stripes.osl: -------------------------------------------------------------------------------- 1 | shader sine_pattern( 2 | color Color = color(0.0, 0.2, 0.6), 3 | float Time = 7.0, 4 | float Scale = 0.5, 5 | float Intensity = 10.0, 6 | int Stripes = 10, 7 | point Vector = P, 8 | output closure color BSDF = 0) 9 | { 10 | point Pos = Vector * Scale; 11 | float pattern = 0.0; 12 | 13 | for( float i = 0.0; i < Stripes; ++i ) 14 | { 15 | float t = Time/10.0 * (i); 16 | 17 | Pos[0] += sin( (Pos[1] + t) * 10.0 ) * 0.1; 18 | 19 | float f = abs(Intensity / Pos[0] * 0.001); 20 | pattern += f; 21 | } 22 | 23 | BSDF = (Color * pattern) * diffuse(N); 24 | } -------------------------------------------------------------------------------- /examples/scene_cube_surface.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/scene_osl_stripes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /examples/scene_sphere_bump.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /make.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | REM Convenience wrapper for CMake commands 4 | 5 | setlocal enableextensions enabledelayedexpansion 6 | 7 | set BUILD_DIR=build 8 | set PYTHON=python 9 | set COMMAND=%1 10 | 11 | if "%COMMAND%" == "" ( 12 | set COMMAND=release 13 | ) 14 | 15 | if "%COMMAND%" == "release" ( 16 | cmake -B %BUILD_DIR% && cd %BUILD_DIR% && cmake --build . --target install --config Release 17 | ) else if "%COMMAND%" == "debug" ( 18 | cmake -B %BUILD_DIR% && cd %BUILD_DIR% && cmake --build . --target install --config Debug 19 | ) else if "%COMMAND%" == "clean" ( 20 | cd %BUILD_DIR% && cmake --build . --target install --config Clean 21 | ) else if "%COMMAND%" == "test" ( 22 | cd %BUILD_DIR% && ctest --config Release 23 | ) else if "%COMMAND%" == "update" ( 24 | %PYTHON% src/cmake/make_update.py 25 | ) else if "%COMMAND%" == "format" ( 26 | %PYTHON% src/cmake/make_format.py 27 | ) else ( 28 | echo Command "%COMMAND%" unknown 29 | ) 30 | -------------------------------------------------------------------------------- /make_hip.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | BUILD_DIR=build_hip 6 | PYTHON=python3 7 | COMMAND=$1 8 | 9 | #rm -rf $BUILD_DIR 10 | 11 | if [ -z "$COMMAND" ] 12 | then 13 | COMMAND=Release 14 | fi 15 | 16 | #$PYTHON src/cmake/make_update.py 17 | 18 | cmake -B $BUILD_DIR \ 19 | -DWITH_CYCLES_ALEMBIC=OFF \ 20 | -DWITH_CYCLES_EMBREE=OFF \ 21 | -DWITH_CYCLES_OPENCOLORIO=OFF \ 22 | -DWITH_CYCLES_OPENIMAGEDENOISE=OFF \ 23 | -DWITH_CYCLES_OPENSUBDIV=OFF \ 24 | -DWITH_CYCLES_OPENVDB=OFF \ 25 | -DWITH_CYCLES_NANOVDB=OFF \ 26 | -DWITH_CYCLES_OSL=OFF \ 27 | -DWITH_CYCLES_USD=OFF \ 28 | -DWITH_CYCLES_HYDRA_RENDER_DELEGATE=OFF \ 29 | -DWITH_CYCLES_CUDA_BINARIES=OFF \ 30 | -DWITH_CYCLES_DEVICE_OPTIX=OFF \ 31 | -DWITH_CUDA_DYNLOAD=OFF \ 32 | -DWITH_CYCLES_DEVICE_HIP=ON \ 33 | -DWITH_CYCLES_HIP_BINARIES=ON \ 34 | -DCYCLES_HIP_BINARIES_ARCH="gfx900;gfx906;gfx90c;gfx902;gfx1010;gfx1011;gfx1012;gfx1030;gfx1031;gfx1032;gfx1034;gfx1035;gfx1036;gfx1100;gfx1101;gfx1102;gfx1103;gfx1150;gfx1151;gfx1152;gfx1200;gfx1201" \ 35 | -DHIP_HIPCC_EXECUTABLE="/opt/rocm-6.2.2/bin/hipcc" \ 36 | && cd $BUILD_DIR && cmake --build . -j 8 --target install --config $COMMAND 37 | -------------------------------------------------------------------------------- /make_oneapi.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | BUILD_DIR=build_oneapi 6 | PYTHON=python3 7 | COMMAND=$1 8 | 9 | if [ -z "$COMMAND" ] 10 | then 11 | COMMAND=Release 12 | fi 13 | 14 | $PYTHON src/cmake/make_update.py 15 | 16 | cmake -B $BUILD_DIR \ 17 | -DWITH_CYCLES_ALEMBIC=OFF \ 18 | -DWITH_CYCLES_EMBREE=OFF \ 19 | -DWITH_CYCLES_OPENCOLORIO=OFF \ 20 | -DWITH_CYCLES_OPENIMAGEDENOISE=OFF \ 21 | -DWITH_CYCLES_OPENSUBDIV=OFF \ 22 | -DWITH_CYCLES_OPENVDB=OFF \ 23 | -DWITH_CYCLES_NANOVDB=OFF \ 24 | -DWITH_CYCLES_OSL=OFF \ 25 | -DWITH_CYCLES_USD=OFF \ 26 | -DWITH_CYCLES_HYDRA_RENDER_DELEGATE=OFF \ 27 | -DWITH_CYCLES_CUDA_BINARIES=OFF \ 28 | -DWITH_CYCLES_DEVICE_OPTIX=OFF \ 29 | -DWITH_CUDA_DYNLOAD=OFF \ 30 | -DWITH_CYCLES_DEVICE_ONEAPI=ON \ 31 | -DWITH_CYCLES_ONEAPI_BINARIES=ON \ 32 | && cd $BUILD_DIR && cmake --build . --target install --config $COMMAND 33 | -------------------------------------------------------------------------------- /src/app/cycles_xml.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __CYCLES_XML_H__ 5 | #define __CYCLES_XML_H__ 6 | 7 | CCL_NAMESPACE_BEGIN 8 | 9 | class Scene; 10 | 11 | void xml_read_file(Scene *scene, const char *filepath); 12 | 13 | /* macros for importing */ 14 | #define RAD2DEGF(_rad) ((_rad) * (float)(180.0 / M_PI)) 15 | #define DEG2RADF(_deg) ((_deg) * (float)(M_PI / 180.0)) 16 | 17 | CCL_NAMESPACE_END 18 | 19 | #endif /* __CYCLES_XML_H__ */ 20 | -------------------------------------------------------------------------------- /src/app/oiio_output_driver.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2021-2022 Blender Foundation */ 3 | 4 | #include "session/output_driver.h" 5 | 6 | #include "util/function.h" 7 | #include "util/image.h" 8 | #include "util/string.h" 9 | #include "util/unique_ptr.h" 10 | #include "util/vector.h" 11 | 12 | CCL_NAMESPACE_BEGIN 13 | 14 | class OIIOOutputDriver : public OutputDriver { 15 | public: 16 | typedef function LogFunction; 17 | 18 | OIIOOutputDriver(const string_view filepath, const string_view pass, LogFunction log); 19 | virtual ~OIIOOutputDriver(); 20 | 21 | void write_render_tile(const Tile &tile) override; 22 | 23 | protected: 24 | string filepath_; 25 | string pass_; 26 | LogFunction log_; 27 | }; 28 | 29 | CCL_NAMESPACE_END 30 | -------------------------------------------------------------------------------- /src/app/opengl/window.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | /* Functions to display a simple OpenGL window using SDL, simplified to the 7 | * bare minimum we need to reduce boilerplate code in tests apps. */ 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | typedef void (*WindowInitFunc)(); 12 | typedef void (*WindowExitFunc)(); 13 | typedef void (*WindowResizeFunc)(int width, int height); 14 | typedef void (*WindowDisplayFunc)(); 15 | typedef void (*WindowKeyboardFunc)(unsigned char key); 16 | typedef void (*WindowMotionFunc)(int x, int y, int button); 17 | 18 | void window_main_loop(const char *title, 19 | int width, 20 | int height, 21 | WindowInitFunc initf, 22 | WindowExitFunc exitf, 23 | WindowResizeFunc resize, 24 | WindowDisplayFunc display, 25 | WindowKeyboardFunc keyboard, 26 | WindowMotionFunc motion); 27 | 28 | void window_display_info(const char *info); 29 | void window_display_help(); 30 | void window_redraw(); 31 | 32 | bool window_opengl_context_enable(); 33 | void window_opengl_context_disable(); 34 | 35 | CCL_NAMESPACE_END 36 | -------------------------------------------------------------------------------- /src/bvh/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2011-2022 Blender Foundation 3 | 4 | set(INC 5 | .. 6 | ) 7 | 8 | set(INC_SYS 9 | ) 10 | 11 | set(SRC 12 | bvh.cpp 13 | bvh2.cpp 14 | binning.cpp 15 | build.cpp 16 | embree.cpp 17 | multi.cpp 18 | node.cpp 19 | optix.cpp 20 | sort.cpp 21 | split.cpp 22 | unaligned.cpp 23 | ) 24 | 25 | set(SRC_METAL 26 | metal.mm 27 | ) 28 | 29 | if(WITH_CYCLES_DEVICE_METAL) 30 | list(APPEND SRC 31 | ${SRC_METAL} 32 | ) 33 | add_definitions(-DWITH_METAL) 34 | endif() 35 | 36 | set(SRC_HEADERS 37 | bvh.h 38 | bvh2.h 39 | binning.h 40 | build.h 41 | embree.h 42 | multi.h 43 | node.h 44 | optix.h 45 | params.h 46 | sort.h 47 | split.h 48 | unaligned.h 49 | metal.h 50 | ) 51 | 52 | set(LIB 53 | cycles_scene 54 | cycles_util 55 | ) 56 | 57 | include_directories(${INC}) 58 | include_directories(SYSTEM ${INC_SYS}) 59 | 60 | if(WITH_CYCLES_EMBREE) 61 | list(APPEND LIB 62 | ${EMBREE_LIBRARIES} 63 | ) 64 | endif() 65 | 66 | cycles_add_library(cycles_bvh "${LIB}" ${SRC} ${SRC_HEADERS}) 67 | -------------------------------------------------------------------------------- /src/bvh/metal.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2021-2022 Blender Foundation */ 3 | 4 | #ifndef __BVH_METAL_H__ 5 | #define __BVH_METAL_H__ 6 | 7 | #ifdef WITH_METAL 8 | 9 | # include "bvh/bvh.h" 10 | 11 | CCL_NAMESPACE_BEGIN 12 | 13 | BVH *bvh_metal_create(const BVHParams ¶ms, 14 | const vector &geometry, 15 | const vector &objects, 16 | Device *device); 17 | 18 | CCL_NAMESPACE_END 19 | 20 | #endif /* WITH_METAL */ 21 | 22 | #endif /* __BVH_METAL_H__ */ 23 | -------------------------------------------------------------------------------- /src/bvh/metal.mm: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2021-2022 Blender Foundation */ 3 | 4 | #ifdef WITH_METAL 5 | 6 | # include "device/metal/bvh.h" 7 | 8 | CCL_NAMESPACE_BEGIN 9 | 10 | BVH *bvh_metal_create(const BVHParams ¶ms, 11 | const vector &geometry, 12 | const vector &objects, 13 | Device *device) 14 | { 15 | return new BVHMetal(params, geometry, objects, device); 16 | } 17 | 18 | CCL_NAMESPACE_END 19 | 20 | #endif /* WITH_METAL */ 21 | -------------------------------------------------------------------------------- /src/bvh/multi.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2020-2022 Blender Foundation. */ 3 | 4 | #include "bvh/multi.h" 5 | 6 | #include "util/foreach.h" 7 | 8 | CCL_NAMESPACE_BEGIN 9 | 10 | BVHMulti::BVHMulti(const BVHParams ¶ms_, 11 | const vector &geometry_, 12 | const vector &objects_) 13 | : BVH(params_, geometry_, objects_) 14 | { 15 | } 16 | 17 | BVHMulti::~BVHMulti() 18 | { 19 | foreach (BVH *bvh, sub_bvhs) { 20 | delete bvh; 21 | } 22 | } 23 | 24 | void BVHMulti::replace_geometry(const vector &geometry, 25 | const vector &objects) 26 | { 27 | foreach (BVH *bvh, sub_bvhs) { 28 | bvh->replace_geometry(geometry, objects); 29 | } 30 | } 31 | 32 | CCL_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /src/bvh/multi.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2020-2022 Blender Foundation. */ 3 | 4 | #ifndef __BVH_MULTI_H__ 5 | #define __BVH_MULTI_H__ 6 | 7 | #include "bvh/bvh.h" 8 | #include "bvh/params.h" 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | class BVHMulti : public BVH { 13 | public: 14 | vector sub_bvhs; 15 | 16 | protected: 17 | friend class BVH; 18 | BVHMulti(const BVHParams ¶ms, 19 | const vector &geometry, 20 | const vector &objects); 21 | virtual ~BVHMulti(); 22 | 23 | virtual void replace_geometry(const vector &geometry, 24 | const vector &objects); 25 | }; 26 | 27 | CCL_NAMESPACE_END 28 | 29 | #endif /* __BVH_MULTI_H__ */ 30 | -------------------------------------------------------------------------------- /src/bvh/optix.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2019, NVIDIA Corporation. 3 | * Copyright 2019-2022 Blender Foundation. */ 4 | 5 | #ifdef WITH_OPTIX 6 | 7 | # include "device/device.h" 8 | 9 | # include "bvh/optix.h" 10 | 11 | CCL_NAMESPACE_BEGIN 12 | 13 | BVHOptiX::BVHOptiX(const BVHParams ¶ms_, 14 | const vector &geometry_, 15 | const vector &objects_, 16 | Device *device) 17 | : BVH(params_, geometry_, objects_), 18 | device(device), 19 | traversable_handle(0), 20 | as_data(make_unique>( 21 | device, params.top_level ? "optix tlas" : "optix blas", false)), 22 | motion_transform_data( 23 | make_unique>(device, "optix motion transform", false)) 24 | { 25 | } 26 | 27 | BVHOptiX::~BVHOptiX() 28 | { 29 | /* Acceleration structure memory is delayed freed on device, since deleting the 30 | * BVH may happen while still being used for rendering. */ 31 | device->release_optix_bvh(this); 32 | } 33 | 34 | CCL_NAMESPACE_END 35 | 36 | #endif /* WITH_OPTIX */ 37 | -------------------------------------------------------------------------------- /src/bvh/optix.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2019, NVIDIA Corporation. 3 | * Copyright 2019-2022 Blender Foundation. */ 4 | 5 | #ifndef __BVH_OPTIX_H__ 6 | #define __BVH_OPTIX_H__ 7 | 8 | #ifdef WITH_OPTIX 9 | 10 | # include "bvh/bvh.h" 11 | # include "bvh/params.h" 12 | 13 | # include "device/memory.h" 14 | 15 | # include "util/unique_ptr.h" 16 | 17 | CCL_NAMESPACE_BEGIN 18 | 19 | class BVHOptiX : public BVH { 20 | public: 21 | Device *device; 22 | uint64_t traversable_handle; 23 | unique_ptr> as_data; 24 | unique_ptr> motion_transform_data; 25 | 26 | protected: 27 | friend class BVH; 28 | BVHOptiX(const BVHParams ¶ms, 29 | const vector &geometry, 30 | const vector &objects, 31 | Device *device); 32 | virtual ~BVHOptiX(); 33 | }; 34 | 35 | CCL_NAMESPACE_END 36 | 37 | #endif /* WITH_OPTIX */ 38 | 39 | #endif /* __BVH_OPTIX_H__ */ 40 | -------------------------------------------------------------------------------- /src/bvh/sort.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Adapted from code copyright 2009-2010 NVIDIA Corporation 3 | * Modifications Copyright 2011-2022 Blender Foundation. */ 4 | 5 | #ifndef __BVH_SORT_H__ 6 | #define __BVH_SORT_H__ 7 | 8 | #include 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | class BVHReference; 13 | class BVHUnaligned; 14 | struct Transform; 15 | 16 | void bvh_reference_sort(int start, 17 | int end, 18 | BVHReference *data, 19 | int dim, 20 | const BVHUnaligned *unaligned_heuristic = NULL, 21 | const Transform *aligned_space = NULL); 22 | 23 | CCL_NAMESPACE_END 24 | 25 | #endif /* __BVH_SORT_H__ */ 26 | -------------------------------------------------------------------------------- /src/ccycles/transform.cpp: -------------------------------------------------------------------------------- 1 | /** 2 | Copyright 2014-2017 Robert McNeel and Associates 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); 5 | you may not use this file except in compliance with the License. 6 | You may obtain a copy of the License at 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, 12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | See the License for the specific language governing permissions and 14 | limitations under the License. 15 | **/ 16 | 17 | //#include "internal_types.h" 18 | 19 | -------------------------------------------------------------------------------- /src/ccycles/version.h: -------------------------------------------------------------------------------- 1 | #define VERSION_WITH_PERIODS 1.0.0.01000 2 | #define VERSION_WITH_COMMAS 1,0,0,1000 3 | #define COPYRIGHT "Copyright (C) 1993-2017, Robert McNeel & Associates. All Rights Reserved." 4 | #define RMA_VERSION_WITH_PERIODS_STRING "1.0.0.01000" 5 | #define RHINO_FILE_FLAGS_MASK 0x0L 6 | -------------------------------------------------------------------------------- /src/ccycles/vshader.h: -------------------------------------------------------------------------------- 1 | static const GLchar* vs_src = 2 | "#version 330 \n" 3 | 4 | "layout(location = 0) in vec2 Vertex; \n" 5 | 6 | "void main() \n" 7 | "{ \n" 8 | " gl_Position = vec4(Vertex, 0.0, 1.0); \n" 9 | "} \n"; 10 | -------------------------------------------------------------------------------- /src/cmake/detect_platform.cmake: -------------------------------------------------------------------------------- 1 | # Copyright 2011-2020 Blender Foundation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | if(APPLE) 16 | if(NOT CMAKE_OSX_ARCHITECTURES) 17 | execute_process(COMMAND uname -m OUTPUT_VARIABLE ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE) 18 | set(CMAKE_OSX_ARCHITECTURES ${ARCHITECTURE} CACHE STRING "" FORCE) 19 | endif() 20 | 21 | if(NOT CMAKE_OSX_DEPLOYMENT_TARGET) 22 | if("${CMAKE_OSX_ARCHITECTURES}" STREQUAL "arm64") 23 | set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "" FORCE) 24 | else() 25 | set(CMAKE_OSX_DEPLOYMENT_TARGET "10.13" CACHE STRING "" FORCE) 26 | endif() 27 | endif() 28 | endif() 29 | -------------------------------------------------------------------------------- /src/cmake/msvc_arch_flags.c: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include 5 | #include 6 | 7 | /* The MS CRT defines this */ 8 | extern int __isa_available; 9 | 10 | const char *get_arch_flags() 11 | { 12 | if (__isa_available >= __ISA_AVAILABLE_AVX2) { 13 | return "/arch:AVX2"; 14 | } 15 | if (__isa_available >= __ISA_AVAILABLE_AVX) { 16 | return "/arch:AVX"; 17 | } 18 | return ""; 19 | } 20 | 21 | int main() 22 | { 23 | printf("%s\n", get_arch_flags()); 24 | return 0; 25 | } 26 | -------------------------------------------------------------------------------- /src/device/cpu/device.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "util/string.h" 7 | #include "util/vector.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | class Device; 12 | class DeviceInfo; 13 | class Profiler; 14 | class Stats; 15 | 16 | Device *device_cpu_create(const DeviceInfo &info, Stats &stats, Profiler &profiler); 17 | 18 | void device_cpu_info(vector &devices); 19 | 20 | string device_cpu_capabilities(); 21 | 22 | CCL_NAMESPACE_END 23 | -------------------------------------------------------------------------------- /src/device/cuda/device.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "util/string.h" 7 | #include "util/vector.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | class Device; 12 | class DeviceInfo; 13 | class Profiler; 14 | class Stats; 15 | 16 | bool device_cuda_init(); 17 | 18 | Device *device_cuda_create(const DeviceInfo &info, Stats &stats, Profiler &profiler); 19 | 20 | void device_cuda_info(vector &devices); 21 | 22 | string device_cuda_capabilities(); 23 | 24 | CCL_NAMESPACE_END 25 | -------------------------------------------------------------------------------- /src/device/cuda/kernel.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifdef WITH_CUDA 7 | 8 | # include "device/kernel.h" 9 | 10 | # ifdef WITH_CUDA_DYNLOAD 11 | # include "cuew.h" 12 | # else 13 | # include 14 | # endif 15 | 16 | CCL_NAMESPACE_BEGIN 17 | 18 | class CUDADevice; 19 | 20 | /* CUDA kernel and associate occupancy information. */ 21 | class CUDADeviceKernel { 22 | public: 23 | CUfunction function = nullptr; 24 | 25 | int num_threads_per_block = 0; 26 | int min_blocks = 0; 27 | }; 28 | 29 | /* Cache of CUDA kernels for each DeviceKernel. */ 30 | class CUDADeviceKernels { 31 | public: 32 | void load(CUDADevice *device); 33 | const CUDADeviceKernel &get(DeviceKernel kernel) const; 34 | bool available(DeviceKernel kernel) const; 35 | 36 | protected: 37 | CUDADeviceKernel kernels_[DEVICE_KERNEL_NUM]; 38 | bool loaded = false; 39 | }; 40 | 41 | CCL_NAMESPACE_END 42 | 43 | #endif /* WITH_CUDA */ 44 | -------------------------------------------------------------------------------- /src/device/cuda/util.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifdef WITH_CUDA 5 | 6 | # include "device/cuda/util.h" 7 | # include "device/cuda/device_impl.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | CUDAContextScope::CUDAContextScope(CUDADevice *device) : device(device) 12 | { 13 | cuda_device_assert(device, cuCtxPushCurrent(device->cuContext)); 14 | } 15 | 16 | CUDAContextScope::~CUDAContextScope() 17 | { 18 | cuda_device_assert(device, cuCtxPopCurrent(NULL)); 19 | } 20 | 21 | # ifndef WITH_CUDA_DYNLOAD 22 | const char *cuewErrorString(CUresult result) 23 | { 24 | /* We can only give error code here without major code duplication, that 25 | * should be enough since dynamic loading is only being disabled by folks 26 | * who knows what they're doing anyway. 27 | * 28 | * NOTE: Avoid call from several threads. 29 | */ 30 | static string error; 31 | error = string_printf("%d", result); 32 | return error.c_str(); 33 | } 34 | 35 | const char *cuewCompilerPath() 36 | { 37 | return CYCLES_CUDA_NVCC_EXECUTABLE; 38 | } 39 | 40 | int cuewCompilerVersion() 41 | { 42 | return (CUDA_VERSION / 100) + (CUDA_VERSION % 100 / 10); 43 | } 44 | # endif 45 | 46 | CCL_NAMESPACE_END 47 | 48 | #endif /* WITH_CUDA */ 49 | -------------------------------------------------------------------------------- /src/device/dummy/device.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "util/string.h" 7 | #include "util/vector.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | class Device; 12 | class DeviceInfo; 13 | class Profiler; 14 | class Stats; 15 | 16 | Device *device_dummy_create(const DeviceInfo &info, Stats &stats, Profiler &profiler); 17 | 18 | CCL_NAMESPACE_END 19 | -------------------------------------------------------------------------------- /src/device/graphics_interop.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "device/graphics_interop.h" 5 | 6 | CCL_NAMESPACE_BEGIN 7 | 8 | CCL_NAMESPACE_END 9 | -------------------------------------------------------------------------------- /src/device/graphics_interop.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "session/display_driver.h" 7 | 8 | #include "util/types.h" 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | /* Device-side graphics interoperability support. 13 | * 14 | * Takes care of holding all the handlers needed by the device to implement interoperability with 15 | * the graphics library. */ 16 | class DeviceGraphicsInterop { 17 | public: 18 | DeviceGraphicsInterop() = default; 19 | virtual ~DeviceGraphicsInterop() = default; 20 | 21 | /* Update this device-side graphics interoperability object with the given destination resource 22 | * information. */ 23 | virtual void set_display_interop(const DisplayDriver::GraphicsInterop &display_interop) = 0; 24 | 25 | virtual device_ptr map() = 0; 26 | virtual void unmap() = 0; 27 | }; 28 | 29 | CCL_NAMESPACE_END 30 | -------------------------------------------------------------------------------- /src/device/hip/device.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "util/string.h" 7 | #include "util/vector.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | class Device; 12 | class DeviceInfo; 13 | class Profiler; 14 | class Stats; 15 | 16 | bool device_hip_init(); 17 | 18 | Device *device_hip_create(const DeviceInfo &info, Stats &stats, Profiler &profiler); 19 | 20 | void device_hip_info(vector &devices); 21 | 22 | string device_hip_capabilities(); 23 | 24 | CCL_NAMESPACE_END 25 | -------------------------------------------------------------------------------- /src/device/hip/kernel.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifdef WITH_HIP 7 | 8 | # include "device/kernel.h" 9 | 10 | # ifdef WITH_HIP_DYNLOAD 11 | # include "hipew.h" 12 | # endif 13 | 14 | CCL_NAMESPACE_BEGIN 15 | 16 | class HIPDevice; 17 | 18 | /* HIP kernel and associate occupancy information. */ 19 | class HIPDeviceKernel { 20 | public: 21 | hipFunction_t function = nullptr; 22 | 23 | int num_threads_per_block = 0; 24 | int min_blocks = 0; 25 | }; 26 | 27 | /* Cache of HIP kernels for each DeviceKernel. */ 28 | class HIPDeviceKernels { 29 | public: 30 | void load(HIPDevice *device); 31 | const HIPDeviceKernel &get(DeviceKernel kernel) const; 32 | bool available(DeviceKernel kernel) const; 33 | 34 | protected: 35 | HIPDeviceKernel kernels_[DEVICE_KERNEL_NUM]; 36 | bool loaded = false; 37 | }; 38 | 39 | CCL_NAMESPACE_END 40 | 41 | #endif /* WITH_HIP */ 42 | -------------------------------------------------------------------------------- /src/device/hip/util.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifdef WITH_HIP 5 | 6 | # include "device/hip/util.h" 7 | # include "device/hip/device_impl.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | HIPContextScope::HIPContextScope(HIPDevice *device) : device(device) 12 | { 13 | hip_device_assert(device, hipCtxPushCurrent(device->hipContext)); 14 | } 15 | 16 | HIPContextScope::~HIPContextScope() 17 | { 18 | hip_device_assert(device, hipCtxPopCurrent(NULL)); 19 | } 20 | 21 | # ifndef WITH_HIP_DYNLOAD 22 | const char *hipewErrorString(hipError_t result) 23 | { 24 | /* We can only give error code here without major code duplication, that 25 | * should be enough since dynamic loading is only being disabled by folks 26 | * who knows what they're doing anyway. 27 | * 28 | * NOTE: Avoid call from several threads. 29 | */ 30 | static string error; 31 | error = string_printf("%d", result); 32 | return error.c_str(); 33 | } 34 | 35 | const char *hipewCompilerPath() 36 | { 37 | return CYCLES_HIP_HIPCC_EXECUTABLE; 38 | } 39 | 40 | int hipewCompilerVersion() 41 | { 42 | return (HIP_VERSION / 100) + (HIP_VERSION % 100 / 10); 43 | } 44 | # endif 45 | 46 | CCL_NAMESPACE_END 47 | 48 | #endif /* WITH_HIP */ 49 | -------------------------------------------------------------------------------- /src/device/kernel.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "kernel/types.h" 7 | 8 | #include "util/string.h" 9 | 10 | #include // NOLINT 11 | 12 | CCL_NAMESPACE_BEGIN 13 | 14 | bool device_kernel_has_shading(DeviceKernel kernel); 15 | bool device_kernel_has_intersection(DeviceKernel kernel); 16 | 17 | const char *device_kernel_as_string(DeviceKernel kernel); 18 | std::ostream &operator<<(std::ostream &os, DeviceKernel kernel); 19 | 20 | typedef uint64_t DeviceKernelMask; 21 | string device_kernel_mask_as_string(DeviceKernelMask mask); 22 | 23 | CCL_NAMESPACE_END 24 | -------------------------------------------------------------------------------- /src/device/metal/device.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2021-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "util/string.h" 7 | #include "util/vector.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | class Device; 12 | class DeviceInfo; 13 | class Profiler; 14 | class Stats; 15 | 16 | bool device_metal_init(); 17 | 18 | Device *device_metal_create(const DeviceInfo &info, Stats &stats, Profiler &profiler); 19 | 20 | void device_metal_info(vector &devices); 21 | 22 | string device_metal_capabilities(); 23 | 24 | CCL_NAMESPACE_END 25 | -------------------------------------------------------------------------------- /src/device/multi/device.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "util/string.h" 7 | #include "util/vector.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | class Device; 12 | class DeviceInfo; 13 | class Profiler; 14 | class Stats; 15 | 16 | Device *device_multi_create(const DeviceInfo &info, Stats &stats, Profiler &profiler); 17 | 18 | CCL_NAMESPACE_END 19 | -------------------------------------------------------------------------------- /src/device/oneapi/device.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "util/string.h" 7 | #include "util/vector.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | class Device; 12 | class DeviceInfo; 13 | class Profiler; 14 | class Stats; 15 | 16 | bool device_oneapi_init(); 17 | 18 | Device *device_oneapi_create(const DeviceInfo &info, Stats &stats, Profiler &profiler); 19 | 20 | void device_oneapi_info(vector &devices); 21 | 22 | string device_oneapi_capabilities(); 23 | 24 | CCL_NAMESPACE_END 25 | -------------------------------------------------------------------------------- /src/device/optix/device.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "util/string.h" 7 | #include "util/vector.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | class Device; 12 | class DeviceInfo; 13 | class Profiler; 14 | class Stats; 15 | 16 | bool device_optix_init(); 17 | 18 | Device *device_optix_create(const DeviceInfo &info, Stats &stats, Profiler &profiler); 19 | 20 | void device_optix_info(const vector &cuda_devices, vector &devices); 21 | 22 | CCL_NAMESPACE_END 23 | -------------------------------------------------------------------------------- /src/device/optix/queue.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifdef WITH_OPTIX 7 | 8 | # include "device/cuda/queue.h" 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | class OptiXDevice; 13 | 14 | /* Base class for CUDA queues. */ 15 | class OptiXDeviceQueue : public CUDADeviceQueue { 16 | public: 17 | OptiXDeviceQueue(OptiXDevice *device); 18 | 19 | virtual void init_execution() override; 20 | 21 | virtual bool enqueue(DeviceKernel kernel, 22 | const int work_size, 23 | DeviceKernelArguments const &args) override; 24 | }; 25 | 26 | CCL_NAMESPACE_END 27 | 28 | #endif /* WITH_OPTIX */ 29 | -------------------------------------------------------------------------------- /src/device/optix/util.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifdef WITH_OPTIX 7 | 8 | # include "device/cuda/util.h" 9 | 10 | # ifdef WITH_CUDA_DYNLOAD 11 | # include 12 | // Do not use CUDA SDK headers when using CUEW 13 | # define OPTIX_DONT_INCLUDE_CUDA 14 | # endif 15 | 16 | # include 17 | 18 | /* Utility for checking return values of OptiX function calls. */ 19 | # define optix_device_assert(optix_device, stmt) \ 20 | { \ 21 | OptixResult result = stmt; \ 22 | if (result != OPTIX_SUCCESS) { \ 23 | const char *name = optixGetErrorName(result); \ 24 | optix_device->set_error( \ 25 | string_printf("%s in %s (%s:%d)", name, #stmt, __FILE__, __LINE__)); \ 26 | } \ 27 | } \ 28 | (void)0 29 | 30 | # define optix_assert(stmt) optix_device_assert(this, stmt) 31 | 32 | #endif /* WITH_OPTIX */ 33 | -------------------------------------------------------------------------------- /src/doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2011-2022 Blender Foundation 3 | 4 | add_subdirectory(license) 5 | -------------------------------------------------------------------------------- /src/doc/license/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2011-2022 Blender Foundation 3 | 4 | set(LICENSES 5 | Apache2-license.txt 6 | BSD-3-Clause-license.txt 7 | MIT-license.txt 8 | readme.txt 9 | SPDX-license-identifiers.txt 10 | Zlib-license.txt 11 | ) 12 | 13 | delayed_install(${CMAKE_CURRENT_SOURCE_DIR} "${LICENSES}" ${CYCLES_INSTALL_PATH}/license) 14 | -------------------------------------------------------------------------------- /src/doc/license/MIT-license.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /src/doc/license/SPDX-license-identifiers.txt: -------------------------------------------------------------------------------- 1 | SPDX license identifiers in the source code: 2 | 3 | Apache-2.0 Apache-2-license.txt https://spdx.org/licenses/Apache-2.0.html 4 | BSD-3-Clause BSD-3-Clause-license.txt https://spdx.org/licenses/BSD-3-Clause.html 5 | MIT MIT-license.txt https://spdx.org/licenses/MIT.html 6 | Zlib Zlib-license.txt https://spdx.org/licenses/Zlib.html 7 | -------------------------------------------------------------------------------- /src/doc/license/Zlib-license.txt: -------------------------------------------------------------------------------- 1 | Zlib License 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 2. Altered source versions must be plainly marked as such, and must not be 16 | misrepresented as being the original software. 17 | 3. This notice may not be removed or altered from any source distribution. 18 | -------------------------------------------------------------------------------- /src/doc/license/readme.txt: -------------------------------------------------------------------------------- 1 | The default license for Cycles source code is Apache 2.0. 2 | 3 | There is also code adapted from other sources with different but compatible 4 | licenses. This is marked with appropriate SPDX license identifiers and 5 | copyright notices in source files. 6 | 7 | See SPDX-license-identifiers.txt for a list of licenses used in the code. 8 | -------------------------------------------------------------------------------- /src/graph/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2011-2022 Blender Foundation 3 | 4 | set(INC 5 | .. 6 | ) 7 | 8 | set(INC_SYS 9 | ) 10 | 11 | set(SRC 12 | node.cpp 13 | node_type.cpp 14 | node_xml.cpp 15 | ) 16 | 17 | set(SRC_HEADERS 18 | node.h 19 | node_enum.h 20 | node_type.h 21 | node_xml.h 22 | ) 23 | 24 | set(LIB 25 | cycles_util 26 | ) 27 | 28 | include_directories(${INC}) 29 | include_directories(SYSTEM ${INC_SYS}) 30 | 31 | cycles_add_library(cycles_graph "${LIB}" ${SRC} ${SRC_HEADERS}) 32 | -------------------------------------------------------------------------------- /src/graph/node_xml.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "graph/node.h" 7 | 8 | #include "util/map.h" 9 | #include "util/string.h" 10 | #include "util/xml.h" 11 | 12 | CCL_NAMESPACE_BEGIN 13 | 14 | struct XMLReader { 15 | map node_map; 16 | }; 17 | 18 | void xml_read_node(XMLReader &reader, Node *node, xml_node xml_node); 19 | xml_node xml_write_node(Node *node, xml_node xml_root); 20 | 21 | CCL_NAMESPACE_END 22 | -------------------------------------------------------------------------------- /src/hydra/attribute.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2022 NVIDIA Corporation 3 | * Copyright 2022 Blender Foundation */ 4 | 5 | #pragma once 6 | 7 | #include "hydra/config.h" 8 | #include "scene/attribute.h" 9 | 10 | #include 11 | #include 12 | 13 | HDCYCLES_NAMESPACE_OPEN_SCOPE 14 | 15 | void ApplyPrimvars(CCL_NS::AttributeSet &attributes, 16 | const CCL_NS::ustring &name, 17 | PXR_NS::VtValue value, 18 | CCL_NS::AttributeElement elem, 19 | CCL_NS::AttributeStandard std); 20 | 21 | HDCYCLES_NAMESPACE_CLOSE_SCOPE 22 | -------------------------------------------------------------------------------- /src/hydra/config.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2022 NVIDIA Corporation 3 | * Copyright 2022 Blender Foundation */ 4 | 5 | #pragma once 6 | 7 | #include 8 | 9 | #define CCL_NS ccl 10 | #define CCL_NAMESPACE_USING_DIRECTIVE using namespace CCL_NS; 11 | 12 | #define HD_CYCLES_NS HdCycles 13 | #define HDCYCLES_NAMESPACE_OPEN_SCOPE \ 14 | namespace HD_CYCLES_NS { \ 15 | CCL_NAMESPACE_USING_DIRECTIVE; \ 16 | PXR_NAMESPACE_USING_DIRECTIVE; 17 | #define HDCYCLES_NAMESPACE_CLOSE_SCOPE } 18 | 19 | namespace HD_CYCLES_NS { 20 | class HdCyclesCamera; 21 | class HdCyclesDelegate; 22 | class HdCyclesSession; 23 | class HdCyclesRenderBuffer; 24 | } // namespace HD_CYCLES_NS 25 | 26 | namespace CCL_NS { 27 | class AttributeSet; 28 | class BufferParams; 29 | class Camera; 30 | class Geometry; 31 | class Hair; 32 | class Light; 33 | class Mesh; 34 | class Object; 35 | class ParticleSystem; 36 | class Pass; 37 | class PointCloud; 38 | class Scene; 39 | class Session; 40 | class SessionParams; 41 | class Shader; 42 | class ShaderGraph; 43 | class ShaderNode; 44 | class Volume; 45 | } // namespace CCL_NS 46 | -------------------------------------------------------------------------------- /src/hydra/curves.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2022 NVIDIA Corporation 3 | * Copyright 2022 Blender Foundation */ 4 | 5 | #pragma once 6 | 7 | #include "hydra/config.h" 8 | #include "hydra/geometry.h" 9 | 10 | #include 11 | 12 | HDCYCLES_NAMESPACE_OPEN_SCOPE 13 | 14 | class HdCyclesCurves final : public HdCyclesGeometry { 15 | public: 16 | HdCyclesCurves( 17 | const PXR_NS::SdfPath &rprimId 18 | #if PXR_VERSION < 2102 19 | , 20 | const PXR_NS::SdfPath &instancerId = {} 21 | #endif 22 | ); 23 | ~HdCyclesCurves() override; 24 | 25 | PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override; 26 | 27 | private: 28 | PXR_NS::HdDirtyBits _PropagateDirtyBits(PXR_NS::HdDirtyBits bits) const override; 29 | 30 | void Populate(PXR_NS::HdSceneDelegate *sceneDelegate, 31 | PXR_NS::HdDirtyBits dirtyBits, 32 | bool &rebuild) override; 33 | 34 | void PopulatePoints(PXR_NS::HdSceneDelegate *sceneDelegate); 35 | void PopulateWidths(PXR_NS::HdSceneDelegate *sceneDelegate); 36 | 37 | void PopulatePrimvars(PXR_NS::HdSceneDelegate *sceneDelegate); 38 | 39 | void PopulateTopology(PXR_NS::HdSceneDelegate *sceneDelegate); 40 | }; 41 | 42 | HDCYCLES_NAMESPACE_CLOSE_SCOPE 43 | -------------------------------------------------------------------------------- /src/hydra/field.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2022 NVIDIA Corporation 3 | * Copyright 2022 Blender Foundation */ 4 | 5 | #pragma once 6 | 7 | #include "hydra/config.h" 8 | #include "scene/image.h" 9 | 10 | #include 11 | 12 | HDCYCLES_NAMESPACE_OPEN_SCOPE 13 | 14 | class HdCyclesField final : public PXR_NS::HdField { 15 | public: 16 | HdCyclesField(const PXR_NS::SdfPath &bprimId, const PXR_NS::TfToken &typeId); 17 | ~HdCyclesField() override; 18 | 19 | PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override; 20 | 21 | void Sync(PXR_NS::HdSceneDelegate *sceneDelegate, 22 | PXR_NS::HdRenderParam *renderParam, 23 | PXR_NS::HdDirtyBits *dirtyBits) override; 24 | 25 | CCL_NS::ImageHandle GetImageHandle() const 26 | { 27 | return _handle; 28 | } 29 | 30 | private: 31 | CCL_NS::ImageHandle _handle; 32 | }; 33 | 34 | HDCYCLES_NAMESPACE_CLOSE_SCOPE 35 | -------------------------------------------------------------------------------- /src/hydra/file_reader.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "hydra/config.h" 7 | 8 | #include "session/session.h" 9 | 10 | HDCYCLES_NAMESPACE_OPEN_SCOPE 11 | 12 | class HdCyclesFileReader { 13 | public: 14 | static void read(Session *session, const char *filepath, const bool use_camera = true); 15 | }; 16 | 17 | HDCYCLES_NAMESPACE_CLOSE_SCOPE 18 | -------------------------------------------------------------------------------- /src/hydra/light.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2022 NVIDIA Corporation 3 | * Copyright 2022 Blender Foundation */ 4 | 5 | #pragma once 6 | 7 | #include "hydra/config.h" 8 | 9 | #include 10 | 11 | HDCYCLES_NAMESPACE_OPEN_SCOPE 12 | 13 | class HdCyclesLight final : public PXR_NS::HdLight { 14 | public: 15 | HdCyclesLight(const PXR_NS::SdfPath &sprimId, const PXR_NS::TfToken &lightType); 16 | ~HdCyclesLight() override; 17 | 18 | PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override; 19 | 20 | void Sync(PXR_NS::HdSceneDelegate *sceneDelegate, 21 | PXR_NS::HdRenderParam *renderParam, 22 | PXR_NS::HdDirtyBits *dirtyBits) override; 23 | 24 | void Finalize(PXR_NS::HdRenderParam *renderParam) override; 25 | 26 | private: 27 | void Initialize(PXR_NS::HdRenderParam *renderParam); 28 | 29 | void PopulateShaderGraph(PXR_NS::HdSceneDelegate *sceneDelegate); 30 | 31 | CCL_NS::Light *_light = nullptr; 32 | PXR_NS::TfToken _lightType; 33 | }; 34 | 35 | HDCYCLES_NAMESPACE_CLOSE_SCOPE 36 | -------------------------------------------------------------------------------- /src/hydra/node_util.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2022 NVIDIA Corporation 3 | * Copyright 2022 Blender Foundation */ 4 | 5 | #pragma once 6 | 7 | #include "graph/node.h" 8 | #include "hydra/config.h" 9 | 10 | #include 11 | 12 | HDCYCLES_NAMESPACE_OPEN_SCOPE 13 | 14 | void SetNodeValue(CCL_NS::Node *node, const CCL_NS::SocketType &socket, const VtValue &value); 15 | 16 | VtValue GetNodeValue(const CCL_NS::Node *node, const CCL_NS::SocketType &socket); 17 | 18 | HDCYCLES_NAMESPACE_CLOSE_SCOPE 19 | -------------------------------------------------------------------------------- /src/hydra/output_driver.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2022 NVIDIA Corporation 3 | * Copyright 2022 Blender Foundation */ 4 | 5 | #pragma once 6 | 7 | #include "hydra/config.h" 8 | #include "session/output_driver.h" 9 | 10 | HDCYCLES_NAMESPACE_OPEN_SCOPE 11 | 12 | class HdCyclesOutputDriver final : public CCL_NS::OutputDriver { 13 | public: 14 | HdCyclesOutputDriver(HdCyclesSession *renderParam); 15 | 16 | private: 17 | void write_render_tile(const Tile &tile) override; 18 | bool update_render_tile(const Tile &tile) override; 19 | 20 | HdCyclesSession *const _renderParam; 21 | }; 22 | 23 | HDCYCLES_NAMESPACE_CLOSE_SCOPE 24 | -------------------------------------------------------------------------------- /src/hydra/plugInfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "Includes": [ "*/resources/" ] 3 | } 4 | -------------------------------------------------------------------------------- /src/hydra/plugin.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2022 NVIDIA Corporation 3 | * Copyright 2022 Blender Foundation */ 4 | 5 | #pragma once 6 | 7 | #include "hydra/config.h" 8 | #include 9 | 10 | PXR_NAMESPACE_OPEN_SCOPE 11 | 12 | class HdCyclesPlugin final : public PXR_NS::HdRendererPlugin { 13 | public: 14 | HdCyclesPlugin(); 15 | ~HdCyclesPlugin() override; 16 | 17 | #if PXR_VERSION < 2302 18 | bool IsSupported() const override; 19 | #else 20 | bool IsSupported(bool gpuEnabled) const override; 21 | #endif 22 | 23 | PXR_NS::HdRenderDelegate *CreateRenderDelegate() override; 24 | PXR_NS::HdRenderDelegate *CreateRenderDelegate(const PXR_NS::HdRenderSettingsMap &) override; 25 | 26 | void DeleteRenderDelegate(PXR_NS::HdRenderDelegate *) override; 27 | }; 28 | 29 | PXR_NAMESPACE_CLOSE_SCOPE 30 | -------------------------------------------------------------------------------- /src/hydra/pointcloud.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2022 NVIDIA Corporation 3 | * Copyright 2022 Blender Foundation */ 4 | 5 | #pragma once 6 | 7 | #include "hydra/config.h" 8 | #include "hydra/geometry.h" 9 | 10 | #include 11 | 12 | HDCYCLES_NAMESPACE_OPEN_SCOPE 13 | 14 | class HdCyclesPoints final : public HdCyclesGeometry { 15 | public: 16 | HdCyclesPoints( 17 | const PXR_NS::SdfPath &rprimId 18 | #if PXR_VERSION < 2102 19 | , 20 | const PXR_NS::SdfPath &instancerId = {} 21 | #endif 22 | ); 23 | ~HdCyclesPoints() override; 24 | 25 | PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override; 26 | 27 | private: 28 | PXR_NS::HdDirtyBits _PropagateDirtyBits(PXR_NS::HdDirtyBits bits) const override; 29 | 30 | void Populate(PXR_NS::HdSceneDelegate *sceneDelegate, 31 | PXR_NS::HdDirtyBits dirtyBits, 32 | bool &rebuild) override; 33 | 34 | void PopulatePoints(PXR_NS::HdSceneDelegate *sceneDelegate); 35 | void PopulateWidths(PXR_NS::HdSceneDelegate *sceneDelegate); 36 | 37 | void PopulatePrimvars(PXR_NS::HdSceneDelegate *sceneDelegate); 38 | }; 39 | 40 | HDCYCLES_NAMESPACE_CLOSE_SCOPE 41 | -------------------------------------------------------------------------------- /src/hydra/render_pass.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2022 NVIDIA Corporation 3 | * Copyright 2022 Blender Foundation */ 4 | 5 | #pragma once 6 | 7 | #include "hydra/config.h" 8 | 9 | #include 10 | 11 | HDCYCLES_NAMESPACE_OPEN_SCOPE 12 | 13 | class HdCyclesRenderPass final : public PXR_NS::HdRenderPass { 14 | public: 15 | HdCyclesRenderPass(PXR_NS::HdRenderIndex *index, 16 | const PXR_NS::HdRprimCollection &collection, 17 | HdCyclesSession *renderParam); 18 | ~HdCyclesRenderPass() override; 19 | 20 | bool IsConverged() const override; 21 | 22 | private: 23 | void ResetConverged(); 24 | 25 | void _Execute(const PXR_NS::HdRenderPassStateSharedPtr &renderPassState, 26 | const PXR_NS::TfTokenVector &renderTags) override; 27 | 28 | void _MarkCollectionDirty() override; 29 | 30 | HdCyclesSession *_renderParam; 31 | unsigned int _lastSettingsVersion = 0; 32 | }; 33 | 34 | HDCYCLES_NAMESPACE_CLOSE_SCOPE 35 | -------------------------------------------------------------------------------- /src/hydra/resources/apple_symbols.map: -------------------------------------------------------------------------------- 1 | *PXR* 2 | -------------------------------------------------------------------------------- /src/hydra/resources/cycles.json: -------------------------------------------------------------------------------- 1 | { 2 | "env":[ 3 | { 4 | "HOUDINI_PATH":"@CMAKE_INSTALL_PREFIX@/houdini" 5 | } 6 | ] 7 | } 8 | -------------------------------------------------------------------------------- /src/hydra/resources/linux_symbols.map: -------------------------------------------------------------------------------- 1 | /* Hide everything except USD / Hydra symbols, to avoid conflicts with other 2 | * application using different library versions. */ 3 | { 4 | global: 5 | PXR*; 6 | local: 7 | *; 8 | }; 9 | -------------------------------------------------------------------------------- /src/hydra/resources/plugInfo.json: -------------------------------------------------------------------------------- 1 | { 2 | "Plugins": [ 3 | { 4 | "Info": { 5 | "Types": { 6 | "HdCyclesPlugin": { 7 | "bases": [ 8 | "HdRendererPlugin" 9 | ], 10 | "displayName": "Cycles", 11 | "priority": 0 12 | } 13 | } 14 | }, 15 | "LibraryPath": "@PLUG_INFO_LIBRARY_PATH@", 16 | "Name": "hdCycles", 17 | "ResourcePath": "@PLUG_INFO_RESOURCE_PATH@", 18 | "Root": "@PLUG_INFO_ROOT@", 19 | "Type": "library" 20 | } 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /src/hydra/volume.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2022 NVIDIA Corporation 3 | * Copyright 2022 Blender Foundation */ 4 | 5 | #pragma once 6 | 7 | #include "hydra/config.h" 8 | #include "hydra/geometry.h" 9 | 10 | #include 11 | 12 | HDCYCLES_NAMESPACE_OPEN_SCOPE 13 | 14 | class HdCyclesVolume final : public HdCyclesGeometry { 15 | public: 16 | HdCyclesVolume( 17 | const PXR_NS::SdfPath &rprimId 18 | #if PXR_VERSION < 2102 19 | , 20 | const PXR_NS::SdfPath &instancerId = {} 21 | #endif 22 | ); 23 | ~HdCyclesVolume() override; 24 | 25 | PXR_NS::HdDirtyBits GetInitialDirtyBitsMask() const override; 26 | 27 | private: 28 | void Populate(PXR_NS::HdSceneDelegate *sceneDelegate, 29 | PXR_NS::HdDirtyBits dirtyBits, 30 | bool &rebuild) override; 31 | }; 32 | 33 | HDCYCLES_NAMESPACE_CLOSE_SCOPE 34 | -------------------------------------------------------------------------------- /src/integrator/guiding.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "kernel/types.h" 7 | 8 | CCL_NAMESPACE_BEGIN 9 | 10 | struct GuidingParams { 11 | /* The subset of path guiding parameters that can trigger a creation/rebuild 12 | * of the guiding field. */ 13 | bool use = false; 14 | bool use_surface_guiding = false; 15 | bool use_volume_guiding = false; 16 | 17 | GuidingDistributionType type = GUIDING_TYPE_PARALLAX_AWARE_VMM; 18 | int training_samples = 128; 19 | bool deterministic = false; 20 | 21 | GuidingParams() = default; 22 | 23 | bool modified(const GuidingParams &other) const 24 | { 25 | return !((use == other.use) && (use_surface_guiding == other.use_surface_guiding) && 26 | (use_volume_guiding == other.use_volume_guiding) && (type == other.type) && 27 | (training_samples == other.training_samples) && 28 | (deterministic == other.deterministic)); 29 | } 30 | }; 31 | 32 | CCL_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /src/integrator/path_trace_tile.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2021-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "session/output_driver.h" 7 | 8 | CCL_NAMESPACE_BEGIN 9 | 10 | /* PathTraceTile 11 | * 12 | * Implementation of OutputDriver::Tile interface for path tracer. */ 13 | 14 | class PathTrace; 15 | 16 | class PathTraceTile : public OutputDriver::Tile { 17 | public: 18 | PathTraceTile(PathTrace &path_trace); 19 | 20 | bool get_pass_pixels(const string_view pass_name, const int num_channels, float *pixels) const; 21 | bool set_pass_pixels(const string_view pass_name, 22 | const int num_channels, 23 | const float *pixels) const; 24 | int get_sample() const; 25 | 26 | private: 27 | PathTrace &path_trace_; 28 | mutable bool copied_from_device_; 29 | }; 30 | 31 | CCL_NAMESPACE_END 32 | -------------------------------------------------------------------------------- /src/integrator/work_balancer.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "util/vector.h" 7 | 8 | CCL_NAMESPACE_BEGIN 9 | 10 | struct WorkBalanceInfo { 11 | /* Time spent performing corresponding work. */ 12 | double time_spent = 0; 13 | 14 | /* Average occupancy of the device while performing the work. */ 15 | float occupancy = 1.0f; 16 | 17 | /* Normalized weight, which is ready to be used for work balancing (like calculating fraction of 18 | * the big tile which is to be rendered on the device). */ 19 | double weight = 1.0; 20 | }; 21 | 22 | /* Balance work for an initial render integration, before any statistics is known. */ 23 | void work_balance_do_initial(vector &work_balance_infos); 24 | 25 | /* Rebalance work after statistics has been accumulated. 26 | * Returns true if the balancing did change. */ 27 | bool work_balance_do_rebalance(vector &work_balance_infos); 28 | 29 | CCL_NAMESPACE_END 30 | -------------------------------------------------------------------------------- /src/kernel/bvh/types.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | CCL_NAMESPACE_BEGIN 7 | 8 | /* Don't inline intersect functions on GPU, this is faster */ 9 | #ifdef __KERNEL_GPU__ 10 | # define ccl_device_intersect ccl_device_forceinline 11 | #else 12 | # define ccl_device_intersect ccl_device_inline 13 | #endif 14 | 15 | /* bottom-most stack entry, indicating the end of traversal */ 16 | #define ENTRYPOINT_SENTINEL 0x76543210 17 | 18 | /* 64 object BVH + 64 mesh BVH + 64 object node splitting */ 19 | #define BVH_STACK_SIZE 192 20 | /* BVH intersection function variations */ 21 | 22 | #define BVH_MOTION 1 23 | #define BVH_HAIR 2 24 | #define BVH_POINTCLOUD 4 25 | 26 | #define BVH_NAME_JOIN(x, y) x##_##y 27 | #define BVH_NAME_EVAL(x, y) BVH_NAME_JOIN(x, y) 28 | #define BVH_FUNCTION_FULL_NAME(prefix) BVH_NAME_EVAL(prefix, BVH_FUNCTION_NAME) 29 | 30 | #define BVH_FEATURE(f) (((BVH_FUNCTION_FEATURES) & (f)) != 0) 31 | 32 | CCL_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /src/kernel/device/cpu/kernel_avx2.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | /* Optimized CPU kernel entry points. This file is compiled with AVX2 5 | * optimization flags and nearly all functions inlined, while kernel.cpp 6 | * is compiled without for other CPU's. */ 7 | 8 | #include "util/optimization.h" 9 | 10 | #ifndef WITH_CYCLES_OPTIMIZED_KERNEL_AVX2 11 | # define KERNEL_STUB 12 | #else 13 | /* SSE optimization disabled for now on 32 bit, see bug #36316. */ 14 | # if !(defined(__GNUC__) && (defined(i386) || defined(_M_IX86))) 15 | # define __KERNEL_SSE__ 16 | # define __KERNEL_SSE2__ 17 | # define __KERNEL_SSE3__ 18 | # define __KERNEL_SSSE3__ 19 | # define __KERNEL_SSE41__ 20 | # define __KERNEL_AVX__ 21 | # define __KERNEL_AVX2__ 22 | # endif 23 | #endif /* WITH_CYCLES_OPTIMIZED_KERNEL_AVX2 */ 24 | 25 | #include "kernel/device/cpu/kernel.h" 26 | #define KERNEL_ARCH cpu_avx2 27 | #include "kernel/device/cpu/kernel_arch_impl.h" 28 | -------------------------------------------------------------------------------- /src/kernel/device/cpu/kernel_sse2.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | /* Optimized CPU kernel entry points. This file is compiled with SSE2 5 | * optimization flags and nearly all functions inlined, while kernel.cpp 6 | * is compiled without for other CPU's. */ 7 | 8 | #include "util/optimization.h" 9 | 10 | #ifndef WITH_CYCLES_OPTIMIZED_KERNEL_SSE2 11 | # define KERNEL_STUB 12 | #else 13 | /* SSE optimization disabled for now on 32 bit, see bug #36316. */ 14 | # if !(defined(__GNUC__) && (defined(i386) || defined(_M_IX86))) 15 | # define __KERNEL_SSE2__ 16 | # endif 17 | #endif /* WITH_CYCLES_OPTIMIZED_KERNEL_SSE2 */ 18 | 19 | #include "kernel/device/cpu/kernel.h" 20 | #define KERNEL_ARCH cpu_sse2 21 | #include "kernel/device/cpu/kernel_arch_impl.h" 22 | -------------------------------------------------------------------------------- /src/kernel/device/cpu/kernel_sse41.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | /* Optimized CPU kernel entry points. This file is compiled with SSE3/SSSE3 5 | * optimization flags and nearly all functions inlined, while kernel.cpp 6 | * is compiled without for other CPU's. */ 7 | 8 | #include "util/optimization.h" 9 | 10 | #ifndef WITH_CYCLES_OPTIMIZED_KERNEL_SSE41 11 | # define KERNEL_STUB 12 | #else 13 | /* SSE optimization disabled for now on 32 bit, see bug #36316. */ 14 | # if !(defined(__GNUC__) && (defined(i386) || defined(_M_IX86))) 15 | # define __KERNEL_SSE2__ 16 | # define __KERNEL_SSE3__ 17 | # define __KERNEL_SSSE3__ 18 | # define __KERNEL_SSE41__ 19 | # endif 20 | #endif /* WITH_CYCLES_OPTIMIZED_KERNEL_SSE41 */ 21 | 22 | #include "kernel/device/cpu/kernel.h" 23 | #define KERNEL_ARCH cpu_sse41 24 | #include "kernel/device/cpu/kernel_arch_impl.h" 25 | -------------------------------------------------------------------------------- /src/kernel/device/cuda/globals.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | /* Constant Globals */ 5 | 6 | #pragma once 7 | 8 | #include "kernel/types.h" 9 | 10 | #include "kernel/integrator/state.h" 11 | 12 | #include "kernel/util/profiling.h" 13 | 14 | CCL_NAMESPACE_BEGIN 15 | 16 | /* Not actually used, just a NULL pointer that gets passed everywhere, which we 17 | * hope gets optimized out by the compiler. */ 18 | struct KernelGlobalsGPU { 19 | int unused[1]; 20 | }; 21 | typedef ccl_global const KernelGlobalsGPU *ccl_restrict KernelGlobals; 22 | 23 | struct KernelParamsCUDA { 24 | /* Global scene data and textures */ 25 | KernelData data; 26 | #define KERNEL_DATA_ARRAY(type, name) const type *name; 27 | #include "kernel/data_arrays.h" 28 | 29 | /* Integrator state */ 30 | IntegratorStateGPU integrator_state; 31 | }; 32 | 33 | #ifdef __KERNEL_GPU__ 34 | __constant__ KernelParamsCUDA kernel_params; 35 | #endif 36 | 37 | /* Abstraction macros */ 38 | #define kernel_data kernel_params.data 39 | #define kernel_data_fetch(name, index) kernel_params.name[(index)] 40 | #define kernel_data_array(name) (kernel_params.name) 41 | #define kernel_integrator_state kernel_params.integrator_state 42 | 43 | CCL_NAMESPACE_END 44 | -------------------------------------------------------------------------------- /src/kernel/device/cuda/kernel.cu: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | /* CUDA kernel entry points */ 5 | 6 | #ifdef __CUDA_ARCH__ 7 | 8 | # include "kernel/device/cuda/compat.h" 9 | # include "kernel/device/cuda/config.h" 10 | # include "kernel/device/cuda/globals.h" 11 | 12 | # include "kernel/device/gpu/image.h" 13 | # include "kernel/device/gpu/kernel.h" 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/kernel/device/gpu/parallel_prefix_sum.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2021-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | CCL_NAMESPACE_BEGIN 7 | 8 | /* Parallel prefix sum. 9 | * 10 | * TODO: actually make this work in parallel. 11 | * 12 | * This is used for an array the size of the number of shaders in the scene 13 | * which is not usually huge, so might not be a significant bottleneck. */ 14 | 15 | #include "util/atomic.h" 16 | 17 | #ifdef __HIP__ 18 | # define GPU_PARALLEL_PREFIX_SUM_DEFAULT_BLOCK_SIZE 1024 19 | #else 20 | # define GPU_PARALLEL_PREFIX_SUM_DEFAULT_BLOCK_SIZE 512 21 | #endif 22 | 23 | __device__ void gpu_parallel_prefix_sum(const int global_id, 24 | ccl_global int *counter, 25 | ccl_global int *prefix_sum, 26 | const int num_values) 27 | { 28 | if (global_id != 0) { 29 | return; 30 | } 31 | 32 | int offset = 0; 33 | for (int i = 0; i < num_values; i++) { 34 | const int new_offset = offset + counter[i]; 35 | prefix_sum[i] = offset; 36 | counter[i] = 0; 37 | offset = new_offset; 38 | } 39 | } 40 | 41 | CCL_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /src/kernel/device/hip/globals.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | /* Constant Globals */ 5 | 6 | #pragma once 7 | 8 | #include "kernel/types.h" 9 | 10 | #include "kernel/integrator/state.h" 11 | 12 | #include "kernel/util/profiling.h" 13 | 14 | CCL_NAMESPACE_BEGIN 15 | 16 | /* Not actually used, just a NULL pointer that gets passed everywhere, which we 17 | * hope gets optimized out by the compiler. */ 18 | struct KernelGlobalsGPU { 19 | int unused[1]; 20 | }; 21 | typedef ccl_global const KernelGlobalsGPU *ccl_restrict KernelGlobals; 22 | 23 | struct KernelParamsHIP { 24 | /* Global scene data and textures */ 25 | KernelData data; 26 | #define KERNEL_DATA_ARRAY(type, name) const type *name; 27 | #include "kernel/data_arrays.h" 28 | 29 | /* Integrator state */ 30 | IntegratorStateGPU integrator_state; 31 | }; 32 | 33 | #ifdef __KERNEL_GPU__ 34 | __constant__ KernelParamsHIP kernel_params; 35 | #endif 36 | 37 | /* Abstraction macros */ 38 | #define kernel_data kernel_params.data 39 | #define kernel_data_fetch(name, index) kernel_params.name[(index)] 40 | #define kernel_data_array(name) (kernel_params.name) 41 | #define kernel_integrator_state kernel_params.integrator_state 42 | 43 | CCL_NAMESPACE_END 44 | -------------------------------------------------------------------------------- /src/kernel/device/hip/kernel.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | /* HIP kernel entry points */ 5 | 6 | #ifdef __HIP_DEVICE_COMPILE__ 7 | 8 | # include "kernel/device/hip/compat.h" 9 | # include "kernel/device/hip/config.h" 10 | # include "kernel/device/hip/globals.h" 11 | 12 | # include "kernel/device/gpu/image.h" 13 | # include "kernel/device/gpu/kernel.h" 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /src/kernel/device/metal/context_end.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2021-2022 Blender Foundation */ 3 | } 4 | ; /* end of MetalKernelContext class definition */ 5 | 6 | /* Silently redirect into the MetalKernelContext instance */ 7 | /* NOTE: These macros will need maintaining as entry-points change. */ 8 | 9 | #undef kernel_integrator_state 10 | #define kernel_integrator_state context.launch_params_metal.integrator_state 11 | -------------------------------------------------------------------------------- /src/kernel/device/metal/function_constants.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2021-2022 Blender Foundation */ 3 | 4 | enum { 5 | Kernel_DummyConstant, 6 | #define KERNEL_STRUCT_MEMBER(parent, type, name) KernelData_##parent##_##name, 7 | #include "kernel/data_template.h" 8 | }; 9 | 10 | #ifdef __KERNEL_METAL__ 11 | # define KERNEL_STRUCT_MEMBER(parent, type, name) \ 12 | constant type kernel_data_##parent##_##name \ 13 | [[function_constant(KernelData_##parent##_##name)]]; 14 | # include "kernel/data_template.h" 15 | #endif 16 | -------------------------------------------------------------------------------- /src/kernel/device/metal/globals.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2021-2022 Blender Foundation */ 3 | 4 | /* Constant Globals */ 5 | 6 | #include "kernel/types.h" 7 | #include "kernel/util/profiling.h" 8 | 9 | #include "kernel/integrator/state.h" 10 | 11 | CCL_NAMESPACE_BEGIN 12 | 13 | typedef struct KernelParamsMetal { 14 | 15 | #define KERNEL_DATA_ARRAY(type, name) ccl_global const type *name; 16 | #include "kernel/data_arrays.h" 17 | #undef KERNEL_DATA_ARRAY 18 | 19 | const IntegratorStateGPU integrator_state; 20 | const KernelData data; 21 | 22 | } KernelParamsMetal; 23 | 24 | typedef struct KernelGlobalsGPU { 25 | int unused[1]; 26 | } KernelGlobalsGPU; 27 | 28 | typedef ccl_global const KernelGlobalsGPU *ccl_restrict KernelGlobals; 29 | 30 | /* Abstraction macros */ 31 | #define kernel_data launch_params_metal.data 32 | #define kernel_data_fetch(name, index) launch_params_metal.name[index] 33 | #define kernel_data_array(name) launch_params_metal.name 34 | #define kernel_integrator_state launch_params_metal.integrator_state 35 | 36 | CCL_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /src/kernel/device/oneapi/context_begin.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2021-2022 Intel Corporation */ 3 | 4 | #ifdef WITH_NANOVDB 5 | # include 6 | # include 7 | #endif 8 | 9 | /* clang-format off */ 10 | struct ONEAPIKernelContext : public KernelGlobalsGPU { 11 | public: 12 | # include "kernel/device/oneapi/image.h" 13 | /* clang-format on */ 14 | -------------------------------------------------------------------------------- /src/kernel/device/oneapi/context_end.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2021-2022 Intel Corporation */ 3 | } 4 | ; /* end of ONEAPIKernelContext class definition */ 5 | 6 | #undef kernel_integrator_state 7 | #define kernel_integrator_state (*(kg->integrator_state)) 8 | -------------------------------------------------------------------------------- /src/kernel/device/optix/kernel_shader_raytrace.cu: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2021-2022 Blender Foundation. */ 3 | 4 | /* Copy of the regular kernels with additional shader ray-tracing kernel that takes 5 | * much longer to compiler. This is only loaded when needed by the scene. */ 6 | 7 | #include "kernel/device/optix/kernel.cu" 8 | 9 | #include "kernel/integrator/shade_surface.h" 10 | 11 | extern "C" __global__ void __raygen__kernel_optix_integrator_shade_surface_raytrace() 12 | { 13 | const int global_index = optixGetLaunchIndex().x; 14 | const int path_index = (kernel_params.path_index_array) ? kernel_params.path_index_array[global_index] : 15 | global_index; 16 | integrator_shade_surface_raytrace(nullptr, path_index, kernel_params.render_buffer); 17 | } 18 | 19 | extern "C" __global__ void __raygen__kernel_optix_integrator_shade_surface_mnee() 20 | { 21 | const int global_index = optixGetLaunchIndex().x; 22 | const int path_index = (kernel_params.path_index_array) ? kernel_params.path_index_array[global_index] : 23 | global_index; 24 | integrator_shade_surface_mnee(nullptr, path_index, kernel_params.render_buffer); 25 | } 26 | -------------------------------------------------------------------------------- /src/kernel/geom/geom.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | // clang-format off 7 | #include "kernel/geom/attribute.h" 8 | #include "kernel/geom/object.h" 9 | #ifdef __PATCH_EVAL__ 10 | # include "kernel/geom/patch.h" 11 | #endif 12 | #include "kernel/geom/triangle.h" 13 | #include "kernel/geom/subd_triangle.h" 14 | #include "kernel/geom/triangle_intersect.h" 15 | #include "kernel/geom/motion_triangle.h" 16 | #include "kernel/geom/motion_triangle_intersect.h" 17 | #include "kernel/geom/motion_triangle_shader.h" 18 | #include "kernel/geom/motion_curve.h" 19 | #include "kernel/geom/motion_point.h" 20 | #include "kernel/geom/point.h" 21 | #include "kernel/geom/point_intersect.h" 22 | #include "kernel/geom/curve.h" 23 | #include "kernel/geom/curve_intersect.h" 24 | #include "kernel/geom/volume.h" 25 | #include "kernel/geom/primitive.h" 26 | #include "kernel/geom/shader_data.h" 27 | // clang-format on 28 | -------------------------------------------------------------------------------- /src/kernel/integrator/displacement_shader.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | /* Functions to evaluate displacement shader. */ 5 | 6 | #pragma once 7 | 8 | #ifdef __SVM__ 9 | # include "kernel/svm/svm.h" 10 | #endif 11 | #ifdef __OSL__ 12 | # include "kernel/osl/osl.h" 13 | #endif 14 | 15 | CCL_NAMESPACE_BEGIN 16 | 17 | template 18 | ccl_device void displacement_shader_eval(KernelGlobals kg, 19 | ConstIntegratorGenericState state, 20 | ccl_private ShaderData *sd) 21 | { 22 | sd->num_closure = 0; 23 | sd->num_closure_left = 0; 24 | 25 | /* this will modify sd->P */ 26 | #ifdef __OSL__ 27 | if (kernel_data.kernel_features & KERNEL_FEATURE_OSL) { 28 | osl_eval_nodes(kg, state, sd, 0); 29 | } 30 | else 31 | #endif 32 | { 33 | #ifdef __SVM__ 34 | svm_eval_nodes( 35 | kg, state, sd, NULL, 0); 36 | #endif 37 | } 38 | } 39 | 40 | CCL_NAMESPACE_END 41 | -------------------------------------------------------------------------------- /src/kernel/integrator/intersect_subsurface.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "kernel/integrator/subsurface.h" 7 | 8 | CCL_NAMESPACE_BEGIN 9 | 10 | ccl_device void integrator_intersect_subsurface(KernelGlobals kg, IntegratorState state) 11 | { 12 | PROFILING_INIT(kg, PROFILING_INTERSECT_SUBSURFACE); 13 | 14 | #ifdef __SUBSURFACE__ 15 | if (subsurface_scatter(kg, state)) { 16 | return; 17 | } 18 | #endif 19 | 20 | integrator_path_terminate(kg, state, DEVICE_KERNEL_INTEGRATOR_INTERSECT_SUBSURFACE); 21 | } 22 | 23 | CCL_NAMESPACE_END 24 | -------------------------------------------------------------------------------- /src/kernel/osl/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2011-2022 Blender Foundation 3 | 4 | set(INC 5 | ../.. 6 | ) 7 | 8 | set(INC_SYS 9 | 10 | ) 11 | 12 | set(SRC 13 | closures.cpp 14 | globals.cpp 15 | services.cpp 16 | ) 17 | 18 | set(HEADER_SRC 19 | closures_setup.h 20 | closures_template.h 21 | globals.h 22 | osl.h 23 | services.h 24 | types.h 25 | ) 26 | 27 | set(LIB 28 | cycles_scene 29 | 30 | ${OSL_LIBRARIES} 31 | ${OPENIMAGEIO_LIBRARIES} 32 | ${PUGIXML_LIBRARIES} 33 | ${CLANG_LIBRARIES} 34 | ${LLVM_LIBRARY} 35 | ) 36 | 37 | # OSL and LLVM are built without RTTI 38 | string(APPEND CMAKE_CXX_FLAGS " ${RTTI_DISABLE_FLAGS}") 39 | 40 | if(APPLE) 41 | # Disable allocation warning on macOS prior to 10.14: the OSLRenderServices 42 | # contains member which is 64 bytes aligned (cache inside of OIIO's 43 | # unordered_map_concurrent). This is not something what the SDK supportsm, but 44 | # since we take care of allocations ourselves is OK to ignore the 45 | # diagnostic message. 46 | string(APPEND CMAKE_CXX_FLAGS " -faligned-allocation") 47 | endif() 48 | 49 | include_directories(${INC}) 50 | include_directories(SYSTEM ${INC_SYS}) 51 | 52 | cycles_add_library(cycles_kernel_osl "${LIB}" ${SRC} ${HEADER_SRC}) 53 | -------------------------------------------------------------------------------- /src/kernel/osl/services_optix.cu: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #define WITH_OSL 5 | 6 | // clang-format off 7 | #include "kernel/device/optix/compat.h" 8 | #include "kernel/device/optix/globals.h" 9 | 10 | #include "kernel/device/gpu/image.h" /* Texture lookup uses normal CUDA intrinsics. */ 11 | 12 | #include "kernel/osl/services_gpu.h" 13 | // clang-format on 14 | 15 | extern "C" __device__ void __direct_callable__dummy_services() 16 | { 17 | } 18 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_absorption_volume.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_absorption_volume(color Color = color(0.8, 0.8, 0.8), 7 | float Density = 1.0, 8 | output closure color Volume = 0) 9 | { 10 | Volume = ((color(1.0, 1.0, 1.0) - Color) * max(Density, 0.0)) * absorption(); 11 | } 12 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_add_closure.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_add_closure(closure color Closure1 = 0, 7 | closure color Closure2 = 0, 8 | output closure color Closure = 0) 9 | { 10 | Closure = Closure1 + Closure2; 11 | } 12 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_ambient_occlusion.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_ambient_occlusion(color ColorIn = color(1.0, 1.0, 1.0), 7 | int samples = 16, 8 | float Distance = 1.0, 9 | normal Normal = N, 10 | int inside = 0, 11 | int only_local = 0, 12 | output color ColorOut = color(1.0, 1.0, 1.0), 13 | output float AO = 1.0) 14 | { 15 | int global_radius = (Distance == 0.0 && !isconnected(Distance)); 16 | 17 | /* Abuse texture call with special @ao token. */ 18 | AO = texture("@ao", 19 | samples, 20 | Distance, 21 | Normal[0], 22 | Normal[1], 23 | Normal[2], 24 | inside, 25 | "sblur", 26 | only_local, 27 | "tblur", 28 | global_radius); 29 | ColorOut = ColorIn * AO; 30 | } 31 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_attribute.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_attribute(string bump_offset = "center", 7 | string name = "", 8 | output point Vector = point(0.0, 0.0, 0.0), 9 | output color Color = 0.0, 10 | output float Fac = 0.0, 11 | output float Alpha = 0.0) 12 | { 13 | float data[4] = {0.0, 0.0, 0.0, 0.0}; 14 | getattribute(name, data); 15 | Color = color(data[0], data[1], data[2]); 16 | Vector = point(Color); 17 | getattribute(name, Fac); 18 | Alpha = data[3]; 19 | 20 | if (bump_offset == "dx") { 21 | Color += Dx(Color); 22 | Vector += Dx(Vector); 23 | Fac += Dx(Fac); 24 | Alpha += Dx(Alpha); 25 | } 26 | else if (bump_offset == "dy") { 27 | Color += Dy(Color); 28 | Vector += Dy(Vector); 29 | Fac += Dy(Fac); 30 | Alpha += Dy(Alpha); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_background.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_background(color Color = 0.8, 7 | float Strength = 1.0, 8 | output closure color Background = 0) 9 | { 10 | Background = Color * Strength * background(); 11 | } 12 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_bevel.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_bevel(int samples = 4, 7 | float Radius = 0.05, 8 | normal NormalIn = N, 9 | output normal NormalOut = N) 10 | { 11 | /* Abuse texture call with special @bevel token. */ 12 | vector bevel_N = (normal)(color)texture("@bevel", samples, Radius); 13 | 14 | /* Preserve input normal. */ 15 | NormalOut = normalize(NormalIn + (bevel_N - N)); 16 | } 17 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_blackbody.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_blackbody(float Temperature = 1200.0, output color Color = 0.0) 7 | { 8 | color rgb = blackbody(Temperature); 9 | 10 | /* Scale by luminance */ 11 | float l = luminance(rgb); 12 | if (l != 0.0) 13 | rgb /= l; 14 | Color = rgb; 15 | } 16 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_brightness.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_brightness(color ColorIn = 0.8, 7 | float Bright = 0.0, 8 | float Contrast = 0.0, 9 | output color ColorOut = 0.8) 10 | { 11 | float a = 1.0 + Contrast; 12 | float b = Bright - Contrast * 0.5; 13 | 14 | ColorOut[0] = max(a * ColorIn[0] + b, 0.0); 15 | ColorOut[1] = max(a * ColorIn[1] + b, 0.0); 16 | ColorOut[2] = max(a * ColorIn[2] + b, 0.0); 17 | } 18 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_camera.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_camera(output vector ViewVector = vector(0.0, 0.0, 0.0), 7 | output float ViewZDepth = 0.0, 8 | output float ViewDistance = 0.0) 9 | { 10 | ViewVector = (vector)transform("world", "camera", P); 11 | 12 | ViewZDepth = fabs(ViewVector[2]); 13 | ViewDistance = length(ViewVector); 14 | 15 | ViewVector = normalize(ViewVector); 16 | } 17 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_checker_texture.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | /* Checker */ 7 | 8 | float checker(point ip) 9 | { 10 | point p; 11 | p[0] = (ip[0] + 0.000001) * 0.999999; 12 | p[1] = (ip[1] + 0.000001) * 0.999999; 13 | p[2] = (ip[2] + 0.000001) * 0.999999; 14 | 15 | int xi = (int)fabs(floor(p[0])); 16 | int yi = (int)fabs(floor(p[1])); 17 | int zi = (int)fabs(floor(p[2])); 18 | 19 | if ((xi % 2 == yi % 2) == (zi % 2)) { 20 | return 1.0; 21 | } 22 | else { 23 | return 0.0; 24 | } 25 | } 26 | 27 | shader node_checker_texture( 28 | int use_mapping = 0, 29 | matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 30 | float Scale = 5.0, 31 | point Vector = P, 32 | color Color1 = 0.8, 33 | color Color2 = 0.2, 34 | output float Fac = 0.0, 35 | output color Color = 0.0) 36 | { 37 | point p = Vector; 38 | 39 | if (use_mapping) 40 | p = transform(mapping, p); 41 | 42 | Fac = checker(p * Scale); 43 | if (Fac == 1.0) { 44 | Color = Color1; 45 | } 46 | else { 47 | Color = Color2; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_clamp.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_clamp(string clamp_type = "minmax", 7 | float Value = 1.0, 8 | float Min = 0.0, 9 | float Max = 1.0, 10 | output float Result = 0.0) 11 | { 12 | Result = (clamp_type == "range" && (Min > Max)) ? clamp(Value, Max, Min) : 13 | clamp(Value, Min, Max); 14 | } 15 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_combine_color.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_combine_color(string color_type = "rgb", 7 | float Red = 0.0, 8 | float Green = 0.0, 9 | float Blue = 0.0, 10 | output color Color = 0.8) 11 | { 12 | if (color_type == "rgb" || color_type == "hsv" || color_type == "hsl") 13 | Color = color(color_type, Red, Green, Blue); 14 | else 15 | warning("%s", "Unknown color space!"); 16 | } 17 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_combine_hsv.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_combine_hsv(float H = 0.0, float S = 0.0, float V = 0.0, output color Color = 0.8) 7 | { 8 | Color = color("hsv", H, S, V); 9 | } 10 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_combine_rgb.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_combine_rgb(float R = 0.0, float G = 0.0, float B = 0.0, output color Image = 0.8) 7 | { 8 | Image = color(R, G, B); 9 | } 10 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_combine_xyz.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_combine_xyz(float X = 0.0, float Y = 0.0, float Z = 0.0, output vector Vector = 0.8) 7 | { 8 | Vector = vector(X, Y, Z); 9 | } 10 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_convert_from_color.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_convert_from_color(color value_color = 0.0, 7 | output string value_string = "", 8 | output float value_float = 0.0, 9 | output int value_int = 0, 10 | output vector value_vector = vector(0.0, 0.0, 0.0), 11 | output point value_point = point(0.0, 0.0, 0.0), 12 | output normal value_normal = normal(0.0, 0.0, 0.0)) 13 | { 14 | value_float = value_color[0] * 0.2126 + value_color[1] * 0.7152 + value_color[2] * 0.0722; 15 | value_int = (int)(value_color[0] * 0.2126 + value_color[1] * 0.7152 + value_color[2] * 0.0722); 16 | value_vector = vector(value_color[0], value_color[1], value_color[2]); 17 | value_point = point(value_color[0], value_color[1], value_color[2]); 18 | value_normal = normal(value_color[0], value_color[1], value_color[2]); 19 | } 20 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_convert_from_float.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_convert_from_float(float value_float = 0.0, 7 | output string value_string = "", 8 | output int value_int = 0, 9 | output color value_color = 0.0, 10 | output vector value_vector = vector(0.0, 0.0, 0.0), 11 | output point value_point = point(0.0, 0.0, 0.0), 12 | output normal value_normal = normal(0.0, 0.0, 0.0)) 13 | { 14 | value_int = (int)value_float; 15 | value_color = color(value_float, value_float, value_float); 16 | value_vector = vector(value_float, value_float, value_float); 17 | value_point = point(value_float, value_float, value_float); 18 | value_normal = normal(value_float, value_float, value_float); 19 | } 20 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_convert_from_int.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_convert_from_int(int value_int = 0, 7 | output string value_string = "", 8 | output float value_float = 0.0, 9 | output color value_color = 0.0, 10 | output vector value_vector = vector(0.0, 0.0, 0.0), 11 | output point value_point = point(0.0, 0.0, 0.0), 12 | output normal value_normal = normal(0.0, 0.0, 0.0)) 13 | { 14 | float f = (float)value_int; 15 | value_float = f; 16 | value_color = color(f, f, f); 17 | value_vector = vector(f, f, f); 18 | value_point = point(f, f, f); 19 | value_normal = normal(f, f, f); 20 | } 21 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_convert_from_normal.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_convert_from_normal(normal value_normal = normal(0.0, 0.0, 0.0), 7 | output string value_string = "", 8 | output float value_float = 0.0, 9 | output int value_int = 0, 10 | output vector value_vector = vector(0.0, 0.0, 0.0), 11 | output color value_color = 0.0, 12 | output point value_point = point(0.0, 0.0, 0.0)) 13 | { 14 | value_float = (value_normal[0] + value_normal[1] + value_normal[2]) * (1.0 / 3.0); 15 | value_int = (int)((value_normal[0] + value_normal[1] + value_normal[2]) * (1.0 / 3.0)); 16 | value_vector = vector(value_normal[0], value_normal[1], value_normal[2]); 17 | value_color = color(value_normal[0], value_normal[1], value_normal[2]); 18 | value_point = point(value_normal[0], value_normal[1], value_normal[2]); 19 | } 20 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_convert_from_point.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_convert_from_point(point value_point = point(0.0, 0.0, 0.0), 7 | output string value_string = "", 8 | output float value_float = 0.0, 9 | output int value_int = 0, 10 | output vector value_vector = vector(0.0, 0.0, 0.0), 11 | output color value_color = 0.0, 12 | output normal value_normal = normal(0.0, 0.0, 0.0)) 13 | { 14 | value_float = (value_point[0] + value_point[1] + value_point[2]) * (1.0 / 3.0); 15 | value_int = (int)((value_normal[0] + value_normal[1] + value_normal[2]) * (1.0 / 3.0)); 16 | value_vector = vector(value_point[0], value_point[1], value_point[2]); 17 | value_color = color(value_point[0], value_point[1], value_point[2]); 18 | value_normal = normal(value_point[0], value_point[1], value_point[2]); 19 | } 20 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_convert_from_string.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_convert_from_string(string value_string = "", 7 | output color value_color = color(0.0, 0.0, 0.0), 8 | output float value_float = 0.0, 9 | output int value_int = 0, 10 | output vector value_vector = vector(0.0, 0.0, 0.0), 11 | output point value_point = point(0.0, 0.0, 0.0), 12 | output normal value_normal = normal(0.0, 0.0, 0.0)) 13 | { 14 | } 15 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_convert_from_vector.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_convert_from_vector(vector value_vector = vector(0.0, 0.0, 0.0), 7 | output string value_string = "", 8 | output float value_float = 0.0, 9 | output int value_int = 0, 10 | output color value_color = color(0.0, 0.0, 0.0), 11 | output point value_point = point(0.0, 0.0, 0.0), 12 | output normal value_normal = normal(0.0, 0.0, 0.0)) 13 | { 14 | value_float = (value_vector[0] + value_vector[1] + value_vector[2]) * (1.0 / 3.0); 15 | value_int = (int)((value_normal[0] + value_normal[1] + value_normal[2]) * (1.0 / 3.0)); 16 | value_color = color(value_vector[0], value_vector[1], value_vector[2]); 17 | value_point = point(value_vector[0], value_vector[1], value_vector[2]); 18 | value_normal = normal(value_vector[0], value_vector[1], value_vector[2]); 19 | } 20 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_diffuse_bsdf.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_diffuse_bsdf(color Color = 0.8, 7 | float Roughness = 0.0, 8 | normal Normal = N, 9 | output closure color BSDF = 0) 10 | { 11 | if (Roughness == 0.0) 12 | BSDF = Color * diffuse(Normal); 13 | else 14 | BSDF = Color * oren_nayar(Normal, Roughness); 15 | } 16 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_displacement.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_displacement(string space = "object", 7 | float Height = 0.0, 8 | float Midlevel = 0.5, 9 | float Scale = 1.0, 10 | normal Normal = N, 11 | output vector Displacement = vector(0.0, 0.0, 0.0)) 12 | { 13 | Displacement = Normal; 14 | if (space == "object") { 15 | Displacement = transform("object", Displacement); 16 | } 17 | 18 | Displacement = normalize(Displacement) * (Height - Midlevel) * Scale; 19 | 20 | if (space == "object") { 21 | Displacement = transform("object", "world", Displacement); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_emission.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_emission(color Color = 0.8, float Strength = 1.0, output closure color Emission = 0) 7 | { 8 | Emission = (Strength * Color) * emission(); 9 | } 10 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_float_curve.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "node_ramp_util.h" 5 | #include "stdcycles.h" 6 | 7 | shader node_float_curve(float ramp[] = {0.0}, 8 | float min_x = 0.0, 9 | float max_x = 1.0, 10 | int extrapolate = 1, 11 | 12 | float ValueIn = 0.0, 13 | float Factor = 0.0, 14 | output float ValueOut = 0.0) 15 | { 16 | float c = (ValueIn - min_x) / (max_x - min_x); 17 | 18 | ValueOut = rgb_ramp_lookup(ramp, c, 1, extrapolate); 19 | 20 | ValueOut = mix(ValueIn, ValueOut, Factor); 21 | } 22 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_fresnel.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause 2 | * 3 | * Adapted from Open Shading Language 4 | * Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al. 5 | * All Rights Reserved. 6 | * 7 | * Modifications Copyright 2011-2022 Blender Foundation. */ 8 | 9 | float fresnel_dielectric_cos(float cosi, float eta) 10 | { 11 | /* compute fresnel reflectance without explicitly computing 12 | * the refracted direction */ 13 | float c = fabs(cosi); 14 | float g = eta * eta - 1 + c * c; 15 | float result; 16 | 17 | if (g > 0) { 18 | g = sqrt(g); 19 | float A = (g - c) / (g + c); 20 | float B = (c * (g + c) - 1) / (c * (g - c) + 1); 21 | result = 0.5 * A * A * (1 + B * B); 22 | } 23 | else 24 | result = 1.0; /* TIR (no refracted component) */ 25 | 26 | return result; 27 | } 28 | 29 | color fresnel_conductor(float cosi, color eta, color k) 30 | { 31 | color cosi2 = color(cosi * cosi); 32 | color one = color(1, 1, 1); 33 | color tmp_f = eta * eta + k * k; 34 | color tmp = tmp_f * cosi2; 35 | color Rparl2 = (tmp - (2.0 * eta * cosi) + one) / (tmp + (2.0 * eta * cosi) + one); 36 | color Rperp2 = (tmp_f - (2.0 * eta * cosi) + cosi2) / (tmp_f + (2.0 * eta * cosi) + cosi2); 37 | return (Rparl2 + Rperp2) * 0.5; 38 | } 39 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_fresnel.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "node_fresnel.h" 5 | #include "stdcycles.h" 6 | 7 | shader node_fresnel(float IOR = 1.45, normal Normal = N, output float Fac = 0.0) 8 | { 9 | float f = max(IOR, 1e-5); 10 | float eta = backfacing() ? 1.0 / f : f; 11 | float cosi = dot(I, Normal); 12 | Fac = fresnel_dielectric_cos(cosi, eta); 13 | } 14 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_gamma.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_gamma(color ColorIn = 0.8, float Gamma = 1.0, output color ColorOut = 0.0) 7 | { 8 | ColorOut = pow(ColorIn, Gamma); 9 | } 10 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_glossy_bsdf.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "node_fresnel.h" 5 | #include "stdcycles.h" 6 | 7 | shader node_glossy_bsdf(color Color = 0.8, 8 | string distribution = "GGX", 9 | float Roughness = 0.2, 10 | normal Normal = N, 11 | output closure color BSDF = 0) 12 | { 13 | float roughness = Roughness * Roughness; 14 | 15 | if (distribution == "sharp") 16 | BSDF = Color * reflection(Normal); 17 | else if (distribution == "beckmann") 18 | BSDF = Color * microfacet_beckmann(Normal, roughness); 19 | else if (distribution == "GGX") 20 | BSDF = Color * microfacet_ggx(Normal, roughness); 21 | else if (distribution == "Multiscatter GGX") 22 | BSDF = Color * microfacet_multi_ggx(Normal, roughness, Color); 23 | else 24 | BSDF = Color * ashikhmin_shirley(Normal, vector(0, 0, 0), roughness, roughness); 25 | } 26 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_hair_bsdf.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_hair_bsdf(color Color = 0.8, 7 | string component = "reflection", 8 | float Offset = 0.0, 9 | float RoughnessU = 0.1, 10 | float RoughnessV = 1.0, 11 | normal Tangent = normal(0, 0, 0), 12 | output closure color BSDF = 0) 13 | { 14 | float roughnessh = clamp(RoughnessU, 0.001, 1.0); 15 | float roughnessv = clamp(RoughnessV, 0.001, 1.0); 16 | float offset = -Offset; 17 | 18 | normal T; 19 | float IsCurve = 0; 20 | getattribute("geom:is_curve", IsCurve); 21 | 22 | if (isconnected(Tangent)) { 23 | T = Tangent; 24 | } 25 | else if (!IsCurve) { 26 | T = normalize(dPdv); 27 | offset = 0.0; 28 | } 29 | else { 30 | T = normalize(dPdu); 31 | } 32 | 33 | if (backfacing() && IsCurve) { 34 | BSDF = transparent(); 35 | } 36 | else { 37 | if (component == "reflection") 38 | BSDF = Color * hair_reflection(Ng, roughnessh, roughnessv, T, offset); 39 | else 40 | BSDF = Color * hair_transmission(Ng, roughnessh, roughnessv, T, offset); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_hair_info.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_hair_info(output float IsStrand = 0.0, 7 | output float Intercept = 0.0, 8 | output float Length = 0.0, 9 | output float Thickness = 0.0, 10 | output normal TangentNormal = N, 11 | output float Random = 0) 12 | { 13 | getattribute("geom:is_curve", IsStrand); 14 | getattribute("geom:curve_intercept", Intercept); 15 | getattribute("geom:curve_length", Length); 16 | getattribute("geom:curve_thickness", Thickness); 17 | getattribute("geom:curve_tangent_normal", TangentNormal); 18 | getattribute("geom:curve_random", Random); 19 | } 20 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_holdout.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_holdout(output closure color Holdout = holdout()) 7 | { 8 | } 9 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_hsv.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "node_color.h" 5 | #include "stdcycles.h" 6 | 7 | shader node_hsv(float Hue = 0.5, 8 | float Saturation = 1.0, 9 | float Value = 1.0, 10 | float Fac = 0.5, 11 | color ColorIn = 0.0, 12 | output color ColorOut = 0.0) 13 | { 14 | color Color = rgb_to_hsv(ColorIn); 15 | 16 | // remember: fmod doesn't work for negative numbers 17 | Color[0] = fmod(Color[0] + Hue + 0.5, 1.0); 18 | Color[1] = clamp(Color[1] * Saturation, 0.0, 1.0); 19 | Color[2] *= Value; 20 | 21 | Color = hsv_to_rgb(Color); 22 | 23 | // Clamp color to prevent negative values cauzed by oversaturation. 24 | Color[0] = max(Color[0], 0.0); 25 | Color[1] = max(Color[1], 0.0); 26 | Color[2] = max(Color[2], 0.0); 27 | 28 | ColorOut = mix(ColorIn, Color, Fac); 29 | } 30 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_ies_light.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | /* IES Light */ 7 | 8 | shader node_ies_light(int use_mapping = 0, 9 | matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 10 | string filename = "", 11 | float Strength = 1.0, 12 | point Vector = I, 13 | output float Fac = 0.0) 14 | { 15 | point p = Vector; 16 | 17 | if (use_mapping) { 18 | p = transform(mapping, p); 19 | } 20 | 21 | p = normalize((vector)p); 22 | 23 | float v_angle = acos(-p[2]); 24 | float h_angle = atan2(p[0], p[1]) + M_PI; 25 | 26 | Fac = Strength * texture(filename, h_angle, v_angle); 27 | } 28 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_invert.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_invert(float Fac = 1.0, color ColorIn = 0.8, output color ColorOut = 0.8) 7 | { 8 | color ColorInv = color(1.0) - ColorIn; 9 | ColorOut = mix(ColorIn, ColorInv, Fac); 10 | } 11 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_layer_weight.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "node_fresnel.h" 5 | #include "stdcycles.h" 6 | 7 | shader node_layer_weight(float Blend = 0.5, 8 | normal Normal = N, 9 | output float Fresnel = 0.0, 10 | output float Facing = 0.0) 11 | { 12 | float blend = Blend; 13 | float cosi = dot(I, Normal); 14 | 15 | /* Fresnel */ 16 | float eta = max(1.0 - Blend, 1e-5); 17 | eta = backfacing() ? eta : 1.0 / eta; 18 | Fresnel = fresnel_dielectric_cos(cosi, eta); 19 | 20 | /* Facing */ 21 | Facing = fabs(cosi); 22 | 23 | if (blend != 0.5) { 24 | blend = clamp(blend, 0.0, 1.0 - 1e-5); 25 | blend = (blend < 0.5) ? 2.0 * blend : 0.5 / (1.0 - blend); 26 | 27 | Facing = pow(Facing, blend); 28 | } 29 | 30 | Facing = 1.0 - Facing; 31 | } 32 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_light_falloff.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_light_falloff(float Strength = 0.0, 7 | float Smooth = 0.0, 8 | output float Quadratic = 0.0, 9 | output float Linear = 0.0, 10 | output float Constant = 0.0) 11 | { 12 | float ray_length = 0.0; 13 | float strength = Strength; 14 | getattribute("path:ray_length", ray_length); 15 | 16 | if (Smooth > 0.0) { 17 | float squared = ray_length * ray_length; 18 | strength *= squared / (Smooth + squared); 19 | } 20 | 21 | /* Quadratic */ 22 | Quadratic = strength; 23 | 24 | /* Linear */ 25 | Linear = (strength * ray_length); 26 | 27 | /* Constant */ 28 | Constant = (strength * ray_length * ray_length); 29 | } 30 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_mix_closure.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_mix_closure(float Fac = 0.5, 7 | closure color Closure1 = 0, 8 | closure color Closure2 = 0, 9 | output closure color Closure = 0) 10 | { 11 | float t = clamp(Fac, 0.0, 1.0); 12 | Closure = (1.0 - t) * Closure1 + t * Closure2; 13 | } 14 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_mix_float.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_mix_float( 7 | int use_clamp = 0, float Factor = 0.5, float A = 0.0, float B = 0.0, output float Result = 0.0) 8 | { 9 | float t = (use_clamp) ? clamp(Factor, 0.0, 1.0) : Factor; 10 | Result = mix(A, B, t); 11 | } 12 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_mix_vector.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_mix_vector(int use_clamp = 0, 7 | float Factor = 0.5, 8 | vector A = 0.0, 9 | vector B = 0.0, 10 | output vector Result = 0.0) 11 | { 12 | float t = (use_clamp) ? clamp(Factor, 0.0, 1.0) : Factor; 13 | Result = mix(A, B, t); 14 | } 15 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_mix_vector_non_uniform.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_mix_vector_non_uniform(int use_clamp = 0, 7 | vector Factor = 0.5, 8 | vector A = 0.0, 9 | vector B = 0.0, 10 | output vector Result = 0.0) 11 | { 12 | vector t = (use_clamp) ? clamp(Factor, 0.0, 1.0) : Factor; 13 | Result = mix(A, B, t); 14 | } 15 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_normal.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_normal(normal direction = normal(0.0, 0.0, 0.0), 7 | normal NormalIn = normal(0.0, 0.0, 0.0), 8 | output normal NormalOut = normal(0.0, 0.0, 0.0), 9 | output float Dot = 1.0) 10 | { 11 | NormalOut = normalize(direction); 12 | Dot = dot(NormalOut, normalize(NormalIn)); 13 | } 14 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_object_info.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_object_info(output point Location = point(0.0, 0.0, 0.0), 7 | output color Color = color(1.0, 1.0, 1.0), 8 | output float Alpha = 1.0, 9 | output float ObjectIndex = 0.0, 10 | output float MaterialIndex = 0.0, 11 | output float Random = 0.0) 12 | { 13 | getattribute("object:location", Location); 14 | getattribute("object:color", Color); 15 | getattribute("object:alpha", Alpha); 16 | getattribute("object:index", ObjectIndex); 17 | getattribute("material:index", MaterialIndex); 18 | getattribute("object:random", Random); 19 | } 20 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_output_displacement.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | displacement node_output_displacement(vector Displacement = 0.0) 7 | { 8 | P += Displacement; 9 | } 10 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_output_surface.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | surface node_output_surface(closure color Surface = 0) 7 | { 8 | Ci = Surface; 9 | } 10 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_output_volume.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | volume node_output_volume(closure color Volume = 0) 7 | { 8 | Ci = Volume; 9 | } 10 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_particle_info.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_particle_info(output float Index = 0.0, 7 | output float Random = 0.0, 8 | output float Age = 0.0, 9 | output float Lifetime = 0.0, 10 | output point Location = point(0.0, 0.0, 0.0), 11 | output float Size = 0.0, 12 | output vector Velocity = point(0.0, 0.0, 0.0), 13 | output vector AngularVelocity = point(0.0, 0.0, 0.0)) 14 | { 15 | getattribute("particle:index", Index); 16 | getattribute("particle:random", Random); 17 | getattribute("particle:age", Age); 18 | getattribute("particle:lifetime", Lifetime); 19 | getattribute("particle:location", Location); 20 | getattribute("particle:size", Size); 21 | getattribute("particle:velocity", Velocity); 22 | getattribute("particle:angular_velocity", AngularVelocity); 23 | } 24 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_point_info.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_point_info(output point Position = point(0.0, 0.0, 0.0), 7 | output float Radius = 0.0, 8 | output float Random = 0.0) 9 | { 10 | getattribute("geom:point_position", Position); 11 | getattribute("geom:point_radius", Radius); 12 | getattribute("geom:point_random", Random); 13 | } 14 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_refraction_bsdf.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_refraction_bsdf(color Color = 0.8, 7 | string distribution = "sharp", 8 | float Roughness = 0.2, 9 | float IOR = 1.45, 10 | normal Normal = N, 11 | output closure color BSDF = 0) 12 | { 13 | float f = max(IOR, 1e-5); 14 | float eta = backfacing() ? 1.0 / f : f; 15 | float roughness = Roughness * Roughness; 16 | 17 | if (distribution == "sharp") 18 | BSDF = Color * refraction(Normal, eta); 19 | else if (distribution == "beckmann") 20 | BSDF = Color * microfacet_beckmann_refraction(Normal, roughness, eta); 21 | else if (distribution == "GGX") 22 | BSDF = Color * microfacet_ggx_refraction(Normal, roughness, eta); 23 | } 24 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_rgb_curves.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "node_ramp_util.h" 5 | #include "stdcycles.h" 6 | 7 | shader node_rgb_curves(color ramp[] = {0.0}, 8 | float min_x = 0.0, 9 | float max_x = 1.0, 10 | int extrapolate = 1, 11 | 12 | color ColorIn = 0.0, 13 | float Fac = 0.0, 14 | output color ColorOut = 0.0) 15 | { 16 | color c = (ColorIn - color(min_x, min_x, min_x)) / (max_x - min_x); 17 | 18 | color r = rgb_ramp_lookup(ramp, c[0], 1, extrapolate); 19 | color g = rgb_ramp_lookup(ramp, c[1], 1, extrapolate); 20 | color b = rgb_ramp_lookup(ramp, c[2], 1, extrapolate); 21 | 22 | ColorOut[0] = r[0]; 23 | ColorOut[1] = g[1]; 24 | ColorOut[2] = b[2]; 25 | 26 | ColorOut = mix(ColorIn, ColorOut, Fac); 27 | } 28 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_rgb_ramp.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "node_ramp_util.h" 5 | #include "stdcycles.h" 6 | 7 | shader node_rgb_ramp(color ramp_color[] = {0.0}, 8 | float ramp_alpha[] = {0.0}, 9 | int interpolate = 1, 10 | 11 | float Fac = 0.0, 12 | output color Color = 0.0, 13 | output float Alpha = 1.0) 14 | { 15 | Color = rgb_ramp_lookup(ramp_color, Fac, interpolate, 0); 16 | Alpha = rgb_ramp_lookup(ramp_alpha, Fac, interpolate, 0); 17 | } 18 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_rgb_to_bw.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_rgb_to_bw(color Color = 0.0, output float Val = 0.0) 7 | { 8 | Val = Color[0] * 0.2126 + Color[1] * 0.7152 + Color[2] * 0.0722; 9 | } 10 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_scatter_volume.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_scatter_volume(color Color = color(0.8, 0.8, 0.8), 7 | float Density = 1.0, 8 | float Anisotropy = 0.0, 9 | output closure color Volume = 0) 10 | { 11 | Volume = (Color * max(Density, 0.0)) * henyey_greenstein(Anisotropy); 12 | } 13 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_separate_color.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "node_color.h" 5 | #include "stdcycles.h" 6 | 7 | shader node_separate_color(string color_type = "rgb", 8 | color Color = 0.8, 9 | output float Red = 0.0, 10 | output float Green = 0.0, 11 | output float Blue = 0.0) 12 | { 13 | color col; 14 | if (color_type == "rgb") 15 | col = Color; 16 | else if (color_type == "hsv") 17 | col = rgb_to_hsv(Color); 18 | else if (color_type == "hsl") 19 | col = rgb_to_hsl(Color); 20 | else 21 | warning("%s", "Unknown color space!"); 22 | 23 | Red = col[0]; 24 | Green = col[1]; 25 | Blue = col[2]; 26 | } 27 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_separate_hsv.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "node_color.h" 5 | #include "stdcycles.h" 6 | 7 | shader node_separate_hsv(color Color = 0.8, 8 | output float H = 0.0, 9 | output float S = 0.0, 10 | output float V = 0.0) 11 | { 12 | color col = rgb_to_hsv(Color); 13 | 14 | H = col[0]; 15 | S = col[1]; 16 | V = col[2]; 17 | } 18 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_separate_rgb.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_separate_rgb(color Image = 0.8, 7 | output float R = 0.0, 8 | output float G = 0.0, 9 | output float B = 0.0) 10 | { 11 | R = Image[0]; 12 | G = Image[1]; 13 | B = Image[2]; 14 | } 15 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_separate_xyz.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_separate_xyz(vector Vector = 0.8, 7 | output float X = 0.0, 8 | output float Y = 0.0, 9 | output float Z = 0.0) 10 | { 11 | X = Vector[0]; 12 | Y = Vector[1]; 13 | Z = Vector[2]; 14 | } 15 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_set_normal.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | surface node_set_normal(normal Direction = N, output normal Normal = N) 7 | { 8 | N = Direction; 9 | Normal = Direction; 10 | } 11 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_subsurface_scattering.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_subsurface_scattering(color Color = 0.8, 7 | float Scale = 1.0, 8 | vector Radius = vector(0.1, 0.1, 0.1), 9 | float IOR = 1.4, 10 | float Anisotropy = 0.0, 11 | string method = "random_walk", 12 | normal Normal = N, 13 | output closure color BSSRDF = 0) 14 | { 15 | BSSRDF = Color * 16 | bssrdf(method, Normal, Scale * Radius, Color, "ior", IOR, "anisotropy", Anisotropy); 17 | } 18 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_tangent.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_tangent(string attr_name = "geom:tangent", 7 | string direction_type = "radial", 8 | string axis = "z", 9 | output normal Tangent = normalize(dPdu)) 10 | { 11 | vector T = vector(0.0, 0.0, 0.0); 12 | 13 | if (direction_type == "uv_map") { 14 | getattribute(attr_name, T); 15 | } 16 | else if (direction_type == "radial") { 17 | point generated; 18 | 19 | if (!getattribute("geom:generated", generated)) 20 | generated = P; 21 | 22 | if (axis == "x") 23 | T = vector(0.0, -(generated[2] - 0.5), (generated[1] - 0.5)); 24 | else if (axis == "y") 25 | T = vector(-(generated[2] - 0.5), 0.0, (generated[0] - 0.5)); 26 | else 27 | T = vector(-(generated[1] - 0.5), (generated[0] - 0.5), 0.0); 28 | } 29 | 30 | T = transform("object", "world", T); 31 | Tangent = cross(N, normalize(cross(T, N))); 32 | } 33 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_toon_bsdf.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_toon_bsdf(color Color = 0.8, 7 | string component = "diffuse", 8 | float Size = 0.5, 9 | float Smooth = 0.0, 10 | normal Normal = N, 11 | output closure color BSDF = 0) 12 | { 13 | if (component == "diffuse") 14 | BSDF = Color * diffuse_toon(Normal, Size, Smooth); 15 | else if (component == "glossy") 16 | BSDF = Color * glossy_toon(Normal, Size, Smooth); 17 | } 18 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_translucent_bsdf.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_translucent_bsdf(color Color = 0.8, normal Normal = N, output closure color BSDF = 0) 7 | { 8 | BSDF = Color * translucent(Normal); 9 | } 10 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_transparent_bsdf.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_transparent_bsdf(color Color = 0.8, normal Normal = N, output closure color BSDF = 0) 7 | { 8 | BSDF = Color * transparent(); 9 | } 10 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_uv_map.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_uv_map(int from_dupli = 0, 7 | string attribute = "", 8 | string bump_offset = "center", 9 | output point UV = point(0.0, 0.0, 0.0)) 10 | { 11 | if (from_dupli) { 12 | getattribute("geom:dupli_uv", UV); 13 | } 14 | else { 15 | if (attribute == "") 16 | getattribute("geom:uv", UV); 17 | else 18 | getattribute(attribute, UV); 19 | } 20 | 21 | if (bump_offset == "dx") { 22 | if (!from_dupli) { 23 | UV += Dx(UV); 24 | } 25 | } 26 | else if (bump_offset == "dy") { 27 | if (!from_dupli) { 28 | UV += Dy(UV); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_value.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_value(float value_value = 0.0, 7 | vector vector_value = vector(0.0, 0.0, 0.0), 8 | color color_value = 0.0, 9 | output float Value = 0.0, 10 | output vector Vector = vector(0.0, 0.0, 0.0), 11 | output color Color = 0.0) 12 | { 13 | Value = value_value; 14 | Vector = vector_value; 15 | Color = color_value; 16 | } 17 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_vector_curves.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "node_ramp_util.h" 5 | #include "stdcycles.h" 6 | 7 | shader node_vector_curves(color ramp[] = {0.0}, 8 | float min_x = 0.0, 9 | float max_x = 1.0, 10 | int extrapolate = 1, 11 | 12 | vector VectorIn = vector(0.0, 0.0, 0.0), 13 | float Fac = 0.0, 14 | output vector VectorOut = vector(0.0, 0.0, 0.0)) 15 | { 16 | vector c = (VectorIn - vector(min_x, min_x, min_x)) / (max_x - min_x); 17 | 18 | color r = rgb_ramp_lookup(ramp, c[0], 1, extrapolate); 19 | color g = rgb_ramp_lookup(ramp, c[0], 1, extrapolate); 20 | color b = rgb_ramp_lookup(ramp, c[0], 1, extrapolate); 21 | 22 | VectorOut[0] = r[0]; 23 | VectorOut[1] = g[1]; 24 | VectorOut[2] = b[2]; 25 | 26 | VectorOut = mix(VectorIn, VectorOut, Fac); 27 | } 28 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_vector_transform.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_vector_transform(string transform_type = "vector", 7 | string convert_from = "world", 8 | string convert_to = "object", 9 | vector VectorIn = vector(0.0, 0.0, 0.0), 10 | output vector VectorOut = vector(0.0, 0.0, 0.0)) 11 | { 12 | if (transform_type == "vector" || transform_type == "normal") { 13 | VectorOut = transform(convert_from, convert_to, VectorIn); 14 | if (transform_type == "normal") 15 | VectorOut = normalize(VectorOut); 16 | } 17 | else if (transform_type == "point") { 18 | point Point = (point)VectorIn; 19 | VectorOut = transform(convert_from, convert_to, Point); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_velvet_bsdf.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "node_fresnel.h" 5 | #include "stdcycles.h" 6 | 7 | shader node_velvet_bsdf(color Color = 0.8, 8 | float Sigma = 0.0, 9 | normal Normal = N, 10 | output closure color BSDF = 0) 11 | { 12 | float sigma = clamp(Sigma, 0.0, 1.0); 13 | 14 | BSDF = Color * ashikhmin_velvet(Normal, sigma); 15 | } 16 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_vertex_color.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_vertex_color(string bump_offset = "center", 7 | string layer_name = "", 8 | output color Color = 0.0, 9 | output float Alpha = 0.0) 10 | { 11 | float vertex_color[4]; 12 | string vertex_color_layer; 13 | 14 | if (layer_name == "") { 15 | vertex_color_layer = "geom:vertex_color"; 16 | } 17 | else { 18 | vertex_color_layer = layer_name; 19 | } 20 | 21 | if (getattribute(vertex_color_layer, vertex_color)) { 22 | Color = color(vertex_color[0], vertex_color[1], vertex_color[2]); 23 | Alpha = vertex_color[3]; 24 | 25 | if (bump_offset == "dx") { 26 | Color += Dx(Color); 27 | Alpha += Dx(Alpha); 28 | } 29 | else if (bump_offset == "dy") { 30 | Color += Dy(Color); 31 | Alpha += Dy(Alpha); 32 | } 33 | } 34 | else { 35 | warning("%s", "Invalid attribute."); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_voxel_texture.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_voxel_texture(string filename = "", 7 | string interpolation = "linear", 8 | int use_mapping = 0, 9 | matrix mapping = matrix(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), 10 | point Vector = P, 11 | output float Density = 0, 12 | output color Color = 0) 13 | { 14 | point p = Vector; 15 | if (use_mapping) { 16 | p = transform(mapping, p); 17 | } 18 | else { 19 | p = transform("object", Vector); 20 | matrix tfm; 21 | if (getattribute("geom:generated_transform", tfm)) 22 | p = transform(tfm, p); 23 | } 24 | if (p[0] < 0.0 || p[1] < 0.0 || p[2] < 0.0 || p[0] > 1.0 || p[1] > 1.0 || p[2] > 1.0) { 25 | Density = 0; 26 | Color = color(0, 0, 0); 27 | } 28 | else { 29 | Color = (color)texture3d( 30 | filename, p, "wrap", "periodic", "interp", interpolation, "alpha", Density); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_wavelength.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "stdcycles.h" 5 | 6 | shader node_wavelength(float Wavelength = 500.0, output color Color = 0.0) 7 | { 8 | Color = wavelength_color(Wavelength); 9 | } 10 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_white_noise_texture.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "node_hash.h" 5 | #include "stdcycles.h" 6 | #include "vector2.h" 7 | #include "vector4.h" 8 | 9 | #define vector3 point 10 | 11 | shader node_white_noise_texture(string dimensions = "3D", 12 | point Vector = point(0.0, 0.0, 0.0), 13 | float W = 0.0, 14 | output float Value = 0.0, 15 | output color Color = 0.0) 16 | { 17 | if (dimensions == "1D") { 18 | Value = noise("hash", W); 19 | Color = hash_float_to_color(W); 20 | } 21 | else if (dimensions == "2D") { 22 | Value = noise("hash", Vector[0], Vector[1]); 23 | Color = hash_vector2_to_color(vector2(Vector[0], Vector[1])); 24 | } 25 | else if (dimensions == "3D") { 26 | Value = noise("hash", Vector); 27 | Color = hash_vector3_to_color(vector3(Vector[0], Vector[1], Vector[2])); 28 | } 29 | else if (dimensions == "4D") { 30 | Value = noise("hash", Vector, W); 31 | Color = hash_vector4_to_color(vector4(Vector[0], Vector[1], Vector[2], W)); 32 | } 33 | else { 34 | warning("%s", "Unknown dimension!"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/kernel/osl/shaders/node_wireframe.osl: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "oslutil.h" 5 | #include "stdcycles.h" 6 | 7 | shader node_wireframe(string bump_offset = "center", 8 | int use_pixel_size = 0, 9 | float Size = 0.01, 10 | output float Fac = 0.0) 11 | { 12 | Fac = wireframe("triangles", Size, use_pixel_size); 13 | /* TODO(sergey): Since we can't use autodiff here we do algebraic 14 | * calculation of derivatives by definition. We could probably 15 | * optimize this a bit by doing some extra calculation in wireframe(). 16 | */ 17 | if (bump_offset == "dx") { 18 | point dx = Dx(P); 19 | P -= dx; 20 | Fac += (Fac - wireframe("triangles", Size, use_pixel_size)) / length(dx); 21 | } 22 | else if (bump_offset == "dy") { 23 | point dy = Dy(P); 24 | P -= dy; 25 | Fac += (Fac - wireframe("triangles", Size, use_pixel_size)) / length(dy); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/kernel/sample/lcg.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | CCL_NAMESPACE_BEGIN 7 | 8 | /* Linear Congruential Generator */ 9 | 10 | /* This is templated to handle multiple address spaces on Metal. */ 11 | template ccl_device uint lcg_step_uint(T rng) 12 | { 13 | /* implicit mod 2^32 */ 14 | *rng = (1103515245 * (*rng) + 12345); 15 | return *rng; 16 | } 17 | 18 | /* This is templated to handle multiple address spaces on Metal. */ 19 | template ccl_device float lcg_step_float(T rng) 20 | { 21 | /* implicit mod 2^32 */ 22 | *rng = (1103515245 * (*rng) + 12345); 23 | return (float)*rng * (1.0f / (float)0xFFFFFFFF); 24 | } 25 | 26 | ccl_device uint lcg_init(uint seed) 27 | { 28 | uint rng = seed; 29 | lcg_step_uint(&rng); 30 | return rng; 31 | } 32 | 33 | ccl_device_inline uint lcg_state_init(const uint rng_hash, 34 | const uint rng_offset, 35 | const uint sample, 36 | const uint scramble) 37 | { 38 | return lcg_init(rng_hash + rng_offset + sample * scramble); 39 | } 40 | 41 | CCL_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /src/kernel/sample/mis.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause 2 | * 3 | * Adapted from Open Shading Language 4 | * Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al. 5 | * All Rights Reserved. 6 | * 7 | * Modifications Copyright 2011-2022 Blender Foundation. */ 8 | 9 | #pragma once 10 | 11 | CCL_NAMESPACE_BEGIN 12 | 13 | /* Multiple importance sampling utilities. */ 14 | 15 | ccl_device float balance_heuristic(float a, float b) 16 | { 17 | return (a) / (a + b); 18 | } 19 | 20 | ccl_device float balance_heuristic_3(float a, float b, float c) 21 | { 22 | return (a) / (a + b + c); 23 | } 24 | 25 | ccl_device float power_heuristic(float a, float b) 26 | { 27 | return (a * a) / (a * a + b * b); 28 | } 29 | 30 | ccl_device float power_heuristic_3(float a, float b, float c) 31 | { 32 | return (a * a) / (a * a + b * b + c * c); 33 | } 34 | 35 | ccl_device float max_heuristic(float a, float b) 36 | { 37 | return (a > b) ? 1.0f : 0.0f; 38 | } 39 | 40 | CCL_NAMESPACE_END 41 | -------------------------------------------------------------------------------- /src/kernel/sample/util.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "util/types.h" 7 | 8 | CCL_NAMESPACE_BEGIN 9 | 10 | /* 11 | * Performs base-2 Owen scrambling on a reversed-bit unsigned integer. 12 | * 13 | * This is equivalent to the Laine-Karras permutation, but much higher 14 | * quality. See https://psychopath.io/post/2021_01_30_building_a_better_lk_hash 15 | */ 16 | ccl_device_inline uint reversed_bit_owen(uint n, uint seed) 17 | { 18 | n ^= n * 0x3d20adea; 19 | n += seed; 20 | n *= (seed >> 16) | 1; 21 | n ^= n * 0x05526c56; 22 | n ^= n * 0x53a22864; 23 | 24 | return n; 25 | } 26 | 27 | /* 28 | * Performs base-2 Owen scrambling on an unsigned integer. 29 | */ 30 | ccl_device_inline uint nested_uniform_scramble(uint i, uint seed) 31 | { 32 | return reverse_integer_bits(reversed_bit_owen(reverse_integer_bits(i), seed)); 33 | } 34 | 35 | CCL_NAMESPACE_END 36 | -------------------------------------------------------------------------------- /src/kernel/svm/blackbody.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: BSD-3-Clause 2 | * 3 | * Adapted from Open Shading Language 4 | * Copyright (c) 2009-2010 Sony Pictures Imageworks Inc., et al. 5 | * All Rights Reserved. 6 | * 7 | * Modifications Copyright 2011-2022 Blender Foundation. */ 8 | 9 | #pragma once 10 | 11 | #include "kernel/svm/math_util.h" 12 | 13 | CCL_NAMESPACE_BEGIN 14 | 15 | /* Blackbody Node */ 16 | 17 | ccl_device_noinline void svm_node_blackbody(KernelGlobals kg, 18 | ccl_private ShaderData *sd, 19 | ccl_private float *stack, 20 | uint temperature_offset, 21 | uint col_offset) 22 | { 23 | /* Input */ 24 | float temperature = stack_load_float(stack, temperature_offset); 25 | 26 | float3 color_rgb = rec709_to_rgb(kg, svm_math_blackbody_color_rec709(temperature)); 27 | color_rgb = max(color_rgb, zero_float3()); 28 | 29 | stack_store_float3(stack, col_offset, color_rgb); 30 | } 31 | 32 | CCL_NAMESPACE_END 33 | -------------------------------------------------------------------------------- /src/kernel/svm/brightness.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "kernel/svm/color_util.h" 7 | 8 | CCL_NAMESPACE_BEGIN 9 | 10 | ccl_device_noinline void svm_node_brightness( 11 | ccl_private ShaderData *sd, ccl_private float *stack, uint in_color, uint out_color, uint node) 12 | { 13 | uint bright_offset, contrast_offset; 14 | float3 color = stack_load_float3(stack, in_color); 15 | 16 | svm_unpack_node_uchar2(node, &bright_offset, &contrast_offset); 17 | float brightness = stack_load_float(stack, bright_offset); 18 | float contrast = stack_load_float(stack, contrast_offset); 19 | 20 | color = svm_brightness_contrast(color, brightness, contrast); 21 | 22 | if (stack_valid(out_color)) 23 | stack_store_float3(stack, out_color, color); 24 | } 25 | 26 | CCL_NAMESPACE_END 27 | -------------------------------------------------------------------------------- /src/kernel/svm/camera.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | CCL_NAMESPACE_BEGIN 7 | 8 | ccl_device_noinline void svm_node_camera(KernelGlobals kg, 9 | ccl_private ShaderData *sd, 10 | ccl_private float *stack, 11 | uint out_vector, 12 | uint out_zdepth, 13 | uint out_distance) 14 | { 15 | float distance; 16 | float zdepth; 17 | float3 vector; 18 | 19 | Transform tfm = kernel_data.cam.worldtocamera; 20 | vector = transform_point(&tfm, sd->P); 21 | zdepth = vector.z; 22 | distance = len(vector); 23 | 24 | if (stack_valid(out_vector)) 25 | stack_store_float3(stack, out_vector, normalize(vector)); 26 | 27 | if (stack_valid(out_zdepth)) 28 | stack_store_float(stack, out_zdepth, zdepth); 29 | 30 | if (stack_valid(out_distance)) 31 | stack_store_float(stack, out_distance, distance); 32 | } 33 | 34 | CCL_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /src/kernel/svm/gamma.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | CCL_NAMESPACE_BEGIN 7 | 8 | ccl_device_noinline void svm_node_gamma(ccl_private ShaderData *sd, 9 | ccl_private float *stack, 10 | uint in_gamma, 11 | uint in_color, 12 | uint out_color) 13 | { 14 | float3 color = stack_load_float3(stack, in_color); 15 | float gamma = stack_load_float(stack, in_gamma); 16 | 17 | color = svm_math_gamma_color(color, gamma); 18 | 19 | if (stack_valid(out_color)) 20 | stack_store_float3(stack, out_color, color); 21 | } 22 | 23 | CCL_NAMESPACE_END 24 | -------------------------------------------------------------------------------- /src/kernel/svm/invert.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | CCL_NAMESPACE_BEGIN 7 | 8 | ccl_device float invert(float color, float factor) 9 | { 10 | return factor * (1.0f - color) + (1.0f - factor) * color; 11 | } 12 | 13 | ccl_device_noinline void svm_node_invert(ccl_private ShaderData *sd, 14 | ccl_private float *stack, 15 | uint in_fac, 16 | uint in_color, 17 | uint out_color) 18 | { 19 | float factor = stack_load_float(stack, in_fac); 20 | float3 color = stack_load_float3(stack, in_color); 21 | 22 | color.x = invert(color.x, factor); 23 | color.y = invert(color.y, factor); 24 | color.z = invert(color.z, factor); 25 | 26 | if (stack_valid(out_color)) 27 | stack_store_float3(stack, out_color, color); 28 | } 29 | 30 | CCL_NAMESPACE_END 31 | -------------------------------------------------------------------------------- /src/kernel/svm/mapping_util.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | CCL_NAMESPACE_BEGIN 7 | 8 | ccl_device float3 9 | svm_mapping(NodeMappingType type, float3 vector, float3 location, float3 rotation, float3 scale) 10 | { 11 | Transform rotationTransform = euler_to_transform(rotation); 12 | switch (type) { 13 | case NODE_MAPPING_TYPE_POINT: 14 | return transform_direction(&rotationTransform, (vector * scale)) + location; 15 | case NODE_MAPPING_TYPE_TEXTURE: 16 | return safe_divide(transform_direction_transposed(&rotationTransform, (vector - location)), 17 | scale); 18 | case NODE_MAPPING_TYPE_VECTOR: 19 | return transform_direction(&rotationTransform, (vector * scale)); 20 | case NODE_MAPPING_TYPE_NORMAL: 21 | return safe_normalize(transform_direction(&rotationTransform, safe_divide(vector, scale))); 22 | default: 23 | return make_float3(0.0f, 0.0f, 0.0f); 24 | } 25 | } 26 | 27 | CCL_NAMESPACE_END 28 | -------------------------------------------------------------------------------- /src/kernel/svm/normal.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | CCL_NAMESPACE_BEGIN 7 | 8 | ccl_device_noinline int svm_node_normal(KernelGlobals kg, 9 | ccl_private ShaderData *sd, 10 | ccl_private float *stack, 11 | uint in_normal_offset, 12 | uint out_normal_offset, 13 | uint out_dot_offset, 14 | int offset) 15 | { 16 | /* read extra data */ 17 | uint4 node1 = read_node(kg, &offset); 18 | float3 normal = stack_load_float3(stack, in_normal_offset); 19 | 20 | float3 direction; 21 | direction.x = __int_as_float(node1.x); 22 | direction.y = __int_as_float(node1.y); 23 | direction.z = __int_as_float(node1.z); 24 | direction = normalize(direction); 25 | 26 | if (stack_valid(out_normal_offset)) 27 | stack_store_float3(stack, out_normal_offset, direction); 28 | 29 | if (stack_valid(out_dot_offset)) 30 | stack_store_float(stack, out_dot_offset, dot(direction, normalize(normal))); 31 | return offset; 32 | } 33 | 34 | CCL_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /src/kernel/svm/value.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | CCL_NAMESPACE_BEGIN 7 | 8 | /* Value Nodes */ 9 | 10 | ccl_device void svm_node_value_f(KernelGlobals kg, 11 | ccl_private ShaderData *sd, 12 | ccl_private float *stack, 13 | uint ivalue, 14 | uint out_offset) 15 | { 16 | stack_store_float(stack, out_offset, __uint_as_float(ivalue)); 17 | } 18 | 19 | ccl_device int svm_node_value_v(KernelGlobals kg, 20 | ccl_private ShaderData *sd, 21 | ccl_private float *stack, 22 | uint out_offset, 23 | int offset) 24 | { 25 | /* read extra data */ 26 | uint4 node1 = read_node(kg, &offset); 27 | float3 p = make_float3( 28 | __uint_as_float(node1.y), __uint_as_float(node1.z), __uint_as_float(node1.w)); 29 | 30 | stack_store_float3(stack, out_offset, p); 31 | return offset; 32 | } 33 | 34 | CCL_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /src/kernel/util/lookup_table.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | CCL_NAMESPACE_BEGIN 7 | 8 | /* Interpolated lookup table access */ 9 | 10 | ccl_device float lookup_table_read(KernelGlobals kg, float x, int offset, int size) 11 | { 12 | x = saturatef(x) * (size - 1); 13 | 14 | int index = min(float_to_int(x), size - 1); 15 | int nindex = min(index + 1, size - 1); 16 | float t = x - index; 17 | 18 | float data0 = kernel_data_fetch(lookup_table, index + offset); 19 | if (t == 0.0f) 20 | return data0; 21 | 22 | float data1 = kernel_data_fetch(lookup_table, nindex + offset); 23 | return (1.0f - t) * data0 + t * data1; 24 | } 25 | 26 | ccl_device float lookup_table_read_2D( 27 | KernelGlobals kg, float x, float y, int offset, int xsize, int ysize) 28 | { 29 | y = saturatef(y) * (ysize - 1); 30 | 31 | int index = min(float_to_int(y), ysize - 1); 32 | int nindex = min(index + 1, ysize - 1); 33 | float t = y - index; 34 | 35 | float data0 = lookup_table_read(kg, x, offset + xsize * index, xsize); 36 | if (t == 0.0f) 37 | return data0; 38 | 39 | float data1 = lookup_table_read(kg, x, offset + xsize * nindex, xsize); 40 | return (1.0f - t) * data0 + t * data1; 41 | } 42 | 43 | CCL_NAMESPACE_END 44 | -------------------------------------------------------------------------------- /src/kernel/util/profiling.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifndef __KERNEL_GPU__ 7 | # include "util/profiling.h" 8 | #endif 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | #ifndef __KERNEL_GPU__ 13 | # define PROFILING_INIT(kg, event) \ 14 | ProfilingHelper profiling_helper((ProfilingState *)&kg->profiler, event) 15 | # define PROFILING_EVENT(event) profiling_helper.set_event(event) 16 | # define PROFILING_INIT_FOR_SHADER(kg, event) \ 17 | ProfilingWithShaderHelper profiling_helper((ProfilingState *)&kg->profiler, event) 18 | # define PROFILING_SHADER(object, shader) \ 19 | profiling_helper.set_shader(object, (shader)&SHADER_MASK); 20 | #else 21 | # define PROFILING_INIT(kg, event) 22 | # define PROFILING_EVENT(event) 23 | # define PROFILING_INIT_FOR_SHADER(kg, event) 24 | # define PROFILING_SHADER(object, shader) 25 | #endif /* !__KERNEL_GPU__ */ 26 | 27 | CCL_NAMESPACE_END 28 | -------------------------------------------------------------------------------- /src/scene/background.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __BACKGROUND_H__ 5 | #define __BACKGROUND_H__ 6 | 7 | #include "graph/node.h" 8 | 9 | #include "util/types.h" 10 | 11 | CCL_NAMESPACE_BEGIN 12 | 13 | class Device; 14 | class DeviceScene; 15 | class Scene; 16 | class Shader; 17 | 18 | class Background : public Node { 19 | public: 20 | NODE_DECLARE 21 | 22 | NODE_SOCKET_API(bool, use_shader) 23 | 24 | NODE_SOCKET_API(uint, visibility) 25 | NODE_SOCKET_API(Node *, shader) 26 | 27 | NODE_SOCKET_API(bool, transparent) 28 | NODE_SOCKET_API(bool, transparent_glass) 29 | NODE_SOCKET_API(float, transparent_roughness_threshold) 30 | 31 | NODE_SOCKET_API(float, volume_step_size) 32 | 33 | NODE_SOCKET_API(ustring, lightgroup) 34 | 35 | Background(); 36 | ~Background(); 37 | 38 | void device_update(Device *device, DeviceScene *dscene, Scene *scene); 39 | void device_free(Device *device, DeviceScene *dscene); 40 | 41 | void tag_update(Scene *scene); 42 | 43 | Shader *get_shader(const Scene *scene); 44 | }; 45 | 46 | CCL_NAMESPACE_END 47 | 48 | #endif /* __BACKGROUND_H__ */ 49 | -------------------------------------------------------------------------------- /src/scene/bake.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __BAKE_H__ 5 | #define __BAKE_H__ 6 | 7 | #include "device/device.h" 8 | #include "scene/scene.h" 9 | 10 | #include "util/progress.h" 11 | #include "util/vector.h" 12 | 13 | CCL_NAMESPACE_BEGIN 14 | 15 | class BakeManager { 16 | public: 17 | BakeManager(); 18 | ~BakeManager(); 19 | 20 | void set(Scene *scene, const std::string &object_name); 21 | bool get_baking() const; 22 | 23 | void set_use_camera(bool use_camera); 24 | 25 | void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress); 26 | void device_free(Device *device, DeviceScene *dscene); 27 | 28 | void tag_update(); 29 | 30 | bool need_update() const; 31 | 32 | private: 33 | bool need_update_; 34 | std::string object_name; 35 | bool use_camera_; 36 | }; 37 | 38 | CCL_NAMESPACE_END 39 | 40 | #endif /* __BAKE_H__ */ 41 | -------------------------------------------------------------------------------- /src/scene/curves.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __CURVES_H__ 5 | #define __CURVES_H__ 6 | 7 | #include "util/array.h" 8 | #include "util/types.h" 9 | 10 | #include "scene/hair.h" 11 | 12 | CCL_NAMESPACE_BEGIN 13 | 14 | class Device; 15 | class DeviceScene; 16 | class Progress; 17 | class Scene; 18 | 19 | void curvebounds(float *lower, float *upper, float3 *p, int dim); 20 | 21 | class ParticleCurveData { 22 | 23 | public: 24 | ParticleCurveData(); 25 | ~ParticleCurveData(); 26 | 27 | array psys_firstcurve; 28 | array psys_curvenum; 29 | array psys_shader; 30 | 31 | array psys_rootradius; 32 | array psys_tipradius; 33 | array psys_shape; 34 | array psys_closetip; 35 | 36 | array curve_firstkey; 37 | array curve_keynum; 38 | array curve_length; 39 | array curve_uv; 40 | array curve_vcol; 41 | 42 | array curvekey_co; 43 | array curvekey_time; 44 | }; 45 | 46 | CCL_NAMESPACE_END 47 | 48 | #endif /* __CURVES_H__ */ 49 | -------------------------------------------------------------------------------- /src/scene/image_oiio.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __IMAGE_OIIO__ 5 | #define __IMAGE_OIIO__ 6 | 7 | #include "scene/image.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | class OIIOImageLoader : public ImageLoader { 12 | public: 13 | OIIOImageLoader(const string &filepath); 14 | ~OIIOImageLoader(); 15 | 16 | bool load_metadata(const ImageDeviceFeatures &features, ImageMetaData &metadata) override; 17 | 18 | bool load_pixels(const ImageMetaData &metadata, 19 | void *pixels, 20 | const size_t pixels_size, 21 | const bool associate_alpha) override; 22 | 23 | string name() const override; 24 | 25 | ustring osl_filepath() const override; 26 | 27 | bool equals(const ImageLoader &other) const override; 28 | 29 | protected: 30 | ustring filepath; 31 | }; 32 | 33 | CCL_NAMESPACE_END 34 | 35 | #endif /* __IMAGE_OIIO__ */ 36 | -------------------------------------------------------------------------------- /src/scene/image_sky.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "scene/image.h" 5 | 6 | CCL_NAMESPACE_BEGIN 7 | 8 | class SkyLoader : public ImageLoader { 9 | private: 10 | float sun_elevation; 11 | float altitude; 12 | float air_density; 13 | float dust_density; 14 | float ozone_density; 15 | 16 | public: 17 | SkyLoader(float sun_elevation, 18 | float altitude, 19 | float air_density, 20 | float dust_density, 21 | float ozone_density); 22 | ~SkyLoader(); 23 | 24 | bool load_metadata(const ImageDeviceFeatures &features, ImageMetaData &metadata) override; 25 | 26 | bool load_pixels(const ImageMetaData &metadata, 27 | void *pixels, 28 | const size_t /*pixels_size*/, 29 | const bool /*associate_alpha*/) override; 30 | 31 | string name() const override; 32 | 33 | bool equals(const ImageLoader & /*other*/) const override; 34 | }; 35 | 36 | CCL_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /src/scene/tables.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __TABLES_H__ 5 | #define __TABLES_H__ 6 | 7 | #include "util/list.h" 8 | #include "util/vector.h" 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | class Device; 13 | class DeviceScene; 14 | class Scene; 15 | 16 | enum { TABLE_CHUNK_SIZE = 256 }; 17 | enum { TABLE_OFFSET_INVALID = -1 }; 18 | 19 | class LookupTables { 20 | bool need_update_; 21 | 22 | public: 23 | struct Table { 24 | size_t offset; 25 | size_t size; 26 | }; 27 | 28 | list lookup_tables; 29 | 30 | LookupTables(); 31 | ~LookupTables(); 32 | 33 | void device_update(Device *device, DeviceScene *dscene, Scene *scene); 34 | void device_free(Device *device, DeviceScene *dscene); 35 | 36 | bool need_update() const; 37 | 38 | size_t add_table(DeviceScene *dscene, vector &data); 39 | void remove_table(size_t *offset); 40 | }; 41 | 42 | CCL_NAMESPACE_END 43 | 44 | #endif /* __TABLES_H__ */ 45 | -------------------------------------------------------------------------------- /src/scene/tabulated_sobol.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2019-2022 Blender Foundation */ 3 | 4 | #ifndef __TABULATED_SOBOL_H__ 5 | #define __TABULATED_SOBOL_H__ 6 | 7 | #include "util/types.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | void tabulated_sobol_generate_4D(float4 points[], int size, int rng_seed); 12 | 13 | CCL_NAMESPACE_END 14 | 15 | #endif /* __TABULATED_SOBOL_H__ */ 16 | -------------------------------------------------------------------------------- /src/scene/volume.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2020-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #include "graph/node.h" 7 | 8 | #include "scene/mesh.h" 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | class Volume : public Mesh { 13 | public: 14 | NODE_DECLARE 15 | 16 | Volume(); 17 | 18 | NODE_SOCKET_API(float, clipping) 19 | NODE_SOCKET_API(float, step_size) 20 | NODE_SOCKET_API(bool, object_space) 21 | NODE_SOCKET_API(float, velocity_scale) 22 | 23 | virtual void clear(bool preserve_shaders = false) override; 24 | }; 25 | 26 | CCL_NAMESPACE_END 27 | -------------------------------------------------------------------------------- /src/session/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2011-2022 Blender Foundation 3 | 4 | set(INC 5 | .. 6 | ) 7 | 8 | set(INC_SYS 9 | ) 10 | 11 | set(SRC 12 | buffers.cpp 13 | denoising.cpp 14 | merge.cpp 15 | session.cpp 16 | tile.cpp 17 | ) 18 | 19 | set(SRC_HEADERS 20 | buffers.h 21 | display_driver.h 22 | denoising.h 23 | merge.h 24 | output_driver.h 25 | session.h 26 | tile.h 27 | ) 28 | 29 | set(LIB 30 | cycles_device 31 | cycles_integrator 32 | cycles_util 33 | ) 34 | 35 | include_directories(${INC}) 36 | include_directories(SYSTEM ${INC_SYS}) 37 | 38 | cycles_add_library(cycles_session "${LIB}" ${SRC} ${SRC_HEADERS}) 39 | -------------------------------------------------------------------------------- /src/session/merge.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __MERGE_H__ 5 | #define __MERGE_H__ 6 | 7 | #include "util/string.h" 8 | #include "util/vector.h" 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | /* Merge OpenEXR multi-layer renders. */ 13 | 14 | class ImageMerger { 15 | public: 16 | ImageMerger(); 17 | bool run(); 18 | 19 | /* Error message after running, in case of failure. */ 20 | string error; 21 | 22 | /* List of image filepaths to merge. */ 23 | vector input; 24 | /* Output filepath. */ 25 | string output; 26 | }; 27 | 28 | CCL_NAMESPACE_END 29 | 30 | #endif /* __MERGE_H__ */ 31 | -------------------------------------------------------------------------------- /src/subd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # SPDX-License-Identifier: Apache-2.0 2 | # Copyright 2011-2022 Blender Foundation 3 | 4 | set(INC 5 | .. 6 | ) 7 | 8 | set(INC_SYS 9 | 10 | ) 11 | 12 | set(SRC 13 | dice.cpp 14 | patch.cpp 15 | split.cpp 16 | patch_table.cpp 17 | ) 18 | 19 | set(SRC_HEADERS 20 | dice.h 21 | patch.h 22 | patch_table.h 23 | split.h 24 | subpatch.h 25 | ) 26 | 27 | set(LIB 28 | 29 | ) 30 | 31 | include_directories(${INC}) 32 | include_directories(SYSTEM ${INC_SYS}) 33 | 34 | cycles_add_library(cycles_subd "${LIB}" ${SRC} ${SRC_HEADERS}) 35 | -------------------------------------------------------------------------------- /src/subd/patch.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __SUBD_PATCH_H__ 5 | #define __SUBD_PATCH_H__ 6 | 7 | #include "util/boundbox.h" 8 | #include "util/types.h" 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | class Patch { 13 | public: 14 | Patch() : patch_index(0), shader(0), from_ngon(false) 15 | { 16 | } 17 | 18 | virtual ~Patch() = default; 19 | 20 | virtual void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v) = 0; 21 | 22 | int patch_index; 23 | int shader; 24 | bool from_ngon; 25 | }; 26 | 27 | /* Linear Quad Patch */ 28 | 29 | class LinearQuadPatch : public Patch { 30 | public: 31 | float3 hull[4]; 32 | float3 normals[4]; 33 | 34 | void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v); 35 | BoundBox bound(); 36 | }; 37 | 38 | /* Bicubic Patch */ 39 | 40 | class BicubicPatch : public Patch { 41 | public: 42 | float3 hull[16]; 43 | 44 | void eval(float3 *P, float3 *dPdu, float3 *dPdv, float3 *N, float u, float v); 45 | BoundBox bound(); 46 | }; 47 | 48 | CCL_NAMESPACE_END 49 | 50 | #endif /* __SUBD_PATCH_H__ */ 51 | -------------------------------------------------------------------------------- /src/subd/patch_table.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __SUBD_PATCH_TABLE_H__ 5 | #define __SUBD_PATCH_TABLE_H__ 6 | 7 | #include "util/array.h" 8 | #include "util/types.h" 9 | 10 | #ifdef WITH_OPENSUBDIV 11 | # ifdef _MSC_VER 12 | # include "iso646.h" 13 | # endif 14 | 15 | # include 16 | #endif 17 | 18 | CCL_NAMESPACE_BEGIN 19 | 20 | #ifdef WITH_OPENSUBDIV 21 | using namespace OpenSubdiv; 22 | #else 23 | /* forward declare for when OpenSubdiv is unavailable */ 24 | namespace Far { 25 | struct PatchTable; 26 | } 27 | #endif 28 | 29 | #define PATCH_ARRAY_SIZE 4 30 | #define PATCH_PARAM_SIZE 2 31 | #define PATCH_HANDLE_SIZE 3 32 | #define PATCH_NODE_SIZE 1 33 | 34 | struct PackedPatchTable { 35 | array table; 36 | 37 | size_t num_arrays; 38 | size_t num_indices; 39 | size_t num_patches; 40 | size_t num_nodes; 41 | 42 | /* calculated size from num_* members */ 43 | size_t total_size(); 44 | 45 | void pack(Far::PatchTable *patch_table, int offset = 0); 46 | void copy_adjusting_offsets(uint *dest, int doffset); 47 | }; 48 | 49 | CCL_NAMESPACE_END 50 | 51 | #endif /* __SUBD_PATCH_TABLE_H__ */ 52 | -------------------------------------------------------------------------------- /src/test/integrator_render_scheduler_test.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "testing/testing.h" 5 | 6 | #include "integrator/render_scheduler.h" 7 | 8 | CCL_NAMESPACE_BEGIN 9 | 10 | TEST(IntegratorRenderScheduler, calculate_resolution_divider_for_resolution) 11 | { 12 | EXPECT_EQ(calculate_resolution_divider_for_resolution(1920, 1080, 1920), 1); 13 | EXPECT_EQ(calculate_resolution_divider_for_resolution(1920, 1080, 960), 2); 14 | EXPECT_EQ(calculate_resolution_divider_for_resolution(1920, 1080, 480), 4); 15 | } 16 | 17 | TEST(IntegratorRenderScheduler, calculate_resolution_for_divider) 18 | { 19 | EXPECT_EQ(calculate_resolution_for_divider(1920, 1080, 1), 1440); 20 | EXPECT_EQ(calculate_resolution_for_divider(1920, 1080, 2), 720); 21 | EXPECT_EQ(calculate_resolution_for_divider(1920, 1080, 4), 360); 22 | } 23 | 24 | CCL_NAMESPACE_END 25 | -------------------------------------------------------------------------------- /src/test/util_aligned_malloc_test.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "testing/testing.h" 5 | 6 | #include "util/aligned_malloc.h" 7 | 8 | #define CHECK_ALIGNMENT(ptr, align) EXPECT_EQ((size_t)ptr % align, 0) 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | TEST(util_aligned_malloc, aligned_malloc_16) 13 | { 14 | int *mem = (int *)util_aligned_malloc(sizeof(int), 16); 15 | CHECK_ALIGNMENT(mem, 16); 16 | util_aligned_free(mem); 17 | } 18 | 19 | /* On Apple we currently only support 16 bytes alignment. */ 20 | #ifndef __APPLE__ 21 | TEST(util_aligned_malloc, aligned_malloc_32) 22 | { 23 | int *mem = (int *)util_aligned_malloc(sizeof(int), 32); 24 | CHECK_ALIGNMENT(mem, 32); 25 | util_aligned_free(mem); 26 | } 27 | #endif /* __APPLE__ */ 28 | 29 | CCL_NAMESPACE_END 30 | -------------------------------------------------------------------------------- /src/test/util_float8_avx2_test.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #define __KERNEL_SSE__ 5 | #define __KERNEL_AVX__ 6 | #define __KERNEL_AVX2__ 7 | 8 | #define TEST_CATEGORY_NAME util_avx2 9 | 10 | #if (defined(i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)) && \ 11 | defined(__AVX2__) 12 | # include "util_float8_test.h" 13 | #endif 14 | -------------------------------------------------------------------------------- /src/test/util_float8_avx_test.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #define __KERNEL_SSE__ 5 | #define __KERNEL_AVX__ 6 | 7 | #define TEST_CATEGORY_NAME util_avx 8 | 9 | #if (defined(i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)) && \ 10 | defined(__AVX__) 11 | # include "util_float8_test.h" 12 | #endif 13 | -------------------------------------------------------------------------------- /src/test/util_float8_sse2_test.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #define __KERNEL_SSE__ 5 | #define __KERNEL_SSE2__ 6 | 7 | #define TEST_CATEGORY_NAME util_sse2 8 | 9 | #if (defined(i386) || defined(_M_IX86) || defined(__x86_64__) || defined(_M_X64)) && \ 10 | defined(__SSE2__) 11 | # include "util_float8_test.h" 12 | #endif 13 | -------------------------------------------------------------------------------- /src/test/util_md5_test.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "testing/testing.h" 5 | 6 | #include "util/md5.h" 7 | 8 | CCL_NAMESPACE_BEGIN 9 | 10 | TEST(util, util_md5_string) 11 | { 12 | /* The hash is calculated using `echo -n "Hello, World\!" | md5 | tr '[:lower:]' '[:upper:]'`. */ 13 | EXPECT_EQ(util_md5_string("Hello, World!"), "65A8E27D8879283831B664BD8B7F0AD4"); 14 | } 15 | 16 | CCL_NAMESPACE_END 17 | -------------------------------------------------------------------------------- /src/test/util_task_test.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "testing/testing.h" 5 | 6 | #include "util/task.h" 7 | 8 | CCL_NAMESPACE_BEGIN 9 | 10 | namespace { 11 | 12 | void task_run() 13 | { 14 | } 15 | 16 | } // namespace 17 | 18 | TEST(util_task, basic) 19 | { 20 | TaskScheduler::init(0); 21 | TaskPool pool; 22 | for (int i = 0; i < 100; ++i) { 23 | pool.push(function_bind(task_run)); 24 | } 25 | TaskPool::Summary summary; 26 | pool.wait_work(&summary); 27 | TaskScheduler::exit(); 28 | EXPECT_EQ(summary.num_tasks_handled, 100); 29 | } 30 | 31 | TEST(util_task, multiple_times) 32 | { 33 | for (int N = 0; N < 1000; ++N) { 34 | TaskScheduler::init(0); 35 | TaskPool pool; 36 | for (int i = 0; i < 100; ++i) { 37 | pool.push(function_bind(task_run)); 38 | } 39 | TaskPool::Summary summary; 40 | pool.wait_work(&summary); 41 | TaskScheduler::exit(); 42 | EXPECT_EQ(summary.num_tasks_handled, 100); 43 | } 44 | } 45 | 46 | CCL_NAMESPACE_END 47 | -------------------------------------------------------------------------------- /src/util/algorithm.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_ALGORITHM_H__ 5 | #define __UTIL_ALGORITHM_H__ 6 | 7 | #include 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | using std::remove; 12 | using std::sort; 13 | using std::stable_sort; 14 | using std::swap; 15 | 16 | CCL_NAMESPACE_END 17 | 18 | #endif /* __UTIL_ALGORITHM_H__ */ 19 | -------------------------------------------------------------------------------- /src/util/aligned_malloc.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_ALIGNED_MALLOC_H__ 5 | #define __UTIL_ALIGNED_MALLOC_H__ 6 | 7 | #include "util/types.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | /* Minimum alignment needed by all CPU native data types (SSE, AVX). */ 12 | #define MIN_ALIGNMENT_CPU_DATA_TYPES 16 13 | 14 | /* Allocate block of size bytes at least aligned to a given value. */ 15 | void *util_aligned_malloc(size_t size, int alignment); 16 | 17 | /* Free memory allocated by util_aligned_malloc. */ 18 | void util_aligned_free(void *ptr); 19 | 20 | /* Aligned new operator. */ 21 | template T *util_aligned_new(Args... args) 22 | { 23 | void *mem = util_aligned_malloc(sizeof(T), alignof(T)); 24 | return new (mem) T(args...); 25 | } 26 | 27 | template void util_aligned_delete(T *t) 28 | { 29 | if (t) { 30 | t->~T(); 31 | util_aligned_free(t); 32 | } 33 | } 34 | 35 | CCL_NAMESPACE_END 36 | 37 | #endif /* __UTIL_ALIGNED_MALLOC_H__ */ 38 | -------------------------------------------------------------------------------- /src/util/args.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_ARGS_H__ 5 | #define __UTIL_ARGS_H__ 6 | 7 | /* Argument Parsing for command line, we use the OpenImageIO 8 | * library because it has nice functions to do this. */ 9 | 10 | #include 11 | 12 | CCL_NAMESPACE_BEGIN 13 | 14 | OIIO_NAMESPACE_USING 15 | 16 | CCL_NAMESPACE_END 17 | 18 | #endif /* __UTIL_ARGS_H__ */ 19 | -------------------------------------------------------------------------------- /src/util/deque.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_DEQUE_H__ 5 | #define __UTIL_DEQUE_H__ 6 | 7 | #include 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | using std::deque; 12 | 13 | CCL_NAMESPACE_END 14 | 15 | #endif /* __UTIL_DEQUE_H__ */ 16 | -------------------------------------------------------------------------------- /src/util/foreach.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_FOREACH_H__ 5 | #define __UTIL_FOREACH_H__ 6 | 7 | /* Nice foreach() loops for STL data structures. */ 8 | 9 | #define foreach(x, y) for (x : y) 10 | 11 | #endif /* __UTIL_FOREACH_H__ */ 12 | -------------------------------------------------------------------------------- /src/util/function.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_FUNCTION_H__ 5 | #define __UTIL_FUNCTION_H__ 6 | 7 | #include 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | #define function_bind std::bind 12 | #define function_null nullptr 13 | using std::function; 14 | using std::placeholders::_1; 15 | using std::placeholders::_2; 16 | using std::placeholders::_3; 17 | using std::placeholders::_4; 18 | using std::placeholders::_5; 19 | using std::placeholders::_6; 20 | using std::placeholders::_7; 21 | using std::placeholders::_8; 22 | using std::placeholders::_9; 23 | 24 | CCL_NAMESPACE_END 25 | 26 | #endif /* __UTIL_FUNCTION_H__ */ 27 | -------------------------------------------------------------------------------- /src/util/guarded_allocator.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "util/guarded_allocator.h" 5 | #include "util/stats.h" 6 | 7 | CCL_NAMESPACE_BEGIN 8 | 9 | static Stats global_stats(Stats::static_init); 10 | 11 | /* Internal API. */ 12 | 13 | void util_guarded_mem_alloc(size_t n) 14 | { 15 | global_stats.mem_alloc(n); 16 | } 17 | 18 | void util_guarded_mem_free(size_t n) 19 | { 20 | global_stats.mem_free(n); 21 | } 22 | 23 | /* Public API. */ 24 | 25 | size_t util_guarded_get_mem_used() 26 | { 27 | return global_stats.mem_used; 28 | } 29 | 30 | size_t util_guarded_get_mem_peak() 31 | { 32 | return global_stats.mem_peak; 33 | } 34 | 35 | CCL_NAMESPACE_END 36 | -------------------------------------------------------------------------------- /src/util/guiding.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifdef WITH_PATH_GUIDING 7 | # include 8 | # include 9 | #endif 10 | 11 | #include "util/system.h" 12 | 13 | CCL_NAMESPACE_BEGIN 14 | 15 | static int guiding_device_type() 16 | { 17 | #ifdef WITH_PATH_GUIDING 18 | # if defined(__ARM_NEON) 19 | return 8; 20 | # else 21 | # if OPENPGL_VERSION_MINOR >= 4 22 | if (system_cpu_support_avx2()) { 23 | return 8; 24 | } 25 | # endif 26 | if (system_cpu_support_sse41()) { 27 | return 4; 28 | } 29 | return 0; 30 | # endif 31 | #else 32 | return 0; 33 | #endif 34 | } 35 | 36 | static inline bool guiding_supported() 37 | { 38 | return guiding_device_type() != 0; 39 | } 40 | 41 | CCL_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /src/util/ies.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_IES_H__ 5 | #define __UTIL_IES_H__ 6 | 7 | #include "util/string.h" 8 | #include "util/vector.h" 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | class IESFile { 13 | public: 14 | IESFile() 15 | { 16 | } 17 | ~IESFile(); 18 | 19 | int packed_size(); 20 | void pack(float *data); 21 | 22 | bool load(const string &ies); 23 | void clear(); 24 | 25 | protected: 26 | bool parse(const string &ies); 27 | bool process(); 28 | bool process_type_b(); 29 | bool process_type_c(); 30 | 31 | /* The brightness distribution is stored in spherical coordinates. 32 | * The horizontal angles correspond to theta in the regular notation 33 | * and always span the full range from 0° to 360°. 34 | * The vertical angles correspond to phi and always start at 0°. */ 35 | vector v_angles, h_angles; 36 | /* The actual values are stored here, with every entry storing the values 37 | * of one horizontal segment. */ 38 | vector> intensity; 39 | 40 | /* Types of angle representation in IES files. Currently, only B and C are supported. */ 41 | enum IESType { TYPE_A = 3, TYPE_B = 2, TYPE_C = 1 } type; 42 | }; 43 | 44 | CCL_NAMESPACE_END 45 | 46 | #endif /* __UTIL_IES_H__ */ 47 | -------------------------------------------------------------------------------- /src/util/list.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_LIST_H__ 5 | #define __UTIL_LIST_H__ 6 | 7 | #include 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | using std::list; 12 | 13 | CCL_NAMESPACE_END 14 | 15 | #endif /* __UTIL_LIST_H__ */ 16 | -------------------------------------------------------------------------------- /src/util/map.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_MAP_H__ 5 | #define __UTIL_MAP_H__ 6 | 7 | #include 8 | #include 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | using std::map; 13 | using std::pair; 14 | using std::unordered_map; 15 | using std::unordered_multimap; 16 | 17 | template static void map_free_memory(T &data) 18 | { 19 | /* Use swap() trick to actually free all internal memory. */ 20 | T empty_data; 21 | data.swap(empty_data); 22 | } 23 | 24 | CCL_NAMESPACE_END 25 | 26 | #endif /* __UTIL_MAP_H__ */ 27 | -------------------------------------------------------------------------------- /src/util/math_int2.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_MATH_INT2_H__ 5 | #define __UTIL_MATH_INT2_H__ 6 | 7 | #ifndef __UTIL_MATH_H__ 8 | # error "Do not include this file directly, include util/types.h instead." 9 | #endif 10 | 11 | CCL_NAMESPACE_BEGIN 12 | 13 | #if !defined(__KERNEL_METAL__) 14 | ccl_device_inline bool operator==(const int2 a, const int2 b) 15 | { 16 | return (a.x == b.x && a.y == b.y); 17 | } 18 | 19 | ccl_device_inline int2 operator+(const int2 &a, const int2 &b) 20 | { 21 | return make_int2(a.x + b.x, a.y + b.y); 22 | } 23 | 24 | ccl_device_inline int2 operator+=(int2 &a, const int2 &b) 25 | { 26 | return a = a + b; 27 | } 28 | 29 | ccl_device_inline int2 operator-(const int2 &a, const int2 &b) 30 | { 31 | return make_int2(a.x - b.x, a.y - b.y); 32 | } 33 | 34 | ccl_device_inline int2 operator*(const int2 &a, const int2 &b) 35 | { 36 | return make_int2(a.x * b.x, a.y * b.y); 37 | } 38 | 39 | ccl_device_inline int2 operator/(const int2 &a, const int2 &b) 40 | { 41 | return make_int2(a.x / b.x, a.y / b.y); 42 | } 43 | #endif /* !__KERNEL_METAL__ */ 44 | 45 | CCL_NAMESPACE_END 46 | 47 | #endif /* __UTIL_MATH_INT2_H__ */ 48 | -------------------------------------------------------------------------------- /src/util/md5.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Zlib 2 | * Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. 3 | * L. Peter Deutsch 4 | * ghost@aladdin.com */ 5 | 6 | /* MD5 7 | * 8 | * Simply MD5 hash computation, used by disk cache. Adapted from external 9 | * code, with minor code modifications done to remove some unused code and 10 | * change code style. */ 11 | 12 | #ifndef __UTIL_MD5_H__ 13 | #define __UTIL_MD5_H__ 14 | 15 | #include "util/string.h" 16 | #include "util/types.h" 17 | 18 | CCL_NAMESPACE_BEGIN 19 | 20 | class MD5Hash { 21 | public: 22 | MD5Hash(); 23 | ~MD5Hash(); 24 | 25 | void append(const uint8_t *data, int size); 26 | void append(const string &str); 27 | bool append_file(const string &filepath); 28 | string get_hex(); 29 | 30 | protected: 31 | void process(const uint8_t *data); 32 | void finish(uint8_t digest[16]); 33 | 34 | uint32_t count[2]; /* message length in bits, LSW first. */ 35 | uint32_t abcd[4]; /* digest buffer */ 36 | uint8_t buf[64]; /* accumulate block */ 37 | }; 38 | 39 | string util_md5_string(const string &str); 40 | 41 | CCL_NAMESPACE_END 42 | 43 | #endif /* __UTIL_MD5_H__ */ 44 | -------------------------------------------------------------------------------- /src/util/murmurhash.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2018-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_MURMURHASH_H__ 5 | #define __UTIL_MURMURHASH_H__ 6 | 7 | #include "util/types.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | uint32_t util_murmur_hash3(const void *key, int len, uint32_t seed); 12 | float util_hash_to_float(uint32_t hash); 13 | 14 | CCL_NAMESPACE_END 15 | 16 | #endif /* __UTIL_MURMURHASH_H__ */ 17 | -------------------------------------------------------------------------------- /src/util/openimagedenoise.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_OPENIMAGEDENOISE_H__ 5 | #define __UTIL_OPENIMAGEDENOISE_H__ 6 | 7 | #ifdef WITH_OPENIMAGEDENOISE 8 | # include 9 | #endif 10 | 11 | #include "util/system.h" 12 | 13 | CCL_NAMESPACE_BEGIN 14 | 15 | static inline bool openimagedenoise_supported() 16 | { 17 | #ifdef WITH_OPENIMAGEDENOISE 18 | # ifdef __APPLE__ 19 | /* Always supported through Accelerate framework BNNS. */ 20 | return true; 21 | # else 22 | return system_cpu_support_sse41(); 23 | # endif 24 | #else 25 | return false; 26 | #endif 27 | } 28 | 29 | CCL_NAMESPACE_END 30 | 31 | #endif /* __UTIL_OPENIMAGEDENOISE_H__ */ 32 | -------------------------------------------------------------------------------- /src/util/param.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_PARAM_H__ 5 | #define __UTIL_PARAM_H__ 6 | 7 | /* Parameter value lists from OpenImageIO are used to store custom properties 8 | * on various data, which can then later be used in shaders. */ 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | CCL_NAMESPACE_BEGIN 15 | 16 | OIIO_NAMESPACE_USING 17 | 18 | static constexpr TypeDesc TypeFloat2(TypeDesc::FLOAT, TypeDesc::VEC2); 19 | static constexpr TypeDesc TypeRGBA(TypeDesc::FLOAT, TypeDesc::VEC4, TypeDesc::COLOR); 20 | static constexpr TypeDesc TypeFloatArray4(TypeDesc::FLOAT, 21 | TypeDesc::SCALAR, 22 | TypeDesc::NOSEMANTICS, 23 | 4); 24 | 25 | CCL_NAMESPACE_END 26 | 27 | #endif /* __UTIL_PARAM_H__ */ 28 | -------------------------------------------------------------------------------- /src/util/queue.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_QUEUE_H__ 5 | #define __UTIL_QUEUE_H__ 6 | 7 | #include 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | using std::queue; 12 | 13 | CCL_NAMESPACE_END 14 | 15 | #endif /* __UTIL_LIST_H__ */ 16 | -------------------------------------------------------------------------------- /src/util/semaphore.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_SEMAPHORE_H__ 5 | #define __UTIL_SEMAPHORE_H__ 6 | 7 | #include "util/thread.h" 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | /* Counting Semaphore 12 | * 13 | * To restrict concurrent access to a resource to a specified number 14 | * of threads. Similar to std::counting_semaphore from C++20. */ 15 | 16 | class thread_counting_semaphore { 17 | public: 18 | explicit thread_counting_semaphore(const int count) : count(count) 19 | { 20 | } 21 | 22 | thread_counting_semaphore(const thread_counting_semaphore &) = delete; 23 | 24 | void acquire() 25 | { 26 | thread_scoped_lock lock(mutex); 27 | while (count == 0) { 28 | condition.wait(lock); 29 | } 30 | count--; 31 | } 32 | 33 | void release() 34 | { 35 | thread_scoped_lock lock(mutex); 36 | count++; 37 | condition.notify_one(); 38 | } 39 | 40 | protected: 41 | thread_mutex mutex; 42 | thread_condition_variable condition; 43 | int count; 44 | }; 45 | 46 | CCL_NAMESPACE_END 47 | 48 | #endif /* __UTIL_SEMAPHORE_H__ */ 49 | -------------------------------------------------------------------------------- /src/util/set.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_SET_H__ 5 | #define __UTIL_SET_H__ 6 | 7 | #include 8 | #include 9 | 10 | #if defined(_MSC_VER) && (_MSC_VER >= 1900) 11 | # include 12 | #endif 13 | 14 | CCL_NAMESPACE_BEGIN 15 | 16 | using std::set; 17 | using std::unordered_set; 18 | 19 | CCL_NAMESPACE_END 20 | 21 | #endif /* __UTIL_SET_H__ */ 22 | -------------------------------------------------------------------------------- /src/util/static_assert.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | /* clang-format off */ 5 | 6 | /* #define static_assert triggers a bug in some clang-format versions, disable 7 | * format for entire file to keep results consistent. */ 8 | 9 | #ifndef __UTIL_STATIC_ASSERT_H__ 10 | #define __UTIL_STATIC_ASSERT_H__ 11 | 12 | CCL_NAMESPACE_BEGIN 13 | 14 | #if defined(CYCLES_CUBIN_CC) 15 | # define static_assert(statement, message) 16 | #endif 17 | 18 | #define static_assert_align(st, align) \ 19 | static_assert((sizeof(st) % (align) == 0), "Structure must be strictly aligned") // NOLINT 20 | 21 | CCL_NAMESPACE_END 22 | 23 | #endif /* __UTIL_STATIC_ASSERT_H__ */ 24 | -------------------------------------------------------------------------------- /src/util/stats.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_STATS_H__ 5 | #define __UTIL_STATS_H__ 6 | 7 | #include "util/atomic.h" 8 | #include "util/profiling.h" 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | class Stats { 13 | public: 14 | enum static_init_t { static_init = 0 }; 15 | 16 | Stats() : mem_used(0), mem_peak(0) 17 | { 18 | } 19 | explicit Stats(static_init_t) 20 | { 21 | } 22 | 23 | void mem_alloc(size_t size) 24 | { 25 | atomic_add_and_fetch_z(&mem_used, size); 26 | atomic_fetch_and_update_max_z(&mem_peak, mem_used); 27 | } 28 | 29 | void mem_free(size_t size) 30 | { 31 | assert(mem_used >= size); 32 | atomic_sub_and_fetch_z(&mem_used, size); 33 | } 34 | 35 | size_t mem_used; 36 | size_t mem_peak; 37 | }; 38 | 39 | CCL_NAMESPACE_END 40 | 41 | #endif /* __UTIL_STATS_H__ */ 42 | -------------------------------------------------------------------------------- /src/util/system.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_SYSTEM_H__ 5 | #define __UTIL_SYSTEM_H__ 6 | 7 | #include 8 | #include 9 | 10 | #include 11 | 12 | CCL_NAMESPACE_BEGIN 13 | 14 | /* Get width in characters of the current console output. */ 15 | int system_console_width(); 16 | 17 | std::string system_cpu_brand_string(); 18 | int system_cpu_bits(); 19 | bool system_cpu_support_sse2(); 20 | bool system_cpu_support_sse41(); 21 | bool system_cpu_support_avx2(); 22 | 23 | size_t system_physical_ram(); 24 | 25 | /* Get identifier of the currently running process. */ 26 | uint64_t system_self_process_id(); 27 | 28 | CCL_NAMESPACE_END 29 | 30 | #endif /* __UTIL_SYSTEM_H__ */ 31 | -------------------------------------------------------------------------------- /src/util/transform_avx2.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "util/transform.h" 5 | 6 | CCL_NAMESPACE_BEGIN 7 | 8 | void transform_inverse_cpu_avx2(const Transform &tfm, Transform &itfm) 9 | { 10 | itfm = transform_inverse_impl(tfm); 11 | } 12 | 13 | CCL_NAMESPACE_END 14 | -------------------------------------------------------------------------------- /src/util/transform_sse41.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #include "util/transform.h" 5 | 6 | CCL_NAMESPACE_BEGIN 7 | 8 | void transform_inverse_cpu_sse41(const Transform &tfm, Transform &itfm) 9 | { 10 | itfm = transform_inverse_impl(tfm); 11 | } 12 | 13 | CCL_NAMESPACE_END 14 | -------------------------------------------------------------------------------- /src/util/types_float2.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifndef __UTIL_TYPES_H__ 7 | # error "Do not include this file directly, include util/types.h instead." 8 | #endif 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 13 | struct float2 { 14 | float x, y; 15 | 16 | # ifndef __KERNEL_GPU__ 17 | __forceinline float operator[](int i) const; 18 | __forceinline float &operator[](int i); 19 | # endif 20 | }; 21 | 22 | ccl_device_inline float2 make_float2(float x, float y); 23 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 24 | 25 | ccl_device_inline void print_float2(ccl_private const char *label, const float2 a); 26 | 27 | CCL_NAMESPACE_END 28 | -------------------------------------------------------------------------------- /src/util/types_float2_impl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifndef __UTIL_TYPES_H__ 7 | # error "Do not include this file directly, include util/types.h instead." 8 | #endif 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 13 | # ifndef __KERNEL_GPU__ 14 | __forceinline float float2::operator[](int i) const 15 | { 16 | util_assert(i >= 0); 17 | util_assert(i < 2); 18 | return *(&x + i); 19 | } 20 | 21 | __forceinline float &float2::operator[](int i) 22 | { 23 | util_assert(i >= 0); 24 | util_assert(i < 2); 25 | return *(&x + i); 26 | } 27 | # endif 28 | 29 | ccl_device_inline float2 make_float2(float x, float y) 30 | { 31 | float2 a = {x, y}; 32 | return a; 33 | } 34 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 35 | 36 | ccl_device_inline void print_float2(ccl_private const char *label, const float2 a) 37 | { 38 | #ifdef __KERNEL_PRINTF__ 39 | printf("%s: %.8f %.8f\n", label, (double)a.x, (double)a.y); 40 | #endif 41 | } 42 | 43 | CCL_NAMESPACE_END 44 | -------------------------------------------------------------------------------- /src/util/types_int2.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifndef __UTIL_TYPES_H__ 7 | # error "Do not include this file directly, include util/types.h instead." 8 | #endif 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 13 | struct int2 { 14 | int x, y; 15 | 16 | # ifndef __KERNEL_GPU__ 17 | __forceinline int operator[](int i) const; 18 | __forceinline int &operator[](int i); 19 | # endif 20 | }; 21 | 22 | ccl_device_inline int2 make_int2(int x, int y); 23 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 24 | 25 | CCL_NAMESPACE_END 26 | -------------------------------------------------------------------------------- /src/util/types_int2_impl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifndef __UTIL_TYPES_H__ 7 | # error "Do not include this file directly, include util/types.h instead." 8 | #endif 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 13 | # ifndef __KERNEL_GPU__ 14 | int int2::operator[](int i) const 15 | { 16 | util_assert(i >= 0); 17 | util_assert(i < 2); 18 | return *(&x + i); 19 | } 20 | 21 | int &int2::operator[](int i) 22 | { 23 | util_assert(i >= 0); 24 | util_assert(i < 2); 25 | return *(&x + i); 26 | } 27 | # endif 28 | 29 | ccl_device_inline int2 make_int2(int x, int y) 30 | { 31 | int2 a = {x, y}; 32 | return a; 33 | } 34 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 35 | 36 | CCL_NAMESPACE_END 37 | -------------------------------------------------------------------------------- /src/util/types_spectrum.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_TYPES_SPECTRUM_H__ 5 | #define __UTIL_TYPES_SPECTRUM_H__ 6 | 7 | #ifndef __UTIL_TYPES_H__ 8 | # error "Do not include this file directly, include util/types.h instead." 9 | #endif 10 | 11 | CCL_NAMESPACE_BEGIN 12 | 13 | #define SPECTRUM_CHANNELS 3 14 | #define SPECTRUM_DATA_TYPE float3 15 | #define PACKED_SPECTRUM_DATA_TYPE packed_float3 16 | 17 | using Spectrum = SPECTRUM_DATA_TYPE; 18 | using PackedSpectrum = PACKED_SPECTRUM_DATA_TYPE; 19 | 20 | #define make_spectrum(f) CONCAT(make_, SPECTRUM_DATA_TYPE(f)) 21 | #define load_spectrum(f) CONCAT(load_, SPECTRUM_DATA_TYPE(f)) 22 | #define store_spectrum(s, f) CONCAT(store_, SPECTRUM_DATA_TYPE((s), (f))) 23 | 24 | #define zero_spectrum CONCAT(zero_, SPECTRUM_DATA_TYPE) 25 | #define one_spectrum CONCAT(one_, SPECTRUM_DATA_TYPE) 26 | 27 | #define FOREACH_SPECTRUM_CHANNEL(counter) \ 28 | for (int counter = 0; counter < SPECTRUM_CHANNELS; counter++) 29 | 30 | #define GET_SPECTRUM_CHANNEL(v, i) (((ccl_private float *)(&(v)))[i]) 31 | 32 | CCL_NAMESPACE_END 33 | 34 | #endif /* __UTIL_TYPES_SPECTRUM_H__ */ 35 | -------------------------------------------------------------------------------- /src/util/types_uchar2.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifndef __UTIL_TYPES_H__ 7 | # error "Do not include this file directly, include util/types.h instead." 8 | #endif 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 13 | struct uchar2 { 14 | uchar x, y; 15 | 16 | # ifndef __KERNEL_GPU__ 17 | __forceinline uchar operator[](int i) const; 18 | __forceinline uchar &operator[](int i); 19 | # endif 20 | }; 21 | 22 | ccl_device_inline uchar2 make_uchar2(uchar x, uchar y); 23 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 24 | 25 | CCL_NAMESPACE_END 26 | -------------------------------------------------------------------------------- /src/util/types_uchar2_impl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_TYPES_UCHAR2_IMPL_H__ 5 | #define __UTIL_TYPES_UCHAR2_IMPL_H__ 6 | 7 | #ifndef __UTIL_TYPES_H__ 8 | # error "Do not include this file directly, include util/types.h instead." 9 | #endif 10 | 11 | CCL_NAMESPACE_BEGIN 12 | 13 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 14 | # ifndef __KERNEL_GPU__ 15 | uchar uchar2::operator[](int i) const 16 | { 17 | util_assert(i >= 0); 18 | util_assert(i < 2); 19 | return *(&x + i); 20 | } 21 | 22 | uchar &uchar2::operator[](int i) 23 | { 24 | util_assert(i >= 0); 25 | util_assert(i < 2); 26 | return *(&x + i); 27 | } 28 | # endif 29 | 30 | ccl_device_inline uchar2 make_uchar2(uchar x, uchar y) 31 | { 32 | uchar2 a = {x, y}; 33 | return a; 34 | } 35 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 36 | 37 | CCL_NAMESPACE_END 38 | 39 | #endif /* __UTIL_TYPES_UCHAR2_IMPL_H__ */ 40 | -------------------------------------------------------------------------------- /src/util/types_uchar3.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_TYPES_UCHAR3_H__ 5 | #define __UTIL_TYPES_UCHAR3_H__ 6 | 7 | #ifndef __UTIL_TYPES_H__ 8 | # error "Do not include this file directly, include util/types.h instead." 9 | #endif 10 | 11 | CCL_NAMESPACE_BEGIN 12 | 13 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 14 | struct uchar3 { 15 | uchar x, y, z; 16 | 17 | # ifndef __KERNEL_GPU__ 18 | __forceinline uchar operator[](int i) const; 19 | __forceinline uchar &operator[](int i); 20 | # endif 21 | }; 22 | 23 | ccl_device_inline uchar3 make_uchar3(uchar x, uchar y, uchar z); 24 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 25 | 26 | CCL_NAMESPACE_END 27 | 28 | #endif /* __UTIL_TYPES_UCHAR3_H__ */ 29 | -------------------------------------------------------------------------------- /src/util/types_uchar3_impl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_TYPES_UCHAR3_IMPL_H__ 5 | #define __UTIL_TYPES_UCHAR3_IMPL_H__ 6 | 7 | #ifndef __UTIL_TYPES_H__ 8 | # error "Do not include this file directly, include util/types.h instead." 9 | #endif 10 | 11 | CCL_NAMESPACE_BEGIN 12 | 13 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 14 | # ifndef __KERNEL_GPU__ 15 | uchar uchar3::operator[](int i) const 16 | { 17 | util_assert(i >= 0); 18 | util_assert(i < 3); 19 | return *(&x + i); 20 | } 21 | 22 | uchar &uchar3::operator[](int i) 23 | { 24 | util_assert(i >= 0); 25 | util_assert(i < 3); 26 | return *(&x + i); 27 | } 28 | # endif 29 | 30 | ccl_device_inline uchar3 make_uchar3(uchar x, uchar y, uchar z) 31 | { 32 | uchar3 a = {x, y, z}; 33 | return a; 34 | } 35 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 36 | 37 | CCL_NAMESPACE_END 38 | 39 | #endif /* __UTIL_TYPES_UCHAR3_IMPL_H__ */ 40 | -------------------------------------------------------------------------------- /src/util/types_uchar4.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifndef __UTIL_TYPES_H__ 7 | # error "Do not include this file directly, include util/types.h instead." 8 | #endif 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 13 | struct uchar4 { 14 | uchar x, y, z, w; 15 | 16 | # ifndef __KERNEL_GPU__ 17 | __forceinline uchar operator[](int i) const; 18 | __forceinline uchar &operator[](int i); 19 | # endif 20 | }; 21 | 22 | ccl_device_inline uchar4 make_uchar4(uchar x, uchar y, uchar z, uchar w); 23 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 24 | 25 | CCL_NAMESPACE_END 26 | -------------------------------------------------------------------------------- /src/util/types_uchar4_impl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_TYPES_UCHAR4_IMPL_H__ 5 | #define __UTIL_TYPES_UCHAR4_IMPL_H__ 6 | 7 | #ifndef __UTIL_TYPES_H__ 8 | # error "Do not include this file directly, include util/types.h instead." 9 | #endif 10 | 11 | CCL_NAMESPACE_BEGIN 12 | 13 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 14 | # ifndef __KERNEL_GPU__ 15 | uchar uchar4::operator[](int i) const 16 | { 17 | util_assert(i >= 0); 18 | util_assert(i < 4); 19 | return *(&x + i); 20 | } 21 | 22 | uchar &uchar4::operator[](int i) 23 | { 24 | util_assert(i >= 0); 25 | util_assert(i < 4); 26 | return *(&x + i); 27 | } 28 | # endif 29 | 30 | ccl_device_inline uchar4 make_uchar4(uchar x, uchar y, uchar z, uchar w) 31 | { 32 | uchar4 a = {x, y, z, w}; 33 | return a; 34 | } 35 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 36 | 37 | CCL_NAMESPACE_END 38 | 39 | #endif /* __UTIL_TYPES_UCHAR4_IMPL_H__ */ 40 | -------------------------------------------------------------------------------- /src/util/types_uint2.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifndef __UTIL_TYPES_H__ 7 | # error "Do not include this file directly, include util/types.h instead." 8 | #endif 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 13 | struct uint2 { 14 | uint x, y; 15 | 16 | # ifndef __KERNEL_GPU__ 17 | __forceinline uint operator[](uint i) const; 18 | __forceinline uint &operator[](uint i); 19 | # endif 20 | }; 21 | 22 | ccl_device_inline uint2 make_uint2(uint x, uint y); 23 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 24 | 25 | CCL_NAMESPACE_END 26 | -------------------------------------------------------------------------------- /src/util/types_uint2_impl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifndef __UTIL_TYPES_H__ 7 | # error "Do not include this file directly, include util/types.h instead." 8 | #endif 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 13 | # ifndef __KERNEL_GPU__ 14 | __forceinline uint uint2::operator[](uint i) const 15 | { 16 | util_assert(i < 2); 17 | return *(&x + i); 18 | } 19 | 20 | __forceinline uint &uint2::operator[](uint i) 21 | { 22 | util_assert(i < 2); 23 | return *(&x + i); 24 | } 25 | # endif 26 | 27 | ccl_device_inline uint2 make_uint2(uint x, uint y) 28 | { 29 | uint2 a = {x, y}; 30 | return a; 31 | } 32 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 33 | 34 | CCL_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /src/util/types_uint3.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifndef __UTIL_TYPES_H__ 7 | # error "Do not include this file directly, include util/types.h instead." 8 | #endif 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 13 | struct uint3 { 14 | uint x, y, z; 15 | 16 | # ifndef __KERNEL_GPU__ 17 | __forceinline uint operator[](uint i) const; 18 | __forceinline uint &operator[](uint i); 19 | # endif 20 | }; 21 | 22 | ccl_device_inline uint3 make_uint3(uint x, uint y, uint z); 23 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 24 | 25 | CCL_NAMESPACE_END 26 | -------------------------------------------------------------------------------- /src/util/types_uint3_impl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifndef __UTIL_TYPES_H__ 7 | # error "Do not include this file directly, include util/types.h instead." 8 | #endif 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 13 | # ifndef __KERNEL_GPU__ 14 | __forceinline uint uint3::operator[](uint i) const 15 | { 16 | util_assert(i < 3); 17 | return *(&x + i); 18 | } 19 | 20 | __forceinline uint &uint3::operator[](uint i) 21 | { 22 | util_assert(i < 3); 23 | return *(&x + i); 24 | } 25 | # endif 26 | 27 | ccl_device_inline uint3 make_uint3(uint x, uint y, uint z) 28 | { 29 | uint3 a = {x, y, z}; 30 | return a; 31 | } 32 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 33 | 34 | CCL_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /src/util/types_uint4.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifndef __UTIL_TYPES_H__ 7 | # error "Do not include this file directly, include util/types.h instead." 8 | #endif 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 13 | struct uint4 { 14 | uint x, y, z, w; 15 | 16 | # ifndef __KERNEL_GPU__ 17 | __forceinline uint operator[](uint i) const; 18 | __forceinline uint &operator[](uint i); 19 | # endif 20 | }; 21 | 22 | ccl_device_inline uint4 make_uint4(uint x, uint y, uint z, uint w); 23 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 24 | 25 | CCL_NAMESPACE_END 26 | -------------------------------------------------------------------------------- /src/util/types_uint4_impl.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #pragma once 5 | 6 | #ifndef __UTIL_TYPES_H__ 7 | # error "Do not include this file directly, include util/types.h instead." 8 | #endif 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 13 | # ifndef __KERNEL_GPU__ 14 | __forceinline uint uint4::operator[](uint i) const 15 | { 16 | util_assert(i < 3); 17 | return *(&x + i); 18 | } 19 | 20 | __forceinline uint &uint4::operator[](uint i) 21 | { 22 | util_assert(i < 3); 23 | return *(&x + i); 24 | } 25 | # endif 26 | 27 | ccl_device_inline uint4 make_uint4(uint x, uint y, uint z, uint w) 28 | { 29 | uint4 a = {x, y, z, w}; 30 | return a; 31 | } 32 | #endif /* __KERNEL_NATIVE_VECTOR_TYPES__ */ 33 | 34 | CCL_NAMESPACE_END 35 | -------------------------------------------------------------------------------- /src/util/types_ushort4.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_TYPES_USHORT4_H__ 5 | #define __UTIL_TYPES_USHORT4_H__ 6 | 7 | #ifndef __UTIL_TYPES_H__ 8 | # error "Do not include this file directly, include util/types.h instead." 9 | #endif 10 | 11 | CCL_NAMESPACE_BEGIN 12 | 13 | #ifndef __KERNEL_NATIVE_VECTOR_TYPES__ 14 | 15 | struct ushort4 { 16 | uint16_t x, y, z, w; 17 | }; 18 | 19 | #endif 20 | 21 | CCL_NAMESPACE_END 22 | 23 | #endif /* __UTIL_TYPES_USHORT4_H__ */ 24 | -------------------------------------------------------------------------------- /src/util/unique_ptr.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_UNIQUE_PTR_H__ 5 | #define __UTIL_UNIQUE_PTR_H__ 6 | 7 | #include 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | using std::make_unique; 12 | using std::unique_ptr; 13 | 14 | CCL_NAMESPACE_END 15 | 16 | #endif /* __UTIL_UNIQUE_PTR_H__ */ 17 | -------------------------------------------------------------------------------- /src/util/version.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_VERSION_H__ 5 | #define __UTIL_VERSION_H__ 6 | 7 | /* Cycles version number */ 8 | 9 | CCL_NAMESPACE_BEGIN 10 | 11 | #define CYCLES_VERSION_MAJOR 3 12 | #define CYCLES_VERSION_MINOR 5 13 | #define CYCLES_VERSION_PATCH 0 14 | 15 | #define CYCLES_MAKE_VERSION_STRING2(a, b, c) #a "." #b "." #c 16 | #define CYCLES_MAKE_VERSION_STRING(a, b, c) CYCLES_MAKE_VERSION_STRING2(a, b, c) 17 | #define CYCLES_VERSION_STRING \ 18 | CYCLES_MAKE_VERSION_STRING(CYCLES_VERSION_MAJOR, CYCLES_VERSION_MINOR, CYCLES_VERSION_PATCH) 19 | 20 | /* Blender libraries version compatible with this version */ 21 | 22 | #define CYCLES_BLENDER_LIBRARIES_VERSION 3.5 23 | 24 | CCL_NAMESPACE_END 25 | 26 | #endif /* __UTIL_VERSION_H__ */ 27 | -------------------------------------------------------------------------------- /src/util/windows.cpp: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2019-2022 Blender Foundation */ 3 | 4 | #ifdef _WIN32 5 | # include 6 | #endif 7 | 8 | #include "util/windows.h" 9 | 10 | CCL_NAMESPACE_BEGIN 11 | 12 | bool system_windows_version_at_least(int major, int build) 13 | { 14 | #ifdef _WIN32 15 | HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll"); 16 | if (hMod == 0) { 17 | return false; 18 | } 19 | 20 | typedef NTSTATUS(WINAPI * RtlGetVersionPtr)(PRTL_OSVERSIONINFOW); 21 | RtlGetVersionPtr rtl_get_version = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion"); 22 | if (rtl_get_version == NULL) { 23 | return false; 24 | } 25 | 26 | RTL_OSVERSIONINFOW rovi = {0}; 27 | rovi.dwOSVersionInfoSize = sizeof(rovi); 28 | if (rtl_get_version(&rovi) != 0) { 29 | return false; 30 | } 31 | 32 | return (rovi.dwMajorVersion > major || 33 | (rovi.dwMajorVersion == major && rovi.dwBuildNumber >= build)); 34 | #else 35 | (void)major; 36 | (void)build; 37 | return false; 38 | #endif 39 | } 40 | 41 | CCL_NAMESPACE_END 42 | -------------------------------------------------------------------------------- /src/util/windows.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_WINDOWS_H__ 5 | #define __UTIL_WINDOWS_H__ 6 | 7 | #ifdef _WIN32 8 | 9 | # ifndef NOGDI 10 | # define NOGDI 11 | # endif 12 | # ifndef NOMINMAX 13 | # define NOMINMAX 14 | # endif 15 | # ifndef WIN32_LEAN_AND_MEAN 16 | # define WIN32_LEAN_AND_MEAN 17 | # endif 18 | 19 | # include 20 | 21 | #endif /* _WIN32 */ 22 | 23 | CCL_NAMESPACE_BEGIN 24 | 25 | bool system_windows_version_at_least(int major, int build); 26 | 27 | CCL_NAMESPACE_END 28 | 29 | #endif /* __UTIL_WINDOWS_H__ */ 30 | -------------------------------------------------------------------------------- /src/util/xml.h: -------------------------------------------------------------------------------- 1 | /* SPDX-License-Identifier: Apache-2.0 2 | * Copyright 2011-2022 Blender Foundation */ 3 | 4 | #ifndef __UTIL_XML_H__ 5 | #define __UTIL_XML_H__ 6 | 7 | /* PugiXML is used for XML parsing. */ 8 | 9 | #include 10 | 11 | CCL_NAMESPACE_BEGIN 12 | 13 | OIIO_NAMESPACE_USING 14 | 15 | #ifdef WITH_SYSTEM_PUGIXML 16 | # define PUGIXML_NAMESPACE pugi 17 | #else 18 | # define PUGIXML_NAMESPACE OIIO_NAMESPACE::pugi 19 | #endif 20 | 21 | using PUGIXML_NAMESPACE::xml_attribute; 22 | using PUGIXML_NAMESPACE::xml_document; 23 | using PUGIXML_NAMESPACE::xml_node; 24 | using PUGIXML_NAMESPACE::xml_parse_result; 25 | 26 | CCL_NAMESPACE_END 27 | 28 | #endif /* __UTIL_XML_H__ */ 29 | -------------------------------------------------------------------------------- /third_party/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_subdirectory(cuew) 2 | add_subdirectory(hipew) 3 | add_subdirectory(sky) 4 | if(UNIX AND NOT APPLE) 5 | add_subdirectory(libc_compat) 6 | endif() 7 | -------------------------------------------------------------------------------- /third_party/cuew/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SRC 2 | src/cuew.c 3 | ) 4 | 5 | set(SRC_HEADERS 6 | include/cuew.h 7 | ) 8 | 9 | include_directories( 10 | . 11 | include 12 | ) 13 | 14 | add_library(extern_cuew ${SRC} ${SRC_HEADERS}) 15 | -------------------------------------------------------------------------------- /third_party/cuew/README: -------------------------------------------------------------------------------- 1 | The CUDA Extension Wrangler Library (CUEW) is a cross-platform open-source 2 | C/C++ extension loading library. CUEW provides efficient run-time mechanisms 3 | for determining which CUDA functions and extensions extensions are supported 4 | on the target platform. 5 | 6 | CUDA core and extension functionality is exposed in a single header file. 7 | CUEW has been tested on a variety of operating systems, including Windows, 8 | Linux, Mac OS X. 9 | 10 | LICENSE 11 | 12 | CUEW library is released under the Apache 2.0 license. 13 | -------------------------------------------------------------------------------- /third_party/cuew/auto/cuew_gen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # This script invokes cuew_gen.py and updates the 4 | # header and source files in the repository. 5 | 6 | SCRIPT=`realpath -s $0` 7 | DIR=`dirname $SCRIPT` 8 | 9 | python3 ${DIR}/cuew_gen.py hdr $@ > $DIR/../include/cuew.h 10 | python3 ${DIR}/cuew_gen.py impl $@ > $DIR/../src/cuew.c 11 | -------------------------------------------------------------------------------- /third_party/cuew/auto/stdint.h: -------------------------------------------------------------------------------- 1 | /* This file is needed to workaround issue with parsing system headers. */ 2 | 3 | typedef unsigned int uint32_t; 4 | typedef unsigned long int uint64_t; 5 | -------------------------------------------------------------------------------- /third_party/cuew/auto/stdlib.h: -------------------------------------------------------------------------------- 1 | /* This file is needed to workaround issue with parsing system headers. */ 2 | 3 | typedef long size_t; 4 | -------------------------------------------------------------------------------- /third_party/hipew/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | set(SRC 2 | src/hipew.c 3 | ) 4 | 5 | set(SRC_HEADERS 6 | include/hipew.h 7 | ) 8 | 9 | include_directories( 10 | . 11 | include 12 | ) 13 | 14 | add_library(extern_hipew ${SRC} ${SRC_HEADERS}) 15 | -------------------------------------------------------------------------------- /third_party/hipew/README: -------------------------------------------------------------------------------- 1 | The HIP Extension Wrangler Library (HIPEW) is a cross-platform open-source 2 | C/C++ library to dynamically load the HIP library. 3 | 4 | HIP (Heterogeneous-Compute Interface for Portability) is an API for C++ 5 | programming on AMD GPUs. 6 | 7 | It is maintained as part of the Blender project, but included in extern/ 8 | for consistency with CUEW and CLEW libraries. 9 | 10 | LICENSE 11 | 12 | HIPEW is released under the Apache 2.0 license. 13 | -------------------------------------------------------------------------------- /third_party/libc_compat/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2020 Blender Foundation 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | set(INC 16 | . 17 | ) 18 | 19 | set(INC_SYS 20 | ) 21 | 22 | set(SRC 23 | libc_compat.c 24 | ) 25 | 26 | set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffast-math") 27 | 28 | include_directories( 29 | ${INC} ${INC_SYS} 30 | ) 31 | 32 | add_library(extern_libc_compat "${SRC}" "${INC}" "${INC_SYS}") 33 | -------------------------------------------------------------------------------- /third_party/mikktspace/README.md: -------------------------------------------------------------------------------- 1 | # MikkTSpace 2 | A common standard for tangent space used in baking tools to produce normal maps. 3 | 4 | More information can be found at http://www.mikktspace.com/. 5 | -------------------------------------------------------------------------------- /third_party/sky/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # ***** BEGIN GPL LICENSE BLOCK ***** 2 | # 3 | # This program is free software; you can redistribute it and/or 4 | # modify it under the terms of the GNU General Public License 5 | # as published by the Free Software Foundation; either version 2 6 | # of the License, or (at your option) any later version. 7 | # 8 | # This program is distributed in the hope that it will be useful, 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 | # GNU General Public License for more details. 12 | # 13 | # You should have received a copy of the GNU General Public License 14 | # along with this program; if not, write to the Free Software Foundation, 15 | # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 | # 17 | # ***** END GPL LICENSE BLOCK ***** 18 | 19 | set(INC 20 | include 21 | ) 22 | 23 | set(INC_SYS 24 | 25 | ) 26 | 27 | set(SRC 28 | source/sky_model.cpp 29 | source/sky_nishita.cpp 30 | 31 | include/sky_model.h 32 | source/sky_float3.h 33 | source/sky_model_data.h 34 | ) 35 | 36 | include_directories( 37 | ${INC} ${INC_SYS} 38 | ) 39 | 40 | add_library(extern_sky "${SRC}" "${INC}" "${INC_SYS}") 41 | -------------------------------------------------------------------------------- /web/config.toml: -------------------------------------------------------------------------------- 1 | baseURL = 'https://www.cycles-renderer.org' 2 | title = 'Cycles' 3 | theme = "custom" 4 | 5 | [params] 6 | subtitle = 'Open Source Production Rendering' 7 | 8 | [menu] 9 | [[menu.main]] 10 | name = "Features" 11 | url = "/features/" 12 | weight = 2 13 | [[menu.main]] 14 | name = "Development" 15 | url = "/development/" 16 | weight = 3 17 | [[menu.main]] 18 | name = "" 19 | pre = "fa fa-twitter" 20 | url = "https://twitter.com/cyclesrenderer" 21 | weight = 4 22 | -------------------------------------------------------------------------------- /web/content/_index.md: -------------------------------------------------------------------------------- 1 | Cycles is an physically based production renderer developed by the [Blender project](https://www.blender.org). 2 | 3 | The source code is available under the Apache License v2, and can be integrated in open source and commercial software. 4 | -------------------------------------------------------------------------------- /web/static/CNAME: -------------------------------------------------------------------------------- 1 | www.cycles-renderer.org 2 | -------------------------------------------------------------------------------- /web/themes/custom/layouts/404.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcneel/cycles/95dc48e9c61910c61a52b72065b0b30bf1ee793c/web/themes/custom/layouts/404.html -------------------------------------------------------------------------------- /web/themes/custom/layouts/_default/baseof.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | {{- partial "head.html" . -}} 4 | 5 | {{- partial "header.html" . -}} 6 |
7 | {{- block "main" . }}{{- end }} 8 |
9 | {{- partial "footer.html" . -}} 10 | 11 | 12 | -------------------------------------------------------------------------------- /web/themes/custom/layouts/_default/list.html: -------------------------------------------------------------------------------- 1 | {{ define "main" }} 2 |

{{ .Title }}

3 | {{ range .Pages.ByPublishDate.Reverse }} 4 |

5 |

{{ .Title }}

6 | 7 |

{{ .Summary }}

8 |
9 |

10 | {{ end }} 11 | {{ end }} 12 | -------------------------------------------------------------------------------- /web/themes/custom/layouts/_default/single.html: -------------------------------------------------------------------------------- 1 | {{ define "main" }} 2 |
3 | {{ .Content }} 4 | {{ end }} 5 | -------------------------------------------------------------------------------- /web/themes/custom/layouts/index.html: -------------------------------------------------------------------------------- 1 | {{ define "main" }} 2 |
3 | {{.Content}} 4 | {{ end }} 5 | -------------------------------------------------------------------------------- /web/themes/custom/layouts/partials/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /web/themes/custom/layouts/partials/head.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | Cycles 8 | 9 | -------------------------------------------------------------------------------- /web/themes/custom/layouts/partials/header.html: -------------------------------------------------------------------------------- 1 |
2 |
3 | 4 | 9 | 10 | 26 |
27 |
28 |
29 | -------------------------------------------------------------------------------- /web/themes/custom/layouts/shortcodes/figure.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 |
5 |
6 | 7 | 8 |
9 | 10 |
11 | {{ .Inner }} 12 |
13 |
14 |
15 | -------------------------------------------------------------------------------- /web/themes/custom/layouts/shortcodes/gallery.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | {{ $baseURL := .Site.BaseURL }} 5 | 8 | -------------------------------------------------------------------------------- /web/themes/custom/theme.toml: -------------------------------------------------------------------------------- 1 | name = "custom" 2 | --------------------------------------------------------------------------------