summaryrefslogtreecommitdiff
path: root/src/video_core/surface.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/surface.h')
-rw-r--r--src/video_core/surface.h385
1 files changed, 385 insertions, 0 deletions
diff --git a/src/video_core/surface.h b/src/video_core/surface.h
new file mode 100644
index 000000000..3232e437f
--- /dev/null
+++ b/src/video_core/surface.h
@@ -0,0 +1,385 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <climits>
8#include <utility>
9#include "common/assert.h"
10#include "common/common_types.h"
11#include "common/logging/log.h"
12#include "video_core/gpu.h"
13#include "video_core/textures/texture.h"
14
15namespace VideoCore::Surface {
16
17enum class PixelFormat {
18 ABGR8U = 0,
19 ABGR8S = 1,
20 ABGR8UI = 2,
21 B5G6R5U = 3,
22 A2B10G10R10U = 4,
23 A1B5G5R5U = 5,
24 R8U = 6,
25 R8UI = 7,
26 RGBA16F = 8,
27 RGBA16U = 9,
28 RGBA16UI = 10,
29 R11FG11FB10F = 11,
30 RGBA32UI = 12,
31 DXT1 = 13,
32 DXT23 = 14,
33 DXT45 = 15,
34 DXN1 = 16, // This is also known as BC4
35 DXN2UNORM = 17,
36 DXN2SNORM = 18,
37 BC7U = 19,
38 BC6H_UF16 = 20,
39 BC6H_SF16 = 21,
40 ASTC_2D_4X4 = 22,
41 G8R8U = 23,
42 G8R8S = 24,
43 BGRA8 = 25,
44 RGBA32F = 26,
45 RG32F = 27,
46 R32F = 28,
47 R16F = 29,
48 R16U = 30,
49 R16S = 31,
50 R16UI = 32,
51 R16I = 33,
52 RG16 = 34,
53 RG16F = 35,
54 RG16UI = 36,
55 RG16I = 37,
56 RG16S = 38,
57 RGB32F = 39,
58 RGBA8_SRGB = 40,
59 RG8U = 41,
60 RG8S = 42,
61 RG32UI = 43,
62 R32UI = 44,
63 ASTC_2D_8X8 = 45,
64 ASTC_2D_8X5 = 46,
65 ASTC_2D_5X4 = 47,
66 BGRA8_SRGB = 48,
67 DXT1_SRGB = 49,
68 DXT23_SRGB = 50,
69 DXT45_SRGB = 51,
70 BC7U_SRGB = 52,
71 ASTC_2D_4X4_SRGB = 53,
72 ASTC_2D_8X8_SRGB = 54,
73 ASTC_2D_8X5_SRGB = 55,
74 ASTC_2D_5X4_SRGB = 56,
75
76 MaxColorFormat,
77
78 // Depth formats
79 Z32F = 57,
80 Z16 = 58,
81
82 MaxDepthFormat,
83
84 // DepthStencil formats
85 Z24S8 = 59,
86 S8Z24 = 60,
87 Z32FS8 = 61,
88
89 MaxDepthStencilFormat,
90
91 Max = MaxDepthStencilFormat,
92 Invalid = 255,
93};
94
95static constexpr std::size_t MaxPixelFormat = static_cast<std::size_t>(PixelFormat::Max);
96
97enum class ComponentType {
98 Invalid = 0,
99 SNorm = 1,
100 UNorm = 2,
101 SInt = 3,
102 UInt = 4,
103 Float = 5,
104};
105
106enum class SurfaceType {
107 ColorTexture = 0,
108 Depth = 1,
109 DepthStencil = 2,
110 Fill = 3,
111 Invalid = 4,
112};
113
114enum class SurfaceTarget {
115 Texture1D,
116 Texture2D,
117 Texture3D,
118 Texture1DArray,
119 Texture2DArray,
120 TextureCubemap,
121};
122
123/**
124 * Gets the compression factor for the specified PixelFormat. This applies to just the
125 * "compressed width" and "compressed height", not the overall compression factor of a
126 * compressed image. This is used for maintaining proper surface sizes for compressed
127 * texture formats.
128 */
129static constexpr u32 GetCompressionFactor(PixelFormat format) {
130 if (format == PixelFormat::Invalid)
131 return 0;
132
133 constexpr std::array<u32, MaxPixelFormat> compression_factor_table = {{
134 1, // ABGR8U
135 1, // ABGR8S
136 1, // ABGR8UI
137 1, // B5G6R5U
138 1, // A2B10G10R10U
139 1, // A1B5G5R5U
140 1, // R8U
141 1, // R8UI
142 1, // RGBA16F
143 1, // RGBA16U
144 1, // RGBA16UI
145 1, // R11FG11FB10F
146 1, // RGBA32UI
147 4, // DXT1
148 4, // DXT23
149 4, // DXT45
150 4, // DXN1
151 4, // DXN2UNORM
152 4, // DXN2SNORM
153 4, // BC7U
154 4, // BC6H_UF16
155 4, // BC6H_SF16
156 4, // ASTC_2D_4X4
157 1, // G8R8U
158 1, // G8R8S
159 1, // BGRA8
160 1, // RGBA32F
161 1, // RG32F
162 1, // R32F
163 1, // R16F
164 1, // R16U
165 1, // R16S
166 1, // R16UI
167 1, // R16I
168 1, // RG16
169 1, // RG16F
170 1, // RG16UI
171 1, // RG16I
172 1, // RG16S
173 1, // RGB32F
174 1, // RGBA8_SRGB
175 1, // RG8U
176 1, // RG8S
177 1, // RG32UI
178 1, // R32UI
179 4, // ASTC_2D_8X8
180 4, // ASTC_2D_8X5
181 4, // ASTC_2D_5X4
182 1, // BGRA8_SRGB
183 4, // DXT1_SRGB
184 4, // DXT23_SRGB
185 4, // DXT45_SRGB
186 4, // BC7U_SRGB
187 4, // ASTC_2D_4X4_SRGB
188 4, // ASTC_2D_8X8_SRGB
189 4, // ASTC_2D_8X5_SRGB
190 4, // ASTC_2D_5X4_SRGB
191 1, // Z32F
192 1, // Z16
193 1, // Z24S8
194 1, // S8Z24
195 1, // Z32FS8
196 }};
197
198 ASSERT(static_cast<std::size_t>(format) < compression_factor_table.size());
199 return compression_factor_table[static_cast<std::size_t>(format)];
200}
201
202static constexpr u32 GetDefaultBlockHeight(PixelFormat format) {
203 if (format == PixelFormat::Invalid)
204 return 0;
205
206 constexpr std::array<u32, MaxPixelFormat> block_height_table = {{
207 1, // ABGR8U
208 1, // ABGR8S
209 1, // ABGR8UI
210 1, // B5G6R5U
211 1, // A2B10G10R10U
212 1, // A1B5G5R5U
213 1, // R8U
214 1, // R8UI
215 1, // RGBA16F
216 1, // RGBA16U
217 1, // RGBA16UI
218 1, // R11FG11FB10F
219 1, // RGBA32UI
220 4, // DXT1
221 4, // DXT23
222 4, // DXT45
223 4, // DXN1
224 4, // DXN2UNORM
225 4, // DXN2SNORM
226 4, // BC7U
227 4, // BC6H_UF16
228 4, // BC6H_SF16
229 4, // ASTC_2D_4X4
230 1, // G8R8U
231 1, // G8R8S
232 1, // BGRA8
233 1, // RGBA32F
234 1, // RG32F
235 1, // R32F
236 1, // R16F
237 1, // R16U
238 1, // R16S
239 1, // R16UI
240 1, // R16I
241 1, // RG16
242 1, // RG16F
243 1, // RG16UI
244 1, // RG16I
245 1, // RG16S
246 1, // RGB32F
247 1, // RGBA8_SRGB
248 1, // RG8U
249 1, // RG8S
250 1, // RG32UI
251 1, // R32UI
252 8, // ASTC_2D_8X8
253 5, // ASTC_2D_8X5
254 4, // ASTC_2D_5X4
255 1, // BGRA8_SRGB
256 4, // DXT1_SRGB
257 4, // DXT23_SRGB
258 4, // DXT45_SRGB
259 4, // BC7U_SRGB
260 4, // ASTC_2D_4X4_SRGB
261 8, // ASTC_2D_8X8_SRGB
262 5, // ASTC_2D_8X5_SRGB
263 4, // ASTC_2D_5X4_SRGB
264 1, // Z32F
265 1, // Z16
266 1, // Z24S8
267 1, // S8Z24
268 1, // Z32FS8
269 }};
270
271 ASSERT(static_cast<std::size_t>(format) < block_height_table.size());
272 return block_height_table[static_cast<std::size_t>(format)];
273}
274
275static constexpr u32 GetFormatBpp(PixelFormat format) {
276 if (format == PixelFormat::Invalid)
277 return 0;
278
279 constexpr std::array<u32, MaxPixelFormat> bpp_table = {{
280 32, // ABGR8U
281 32, // ABGR8S
282 32, // ABGR8UI
283 16, // B5G6R5U
284 32, // A2B10G10R10U
285 16, // A1B5G5R5U
286 8, // R8U
287 8, // R8UI
288 64, // RGBA16F
289 64, // RGBA16U
290 64, // RGBA16UI
291 32, // R11FG11FB10F
292 128, // RGBA32UI
293 64, // DXT1
294 128, // DXT23
295 128, // DXT45
296 64, // DXN1
297 128, // DXN2UNORM
298 128, // DXN2SNORM
299 128, // BC7U
300 128, // BC6H_UF16
301 128, // BC6H_SF16
302 32, // ASTC_2D_4X4
303 16, // G8R8U
304 16, // G8R8S
305 32, // BGRA8
306 128, // RGBA32F
307 64, // RG32F
308 32, // R32F
309 16, // R16F
310 16, // R16U
311 16, // R16S
312 16, // R16UI
313 16, // R16I
314 32, // RG16
315 32, // RG16F
316 32, // RG16UI
317 32, // RG16I
318 32, // RG16S
319 96, // RGB32F
320 32, // RGBA8_SRGB
321 16, // RG8U
322 16, // RG8S
323 64, // RG32UI
324 32, // R32UI
325 16, // ASTC_2D_8X8
326 16, // ASTC_2D_8X5
327 32, // ASTC_2D_5X4
328 32, // BGRA8_SRGB
329 64, // DXT1_SRGB
330 128, // DXT23_SRGB
331 128, // DXT45_SRGB
332 128, // BC7U
333 32, // ASTC_2D_4X4_SRGB
334 16, // ASTC_2D_8X8_SRGB
335 16, // ASTC_2D_8X5_SRGB
336 32, // ASTC_2D_5X4_SRGB
337 32, // Z32F
338 16, // Z16
339 32, // Z24S8
340 32, // S8Z24
341 64, // Z32FS8
342 }};
343
344 ASSERT(static_cast<std::size_t>(format) < bpp_table.size());
345 return bpp_table[static_cast<std::size_t>(format)];
346}
347
348/// Returns the sizer in bytes of the specified pixel format
349static constexpr u32 GetBytesPerPixel(PixelFormat pixel_format) {
350 if (pixel_format == PixelFormat::Invalid) {
351 return 0;
352 }
353 return GetFormatBpp(pixel_format) / CHAR_BIT;
354}
355
356SurfaceTarget SurfaceTargetFromTextureType(Tegra::Texture::TextureType texture_type);
357
358bool SurfaceTargetIsLayered(SurfaceTarget target);
359
360PixelFormat PixelFormatFromDepthFormat(Tegra::DepthFormat format);
361
362PixelFormat PixelFormatFromRenderTargetFormat(Tegra::RenderTargetFormat format);
363
364PixelFormat PixelFormatFromTextureFormat(Tegra::Texture::TextureFormat format,
365 Tegra::Texture::ComponentType component_type,
366 bool is_srgb);
367
368ComponentType ComponentTypeFromTexture(Tegra::Texture::ComponentType type);
369
370ComponentType ComponentTypeFromRenderTarget(Tegra::RenderTargetFormat format);
371
372PixelFormat PixelFormatFromGPUPixelFormat(Tegra::FramebufferConfig::PixelFormat format);
373
374ComponentType ComponentTypeFromDepthFormat(Tegra::DepthFormat format);
375
376SurfaceType GetFormatType(PixelFormat pixel_format);
377
378bool IsPixelFormatASTC(PixelFormat format);
379
380std::pair<u32, u32> GetASTCBlockSize(PixelFormat format);
381
382/// Returns true if the specified PixelFormat is a BCn format, e.g. DXT or DXN
383bool IsFormatBCn(PixelFormat format);
384
385} // namespace VideoCore::Surface