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,
60  anisotropic = 0x55,
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 
147 
151  enum class map_access
152  {
153  read_only = 1,
154  write_only,
155  read_write,
157  };
158 
162  enum class memory_heap : uint32_t
163  {
167  unknown,
171  default_,
175  upload,
179  readback,
183  custom = 5,
187  scratch = 4,
191  gpu_upload = 6,
192 
193  gpu_only [[deprecated("use 'memory_heap::default_' instead")]] = default_,
194  cpu_to_gpu [[deprecated("use 'memory_heap::upload' instead")]] = upload,
195  gpu_to_cpu [[deprecated("use 'memory_heap::readback' instead")]] = readback,
196  cpu_only [[deprecated("use 'memory_heap::scratch' instead")]] = scratch,
197  };
198 
203  enum class resource_type : uint32_t
204  {
205  unknown,
206  buffer,
207  texture_1d,
208  texture_2d,
209  texture_3d,
210  surface, // Special type for resources that are implicitly both resource and render target view.
211  };
212 
216  enum class resource_flags : uint32_t
217  {
218  none = 0,
223  dynamic = 0x8,
228  immutable = 0x10,
232  cube_compatible = 0x4,
236  generate_mipmaps = 0x1,
241  shared = 0x2,
242  shared_nt_handle = 0x800,
246  sparse_binding = 0x40000,
247  };
249 
254  enum class resource_usage : uint32_t
255  {
256  undefined = 0,
257 
258  index_buffer = 0x2,
259  vertex_buffer = 0x1,
260  constant_buffer = 0x8000,
261  stream_output = 0x100,
262  indirect_argument = 0x200,
263 
264  depth_stencil = 0x30,
265  depth_stencil_read = 0x20,
266  depth_stencil_write = 0x10,
267  render_target = 0x4,
268  shader_resource = 0xC0,
269  shader_resource_pixel = 0x80,
271  unordered_access = 0x8,
272 
273  copy_dest = 0x400,
274  copy_source = 0x800,
275  resolve_dest = 0x1000,
276  resolve_source = 0x2000,
277 
278  acceleration_structure = 0x400000,
279 
280  // The following are special resource states and may only be used in barriers:
281 
282  general = 0x80000000,
283  present = 0x80000000 | render_target | copy_source,
285  };
287 
291  struct [[nodiscard]] resource_desc
292  {
293  constexpr resource_desc() : texture({ 0, 0, 0, 0, format::unknown, 0 }) {}
294  constexpr resource_desc(uint64_t size, memory_heap heap, resource_usage usage, resource_flags flags = resource_flags::none) :
295  type(resource_type::buffer), buffer({ size }), heap(heap), usage(usage), flags(flags) {}
296  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) :
297  type(resource_type::texture_2d), texture({ width, height, layers, levels, format, samples }), heap(heap), usage(usage), flags(flags) {}
298  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) :
299  type(type), texture({ width, height, depth_or_layers, levels, format, samples }), heap(heap), usage(usage), flags(flags) {}
300 
305 
306  union
307  {
311  struct
312  {
316  uint64_t size = 0;
317 
318  struct
319  {
323  uint32_t stride = 0;
324  } structured;
326 
330  struct
331  {
335  uint32_t width = 1;
339  uint32_t height = 1;
343  uint16_t depth_or_layers = 1;
348  uint16_t levels = 1;
356  uint16_t samples = 1;
357  } texture;
358  };
359 
373  };
374 
391 
395  enum class resource_view_type : uint32_t
396  {
397  unknown,
398  buffer,
399  texture_1d,
401  texture_2d,
405  texture_3d,
406  texture_cube,
409  };
410 
414  struct [[nodiscard]] resource_view_desc
415  {
416  constexpr resource_view_desc() : texture({ 0, 0, 0, 0 }) {}
417  constexpr resource_view_desc(format format, uint64_t offset, uint64_t size) :
418  type(resource_view_type::buffer), format(format), buffer({ offset, size }) {}
419  constexpr resource_view_desc(format format, uint32_t first_level, uint32_t levels, uint32_t first_layer, uint32_t layers) :
420  type(resource_view_type::texture_2d), format(format), texture({ first_level, levels, first_layer, layers }) {}
421  constexpr resource_view_desc(resource_view_type type, format format, uint64_t offset, uint64_t size) :
422  type(type), format(format), buffer({ offset, size }) {}
423  constexpr resource_view_desc(resource_view_type type, format format, uint32_t first_level, uint32_t levels, uint32_t first_layer, uint32_t layers) :
424  type(type), format(format), texture({ first_level, levels, first_layer, layers }) {}
425  constexpr explicit resource_view_desc(format format) : type(resource_view_type::texture_2d), format(format), texture({ 0, 1, 0, 1 }) {}
426 
437 
438  union
439  {
443  struct
444  {
448  uint64_t offset = 0;
449 
450  union
451  {
456  uint64_t size = UINT64_MAX;
457 
461  struct
462  {
466  uint32_t count;
470  uint32_t stride;
471  } structured;
472  };
474 
478  struct
479  {
483  uint32_t first_level = 0;
488  uint32_t levels = UINT32_MAX;
492  uint32_t first_layer = 0;
497  uint32_t layers = UINT32_MAX;
498  } texture;
499  };
500  };
501 
518 
523  {
524  uint32_t left = 0;
525  uint32_t top = 0;
526  uint32_t front = 0;
527  uint32_t right = 0;
528  uint32_t bottom = 0;
529  uint32_t back = 0;
530 
531  constexpr uint32_t width() const { return right - left; }
532  constexpr uint32_t height() const { return bottom - top; }
533  constexpr uint32_t depth() const { return back - front; }
534  };
535 
540  {
544  void *data = nullptr;
549  uint32_t row_pitch = 0;
554  uint32_t slice_pitch = 0;
555  };
556 
560  enum class render_pass_flags : uint32_t
561  {
562  none = 0,
563  resume = 0x4,
564  suspend = 0x2,
565  };
567 
571  enum class render_pass_load_op : uint32_t
572  {
573  load,
574  clear,
575  discard,
576  no_access,
577  };
578 
582  enum class render_pass_store_op : uint32_t
583  {
584  store,
585  discard,
586  no_access,
587  };
588 
593  {
617  float clear_depth = 0.0f;
621  uint8_t clear_stencil = 0;
622  };
623 
628  {
644  float clear_color[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
645  };
646 
651  {
652  generic = 2,
653  top_level = 0,
654  bottom_level = 1,
655  };
656 
661  {
662  clone = 0,
663  compact = 1,
664  serialize = 2,
665  deserialize = 3,
666  };
667 
672  {
673  build = 0,
674  update = 1,
675  };
676 
681  {
682  none = 0,
683  allow_update = 0x1,
684  allow_compaction = 0x2,
685  prefer_fast_trace = 0x4,
686  prefer_fast_build = 0x8,
687  minimize_memory_usage = 0x10,
688  };
690 
695  {
696  triangles = 0,
697  aabbs = 1,
698  instances = 2,
699  };
700 
705  {
706  none = 0,
707  opaque = 0x1,
709  };
711 
717  {
718  float transform[3][4];
719  uint32_t custom_index : 24;
720  uint32_t mask : 8;
722  uint32_t flags : 8;
724  };
725 
730  {
732  constexpr acceleration_structure_build_input(resource vertex_buffer, uint64_t vertex_offset, uint32_t vertex_count, uint64_t vertex_stride, format vertex_format, resource index_buffer, uint64_t index_offset, uint32_t index_count, 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 }) {}
733  constexpr acceleration_structure_build_input(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 }) {}
734  constexpr acceleration_structure_build_input(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 }) {}
735 
740 
741  union
742  {
746  struct
747  {
749  uint64_t vertex_offset = 0;
750  uint32_t vertex_count = 0;
751  uint64_t vertex_stride = 0;
752  format vertex_format = api::format::unknown;
753 
755  uint64_t index_offset = 0;
756  uint32_t index_count = 0;
757  format index_format = api::format::unknown;
758 
759  resource transform_buffer = {};
760  uint64_t transform_offset = 0;
762 
766  struct
767  {
769  uint64_t offset = 0;
770  uint32_t count = 0;
771  uint64_t stride = 0;
772  } aabbs;
773 
777  struct
778  {
779  resource buffer = {};
780  uint64_t offset = 0;
781  uint32_t count = 0;
782  bool array_of_pointers = false;
784  };
785 
790  };
791 }
Definition: reshade_api.hpp:11
resource_view_type
Type of a resource view. This identifies how a resource view interprets the data of its resource.
Definition: reshade_api_resource.hpp:396
acceleration_structure_build_mode
Type of an acceleration structure build operation.
Definition: reshade_api_resource.hpp:672
acceleration_structure_type
Type of an acceleration structure.
Definition: reshade_api_resource.hpp:651
compare_op
Comparison operations.
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:583
resource_type
Type of a resource. This is specified during creation and is immutable. Various operations may have s...
Definition: reshade_api_resource.hpp:204
memory_heap
Memory heap types, which give a hint as to where to place the allocation for a resource.
Definition: reshade_api_resource.hpp:163
@ default_
The default heap, which the GPU can read and write, but the CPU does not have access.
@ upload
This heap has CPU access optimized for uploading to the GPU.
@ custom
This heap has custom properties not covered by the other types.
@ scratch
This heap is only accessible by the CPU.
@ readback
This heap has CPU access optimized for reading data back from the GPU.
@ unknown
Usually indicates a resource that is reserved, but not yet bound to any memory.
@ gpu_upload
CPU visible GPU memory, when available (Resizable BAR).
acceleration_structure_build_input_type
Type of an acceleration structure structure build input.
Definition: reshade_api_resource.hpp:695
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:572
render_pass_flags
Flags that specify additional parameters of a render pass.
Definition: reshade_api_resource.hpp:561
map_access
Memory mapping access types.
Definition: reshade_api_resource.hpp:152
acceleration_structure_copy_mode
Type of an acceleration structure copy operation.
Definition: reshade_api_resource.hpp:661
acceleration_structure_build_flags
Flags that specify additional parameters to an acceleration structure build operation.
Definition: reshade_api_resource.hpp:681
acceleration_structure_build_input_flags
Flags that specify additional parameters of an acceleration structure build input.
Definition: reshade_api_resource.hpp:705
@ flags
Additional pipeline creation flags. Sub-object data is a pointer to a pipeline_flags value.
format
Available data and texture formats. This is mostly compatible with 'DXGI_FORMAT'.
Definition: reshade_api_format.hpp:18
texture_address_mode
Sampling behavior at texture coordinates outside the bounds of a texture resource.
Definition: reshade_api_resource.hpp:77
filter_mode
Texture filtering modes available for texture sampling operations.
Definition: reshade_api_resource.hpp:50
resource_flags
Flags that specify additional parameters of a resource.
Definition: reshade_api_resource.hpp:217
@ generate_mipmaps
Required to use the resource with command_list::generate_mipmaps.
@ immutable
Immutable resources can never be written to again after creationn, either by the CPU or the GPU....
@ shared
Shared resources can be imported/exported from/to different graphics APIs and/or processes....
@ cube_compatible
Required to create resource_view_type::texture_cube or resource_view_type::texture_cube_array views o...
@ dynamic
Dynamic resources can be frequently updated during a frame, with previous contents automatically bein...
@ sparse_binding
Resource is backed by sparse memory.
resource_usage
Flags that specify how a resource is used. This needs to be specified during creation and is also use...
Definition: reshade_api_resource.hpp:255
#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 operation.
Definition: reshade_api_resource.hpp:730
constexpr acceleration_structure_build_input()
Definition: reshade_api_resource.hpp:731
constexpr acceleration_structure_build_input(resource instance_buffer, uint64_t instance_offset, uint32_t instance_count, bool array_of_pointers=false)
Definition: reshade_api_resource.hpp:734
constexpr acceleration_structure_build_input(resource aabb_buffer, uint64_t aabb_offset, uint32_t aabb_count, uint64_t aabb_stride)
Definition: reshade_api_resource.hpp:733
constexpr acceleration_structure_build_input(resource vertex_buffer, uint64_t vertex_offset, uint32_t vertex_count, uint64_t vertex_stride, format vertex_format, resource index_buffer, uint64_t index_offset, uint32_t index_count, format index_format, uint64_t transform_address=0)
Definition: reshade_api_resource.hpp:732
Describes a single instance in a top-level acceleration structure. The data in acceleration_structure...
Definition: reshade_api_resource.hpp:717
uint32_t shader_binding_table_offset
Definition: reshade_api_resource.hpp:721
uint32_t mask
Definition: reshade_api_resource.hpp:720
uint32_t flags
Definition: reshade_api_resource.hpp:722
uint32_t custom_index
Definition: reshade_api_resource.hpp:719
uint64_t acceleration_structure_gpu_address
Definition: reshade_api_resource.hpp:723
Describes a depth-stencil view and how it is treated at the start and end of a render pass.
Definition: reshade_api_resource.hpp:593
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:601
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:605
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:613
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:621
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:609
resource_view view
Depth-stencil resource view.
Definition: reshade_api_resource.hpp:597
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:617
Describes a render target view and how it is treated at the start and end of a render pass.
Definition: reshade_api_resource.hpp:628
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:640
resource_view view
Render target resource view.
Definition: reshade_api_resource.hpp:632
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:644
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:636
Describes a resource, such as a buffer or texture.
Definition: reshade_api_resource.hpp:292
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:296
constexpr resource_desc(uint64_t size, memory_heap heap, resource_usage usage, resource_flags flags=resource_flags::none)
Definition: reshade_api_resource.hpp:294
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:298
constexpr resource_desc()
Definition: reshade_api_resource.hpp:293
Describes a resource view, which specifies how to interpret the data of a resource.
Definition: reshade_api_resource.hpp:415
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:423
constexpr resource_view_desc()
Definition: reshade_api_resource.hpp:416
uint32_t stride
Structure stride for structured buffers (in bytes).
Definition: reshade_api_resource.hpp:470
constexpr resource_view_desc(format format)
Definition: reshade_api_resource.hpp:425
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:419
constexpr resource_view_desc(format format, uint64_t offset, uint64_t size)
Definition: reshade_api_resource.hpp:417
constexpr resource_view_desc(resource_view_type type, format format, uint64_t offset, uint64_t size)
Definition: reshade_api_resource.hpp:421
uint32_t count
Number of elements this view covers for structured buffers.
Definition: reshade_api_resource.hpp:466
An opaque handle to a resource view object (depth-stencil, render target, shader resource view,...
Definition: reshade_api_resource.hpp:517
An opaque handle to a resource object (buffer, texture, ...).
Definition: reshade_api_resource.hpp:390
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:146
Describes a region inside a subresource.
Definition: reshade_api_resource.hpp:523
uint32_t right
Definition: reshade_api_resource.hpp:527
constexpr uint32_t height() const
Definition: reshade_api_resource.hpp:532
uint32_t left
Definition: reshade_api_resource.hpp:524
uint32_t back
Definition: reshade_api_resource.hpp:529
uint32_t bottom
Definition: reshade_api_resource.hpp:528
uint32_t top
Definition: reshade_api_resource.hpp:525
uint32_t front
Definition: reshade_api_resource.hpp:526
constexpr uint32_t width() const
Definition: reshade_api_resource.hpp:531
constexpr uint32_t depth() const
Definition: reshade_api_resource.hpp:533
Describes the data of a subresource.
Definition: reshade_api_resource.hpp:540
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:554
void * data
Pointer to the data.
Definition: reshade_api_resource.hpp:544
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:549