1 //
2 // Copyright 2016 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 // Helper routines for the D3D11 texture format table.
7 
8 #ifndef LIBANGLE_RENDERER_D3D_D3D11_TEXTURE_FORMAT_TABLE_UTILS_H_
9 #define LIBANGLE_RENDERER_D3D_D3D11_TEXTURE_FORMAT_TABLE_UTILS_H_
10 
11 #include "libANGLE/renderer/d3d/d3d11/Renderer11.h"
12 
13 namespace rx
14 {
15 
16 namespace d3d11
17 {
18 
19 using FormatSupportFunction = bool (*)(const Renderer11DeviceCaps &);
20 
OnlyFL10Plus(const Renderer11DeviceCaps & deviceCaps)21 inline bool OnlyFL10Plus(const Renderer11DeviceCaps &deviceCaps)
22 {
23     return (deviceCaps.featureLevel >= D3D_FEATURE_LEVEL_10_0);
24 }
25 
OnlyFL9_3(const Renderer11DeviceCaps & deviceCaps)26 inline bool OnlyFL9_3(const Renderer11DeviceCaps &deviceCaps)
27 {
28     return (deviceCaps.featureLevel == D3D_FEATURE_LEVEL_9_3);
29 }
30 
SupportsFormat(DXGI_FORMAT format,const Renderer11DeviceCaps & deviceCaps)31 inline bool SupportsFormat(DXGI_FORMAT format, const Renderer11DeviceCaps &deviceCaps)
32 {
33     // Must support texture, SRV and RTV support
34     UINT mustSupport = D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURECUBE |
35                        D3D11_FORMAT_SUPPORT_SHADER_SAMPLE | D3D11_FORMAT_SUPPORT_MIP |
36                        D3D11_FORMAT_SUPPORT_RENDER_TARGET;
37     UINT minimumRequiredSamples = 0;
38 
39     if (d3d11_gl::GetMaximumClientVersion(deviceCaps.featureLevel).major > 2)
40     {
41         mustSupport |= D3D11_FORMAT_SUPPORT_TEXTURE3D;
42 
43         // RGBA4, RGB5A1 and RGB565 are all required multisampled renderbuffer formats in ES3 and
44         // need to support a minimum of 4 samples.
45         minimumRequiredSamples = 4;
46     }
47 
48     bool fullSupport = false;
49     if (format == DXGI_FORMAT_B5G6R5_UNORM)
50     {
51         // All hardware that supports DXGI_FORMAT_B5G6R5_UNORM should support autogen mipmaps, but
52         // check anyway.
53         mustSupport |= D3D11_FORMAT_SUPPORT_MIP_AUTOGEN;
54         fullSupport = ((deviceCaps.B5G6R5support & mustSupport) == mustSupport) &&
55                       deviceCaps.B5G6R5maxSamples >= minimumRequiredSamples;
56     }
57     else if (format == DXGI_FORMAT_B4G4R4A4_UNORM)
58     {
59         fullSupport = ((deviceCaps.B4G4R4A4support & mustSupport) == mustSupport) &&
60                       deviceCaps.B4G4R4A4maxSamples >= minimumRequiredSamples;
61     }
62     else if (format == DXGI_FORMAT_B5G5R5A1_UNORM)
63     {
64         fullSupport = ((deviceCaps.B5G5R5A1support & mustSupport) == mustSupport) &&
65                       deviceCaps.B5G5R5A1maxSamples >= minimumRequiredSamples;
66     }
67     else
68     {
69         UNREACHABLE();
70         return false;
71     }
72 
73     // This means that ANGLE would like to use the entry in the map if the inputted DXGI format
74     // *IS* supported.
75     // e.g. the entry might map GL_RGB5_A1 to DXGI_FORMAT_B5G5R5A1, which should only be used if
76     // DXGI_FORMAT_B5G5R5A1 is supported.
77     // In this case, we should only return 'true' if the format *IS* supported.
78     return fullSupport;
79 }
80 
81 }  // namespace d3d11
82 
83 }  // namespace rx
84 
85 #endif  // LIBANGLE_RENDERER_D3D_D3D11_TEXTURE_FORMAT_TABLE_UTILS_H_
86