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 
OnlyFL11_1Plus(const Renderer11DeviceCaps & deviceCaps)21 inline bool OnlyFL11_1Plus(const Renderer11DeviceCaps &deviceCaps)
22 {
23     return (deviceCaps.featureLevel >= D3D_FEATURE_LEVEL_11_1);
24 }
25 
OnlyFL10Plus(const Renderer11DeviceCaps & deviceCaps)26 inline bool OnlyFL10Plus(const Renderer11DeviceCaps &deviceCaps)
27 {
28     return (deviceCaps.featureLevel >= D3D_FEATURE_LEVEL_10_0);
29 }
30 
OnlyFL9_3(const Renderer11DeviceCaps & deviceCaps)31 inline bool OnlyFL9_3(const Renderer11DeviceCaps &deviceCaps)
32 {
33     return (deviceCaps.featureLevel == D3D_FEATURE_LEVEL_9_3);
34 }
35 
SupportsFormat(DXGI_FORMAT format,const Renderer11DeviceCaps & deviceCaps)36 inline bool SupportsFormat(DXGI_FORMAT format, const Renderer11DeviceCaps &deviceCaps)
37 {
38     // Must support texture, SRV and RTV support
39     UINT mustSupport = D3D11_FORMAT_SUPPORT_TEXTURE2D | D3D11_FORMAT_SUPPORT_TEXTURECUBE |
40                        D3D11_FORMAT_SUPPORT_SHADER_SAMPLE | D3D11_FORMAT_SUPPORT_MIP |
41                        D3D11_FORMAT_SUPPORT_RENDER_TARGET;
42     UINT minimumRequiredSamples = 0;
43 
44     if (d3d11_gl::GetMaximumClientVersion(deviceCaps).major > 2)
45     {
46         mustSupport |= D3D11_FORMAT_SUPPORT_TEXTURE3D;
47 
48         // RGBA4, RGB5A1 and RGB565 are all required multisampled renderbuffer formats in ES3 and
49         // need to support a minimum of 4 samples.
50         minimumRequiredSamples = 4;
51     }
52 
53     bool fullSupport = false;
54     if (format == DXGI_FORMAT_B5G6R5_UNORM)
55     {
56         // All hardware that supports DXGI_FORMAT_B5G6R5_UNORM should support autogen mipmaps, but
57         // check anyway.
58         mustSupport |= D3D11_FORMAT_SUPPORT_MIP_AUTOGEN;
59         fullSupport = ((deviceCaps.B5G6R5support & mustSupport) == mustSupport) &&
60                       deviceCaps.B5G6R5maxSamples >= minimumRequiredSamples;
61     }
62     else if (format == DXGI_FORMAT_B4G4R4A4_UNORM)
63     {
64         fullSupport = ((deviceCaps.B4G4R4A4support & mustSupport) == mustSupport) &&
65                       deviceCaps.B4G4R4A4maxSamples >= minimumRequiredSamples;
66     }
67     else if (format == DXGI_FORMAT_B5G5R5A1_UNORM)
68     {
69         fullSupport = ((deviceCaps.B5G5R5A1support & mustSupport) == mustSupport) &&
70                       deviceCaps.B5G5R5A1maxSamples >= minimumRequiredSamples;
71     }
72     else
73     {
74         UNREACHABLE();
75         return false;
76     }
77 
78     // This means that ANGLE would like to use the entry in the map if the inputted DXGI format
79     // *IS* supported.
80     // e.g. the entry might map GL_RGB5_A1 to DXGI_FORMAT_B5G5R5A1, which should only be used if
81     // DXGI_FORMAT_B5G5R5A1 is supported.
82     // In this case, we should only return 'true' if the format *IS* supported.
83     return fullSupport;
84 }
85 
86 }  // namespace d3d11
87 
88 }  // namespace rx
89 
90 #endif  // LIBANGLE_RENDERER_D3D_D3D11_TEXTURE_FORMAT_TABLE_UTILS_H_
91