How nvidia-rtx/rtxntc-library works
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.