# nvidia-rtx/rtxntc-library architecture

> Architecture diagram of the GitHub repository nvidia-rtx/rtxntc-library, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nvidia-rtx/rtxntc-library
- Repository: https://github.com/nvidia-rtx/rtxntc-library

## Overview

##### Project Type and Purpose
- LibNTC is a specialized library designed for neural texture compression. It’s intended to be built independently or integrated into larger projects (such as the full RTXNTC SDK).
- Its functionality centers around compression/decompression using CUDA kernels, GPU shader processing (DX12/Vulkan), and an internal Tiny Inline Networks (TIN) component for neural networks.
- The library supports different GPU processing environments and uses prebuilt shader binaries and external compilers (DXC, Slang), making it a multi-modal back-end library that provides advanced GPU-accelerated texture compression.

##### Analyzing the File Structure
- Top Level:
– Build/configuration files (CMakeLists.txt, .gitlab-ci.yml, etc.) indicate a highly configurable build with CMake and continuous integration.
- External Directory:
– Contains third-party dependencies such as:
- dxc: builds of the DirectX Shader Compiler for both Linux and Windows.
- slang: includes binary builds for Slang compiler (with a custom DXC supporting Cooperative Vector support).
- rapidjson and ninja which support JSON parsing and build automation.
- Directory:
– Contains “include/libntc” – the public C++ interface for the library along with shader headers.
- Source (src) Directory:
– Contains core C++ source files and CUDA (.cu) files that implement the actual compression sessions, kernel invocations, error handling, and related algorithms.
– Contains subdirectories for CUDA kernels (src/kernels), prebuilt shaders (src/shaders), and the TIN library (src/tin) that implements the tiny inline neural network functionality.
- Tools:
– The presence of integration and support scripts (e.g., “set_vs_vars.ps1”) used to set up environment variables for builds.

##### Key Components
a. Public Interface:
– Represent “include/libntc” as the API boundary where external projects interact with LibNTC.
b. Core Engine:
– The main internal implementation found in “src”, including:
- Adaptive Compression Session
- Core Context and Resource Management
- CUDA and CPU-based implementations for error processing, graphics resource handling, and data serialization.
c. GPU Acceleration & Shader Modules:
– The CUDA kernels (in “src/kernels”) that perform the heavy compression/decompression calculations.
– The shader modules (in “src/shaders”) that handle tasks such as compressing BCn formats and decompression passes.
d. TIN (Tiny Inline Networks):
– A distinct module (“src/tin”) providing neural network functionality customized for LibNTC.
e. External Dependencies and Tools:
– External binary tools from “external/dxc” and “external/slang” utilized for shader compilation. Also include external libraries like rapidjson.
– Integration with NVIDIA-specific APIs (notably referenced in the licensing and README).

##### Relationships and Interactions
- The Public Interface (API) receives function calls from the integrating application, which trigger operations in the Core Engine.
- Depending on the configuration (via CMake settings such as NTC_WITH_CUDA, NTC_WITH_DX12, NTC_WITH_VULKAN):
– Data flows from the API into specialized compression or decompression pipelines.
– GPU processes are managed through CUDA kernels and shader invocations.
– There is a clear separation where the CPU side manages orchestration and error handling, while the GPU side (CUDA kernels and shader modules) does the heavy lifting.
- The Core Engine relies on external components for shader compilation (DXC/Slang) and uses rapidjson for JSON processing in data serialization/deserialization.

##### Architectural Patterns and Design Principles
- Layered Architecture: Separation from public interface to core processing layers, and further split between CPU orchestration and GPU processing.
- Modularity: Each component (API, core engine, GPU modules, and TIN library) is clearly separated, allowing isolated integration or substitution.
- Configurability: CMake options highlight the importance of build-time switches (e.g., enabling/disabling CUDA/DX12/Vulkan) which should be indicated.
- Dependency Inversion: External dependencies (DXC, Slang, rapidjson) are factored out and should be shown as modules that the core engine depends on.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Nodes
    A["Public API"]:::api
    B["Core Engine"]:::core
    C["CUDA Kernels"]:::gpu
    D["Shader Modules"]:::gpu
    E["TIN Neural Network Module"]:::gpu
    F["DXC Compiler"]:::extern
    G["Slang Compiler"]:::extern
    H["RapidJSON"]:::extern

    %% Relationships
    A -->|"API_call"| B
    B -->|"kernel_invocation"| C
    B -->|"shader_management"| D
    B -->|"nn_processing"| E
    F -->|"shader_compilation"| D
    G -->|"shader_compilation"| D
    H -->|"data_serialization"| B

    %% Click Events
    click A "https://github.com/nvidia-rtx/rtxntc-library/tree/main/include/libntc"
    click B "https://github.com/nvidia-rtx/rtxntc-library/tree/main/src"
    click C "https://github.com/nvidia-rtx/rtxntc-library/tree/main/src/kernels"
    click D "https://github.com/nvidia-rtx/rtxntc-library/tree/main/src/shaders"
    click E "https://github.com/nvidia-rtx/rtxntc-library/tree/main/src/tin"
    click F "https://github.com/nvidia-rtx/rtxntc-library/tree/main/external/dxc"
    click G "https://github.com/nvidia-rtx/rtxntc-library/tree/main/external/slang"
    click H "https://github.com/nvidia-rtx/rtxntc-library/tree/main/external/rapidjson"

    %% Styles
    classDef api fill:#f9c74f,stroke:#333,stroke-width:2px;
    classDef core fill:#90be6d,stroke:#333,stroke-width:2px;
    classDef gpu fill:#f3722c,stroke:#333,stroke-width:2px;
    classDef extern fill:#577590,stroke:#333,stroke-width:2px;
```
