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 { namespace 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,
60  anisotropic = 0x55,
70  compare_anisotropic = 0xd5
71  };
72 
76  enum class texture_address_mode : uint32_t
77  {
78  wrap = 1,
79  mirror = 2,
80  clamp = 3,
81  border = 4,
82  mirror_once = 5
83  };
84 
88  struct sampler_desc
89  {
109  float mip_lod_bias = 0.0f;
113  float max_anisotropy = 1.0f;
121  float border_color[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
125  float min_lod = -FLT_MAX;
129  float max_lod = +FLT_MAX;
130  };
131 
137 
141  enum class map_access
142  {
143  read_only = 1,
144  write_only,
145  read_write,
147  };
148 
152  enum class memory_heap : uint32_t
153  {
154  unknown, // Usually indicates a resource that is reserved, but not yet bound to any memory.
155  gpu_only,
156  // Upload heap
157  cpu_to_gpu,
158  // Readback heap
159  gpu_to_cpu,
160  cpu_only,
161  custom
162  };
163 
168  enum class resource_type : uint32_t
169  {
170  unknown,
171  buffer,
172  texture_1d,
173  texture_2d,
174  texture_3d,
175  surface // Special type for resources that are implicitly both resource and render target view.
176  };
177 
181  enum class resource_flags : uint32_t
182  {
183  none = 0,
184  dynamic = (1 << 3),
185  cube_compatible = (1 << 2),
186  generate_mipmaps = (1 << 0),
187  shared = (1 << 1),
188  shared_nt_handle = (1 << 11),
189  structured = (1 << 6),
190  sparse_binding = (1 << 18)
191  };
193 
198  enum class resource_usage : uint32_t
199  {
200  undefined = 0,
201 
202  index_buffer = 0x2,
203  vertex_buffer = 0x1,
204  constant_buffer = 0x8000,
205  stream_output = 0x100,
206  indirect_argument = 0x200,
207 
208  depth_stencil = 0x30,
209  depth_stencil_read = 0x20,
210  depth_stencil_write = 0x10,
211  render_target = 0x4,
212  shader_resource = 0xC0,
213  shader_resource_pixel = 0x80,
215  unordered_access = 0x8,
216 
217  copy_dest = 0x400,
218  copy_source = 0x800,
219  resolve_dest = 0x1000,
220  resolve_source = 0x2000,
221 
222  acceleration_structure = 0x400000,
223 
224  // The following are special resource states and may only be used in barriers:
225 
226  general = 0x80000000,
227  present = 0x80000000 | render_target | copy_source,
229  };
231 
235  struct [[nodiscard]] resource_desc
236  {
237  constexpr resource_desc() : texture() {}
238  constexpr resource_desc(uint64_t size, memory_heap heap, resource_usage usage) :
239  type(resource_type::buffer), buffer({ size }), heap(heap), usage(usage) {}
240  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) :
241  type(resource_type::texture_2d), texture({ width, height, layers, levels, format, samples }), heap(heap), usage(usage), flags(flags) {}
242  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) :
243  type(type), texture({ width, height, depth_or_layers, levels, format, samples }), heap(heap), usage(usage), flags(flags) {}
244 
249 
250  union
251  {
255  struct
256  {
260  uint64_t size = 0;
264  uint32_t stride = 0;
266 
270  struct
271  {
275  uint32_t width = 1;
279  uint32_t height = 1;
283  uint16_t depth_or_layers = 1;
288  uint16_t levels = 1;
296  uint16_t samples = 1;
297  } texture;
298  };
299 
313  };
314 
321 
325  enum class resource_view_type : uint32_t
326  {
327  unknown,
328  buffer,
329  texture_1d,
331  texture_2d,
335  texture_3d,
336  texture_cube,
339  };
340 
344  struct [[nodiscard]] resource_view_desc
345  {
346  constexpr resource_view_desc() : texture() {}
347  constexpr resource_view_desc(format format, uint64_t offset, uint64_t size) :
348  type(resource_view_type::buffer), format(format), buffer({ offset, size }) {}
349  constexpr resource_view_desc(format format, uint32_t first_level, uint32_t levels, uint32_t first_layer, uint32_t layers) :
350  type(resource_view_type::texture_2d), format(format), texture({ first_level, levels, first_layer, layers }) {}
351  constexpr resource_view_desc(resource_view_type type, format format, uint64_t offset, uint64_t size) :
352  type(type), format(format), buffer({ offset, size }) {}
353  constexpr resource_view_desc(resource_view_type type, format format, uint32_t first_level, uint32_t levels, uint32_t first_layer, uint32_t layers) :
354  type(type), format(format), texture({ first_level, levels, first_layer, layers }) {}
355  constexpr explicit resource_view_desc(format format) : type(resource_view_type::texture_2d), format(format), texture({ 0, 1, 0, 1 }) {}
356 
365 
366  union
367  {
371  struct
372  {
376  uint64_t offset = 0;
381  uint64_t size = UINT64_MAX;
383 
387  struct
388  {
392  uint32_t first_level = 0;
397  uint32_t level_count = UINT32_MAX;
401  uint32_t first_layer = 0;
406  uint32_t layer_count = UINT32_MAX;
407  } texture;
408  };
409  };
410 
417 
422  {
423  int32_t left = 0;
424  int32_t top = 0;
425  int32_t front = 0;
426  int32_t right = 0;
427  int32_t bottom = 0;
428  int32_t back = 0;
429 
430  constexpr uint32_t width() const { return right - left; }
431  constexpr uint32_t height() const { return bottom - top; }
432  constexpr uint32_t depth() const { return back - front; }
433  };
434 
439  {
443  void *data = nullptr;
448  uint32_t row_pitch = 0;
453  uint32_t slice_pitch = 0;
454  };
455 
459  enum class render_pass_load_op : uint32_t
460  {
461  load,
462  clear,
463  discard,
464  no_access
465  };
466 
470  enum class render_pass_store_op : uint32_t
471  {
472  store,
473  discard,
474  no_access
475  };
476 
481  {
505  float clear_depth = 0.0f;
509  uint8_t clear_stencil = 0;
510  };
511 
516  {
532  float clear_color[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
533  };
534 
539  {
540  top_level = 0,
541  bottom_level = 1,
542  generic = 2
543  };
544 
549  {
550  clone = 0,
551  compact = 1,
552  serialize = 2,
553  deserialize = 3
554  };
555 
560  {
561  build = 0,
562  update = 1
563  };
564 
569  {
570  none = 0,
571  allow_update = (1 << 0),
572  allow_compaction = (1 << 1),
573  prefer_fast_trace = (1 << 2),
574  prefer_fast_build = (1 << 3),
575  minimize_memory_usage = (1 << 4)
576  };
578 
583  {
584  triangles = 0,
585  aabbs = 1,
586  instances = 2
587  };
588 
593  {
594  none = 0,
595  opaque = (1 << 0),
597  };
599 
605  {
606  float transform[3][4];
607  uint32_t custom_index : 24;
608  uint32_t mask : 8;
610  uint32_t flags : 8;
612  };
613 
618  {
620  constexpr acceleration_structure_build_input(api::resource vertex_buffer, uint64_t vertex_offset, uint32_t vertex_count, uint64_t vertex_stride, api::format vertex_format, api::resource index_buffer, uint64_t index_offset, uint32_t index_count, api::format index_format, uint64_t transform_address = 0) : type(acceleration_structure_build_input_type::triangles), triangles({ vertex_buffer, vertex_offset, vertex_count, vertex_stride, vertex_format, index_buffer, index_offset, index_count, index_format, transform_address }) {}
621  constexpr acceleration_structure_build_input(api::resource aabb_buffer, uint64_t aabb_offset, uint32_t aabb_count, uint64_t aabb_stride) : type(acceleration_structure_build_input_type::aabbs), aabbs({ aabb_buffer, aabb_offset, aabb_count, aabb_stride }) {}
622  constexpr acceleration_structure_build_input(api::resource instance_buffer, uint64_t instance_offset, uint32_t instance_count, bool array_of_pointers = false) : type(acceleration_structure_build_input_type::instances), instances({ instance_buffer, instance_offset, instance_count, array_of_pointers }) {}
623 
628 
629  union
630  {
634  struct
635  {
637  uint64_t vertex_offset = 0;
638  uint32_t vertex_count = 0;
639  uint64_t vertex_stride = 0;
642  uint64_t index_offset = 0;
643  uint32_t index_count = 0;
645  api::resource transform_buffer = {};
646  uint64_t transform_offset = 0;
648 
652  struct
653  {
655  uint64_t offset = 0;
656  uint32_t count = 0;
657  uint64_t stride = 0;
658  } aabbs;
659 
663  struct
664  {
665  api::resource buffer = {};
666  uint64_t offset = 0;
667  uint32_t count = 0;
668  bool array_of_pointers = false;
670  };
671 
676  };
677 } }
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:326
acceleration_structure_build_mode
The available acceleration structure build modes.
Definition: reshade_api_resource.hpp:560
acceleration_structure_type
The available acceleration structure types.
Definition: reshade_api_resource.hpp:539
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:471
resource_type
The available resource types. The type of a resource is specified during creation and is immutable....
Definition: reshade_api_resource.hpp:169
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:153
acceleration_structure_build_input_type
The available acceleration structure build input types.
Definition: reshade_api_resource.hpp:583
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:460
map_access
The available memory mapping access types.
Definition: reshade_api_resource.hpp:142
acceleration_structure_copy_mode
The available acceleration structure copy modes.
Definition: reshade_api_resource.hpp:549
acceleration_structure_build_flags
The available acceleration structure build flags.
Definition: reshade_api_resource.hpp:569
acceleration_structure_build_input_flags
The available acceleration structure build input flags.
Definition: reshade_api_resource.hpp:593
@ flags
Additional pipeline creation flags. Sub-object data is a pointer to a pipeline_flags value.
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:77
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:182
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:199
Definition: reshade.hpp:52
#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 build input for an acceleration structure build.
Definition: reshade_api_resource.hpp:618
constexpr acceleration_structure_build_input()
Definition: reshade_api_resource.hpp:619
constexpr acceleration_structure_build_input(api::resource vertex_buffer, uint64_t vertex_offset, uint32_t vertex_count, uint64_t vertex_stride, api::format vertex_format, api::resource index_buffer, uint64_t index_offset, uint32_t index_count, api::format index_format, uint64_t transform_address=0)
Definition: reshade_api_resource.hpp:620
constexpr acceleration_structure_build_input(api::resource instance_buffer, uint64_t instance_offset, uint32_t instance_count, bool array_of_pointers=false)
Definition: reshade_api_resource.hpp:622
constexpr acceleration_structure_build_input(api::resource aabb_buffer, uint64_t aabb_offset, uint32_t aabb_count, uint64_t aabb_stride)
Definition: reshade_api_resource.hpp:621
Describes an instance in a top-level acceleration structure. The data in acceleration_structure_build...
Definition: reshade_api_resource.hpp:605
uint32_t shader_binding_table_offset
Definition: reshade_api_resource.hpp:609
uint32_t mask
Definition: reshade_api_resource.hpp:608
uint32_t flags
Definition: reshade_api_resource.hpp:610
uint32_t custom_index
Definition: reshade_api_resource.hpp:607
uint64_t acceleration_structure_gpu_address
Definition: reshade_api_resource.hpp:611
Describes a depth-stencil view and how it is treated at the start and end of a render pass.
Definition: reshade_api_resource.hpp:481
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:489
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:493
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:501
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:509
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:497
resource_view view
Depth-stencil resource view.
Definition: reshade_api_resource.hpp:485
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:505
Describes a render target view and how it is treated at the start and end of a render pass.
Definition: reshade_api_resource.hpp:516
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:528
resource_view view
Render target resource view.
Definition: reshade_api_resource.hpp:520
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:532
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:524
Describes a resource, such as a buffer or texture.
Definition: reshade_api_resource.hpp:236
constexpr resource_desc(uint64_t size, memory_heap heap, resource_usage usage)
Definition: reshade_api_resource.hpp:238
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:240
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:242
constexpr resource_desc()
Definition: reshade_api_resource.hpp:237
Describes a resource view, which specifies how to interpret the data of a resource.
Definition: reshade_api_resource.hpp: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)
Definition: reshade_api_resource.hpp:353
constexpr resource_view_desc()
Definition: reshade_api_resource.hpp:346
constexpr resource_view_desc(format format)
Definition: reshade_api_resource.hpp:355
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:349
constexpr resource_view_desc(format format, uint64_t offset, uint64_t size)
Definition: reshade_api_resource.hpp:347
constexpr resource_view_desc(resource_view_type type, format format, uint64_t offset, uint64_t size)
Definition: reshade_api_resource.hpp:351
An opaque handle to a resource view object (depth-stencil, render target, shader resource view,...
Definition: reshade_api_resource.hpp:416
An opaque handle to a resource object (buffer, texture, ...).
Definition: reshade_api_resource.hpp:320
Describes a sampler state.
Definition: reshade_api_resource.hpp:89
filter_mode filter
Filtering mode to use when sampling a texture.
Definition: reshade_api_resource.hpp:93
float mip_lod_bias
Offset applied to the calculated mipmap level when sampling a texture.
Definition: reshade_api_resource.hpp:109
texture_address_mode address_u
Method to use for resolving U texture coordinates outside 0 to 1 range.
Definition: reshade_api_resource.hpp:97
float max_lod
Upper end of the mipmap range to clamp access to.
Definition: reshade_api_resource.hpp:129
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:121
float min_lod
Lower end of the mipmap range to clamp access to.
Definition: reshade_api_resource.hpp:125
float max_anisotropy
Clamping value to use when filtering mode is filter_mode::anisotropic.
Definition: reshade_api_resource.hpp:113
texture_address_mode address_v
Method to use for resolving V texture coordinates outside 0 to 1 range.
Definition: reshade_api_resource.hpp:101
texture_address_mode address_w
Method to use for resolving W texture coordinates outside 0 to 1 range.
Definition: reshade_api_resource.hpp:105
An opaque handle to a sampler state object.
Definition: reshade_api_resource.hpp:136
Describes a region inside a subresource.
Definition: reshade_api_resource.hpp:422
int32_t right
Definition: reshade_api_resource.hpp:426
int32_t bottom
Definition: reshade_api_resource.hpp:427
constexpr uint32_t height() const
Definition: reshade_api_resource.hpp:431
int32_t back
Definition: reshade_api_resource.hpp:428
int32_t left
Definition: reshade_api_resource.hpp:423
int32_t top
Definition: reshade_api_resource.hpp:424
int32_t front
Definition: reshade_api_resource.hpp:425
constexpr uint32_t width() const
Definition: reshade_api_resource.hpp:430
constexpr uint32_t depth() const
Definition: reshade_api_resource.hpp:432
Describes the data of a subresource.
Definition: reshade_api_resource.hpp:439
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:453
void * data
Pointer to the data.
Definition: reshade_api_resource.hpp:443
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:448