# trisycl/path_tracer architecture

> Architecture diagram of the GitHub repository trisycl/path_tracer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-16). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/trisycl/path_tracer
- Repository: https://github.com/trisycl/path_tracer

## Overview

##### Project type and purpose
- This is a standalone, compute-heavy CLI application: an experimental C++20 path tracer accelerated via SYCL (triSYCL by default) targeting GPUs or FPGAs.
- Its goal is to render images by simulating light paths (“path tracing”) and to explore replacing dynamic polymorphism with `std::variant`/`std::visit` in a heterogeneous context.

##### File structure
- Top-level:
- CMakeLists.txt + cmake/… → build system and custom FindTriSYCL module.
- src/main.cpp → host entry point compiling scene, invoking SYCL kernels, writing output.
- doc/ + images/ → documentation and example render.
- No separate “frontend/backend” folders: it’s a monolithic host/device compute engine.
- Dependencies: triSYCL (or other SYCL implementations), stb image library.

##### README
- Specifies features (motion blur, depth of field, various materials/geometry), build instructions (CMake + triSYCL or other SYCL), and run producing `out.png`.
- Emphasizes modern C++ constructs over classic dynamic polymorphism.

##### Detail
- `std::variant` layer sitting between Scene Data and Device Kernels, indicating compile-time dispatch.
- Call out optional FPGA mode vs. GPU mode (single_task vs. parallel_for).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build System
    subgraph "Build System"
        BS_CMake["CMakeLists.txt"]:::build
        BS_Find["FindTriSYCL Module"]:::build
        BS_Config["triSYCLConfig.cmake.in"]:::build
    end

    %% Host Application
    subgraph "Host Application" 
        HA_Main["main.cpp"]:::host
        subgraph "Scene Graph Data Structures"
            SG_Hitable["hitable.hpp"]:::host
            SG_Sphere["sphere.hpp"]:::host
            SG_Triangle["triangle.hpp"]:::host
            SG_Box["box.hpp"]:::host
            SG_Rect["rectangle.hpp"]:::host
            SG_ConstMed["constant_medium.hpp"]:::host
            SG_Material["material.hpp"]:::host
            SG_Texture["texture.hpp"]:::host
        end
        HA_Dispatch["Static-Dispatch Layer\n(std::variant/std::visit)"]:::host
        subgraph "Math Utilities"
            RV_Ray["ray.hpp"]:::host
            RV_Vec["vec.hpp"]:::host
            RV_RTWeek["rtweekend.hpp"]:::host
            RV_Xor["xorshift.hpp"]:::host
        end
        subgraph "Camera & Parameters"
            Camera["camera.hpp"]:::host
            BuildParams["build_parameters.hpp"]:::host
        end
        HA_Output["Image Output\n(stb write PNG)"]:::host
    end

    %% SYCL & Device
    subgraph "SYCL Runtime & Device Kernels"
        SYCL_RT["SYCL Runtime Interface"]:::device
        Kernels["Render Logic &\nDevice Kernels"]:::device
        Buffers["Memory Buffers"]:::device
    end

    %% External Dependencies
    subgraph "External Dependencies"
        Dep_Sycl["triSYCL / SYCL Impl."]:::ext
        Dep_Stb["stb image library"]:::ext
        Doc["Documentation (doc/)"]:::ext
        Images["Example Images (images/)"]:::ext
    end

    %% Connections
    BS_CMake --> HA_Main
    BS_Find --> HA_Main
    BS_Config --> HA_Main

    HA_Main --> SG_Hitable
    HA_Main --> HA_Dispatch
    HA_Main --> RV_Ray
    HA_Main --> Camera
    HA_Main --> SYCL_RT
    HA_Main --> Dep_Sycl
    HA_Main --> Dep_Stb

    SG_Hitable -->|"upload scene data"| Buffers
    SG_Sphere --> Buffers
    SG_Triangle --> Buffers
    SG_Box --> Buffers
    SG_Rect --> Buffers
    SG_ConstMed --> Buffers
    SG_Material --> Buffers
    SG_Texture --> Buffers

    HA_Dispatch -->|"dispatch variant types"| Kernels

    HA_Main -->|"submit kernel"| SYCL_RT
    SYCL_RT -->|"dispatch kernel"| Kernels

    Kernels -->|"write pixel data"| Buffers
    Buffers -->|"download pixel data"| HA_Main

    HA_Main -->|"write PNG"| HA_Output

    Doc --> Dep_Stb
    Images --> Dep_Stb

    %% Click Events
    click BS_CMake "https://github.com/trisycl/path_tracer/blob/main/CMakeLists.txt"
    click BS_Find "https://github.com/trisycl/path_tracer/blob/main/cmake/FindTriSYCL.cmake"
    click BS_Config "https://github.com/trisycl/path_tracer/blob/main/cmake/triSYCLConfig.cmake.in"
    click HA_Main "https://github.com/trisycl/path_tracer/blob/main/src/main.cpp"
    click SG_Hitable "https://github.com/trisycl/path_tracer/blob/main/include/hitable.hpp"
    click SG_Sphere "https://github.com/trisycl/path_tracer/blob/main/include/sphere.hpp"
    click SG_Triangle "https://github.com/trisycl/path_tracer/blob/main/include/triangle.hpp"
    click SG_Box "https://github.com/trisycl/path_tracer/blob/main/include/box.hpp"
    click SG_Rect "https://github.com/trisycl/path_tracer/blob/main/include/rectangle.hpp"
    click SG_ConstMed "https://github.com/trisycl/path_tracer/blob/main/include/constant_medium.hpp"
    click SG_Material "https://github.com/trisycl/path_tracer/blob/main/include/material.hpp"
    click SG_Texture "https://github.com/trisycl/path_tracer/blob/main/include/texture.hpp"
    click HA_Dispatch "https://github.com/trisycl/path_tracer/blob/main/include/visit.hpp"
    click RV_Ray "https://github.com/trisycl/path_tracer/blob/main/include/ray.hpp"
    click RV_Vec "https://github.com/trisycl/path_tracer/blob/main/include/vec.hpp"
    click RV_RTWeek "https://github.com/trisycl/path_tracer/blob/main/include/rtweekend.hpp"
    click RV_Xor "https://github.com/trisycl/path_tracer/blob/main/include/xorshift.hpp"
    click Camera "https://github.com/trisycl/path_tracer/blob/main/include/camera.hpp"
    click BuildParams "https://github.com/trisycl/path_tracer/blob/main/include/build_parameters.hpp"
    click SYCL_RT "https://github.com/trisycl/path_tracer/blob/main/include/sycl.hpp"
    click Kernels "https://github.com/trisycl/path_tracer/blob/main/include/render.hpp"
    click Doc "https://github.com/trisycl/path_tracer/tree/main/doc/"
    click Images "https://github.com/trisycl/path_tracer/tree/main/images/"

    %% Styles
    classDef build fill:#AED6F1,stroke:#21618C,color:#1B2631
    classDef host fill:#ABEBC6,stroke:#196F3D,color:#1B2631
    classDef device fill:#F5B041,stroke:#B9770E,color:#1B2631
    classDef ext fill:#D5D8DC,stroke:#566573,color:#1B2631
```
