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  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_typeless = 0x424757B8,
44  r8g8b8x8_unorm = 0x424757B9,
45  r8g8b8x8_unorm_srgb = 0x424757BA,
46  b8g8r8a8_typeless = 90,
47  b8g8r8a8_unorm = 87,
49  b8g8r8x8_typeless = 92,
50  b8g8r8x8_unorm = 88,
53  r10g10b10a2_uint = 25,
54  r10g10b10a2_unorm = 24,
56  b10g10r10a2_typeless = 0x42475330,
57  b10g10r10a2_uint = 0x42475332,
58  b10g10r10a2_unorm = 0x42475331,
59  l16_unorm = 0x3036314C,
60  r16_typeless = 53,
61  r16_uint = 57,
62  r16_sint = 59,
63  r16_float = 54,
64  r16_unorm = 56,
65  r16_snorm = 58,
66  l16a16_unorm = 0x3631414C,
67  r16g16_typeless = 33,
68  r16g16_uint = 36,
69  r16g16_sint = 38,
70  r16g16_float = 34,
71  r16g16_unorm = 35,
72  r16g16_snorm = 37,
74  r16g16b16a16_uint = 12,
75  r16g16b16a16_sint = 14,
76  r16g16b16a16_float = 10,
77  r16g16b16a16_unorm = 11,
78  r16g16b16a16_snorm = 13,
79  r32_typeless = 39,
80  r32_uint = 42,
81  r32_sint = 43,
82  r32_float = 41,
83  r32g32_typeless = 15,
84  r32g32_uint = 17,
85  r32g32_sint = 18,
86  r32g32_float = 16,
88  r32g32b32_uint = 7,
89  r32g32b32_sint = 8,
90  r32g32b32_float = 6,
95  r9g9b9e5 = 67,
96  r11g11b10_float = 26,
97  b5g6r5_unorm = 85,
98  b5g5r5a1_unorm = 86,
99  b5g5r5x1_unorm = 0x424757B5,
100  b4g4r4a4_unorm = 115,
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;
212  case format::l16_unorm:
213  case format::d16_unorm:
215  case format::r16_uint:
216  case format::r16_sint:
217  case format::r16_float:
218  case format::r16_unorm:
219  case format::r16_snorm:
220  return format::r16_typeless;
223  case format::r16g16_uint:
224  case format::r16g16_sint:
236  case format::d32_float:
238  case format::r32_uint:
239  case format::r32_sint:
240  case format::r32_float:
241  return format::r32_typeless;
243  case format::r32g32_uint:
244  case format::r32g32_sint:
262  case format::d24_unorm_s8_uint: // Do not also convert 'd24_unorm_x8_uint' here, to keep it distinguishable from 'd24_unorm_s8_uint'
268  case format::bc1_unorm:
270  return format::bc1_typeless;
272  case format::bc2_unorm:
274  return format::bc2_typeless;
276  case format::bc3_unorm:
278  return format::bc2_typeless;
280  case format::bc4_unorm:
281  case format::bc4_snorm:
282  return format::bc4_typeless;
284  case format::bc5_unorm:
285  case format::bc5_snorm:
286  return format::bc5_typeless;
288  case format::bc6h_ufloat:
289  case format::bc6h_sfloat:
290  return format::bc6h_typeless;
292  case format::bc7_unorm:
294  return format::bc7_typeless;
295  default:
296  return value;
297  }
298  }
299 
305  inline format format_to_default_typed(format value, int srgb_variant = -1)
306  {
307  switch (value)
308  {
309  case format::r8_typeless:
310  return format::r8_unorm;
312  return format::r8g8_unorm;
315  return srgb_variant == 1 ? format::r8g8b8a8_unorm_srgb : format::r8g8b8a8_unorm;
317  return srgb_variant != 0 ? format::r8g8b8a8_unorm_srgb : format::r8g8b8a8_unorm;
320  return srgb_variant == 1 ? format::r8g8b8x8_unorm_srgb : format::r8g8b8x8_unorm;
322  return srgb_variant != 0 ? format::r8g8b8x8_unorm_srgb : format::r8g8b8x8_unorm;
325  return srgb_variant == 1 ? format::b8g8r8a8_unorm_srgb : format::b8g8r8a8_unorm;
327  return srgb_variant != 0 ? format::b8g8r8a8_unorm_srgb : format::b8g8r8a8_unorm;
330  return srgb_variant == 1 ? format::b8g8r8x8_unorm_srgb : format::b8g8r8x8_unorm;
332  return srgb_variant != 0 ? format::b8g8r8x8_unorm_srgb : format::b8g8r8x8_unorm;
337  case format::d16_unorm:
339  return format::r16_unorm;
341  return format::r16g16_unorm;
344  case format::d32_float:
346  return format::r32_float;
348  return format::r32g32_float;
356  case format::d24_unorm_s8_uint: // Do not also convert 'd24_unorm_x8_uint' here, to keep it distinguishable from 'd24_unorm_s8_uint'
360  case format::bc1_unorm:
361  return srgb_variant == 1 ? format::bc1_unorm_srgb : format::bc1_unorm;
363  return srgb_variant != 0 ? format::bc1_unorm_srgb : format::bc1_unorm;
365  case format::bc2_unorm:
366  return srgb_variant == 1 ? format::bc2_unorm_srgb : format::bc2_unorm;
368  return srgb_variant != 0 ? format::bc2_unorm_srgb : format::bc2_unorm;
370  case format::bc3_unorm:
371  return srgb_variant == 1 ? format::bc3_unorm_srgb : format::bc3_unorm;
373  return srgb_variant != 0 ? format::bc3_unorm_srgb : format::bc3_unorm;
375  return format::bc4_unorm;
377  return format::bc5_unorm;
379  return format::bc6h_ufloat;
381  case format::bc7_unorm:
382  return srgb_variant == 1 ? format::bc7_unorm_srgb : format::bc7_unorm;
384  return srgb_variant != 0 ? format::bc7_unorm_srgb : format::bc7_unorm;
385  default:
386  return value;
387  }
388  }
389 
395  {
396  switch (value)
397  {
399  case format::r16_unorm:
400  return format::d16_unorm;
402  case format::r32_float:
403  return format::d32_float;
412  default:
413  return value;
414  }
415  }
416 
420  inline const uint32_t format_row_pitch(format value, uint32_t width)
421  {
422  if (value == format::unknown)
423  return 0;
424 
425  if (value <= format::r32g32b32a32_sint)
426  return 16 * width;
427  if (value <= format::r32g32b32_sint)
428  return 12 * width;
429  if (value <= format::x32_float_g8_uint)
430  return 8 * width;
431  if (value <= format::x24_unorm_g8_uint || value == format::l16a16_unorm)
432  return 4 * width;
433  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)
434  return 2 * width;
435  if (value <= format::a8_unorm || value == format::l8_unorm)
436  return 1 * width;
438  return 4 * width;
439 
440  // Block compressed formats are bytes per block, rather than per pixel
441  if ((value >= format::bc1_typeless && value <= format::bc1_unorm_srgb) || (value >= format::bc4_typeless && value <= format::bc4_snorm))
442  return 8 * ((width + 3) / 4);
443  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))
444  return 16 * ((width + 3) / 4);
445 
446  return 0;
447  }
451  inline const uint32_t format_slice_pitch(format value, uint32_t row_pitch, uint32_t height)
452  {
453  if ((value >= format::bc1_typeless && value <= format::bc5_snorm) || (value >= format::bc6h_typeless && value <= format::bc7_unorm_srgb))
454  return row_pitch * ((height + 3) / 4);
455 
456  return row_pitch * height;
457  }
458 }
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:305
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:451
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:420
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:394
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