Skip to content

Commit 9cbd74d

Browse files
committed
Add "update_buffer_region_command" and "update_texture_region_command" events specific to a command list
Includes hook for "vkCmdUpdateBuffer" and improves handling for "ID3D11DeviceContext::UpdateSubresource" on deferred device contexts
1 parent dc23551 commit 9cbd74d

22 files changed

+294
-53
lines changed

include/reshade.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include <Windows.h>
1212

1313
// Current version of the ReShade API
14-
#define RESHADE_API_VERSION 17
14+
#define RESHADE_API_VERSION 18
1515

1616
// Optionally import ReShade API functions when 'RESHADE_API_LIBRARY' is defined instead of using header-only mode
1717
#if defined(RESHADE_API_LIBRARY) || defined(RESHADE_API_LIBRARY_EXPORT)

include/reshade_api_device.hpp

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,16 @@ namespace reshade { namespace api
186186
/// If this feature is not present, <see cref="resource_view_type::acceleration_structure"/>, <see cref="command_list::dispatch_rays"/>, <see cref="command_list::copy_acceleration_structure"/>, <see cref="command_list::build_acceleration_structure"/> and <see cref="command_list::query_acceleration_structures"/> must not be used.
187187
/// </summary>
188188
ray_tracing,
189+
/// <summary>
190+
/// Specifies whether deferred buffer updates can be used.
191+
/// If this feature is not present, <see cref="command_list::update_buffer_region"/> must not be used.
192+
/// </summary>
193+
update_buffer_region_command,
194+
/// <summary>
195+
/// Specifies whether deferred texture updates can be used.
196+
/// If this feature is not present, <see cref="command_list::update_texture_region"/> must not be used.
197+
/// </summary>
198+
update_texture_region_command,
189199
};
190200

191201
/// <summary>
@@ -412,15 +422,15 @@ namespace reshade { namespace api
412422
virtual void unmap_texture_region(resource resource, uint32_t subresource) = 0;
413423

414424
/// <summary>
415-
/// Uploads data to a buffer resource.
425+
/// Uploads data to a buffer resource immediately.
416426
/// </summary>
417427
/// <param name="data">Pointer to the data to upload.</param>
418428
/// <param name="resource">Buffer resource to upload to.</param>
419429
/// <param name="offset">Offset (in bytes) into the buffer resource to start uploading to.</param>
420430
/// <param name="size">Number of bytes to upload.</param>
421431
virtual void update_buffer_region(const void *data, resource resource, uint64_t offset, uint64_t size) = 0;
422432
/// <summary>
423-
/// Uploads data to a texture resource.
433+
/// Uploads data to a texture resource immediately.
424434
/// </summary>
425435
/// <param name="data">Pointer to the data to upload.</param>
426436
/// <param name="resource">Texture resource to upload to.</param>
@@ -813,7 +823,7 @@ namespace reshade { namespace api
813823
/// <param name="max_sizes">Optional pointer to an array of size values, one for each buffer. Can be <see langword="nullptr"/> or have elements set to UINT64_MAX to use the entire buffer.</param>
814824
/// <param name="counter_buffers">Pointer to the first element of an array of counter buffer resources. These resources must have been created with the <see cref="resource_usage::stream_output"/> usage.</param>
815825
/// <param name="counter_offsets">Pointer to the first element of 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.</param>
816-
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;
826+
virtual void bind_stream_output_buffers(uint32_t first, uint32_t count, const resource *buffers, const uint64_t *offsets, const uint64_t *max_sizes, const resource *counter_buffers, const uint64_t *counter_offsets) = 0;
817827

818828
/// <summary>
819829
/// Draws non-indexed primitives.
@@ -1104,7 +1114,7 @@ namespace reshade { namespace api
11041114
/// <param name="source">Acceleration structure to read data from when <paramref name="mode"/> is <see cref="acceleration_structure_build_mode::update"/>, otherwise zero.</param>
11051115
/// <param name="dest">Acceleration structure to write data to.</param>
11061116
/// <param name="mode">Choose between building a new or updating an existing acceleration structure.</param>
1107-
virtual void build_acceleration_structure(acceleration_structure_type type, acceleration_structure_build_flags flags, uint32_t input_count, const acceleration_structure_build_input *inputs, api::resource scratch, uint64_t scratch_offset, resource_view source, resource_view dest, acceleration_structure_build_mode mode) = 0;
1117+
virtual void build_acceleration_structure(acceleration_structure_type type, acceleration_structure_build_flags flags, uint32_t input_count, const acceleration_structure_build_input *inputs, resource scratch, uint64_t scratch_offset, resource_view source, resource_view dest, acceleration_structure_build_mode mode) = 0;
11081118

11091119
/// <summary>
11101120
/// Queries acceleration structure size parameters.
@@ -1116,6 +1126,31 @@ namespace reshade { namespace api
11161126
/// <param name="type">Type of the acceleration structure query.</param>
11171127
/// <param name="first">Index of the first query in the query heap to write the result to.</param>
11181128
virtual void query_acceleration_structures(uint32_t count, const resource_view *acceleration_structures, query_heap heap, query_type type, uint32_t first) = 0;
1129+
1130+
/// <summary>
1131+
/// Uploads data to a buffer resource when the command list is executed.
1132+
/// </summary>
1133+
/// <remarks>
1134+
/// The <paramref name="dest"/>ination resource has to be in the <see cref="resource_usage::copy_dest"/> state.
1135+
/// </remarks>
1136+
/// <seealso cref="device_caps::update_buffer_region_command"/>
1137+
/// <param name="data">Pointer to the data to upload.</param>
1138+
/// <param name="dest">Buffer resource to upload to.</param>
1139+
/// <param name="dest_offset">Offset (in bytes) into the buffer resource to start uploading to.</param>
1140+
/// <param name="size">Number of bytes to upload.</param>
1141+
virtual void update_buffer_region(const void *data, resource dest, uint64_t dest_offset, uint64_t size) = 0;
1142+
/// <summary>
1143+
/// Uploads data to a texture resource when the command list is executed.
1144+
/// </summary>
1145+
/// <remarks>
1146+
/// The <paramref name="dest"/>ination resource has to be in the <see cref="resource_usage::copy_dest"/> state.
1147+
/// </remarks>
1148+
/// <seealso cref="device_caps::update_texture_region_command"/>
1149+
/// <param name="data">Pointer to the data to upload.</param>
1150+
/// <param name="dest">Texture resource to upload to.</param>
1151+
/// <param name="dest_subresource">Index of the subresource to upload to (<c>level + (layer * levels)</c>).</param>
1152+
/// <param name="dest_box">Optional 3D box (or <see langword="nullptr"/> to reference the entire subresource) that defines the region in the <paramref name="resource"/> to upload to.</param>
1153+
virtual void update_texture_region(const subresource_data &data, resource dest, uint32_t dest_subresource, const subresource_box *dest_box = nullptr) = 0;
11191154
};
11201155

11211156
/// <summary>

include/reshade_events.hpp

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,22 +553,37 @@ namespace reshade
553553
/// <list type="bullet">
554554
/// <item><description>ID3D10Device::UpdateSubresource</description></item>
555555
/// <item><description>ID3D11DeviceContext::UpdateSubresource</description></item>
556+
/// <item><description>ID3D11DeviceContext1::UpdateSubresource1</description></item>
556557
/// <item><description>glBufferSubData</description></item>
557558
/// <item><description>glNamedBufferSubData</description></item>
558559
/// </list>
559560
/// <para>Callback function signature: <c>bool (api::device *device, const void *data, api::resource resource, uint64_t offset, uint64_t size)</c></para>
560561
/// </summary>
561562
/// <remarks>
563+
/// To prevent this action from being executed, return <see langword="true"/>, otherwise return <see langword="false"/>.
564+
/// </remarks>
565+
update_buffer_region = 24,
566+
/// <summary>
567+
/// Called before:
568+
/// <list type="bullet">
569+
/// <item><description>ID3D11DeviceContext::UpdateSubresource (on deferred device contexts)</description></item>
570+
/// <item><description>ID3D11DeviceContext1::UpdateSubresource1 (on deferred device contexts)</description></item>
571+
/// <item><description>vkCmdUpdateBuffer</description></item>
572+
/// </list>
573+
/// <para>Callback function signature: <c>bool (api::command_list *cmd_list, const void *data, api::resource dest, uint64_t dest_offset, uint64_t size)</c></para>
574+
/// </summary>
575+
/// <remarks>
562576
/// To prevent this command from being executed, return <see langword="true"/>, otherwise return <see langword="false"/>.
563577
/// Destination resource will be in the <see cref="api::resource_usage::copy_dest"/> state.
564578
/// </remarks>
565-
update_buffer_region,
579+
update_buffer_region_command = 98,
566580

567581
/// <summary>
568582
/// Called before:
569583
/// <list type="bullet">
570584
/// <item><description>ID3D10Device::UpdateSubresource</description></item>
571585
/// <item><description>ID3D11DeviceContext::UpdateSubresource</description></item>
586+
/// <item><description>ID3D11DeviceContext1::UpdateSubresource1</description></item>
572587
/// <item><description>glTexSubData1D</description></item>
573588
/// <item><description>glTexSubData2D</description></item>
574589
/// <item><description>glTexSubData3D</description></item>
@@ -585,10 +600,22 @@ namespace reshade
585600
/// <para>Callback function signature: <c>bool (api::device *device, const api::subresource_data &amp;data, api::resource resource, uint32_t subresource, const api::subresource_box *box)</c></para>
586601
/// </summary>
587602
/// <remarks>
603+
/// To prevent this action from being executed, return <see langword="true"/>, otherwise return <see langword="false"/>.
604+
/// </remarks>
605+
update_texture_region = 25,
606+
/// <summary>
607+
/// Called before:
608+
/// <list type="bullet">
609+
/// <item><description>ID3D11DeviceContext::UpdateSubresource (on deferred device contexts)</description></item>
610+
/// <item><description>ID3D11DeviceContext1::UpdateSubresource1 (on deferred device contexts)</description></item>
611+
/// </list>
612+
/// <para>Callback function signature: <c>bool (api::command_list *cmd_list, const api::subresource_data &amp;data, api::resource dest, uint32_t dest_subresource, const api::subresource_box *dest_box)</c></para>
613+
/// </summary>
614+
/// <remarks>
588615
/// To prevent this command from being executed, return <see langword="true"/>, otherwise return <see langword="false"/>.
589616
/// Destination resource will be in the <see cref="api::resource_usage::copy_dest"/> state.
590617
/// </remarks>
591-
update_texture_region,
618+
update_texture_region_command = 99,
592619

593620
/// <summary>
594621
/// Called after successful pipeline creation from:
@@ -636,7 +663,7 @@ namespace reshade
636663
/// <remarks>
637664
/// May be called multiple times with the same pipeline handle (whenever the pipeline is updated or its reference count is incremented).
638665
/// </remarks>
639-
init_pipeline,
666+
init_pipeline = 26,
640667

641668
/// <summary>
642669
/// Called on pipeline creation, before:
@@ -1252,6 +1279,8 @@ namespace reshade
12521279
/// <summary>
12531280
/// Called before:
12541281
/// <list type="bullet">
1282+
/// <item><description>ID3D11DeviceContext::CopySubresourceRegion</description></item>
1283+
/// <item><description>ID3D11DeviceContext1::CopySubresourceRegion1</description></item>
12551284
/// <item><description>ID3D12GraphicsCommandList::CopyBufferRegion</description></item>
12561285
/// <item><description>glCopyBufferSubData</description></item>
12571286
/// <item><description>glCopyNamedBufferSubData</description></item>
@@ -1291,6 +1320,7 @@ namespace reshade
12911320
/// <item><description>IDirect3DDevice9::StretchRect</description></item>
12921321
/// <item><description>ID3D10Device::CopySubresourceRegion</description></item>
12931322
/// <item><description>ID3D11DeviceContext::CopySubresourceRegion</description></item>
1323+
/// <item><description>ID3D11DeviceContext1::CopySubresourceRegion1</description></item>
12941324
/// <item><description>ID3D12GraphicsCommandList::CopyTextureRegion</description></item>
12951325
/// <item><description>glBlitFramebuffer</description></item>
12961326
/// <item><description>glBlitNamedFramebuffer</description></item>
@@ -1742,7 +1772,7 @@ namespace reshade
17421772
reshade_overlay_technique,
17431773

17441774
#if RESHADE_ADDON
1745-
max = 98 // Last value used internally by ReShade to determine number of events in this enum
1775+
max = 100 // Last value used internally by ReShade to determine number of events in this enum
17461776
#endif
17471777
};
17481778

@@ -1856,6 +1886,9 @@ namespace reshade
18561886
RESHADE_DEFINE_ADDON_EVENT_TRAITS(addon_event::build_acceleration_structure, bool, api::command_list *cmd_list, api::acceleration_structure_type type, api::acceleration_structure_build_flags flags, uint32_t input_count, const api::acceleration_structure_build_input *inputs, api::resource scratch, uint64_t scratch_offset, api::resource_view source, api::resource_view dest, api::acceleration_structure_build_mode mode);
18571887
RESHADE_DEFINE_ADDON_EVENT_TRAITS(addon_event::query_acceleration_structures, bool, api::command_list *cmd_list, uint32_t count, const api::resource_view *acceleration_structures, api::query_heap heap, api::query_type type, uint32_t first);
18581888

1889+
RESHADE_DEFINE_ADDON_EVENT_TRAITS(addon_event::update_buffer_region_command, bool, api::command_list *cmd_list, const void *data, api::resource dest, uint64_t dest_offset, uint64_t size);
1890+
RESHADE_DEFINE_ADDON_EVENT_TRAITS(addon_event::update_texture_region_command, bool, api::command_list *cmd_list, const api::subresource_data &data, api::resource dest, uint32_t dest_subresource, const api::subresource_box *dest_box);
1891+
18591892
RESHADE_DEFINE_ADDON_EVENT_TRAITS(addon_event::reset_command_list, void, api::command_list *cmd_list);
18601893
RESHADE_DEFINE_ADDON_EVENT_TRAITS(addon_event::close_command_list, void, api::command_list *cmd_list);
18611894

source/addon_manager.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ static const char *addon_event_to_string(reshade::addon_event ev)
5252
case addon_event::map_texture_region: return "map_texture_region";
5353
case addon_event::unmap_texture_region: return "unmap_texture_region";
5454
case addon_event::update_buffer_region: return "update_buffer_region";
55+
case addon_event::update_buffer_region_command: return "update_buffer_region_command";
5556
case addon_event::update_texture_region: return "update_texture_region";
57+
case addon_event::update_texture_region_command: return "update_texture_region_command";
5658
case addon_event::init_pipeline: return "init_pipeline";
5759
case addon_event::create_pipeline: return "create_pipeline";
5860
case addon_event::destroy_pipeline: return "destroy_pipeline";

source/d3d10/d3d10_impl_device.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ bool reshade::d3d10::device_impl::check_capability(api::device_caps capability)
125125
case api::device_caps::shared_fence_nt_handle:
126126
case api::device_caps::amplification_and_mesh_shader:
127127
case api::device_caps::ray_tracing:
128+
return false;
129+
case api::device_caps::update_buffer_region_command:
130+
case api::device_caps::update_texture_region_command:
131+
return true;
128132
default:
129133
return false;
130134
}

0 commit comments

Comments
 (0)