How to enable ReShade for secondary render target

  • Posts: 6
3 years 5 months ago #1 by Nightingale
Hi,
I am the developer of the Extended Video Export mod for GTA V.
Video exporting in Rockstar Editor uses an offscreen render target, and ReShade effects are not enabled on that target.
I need to know how to enable ReShade for the offscreen render target.
So far I've been able to hook into the game functions and get access to the D3D11 rendering pipeline.

Please Log in or Create an account to join the conversation.

  • Posts: 3725
3 years 5 months ago #2 by crosire
ReShade always renders to the backbuffer and caches the texture, so there is no way to change it (unless the swapchain is reset).
The following user(s) said Thank You: Nightingale

Please Log in or Create an account to join the conversation.

  • Posts: 6
3 years 5 months ago #3 by Nightingale
Thank you for your response. So I guess creating a fake swap chain bound to my alternative render target and presenting it would do the trick? I'll try it later today and see if it works.

Please Log in or Create an account to join the conversation.

  • Posts: 3725
3 years 5 months ago #4 by crosire
Yes, that should work. ReShade creates an instance for each swapchain it can find, so using it to present your render target to an invisible window or similar would cause it to render the post-processing effects over it. You'll have to get the results back somehow though, which could be difficult after the present call finished, depending on the presentation technique used. Another way would be to overwrite the IDXGISwapChain::GetBuffer method and have it return your offscreen target on the custom swapchain, so ReShade renders to it directly.
The following user(s) said Thank You: Nightingale

Please Log in or Create an account to join the conversation.

  • Posts: 6
3 years 5 months ago #5 by Nightingale
Using a new swap chain with a hidden window did the job. The only problem is that ReShade reloads everything for the new swap chain and thus effects are disabled until all shaders are loaded and the initial ReShade message is visible on the buffer. Is there a way to wait for ReShade to load everything and hide the message?
Here is a frame from captured video: imgur.com/GuuUgGu

Please Log in or Create an account to join the conversation.

  • Posts: 6
3 years 5 months ago - 3 years 5 months ago #6 by Nightingale
Update: I managed to fix the problem by resizing the hidden swap chain whenever the original swap chain got resized, and doing a present() on it. This way the ReShade initialization is done before exporting video begins. Thank you for your help crosire.

Please Log in or Create an account to join the conversation.

  • Posts: 3725
3 years 5 months ago #7 by crosire
Glad to hear!

Please Log in or Create an account to join the conversation.

  • Posts: 6
3 years 5 months ago #8 by Nightingale
I was wrong. It still initializes ReShade as soon as exporting video starts and the initialization message is exported too.

Please Log in or Create an account to join the conversation.

  • Posts: 3725
3 years 5 months ago - 3 years 5 months ago #9 by crosire
ReShade has to reinitialize each time the swapchain is created/reset. There is no way around that. You'll have to create the swapchain earlier before exporting or add a delay.

Please Log in or Create an account to join the conversation.

  • Posts: 154
3 years 5 months ago #10 by ShoterXX
You could just render a couple of seconds worth of black screen, then just crop it off in the end.

Please Log in or Create an account to join the conversation.

  • Posts: 6
3 years 5 months ago - 3 years 5 months ago #11 by Nightingale
The problem is that it seems that ReShade doesn't initialize two swap chains at once. I would have to wait until the main swap chain is initialized, then call present on the other swap chain. I fixed it by calling present on secondary swap chain (width DXGI_PRESENT_TEST flag) whenever the present is called on the primary swap chain. I don't know about any performance issues of this hack, but it seems to be working perfectly right now.

Please Log in or Create an account to join the conversation.

  • Posts: 3725
3 years 5 months ago - 3 years 5 months ago #12 by crosire
ReShade does lazy initialization over the course of multiple present calls (at least as many calls as effects files to load). Creation/Reset of a swapchain effectively only sets a flag so ReShade knows to start reloading on the next couple of presents.

Please Log in or Create an account to join the conversation.