RTX Neural Texture Compression (NTC) SDK

repository·main·Indexed 20 days ago

https://github.com/nvidia-rtx/rtxntc

An SDK for compressing multiple PBR texture channels into a single neural-encoded bundle to reduce disk and VRAM footprints. It features real-time decompression via small neural networks with three modes: Inference on Sample, Inference on Load, and Inference on Feedback. The SDK includes LibNTC, ntc-cli, NTC Explorer, and NTC Renderer, and supports acceleration via Cooperative Vector extensions for Vulkan and Direct3D 12 on Ada- and Blackwell-class GPUs.

Tokens
24K
Snippets
39
Records
95
Agent score
68%

What's inside RTX Neural Texture Compression (NTC)

  1. What is Inference on Sample and when to use it

    main

    Inference on Sample is a mode where NTC decompression logic is executed directly within a pixel or ray tracing shader to decompress only the specific texels needed for a view.

    Key Characteristics:

    • Performance: Decompressing texels is computationally expensive compared to regular sampling. It returns one unfiltered texel with all material channels at a time.
    • Hardware Requirements: It should ideally be used on high-performance GPUs supporting Cooperative Vector (CoopVec) extensions. While a DP4a fallback exists, it is significantly slower and intended only for functional validation.
    • Filtering: Because simulating trilinear or anisotropic filtering is prohibitively expensive, Inference on Sample should be used in conjunction with Stochastic Texture Filtering (STF), followed by denoising or DLSS after shading.
  2. How MIP chain compression works in NTC

    main

    NTC can compress full MIP chains (from highest LOD down to 1x1).

    To achieve this, texture MIP levels are grouped into sets of 2-4 levels. Each group is compressed into a pair of latent tensors (one high-res and one low-res).

    Note on quality: Due to grouping and sampling, compression quality may vary across MIP levels. This difference is most noticeable in LODs 3 and above, while high-detail levels remain largely unaffected.

  3. Decompress GDeflate-compressed latent data

    main

    NTC files may use GDeflate lossless compression for latent data. You can decompress this data using one of three methods:

    1. GPU Decompression (Vulkan): Use IContext::DecompressGDeflateOnVulkanGPU(...) which utilizes the VK_NV_memory_decompression extension. The application must still manage data uploads and memory.
    2. DirectStorage: Consume the compressed buffers directly using the DSTORAGE_COMPRESSION_FORMAT_GDEFLATE format. This requires implementing the DirectStorage API calls on the application side.
    3. CPU Decompression: Use IContext::DecompressBuffer(...). This is the simplest method but the slowest.

    Note: GDeflate compression is optional and can be configured via ITextureSet::ConfigureLosslessCompression(...) or the --gdeflate <option> flag in ntc-cli.

  4. Manage MIP chains in ntc-cli

    main

    MIP chains can be handled in three ways:

    1. Loading from directory: When using --loadImages and --loadMips, the tool scans for a mips/ subdirectory next to the base textures. It expects files named <base-name>.<mip>.png (e.g., albedo.01.png for MIP 1).
    2. Loading from manifest: Exact file names for MIP levels can be specified within the JSON manifest.
    3. Generating Mips: Using --generateMips automatically creates MIP levels 1 and above from mip 0 before compression. If --saveMips is also used, these generated levels are saved using the same directory layout described in point 1.
    # Example directory structure for --loadMips
    material-name/
        albedo.png # MIP 0
        normal.png
        mips/
            albedo.01.png
            normal.01.png
            albedo.02.png
            normal.02.png
  5. Configure NTC compression quality and bitrate

    main

    NTC acts as an adjustable quality/constant bitrate lossy compression scheme. The per-texel memory footprint is determined by the Latent Shape, which is a composite of:

    • The number of high- and low-resolution latent channels.
    • The bit-depth of those channels.
    • The scale factor between them.

    To achieve a specific bitrate, you must select a compatible Latent Shape. For an approximate constant quality/variable bitrate approach, you can perform pre-analysis of the texture bundle to determine the required formats. See the Settings and Quality Guide for detailed configuration.

  6. Understand the NTC Texture Set File Container Format

    main

    The NTC container format is a binary format modeled after GLB (Binary GLTF). It stores data in little-endian format and consists of a file header followed by two primary chunks: a JSON descriptor and a binary data chunk.

    File Header Structure

    • Signature: 4 bytes, NTEX
    • Container version: 4 bytes (Current: 0x100)
    • JSON chunk offset: 8 bytes
    • JSON chunk size: 8 bytes
    • Data chunk offset: 8 bytes
    • Data chunk size: 8 bytes

    Key Constraints

    • Alignment: Chunk offsets and sizes must be multiples of 4 bytes to ensure efficient access (especially for GPU memory loading). If data is not a multiple of 4 bytes, it must be padded with zeros.
    • Indexing: The JSON descriptor uses offsets relative to the start of the binary data chunk to locate specific data segments.
  7. Understand NTC compression quality metrics (PSNR)

    main

    Image quality is reported as Peak Signal-to-Noise Ratio (PSNR) in decibels (dB).

    • 35-40 dB: Generally considered sufficient for most uses.
    • 50 dB: Perceptually lossless.

    Note that for HDR images (EXR), PSNR values are not correctly normalized and should only be compared against other runs of the same type, not against other image comparison methods.

  8. Configure HDR image compression

    main

    NTC supports High Dynamic Range (HDR) images (more than 8 bits per channel, values > 1.0).

    To ensure compatibility with the neural decoder, the library automatically converts HDR images to the Hybrid Log-Gamma (HLG) color space before compression and linearizes them after decompression. This is enabled automatically in the CLI for all .exr images.

    Consequences of HLG conversion:

    1. Channel values with high magnitude are represented with lower accuracy.
    2. Reported PSNR values for HDR images are not correctly normalized for comparison with standard SDR methods.
  9. NTC Manifest File Format Overview

    main

    NTC manifest files use the JSON format to define a texture set. The root object specifies the textures to be included and can optionally define custom dimensions for the resulting texture set.

    Root Document Fields

    Field NameTypeDefaultDescription
    texturesarray of ManifestEntry(required)List of textures to include in the texture set
    widthintderivedCustom width for the texture set
    heightintderivedCustom height for the texture set
  10. How Inference on Feedback mode works

    main

    Inference on Feedback is a streaming virtual texturing system implemented in the Renderer for Windows/DX12. It uses Sampler Feedback to decompress only the necessary texture tiles (up to 512x512) and encode them into BCn on demand.

    Workflow:

    1. Data Loading: NtcMaterialLoader loads NTC texture sets into VRAM and prepares temporary textures for tile decompression.
    2. Feedback Recording: During rendering, the NtcForwardShadingPass uses a specialized pixel shader (ForwardShadingPassFeedback.hlsl) that samples material textures. If a tile is unmapped, it falls back to coarser mip levels. The shader records accessed texels into a FeedbackTexture (sampler feedback resource).
    3. Tile Management: The FeedbackManager (relying on RTXTS-TTM) reads the sampler feedback to identify which tiles need mapping.
    4. On-Demand Transcoding: The NtcSceneRenderer triggers the NtcMaterialLoader to decompress the requested tiles from NTC into color textures and then encode them into BCn, storing them in the newly mapped tiles.

    Benefits: This mode can achieve up to 6x memory savings compared to fully mapped BCn textures, even when including the resident NTC texture sets.

  11. How Neural Texture Compression (NTC) works

    main

    Neural Texture Compression (NTC) is an algorithm that compresses multiple PBR texture channels (up to 16) into a single NTC texture set. It works by transforming original texture data into a combination of weights for a small neural network (the decoder) and a tensor of latents/features.

    During rendering, the decoder is sampled and run through the network to reconstruct texture colors. This process is fast enough for use in shaders like base pass pixel shaders or ray tracing hit shaders.

    Decompression Modes

    • Inference on Sample: Decompresses texels directly in the shader. This has the smallest VRAM footprint but requires real-time inference.
    • Inference on Load: Decompresses NTC textures when a game or map is loaded and transcodes them into block-compressed formats (BCn). This reduces disk/PCI-E traffic but increases VRAM usage to match standard BCn textures.
    • Inference on Feedback: An advanced mode using Sampler Feedback to identify specific texture tiles needed for the current view, decompressing only those tiles into a sparse tiled texture as BCn.
  12. Use the Pixel Inspector to analyze raw texture values

    main

    The Pixel Inspector (located in the top-right of the UI) allows for precise per-pixel analysis. It displays the raw RGBA values for the pixel currently under the mouse pointer for both the left and right image slots, regardless of whether you are in 2D or 3D view mode.

    Value Formats:

    • If the active image uses the UNORM8 pixel format, values are displayed as integers.
    • For all other pixel formats, values are displayed as floating-point numbers.