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  l8_unorm = 0x3030384C,
25  a8_unorm = 65,
26  r8_typeless = 60,
27  r8_uint = 62,
28  r8_sint = 64,
29  r8_unorm = 61,
30  r8_snorm = 63,
31  l8a8_unorm = 0x3038414C,
32  r8g8_typeless = 48,
33  r8g8_uint = 50,
34  r8g8_sint = 52,
35  r8g8_unorm = 49,
36  r8g8_snorm = 51,
37  r8g8b8a8_typeless = 27,
38  r8g8b8a8_uint = 30,
39  r8g8b8a8_sint = 32,
40  r8g8b8a8_unorm = 28,
42  r8g8b8a8_snorm = 31,
43  r8g8b8x8_unorm = 0x424757B9,
44  r8g8b8x8_unorm_srgb = 0x424757BA,
45  b8g8r8a8_typeless = 90,
46  b8g8r8a8_unorm = 87,
48  b8g8r8x8_typeless = 92,
49  b8g8r8x8_unorm = 88,
52  r10g10b10a2_uint = 25,
53  r10g10b10a2_unorm = 24,
55  b10g10r10a2_typeless = 0x42475330,
56  b10g10r10a2_uint = 0x42475332,
57  b10g10r10a2_unorm = 0x42475331,
58  l16_unorm = 0x3036314C,
59  r16_typeless = 53,
60  r16_uint = 57,
61  r16_sint = 59,
62  r16_unorm = 56,
63  r16_snorm = 58,
64  r16_float = 54,
65  l16a16_unorm = 0x3631414C,
66  r16g16_typeless = 33,
67  r16g16_uint = 36,
68  r16g16_sint = 38,
69  r16g16_unorm = 35,
70  r16g16_snorm = 37,
71  r16g16_float = 34,
73  r16g16b16a16_uint = 12,
74  r16g16b16a16_sint = 14,
75  r16g16b16a16_unorm = 11,
76  r16g16b16a16_snorm = 13,
77  r16g16b16a16_float = 10,
78  r32_typeless = 39,
79  r32_uint = 42,
80  r32_sint = 43,
81  r32_float = 41,
82  r32g32_typeless = 15,
83  r32g32_uint = 17,
84  r32g32_sint = 18,
85  r32g32_float = 16,
87  r32g32b32_uint = 7,
88  r32g32b32_sint = 8,
89  r32g32b32_float = 6,
94  r9g9b9e5 = 67,
95  r11g11b10_float = 26,
96  b5g6r5_unorm = 85,
97  b5g5r5a1_unorm = 86,
98  b5g5r5x1_unorm = 0x424757B5,
99  b4g4r4a4_unorm = 115,
100  a4b4g4r4_unorm = 191,
101 
102  // Depth-stencil formats
103 
104  s8_uint = 0x30303853,
105  d16_unorm = 55,
106  d16_unorm_s8_uint = 0x38363144,
107  d24_unorm_x8_uint = 0x38343244,
108  d24_unorm_s8_uint = 45,
109  d32_float = 40,
110  d32_float_s8_uint = 20,
111 
112  r24_g8_typeless = 44,
113  r24_unorm_x8_uint = 46,
114  x24_unorm_g8_uint = 47,
115  r32_g8_typeless = 19,
116  r32_float_x8_uint = 21,
117  x32_float_g8_uint = 22,
118 
119  // Compressed data formats
120 
121  bc1_typeless = 70,
122  bc1_unorm = 71,
123  bc1_unorm_srgb = 72,
124  bc2_typeless = 73,
125  bc2_unorm = 74,
126  bc2_unorm_srgb = 75,
127  bc3_typeless = 76,
128  bc3_unorm = 77,
129  bc3_unorm_srgb = 78,
130  bc4_typeless = 79,
131  bc4_unorm = 80,
132  bc4_snorm = 81,
133  bc5_typeless = 82,
134  bc5_unorm = 83,
135  bc5_snorm = 84,
136  bc6h_typeless = 94,
137  bc6h_ufloat = 95,
138  bc6h_sfloat = 96,
139  bc7_typeless = 97,
140  bc7_unorm = 98,
141  bc7_unorm_srgb = 99,
142 
143  // Video formats
144 
145  r8g8_b8g8_unorm = 68,
146  g8r8_g8b8_unorm = 69,
147 
148  // Special purpose formats
149 
150  intz = 0x5A544E49,
151  };
152 
156  enum class color_space : uint32_t
157  {
158  unknown = 0,
159 
162  hdr10_st2084,
163  hdr10_hlg,
164  };
165 
171  {
172  switch (value)
173  {
174  case format::l8_unorm:
175  case format::r8_typeless:
176  case format::r8_uint:
177  case format::r8_sint:
178  case format::r8_unorm:
179  case format::r8_snorm:
180  return format::r8_typeless;
181  case format::l8a8_unorm:
183  case format::r8g8_uint:
184  case format::r8g8_sint:
185  case format::r8g8_unorm:
186  case format::r8g8_snorm:
187  return format::r8g8_typeless;
214  case format::l16_unorm:
215  case format::d16_unorm:
217  case format::r16_uint:
218  case format::r16_sint:
219  case format::r16_float:
220  case format::r16_unorm:
221  case format::r16_snorm:
222  return format::r16_typeless;
225  case format::r16g16_uint:
226  case format::r16g16_sint:
238  case format::d32_float:
240  case format::r32_uint:
241  case format::r32_sint:
242  case format::r32_float:
243  return format::r32_typeless;
245  case format::r32g32_uint:
246  case format::r32g32_sint:
264  case format::d24_unorm_s8_uint: // Do not also convert 'd24_unorm_x8_uint' here, to keep it distinguishable from 'd24_unorm_s8_uint'
270  case format::bc1_unorm:
272  return format::bc1_typeless;
274  case format::bc2_unorm:
276  return format::bc2_typeless;
278  case format::bc3_unorm:
280  return format::bc2_typeless;
282  case format::bc4_unorm:
283  case format::bc4_snorm:
284  return format::bc4_typeless;
286  case format::bc5_unorm:
287  case format::bc5_snorm:
288  return format::bc5_typeless;
290  case format::bc6h_ufloat:
291  case format::bc6h_sfloat:
292  return format::bc6h_typeless;
294  case format::bc7_unorm:
296  return format::bc7_typeless;
297  default:
298  return value;
299  }
300  }
301 
307  inline format format_to_default_typed(format value, int srgb_variant = -1)
308  {
309  switch (value)
310  {
311  case format::r8_typeless:
312  return format::r8_unorm;
314  return format::r8g8_unorm;
317  return srgb_variant == 1 ? format::r8g8b8a8_unorm_srgb : format::r8g8b8a8_unorm;
319  return srgb_variant != 0 ? format::r8g8b8a8_unorm_srgb : format::r8g8b8a8_unorm;
321  return srgb_variant == 1 ? format::r8g8b8x8_unorm_srgb : format::r8g8b8x8_unorm;
323  return srgb_variant != 0 ? format::r8g8b8x8_unorm_srgb : format::r8g8b8x8_unorm;
326  return srgb_variant == 1 ? format::b8g8r8a8_unorm_srgb : format::b8g8r8a8_unorm;
328  return srgb_variant != 0 ? format::b8g8r8a8_unorm_srgb : format::b8g8r8a8_unorm;
331  return srgb_variant == 1 ? format::b8g8r8x8_unorm_srgb : format::b8g8r8x8_unorm;
333  return srgb_variant != 0 ? format::b8g8r8x8_unorm_srgb : format::b8g8r8x8_unorm;
338  case format::d16_unorm:
339  return format::r16_unorm;
341  return format::r16_float;
343  return format::r16g16_float;
346  case format::d32_float:
348  return format::r32_float;
350  return format::r32g32_float;
358  case format::d24_unorm_s8_uint: // Do not also convert 'd24_unorm_x8_uint' here, to keep it distinguishable from 'd24_unorm_s8_uint'
362  case format::bc1_unorm:
363  return srgb_variant == 1 ? format::bc1_unorm_srgb : format::bc1_unorm;
365  return srgb_variant != 0 ? format::bc1_unorm_srgb : format::bc1_unorm;
367  case format::bc2_unorm:
368  return srgb_variant == 1 ? format::bc2_unorm_srgb : format::bc2_unorm;
370  return srgb_variant != 0 ? format::bc2_unorm_srgb : format::bc2_unorm;
372  case format::bc3_unorm:
373  return srgb_variant == 1 ? format::bc3_unorm_srgb : format::bc3_unorm;
375  return srgb_variant != 0 ? format::bc3_unorm_srgb : format::bc3_unorm;
377  return format::bc4_unorm;
379  return format::bc5_unorm;
381  return format::bc6h_ufloat;
383  case format::bc7_unorm:
384  return srgb_variant == 1 ? format::bc7_unorm_srgb : format::bc7_unorm;
386  return srgb_variant != 0 ? format::bc7_unorm_srgb : format::bc7_unorm;
387  default:
388  return value;
389  }
390  }
391 
397  {
398  switch (value)
399  {
401  case format::r16_unorm:
402  return format::d16_unorm;
404  case format::r32_float:
405  return format::d32_float;
414  default:
415  return value;
416  }
417  }
418 
422  inline const uint32_t format_row_pitch(format value, uint32_t width)
423  {
424  if (value == format::unknown)
425  return 0;
426 
427  if (value <= format::r32g32b32a32_sint)
428  return 16 * width;
429  if (value <= format::r32g32b32_sint)
430  return 12 * width;
431  if (value <= format::x32_float_g8_uint)
432  return 8 * width;
433  if (value <= format::x24_unorm_g8_uint || value == format::l16a16_unorm)
434  return 4 * width;
435  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)
436  return 2 * width;
437  if (value <= format::a8_unorm || value == format::l8_unorm)
438  return 1 * width;
440  return 4 * width;
441 
442  // Block compressed formats are bytes per block, rather than per pixel
443  if ((value >= format::bc1_typeless && value <= format::bc1_unorm_srgb) || (value >= format::bc4_typeless && value <= format::bc4_snorm))
444  return 8 * ((width + 3) / 4);
445  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))
446  return 16 * ((width + 3) / 4);
447 
448  return 0;
449  }
450 
454  inline const uint32_t format_slice_pitch(format value, uint32_t row_pitch, uint32_t height)
455  {
456  if ((value >= format::bc1_typeless && value <= format::bc5_snorm) || (value >= format::bc6h_typeless && value <= format::bc7_unorm_srgb))
457  return row_pitch * ((height + 3) / 4);
458 
459  return row_pitch * height;
460  }
461 } }
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:307
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:454
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:422
color_space
The available color space types for presentation.
Definition: reshade_api_format.hpp:157
format format_to_depth_stencil_typed(format value)
Converts the specified format value to its equivalent depth-stencil variant.
Definition: reshade_api_format.hpp:396
format format_to_typeless(format value)
Converts the specified format value to its equivalent typeless variant.
Definition: reshade_api_format.hpp:170
format
The available data and texture formats. This is mostly compatible with 'DXGI_FORMAT'.
Definition: reshade_api_format.hpp:18
Definition: reshade.hpp:52