ReShade
A generic post-processing injector for games and video software.
reshade_api_resource.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 #define RESHADE_DEFINE_HANDLE(name) \
9  typedef struct { uint64_t handle; } name; \
10  constexpr bool operator< (name lhs, name rhs) { return lhs.handle < rhs.handle; } \
11  constexpr bool operator!=(name lhs, name rhs) { return lhs.handle != rhs.handle; } \
12  constexpr bool operator!=(name lhs, uint64_t rhs) { return lhs.handle != rhs; } \
13  constexpr bool operator==(name lhs, name rhs) { return lhs.handle == rhs.handle; } \
14  constexpr bool operator==(name lhs, uint64_t rhs) { return lhs.handle == rhs; }
15 
16 #define RESHADE_DEFINE_ENUM_FLAG_OPERATORS(type) \
17  constexpr type operator~(type a) { return static_cast<type>(~static_cast<uint32_t>(a)); } \
18  inline type &operator&=(type &a, type b) { return reinterpret_cast<type &>(reinterpret_cast<uint32_t &>(a) &= static_cast<uint32_t>(b)); } \
19  constexpr type operator&(type a, type b) { return static_cast<type>(static_cast<uint32_t>(a) & static_cast<uint32_t>(b)); } \
20  inline type &operator|=(type &a, type b) { return reinterpret_cast<type &>(reinterpret_cast<uint32_t &>(a) |= static_cast<uint32_t>(b)); } \
21  constexpr type operator|(type a, type b) { return static_cast<type>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b)); } \
22  inline type &operator^=(type &a, type b) { return reinterpret_cast<type &>(reinterpret_cast<uint32_t &>(a) ^= static_cast<uint32_t>(b)); } \
23  constexpr type operator^(type a, type b) { return static_cast<type>(static_cast<uint32_t>(a) ^ static_cast<uint32_t>(b)); } \
24  constexpr bool operator==(type lhs, uint32_t rhs) { return static_cast<uint32_t>(lhs) == rhs; } \
25  constexpr bool operator!=(type lhs, uint32_t rhs) { return static_cast<uint32_t>(lhs) != rhs; }
26 
27 #include "reshade_api_format.hpp"
28 
29 namespace reshade::api
30 {
34  enum class compare_op : uint32_t
35  {
36  never = 0,
37  less = 1,
38  equal = 2,
39  less_equal = 3,
40  greater = 4,
41  not_equal = 5,
42  greater_equal = 6,
43  always = 7
44  };
45 
49  enum class filter_mode : uint32_t
50  {
58  min_mag_mip_linear = 0x15,
59  anisotropic = 0x55,
68  compare_anisotropic = 0xd5
69  };
70 
74  enum class texture_address_mode : uint32_t
75  {
76  wrap = 1,
77  mirror = 2,
78  clamp = 3,
79  border = 4,
80  mirror_once = 5
81  };
82 
86  struct sampler_desc
87  {
107  float mip_lod_bias = 0.0f;
111  float max_anisotropy = 1.0f;
119  float border_color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
123  float min_lod = -FLT_MAX;
127  float max_lod = +FLT_MAX;
128  };
129 
135 
139  enum class map_access
140  {
141  read_only = 1,
142  write_only,
143  read_write,
145  };
146 
150  enum class memory_heap : uint32_t
151  {
152  unknown, // Usually indicates a resource that is reserved, but not yet bound to any memory.
153  gpu_only,
154  // Upload heap
155  cpu_to_gpu,
156  // Readback heap
157  gpu_to_cpu,
158  cpu_only,
159  custom
160  };
161 
166  enum class resource_type : uint32_t
167  {
168  unknown,
169  buffer,
170  texture_1d,
171  texture_2d,
172  texture_3d,
173  surface // Special type for resources that are implicitly both resource and render target view.
174  };
175 
179  enum class resource_flags : uint32_t
180  {
181  none = 0,
182  dynamic = (1 << 3),
183  cube_compatible = (1 << 2),
184  generate_mipmaps = (1 << 0),
185  shared = (1 << 1),
186  shared_nt_handle = (1 << 11),
187  structured = (1 << 6),
188  sparse_binding = (1 << 18)
189  };
191 
196  enum class resource_usage : uint32_t
197  {
198  undefined = 0,
199 
200  index_buffer = 0x2,
201  vertex_buffer = 0x1,
202  constant_buffer = 0x8000,
203  stream_output = 0x100,
204  indirect_argument = 0x200,
205 
206  depth_stencil = 0x30,
207  depth_stencil_read = 0x20,
208  depth_stencil_write = 0x10,
209  render_target = 0x4,
210  shader_resource = 0xC0,
211  shader_resource_pixel = 0x80,
213  unordered_access = 0x8,
214 
215  copy_dest = 0x400,
216  copy_source = 0x800,
217  resolve_dest = 0x1000,
218  resolve_source = 0x2000,
219 
220  // The following are special resource states and may only be used in barriers:
221 
222  general = 0x80000000,
223  present = 0x80000000 | render_target | copy_source,
225  };
227 
231  struct [[nodiscard]] resource_desc
232  {
233  constexpr resource_desc() : texture() {}
234  constexpr resource_desc(uint64_t size, memory_heap heap, resource_usage usage) :
235  type(resource_type::buffer), buffer({ size }), heap(heap), usage(usage) {}
236  constexpr resource_desc(uint32_t width, uint32_t height, uint16_t layers, uint16_t levels, format format, uint16_t samples, memory_heap heap, resource_usage usage, resource_flags flags = resource_flags::none) :
237  type(resource_type::texture_2d), texture({ width, height, layers, levels, format, samples }), heap(heap), usage(usage), flags(flags) {}
238  constexpr resource_desc(resource_type type, uint32_t width, uint32_t height, uint16_t depth_or_layers, uint16_t levels, format format, uint16_t samples, memory_heap heap, resource_usage usage, resource_flags flags = resource_flags::none) :
239  type(type), texture({ width, height, depth_or_layers, levels, format, samples }), heap(heap), usage(usage), flags(flags) {}
240 
245 
246  union
247  {
251  struct
252  {
256  uint64_t size = 0;
260  uint32_t stride = 0;
262 
266  struct
267  {
271  uint32_t width = 1;
275  uint32_t height = 1;
279  uint16_t depth_or_layers = 1;
284  uint16_t levels = 1;
292  uint16_t samples = 1;
293  } texture;
294  };
295 
308  };
309 
316 
320  enum class resource_view_type : uint32_t
321  {
322  unknown,
323  buffer,
324  texture_1d,
326  texture_2d,
330  texture_3d,
331  texture_cube,
333  };
334 
338  struct [[nodiscard]] resource_view_desc
339  {
340  constexpr resource_view_desc() : texture() {}
341  constexpr resource_view_desc(format format, uint64_t offset, uint64_t size) :
342  type(resource_view_type::buffer), format(format), buffer({ offset, size }) {}
343  constexpr resource_view_desc(format format, uint32_t first_level, uint32_t levels, uint32_t first_layer, uint32_t layers) :
344  type(resource_view_type::texture_2d), format(format), texture({ first_level, levels, first_layer, layers }) {}
345  constexpr resource_view_desc(resource_view_type type, format format, uint32_t first_level, uint32_t levels, uint32_t first_layer, uint32_t layers) :
346  type(type), format(format), texture({ first_level, levels, first_layer, layers }) {}
347  constexpr explicit resource_view_desc(format format) : type(resource_view_type::texture_2d), format(format), texture({ 0, 1, 0, 1 }) {}
348 
357 
358  union
359  {
363  struct
364  {
368  uint64_t offset = 0;
373  uint64_t size = UINT64_MAX;
375 
379  struct
380  {
384  uint32_t first_level = 0;
389  uint32_t level_count = UINT32_MAX;
393  uint32_t first_layer = 0;
398  uint32_t layer_count = UINT32_MAX;
399  } texture;
400  };
401  };
402 
409 
414  {
415  int32_t left = 0;
416  int32_t top = 0;
417  int32_t front = 0;
418  int32_t right = 0;
419  int32_t bottom = 0;
420  int32_t back = 0;
421 
422  constexpr uint32_t width() const { return right - left; }
423  constexpr uint32_t height() const { return bottom - top; }
424  constexpr uint32_t depth() const { return back - front; }
425  };
426 
431  {
435  void *data = nullptr;
440  uint32_t row_pitch = 0;
445  uint32_t slice_pitch = 0;
446  };
447 
451  enum class render_pass_load_op : uint32_t
452  {
453  load,
454  clear,
455  discard,
456  no_access
457  };
458 
462  enum class render_pass_store_op : uint32_t
463  {
464  store,
465  discard,
466  no_access
467  };
468 
473  {
497  float clear_depth = 0.0f;
501  uint8_t clear_stencil = 0;
502  };
503 
508  {
524  float clear_color[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
525  };
526 }
Definition: reshade_api.hpp:11
resource_view_type
The available resource view types. These identify how a resource view interprets the data of its reso...
Definition: reshade_api_resource.hpp:321
compare_op
The available comparison types.
Definition: reshade_api_resource.hpp:35
render_pass_store_op
Specifies how the contents of a render target or depth-stencil view are treated at the end of a rende...
Definition: reshade_api_resource.hpp:463
resource_type
The available resource types. The type of a resource is specified during creation and is immutable....
Definition: reshade_api_resource.hpp:167
memory_heap
The available memory heap types, which give a hint as to where to place the memory allocation for a r...
Definition: reshade_api_resource.hpp:151
render_pass_load_op
Specifies how the contents of a render target or depth-stencil view are treated at the start of a ren...
Definition: reshade_api_resource.hpp:452
map_access
The available memory mapping access types.
Definition: reshade_api_resource.hpp:140
format
The available data and texture formats. This is mostly compatible with 'DXGI_FORMAT'.
Definition: reshade_api_format.hpp:18
texture_address_mode
Specifies behavior of sampling with texture coordinates outside a texture resource.
Definition: reshade_api_resource.hpp:75
filter_mode
The available filtering modes used for texture sampling operations.
Definition: reshade_api_resource.hpp:50
resource_flags
A list of flags that describe additional parameters of a resource.
Definition: reshade_api_resource.hpp:180
resource_usage
A list of flags that specify how a resource is to be used. This needs to be specified during creation...
Definition: reshade_api_resource.hpp:197
#define RESHADE_DEFINE_ENUM_FLAG_OPERATORS(type)
Definition: reshade_api_resource.hpp:16
#define RESHADE_DEFINE_HANDLE(name)
Definition: reshade_api_resource.hpp:8
Describes a depth-stencil view and how it is treated at the start and end of a render pass.
Definition: reshade_api_resource.hpp:473
render_pass_load_op depth_load_op
Specifies how the depth contents of the depth-stencil view are treated at the start of the render pas...
Definition: reshade_api_resource.hpp:481
render_pass_store_op depth_store_op
Specifies how the depth contents of the depth-stencil view are treated at the end of the render pass.
Definition: reshade_api_resource.hpp:485
render_pass_store_op stencil_store_op
Specifies how the stencil contents of the depth-stencil view are treated at the end of the render pas...
Definition: reshade_api_resource.hpp:493
uint8_t clear_stencil
Value the stencil contents of the depth-stencil resource is cleared to when stencil_load_op is render...
Definition: reshade_api_resource.hpp:501
render_pass_load_op stencil_load_op
Specifies how the stencil contents of the depth-stencil view are treated at the start of the render p...
Definition: reshade_api_resource.hpp:489
resource_view view
Depth-stencil resource view.
Definition: reshade_api_resource.hpp:477
float clear_depth
Value the depth contents of the depth-stencil resource is cleared to when depth_load_op is render_pas...
Definition: reshade_api_resource.hpp:497
Describes a render target view and how it is treated at the start and end of a render pass.
Definition: reshade_api_resource.hpp:508
render_pass_store_op store_op
Specifies how the contents of the render target view are treated at the end of the render pass.
Definition: reshade_api_resource.hpp:520
resource_view view
Render target resource view.
Definition: reshade_api_resource.hpp:512
float clear_color[4]
Value the render target resource is cleared to when load_op is render_pass_load_op::clear.
Definition: reshade_api_resource.hpp:524
render_pass_load_op load_op
Specifies how the contents of the render target view are treated at the start of the render pass.
Definition: reshade_api_resource.hpp:516
Describes a resource, such as a buffer or texture.
Definition: reshade_api_resource.hpp:232
constexpr resource_desc(uint64_t size, memory_heap heap, resource_usage usage)
Definition: reshade_api_resource.hpp:234
constexpr resource_desc(uint32_t width, uint32_t height, uint16_t layers, uint16_t levels, format format, uint16_t samples, memory_heap heap, resource_usage usage, resource_flags flags=resource_flags::none)
Definition: reshade_api_resource.hpp:236
constexpr resource_desc(resource_type type, uint32_t width, uint32_t height, uint16_t depth_or_layers, uint16_t levels, format format, uint16_t samples, memory_heap heap, resource_usage usage, resource_flags flags=resource_flags::none)
Definition: reshade_api_resource.hpp:238
constexpr resource_desc()
Definition: reshade_api_resource.hpp:233
Describes a resource view, which specifies how to interpret the data of a resource.
Definition: reshade_api_resource.hpp:339
constexpr resource_view_desc(resource_view_type type, format format, uint32_t first_level, uint32_t levels, uint32_t first_layer, uint32_t layers)
Definition: reshade_api_resource.hpp:345
constexpr resource_view_desc()
Definition: reshade_api_resource.hpp:340
constexpr resource_view_desc(format format)
Definition: reshade_api_resource.hpp:347
constexpr resource_view_desc(format format, uint32_t first_level, uint32_t levels, uint32_t first_layer, uint32_t layers)
Definition: reshade_api_resource.hpp:343
constexpr resource_view_desc(format format, uint64_t offset, uint64_t size)
Definition: reshade_api_resource.hpp:341
An opaque handle to a resource view object (depth-stencil, render target, shader resource view,...
Definition: reshade_api_resource.hpp:408
An opaque handle to a resource object (buffer, texture, ...).
Definition: reshade_api_resource.hpp:315
Describes a sampler state.
Definition: reshade_api_resource.hpp:87
filter_mode filter
Filtering mode to use when sampling a texture.
Definition: reshade_api_resource.hpp:91
float mip_lod_bias
Offset applied to the calculated mipmap level when sampling a texture.
Definition: reshade_api_resource.hpp:107
texture_address_mode address_u
Method to use for resolving U texture coordinates outside 0 to 1 range.
Definition: reshade_api_resource.hpp:95
float max_lod
Upper end of the mipmap range to clamp access to.
Definition: reshade_api_resource.hpp:127
float border_color[4]
RGBA value to return for texture coordinates outside 0 to 1 range when addressing mode is texture_add...
Definition: reshade_api_resource.hpp:119
float min_lod
Lower end of the mipmap range to clamp access to.
Definition: reshade_api_resource.hpp:123
float max_anisotropy
Clamping value to use when filtering mode is filter_mode::anisotropic.
Definition: reshade_api_resource.hpp:111
texture_address_mode address_v
Method to use for resolving V texture coordinates outside 0 to 1 range.
Definition: reshade_api_resource.hpp:99
texture_address_mode address_w
Method to use for resolving W texture coordinates outside 0 to 1 range.
Definition: reshade_api_resource.hpp:103
An opaque handle to a sampler state object.
Definition: reshade_api_resource.hpp:134
Describes a region inside a subresource.
Definition: reshade_api_resource.hpp:414
int32_t right
Definition: reshade_api_resource.hpp:418
int32_t bottom
Definition: reshade_api_resource.hpp:419
constexpr uint32_t height() const
Definition: reshade_api_resource.hpp:423
int32_t back
Definition: reshade_api_resource.hpp:420
int32_t left
Definition: reshade_api_resource.hpp:415
int32_t top
Definition: reshade_api_resource.hpp:416
int32_t front
Definition: reshade_api_resource.hpp:417
constexpr uint32_t width() const
Definition: reshade_api_resource.hpp:422
constexpr uint32_t depth() const
Definition: reshade_api_resource.hpp:424
Describes the data of a subresource.
Definition: reshade_api_resource.hpp:431
uint32_t slice_pitch
Depth pitch of the data (added to the data pointer to move between texture depth/array slices,...
Definition: reshade_api_resource.hpp:445
void * data
Pointer to the data.
Definition: reshade_api_resource.hpp:435
uint32_t row_pitch
Row pitch of the data (added to the data pointer to move between texture rows, unused for buffers and...
Definition: reshade_api_resource.hpp:440