xref: /aosp_15_r20/external/angle/src/libANGLE/renderer/d3d_format.cpp (revision 8975f5c5ed3d1c378011245431ada316dfb6f244)
1 //
2 // Copyright 2020 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 // d3d_format: Describes a D3D9 format. Used by the D3D9 and GL back-ends.
7 
8 #include "libANGLE/renderer/d3d_format.h"
9 
10 using namespace angle;
11 
12 namespace rx
13 {
14 namespace d3d9
15 {
16 namespace
17 {
18 constexpr D3DFORMAT D3DFMT_INTZ = ((D3DFORMAT)(MAKEFOURCC('I', 'N', 'T', 'Z')));
19 constexpr D3DFORMAT D3DFMT_NULL = ((D3DFORMAT)(MAKEFOURCC('N', 'U', 'L', 'L')));
20 }  // anonymous namespace
21 
D3DFormat()22 D3DFormat::D3DFormat()
23     : pixelBytes(0),
24       blockWidth(0),
25       blockHeight(0),
26       redBits(0),
27       greenBits(0),
28       blueBits(0),
29       alphaBits(0),
30       luminanceBits(0),
31       depthBits(0),
32       stencilBits(0),
33       formatID(angle::FormatID::NONE)
34 {}
35 
D3DFormat(GLuint bits,GLuint blockWidth,GLuint blockHeight,GLuint redBits,GLuint greenBits,GLuint blueBits,GLuint alphaBits,GLuint lumBits,GLuint depthBits,GLuint stencilBits,FormatID formatID)36 D3DFormat::D3DFormat(GLuint bits,
37                      GLuint blockWidth,
38                      GLuint blockHeight,
39                      GLuint redBits,
40                      GLuint greenBits,
41                      GLuint blueBits,
42                      GLuint alphaBits,
43                      GLuint lumBits,
44                      GLuint depthBits,
45                      GLuint stencilBits,
46                      FormatID formatID)
47     : pixelBytes(bits / 8),
48       blockWidth(blockWidth),
49       blockHeight(blockHeight),
50       redBits(redBits),
51       greenBits(greenBits),
52       blueBits(blueBits),
53       alphaBits(alphaBits),
54       luminanceBits(lumBits),
55       depthBits(depthBits),
56       stencilBits(stencilBits),
57       formatID(formatID)
58 {}
59 
GetD3DFormatInfo(D3DFORMAT format)60 const D3DFormat &GetD3DFormatInfo(D3DFORMAT format)
61 {
62     if (format == D3DFMT_NULL)
63     {
64         static const D3DFormat info(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FormatID::NONE);
65         return info;
66     }
67 
68     if (format == D3DFMT_INTZ)
69     {
70         static const D3DFormat info(32, 1, 1, 0, 0, 0, 0, 0, 24, 8, FormatID::D24_UNORM_S8_UINT);
71         return info;
72     }
73 
74     switch (format)
75     {
76         case D3DFMT_UNKNOWN:
77         {
78             static const D3DFormat info(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, FormatID::NONE);
79             return info;
80         }
81 
82         case D3DFMT_L8:
83         {
84             static const D3DFormat info(8, 1, 1, 0, 0, 0, 0, 8, 0, 0, FormatID::L8_UNORM);
85             return info;
86         }
87         case D3DFMT_A8:
88         {
89             static const D3DFormat info(8, 1, 1, 0, 0, 0, 8, 0, 0, 0, FormatID::A8_UNORM);
90             return info;
91         }
92         case D3DFMT_A8L8:
93         {
94             static const D3DFormat info(16, 1, 1, 0, 0, 0, 8, 8, 0, 0, FormatID::L8A8_UNORM);
95             return info;
96         }
97         case D3DFMT_A4L4:
98         {
99             static const D3DFormat info(8, 1, 1, 0, 0, 0, 4, 4, 0, 0, FormatID::L4A4_UNORM);
100             return info;
101         }
102 
103         case D3DFMT_A4R4G4B4:
104         {
105             static const D3DFormat info(16, 1, 1, 4, 4, 4, 4, 0, 0, 0, FormatID::B4G4R4A4_UNORM);
106             return info;
107         }
108         case D3DFMT_A1R5G5B5:
109         {
110             static const D3DFormat info(16, 1, 1, 5, 5, 5, 1, 0, 0, 0, FormatID::B5G5R5A1_UNORM);
111             return info;
112         }
113         case D3DFMT_R5G6B5:
114         {
115             static const D3DFormat info(16, 1, 1, 5, 6, 5, 0, 0, 0, 0, FormatID::R5G6B5_UNORM);
116             return info;
117         }
118         case D3DFMT_X8R8G8B8:
119         {
120             static const D3DFormat info(32, 1, 1, 8, 8, 8, 0, 0, 0, 0, FormatID::B8G8R8X8_UNORM);
121             return info;
122         }
123         case D3DFMT_A8R8G8B8:
124         {
125             static const D3DFormat info(32, 1, 1, 8, 8, 8, 8, 0, 0, 0, FormatID::B8G8R8A8_UNORM);
126             return info;
127         }
128 
129         case D3DFMT_R16F:
130         {
131             static const D3DFormat info(16, 1, 1, 16, 0, 0, 0, 0, 0, 0, FormatID::R16_FLOAT);
132             return info;
133         }
134         case D3DFMT_G16R16F:
135         {
136             static const D3DFormat info(32, 1, 1, 16, 16, 0, 0, 0, 0, 0, FormatID::R16G16_FLOAT);
137             return info;
138         }
139         case D3DFMT_A16B16G16R16F:
140         {
141             static const D3DFormat info(64, 1, 1, 16, 16, 16, 16, 0, 0, 0,
142                                         FormatID::R16G16B16A16_FLOAT);
143             return info;
144         }
145         case D3DFMT_R32F:
146         {
147             static const D3DFormat info(32, 1, 1, 32, 0, 0, 0, 0, 0, 0, FormatID::R32_FLOAT);
148             return info;
149         }
150         case D3DFMT_G32R32F:
151         {
152             static const D3DFormat info(64, 1, 1, 32, 32, 0, 0, 0, 0, 0, FormatID::R32G32_FLOAT);
153             return info;
154         }
155         case D3DFMT_A32B32G32R32F:
156         {
157             static const D3DFormat info(128, 1, 1, 32, 32, 32, 32, 0, 0, 0,
158                                         FormatID::R32G32B32A32_FLOAT);
159             return info;
160         }
161 
162         case D3DFMT_D16:
163         {
164             static const D3DFormat info(16, 1, 1, 0, 0, 0, 0, 0, 16, 0, FormatID::D16_UNORM);
165             return info;
166         }
167         case D3DFMT_D24S8:
168         {
169             static const D3DFormat info(32, 1, 1, 0, 0, 0, 0, 0, 24, 8,
170                                         FormatID::D24_UNORM_S8_UINT);
171             return info;
172         }
173         case D3DFMT_D24X8:
174         {
175             static const D3DFormat info(32, 1, 1, 0, 0, 0, 0, 0, 24, 0, FormatID::D16_UNORM);
176             return info;
177         }
178         case D3DFMT_D32:
179         {
180             static const D3DFormat info(32, 1, 1, 0, 0, 0, 0, 0, 32, 0, FormatID::D32_UNORM);
181             return info;
182         }
183 
184         case D3DFMT_DXT1:
185         {
186             static const D3DFormat info(64, 4, 4, 0, 0, 0, 0, 0, 0, 0,
187                                         FormatID::BC1_RGBA_UNORM_BLOCK);
188             return info;
189         }
190         case D3DFMT_DXT3:
191         {
192             static const D3DFormat info(128, 4, 4, 0, 0, 0, 0, 0, 0, 0,
193                                         FormatID::BC2_RGBA_UNORM_BLOCK);
194             return info;
195         }
196         case D3DFMT_DXT5:
197         {
198             static const D3DFormat info(128, 4, 4, 0, 0, 0, 0, 0, 0, 0,
199                                         FormatID::BC3_RGBA_UNORM_BLOCK);
200             return info;
201         }
202 
203         default:
204         {
205             static const D3DFormat defaultInfo;
206             return defaultInfo;
207         }
208     }
209 }
210 }  // namespace d3d9
211 }  // namespace rx
212