@@ -71,7 +71,7 @@ void Direct3DDevice9Ex_LSS<EnableSync>::onDestroy() {
71
71
}
72
72
73
73
template <bool EnableSync>
74
- void Direct3DDevice9Ex_LSS<EnableSync>::releaseInternalObjects() {
74
+ void Direct3DDevice9Ex_LSS<EnableSync>::releaseInternalObjects(bool resetState ) {
75
75
// Take references first so that the device won't be
76
76
// destroyed unintentionally and to prevent releaseInternalObjects()
77
77
// recursion.
@@ -82,23 +82,25 @@ void Direct3DDevice9Ex_LSS<EnableSync>::releaseInternalObjects() {
82
82
83
83
destroyImplicitObjects ();
84
84
85
- for (auto & texture : m_state.textures ) {
86
- texture.reset (nullptr );
87
- }
85
+ if (resetState) {
86
+ for (auto & texture : m_state.textures ) {
87
+ texture.reset (nullptr );
88
+ }
88
89
89
- for (auto & rt : m_state.renderTargets ) {
90
- rt.reset (nullptr );
91
- }
90
+ for (auto & rt : m_state.renderTargets ) {
91
+ rt.reset (nullptr );
92
+ }
92
93
93
- for (auto & st : m_state.streams ) {
94
- st.reset (nullptr );
95
- }
94
+ for (auto & st : m_state.streams ) {
95
+ st.reset (nullptr );
96
+ }
96
97
97
- m_state.indices .reset (nullptr );
98
- m_state.depthStencil .reset (nullptr );
99
- m_state.vertexShader .reset (nullptr );
100
- m_state.pixelShader .reset (nullptr );
101
- m_state.vertexDecl .reset (nullptr );
98
+ m_state.indices .reset (nullptr );
99
+ m_state.depthStencil .reset (nullptr );
100
+ m_state.vertexShader .reset (nullptr );
101
+ m_state.pixelShader .reset (nullptr );
102
+ m_state.vertexDecl .reset (nullptr );
103
+ }
102
104
103
105
for (uint32_t n = 0 ; n < implicitRefCnt; n++) {
104
106
D3DBase::Release ();
@@ -481,47 +483,19 @@ template<bool EnableSync>
481
483
HRESULT Direct3DDevice9Ex_LSS<EnableSync>::Present (CONST RECT* pSourceRect, CONST RECT* pDestRect, HWND hDestWindowOverride, CONST RGNDATA* pDirtyRegion) {
482
484
ZoneScoped;
483
485
LogFunctionCall ();
484
- #ifdef ENABLE_PRESENT_SEMAPHORE_TRACE
485
- Logger::trace (format_string (" Present(): ClientMessage counter is at %d." , ClientMessage::get_counter ()));
486
- #endif
487
- ClientMessage::reset_counter ();
488
- gSceneState = WaitBeginScene;
489
-
490
- const auto hresult = D3D_OK;
491
486
492
487
// If the bridge was disabled in the meantime for some reason we want to bail
493
488
// out here so we don't spend time waiting on the Present semaphore or trying
494
489
// to send keyboard state to the server.
495
490
if (!gbBridgeRunning) {
496
- return hresult ;
491
+ return D3D_OK ;
497
492
}
498
493
499
- if (remixapi::g_bInterfaceInitialized && remixapi::g_presentCallback) {
494
+ if (remixapi::g_bInterfaceInitialized && remixapi::g_presentCallback) {
500
495
remixapi::g_presentCallback ();
501
496
}
502
497
503
-
504
- if (SUCCEEDED (hresult)) {
505
- BRIDGE_DEVICE_LOCKGUARD ();
506
-
507
- // Send present first
508
- {
509
- ClientMessage c (Commands::IDirect3DDevice9Ex_Present, getId ());
510
- c.send_data (sizeof (RECT), (void *) pSourceRect);
511
- c.send_data (sizeof (RECT), (void *) pDestRect);
512
- c.send_data ((uint32_t ) hDestWindowOverride);
513
- c.send_data (sizeof (RGNDATA), (void *) pDirtyRegion);
514
- }
515
-
516
- const auto syncResult = syncOnPresent ();
517
- if (syncResult == ERROR_SEM_TIMEOUT) {
518
- return ERROR_SEM_TIMEOUT;
519
- }
520
- }
521
-
522
- FrameMark;
523
-
524
- return hresult;
498
+ return m_pSwapchain->Present (pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, 0 );
525
499
}
526
500
527
501
template <bool EnableSync>
@@ -3241,7 +3215,15 @@ HRESULT Direct3DDevice9Ex_LSS<EnableSync>::PresentEx(CONST RECT* pSourceRect, CO
3241
3215
ZoneScoped;
3242
3216
LogMissingFunctionCall ();
3243
3217
assert (m_ex);
3244
- return D3D_OK;
3218
+
3219
+ // If the bridge was disabled in the meantime for some reason we want to bail
3220
+ // out here so we don't spend time waiting on the Present semaphore or trying
3221
+ // to send keyboard state to the server.
3222
+ if (!gbBridgeRunning) {
3223
+ return D3D_OK;
3224
+ }
3225
+
3226
+ return m_pSwapchain->Present (pSourceRect, pDestRect, hDestWindowOverride, pDirtyRegion, dwFlags);
3245
3227
}
3246
3228
3247
3229
template <bool EnableSync>
@@ -3442,8 +3424,42 @@ template<bool EnableSync>
3442
3424
HRESULT Direct3DDevice9Ex_LSS<EnableSync>::ResetEx (D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode) {
3443
3425
ZoneScoped;
3444
3426
assert (m_ex);
3445
- LogMissingFunctionCall ();
3446
- return D3D_OK;
3427
+ LogFunctionCall ();
3428
+ HRESULT res = S_OK;
3429
+ {
3430
+ BRIDGE_DEVICE_LOCKGUARD ();
3431
+ // Clear all device state and release implicit/internal objects
3432
+ releaseInternalObjects (false );
3433
+
3434
+ const auto presParam = Direct3DSwapChain9_LSS::sanitizePresentationParameters (*pPresentationParameters, getCreateParams ());
3435
+ m_presParams = presParam;
3436
+ WndProc::unset ();
3437
+ WndProc::set (getWinProcHwnd ());
3438
+ // Tell Server to do the Reset
3439
+ size_t currentUID = 0 ;
3440
+ {
3441
+ ClientMessage c (Commands::IDirect3DDevice9Ex_ResetEx, getId ());
3442
+ currentUID = c.get_uid ();
3443
+ c.send_data (sizeof (D3DPRESENT_PARAMETERS), &presParam);
3444
+ c.send_data (sizeof (D3DDISPLAYMODEEX), pFullscreenDisplayMode);
3445
+ }
3446
+
3447
+ // Perform an WAIT_FOR_OPTIONAL_SERVER_RESPONSE but don't return since we still have work to do.
3448
+ if (GlobalOptions::getSendAllServerResponses ()) {
3449
+ const uint32_t timeoutMs = GlobalOptions::getAckTimeout ();
3450
+ if (Result::Success != DeviceBridge::waitForCommand (Commands::Bridge_Response, timeoutMs, nullptr , true , currentUID)) {
3451
+ Logger::err (" Direct3DDevice9Ex_LSS::ResetEx() failed with : no response from server." );
3452
+ }
3453
+ res = (HRESULT) DeviceBridge::get_data ();
3454
+ DeviceBridge::pop_front ();
3455
+ }
3456
+
3457
+ // Reset swapchain and link server backbuffer/depth buffer after the server reset its swapchain, or we will link to the old backbuffer/depth resources
3458
+ initImplicitObjects (presParam);
3459
+ // Keeping a track of previous present parameters, to detect and handle mode changes
3460
+ m_previousPresentParams = *pPresentationParameters;
3461
+ }
3462
+ return res;
3447
3463
}
3448
3464
3449
3465
template <bool EnableSync>
@@ -3861,13 +3877,15 @@ void Direct3DDevice9Ex_LSS<EnableSync>::destroyImplicitObjects() {
3861
3877
assert (rtRefCnt == 0 && " Implicit RenderTarget has not been released!" );
3862
3878
m_pImplicitRenderTarget = nullptr ;
3863
3879
--m_implicitRefCnt;
3880
+ m_state.renderTargets [0 ].reset (nullptr );
3864
3881
3865
3882
// Release implicit DepthStencil
3866
3883
if (GET_PRES_PARAM ().EnableAutoDepthStencil ) {
3867
3884
const auto dsRefCnt = m_pImplicitDepthStencil->Release ();
3868
3885
assert (dsRefCnt == 0 && " Implicit DepthStencil has not been released!" );
3869
3886
m_pImplicitDepthStencil = nullptr ;
3870
3887
--m_implicitRefCnt;
3888
+ m_state.depthStencil .reset (nullptr );
3871
3889
}
3872
3890
3873
3891
const size_t nBackBuf = GET_PRES_PARAM ().BackBufferCount ;
0 commit comments