/*
* Copyright (C) 2021 Patrick Mours
* SPDX-License-Identifier: BSD-3-Clause OR MIT
*/
#pragma once
#include "reshade_api_pipeline.hpp"
namespace reshade { namespace api
{
///
/// The underlying render API a device is using, as returned by .
///
enum class device_api
{
/// Direct3D 9
/// https://docs.microsoft.com/windows/win32/direct3d9
d3d9 = 0x9000,
/// Direct3D 10
/// https://docs.microsoft.com/windows/win32/direct3d10
d3d10 = 0xa000,
/// Direct3D 11
/// https://docs.microsoft.com/windows/win32/direct3d11
d3d11 = 0xb000,
/// Direct3D 12
/// https://docs.microsoft.com/windows/win32/direct3d12
d3d12 = 0xc000,
/// OpenGL
/// https://www.khronos.org/opengl/
opengl = 0x10000,
/// Vulkan
/// https://www.khronos.org/vulkan/
vulkan = 0x20000
};
///
/// The available features a device may support.
///
enum class device_caps
{
///
/// Specifies whether compute shaders are supported.
/// If this feature is not present, the stage and must not be used.
///
compute_shader = 1,
///
/// Specifies whether geometry shaders are supported.
/// If this feature is not present, the stage must not be used.
///
geometry_shader,
///
/// Specifies whether hull and domain (tessellation) shaders are supported.
/// If this feature is not present, the and stages must not be used.
///
hull_and_domain_shader,
///
/// Specifies whether logic operations are available in the blend state.
/// If this feature is not present, the and fields are ignored.
///
logic_op,
///
/// Specifies whether blend operations which take two sources are supported.
/// If this feature is not present, , , and must not be used.
///
dual_source_blend,
///
/// Specifies whether blend state is controlled independently per render target.
/// If this feature is not present, the blend state settings for all render targets must be identical.
///
independent_blend,
///
/// Specifies whether point and wireframe fill modes are supported.
/// If this feature is not present, and must not be used.
///
fill_mode_non_solid,
///
/// Specifies whether conservative rasterization is supported.
/// If this feature is not present, the field must be 0.
///
conservative_rasterization,
///
/// Specifies whether binding individual render target and depth-stencil resource views is supported.
/// If this feature is not present, must not be used (only render passes).
///
bind_render_targets_and_depth_stencil,
///
/// Specifies whther more than one viewport is supported.
/// If this feature is not present, the "first" and "count" parameters to and must be 0 and 1.
///
multi_viewport,
///
/// Specifies whether partial push constant updates are supported.
/// If this feature is not present, the "first" parameter to must be 0 and "count" must cover the entire constant range.
///
partial_push_constant_updates,
///
/// Specifies whether partial push descriptor updates are supported.
/// If this feature is not present, the "first" parameter to must be 0 and "count" must cover the entire descriptor range.
///
partial_push_descriptor_updates,
///
/// Specifies whether instancing is supported.
/// If this feature is not present, the "instance_count" and "first_instance" parameters to and must be 1 and 0.
///
draw_instanced,
///
/// Specifies whether indirect draw or dispatch calls are supported.
/// If this feature is not present, must not be used.
///
draw_or_dispatch_indirect,
///
/// Specifies whether copying between buffers is supported.
/// If this feature is not present, must not be used.
///
copy_buffer_region,
///
/// Specifies whether copying between buffers and textures is supported.
/// If this feature is not present, and must not be used.
///
copy_buffer_to_texture,
///
/// Specifies whether blitting between resources is supported.
/// If this feature is not present, the "source_box" and "dest_box" parameters to must have the same dimensions.
///
blit,
///
/// Specifies whether resolving a region of a resource rather than its entirety is supported.
/// If this feature is not present, the "source_box", "dest_x", "dest_y" and "dest_z" parameters to must be and zero.
///
resolve_region,
///
/// Specifies whether copying query results to a buffer is supported.
/// If this feature is not present, must not be used.
///
copy_query_heap_results,
///
/// Specifies whether comparison sampling is supported.
/// If this feature is not present, the field is ignored and the compare filter types have no effect.
///
sampler_compare,
///
/// Specifies whether anisotropic filtering is supported.
/// If this feature is not present, must not be used.
///
sampler_anisotropic,
///
/// Specifies whether combined sampler and resource view descriptors are supported.
/// If this feature is not present, must not be used.
///
sampler_with_resource_view,
///
/// Specifies whether resource sharing is supported.
/// If this feature is not present, must not be used.
///
shared_resource,
///
/// Specifies whether resource sharing with NT handles is supported.
/// If this feature is not present, must not be used.
///
shared_resource_nt_handle
};
///
/// The base class for objects provided by the ReShade API.
/// This lets you store and retrieve custom data with objects, e.g. to be able to communicate persistent information between event callbacks.
///
struct __declspec(novtable) api_object
{
///
/// Gets the underlying native object for this API object.
///
///
/// For this will be be a pointer to a 'IDirect3DDevice9', 'ID3D10Device', 'ID3D11Device' or 'ID3D12Device' object or a 'HGLRC' or 'VkDevice' handle.
/// For this will be a pointer to a 'ID3D11DeviceContext' (when recording), 'ID3D11CommandList' (when executing) or 'ID3D12GraphicsCommandList' object or a 'VkCommandBuffer' handle.
/// For this will be a pointer to a 'ID3D11DeviceContext' or 'ID3D12CommandQueue' object or a 'VkQueue' handle.
/// For this will be a pointer to a 'IDirect3DSwapChain9' or 'IDXGISwapChain' object or a 'HDC' or 'VkSwapchainKHR' handle.
///
virtual uint64_t get_native() const = 0;
///
/// Gets a user-defined 64-bit value from the object that was previously set via , or zero if none associated with the specified exists.
///
virtual void get_private_data(const uint8_t guid[16], uint64_t *data) const = 0;
///
/// Stores a user-defined 64-bit value in the object and associates it with the specified .
///
///
/// This function may NOT be called concurrently from multiple threads!
///
virtual void set_private_data(const uint8_t guid[16], const uint64_t data) = 0;
///
/// Gets a reference to user-defined data from the object that was previously allocated via .
///
template inline T &get_private_data() const
{
uint64_t res;
get_private_data(reinterpret_cast(&__uuidof(T)), &res);
return *reinterpret_cast(static_cast(res));
}
///
/// Allocates user-defined data and stores it in the object.
///
template inline T &create_private_data()
{
uint64_t res = reinterpret_cast(new T());
set_private_data(reinterpret_cast(&__uuidof(T)), res);
return *reinterpret_cast(static_cast(res));
}
///
/// Frees user-defined data that was previously allocated via .
///
template inline void destroy_private_data()
{
uint64_t res;
get_private_data(reinterpret_cast(&__uuidof(T)), &res);
delete reinterpret_cast(static_cast(res));
set_private_data(reinterpret_cast(&__uuidof(T)), 0);
}
};
///
/// A logical render device, used for resource creation and global operations.
/// Functionally equivalent to a 'IDirect3DDevice9', 'ID3D10Device', 'ID3D11Device', 'ID3D12Device', 'HGLRC' or 'VkDevice'.
///
///
/// This class is safe to use concurrently from multiple threads in D3D10+ and Vulkan.
///
struct __declspec(novtable) device : public api_object
{
///
/// Gets the underlying graphics API used by this device.
///
virtual device_api get_api() const = 0;
///
/// Checks whether the device supports the specified .
///
virtual bool check_capability(device_caps capability) const = 0;
///
/// Checks whether the specified texture supports the specified .
///
virtual bool check_format_support(format format, resource_usage usage) const = 0;
///
/// Creates a new sampler state object.
///
/// Description of the sampler to create.
/// Pointer to a variable that is set to the handle of the created sampler.
/// if the sampler was successfully created, otherwise (in this case is set to zero).
virtual bool create_sampler(const sampler_desc &desc, sampler *out_handle) = 0;
///
/// Instantly destroys a sampler that was previously created via .
///
virtual void destroy_sampler(sampler handle) = 0;
///
/// Allocates and creates a new resource.
///
/// Description of the resource to create.
/// Optional data to upload to the resource after creation. This should point to an array of , one for each subresource (mipmap levels and array layers). Can be to indicate no initial data to upload.
/// Initial state of the resource after creation. This can later be changed via .
/// Pointer to a variable that is set to the handle of the created resource.
/// Optional pointer to a variable of type HANDLE used when contains . When that variable is a , it is set to the exported shared handle of the created resource. When that variable is a valid handle, the resource is imported from that shared handle.
/// if the resource was successfully created, otherwise (in this case is set to zero).
virtual bool create_resource(const resource_desc &desc, const subresource_data *initial_data, resource_usage initial_state, resource *out_handle, void **shared_handle = nullptr) = 0;
///
/// Instantly destroys a resource that was previously created via and frees its memory.
/// Make sure the resource is no longer in use on the GPU (via any command list that may reference it and is still being executed) before doing this and never try to destroy resources created by the application!
///
virtual void destroy_resource(resource handle) = 0;
///
/// Gets the description of the specified resource.
///
virtual resource_desc get_resource_desc(resource resource) const = 0;
///
/// Creates a new resource view for the specified .
///
/// Resource to create the view to.
/// Usage type of the resource view to create. Set to to create a shader resource view, for a depth-stencil view, for a render target etc.
/// Description of the resource view to create.
/// Pointer to a variable that is set to the handle of the created resource view.
/// if the resource view was successfully created, otherwise (in this case is set to zero).
virtual bool create_resource_view(resource resource, resource_usage usage_type, const resource_view_desc &desc, resource_view *out_handle) = 0;
///
/// Instantly destroys a resource view that was previously created via .
///
virtual void destroy_resource_view(resource_view handle) = 0;
///
/// Gets the handle to the underlying resource the specified resource was created for.
///
///
/// Resource views may be created without a resource in D3D12, which is used to initialize a null descriptor (reading zeroes, writes are discarded). This may therefore return zero for such views.
///
virtual resource get_resource_from_view(resource_view view) const = 0;
///
/// Gets the description of the specified resource view.
///
virtual resource_view_desc get_resource_view_desc(resource_view view) const = 0;
///
/// Maps the memory of a buffer resource into application address space.
///
/// Buffer resource to map to host memory.
/// Offset (in bytes) into the buffer resource to start mapping.
/// Number of bytes to map. Set to -1 (UINT64_MAX) to indicate that the entire buffer should be mapped.
/// Hint on how the returned data pointer will be accessed.
/// Pointer to a variable that is set to a pointer to the memory of the buffer resource.
/// if the memory of the buffer resource was successfully mapped, otherwise (in this case is set to ).
virtual bool map_buffer_region(resource resource, uint64_t offset, uint64_t size, map_access access, void **out_data) = 0;
///
/// Unmaps a previously mapped buffer resource.
///
/// Buffer resource to unmap from host memory.
virtual void unmap_buffer_region(resource resource) = 0;
///
/// Maps the memory of a texture resource into application address space.
///
/// Texture resource to map to host memory.
/// Index of the subresource to map (level + (layer * levels)).
/// Optional 3D box (or to reference the entire subresource) that defines the region in the to map.
/// Hint on how the returned data pointer will be accessed.
/// Pointer to a variable that is set to a pointer to the memory of the texture resource and optionally the row and slice pitch of that data (depending on the resource type).
/// if the memory of the texture resource was successfully mapped, otherwise (in this case is set to ).
virtual bool map_texture_region(resource resource, uint32_t subresource, const subresource_box *box, map_access access, subresource_data *out_data) = 0;
///
/// Unmaps a previously mapped texture resource.
///
/// Texture resource to unmap from host memory.
/// Index of the subresource to unmap (level + (layer * levels)).
virtual void unmap_texture_region(resource resource, uint32_t subresource) = 0;
///
/// Uploads data to a buffer resource.
///
/// Pointer to the data to upload.
/// Buffer resource to upload to.
/// Offset (in bytes) into the buffer resource to start uploading to.
/// Number of bytes to upload.
virtual void update_buffer_region(const void *data, resource resource, uint64_t offset, uint64_t size) = 0;
///
/// Uploads data to a texture resource.
///
/// Pointer to the data to upload.
/// Texture resource to upload to.
/// Index of the subresource to upload to (level + (layer * levels)).
/// Optional 3D box (or to reference the entire subresource) that defines the region in the to upload to.
virtual void update_texture_region(const subresource_data &data, resource resource, uint32_t subresource, const subresource_box *box = nullptr) = 0;
///
/// Creates a new pipeline state object.
///
/// Pipeline layout to use.
/// Number of sub-objects.
/// Pointer to an array of sub-objects that describe this pipeline.
/// Pointer to a variable that is set to the handle of the created pipeline state object.
/// if the pipeline state object was successfully created, otherwise (in this case is set to zero).
virtual bool create_pipeline(pipeline_layout layout, uint32_t subobject_count, const pipeline_subobject *subobjects, pipeline *out_handle) = 0;
///
/// Instantly destroys a pipeline state object that was previously created via .
///
virtual void destroy_pipeline(pipeline handle) = 0;
///
/// Creates a new pipeline layout.
///
/// Number of layout parameters.
/// Pointer to an array of layout parameters that describe this pipeline layout.
/// Pointer to a variable that is set to the handle of the created pipeline layout.
/// if the pipeline layout was successfully created, otherwise (in this case is set to zero).
virtual bool create_pipeline_layout(uint32_t param_count, const pipeline_layout_param *params, pipeline_layout *out_handle) = 0;
///
/// Instantly destroys a pipeline layout that was previously created via .
///
virtual void destroy_pipeline_layout(pipeline_layout handle) = 0;
///
/// Allocates a descriptor table from an internal heap.
///
/// Pipeline layout that contains a parameter that describes the descriptor table.
/// Index of the pipeline layout parameter that describes the descriptor table.
/// Pointer to a a variable that is set to the handles of the created descriptor table.
/// if the descriptor table was successfully allocated, otherwise (in this case is set to zeroe).
inline bool allocate_descriptor_table(pipeline_layout layout, uint32_t param, descriptor_table *out_handle) { return allocate_descriptor_tables(1, layout, param, out_handle); }
///
/// Allocates one or more descriptor tables from an internal heap.
///
/// Number of descriptor tables to allocate.
/// Pipeline layout that contains a parameter that describes the descriptor table.
/// Index of the pipeline layout parameter that describes the descriptor table.
/// Pointer to an array of handles with at least elements that is filled with the handles of the created descriptor tables.
/// if the descriptor tables were successfully allocated, otherwise (in this case is filled with zeroes).
virtual bool allocate_descriptor_tables(uint32_t count, pipeline_layout layout, uint32_t param, descriptor_table *out_handles) = 0;
///
/// Frees a descriptor table that was previously allocated via .
///
inline void free_descriptor_table(descriptor_table handle) { free_descriptor_tables(1, &handle); }
///
/// Frees one or more descriptor tables that were previously allocated via .
///
virtual void free_descriptor_tables(uint32_t count, const descriptor_table *handles) = 0;
///
/// Gets the offset (in descriptors) of the specified binding in the underlying descriptor heap of a descriptor table.
///
/// Descriptor table to get the offset from.
/// Binding in the descriptor table to get the offset from.
/// Array index in the specified .
/// Pointer to a variable that is set to the handle of the underlying descriptor heap the was allocated from.
/// Pointer to a variable that is set to the offset of the binding in the underlying descriptor heap.
virtual void get_descriptor_heap_offset(descriptor_table table, uint32_t binding, uint32_t array_offset, descriptor_heap *out_heap, uint32_t *out_offset) const = 0;
///
/// Copies the contents of a descriptor table to another descriptor table.
///
/// Descriptor table copy to process.
inline void copy_descriptors(const descriptor_table_copy ©) { copy_descriptor_tables(1, ©); }
///
/// Copies the contents between multiple descriptor tables.
///
/// Number of to process.
/// Pointer to an array of descriptor table copies to process.
virtual void copy_descriptor_tables(uint32_t count, const descriptor_table_copy *copies) = 0;
///
/// Updates the contents of a descriptor table with the specified descriptors.
///
/// Descriptor table update to process.
inline void update_descriptors(const descriptor_table_update &update) { update_descriptor_tables(1, &update); }
///
/// Updates the contents of multiple descriptor tables with the specified descriptors.
///
/// Number of to process.
/// Pointer to an array of descriptor table updates to process.
virtual void update_descriptor_tables(uint32_t count, const descriptor_table_update *updates) = 0;
///
/// Creates a new query heap.
///
/// Type of queries that will be used with this query heap.
/// Number of queries to allocate in the query heap.
/// Pointer to a variable that is set to the handle of the created query heap.
/// if the query heap was successfully created, otherwise (in this case is set to zero).
virtual bool create_query_heap(query_type type, uint32_t size, query_heap *out_handle) = 0;
///
/// Instantly destroys a query heap that was previously created via .
///
virtual void destroy_query_heap(query_heap handle) = 0;
///
/// Gets the results of queries in a query heap.
///
/// Query heap that contains the queries.
/// Index of the first query in the query heap to copy the results from.
/// Number of query results to copy.
/// Pointer to an array that is filled with the results.
/// Size (in bytes) of each element in the array.
/// if the query results were successfully downloaded from the GPU, otherwise.
virtual bool get_query_heap_results(query_heap heap, uint32_t first, uint32_t count, void *results, uint32_t stride) = 0;
///
/// Associates a name with a resource, for easier debugging in external tools.
///
/// Resource to associate a name with.
/// Null-terminated name string.
virtual void set_resource_name(resource handle, const char *name) = 0;
///
/// Associates a name with a resource view, for easier debugging in external tools.
///
/// Resource view to associate a name with.
/// Null-terminated name string.
virtual void set_resource_view_name(resource_view handle, const char *name) = 0;
};
///
/// The base class for objects that are children to a logical render .
///
struct __declspec(novtable) device_object : public api_object
{
///
/// Gets the parent device for this object.
///
virtual device *get_device() = 0;
};
///
/// The available indirect command types.
///
enum class indirect_command
{
unknown,
draw,
draw_indexed,
dispatch
};
///
/// A command list, used to enqueue render commands on the CPU, before later executing them in a command queue.
/// Functionally equivalent to a 'ID3D11CommandList', 'ID3D12CommandList' or 'VkCommandBuffer'.
///
///
/// This class may NOT be used concurrently from multiple threads!
///
struct __declspec(novtable) command_list : public device_object
{
///
/// Adds a barrier for the specified to the command stream.
/// When both and are a UAV barrier is added, otherwise a state transition is performed.
///
/// Resource to transition.
/// Usage flags describing how the was used before this barrier.
/// Usage flags describing how the will be used after this barrier.
inline void barrier(resource resource, resource_usage old_state, resource_usage new_state) { barrier(1, &resource, &old_state, &new_state); }
///
/// Adds a barrier for the specified to the command stream.
///
/// Number of resources to transition.
/// Pointer to an array of resources to transition.
/// Pointer to an array of usage flags describing how the were used before this barrier.
/// Pointer to an array of usage flags describing how the will be used after this barrier.
virtual void barrier(uint32_t count, const resource *resources, const resource_usage *old_states, const resource_usage *new_states) = 0;
///
/// Begins a render pass and binds render target and depth-stencil resource views.
///
/// Number of render target views to bind.
/// Pointer to an array of render target descriptions.
/// Optional pointer to a depth-stencil description, or to bind none.
virtual void begin_render_pass(uint32_t count, const render_pass_render_target_desc *rts, const render_pass_depth_stencil_desc *ds = nullptr) = 0;
///
/// Ends a render pass.
/// This must be preceeded by a call to .
/// Render passes cannot be nested.
///
virtual void end_render_pass() = 0;
///
/// Binds individual render target and depth-stencil resource views.
/// This must not be called between and .
///
///
/// Number of render target views to bind.
/// Pointer to an array of render target views to bind.
/// Depth-stencil view to bind, or zero to bind none.
virtual void bind_render_targets_and_depth_stencil(uint32_t count, const resource_view *rtvs, resource_view dsv = { 0 }) = 0;
///
/// Binds a pipeline state object.
///
/// Pipeline stages to update with state from the pipeline state object.
/// Pipeline state object to bind.
virtual void bind_pipeline(pipeline_stage stages, pipeline pipeline) = 0;
///
/// Updates the specfified pipeline to the specified .
/// This is only valid for states that have been listed in the dynamic states provided at creation of the currently bound pipeline state object ().
///
/// Pipeline state to update.
/// Value to update the pipeline state to.
inline void bind_pipeline_state(dynamic_state state, uint32_t value) { bind_pipeline_states(1, &state, &value); }
///
/// Updates the specfified pipeline to the specified .
/// This is only valid for states that have been listed in the dynamic states provided at creation of the currently bound pipeline state object ().
///
/// Number of pipeline states to update.
/// Pointer to an array of pipeline states to update.
/// Pointer to an array of values to update the pipeline states to, with one for each state in .
virtual void bind_pipeline_states(uint32_t count, const dynamic_state *states, const uint32_t *values) = 0;
///
/// Binds an array of viewports to the rasterizer stage.
///
///
/// Index of the first viewport to bind. In D3D9, D3D10, D3D11 and D3D12 this has to be 0.
/// Number of viewports to bind.
/// Pointer to an array of viewports.
virtual void bind_viewports(uint32_t first, uint32_t count, const viewport *viewports) = 0;
///
/// Binds an array of scissor rectangles to the rasterizer stage.
///
///
/// Index of the first scissor rectangle to bind. In D3D9, D3D10, D3D11 and D3D12 this has to be 0.
/// Number of scissor rectangles to bind.
/// Pointer to an array of scissor rectangles.
virtual void bind_scissor_rects(uint32_t first, uint32_t count, const rect *rects) = 0;
///
/// Directly updates constant values in the specified shader pipeline stages.
/// In D3D9 this updates the values of uniform registers, in D3D10/11 and OpenGL the constant buffer specified in the pipeline layout, in D3D12 it sets root constants and in Vulkan push constants.
///
///
/// Shader stages that will use the updated constants.
/// Pipeline layout that describes where the constants are located.
/// Layout parameter index of the constant range in the pipeline (root parameter index in D3D12).
/// Start offset (in 32-bit values) to the first constant in the constant range to begin updating.
/// Number of 32-bit values to update.
/// Pointer to an array of 32-bit values to set the constants to. These can be floating-point, integer or boolean depending on what the shader is expecting.
virtual void push_constants(shader_stage stages, pipeline_layout layout, uint32_t param, uint32_t first, uint32_t count, const void *values) = 0;
///
/// Directly binds a temporary descriptor table for the specfified shader pipeline stage and updates with an array of descriptors.
///
///
/// Shader stages that will use the updated descriptors.
/// Pipeline layout that describes the descriptors.
/// Layout parameter index of the descriptor table in the pipeline (root parameter index in D3D12, descriptor set index in Vulkan).
/// Range of descriptors to update in the temporary descriptor table ( is ignored).
virtual void push_descriptors(shader_stage stages, pipeline_layout layout, uint32_t param, const descriptor_table_update &update) = 0;
///
/// Binds a single descriptor table.
///
/// Shader stages that will use the descriptors.
/// Pipeline layout that describes the descriptors.
/// Index of the pipeline parameter that describes the descriptor table (root parameter index in D3D12, descriptor set index in Vulkan).
/// Descriptor table to bind.
inline void bind_descriptor_table(shader_stage stages, pipeline_layout layout, uint32_t param, descriptor_table table) { bind_descriptor_tables(stages, layout, param, 1, &table); }
///
/// Binds an array of descriptor tables.
///
/// Shader stages that will use the descriptors.
/// Pipeline layout that describes the descriptors.
/// Index of the first pipeline parameter that describes the first descriptor table to bind (root parameter index in D3D12, descriptor set index in Vulkan).
/// Number of descriptor tables to bind.
/// Pointer to an array of descriptor tables to bind.
virtual void bind_descriptor_tables(shader_stage stages, pipeline_layout layout, uint32_t first, uint32_t count, const descriptor_table *tables) = 0;
///
/// Binds an index buffer to the input-assembler stage.
///
/// Index buffer resource. This resource must have been created with the usage.
/// Offset (in bytes) from the start of the index buffer to the first index to use. In D3D9 this has to be 0.
/// Size (in bytes) of each index. Can typically be 2 (16-bit indices) or 4 (32-bit indices).
virtual void bind_index_buffer(resource buffer, uint64_t offset, uint32_t index_size) = 0;
///
/// Binds a single vertex buffer to the input-assembler stage.
///
/// Input slot for binding.
/// Vertex buffer resource. This resources must have been created with the usage.
/// Offset (in bytes) from the start of the vertex buffer to the first vertex element to use.
/// Size (in bytes) of the vertex element that will be used from the vertex buffer (is added to an element offset to advance to the next).
inline void bind_vertex_buffer(uint32_t index, resource buffer, uint64_t offset, uint32_t stride) { bind_vertex_buffers(index, 1, &buffer, &offset, &stride); }
///
/// Binds an array of vertex buffers to the input-assembler stage.
///
/// First input slot for binding.
/// Number of vertex buffers to bind.
/// Pointer to an array of vertex buffer resources. These resources must have been created with the usage.
/// Pointer to an array of offset values, one for each buffer. Each offset is the number of bytes from the start of the vertex buffer to the first vertex element to use.
/// Pointer to an array of stride values, one for each buffer. Each stride is the size (in bytes) of the vertex element that will be used from that vertex buffer (is added to an element offset to advance to the next).
virtual void bind_vertex_buffers(uint32_t first, uint32_t count, const resource *buffers, const uint64_t *offsets, const uint32_t *strides) = 0;
///
/// Binds an array of buffers to the stream-output stage.
///
/// First stream-output slot for binding.
/// Number of stream-output targets to bind.
/// Pointer to an array of buffer resources. These resources must have been created with the usage.
/// Pointer to an array of offset values, one for each buffer. Each offset is the number of bytes from the start of the buffer to the first element to write to.
/// Optional pointer to an array of size values, one for each buffer. Can be or have elements set to UINT64_MAX to use the entire buffer.
/// Pointer to an array of counter buffer resources. These resources must have been created with the usage.
/// Pointer to an array of counter offset values, one for each counter buffer. Each offset is the number of bytes from the start of the counter buffer to the first element to write to.
virtual void bind_stream_output_buffers(uint32_t first, uint32_t count, const api::resource *buffers, const uint64_t *offsets, const uint64_t *max_sizes, const api::resource *counter_buffers, const uint64_t *counter_offsets) = 0;
///
/// Draws non-indexed primitives.
///
///
/// Number of vertices to draw.
/// Number of instances to draw. In D3D9 this has to be 1.
/// Index of the first vertex.
/// Value added to each index before reading per-instance data from a vertex buffer. In D3D9 this has to be 0.
virtual void draw(uint32_t vertex_count, uint32_t instance_count, uint32_t first_vertex, uint32_t first_instance) = 0;
///
/// Draws indexed primitives.
///
///
/// Number of indices read from the index buffer for each instance.
/// Number of instances to draw. In D3D9 this has to be 1.
/// Location of the first index read from the index buffer.
/// Value added to each index before reading per-vertex data from a vertex buffer.
/// Value added to each index before reading per-instance data from a vertex buffer. In D3D9 this has to be 0.
virtual void draw_indexed(uint32_t index_count, uint32_t instance_count, uint32_t first_index, int32_t vertex_offset, uint32_t first_instance) = 0;
///
/// Performs a compute shader dispatch.
///
///
/// Number of thread groups dispatched in the x direction.
/// Number of thread groups dispatched in the y direction.
/// Number of thread groups dispatched in the z direction.
virtual void dispatch(uint32_t group_count_x, uint32_t group_count_y, uint32_t group_count_z) = 0;
///
/// Executes indirect draw or dispatch commands.
///
///
/// Specifies whether this is an indirect draw, indexed draw or dispatch command.
/// Buffer resource that contains command arguments.
/// Offset (in bytes) from the start of the argument buffer to the first argument to use.
/// Number of commands to execute.
/// Stride (in bytes) between commands in the argument buffer.
virtual void draw_or_dispatch_indirect(indirect_command type, resource buffer, uint64_t offset, uint32_t draw_count, uint32_t stride) = 0;
///
/// Copies the entire contents of the resource to the ination resource. Dimensions of the two resources have to match.
///
///
/// The resource has to be in the state.
/// The ination resource has to be in the state.
///
/// Resource to copy from.
/// Resource to copy to.
virtual void copy_resource(resource source, resource dest) = 0;
///
/// Copies a linear memory region from the buffer to the ination buffer.
///
///
/// The resource has to be in the state.
/// The ination resource has to be in the state.
///
///
/// Buffer resource to copy from.
/// Offset (in bytes) into the buffer to start copying at.
/// Buffer resource to copy to.
/// Offset (in bytes) into the ination buffer to start copying to.
/// Number of bytes to copy.
virtual void copy_buffer_region(resource source, uint64_t source_offset, resource dest, uint64_t dest_offset, uint64_t size) = 0;
///
/// Copies a texture region from the buffer to the ination texture.
///
///
/// The resource has to be in the state.
/// The ination resource has to be in the state.
///
///
/// Buffer resource to copy from.
/// Offset (in bytes) into the buffer to start copying at.
/// Number of pixels from one row to the next (in the buffer), or zero if data is tightly packed.
/// Number of rows from one slice to the next (in the buffer) or zero if data is tightly packed.
/// Texture resource to copy to.
/// Index of the subresource of the ination texture to copy to.
/// Optional 3D box (or to reference the entire subresource) that defines the region in the ination texture to copy to.
virtual void copy_buffer_to_texture(resource source, uint64_t source_offset, uint32_t row_length, uint32_t slice_height, resource dest, uint32_t dest_subresource, const subresource_box *dest_box = nullptr) = 0;
///
/// Copies or blits a texture region from the texture to the ination texture.
///
///
/// The resource has to be in the state.
/// The ination resource has to be in the state.
///
///
/// Texture resource to copy from.
/// Index of the subresource of the texture to copy from.
/// Optional 3D box (or to reference the entire subresource) that defines the region in the texture to blit from.
/// Texture resource to copy to.
/// Index of the subresource of the ination texture to copy to.
/// Optional 3D box (or to reference the entire subresource) that defines the region in the ination texture to blit to.
/// Filter to apply when copy requires scaling.
virtual void copy_texture_region(resource source, uint32_t source_subresource, const subresource_box *source_box, resource dest, uint32_t dest_subresource, const subresource_box *dest_box, filter_mode filter = filter_mode::min_mag_mip_point) = 0;
///
/// Copies a texture region from the texture to the ination buffer.
///
///
/// The resource has to be in the state.
/// The ination resource has to be in the state.
///
///
/// Texture resource to copy from.
/// Index of the subresource of the texture to copy from.
/// Optional 3D box (or to reference the entire subresource) that defines the region in the texture to copy from.
/// Buffer resource to copy to.
/// Offset (in bytes) into the ination buffer to start copying to.
/// Number of pixels from one row to the next (in the buffer), or zero if data is tightly packed.
/// Number of rows from one slice to the next (in the buffer), or zero if data is tightly packed.
virtual void copy_texture_to_buffer(resource source, uint32_t source_subresource, const subresource_box *source_box, resource dest, uint64_t dest_offset, uint32_t row_length = 0, uint32_t slice_height = 0) = 0;
///
/// Copies a region from the multisampled texture to the non-multisampled ination texture.
///
///
/// The resource has to be in the state.
/// The ination resource has to be in the state.
///
///
/// Texture resource to resolve from.
/// Index of the subresource of the texture to resolve from.
/// Optional 3D box (or to reference the entire subresource) that defines the region in the texture to resolve.
/// Texture resource to resolve to.
/// Index of the subresource of the ination texture to resolve to.
/// Optional X offset (in texels) that defines the region in the ination texture to resolve to.
/// Optional Y offset (in texels) that defines the region in the ination texture to resolve to.
/// Optional Z offset (in texels) that defines the region in the ination texture to resolve to.
/// Format of the resource data.
virtual void resolve_texture_region(resource source, uint32_t source_subresource, const subresource_box *source_box, resource dest, uint32_t dest_subresource, int32_t dest_x, int32_t dest_y, int32_t dest_z, format format) = 0;
///
/// Clears the resource referenced by the depth-stencil view.
///
///
/// The resource the depth-stencil view points to has to be in the state.
///
/// Resource view handle of the depth-stencil.
/// Optional value to clear the depth buffer with.
/// Optional value to clear the stencil buffer with.
/// Number of rectangles to clear in the depth-stencil resource, or zero to clear the whole resource.
/// Pointer to an array of rectangles.
virtual void clear_depth_stencil_view(resource_view dsv, const float *depth, const uint8_t *stencil, uint32_t rect_count = 0, const rect *rects = nullptr) = 0;
///
/// Clears the resource referenced by the render target view.
///
///
/// The resource the render target view points to has to be in the state.
///
/// Resource view handle of the render target.
/// Value to clear the resource with.
/// Number of rectangles to clear in the render target resource, or zero to clear the whole resource.
/// Pointer to an array of rectangles.
virtual void clear_render_target_view(resource_view rtv, const float color[4], uint32_t rect_count = 0, const rect *rects = nullptr) = 0;
///
/// Clears the resource referenced by the unordered access view.
///
///
/// The resource the unordered access view points to has to be in the state.
///
/// Resource view handle of the unordered access view.
/// Value to clear the resource with.
/// Number of rectangles to clear in the unordered access resource, or zero to clear the whole resource.
/// Pointer to an array of rectangles.
virtual void clear_unordered_access_view_uint(resource_view uav, const uint32_t values[4], uint32_t rect_count = 0, const rect *rects = nullptr) = 0;
///
/// Clears the resource referenced by the unordered access view.
///
///
/// The resource the unordered access view points to has to be in the state.
///
/// Resource view handle of the unordered access view.
/// Value to clear the resource with.
/// Number of rectangles to clear in the unordered access resource, or zero to clear the whole resource.
/// Pointer to an array of rectangles.
virtual void clear_unordered_access_view_float(resource_view uav, const float values[4], uint32_t rect_count = 0, const rect *rects = nullptr) = 0;
///
/// Generates the lower mipmap levels for the specified shader resource view.
/// Uses the largest mipmap level of the view to recursively generate the lower levels of the mipmap chain and stops with the smallest level that is specified by the view.
///
///
/// This will invalidate all previous descriptor and pipeline bindings, which will need to be reset by calls to or and .
/// The resource the shader resource view points to has to be in the state and has to have been created with the flag.
///
/// Shader resource view to update.
virtual void generate_mipmaps(resource_view srv) = 0;
///
/// Begins a query.
///
/// Query heap that will manage the results of the query.
/// Type of the query to begin.
/// Index of the query in the query heap.
virtual void begin_query(query_heap heap, query_type type, uint32_t index) = 0;
///
/// Ends a query.
///
/// Query heap that will manage the results of the query.
/// Type of the query end.
/// Index of the query in the query heap.
virtual void end_query(query_heap heap, query_type type, uint32_t index) = 0;
///
/// Copies the results of queries in a query heap to a buffer resource.
///
///
/// The ination resource has to be in the state.
///
///
/// Query heap that manages the results of the queries.
/// Type of the queries to copy.
/// Index of the first query in the query heap to copy the result from.
/// Number of query results to copy.
/// Buffer resource to copy to.
/// Offset (in bytes) into the ination buffer to start copying to.
/// Size (in bytes) of each result element.
virtual void copy_query_heap_results(query_heap heap, query_type type, uint32_t first, uint32_t count, resource dest, uint64_t dest_offset, uint32_t stride) = 0;
///
/// Opens a debug event region in the command list.
///
/// Null-terminated string containing the label of the event.
/// Optional RGBA color value associated with the event.
virtual void begin_debug_event(const char *label, const float color[4] = nullptr) = 0;
///
/// Closes the current debug event region (the last one opened with ).
///
virtual void end_debug_event() = 0;
///
/// Inserts a debug marker into the command list.
///
/// Null-terminated string containing the label of the debug marker.
/// Optional RGBA color value associated with the debug marker.
virtual void insert_debug_marker(const char *label, const float color[4] = nullptr) = 0;
};
///
/// A list of flags that represent the available command queue types, as returned by .
///
enum class command_queue_type
{
graphics = 0x1,
compute = 0x2,
copy = 0x4
};
RESHADE_DEFINE_ENUM_FLAG_OPERATORS(command_queue_type);
///
/// A command queue, used to execute command lists on the GPU.
/// Functionally equivalent to the immediate 'ID3D11DeviceContext' or a 'ID3D12CommandQueue' or 'VkQueue'.
///
///
/// This class may NOT be used concurrently from multiple threads!
///
struct __declspec(novtable) command_queue : public device_object
{
///
/// Gets the type of the command queue, which specifies what commands can be executed on it.
///
virtual command_queue_type get_type() const = 0;
///
/// Waits for all issued GPU operations on this queue to finish before returning.
/// This can be used to ensure that e.g. resources are no longer in use on the GPU before destroying them.
///
virtual void wait_idle() const = 0;
///
/// Flushes and executes the special immediate command list returned by immediately.
/// This can be used to force commands to execute right away instead of waiting for the runtime to flush it automatically at some point.
///
virtual void flush_immediate_command_list() const = 0;
///
/// Gets a special command list, on which all issued commands are executed as soon as possible (or right before the application executes its next command list on this queue).
/// This only exists on command queues that contain the flag, on other queues is returned.
///
virtual command_list *get_immediate_command_list() = 0;
///
/// Opens a debug event region in the command queue.
///
/// Null-terminated string containing the label of the event.
/// Optional RGBA color value associated with the event.
virtual void begin_debug_event(const char *label, const float color[4] = nullptr) = 0;
///
/// Closes the current debug event region (the last one opened with ).
///
virtual void end_debug_event() = 0;
///
/// Inserts a debug marker into the command queue.
///
/// Null-terminated string containing the label of the debug marker.
/// Optional RGBA color value associated with the debug marker.
virtual void insert_debug_marker(const char *label, const float color[4] = nullptr) = 0;
};
///
/// Describes a swap chain and its back buffer resources.
///
struct swapchain_desc
{
///
/// Description of the back buffer resources.
///
resource_desc back_buffer;
///
/// Number of back buffer resources in the swap chain.
///
uint32_t back_buffer_count = 0;
///
/// Defines how the back buffers should be swapped when a present occurs.
/// Depending on the render API this can be a 'D3DSWAPEFFECT', 'DXGI_SWAP_EFFECT', 'WGL_SWAP_METHOD_ARB' or 'VkPresentModeKHR' value.
///
uint32_t present_mode = 0;
///
/// Swap chain creation flags.
/// Depending on the render API this can be a 'D3DPRESENT', 'DXGI_PRESENT', 'PFD_*' or 'VkSwapchainCreateFlagsKHR' value.
///
uint32_t present_flags = 0;
};
///
/// A swap chain, used to present images to the screen.
/// Functionally equivalent to a 'IDirect3DSwapChain9', 'IDXGISwapChain', 'HDC' or 'VkSwapchainKHR'.
///
struct __declspec(novtable) swapchain : public device_object
{
///
/// Gets the handle of the window this swap chain was created with, or if this is an offscreen swap chain.
///
virtual void *get_hwnd() const = 0;
///
/// Gets the back buffer resource at the specified in this swap chain.
///
/// Index of the back buffer. This has to be between zero and the value returned by .
virtual resource get_back_buffer(uint32_t index) = 0;
///
/// Gets the number of back buffer resources in this swap chain.
///
virtual uint32_t get_back_buffer_count() const = 0;
///
/// Gets the current back buffer resource.
///
inline resource get_current_back_buffer() { return get_back_buffer(get_current_back_buffer_index()); }
///
/// Gets the index of the back buffer resource that can currently be rendered into.
///
virtual uint32_t get_current_back_buffer_index() const = 0;
};
} }