microsoft / DirectXTK12

The DirectX Tool Kit (aka DirectXTK12) is a collection of helper classes for writing DirectX 12 code in C++
https://walbourn.github.io/directx-tool-kit-for-directx-12/
MIT License
1.47k stars 393 forks source link

GenerateMips missing support for a few formats #53

Closed walbourn closed 5 years ago

walbourn commented 5 years ago

GenerateMips (the DirectCompute implementation of auto-gen mips for DirectX 12) currently supports the following DXGI formats:

    case DXGI_FORMAT_R32G32B32A32_FLOAT:
    case DXGI_FORMAT_R32G32B32A32_UINT:
    case DXGI_FORMAT_R32G32B32A32_SINT:
    case DXGI_FORMAT_R16G16B16A16_FLOAT:
    case DXGI_FORMAT_R16G16B16A16_UINT:
    case DXGI_FORMAT_R16G16B16A16_SINT:
    case DXGI_FORMAT_R8G8B8A8_UNORM:
    case DXGI_FORMAT_R8G8B8A8_UINT:
    case DXGI_FORMAT_R8G8B8A8_SINT:
    case DXGI_FORMAT_R32_FLOAT:
    case DXGI_FORMAT_R32_UINT:
    case DXGI_FORMAT_R32_SINT:
    case DXGI_FORMAT_R16_FLOAT:
    case DXGI_FORMAT_R16_UINT:
    case DXGI_FORMAT_R16_SINT:
    case DXGI_FORMAT_R8_UNORM:
    case DXGI_FORMAT_R8_UINT:
    case DXGI_FORMAT_R8_SINT:
    case DXGI_FORMAT_B8G8R8A8_UNORM:
    case DXGI_FORMAT_B8G8R8X8_UNORM:
    case DXGI_FORMAT_B8G8R8A8_UNORM_SRGB:
    case DXGI_FORMAT_B8G8R8X8_UNORM_SRGB:
    case DXGI_FORMAT_R8G8B8A8_UNORM_SRGB:

This is a lot of formats, but there are a few more formats that were required for DirectX 11 drivers to implement for D3D11_FORMAT_SUPPORT_MIP_AUTOGEN that are missing from this list:

DXGI_FORMAT_R16G16B16A16_UNORM
DXGI_FORMAT_R16G16B16A16_SNORM
DXGI_FORMAT_R32G32_FLOAT
DXGI_FORMAT_R10G10B10A2_UNORM
DXGI_FORMAT_R11G11B10_FLOAT
DXGI_FORMAT_R8G8B8A8_SNORM
DXGI_FORMAT_R16G16_FLOAT
DXGI_FORMAT_R16G16_UNORM 
DXGI_FORMAT_R16G16_SNORM
DXGI_FORMAT_R8G8_UNORM
DXGI_FORMAT_R8G8_SNORM
DXGI_FORMAT_R16_UNORM
DXGI_FORMAT_R16_SNORM 
DXGI_FORMAT_R8_SNORM
DXGI_FORMAT_A8_UNORM
DXGI_FORMAT_B5G6R5_UNORM

And these were optional for DirectX 11 drivers to support for D3D11_FORMAT_SUPPORT_MIP_AUTOGEN:

DXGI_FORMAT_R32G32B32_FLOAT
DXGI_FORMAT_B5G5R5A1_UNORM 
DXGI_FORMAT_B4G4R4A4_UNORM 
walbourn commented 5 years ago

The restrictions in the code are covered in detailed on Microsoft Docs. The original list are the only required UAV typed format supports. Any additional formats would require a specific optional support test for each format.

Technically the code is currently written such that it requires D3D12_FEATURE_DATA_D3D12_OPTIONS.TypedUAVLoadAdditionalFormats. Otherwise only three single-channel formats would be supported.

walbourn commented 5 years ago

Turns out I can easily support most of these on devices that support the matching typed UAV. This approach does not support DXGI_FORMAT_R32G32B32_FLOAT which is never supported as a typed UAV, but otherwise it covers all the cases that could be supported by DX11.

And due to the dependency on D3D12_FEATURE_DATA_D3D12_OPTIONS.TypedUAVLoadAdditionalFormats I can't really avoid the complexity for the feature checking anyhow.

walbourn commented 5 years ago

Fixed in this pull request