Intel® Embree Documentation

repository·master·Indexed 25 days ago

https://github.com/renderkit/embree

A high-performance ray tracing library optimized for x86 and ARM CPUs and Intel GPUs. It provides optimized kernels for primitive types and acceleration structure construction. Features include support for SYCL on Xe HPC and HPG GPUs, multi-segment motion blur, point queries, collision detection, and SIMD-optimized ray packets. Includes guidance on CMake build configuration, RTCDevice and RTCScene management, and migration from Embree 3 to Embree 4.

Tokens
93.3K
Snippets
188
Records
446
Agent score
82%

What's inside Embree

  1. Overview of Intel® Embree

    master
    Intel® Embree is a high-performance, open-source (Apache 2.0) ray tracing library designed to improve the performance of photo-realistic rendering applications. It is optimized for production rendering with a focus on incoherent ray performance, high-quality acceleration structure construction, accurate primitive intersection, and low memory consumption.
  2. Check Embree platform and CPU compatibility

    master

    Embree supports the following platforms and hardware requirements:

    CPU Support

    • Windows: x86 (32-bit and 64-bit). ARM support is currently experimental.
    • Linux: x86 (64-bit) and ARM (64-bit).
    • macOS: x86 (64-bit) and ARM (e.g., Apple M1).
    • Minimum Requirement: An x86 CPU with SSE2 support or an Apple M1 CPU.

    GPU Support

    Embree supports Intel GPUs with the following microarchitectures:

    • Intel® Arc™ GPU (Xe HPG): Supported on Linux and Windows.
    • Intel® Data Center GPU Flex Series and Intel® Data Center GPU Max Series (Xe HPC): Supported on Linux.
  3. Programming Interfaces: ISPC and SYCL

    master

    Embree offers specialized interfaces for different programming models:

    • Intel® ISPC Interface: Supports applications written with the Intel® Implicit SPMD Program Compiler (ISPC), allowing developers to write renderers that automatically vectorize and leverage SSE, AVX, AVX2, and AVX-512 instructions.
    • SYCL Interface: Supports Intel GPUs through the SYCL open standard. This allows developers to write a single-source C++ renderer that executes efficiently on both CPUs and GPUs (specifically Xe HPG and Xe HPC microarchitectures), improving productivity and ensuring consistency.
  4. View projects using Embree

    master

    Embree is utilized by various high-fidelity visualization and rendering engines. Notable projects include:

    • OSPRay: A ray tracing based rendering engine for high-fidelity visualization.
    • Corona Renderer
    • FluidRay RT
    • SimLab Composer
    • Brighter3D: A rendering plugin for SketchUp.
    • Visual Designer 3D
    • Glise
    • Meso Star
    • LibThree: 3D visualization tool.
    • Bella Renderer
    • Autodesk Maya 2014 viewport plugin: Based on the Embree Example Renderer.

    If you are using Embree in your product and would like it to be listed, you can contact the support team at embree_support@intel.com.

  5. Manage memory for Embree SYCL with USM shared memory

    master

    To share data buffers (like vertex or index buffers) between the host and device, the easiest method is to allocate them as SYCL USM shared memory. This ensures the data is accessible to Embree during ray tracing. Use sycl::malloc or sycl::aligned_alloc with the sycl::usm::alloc::shared property.

    void* ptr = sycl::aligned_alloc(16, bytes, queue, sycl::usm::alloc::shared);
  6. Implement face-varying interpolation for subdivision meshes

    master

    To support face-varying data (like texture coordinates with different topologies), you can bind multiple topologies to a single subdivision mesh:

    1. Define Topologies: Each topology i requires its own index buffer (RTC_BUFFER_TYPE_INDEX at buffer slot i) and its own subdivision mode set via rtcSetGeometrySubdivisionMode.
    2. Bind Attributes: Use rtcSetGeometryVertexAttributeTopology to assign a specific topology to a vertex attribute buffer (RTC_BUFFER_TYPE_VERTEX_ATTRIBUTE) bound at slot j.
    3. Shared Face Buffer: Note that the face buffer (RTC_BUFFER_TYPE_FACE) is shared across all topologies; the n-th primitive always has the same number of vertices for every topology, even if the indices differ.
  7. Compile Embree with SYCL support on Linux

    master

    To enable GPU support via SYCL, you must use either the open source "oneAPI DPC++ Compiler" or the "Intel(R) oneAPI DPC++/C++ Compiler". Other SYCL compilers are not supported.

    Using oneAPI DPC++ Compiler (unpacked):

    1. Set environment variables to point to your unpacked compiler:
      export SYCL_BUNDLE_ROOT=path_to_dpcpp_compiler
      export PATH=$SYCL_BUNDLE_ROOT/bin:$PATH
      export CPATH=$SYCL_BUNDLE_ROOT/include:$CPATH
      export LIBRARY_PATH=$SYCL_BUNDLE_ROOT/lib:$LIBRARY_PATH
      export LD_LIBRARY_PATH=$SYCL_BUNDLE_ROOT/lib:$LD_LIBRARY_PATH
      export LD_LIBRARY_PATH=$SYCL_BUNDLE_ROOT/linux/lib/x64:$LD_LIBRARY_PATH
    2. Configure and build:
      cmake -B build -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DEMBREE_SYCL_SUPPORT=ON
      cmake --build build -j 8

    Using Intel(R) oneAPI DPC++/C++ Compiler (installed):

    1. Source the environment script:
      source /opt/intel/oneAPI/compiler/latest/env/vars.sh
    2. Configure and build:
      cmake -B build -DCMAKE_CXX_COMPILER=icpx -DCMAKE_C_COMPILER=icx -DEMBREE_SYCL_SUPPORT=ON
      cmake --build build -j 8

    Note: To run SYCL code on Intel Xe HPG/HPC GPUs, install the latest GPGPU drivers and the intel-level-zero-gpu-raytracing package via apt.

    # Example for oneAPI DPC++ Compiler
    cmake -B build \
          -DCMAKE_CXX_COMPILER=clang++ \
          -DCMAKE_C_COMPILER=clang \
          -DEMBREE_SYCL_SUPPORT=ON
    
    cmake --build build -j 8
  8. Manage Embree Geometry objects

    master

    A RTCGeometry object holds the raw data for primitives (e.g., triangle meshes, curves, etc.).

    Workflow:

    1. Create a geometry with rtcNewGeometry.
    2. Bind buffers (e.g., vertex and index buffers) using rtcSetSharedGeometryBuffer.
    3. Call rtcCommitGeometry to finalize the geometry data.
    4. Attach the geometry to a scene using rtcAttachGeometry or rtcAttachGeometryById.

    Motion Blur: To support multi-segment motion blur, specify the number of time steps with rtcSetGeometryTimeStepCount (range 2 to 129) and bind a vertex buffer for each time step. Optionally, define the time range with rtcSetGeometryTimeRange.

  9. Compile Embree on Windows

    master

    To compile Embree on Windows, use Visual Studio (2017, 2019, or 2022) and CMake 3.1 or higher.

    Key Requirements:

    • TBB: Embree uses TBB as its tasking system. You can use the TBB version provided with the Intel® Compiler or install it manually and place it in a tbb folder in the Embree root. Ensure tbb.dll and tbb_malloc.dll are in your PATH.
    • ISPC (Optional): If using Intel® ISPC, ensure it is compatible with your Visual Studio version and add it to your PATH or set EMBREE_ISPC_EXECUTABLE.

    Building via Command Line: Use the Visual Studio command prompt to build:

    cd path\to\embree
    mkdir build
    cd build
    cmake -G "Visual Studio 16 2019" ..
    cmake --build . --config Release

    Building via IDE (cmake-gui):

    1. Run cmake-gui and point to the Embree source and build directories.
    2. Click Configure and select your Generator (e.g., "Visual Studio 12 2013 Win64").
    3. To use Clang instead of MSVC, set the "Optional toolset to use (-T parameter)" to LLVM_v142.
    4. Click Generate and open embree4.sln in Visual Studio.
  10. GPU Performance Recommendations for SYCL

    master

    When using Embree with SYCL, follow these best practices for performance:

    • Low Code Complexity: Split your renderer into separate kernels instead of using a single "Uber kernel" to avoid spill code generation. Use SYCL specialization constants to enable only required features.
    • Feature Flags: Use SYCL specialization constants and feature flags in rtcIntersect1 and rtcOccluded1 to JIT compile minimal code. Use JIT caching if compilation times are an issue.
    • Inline Indirect Calls: Do not attach user geometry or intersection filter callbacks to geometries. Instead, pass the callback function directly through the RTCIntersectArguments (or RTCOccludedArguments) struct to rtcIntersect1 (or rtcOccluded1). This allows the SYCL compiler to inline the call. Do not read the function pointer from memory before passing it.
    • 7-Bit Ray Mask: Use only the lower 7 bits of the ray and geometry mask whenever possible. While Embree supports 32-bit masks, hardware acceleration is optimized for 8-bit masks. Using bits 7-31 requires software intervention and reduces performance. To use 32-bit masks, enable RTC_FEATURE_FLAG_32_BIT_RAY_MASK.
    • Motion Blur: For SYCL, keep primitive motion relatively small. If geometry moves fast, place the geometry into an instance and apply motion blur to the instance itself.
    // Example of passing an intersection filter directly for SYCL inlining
    RTC_SYCL_INDIRECTLY_CALLABLE void intersectionFilter(
      const RTCFilterFunctionNArguments* args
    ) { /* ... */ }
    
    RTCIntersectArguments args;
    rtcInitIntersectArguments(&args);
    args.filter = intersectionFilter;
    
    rtcIntersect1(scene, &ray, &args);