ReShade
A generic post-processing injector for games and video software.
|
The ReShade API lets you interact with the resources and rendering commands of applications ReShade was loaded into. It abstracts away differences between the various graphics API ReShade supports (Direct3D 9/10/11/12, OpenGL and Vulkan), to make it possible to write add-ons that work across a wide range of applications, regardless of the graphics API they use.
A ReShade add-on is a DLL or part of the application that uses the header-only ReShade API to register callbacks for events and do work in those callbacks after they were invoked by ReShade. There are no further requirements, no functions need to be exported and no libraries need to be linked against (although linking against ReShade is supported as well by defining RESHADE_API_LIBRARY
before including the headers if so desired). Simply add the include directory from the ReShade repository to your project and include the reshade.hpp
header to get started.
An add-on may optionally export an AddonInit
function if more complicated one-time initialization than possible in DllMain
is required. It will be called by ReShade right after loading the add-on module.
Similarily it may also export an AddonUninit
function, which will be called right before unloading (but only if initialization was successfull).
Here is a very basic code example of an add-on that registers a callback that gets executed every time a new frame is presented to the screen:
After building an add-on DLL, change its file extension from .dll
to .addon
and put it into the add-on search directory configured in ReShade (which defaults to the same directory as ReShade). It will be picked up and loaded automatically on the next launch of the application.
For more complex examples, see the examples directory in the repository. Contents of this document:
The graphics API abstraction is modeled after the Direct3D 12 and Vulkan APIs, so much of the terminology used should be familiar to developers that have used those before.
Detailed inline documentation for all classes and methods can be found inside the headers (see reshade_api_device.hpp
for the abstraction object classes and reshade_events.hpp
for a list of available events).
The base object everything else is created from is a reshade::api::device
. This represents a logical rendering device that is typically mapped to a physical GPU (but may also be mapped to multiple GPUs). ReShade will call the reshade::addon_event::init_device
event after the application created a device, which can e.g. be used to do some initialization work that only has to happen once. The reshade::addon_event::destroy_device
event is called before this device is destroyed again, which can be used to perform clean up work.
To execute rendering commands (like draw/dispatch commands), an application has to record them into a reshade::api::command_list
and then submit to a reshade::api::command_queue
. In some graphics APIs there is only a single implicit command list and queue, but modern ones like Direct3D 12 and Vulkan allow the creation of multiple for more efficient multi-threaded rendering. ReShade will call the reshade::addon_event::init_command_list
and reshade::addon_event::init_command_queue
events after any such object was created by the application (including the implicit ones for older graphics APIs). Similarily, reshade::addon_event::destroy_command_list
and reshade::addon_event::destroy_command_queue
are called upon their destruction.
ReShade will also pass the current command list object to every command event, like reshade::addon_event::draw
, reshade::addon_event::dispatch
and so on, which can be used to add additional commands to that command list or replace those of the application.
Showing results on the screen is done through a reshade::api::swapchain
object. This is a collection of back buffers that the application can render into, which will eventually be presented to the screen. There may be multiple swap chains, if for example the application is rendering to multiple windows, or to a screen and a VR headset. ReShade again will call the reshade::addon_event::init_swapchain
event after such an object was created by the application (and reshade::addon_event::destroy_swapchain
on destruction). In addition ReShade will call the reshade::addon_event::create_swapchain
event before a swap chain is created, so an add-on may modify its description before that happens. For example, to force the resolution to a specific value, one can do the following:
ReShade associates an independent post-processing effect runtime with most swap chains. This is the runtime one usually controls via the ReShade overlay, but it can also be controlled programatically via the ReShade API using methods of the reshade::api::effect_runtime
object.
In contrast to the described basic API abstraction objects, any buffers, textures, pipelines, etc. are referenced via handles. These are either created by the application and passed to events (like reshade::addon_event::init_resource
, reshade::addon_event::init_pipeline
, ...) or can be created through the reshade::api::device
object of the ReShade API (via reshade::api::device::create_resource()
, reshade::api::device::create_pipeline()
, ...).
Buffers and textures are referenced via reshade::api::resource
handles. Depth-stencil, render target, shader resource or unordered access views to such resources are referenced via reshade::api::resource_view
handles. Sampler state objects are referenced via reshade::api::sampler
handles, (partial) pipeline state objects via reshade::api::pipeline
handles and so on.
It is also supported to add an overlay, which can e.g. be used to display debug information or interact with the user in-application. Overlays are created with the use of the docking branch of Dear ImGui. Including reshade.hpp
after imgui.h
will automatically overwrite all Dear ImGui functions to use the instance created and managed by ReShade. This means all you have to do is include these two headers and use Dear ImGui as usual (without having to build its source code files):
Do not call ImGui::Begin
and ImGui::End
in the callback to create the overlay window itself, ReShade already does this for you before and after calling the callback function. You can however call ImGui::Begin
and ImGui::End
with a different title to open additional popup windows (this is not recommended though, since those are difficult to navigate in VR).
Overlay names are shared across ReShade and all add-ons, which means you can register with a name already used by ReShade or another add-on to append widgets to their overlay. For example, reshade::register_overlay("###settings", ...)
allows you to add widgets to the settings page in ReShade and reshade::register_overlay("OSD", ...)
allows you to add additional information to the always visible on-screen display (clock, FPS, frametime) ReShade provides.
The concept of reshade::api::device
is functionally equivalent to ID3D12Device
in D3D12 or VkDevice
in Vulkan. The concept of reshade::api::command_list
is functionally equivalent to ID3D12CommandList
in D3D12 or VkCommandBuffer
in Vulkan. The concept of reshade::api::command_queue
is functionally equivalent to ID3D12CommandQueue
in D3D12 or VkQueue
in Vulkan.
To allocate memory and create buffers or textures, call reshade::api::device::create_resource()
. Care has to be taken to specify all the possible ways the resource is going to be used via reshade::api::resource_desc::usage
.
Resources allocated in GPU memory (reshade::api::resource_desc::heap
set to reshade::api::memory_heap::gpu_only
) cannot be mapped and accessed on the CPU, so to fill them with contents either have to specify it during resource creation via the initial data parameter or upload it via reshade::api::device::update_buffer_region()
or reshade::api::device::update_texture_region()
.\ Resources allocated in CPU-visible memory (reshade::api::resource_desc::heap
set to reshade::api::memory_heap::cpu_to_gpu
or reshade::api::memory_heap::gpu_to_cpu
) on the other hand can be mapped and directly accessed on the CPU, via reshade::api::device::map_buffer_region()
or reshade::api::device::map_texture_region()
.
The concept of reshade::api::resource
is functionally equivalent to ID3D12Resource
in D3D12 or VkBuffer
/VkImage
in Vulkan. The concept of reshade::api::resource_view
is functionally equivalent to SRV/UAV/... in D3D12 or VkBufferView
/VkImageView
in Vulkan.
Shaders and other render state is combined into monolithic pipeline state objects (reshade::api::pipeline
), which can then be bound at draw time (using reshade::api::command_list::bind_pipeline()
) to make any following draw calls make use of those shaders and render state.
To create a pipeline, call reshade::api::device::create_pipeline()
with a list of sub-objects that should be combined. This can contain graphics shaders and render state to create a graphics pipeline, or just a compute shader sub-object to create a compute pipeline, or ray tracing shaders to create a ray tracing pipeline.
In D3D9, D3D10, D3D11 and OpenGL, pipeline state objects can be partially bound, meaning reshade::api::command_list::bind_pipeline()
can be called with a subset of reshade::api::pipeline_stage
flags and only the sub-objects in the pipeline state object corresponding to those flags will be bound. In D3D12 and Vulkan pipeline state objects have to be monolithic and can only be bound as a whole, meaning the pipeline stage flags have to be reshade::api::pipeline_stage::all_graphics
(for a graphics pipeline), reshade::api::pipeline_stage::all_compute
(for a compute pipeline) or reshade::api::pipeline_stage::all_raytracing
(for a ray tracing pipeline) and only a single pipeline per these stage flags can be bound on a command list at a time.
The concept of reshade::api::pipeline
is functionally equivalent to ID3D12PipelineState
in D3D12 or VkPipeline
in Vulkan.
Binding resources and other objects to the shaders in a pipeline is done via descriptors. A descriptor is just a small handle that points to a shader resource view (reshade::api::resource_view
), a sampler object (reshade::api::sampler
) or a constant buffer resource (reshade::api::buffer_range
). These are written into fixed-size linear tables (reshade::api::descriptor_table
) in memory (reshade::api::descriptor_heap
), which can be quickly swapped at draw time (using reshade::api::command_list::bind_descriptor_tables()
). An additional layout object (reshade::api::pipeline_layout
) is needed to map the entries from these linear tables to shader registers in shaders.
Since this mapping can get pretty complex, below is an example pipeline layout description which describes just a single descriptor table and how the corresponding table would be layed out in memory:
To create a pipeline layout like the above, call reshade::api::device::create_pipeline_layout()
with a list of pipeline layout parameter descriptions. Each parameter can refer to:
reshade::api::pipeline_layout_param_type::push_constants
, which can then be referenced in reshade::api::command_list::push_constants()
via its parameter index in the pipeline layout), more on those nextreshade::api::pipeline_layout_param_type::push_descriptors
, which can then be referenced in reshade::api::command_list::push_descriptors()
via its parameter index in the pipeline layout), more on those nextreshade::api::pipeline_layout_param_type::descriptor_table
, which can then be referenced in reshade::api::command_list::bind_descriptor_table()
via its parameter index in the pipeline layout)Only a single pipeline layout per stage can be bound on a command list at a time. It is updated as part of reshade::api::command_list::bind_descriptor_tables()
, reshade::api::command_list::push_descriptors()
or reshade::api::command_list::push_constants()
.
Managing constant buffers can be cumbersome, so for use cases with just a few constants, command lists have a small memory pool built-in, which can be filled with constant data in-place at draw time and bound to a constant buffer register in shaders. These constants, written using reshade::api::command_list::push_constants()
, are called push constants (equivalent concept in D3D12 is called root constants).
Similarily, managing descriptor tables and the memory they are allocated from manually can be cumbersome, so for simple use cases, command lists also have a small descriptor heap built-in, which can be filled with descriptors in-place at draw time. The descriptors written this way, using reshade::api::command_list::push_descriptors()
without allocating a descriptor table first, are called push descriptors (since they are pushed into the command list). They are limited to a single linear list of descriptors of the same type per pipeline layout parameter however.
Since descriptor tables are effectively just sections in descriptor heap memory, reshade::api::descriptor_table
can be thought of a view into a reshade::api::descriptor_heap
, similar to how reshade::api::resource_view
are views into a reshade::api::resource
. Different views can refer to the same underlying memory, so there can be multiple reshade::api::descriptor_table
pointing to the same descriptors. To uniquely identify a descriptor, reshade::api::device::get_descriptor_heap_offset()
can be used to query its offset in the descriptor heap memory.
To allocate a new descriptor table, call reshade::api::device::allocate_descriptor_tables()
, which will do as the name implies from a descriptor heap that ReShade manages internally. The size and layout of that descriptor table is described by the passed in pipeline layout parameter. reshade::api::device::update_descriptors()
or reshade::api::device::update_descriptor_tables()
(for multiple updates at once) can then be used to fill the table with descriptors before using it.
The concept of reshade::api::pipeline_layout
is functionally equivalent to ID3D12RootSignature
in D3D12 or VkPipelineLayout
in Vulkan. The concept of reshade::api::descriptor_table
is functionally equivalent to descriptor tables in D3D12 or VkDescriptorSet
in Vulkan.