ReShade
A generic post-processing injector for games and video software.
reshade_api_format.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Patrick Mours
3  * SPDX-License-Identifier: BSD-3-Clause OR MIT
4  */
5 
6 #pragma once
7 
8 #include <cfloat>
9 #include <cstdint>
10 
11 namespace reshade { namespace api
12 {
17  enum class format : uint32_t
18  {
19  unknown = 0,
20 
21  // Color formats
22 
23  r1_unorm = 66,
24 
25  l8_unorm = 0x3030384C /* L800 */,
26  a8_unorm = 65,
27  r8_typeless = 60,
28  r8_uint = 62,
29  r8_sint = 64,
30  r8_unorm = 61,
31  r8_snorm = 63,
32 
33  l8a8_unorm = 0x3038414C /* LA80 */,
34  r8g8_typeless = 48,
35  r8g8_uint = 50,
36  r8g8_sint = 52,
37  r8g8_unorm = 49,
38  r8g8_snorm = 51,
39 
40  r8g8b8_typeless = 0x42475230 /* 0RGB */,
41  r8g8b8_uint = 0x42475232 /* 2RGB */,
42  r8g8b8_sint = 0x42475234 /* 4RGB */,
43  r8g8b8_unorm = 0x42475231 /* 1RGB */,
44  r8g8b8_unorm_srgb = 0x42475235 /* 5RGB */,
45  r8g8b8_snorm = 0x42475233 /* 3RGB */,
46  b8g8r8_typeless = 0x52474230 /* 0BGR */,
47  b8g8r8_unorm = 0x52474231 /* 1BGR */,
48  b8g8r8_unorm_srgb = 0x52474235 /* 5BGR */,
49 
50  r8g8b8a8_typeless = 27,
51  r8g8b8a8_uint = 30,
52  r8g8b8a8_sint = 32,
53  r8g8b8a8_unorm = 28,
54  r8g8b8x8_unorm = 0x424757B9 /* _WGB */,
56  r8g8b8x8_unorm_srgb = 0x424757BA /* _WGB */,
57  r8g8b8a8_snorm = 31,
58  b8g8r8a8_typeless = 90,
59  b8g8r8x8_typeless = 92,
60  b8g8r8a8_unorm = 87,
61  b8g8r8x8_unorm = 88,
64 
66  r10g10b10a2_uint = 25,
67  r10g10b10a2_unorm = 24,
69  b10g10r10a2_typeless = 0x42475330 /* 0SGB */,
70  b10g10r10a2_uint = 0x42475332 /* 2SGB */,
71  b10g10r10a2_unorm = 0x42475331 /* 1SGB */,
72 
73  l16_unorm = 0x3036314C,
74  r16_typeless = 53,
75  r16_uint = 57,
76  r16_sint = 59,
77  r16_unorm = 56,
78  r16_snorm = 58,
79  r16_float = 54,
80 
81  l16a16_unorm = 0x3631414C /* LA16 */,
82  r16g16_typeless = 33,
83  r16g16_uint = 36,
84  r16g16_sint = 38,
85  r16g16_unorm = 35,
86  r16g16_snorm = 37,
87  r16g16_float = 34,
88 
89  r16g16b16_typeless = 0x42475430 /* 0TGB */,
90  r16g16b16_uint = 0x42475432 /* 2TGB */,
91  r16g16b16_sint = 0x42475434 /* 4TGB */,
92  r16g16b16_unorm = 0x42475431 /* 1TGB */,
93  r16g16b16_snorm = 0x42475433 /* 3TGB */,
94  r16g16b16_float = 0x42475435 /* 5TGB */,
95 
97  r16g16b16a16_uint = 12,
98  r16g16b16a16_sint = 14,
99  r16g16b16a16_unorm = 11,
100  r16g16b16a16_snorm = 13,
101  r16g16b16a16_float = 10,
102 
103  r32_typeless = 39,
104  r32_uint = 42,
105  r32_sint = 43,
106  r32_float = 41,
107 
108  r32g32_typeless = 15,
109  r32g32_uint = 17,
110  r32g32_sint = 18,
111  r32g32_float = 16,
112 
113  r32g32b32_typeless = 5,
114  r32g32b32_uint = 7,
115  r32g32b32_sint = 8,
116  r32g32b32_float = 6,
117 
119  r32g32b32a32_uint = 3,
120  r32g32b32a32_sint = 4,
121  r32g32b32a32_float = 2,
122 
123  r9g9b9e5 = 67,
124  r11g11b10_float = 26,
125  b5g6r5_unorm = 85,
126  b5g5r5a1_unorm = 86,
127  b5g5r5x1_unorm = 0x424757B5 /* _WGB */,
128  b4g4r4a4_unorm = 115,
129  a4b4g4r4_unorm = 191,
130 
131  // Depth-stencil formats
132 
133  s8_uint = 0x30303853 /* S800 */,
134  d16_unorm = 55,
135  d16_unorm_s8_uint = 0x38363144 /* D168 */,
136  d24_unorm_x8_uint = 0x38343244 /* D248 */,
137  d24_unorm_s8_uint = 45,
138  d32_float = 40,
139  d32_float_s8_uint = 20,
140 
141  r24_g8_typeless = 44,
142  r24_unorm_x8_uint = 46,
143  x24_unorm_g8_uint = 47,
144  r32_g8_typeless = 19,
145  r32_float_x8_uint = 21,
146  x32_float_g8_uint = 22,
147 
148  // Compressed data formats
149 
150  bc1_typeless = 70,
151  bc1_unorm = 71,
152  bc1_unorm_srgb = 72,
153  bc2_typeless = 73,
154  bc2_unorm = 74,
155  bc2_unorm_srgb = 75,
156  bc3_typeless = 76,
157  bc3_unorm = 77,
158  bc3_unorm_srgb = 78,
159  bc4_typeless = 79,
160  bc4_unorm = 80,
161  bc4_snorm = 81,
162  bc5_typeless = 82,
163  bc5_unorm = 83,
164  bc5_snorm = 84,
165  bc6h_typeless = 94,
166  bc6h_ufloat = 95,
167  bc6h_sfloat = 96,
168  bc7_typeless = 97,
169  bc7_unorm = 98,
170  bc7_unorm_srgb = 99,
171 
172  // Video formats
173 
174  r8g8_b8g8_unorm = 68,
175  g8r8_g8b8_unorm = 69,
176 
177  // Special purpose formats
178 
179  intz = 0x5A544E49 /* INTZ */,
180  };
181 
185  enum class color_space : uint32_t
186  {
187  unknown = 0,
188 
191  hdr10_st2084,
192  hdr10_hlg,
193  };
194 
200  {
201  switch (value)
202  {
203  case format::l8_unorm:
204  case format::r8_typeless:
205  case format::r8_uint:
206  case format::r8_sint:
207  case format::r8_unorm:
208  case format::r8_snorm:
209  return format::r8_typeless;
210  case format::l8a8_unorm:
212  case format::r8g8_uint:
213  case format::r8g8_sint:
214  case format::r8g8_unorm:
215  case format::r8g8_snorm:
216  return format::r8g8_typeless;
243  case format::l16_unorm:
244  case format::d16_unorm:
246  case format::r16_uint:
247  case format::r16_sint:
248  case format::r16_float:
249  case format::r16_unorm:
250  case format::r16_snorm:
251  return format::r16_typeless;
254  case format::r16g16_uint:
255  case format::r16g16_sint:
267  case format::d32_float:
269  case format::r32_uint:
270  case format::r32_sint:
271  case format::r32_float:
272  return format::r32_typeless;
274  case format::r32g32_uint:
275  case format::r32g32_sint:
293  case format::d24_unorm_s8_uint: // Do not also convert 'd24_unorm_x8_uint' here, to keep it distinguishable from 'd24_unorm_s8_uint'
299  case format::bc1_unorm:
301  return format::bc1_typeless;
303  case format::bc2_unorm:
305  return format::bc2_typeless;
307  case format::bc3_unorm:
309  return format::bc2_typeless;
311  case format::bc4_unorm:
312  case format::bc4_snorm:
313  return format::bc4_typeless;
315  case format::bc5_unorm:
316  case format::bc5_snorm:
317  return format::bc5_typeless;
319  case format::bc6h_ufloat:
320  case format::bc6h_sfloat:
321  return format::bc6h_typeless;
323  case format::bc7_unorm:
325  return format::bc7_typeless;
326  default:
327  return value;
328  }
329  }
330 
336  inline format format_to_default_typed(format value, int srgb_variant = -1)
337  {
338  switch (value)
339  {
340  case format::r8_typeless:
341  return format::r8_unorm;
343  return format::r8g8_unorm;
346  return srgb_variant == 1 ? format::r8g8b8_unorm_srgb : format::r8g8b8_unorm;
348  return srgb_variant != 0 ? format::r8g8b8_unorm_srgb : format::r8g8b8_unorm;
351  return srgb_variant == 1 ? format::b8g8r8_unorm_srgb : format::b8g8r8_unorm;
353  return srgb_variant != 0 ? format::b8g8r8_unorm_srgb : format::b8g8r8_unorm;
356  return srgb_variant == 1 ? format::r8g8b8a8_unorm_srgb : format::r8g8b8a8_unorm;
358  return srgb_variant != 0 ? format::r8g8b8a8_unorm_srgb : format::r8g8b8a8_unorm;
360  return srgb_variant == 1 ? format::r8g8b8x8_unorm_srgb : format::r8g8b8x8_unorm;
362  return srgb_variant != 0 ? format::r8g8b8x8_unorm_srgb : format::r8g8b8x8_unorm;
365  return srgb_variant == 1 ? format::b8g8r8a8_unorm_srgb : format::b8g8r8a8_unorm;
367  return srgb_variant != 0 ? format::b8g8r8a8_unorm_srgb : format::b8g8r8a8_unorm;
370  return srgb_variant == 1 ? format::b8g8r8x8_unorm_srgb : format::b8g8r8x8_unorm;
372  return srgb_variant != 0 ? format::b8g8r8x8_unorm_srgb : format::b8g8r8x8_unorm;
377  case format::d16_unorm:
378  return format::r16_unorm;
380  return format::r16_float;
382  return format::r16g16_float;
387  case format::d32_float:
389  return format::r32_float;
391  return format::r32g32_float;
399  case format::d24_unorm_s8_uint: // Do not also convert 'd24_unorm_x8_uint' here, to keep it distinguishable from 'd24_unorm_s8_uint'
403  case format::bc1_unorm:
404  return srgb_variant == 1 ? format::bc1_unorm_srgb : format::bc1_unorm;
406  return srgb_variant != 0 ? format::bc1_unorm_srgb : format::bc1_unorm;
408  case format::bc2_unorm:
409  return srgb_variant == 1 ? format::bc2_unorm_srgb : format::bc2_unorm;
411  return srgb_variant != 0 ? format::bc2_unorm_srgb : format::bc2_unorm;
413  case format::bc3_unorm:
414  return srgb_variant == 1 ? format::bc3_unorm_srgb : format::bc3_unorm;
416  return srgb_variant != 0 ? format::bc3_unorm_srgb : format::bc3_unorm;
418  return format::bc4_unorm;
420  return format::bc5_unorm;
422  return format::bc6h_ufloat;
424  case format::bc7_unorm:
425  return srgb_variant == 1 ? format::bc7_unorm_srgb : format::bc7_unorm;
427  return srgb_variant != 0 ? format::bc7_unorm_srgb : format::bc7_unorm;
428  default:
429  return value;
430  }
431  }
432 
438  {
439  switch (value)
440  {
442  case format::r16_unorm:
443  return format::d16_unorm;
445  case format::r32_float:
446  return format::d32_float;
455  default:
456  return value;
457  }
458  }
459 
463  inline const uint32_t format_bit_depth(format value)
464  {
465  switch (value)
466  {
470  return 5;
482  return 8;
488  return 10;
490  return 11;
493  return 16;
498  return 32;
499  default:
500  return 0;
501  }
502  }
503 
507  inline const uint32_t format_row_pitch(format value, uint32_t width)
508  {
509  if (value == format::unknown)
510  return 0;
511 
512  if (value <= format::r32g32b32a32_sint)
513  return 16 * width;
514  if (value <= format::r32g32b32_sint)
515  return 12 * width;
516  if (value <= format::x32_float_g8_uint)
517  return 8 * width;
518  if (value <= format::x24_unorm_g8_uint || value == format::l16a16_unorm)
519  return 4 * width;
520  if (value <= format::r16_sint || value == format::b5g6r5_unorm || value == format::b5g5r5a1_unorm || value == format::b5g5r5x1_unorm || value == format::l8a8_unorm || value == format::l16_unorm)
521  return 2 * width;
522  if (value <= format::a8_unorm || value == format::l8_unorm)
523  return 1 * width;
525  return 4 * width;
526 
527  // Block compressed formats are bytes per block, rather than per pixel
528  if ((value >= format::bc2_typeless && value <= format::bc2_unorm_srgb) || (value >= format::bc3_typeless && value <= format::bc3_unorm_srgb) || (value >= format::bc5_typeless && value <= format::bc7_unorm_srgb))
529  return 16 * ((width + 3) / 4);
530  if ((value >= format::bc1_typeless && value <= format::bc1_unorm_srgb) || (value >= format::bc4_typeless && value <= format::bc4_snorm))
531  return 8 * ((width + 3) / 4);
532 
533  // Unusual formats
534  if ((value >= format::r16g16b16_typeless && value <= format::r16g16b16_float))
535  return 6 * width;
536  if ((value >= format::r8g8b8_typeless && value <= format::r8g8b8_unorm_srgb) || (value >= format::b8g8r8_typeless && value <= format::b8g8r8_unorm_srgb))
537  return 3 * width;
538 
539  return 0;
540  }
541 
545  inline const uint32_t format_slice_pitch(format value, uint32_t row_pitch, uint32_t height)
546  {
547  if ((value >= format::bc1_typeless && value <= format::bc5_snorm) || (value >= format::bc6h_typeless && value <= format::bc7_unorm_srgb))
548  return row_pitch * ((height + 3) / 4);
549 
550  return row_pitch * height;
551  }
552 } }
format format_to_default_typed(format value, int srgb_variant=-1)
Converts the specified format value to its equivalent typed variant ("unorm" or "float").
Definition: reshade_api_format.hpp:336
const uint32_t format_slice_pitch(format value, uint32_t row_pitch, uint32_t height)
Gets the number of bytes a texture slice of the specified format value occupies.
Definition: reshade_api_format.hpp:545
const uint32_t format_row_pitch(format value, uint32_t width)
Gets the number of bytes a texture row of the specified format value occupies.
Definition: reshade_api_format.hpp:507
color_space
The available color space types for presentation.
Definition: reshade_api_format.hpp:186
format format_to_depth_stencil_typed(format value)
Converts the specified format value to its equivalent depth-stencil variant.
Definition: reshade_api_format.hpp:437
const uint32_t format_bit_depth(format value)
Gets the average component bit depth of the specified format value .
Definition: reshade_api_format.hpp:463
format format_to_typeless(format value)
Converts the specified format value to its equivalent typeless variant.
Definition: reshade_api_format.hpp:199
format
Available data and texture formats. This is mostly compatible with 'DXGI_FORMAT'.
Definition: reshade_api_format.hpp:18
Definition: reshade.hpp:56