xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/d3d/d3d11/texture_format_table.h (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2015 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 // texture_format_table:
7 //   Queries for full textureFormat information based on internalFormat
8 //
9 
10 #ifndef LIBANGLE_RENDERER_D3D_D3D11_TEXTUREFORMATTABLE_H_
11 #define LIBANGLE_RENDERER_D3D_D3D11_TEXTUREFORMATTABLE_H_
12 
13 #include <map>
14 
15 #include "common/angleutils.h"
16 #include "common/platform.h"
17 #include "libANGLE/renderer/Format.h"
18 #include "libANGLE/renderer/d3d/formatutilsD3D.h"
19 #include "libANGLE/renderer/renderer_utils.h"
20 
21 namespace rx
22 {
23 
24 struct Renderer11DeviceCaps;
25 
26 namespace d3d11
27 {
28 
29 // For sized GL internal formats, there are several possible corresponding D3D11 formats depending
30 // on device capabilities.
31 // This structure allows querying for the DXGI texture formats to use for textures, SRVs, RTVs and
32 // DSVs given a GL internal format.
33 struct Format final : private angle::NonCopyable
34 {
35     inline constexpr Format();
36     inline constexpr Format(GLenum internalFormat,
37                             angle::FormatID formatID,
38                             DXGI_FORMAT texFormat,
39                             DXGI_FORMAT srvFormat,
40                             DXGI_FORMAT uavFormat,
41                             DXGI_FORMAT rtvFormat,
42                             DXGI_FORMAT dsvFormat,
43                             DXGI_FORMAT blitSRVFormat,
44                             DXGI_FORMAT stencilSRVFormat,
45                             DXGI_FORMAT linearSRVFormat,
46                             DXGI_FORMAT typelessFormat,
47                             GLenum swizzleFormat,
48                             InitializeTextureDataFunction internalFormatInitializer);
49 
50     static const Format &Get(GLenum internalFormat, const Renderer11DeviceCaps &deviceCaps);
51 
52     const Format &getSwizzleFormat(const Renderer11DeviceCaps &deviceCaps) const;
53     LoadFunctionMap getLoadFunctions() const;
54     const angle::Format &format() const;
55 
56     GLenum internalFormat;
57     angle::FormatID formatID;
58 
59     DXGI_FORMAT texFormat;
60     DXGI_FORMAT srvFormat;
61     DXGI_FORMAT uavFormat;
62     DXGI_FORMAT rtvFormat;
63     DXGI_FORMAT dsvFormat;
64 
65     DXGI_FORMAT blitSRVFormat;
66     DXGI_FORMAT stencilSRVFormat;
67     DXGI_FORMAT linearSRVFormat;
68     DXGI_FORMAT typelessFormat;
69 
70     GLenum swizzleFormat;
71 
72     InitializeTextureDataFunction dataInitializerFunction;
73 };
74 
Format()75 constexpr Format::Format()
76     : internalFormat(GL_NONE),
77       formatID(angle::FormatID::NONE),
78       texFormat(DXGI_FORMAT_UNKNOWN),
79       srvFormat(DXGI_FORMAT_UNKNOWN),
80       uavFormat(DXGI_FORMAT_UNKNOWN),
81       rtvFormat(DXGI_FORMAT_UNKNOWN),
82       dsvFormat(DXGI_FORMAT_UNKNOWN),
83       blitSRVFormat(DXGI_FORMAT_UNKNOWN),
84       stencilSRVFormat(DXGI_FORMAT_UNKNOWN),
85       linearSRVFormat(DXGI_FORMAT_UNKNOWN),
86       typelessFormat(DXGI_FORMAT_UNKNOWN),
87       swizzleFormat(GL_NONE),
88       dataInitializerFunction(nullptr)
89 {}
90 
Format(GLenum internalFormat,angle::FormatID formatID,DXGI_FORMAT texFormat,DXGI_FORMAT srvFormat,DXGI_FORMAT uavFormat,DXGI_FORMAT rtvFormat,DXGI_FORMAT dsvFormat,DXGI_FORMAT blitSRVFormat,DXGI_FORMAT stencilSRVFormat,DXGI_FORMAT linearSRVFormat,DXGI_FORMAT typelessFormat,GLenum swizzleFormat,InitializeTextureDataFunction internalFormatInitializer)91 constexpr Format::Format(GLenum internalFormat,
92                          angle::FormatID formatID,
93                          DXGI_FORMAT texFormat,
94                          DXGI_FORMAT srvFormat,
95                          DXGI_FORMAT uavFormat,
96                          DXGI_FORMAT rtvFormat,
97                          DXGI_FORMAT dsvFormat,
98                          DXGI_FORMAT blitSRVFormat,
99                          DXGI_FORMAT stencilSRVFormat,
100                          DXGI_FORMAT linearSRVFormat,
101                          DXGI_FORMAT typelessFormat,
102                          GLenum swizzleFormat,
103                          InitializeTextureDataFunction internalFormatInitializer)
104     : internalFormat(internalFormat),
105       formatID(formatID),
106       texFormat(texFormat),
107       srvFormat(srvFormat),
108       uavFormat(uavFormat),
109       rtvFormat(rtvFormat),
110       dsvFormat(dsvFormat),
111       blitSRVFormat(blitSRVFormat),
112       stencilSRVFormat(stencilSRVFormat),
113       linearSRVFormat(linearSRVFormat),
114       typelessFormat(typelessFormat),
115       swizzleFormat(swizzleFormat),
116       dataInitializerFunction(internalFormatInitializer)
117 {}
118 
119 }  // namespace d3d11
120 
121 }  // namespace rx
122 
123 #endif  // LIBANGLE_RENDERER_D3D_D3D11_TEXTUREFORMATTABLE_H_
124