BC6HBC7EncoderDecoder Sample Update

Direct3D 11 class hardware through the Direct3D 11 API supports two new texture compression formats: BC6H and BC7. These new Block Compressed formats provide excellent compression for High-Dynamic Range (HDR) images and higher-fidelity traditional content. The D3DX11 library includes a software implementation of the encoder, but the new BC formats are extremely asymmetric meaning the encoding algorithm has a very large search space to determine the optimal compression for each 4×4 block. This makes a great candidate for a GPGPU DirectCompute implementation of the compression algorithm. The BC6HBC7EncoderDecoder11 sample in the DirectX SDK provides such an implementation using DirectCompute 4.0.

Attached to this post is a ZIP containing an updated copy of the C++ source files and the two HLSL shaders for encoding which you can drop into the BC6HBC7EncoderDecoder11 sample code in the DirectX SDK (June 2010). This update enables support for HD Photo source images which makes a great source for HDR content (D3DX11 supports the HD Photo file format, but COM must be explicitly initialized for it to work properly), as well as a work-around for an HLSL compiler bug with the June 2010 release that affected encoding in some cases. There are also a few minor cleanups and a diagnostic message to highlight that the source image must have dimensions that are a multiple of 4 for the encoder to succeed (this is a requirement for all the BC formats).

For more information on BC6H and BC7 texture compression, see the Gamefest 2010 talk Block Compression Smorgasbord (US). Remember that DDS files containing BC6H and BC7 content are stored using the ‘DX10’ header extension, which is not widely supported by existing tools

Update: Note that full documentation on the BC6H and BC7 formats is now available on MSDN. The source to the D3DX11 software compressor and decompressor has been incorporated into the DirectXTex library as well.

Note: The latest version of this code is now available on MSDN Code Gallery.

DirectXTex: The DirectCompute BC6H and BC7 compressors are now integrated into DirectXTex.

Comments (9)

  1. Dana says:


    Thank you for the update; the original BC6HBC7EncoderDecoder sample crashed with no error messages – this version works.

    I still have a few issues with the compressor:

    1. The mipmaps don't seem to work. If the input file contains mimpaps, the compressed/decompressed file only contains the top-level image.

    2. BC6 works in both CPU and GPU modes. However, BC7 crashes my GPU. It does work in CPU mode. My GPU is quite recent, so this is surprising (Intel i7 CPU, M620  2.6GHz).



  2. Dana says:

    Hello again,

    Correction to my previous post: my GPU is NVIDIA NVS 3100M (supports ComputeShader).

    Additional question: The BC7 code in this example hardcodes the DXGI_FORMAT_BC7_UNORM sub-format:

    V_RETURN( g_GPUBC7Encoder.GPU_BC7EncodeAndSave( pSourceTexture, DXGI_FORMAT_BC7_UNORM, &fname[0] ) );

    There does not seem to be any options/handing of the DXGI_FORMAT_BC7_UNORM_SRGB code, which ths BC7 compressor needs to support as well. Will there be an additional update for this?



  3. The lack of support for mipmap generation is a known issue. I noted the lack of a command-line option for outputing BC7_SRGB instead of BC7. The support code should handle either, so it's a simple matter of modifying the command-line processing.

  4. As for the BC7 crash on your hardware, that is likely a driver issue. You should contact NVIDIA and see if they have a newer driver. The NVIDIA NVS 3100M is a 'business-class' GPU which means drivers tend to be updated far less often than 'consumer-class' GPUs. The sample requires DirectCompute (CS) 4.1, so it should technically work on that card.

  5. Dana says:

    Hi Chuck,

    Thanks a lot for your answers.

    Do you know if mipmaps will be supported in a future release? If not, are there commercial tools that provide BC6/7 compression with mipmaps?

    There is an additional issue with the HLSL code. For BC6, the images generated by /cpu mode do not match those generated by the GPU. When decompressed, cpu mode correctly decompresses cpu-compressed images and gpu mode correctly decompresses gpu-encoded images. However, mixming compressor and decompressor types produces artifacts.

    It seems to me that the CPU mode one is correct since this one is compatible with the Reference Rasterizer code (bcunit.cpp).



  6. Dana says:

    FYI: I updated my driver and indeed the BC7 gpu version compressor works now.

    However, there is the same issue as the one above: the GPU generated file is not the same as the CPU generated one.



  7. I wouldn't expect the CPU and GPU compressors to produce identical results, but they should appear the same decompressed (within some error tolerance).

  8. At the moment mipmaps are 'left as an excercise to the reader' unfortunately. Note that the DirectXTex sample <blogs.msdn.com/…/directxtex.aspx> includes code for generating mipmaps as well as doing software compression–it's a shared source version of the same code inside D3DX11 which is what BC6HBC7EncoderDecoder is using for the '/cpu' option.

  9. Dana says:

    Hi Chuck,

    Re: they should appear the same decompressed

    Decompressing with bcunit.cpp (from the Reference Rasterizer) seems to produce (visually) correct results for BC7, weather the original texture was compressed in CPU or GPU mode.

    However, decompressing with bcunit.cpp provides (visually) correct results for BC6 CPU compressed texture, and many artifacts for BC6 GPU compressed texture. So my guess is there may be an issue in the BC6 HLSL.