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::api
12 {
17  enum class format : uint32_t
18  {
19  unknown = 0,
20 
21  // Color formats
22 
23  r1_unorm = 66,
24 
25  r8_typeless = 60,
26  r8_unorm = 61,
27  r8_uint = 62,
28  r8_snorm = 63,
29  r8_sint = 64,
30  l8_unorm = 0x3030384C, // L800
31  a8_unorm = 65,
32 
33  r8g8_typeless = 48,
34  r8g8_unorm = 49,
35  r8g8_uint = 50,
36  r8g8_snorm = 51,
37  r8g8_sint = 52,
38  l8a8_unorm = 0x3038414C, // LA80
39 
40  r8g8b8_typeless = 0x42475230,
41  r8g8b8_unorm = 0x42475231,
42  r8g8b8_unorm_srgb = 0x42475235,
43  r8g8b8_uint = 0x42475232,
44  r8g8b8_snorm = 0x42475233,
45  r8g8b8_sint = 0x42475234,
46  b8g8r8_typeless = 0x52474230,
47  b8g8r8_unorm = 0x52474231,
48  b8g8r8_unorm_srgb = 0x52474235,
49 
50  r8g8b8a8_typeless = 27,
51  r8g8b8a8_unorm = 28,
53  r8g8b8a8_uint = 30,
54  r8g8b8a8_snorm = 31,
55  r8g8b8a8_sint = 32,
56  r8g8b8x8_unorm = 0x424757B9,
57  r8g8b8x8_unorm_srgb = 0x424757BA,
58  b8g8r8a8_typeless = 90,
59  b8g8r8a8_unorm = 87,
61  b8g8r8x8_typeless = 92,
62  b8g8r8x8_unorm = 88,
64 
66  r10g10b10a2_unorm = 24,
67  r10g10b10a2_uint = 25,
69  b10g10r10a2_typeless = 0x42475330,
70  b10g10r10a2_unorm = 0x42475331,
71  b10g10r10a2_uint = 0x42475332,
72 
73  r16_typeless = 53,
74  r16_float = 54,
75  r16_unorm = 56,
76  r16_uint = 57,
77  r16_snorm = 58,
78  r16_sint = 59,
79  l16_unorm = 0x3036314C,
80 
81  l16a16_unorm = 0x3631414C, // LA16
82  r16g16_typeless = 33,
83  r16g16_float = 34,
84  r16g16_unorm = 35,
85  r16g16_uint = 36,
86  r16g16_snorm = 37,
87  r16g16_sint = 38,
88 
89  r16g16b16_typeless = 0x42475430,
90  r16g16b16_float = 0x42475435,
91  r16g16b16_unorm = 0x42475431,
92  r16g16b16_uint = 0x42475432,
93  r16g16b16_snorm = 0x42475433,
94  r16g16b16_sint = 0x42475434,
95 
97  r16g16b16a16_float = 10,
98  r16g16b16a16_unorm = 11,
99  r16g16b16a16_uint = 12,
100  r16g16b16a16_snorm = 13,
101  r16g16b16a16_sint = 14,
102 
103  r32_typeless = 39,
104  r32_float = 41,
105  r32_uint = 42,
106  r32_sint = 43,
107 
108  r32g32_typeless = 15,
109  r32g32_float = 16,
110  r32g32_uint = 17,
111  r32g32_sint = 18,
112 
113  r32g32b32_typeless = 5,
114  r32g32b32_float = 6,
115  r32g32b32_uint = 7,
116  r32g32b32_sint = 8,
117 
119  r32g32b32a32_float = 2,
120  r32g32b32a32_uint = 3,
121  r32g32b32a32_sint = 4,
122 
123  r9g9b9e5 = 67,
124  r11g11b10_float = 26,
125  b5g6r5_unorm = 85,
126  b5g5r5a1_unorm = 86,
127  b5g5r5x1_unorm = 0x424757B5,
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 
189  // BT.709/sRGB primaries
190  srgb,
191  // BT.709/sRGB primaries + linear
192  scrgb,
193  // BT.2020 primaries + PQ transfer function
194  hdr10_pq,
195  // BT.2020 primaries + HLG transfer function
196  hdr10_hlg,
197 
201  };
202 
208  {
209  switch (value)
210  {
211  case format::l8_unorm:
212  case format::r8_typeless:
213  case format::r8_uint:
214  case format::r8_sint:
215  case format::r8_unorm:
216  case format::r8_snorm:
217  return format::r8_typeless;
218  case format::l8a8_unorm:
220  case format::r8g8_uint:
221  case format::r8g8_sint:
222  case format::r8g8_unorm:
223  case format::r8g8_snorm:
224  return format::r8g8_typeless;
251  case format::l16_unorm:
252  case format::d16_unorm:
254  case format::r16_uint:
255  case format::r16_sint:
256  case format::r16_float:
257  case format::r16_unorm:
258  case format::r16_snorm:
259  return format::r16_typeless;
262  case format::r16g16_uint:
263  case format::r16g16_sint:
275  case format::d32_float:
277  case format::r32_uint:
278  case format::r32_sint:
279  case format::r32_float:
280  return format::r32_typeless;
282  case format::r32g32_uint:
283  case format::r32g32_sint:
301  case format::d24_unorm_s8_uint: // Do not also convert 'd24_unorm_x8_uint' here, to keep it distinguishable from 'd24_unorm_s8_uint'
307  case format::bc1_unorm:
309  return format::bc1_typeless;
311  case format::bc2_unorm:
313  return format::bc2_typeless;
315  case format::bc3_unorm:
317  return format::bc3_typeless;
319  case format::bc4_unorm:
320  case format::bc4_snorm:
321  return format::bc4_typeless;
323  case format::bc5_unorm:
324  case format::bc5_snorm:
325  return format::bc5_typeless;
327  case format::bc6h_ufloat:
328  case format::bc6h_sfloat:
329  return format::bc6h_typeless;
331  case format::bc7_unorm:
333  return format::bc7_typeless;
334  default:
335  return value;
336  }
337  }
338 
344  inline format format_to_default_typed(format value, int srgb_variant = -1)
345  {
346  switch (value)
347  {
348  case format::r8_typeless:
349  return format::r8_unorm;
351  return format::r8g8_unorm;
354  return srgb_variant == 1 ? format::r8g8b8_unorm_srgb : format::r8g8b8_unorm;
356  return srgb_variant != 0 ? format::r8g8b8_unorm_srgb : format::r8g8b8_unorm;
359  return srgb_variant == 1 ? format::b8g8r8_unorm_srgb : format::b8g8r8_unorm;
361  return srgb_variant != 0 ? format::b8g8r8_unorm_srgb : format::b8g8r8_unorm;
364  return srgb_variant == 1 ? format::r8g8b8a8_unorm_srgb : format::r8g8b8a8_unorm;
366  return srgb_variant != 0 ? format::r8g8b8a8_unorm_srgb : format::r8g8b8a8_unorm;
368  return srgb_variant == 1 ? format::r8g8b8x8_unorm_srgb : format::r8g8b8x8_unorm;
370  return srgb_variant != 0 ? format::r8g8b8x8_unorm_srgb : format::r8g8b8x8_unorm;
373  return srgb_variant == 1 ? format::b8g8r8a8_unorm_srgb : format::b8g8r8a8_unorm;
375  return srgb_variant != 0 ? format::b8g8r8a8_unorm_srgb : format::b8g8r8a8_unorm;
378  return srgb_variant == 1 ? format::b8g8r8x8_unorm_srgb : format::b8g8r8x8_unorm;
380  return srgb_variant != 0 ? format::b8g8r8x8_unorm_srgb : format::b8g8r8x8_unorm;
385  case format::d16_unorm:
386  return format::r16_unorm;
388  return format::r16_float;
390  return format::r16g16_float;
395  case format::d32_float:
397  return format::r32_float;
399  return format::r32g32_float;
407  case format::d24_unorm_s8_uint: // Do not also convert 'd24_unorm_x8_uint' here, to keep it distinguishable from 'd24_unorm_s8_uint'
411  case format::bc1_unorm:
412  return srgb_variant == 1 ? format::bc1_unorm_srgb : format::bc1_unorm;
414  return srgb_variant != 0 ? format::bc1_unorm_srgb : format::bc1_unorm;
416  case format::bc2_unorm:
417  return srgb_variant == 1 ? format::bc2_unorm_srgb : format::bc2_unorm;
419  return srgb_variant != 0 ? format::bc2_unorm_srgb : format::bc2_unorm;
421  case format::bc3_unorm:
422  return srgb_variant == 1 ? format::bc3_unorm_srgb : format::bc3_unorm;
424  return srgb_variant != 0 ? format::bc3_unorm_srgb : format::bc3_unorm;
426  return format::bc4_unorm;
428  return format::bc5_unorm;
430  return format::bc6h_ufloat;
432  case format::bc7_unorm:
433  return srgb_variant == 1 ? format::bc7_unorm_srgb : format::bc7_unorm;
435  return srgb_variant != 0 ? format::bc7_unorm_srgb : format::bc7_unorm;
436  default:
437  return value;
438  }
439  }
440 
446  {
447  switch (value)
448  {
450  case format::r16_unorm:
451  return format::d16_unorm;
453  case format::r32_float:
454  return format::d32_float;
463  default:
464  return value;
465  }
466  }
467 
471  inline const uint32_t format_bit_depth(format value)
472  {
473  switch (value)
474  {
478  return 5;
490  return 8;
491  case format::r9g9b9e5:
492  return 9;
498  return 10;
500  return 11;
503  return 16;
508  return 32;
509  default:
510  return 0;
511  }
512  }
513 
517  inline const uint32_t format_row_pitch(format value, uint32_t width)
518  {
519  if (value == format::unknown)
520  return 0;
521 
522  if (value <= format::r32g32b32a32_sint)
523  return 16 * width;
524  if (value <= format::r32g32b32_sint)
525  return 12 * width;
526  if (value <= format::x32_float_g8_uint)
527  return 8 * width;
528  if (value <= format::x24_unorm_g8_uint || value == format::l16a16_unorm)
529  return 4 * width;
530  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)
531  return 2 * width;
532  if (value <= format::a8_unorm || value == format::l8_unorm)
533  return 1 * width;
535  return 4 * width;
536 
537  // Block compressed formats are bytes per block, rather than per pixel
538  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))
539  return 16 * ((width + 3) / 4);
540  if ((value >= format::bc1_typeless && value <= format::bc1_unorm_srgb) || (value >= format::bc4_typeless && value <= format::bc4_snorm))
541  return 8 * ((width + 3) / 4);
542 
543  // Unusual formats
544  if ((value >= format::r16g16b16_typeless && value <= format::r16g16b16_float))
545  return 6 * width;
546  if ((value >= format::r8g8b8_typeless && value <= format::r8g8b8_unorm_srgb) || (value >= format::b8g8r8_typeless && value <= format::b8g8r8_unorm_srgb))
547  return 3 * width;
548 
549  return 0;
550  }
551 
555  inline const uint32_t format_slice_pitch(format value, uint32_t row_pitch, uint32_t height)
556  {
557  if ((value >= format::bc1_typeless && value <= format::bc5_snorm) || (value >= format::bc6h_typeless && value <= format::bc7_unorm_srgb))
558  return row_pitch * ((height + 3) / 4);
559 
560  return row_pitch * height;
561  }
562 
566  inline bool format_is_typeless(format value)
567  {
568  return value == api::format_to_typeless(value) && value != api::format_to_default_typed(value);
569  }
570 
575  {
576  switch (value)
577  {
579  case format::bc1_unorm:
582  case format::bc2_unorm:
585  case format::bc3_unorm:
588  case format::bc4_unorm:
589  case format::bc4_snorm:
591  case format::bc5_unorm:
592  case format::bc5_snorm:
594  case format::bc6h_ufloat:
595  case format::bc6h_sfloat:
597  case format::bc7_unorm:
599  return true;
600  default:
601  return false;
602  }
603  }
604 }
Definition: reshade_api.hpp:11
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:344
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:555
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:517
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:445
const uint32_t format_bit_depth(format value)
Gets the average component bit depth of the specified format value .
Definition: reshade_api_format.hpp:471
format format_to_typeless(format value)
Converts the specified format value to its equivalent typeless variant.
Definition: reshade_api_format.hpp:207
bool format_is_typeless(format value)
Checks whether the specified format value is a typeless format.
Definition: reshade_api_format.hpp:566
bool format_is_block_compressed(format value)
Checks whether the specified format value is a block compressed (BC) format.
Definition: reshade_api_format.hpp:574
format
Available data and texture formats. This is mostly compatible with 'DXGI_FORMAT'.
Definition: reshade_api_format.hpp:18