# gameknife/gknextrenderer architecture

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

- Interactive diagram: https://gitdiagram.com/gameknife/gknextrenderer
- Repository: https://github.com/gameknife/gknextrenderer

## Overview

##### Main Components
- Core Rendering Engine: Representing the heart of the project, which includes multiple rendering techniques. There are modules for:
- Real-time path tracing (ground truth techniques)
- Various deferred rendering pipelines (Legacy, Modern, and Hybrid Deferred, as seen in the Vulkan subdirectories)
- Ray tracing modules (Bottom and Top Level Acceleration Structures, RayQuery, Shader Binding Table)
- Scene and Asset Management: Modules include handling of GLTF scenes, materials, models, textures, and procedural assets (found in src/Assets, src/Runtime/SceneList, etc.).
- Editor Component: A separate subproject (gkNextEditor) using ImGui; this is used to edit scenes and materials (node-based material editor with Editor/Nodes).
- Benchmark Module: Implements specialized benchmarking for both static and dynamic scenes (gkNextBenchmark under src/Application).
- MagicaLego: A game-like subproject to validate real-time rendering techniques with interactive gameplay.
- Packager: Handles asset packaging into pkg files for deployment.
- Platform Adaptation: Specific code and build configuration for various platforms such as Android, Windows, Linux, and macOS (evidenced by dedicated folders like android and platform-specific build scripts).

##### Relationships and Interactions
- Data Flow: Assets and scene data are loaded, managed, and passed to the rendering engine. The engine interacts with Vulkan’s API (modules in src/Vulkan) to process shaders, compute pipelines, and perform rendering.
- Editor Integration: The editor serves as an interface on top of the core engine, allowing scene modifications, material adjustments, and other configurations. This component communicates with the scene and rendering components.
- Subsystem Dependencies: Benchmarking tools make calls to the renderer to evaluate performance, while the packager collects resources from assets and source directories for quick deployment.
- Cross-platform Build/Deployment: Build scripts (e.g., build_windows.bat, build_linux.sh, etc.) and CI workflows (in .github/workflows) indicate reliance on external services and continuous integration for delivering builds on all supported platforms.

##### Architectural Patterns and Design Principles
- Modular Architecture: Separate modules for rendering, asset management, editor, and benchmarking facilitate isolation and reusability.
- Cross-platform Layering: The use of platform-specific source files (e.g., PlatformAndroid.h, PlatformWindows.h) suggests a clean abstraction layer to encapsulate system-specific logic.
- Data-driven Pipeline: Use of GLTF support and shader management shows an architecture that emphasizes flexibility in asset loading and rendering configuration.
- Modern C++ Practices: The project leverages new C++ standards and multithreading (Async Resource Loading, TaskDispatcher) to maximize performance.

##### Relevant Technologies and Frameworks
- Vulkan SDK for rendering.
- vcpkg package manager for dependency management.
- ImGui for the editor UI.
- Various libraries included under ThirdParty (e.g., OpenImageDenoise, quickjs-ng, miniaudio).
- Build systems and scripts based on CMake and platform-specific batch/shell scripts.
- Android build integration and Gradle for mobile deployment.

##### Final Advice
- Be detailed – break the project into as many coherent components as possible.
- Capturing essential elements: the interactivity of the editor with the engine, the complexity of multiple rendering pipelines, and the unified asset/scene management core.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Rendering Engine Layer
    subgraph "Rendering Engine Layer"
        A["Core Rendering Engine"]:::engine
        B["Real-time Path Tracing & Ray Tracing Modules"]:::modules
        subgraph "Deferred Rendering Pipelines"
            D["Legacy Deferred"]:::pipeline
            E["Modern Deferred"]:::pipeline
            F["Hybrid Deferred"]:::pipeline
        end
    end

    %% Application Services Layer
    subgraph "Application Services Layer"
        G["Scene & Asset Management"]:::service
    end

    %% Frontend & Tools
    subgraph "Frontend & Tools"
        H["Editor Component (ImGui-based)"]:::frontend
        I["Benchmark Module"]:::benchmark
        J["MagicaLego Game Instance"]:::frontend
        K["Packager"]:::frontend
    end

    %% Platform & Build
    subgraph "Platform & Build"
        L["Platform Adaptation"]:::platform
        N["Android Integration"]:::platform
        M["Build/CI Integration"]:::build
    end

    %% Connections
    G -->|"asset_to_engine"| A
    A -->|"ray_tracing"| B
    A -->|"legacy_deferred"| D
    A -->|"modern_deferred"| E
    A -->|"hybrid_deferred"| F
    H -->|"editor_control"| A
    I -->|"benchmark_calls"| A
    J -->|"game_engine_access"| A
    K -->|"packages_from"| G
    A -->|"platform_calls"| L
    L -->|"android_support"| N
    A -->|"build_ops"| M
    L -->|"ci_cd"| M

    %% Click Events
    click A "https://github.com/gameknife/gknextrenderer/blob/main/src/Application/gkNextRenderer/gkNextRenderer.cpp"
    click B "https://github.com/gameknife/gknextrenderer/tree/main/src/Vulkan/RayTracing/"
    click D "https://github.com/gameknife/gknextrenderer/tree/main/src/Vulkan/LegacyDeferred/"
    click E "https://github.com/gameknife/gknextrenderer/tree/main/src/Vulkan/ModernDeferred/"
    click F "https://github.com/gameknife/gknextrenderer/tree/main/src/Vulkan/HybridDeferred/"
    click G "https://github.com/gameknife/gknextrenderer/tree/main/src/Assets/"
    click H "https://github.com/gameknife/gknextrenderer/tree/main/src/Editor/"
    click I "https://github.com/gameknife/gknextrenderer/tree/main/src/Application/gkNextBenchmark/"
    click J "https://github.com/gameknife/gknextrenderer/tree/main/src/MagicaLego/"
    click K "https://github.com/gameknife/gknextrenderer/tree/main/src/Packager/"
    click L "https://github.com/gameknife/gknextrenderer/tree/main/src/Runtime/Platform/"
    click N "https://github.com/gameknife/gknextrenderer/tree/main/android/app/"

    %% Styles
    classDef engine fill:#f9c,stroke:#333,stroke-width:2px;
    classDef modules fill:#ccf,stroke:#333,stroke-width:2px;
    classDef pipeline fill:#cfc,stroke:#333,stroke-width:2px;
    classDef service fill:#fcf,stroke:#333,stroke-width:2px;
    classDef frontend fill:#cff,stroke:#333,stroke-width:2px;
    classDef benchmark fill:#ffc,stroke:#333,stroke-width:2px;
    classDef platform fill:#efe,stroke:#333,stroke-width:2px;
    classDef build fill:#fee,stroke:#333,stroke-width:2px;
```
