Skip to content

Commit

Permalink
Merge branch 'dev/lvengesanam/resolve_screenshot_issue' into 'main'
Browse files Browse the repository at this point in the history
[REMIX-3468] Resolve issue with capturing screenshot with certain games

See merge request lightspeedrtx/bridge-remix-nv!101
  • Loading branch information
lvengesanam committed Sep 23, 2024
2 parents 1001394 + 19d9c6d commit 8140bd3
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 9 deletions.
10 changes: 10 additions & 0 deletions bridge.conf
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,16 @@
# server.useVanillaDxvk = False


# In certain games, backbuffer is used to capture screenshot and in
# those cases we need to send LockRect calls on backbuffer to server.
# To facilitate that below flag is to be enabled and by default this flag
# is set to False to prevent lags in other games that do not use backbuffers
# for screenshot.
#
# Supported values: True, False

# client.enableBackbufferCapture = False

# When the bridge server shuts down after the client process has
# exited due to a crash or other unexpected event it will try to shut
# itself down gracefully by disabling the bridge and letting the
Expand Down
4 changes: 4 additions & 0 deletions src/client/client_options.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ namespace ClientOptions {
return bridge_util::Config::getOption<bool>("client.DirectInput.disableExclusiveInput", false);
}

inline bool getEnableBackbufferCapture() {
return bridge_util::Config::getOption<bool>("client.enableBackbufferCapture", false);
}

inline DI::ForwardPolicy getForwardDirectInputMousePolicy() {
return (DI::ForwardPolicy)bridge_util::Config::getOption<int>("client.DirectInput.forward.mousePolicy", DI::RemixUIActive);
}
Expand Down
20 changes: 17 additions & 3 deletions src/client/d3d9_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@
#include "d3d9_texture.h"
#include "d3d9_cubetexture.h"

#include "d3d9_surfacebuffer_helper.h"
#include "util_bridge_assert.h"
#include "util_gdi.h"

Direct3DSurface9_LSS::Direct3DSurface9_LSS(BaseDirect3DDevice9Ex_LSS* const pDevice,
const D3DSURFACE_DESC& desc)
const D3DSURFACE_DESC& desc, bool isBackBuffer)
: Direct3DResource9_LSS((IDirect3DSurface9*)nullptr, pDevice)
, m_bUseSharedHeap(GlobalOptions::getUseSharedHeapForTextures())
, m_desc(desc) {
, m_desc(desc)
, m_isBackBuffer(isBackBuffer)
{
}

Direct3DSurface9_LSS::~Direct3DSurface9_LSS() {
Expand Down Expand Up @@ -129,7 +132,18 @@ HRESULT Direct3DSurface9_LSS::LockRect(D3DLOCKED_RECT* pLockedRect, CONST RECT*
return E_FAIL;
}
}
// Do nothing on lock on server side for now, all logic happens on unlock!

// We send LockRect() calls to server in cases wherein backbuffer is used to capture the screenshot
if (m_isBackBuffer && ClientOptions::getEnableBackbufferCapture() && !(Flags & D3DLOCK_DISCARD)) {
UID currentUID;
{
ClientMessage c(Commands::IDirect3DSurface9_LockRect, getId());
currentUID = c.get_uid();
}

return copyServerSurfaceRawData(this, currentUID);
}

return S_OK;
}

Expand Down
10 changes: 7 additions & 3 deletions src/client/d3d9_surface.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,18 @@ class Direct3DSurface9_LSS: public Direct3DResource9_LSS<IDirect3DSurface9> {

public:
Direct3DSurface9_LSS(BaseDirect3DDevice9Ex_LSS* const pDevice,
const D3DSURFACE_DESC& desc);
const D3DSURFACE_DESC& desc,
bool isBackBuffer = false);

template<typename ContainerType>
Direct3DSurface9_LSS(BaseDirect3DDevice9Ex_LSS* const pDevice,
ContainerType* const pContainer,
const D3DSURFACE_DESC& desc)
const D3DSURFACE_DESC& desc,
bool isBackBuffer = false)
: Direct3DResource9_LSS((IDirect3DSurface9*)nullptr, pDevice, pContainer)
, m_bUseSharedHeap(GlobalOptions::getUseSharedHeapForTextures())
, m_desc(desc) {
, m_desc(desc)
, m_isBackBuffer(isBackBuffer) {
}

~Direct3DSurface9_LSS();
Expand Down Expand Up @@ -89,6 +92,7 @@ class Direct3DSurface9_LSS: public Direct3DResource9_LSS<IDirect3DSurface9> {

private:
/*** Lock/Unlock Functionality ***/
bool m_isBackBuffer;
bool lock(D3DLOCKED_RECT& lockedRect, const RECT* pRect, const DWORD& flags);
void unlock();
static RECT resolveLockInfoRect(const RECT* const pRect, const D3DSURFACE_DESC& desc);
Expand Down
2 changes: 1 addition & 1 deletion src/client/d3d9_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ HRESULT Direct3DSwapChain9_LSS::GetBackBuffer(UINT iBackBuffer, D3DBACKBUFFER_TY
desc.Pool = D3DPOOL_DEFAULT;
desc.Type = D3DRTYPE_SURFACE;

Direct3DSurface9_LSS* pLssSurface = trackWrapper(new Direct3DSurface9_LSS(m_pDevice, this, desc));
Direct3DSurface9_LSS* pLssSurface = trackWrapper(new Direct3DSurface9_LSS(m_pDevice, this, desc, true));
setChild(iBackBuffer, pLssSurface);

(*ppBackBuffer) = pLssSurface;
Expand Down
3 changes: 2 additions & 1 deletion src/client/d3d9_swapchain.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class Direct3DSwapChain9_LSS: public Direct3DContainer9_LSS<D3DBase<IDirect3DSwa
m_presParam.BackBufferWidth,
m_presParam.BackBufferHeight
};
auto* const pLssBackBuffer = trackWrapper(new Direct3DSurface9_LSS(pDevice, this, backBufferDesc));
auto* const pLssBackBuffer = trackWrapper(new Direct3DSurface9_LSS(pDevice, this, backBufferDesc, true));

setChild(childIdx, pLssBackBuffer);
UID currentUID = 0;
{
Expand Down
6 changes: 5 additions & 1 deletion src/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2521,7 +2521,11 @@ void ProcessDeviceCommandQueue() {
}
case IDirect3DSurface9_LockRect:
{
// This is a no-op right now because we're doing all the logic on Unlock
// Currently we only recieve calls for LockRect in cases where backbuffer data is to be copied for screenshots
GET_HND(pHandle);
const auto pSurface = (IDirect3DSurface9*) gpD3DResources[pHandle];
HRESULT hresult = ReturnSurfaceDataToClient(pSurface, S_OK, currentUID);
assert(SUCCEEDED(hresult));
break;
}
case IDirect3DSurface9_UnlockRect:
Expand Down

0 comments on commit 8140bd3

Please sign in to comment.