Skip to content

Commit 4d95676

Browse files
committed
Add "reshade_present" event and API to get window handle from swapchain
1 parent bad57c2 commit 4d95676

14 files changed

+82
-0
lines changed

include/reshade_api_device.hpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,7 @@ namespace reshade::api
941941
/// </summary>
942942
/// <param name="index">Index of the back buffer. This has to be between zero and the value returned by <see cref="get_back_buffer_count"/>.</param>
943943
virtual resource get_back_buffer(uint32_t index) = 0;
944+
944945
/// <summary>
945946
/// Gets the number of back buffer resources in this swap chain.
946947
/// </summary>
@@ -954,5 +955,15 @@ namespace reshade::api
954955
/// Gets the index of the back buffer resource that can currently be rendered into.
955956
/// </summary>
956957
virtual uint32_t get_current_back_buffer_index() const = 0;
958+
959+
/// <summary>
960+
/// Gets the HWND of the window this swap chain was created with, or <see langword="nullptr"/> if none exists.
961+
/// </summary>
962+
virtual void *get_window_handle() const = 0;
963+
964+
/// <summary>
965+
/// Gets the description of the back buffer resources in this swap chain.
966+
/// </summary>
967+
inline resource_desc get_back_buffer_resource_desc() { return get_device()->get_resource_desc(get_current_back_buffer()); }
957968
};
958969
}

include/reshade_events.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,12 @@ namespace reshade
13901390
/// </summary>
13911391
present,
13921392

1393+
/// <summary>
1394+
/// Called after ReShade has rendered its overlay.
1395+
/// <para>Callback function signature: <c>void (api::command_queue *queue, api::effect_runtime *runtime)</c></para>
1396+
/// </summary>
1397+
reshade_present,
1398+
13931399
/// <summary>
13941400
/// Called right before ReShade effects are rendered.
13951401
/// <para>Callback function signature: <c>void (api::effect_runtime *runtime, api::command_list *cmd_list, api::resource_view rtv, api::resource_view rtv_srgb)</c></para>
@@ -1540,6 +1546,7 @@ namespace reshade
15401546

15411547
RESHADE_DEFINE_ADDON_EVENT_TRAITS(addon_event::present, void, api::command_queue *queue, api::swapchain *swapchain);
15421548

1549+
RESHADE_DEFINE_ADDON_EVENT_TRAITS(addon_event::reshade_present, void, api::command_queue *queue, api::effect_runtime *runtime);
15431550
RESHADE_DEFINE_ADDON_EVENT_TRAITS(addon_event::reshade_begin_effects, void, api::effect_runtime *runtime, api::command_list *cmd_list, api::resource_view rtv, api::resource_view rtv_srgb);
15441551
RESHADE_DEFINE_ADDON_EVENT_TRAITS(addon_event::reshade_finish_effects, void, api::effect_runtime *runtime, api::command_list *cmd_list, api::resource_view rtv, api::resource_view rtv_srgb);
15451552
RESHADE_DEFINE_ADDON_EVENT_TRAITS(addon_event::reshade_reloaded_effects, void, api::effect_runtime *runtime);

source/d3d12/d3d12_command_queue_downlevel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ HRESULT STDMETHODCALLTYPE D3D12CommandQueueDownlevel::Present(ID3D12GraphicsComm
5151

5252
swapchain_impl::on_present(pSourceTex2D, hWindow);
5353

54+
#if RESHADE_ADDON
55+
reshade::invoke_addon_event<reshade::addon_event::reshade_present>(_parent_queue, this);
56+
#endif
57+
5458
_parent_queue->flush_immediate_command_list();
5559

5660
// Get original command list pointer from proxy object

source/d3d9/d3d9_device.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice9::Present(const RECT *pSourceRect, cons
574574
reshade::invoke_addon_event<reshade::addon_event::present>(this, _implicit_swapchain);
575575
#endif
576576
_implicit_swapchain->on_present();
577+
#if RESHADE_ADDON
578+
reshade::invoke_addon_event<reshade::addon_event::reshade_present>(this, _implicit_swapchain);
579+
#endif
577580
}
578581

579582
return _orig->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion);
@@ -2186,6 +2189,9 @@ HRESULT STDMETHODCALLTYPE Direct3DDevice9::PresentEx(const RECT *pSourceRect, co
21862189
reshade::invoke_addon_event<reshade::addon_event::present>(this, _implicit_swapchain);
21872190
#endif
21882191
_implicit_swapchain->on_present();
2192+
#if RESHADE_ADDON
2193+
reshade::invoke_addon_event<reshade::addon_event::reshade_present>(this, _implicit_swapchain);
2194+
#endif
21892195
}
21902196

21912197
assert(_extended_interface);

source/d3d9/d3d9_swapchain.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ HRESULT STDMETHODCALLTYPE Direct3DSwapChain9::Present(const RECT *pSourceRect, c
116116
reshade::invoke_addon_event<reshade::addon_event::present>(_device, this);
117117
#endif
118118
swapchain_impl::on_present();
119+
#if RESHADE_ADDON
120+
reshade::invoke_addon_event<reshade::addon_event::reshade_present>(_device, this);
121+
#endif
119122
}
120123

121124
return _orig->Present(pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);

source/dxgi/dxgi_swapchain.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,18 +131,27 @@ void DXGISwapChain::runtime_present(UINT flags)
131131
reshade::invoke_addon_event<reshade::addon_event::present>(static_cast<D3D10Device *>(static_cast<ID3D10Device *>(_direct3d_device)), _impl);
132132
#endif
133133
static_cast<reshade::d3d10::swapchain_impl *>(_impl)->on_present();
134+
#if RESHADE_ADDON
135+
reshade::invoke_addon_event<reshade::addon_event::reshade_present>(static_cast<D3D10Device *>(static_cast<ID3D10Device *>(_direct3d_device)), _impl);
136+
#endif
134137
break;
135138
case 11:
136139
#if RESHADE_ADDON
137140
reshade::invoke_addon_event<reshade::addon_event::present>(static_cast<D3D11Device *>(static_cast<ID3D11Device *>(_direct3d_device))->_immediate_context, _impl);
138141
#endif
139142
static_cast<reshade::d3d11::swapchain_impl *>(_impl)->on_present();
143+
#if RESHADE_ADDON
144+
reshade::invoke_addon_event<reshade::addon_event::reshade_present>(static_cast<D3D11Device *>(static_cast<ID3D11Device *>(_direct3d_device))->_immediate_context, _impl);
145+
#endif
140146
break;
141147
case 12:
142148
#if RESHADE_ADDON
143149
reshade::invoke_addon_event<reshade::addon_event::present>(static_cast<D3D12CommandQueue *>(_direct3d_command_queue), _impl);
144150
#endif
145151
static_cast<reshade::d3d12::swapchain_impl *>(_impl)->on_present();
152+
#if RESHADE_ADDON
153+
reshade::invoke_addon_event<reshade::addon_event::reshade_present>(static_cast<D3D12CommandQueue *>(_direct3d_command_queue), _impl);
154+
#endif
146155
static_cast<D3D12CommandQueue *>(_direct3d_command_queue)->flush_immediate_command_list();
147156
break;
148157
}

source/input.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ namespace reshade
3535
/// <returns>A pointer to the input manager for the <paramref name="window"/>.</returns>
3636
static std::shared_ptr<input> register_window(window_handle window);
3737

38+
window_handle get_window_handle() const { return _window; }
39+
3840
bool is_key_down(unsigned int keycode) const;
3941
bool is_key_pressed(unsigned int keycode) const;
4042
bool is_key_pressed(unsigned int keycode, bool ctrl, bool shift, bool alt, bool force_modifiers = false) const;

source/opengl/opengl_hooks_wgl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,10 @@ HOOK_EXPORT BOOL WINAPI wglSwapBuffers(HDC hdc)
885885

886886
// Assume that the correct OpenGL context is still current here
887887
runtime->on_present();
888+
889+
#if RESHADE_ADDON
890+
reshade::invoke_addon_event<reshade::addon_event::reshade_present>(runtime, runtime);
891+
#endif
888892
}
889893

890894
return trampoline(hdc);

source/opengl/opengl_impl_device.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,7 @@ static bool create_shader_module(GLenum type, const reshade::api::shader_desc &d
16461646
else
16471647
{
16481648
assert(desc.code_size <= static_cast<size_t>(std::numeric_limits<GLsizei>::max()));
1649+
assert(desc.entry_point != nullptr);
16491650

16501651
glShaderBinary(1, &shader_object, GL_SPIR_V_BINARY, desc.code, static_cast<GLsizei>(desc.code_size));
16511652
glSpecializeShader(shader_object, desc.entry_point, desc.spec_constants, desc.spec_constant_ids, desc.spec_constant_values);

source/openvr/openvr.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ static vr::EVRCompositorError on_vr_submit_d3d10(vr::IVRCompositor *compositor,
7474

7575
s_vr_swapchain->on_present();
7676

77+
#if RESHADE_ADDON
78+
reshade::invoke_addon_event<reshade::addon_event::reshade_present>(device_proxy, s_vr_swapchain);
79+
#endif
80+
7781
const auto target_texture = reinterpret_cast<ID3D10Texture2D *>(s_vr_swapchain->get_current_back_buffer().handle);
7882

7983
// The left and right eye were copied side-by-side to a single texture in 'on_vr_submit', so set bounds accordingly
@@ -130,6 +134,10 @@ static vr::EVRCompositorError on_vr_submit_d3d11(vr::IVRCompositor *compositor,
130134

131135
s_vr_swapchain->on_present();
132136

137+
#if RESHADE_ADDON
138+
reshade::invoke_addon_event<reshade::addon_event::reshade_present>(device_proxy->_immediate_context, s_vr_swapchain);
139+
#endif
140+
133141
const auto target_texture = reinterpret_cast<ID3D11Texture2D *>(s_vr_swapchain->get_current_back_buffer().handle);
134142

135143
// The left and right eye were copied side-by-side to a single texture in 'on_vr_submit', so set bounds accordingly
@@ -177,6 +185,10 @@ static vr::EVRCompositorError on_vr_submit_d3d12(vr::IVRCompositor *compositor,
177185

178186
s_vr_swapchain->on_present();
179187

188+
#if RESHADE_ADDON
189+
reshade::invoke_addon_event<reshade::addon_event::reshade_present>(command_queue_proxy.get(), s_vr_swapchain);
190+
#endif
191+
180192
command_queue_proxy->flush_immediate_command_list();
181193

182194
lock.unlock();
@@ -228,6 +240,10 @@ static vr::EVRCompositorError on_vr_submit_opengl(vr::IVRCompositor *compositor,
228240

229241
s_vr_swapchain->on_present();
230242

243+
#if RESHADE_ADDON
244+
reshade::invoke_addon_event<reshade::addon_event::reshade_present>(g_current_context, s_vr_swapchain);
245+
#endif
246+
231247
const GLuint target_rbo = s_vr_swapchain->get_current_back_buffer().handle & 0xFFFFFFFF;
232248

233249
// Target object created in 'on_vr_submit' is a 2D texture
@@ -286,6 +302,10 @@ static vr::EVRCompositorError on_vr_submit_vulkan(vr::IVRCompositor *compositor,
286302

287303
s_vr_swapchain->on_present();
288304

305+
#if RESHADE_ADDON
306+
reshade::invoke_addon_event<reshade::addon_event::reshade_present>(queue, s_vr_swapchain);
307+
#endif
308+
289309
queue->flush_immediate_command_list();
290310

291311
vr::VRVulkanTextureData_t target_texture = *texture;

0 commit comments

Comments
 (0)