Skip to content

Commit

Permalink
Moved DX9 device creation back to the main thread
Browse files Browse the repository at this point in the history
This fixes fullscreen in DX9 and allows to remove workarounds
  • Loading branch information
Xottab-DUTY committed Oct 23, 2019
1 parent ec0314c commit eb3b489
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/Layers/xrRenderDX9/dx9HW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void CHW::CreateDevice(SDL_Window* m_sdlWnd)
{
CreateD3D();

const bool bWindowed = true; //!psDeviceFlags.is(rsFullscreen);
const bool bWindowed = !psDeviceFlags.is(rsFullscreen);

m_DriverType = Caps.bForceGPU_REF ? D3DDEVTYPE_REF : D3DDEVTYPE_HAL;

Expand Down Expand Up @@ -227,7 +227,7 @@ void CHW::Reset()
_RELEASE(pBaseZB);
_RELEASE(pBaseRT);

const bool bWindowed = true; // !psDeviceFlags.is(rsFullscreen);
const bool bWindowed = !psDeviceFlags.is(rsFullscreen);

DevPP.BackBufferWidth = Device.dwWidth;
DevPP.BackBufferHeight = Device.dwHeight;
Expand Down
6 changes: 6 additions & 0 deletions src/xrEngine/Device_create.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ void CRenderDevice::Create()
// Start all threads
mt_bMustExit = FALSE;

// To work correctly, DX9 in fullscreen mode requires that
// the device must be created at the same thread where the main window was created
const static bool isDX9Renderer = GEnv.Render->get_dx_level() == 0x00090000;
if (isDX9Renderer)
CreateInternal();

Threading::SetThreadName(NULL, "X-Ray Window thread");
Threading::SpawnThread(PrimaryThreadProc, "X-RAY Primary thread", 0, this);
Threading::SpawnThread(SecondaryThreadProc, "X-Ray Secondary thread", 0, this);
Expand Down
3 changes: 3 additions & 0 deletions src/xrEngine/Device_destroy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,7 @@ void CRenderDevice::ResetInternal(bool precache)

if (!GEnv.isDedicatedServer)
pInput->GrabInput(true);

shouldReset = false;
precacheWhileReset = false;
}
23 changes: 18 additions & 5 deletions src/xrEngine/device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ bool CRenderDevice::RenderBegin()
if (GEnv.isDedicatedServer)
return true;

switch (GEnv.Render->GetDeviceState())
const static bool isDX9Renderer = GEnv.Render->get_dx_level() == 0x00090000;
if (!isDX9Renderer)
LastDeviceState = GEnv.Render->GetDeviceState();

switch (LastDeviceState)
{
case DeviceState::Normal: break;
case DeviceState::Lost:
Expand All @@ -63,7 +67,7 @@ bool CRenderDevice::RenderBegin()

case DeviceState::NeedReset:
// Check if the device is ready to be reset
ResetInternal();
Reset();
return false;

default: R_ASSERT(0);
Expand Down Expand Up @@ -185,11 +189,9 @@ void CRenderDevice::PrimaryThreadProc(void* context)
return;
}

if (device.shouldReset)
if (device.shouldReset) // never happen on DX9, will be done in message_loop()
{
device.ResetInternal(device.precacheWhileReset);
device.shouldReset = false;
device.precacheWhileReset = false;
}

device.ProcessFrame();
Expand Down Expand Up @@ -406,6 +408,8 @@ void CRenderDevice::message_loop()
return;
}

const static bool isDX9Renderer = GEnv.Render->get_dx_level() == 0x00090000;

bool timedOut = false;

while (!SDL_QuitRequested()) // SDL_PumpEvents is here
Expand Down Expand Up @@ -481,8 +485,17 @@ void CRenderDevice::message_loop()
}
}

if (isDX9Renderer)
{
LastDeviceState = GEnv.Render->GetDeviceState();
}

if (!timedOut)
{
if (isDX9Renderer && shouldReset)
{
ResetInternal(precacheWhileReset);
}
primaryProcessFrame.Set();
}

Expand Down
1 change: 1 addition & 0 deletions src/xrEngine/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ class ENGINE_API CRenderDevice : public CRenderDeviceBase, public IWindowHandler
}

private:
std::atomic<DeviceState> LastDeviceState;
std::atomic<bool> shouldReset;
std::atomic<bool> precacheWhileReset;
std::atomic<bool> mtProcessingAllowed;
Expand Down

0 comments on commit eb3b489

Please sign in to comment.