DirectXTex


As part of my Gamefest 2011 presentation Modern Texture Content Pipelines (US / UK), I demonstrated the “DirectXTex” library which is a shared source implementation of DDS file I/O (including the “DX10” header extension), texture content processing operations (resize, format conversion, mip-map-generation), software block compression (BC1 – BC7), height-map to normal-map conversion, and a simple .TGA file reader and writer.

The attached package includes:

  • The DirectXTex library
  • Texconv, a sample using DirectXTex that is a command-line tool replacement for the DirectX SDK Texture Conversion Tool (Extended)
  • DDSView, a simple DDS viewer sample using DirectXTex
  • DDSTextureLoader, a light-weight DDS loader for DirectX 11 applications
  • WICTextureLoader, a WIC-based image loader for creating simple 2D textures with auto-gen mipmaps for DirectX 11 applications
  • ScreenGrab, a light-weight screen shot saver for DirectX 11 applications
  • A copy of XNAMath 2.04, which is required to build the DirectXTex library with VS 2010

See the ReadMe.txt file in the package for more details.

Platforms: The code is designed to build with the Windows 8.x SDK using Visual Studio 2010, 2012, or 2013 and works on Windows Vista, Windows 7, Windows 8.x Win32 desktop, Windows Store apps, Windows phone 8.1, and Xbox One.

Note: DDSTextureLoader, WICTextureLoader, and ScreenGrab are also provided in the DirectX Tool Kit

Porting Notes

Here’s a handy table of equivalents for D3DX (see Living without D3DX for a complete listing):

D3DX11ComputeNormalMap

ComputeNormalMap

D3DX11CreateShaderResourceViewFromFile

LoadFromXXXFile, CreateShaderResourceView

-or-

CreateXXXTextureFromFile

D3DX11CreateShaderResourceViewFromResource
D3DX11CreateShaderResourceViewFromMemory

LoadFromXXXMemory, CreateShaderResourceView

-or-

CreateXXXTextureFromMemory

D3DX11CreateTextureFromFile

LoadFromXXXFile, CreateTexture

-or-

CreateXXXTextureFromFile

D3DX11CreateTextureFromResource
D3DX11CreateTextureFromMemory

LoadFromXXXMemory, CreateTexture

-or-

CreateXXXTextureFromMemory

D3DX11FilterTexture

GenerateMipMaps, GenerateMipMaps3D

D3DX11GetImageInfoFromFile

GetMetadataFromXXXFile

D3DX11GetImageInfoFromResource
D3DX11GetImageInfoFromMemory

GetMetadataFromXXXMemory

D3DX11LoadTextureFromTexture

Resize, Convert, Compress, Decompress, and/or CopyRectangle

D3DX11SaveTextureToFile

CaptureTexture, SaveToXXXFile

-or-

SaveXXXTextureToFile

D3DX11SaveTextureToMemory

CaptureTexture, SaveToXXXMemory

Where XXX is “DDS” for working with .DDS files, “WIC” for working with WIC-supported bitmap image formats such as .BMP, .JPG, .PNG, etc. or “TGA” for working with Targa Truvision files. Note that .TGA is supported by legacy D3DX and by DirectXTex, but not by WICTextureLoader or DirectXTK.

Note

There is another version of the Texconv sample with the DirectXTex library that uses DirectXMath with DXGI 1.2 support available on the Windows SDK Samples Code Gallery. It can be built using either Visual Studio 2012 or VS 2010 with the new Windows SDK. There is also a Windows Store app (a.k.a. Metro style app) version of the DDSTextureLoader there as well. The Windows SDK Samples Code Gallery version of DirectXTex can be made to run on Windows Vista and WIndows 7 by adding _WIN32_WINNT=0x0600 to the Preprocessor Definitions.

Update: DirectXTex is now hosted on CodePlex and GitHub. The latest version of the library, documentation, notes on future work, release history, and other information is now available there.

Related: DirectX Tool Kit, DirectXMesh

Comments (3)

  1. Nate says:

    This is awesome!  Any chance you can make a WinRT component project exposing it to C# devlopers?

  2. Oscar says:

    Hello Chuck,

    I'm trying to run the DirectX SDK HDRFormats10 sample using DirectX 11.

    I'm having problems with the following code in the OnD3D10CreateDevice function:

    D3DX10_IMAGE_LOAD_INFO LoadInfo;

    LoadInfo.Format = g_EncodingFormats[i];

    hr = D3DX10CreateShaderResourceViewFromFile( pd3dDevice, strPath, &LoadInfo, NULL, &pCubeRV, NULL );

    The dds file passed to this function is uffizi_cross.dds

    To check the description of the shader resource view I call the following:

    D3D10_SHADER_RESOURCE_VIEW_DESC desc;

    ZeroMemory(&desc, sizeof(D3D10_SHADER_RESOURCE_VIEW_DESC));

    pCubeRV->GetDesc(&desc);

    I'm having problems when the format is DXGI_FORMAT_R11G11B10_FLOAT.

    The desc structure has the following values:

    Format = DXGI_FORMAT_R11G11B10_FLOAT

    View Dimension = D3D_SRV_DIMENSION_TEXTURECUBE

    TextureCube.MostDetailedMip = 0

    TextureCube.MipLevels = 10

    To get a similar resource view in DirecX 11 I call the following:

    ScratchImage image;

    TexMetadata metadata;

    hr = LoadFromDDSFile(pSrcFile, 0, &metadata, image);

    Then I call the GenerateMipMaps function:

    ScratchImage mipChain;

    hr = GenerateMipMaps(image.GetImages(), imagePtr.GetImageCount(), imagePtr.GetMetadata(), 0, 10, mipChain);

    Then I call the Convert function:

    ScratchImage convimage;

    hr = Convert(mipChain.GetImages(), mipChain.GetImageCount(), mipChain.GetMetadata(), DXGI_FORMAT_R11G11B10_FLOAT, 0, 1.0f, convimage);

    Then I call the CreateTexture function:

    ID3D11Resource *pResource;

    hr = CreateTexture(pDevice, convimage.GetImages(), convimage.GetImageCount(), convimage.GetMetadata(), &pResource);

    Then I call the CreateShaderResourceView function:

    D3D11_SHADER_RESOURCE_VIEW_DESC DescRV;

    memset(&DescRV, 0, sizeof(D3D11_SHADER_RESOURCE_VIEW_DESC));

    DescRV.Format = DXGI_FORMAT_R11G11B10_FLOAT;

    DescRV.Texture2D.MipLevels = 10;

    DescRV.Texture2D.MostDetailedMip = 0;

    DescRV.ViewDimension = D3D11_SRV_DIMENSION_TEXTURECUBE;

    hr = pDevice->CreateShaderResourceView(pResource, &DescRV, &pCubeRV);

    When rendering, the texture looks different than the original example.

    I accessed the bytes to compare the first pixels against the original sample, they have different values.

    I wonder if you know of differences between the Convert function and the way the D3DX10CreateShaderResourceViewFromFile does the convertion?

    Do you think there is an mistake in my code?

    I'd appreciate any advice.

    Thanks,

    Oscar

  3. Oscar says:

    Hello Chuck

    I think I found the problem, when generating the mipmaps I have to specify the TEX_FILTER_CUBIC filter.

    Thanks,

    Oscar