Skip to content

Commit

Permalink
Merge branch 'dev/lvengesanam/optimize_device-reset_api_call' into 'm…
Browse files Browse the repository at this point in the history
…ain'

Optimize Direct3DDevice9::Reset api call on bridge

See merge request lightspeedrtx/bridge-remix-nv!142
  • Loading branch information
lvengesanam committed Feb 2, 2025
2 parents 39e4a83 + 9490ed2 commit 72385cb
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 19 deletions.
47 changes: 31 additions & 16 deletions src/client/d3d9_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3801,14 +3801,22 @@ void Direct3DDevice9Ex_LSS<EnableSync>::initImplicitSwapchain(const D3DPRESENT_P
template<bool EnableSync>
void Direct3DDevice9Ex_LSS<EnableSync>::initImplicitRenderTarget() {
IDirect3DSurface9* pRenderTarget = nullptr;
CreateRenderTarget(GET_PRES_PARAM().BackBufferWidth,
GET_PRES_PARAM().BackBufferHeight,
GET_PRES_PARAM().BackBufferFormat,
GET_PRES_PARAM().MultiSampleType,
GET_PRES_PARAM().MultiSampleQuality,
false,
&pRenderTarget,
nullptr);

// Creating a place-holder surface
D3DSURFACE_DESC desc;
desc.Width = GET_PRES_PARAM().BackBufferWidth;
desc.Height = GET_PRES_PARAM().BackBufferHeight;
desc.Format = GET_PRES_PARAM().BackBufferFormat;
desc.MultiSampleType = GET_PRES_PARAM().MultiSampleType;
desc.MultiSampleQuality = GET_PRES_PARAM().MultiSampleQuality;
desc.Usage = D3DUSAGE_RENDERTARGET;
desc.Pool = D3DPOOL_DEFAULT;
desc.Type = D3DRTYPE_SURFACE;

// Insert our own IDirect3DSurface9 interface implementation
Direct3DSurface9_LSS* pLssSurface = trackWrapper(new Direct3DSurface9_LSS(this, desc));
pRenderTarget = (IDirect3DSurface9*) pLssSurface;

m_pImplicitRenderTarget = bridge_cast<Direct3DSurface9_LSS*>(pRenderTarget);
{
ClientMessage c(Commands::IDirect3DDevice9Ex_LinkBackBuffer, getId());
Expand All @@ -3822,14 +3830,21 @@ template<bool EnableSync>
void Direct3DDevice9Ex_LSS<EnableSync>::initImplicitDepthStencil() {
assert(GET_PRES_PARAM().EnableAutoDepthStencil);
IDirect3DSurface9* pShadowDepthBuffer = nullptr;
CreateDepthStencilSurface(GET_PRES_PARAM().BackBufferWidth,
GET_PRES_PARAM().BackBufferHeight,
GET_PRES_PARAM().AutoDepthStencilFormat,
GET_PRES_PARAM().MultiSampleType,
GET_PRES_PARAM().MultiSampleQuality,
false,
&pShadowDepthBuffer,
nullptr);

// Creating a place-holder surface
D3DSURFACE_DESC desc;
desc.Width = GET_PRES_PARAM().BackBufferWidth;
desc.Height = GET_PRES_PARAM().BackBufferHeight;
desc.Format = GET_PRES_PARAM().AutoDepthStencilFormat;
desc.MultiSampleType = GET_PRES_PARAM().MultiSampleType;
desc.MultiSampleQuality = GET_PRES_PARAM().MultiSampleQuality;
desc.Usage = D3DUSAGE_DEPTHSTENCIL;
desc.Pool = D3DPOOL_DEFAULT;
desc.Type = D3DRTYPE_SURFACE;

Direct3DSurface9_LSS* pLssSurface = trackWrapper(new Direct3DSurface9_LSS(this, desc));
pShadowDepthBuffer = (IDirect3DSurface9*) pLssSurface;

m_pImplicitDepthStencil = bridge_cast<Direct3DSurface9_LSS*>(pShadowDepthBuffer);
{
ClientMessage c(Commands::IDirect3DDevice9Ex_LinkAutoDepthStencil, getId());
Expand Down
2 changes: 1 addition & 1 deletion src/client/d3d9_volume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void Direct3DVolume9_LSS::onDestroy() {
// are completely owned and managed by their parent container, and so only need
// to be unlinked from x64 counterpart to prevent hash collisions at server side.
const auto command = isStandalone() ? Commands::IDirect3DVolume9_Destroy :
Commands::Bridge_UnlinkResource;
Commands::Bridge_UnlinkVolumeResource;

ClientMessage { command, getId() };
}
Expand Down
7 changes: 6 additions & 1 deletion src/server/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2767,7 +2767,12 @@ void ProcessDeviceCommandQueue() {
gpD3DResources.erase(pHandle);
break;
}

case Bridge_UnlinkVolumeResource:
{
GET_HND(pHandle);
gpD3DVolumes.erase(pHandle);
break;
}
/*
* BridgeApi commands
*/
Expand Down
3 changes: 2 additions & 1 deletion src/util/util_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ namespace Commands {
// desposed of, or known to be released before the unlink to
// prevent leaks.
Bridge_UnlinkResource,

Bridge_UnlinkVolumeResource,
// These are not actually official D3D9 API calls.
IDirect3DDevice9Ex_LinkSwapchain,
IDirect3DDevice9Ex_LinkBackBuffer,
Expand Down Expand Up @@ -493,6 +493,7 @@ namespace Commands {
case Bridge_SharedHeap_Dealloc: return "SharedHeap_Dealloc";

case Bridge_UnlinkResource: return "Bridge_UnlinkResource";
case Bridge_UnlinkVolumeResource: return "Bridge_UnlinkVolumeResource";

case IDirect3DDevice9Ex_LinkSwapchain: return "IDirect3DDevice9Ex_LinkSwapchain";
case IDirect3DDevice9Ex_LinkBackBuffer: return "IDirect3DDevice9Ex_LinkBackBuffer";
Expand Down

0 comments on commit 72385cb

Please sign in to comment.