Skip to content

Commit

Permalink
Switch to the D3DSWAPEFFECT_FLIPEX swap model
Browse files Browse the repository at this point in the history
  • Loading branch information
dpjudas committed Dec 2, 2019
1 parent 4313927 commit a9e6592
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
8 changes: 4 additions & 4 deletions src/rendering/polyrenderer/backend/poly_framebuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ extern FString gpuStatOutput;

#ifdef WIN32
void I_PolyPresentInit();
uint8_t *I_PolyPresentLock(int w, int h, int &pitch);
uint8_t *I_PolyPresentLock(int w, int h, bool vsync, int &pitch);
void I_PolyPresentUnlock(int x, int y, int w, int h);
void I_PolyPresentDeinit();
#else
void I_PolyPresentInit() { }
uint8_t *I_PolyPresentLock(int w, int h, int &pitch) { pitch = 0; return nullptr; }
uint8_t *I_PolyPresentLock(int w, int h, bool vsync, int &pitch) { pitch = 0; return nullptr; }
void I_PolyPresentUnlock(int x, int y, int w, int h) { }
void I_PolyPresentDeinit() { }
#endif
Expand Down Expand Up @@ -157,7 +157,7 @@ void PolyFrameBuffer::Update()
int pixelsize = 4;
const uint8_t *src = (const uint8_t*)mCanvas->GetPixels();
int pitch = 0;
uint8_t *dst = I_PolyPresentLock(w, h, pitch);
uint8_t *dst = I_PolyPresentLock(w, h, cur_vsync, pitch);
if (dst)
{
#if 1
Expand Down Expand Up @@ -444,7 +444,7 @@ uint32_t PolyFrameBuffer::GetCaps()

void PolyFrameBuffer::SetVSync(bool vsync)
{
// This is handled in PolySwapChain::AcquireImage.
cur_vsync = vsync;
}

void PolyFrameBuffer::CleanForRestart()
Expand Down
2 changes: 2 additions & 0 deletions src/rendering/polyrenderer/backend/poly_framebuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ class PolyFrameBuffer : public SystemBaseFrameBuffer
std::unique_ptr<PolyDepthStencil> mDepthStencil;
std::shared_ptr<DrawerCommandQueue> mDrawCommands;
RenderMemory mFrameMemory;

bool cur_vsync = false;
};

inline PolyFrameBuffer *GetPolyFrameBuffer() { return static_cast<PolyFrameBuffer*>(screen); }
27 changes: 13 additions & 14 deletions src/win32/win32polyvideo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ namespace
int ClientHeight = 0;
bool CurrentVSync = false;

IDirect3D9 *d3d9 = nullptr;
IDirect3DDevice9 *device = nullptr;
IDirect3DSurface9 *surface = nullptr;
IDirect3D9Ex *d3d9 = nullptr;
IDirect3DDevice9Ex *device = nullptr;
IDirect3DSurface9* surface = nullptr;
}

void I_PolyPresentInit()
{
d3d9 = Direct3DCreate9(D3D_SDK_VERSION);
Direct3DCreate9Ex(D3D_SDK_VERSION, &d3d9);
if (!d3d9)
{
I_FatalError("Direct3DCreate9 failed");
Expand All @@ -35,52 +35,51 @@ void I_PolyPresentInit()
RECT rect = {};
GetClientRect(Window, &rect);

CurrentVSync = vid_vsync;
ClientWidth = rect.right;
ClientHeight = rect.bottom;

D3DPRESENT_PARAMETERS pp = {};
pp.Windowed = true;
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
pp.SwapEffect = D3DSWAPEFFECT_FLIPEX;
pp.BackBufferWidth = ClientWidth;
pp.BackBufferHeight = ClientHeight;
pp.BackBufferCount = 1;
pp.hDeviceWindow = Window;
pp.PresentationInterval = CurrentVSync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
pp.PresentationInterval = CurrentVSync ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_IMMEDIATE;

HRESULT result = d3d9->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Window, D3DCREATE_HARDWARE_VERTEXPROCESSING, &pp, &device);
HRESULT result = d3d9->CreateDeviceEx(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Window, D3DCREATE_HARDWARE_VERTEXPROCESSING, &pp, nullptr, &device);
if (FAILED(result))
{
I_FatalError("IDirect3D9.CreateDevice failed");
}
}

uint8_t *I_PolyPresentLock(int w, int h, int &pitch)
uint8_t *I_PolyPresentLock(int w, int h, bool vsync, int &pitch)
{
HRESULT result;

RECT rect = {};
GetClientRect(Window, &rect);
if (rect.right != ClientWidth || rect.bottom != ClientHeight || CurrentVSync != vid_vsync)
if (rect.right != ClientWidth || rect.bottom != ClientHeight || CurrentVSync != vsync)
{
if (surface)
{
surface->Release();
surface = nullptr;
}

CurrentVSync = vid_vsync;
CurrentVSync = vsync;
ClientWidth = rect.right;
ClientHeight = rect.bottom;

D3DPRESENT_PARAMETERS pp = {};
pp.Windowed = true;
pp.SwapEffect = D3DSWAPEFFECT_DISCARD;
pp.SwapEffect = D3DSWAPEFFECT_FLIPEX;
pp.BackBufferWidth = ClientWidth;
pp.BackBufferHeight = ClientHeight;
pp.BackBufferCount = 1;
pp.hDeviceWindow = Window;
pp.PresentationInterval = CurrentVSync ? D3DPRESENT_INTERVAL_ONE : D3DPRESENT_INTERVAL_IMMEDIATE;
pp.PresentationInterval = CurrentVSync ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_IMMEDIATE;
device->Reset(&pp);
}

Expand Down Expand Up @@ -173,7 +172,7 @@ void I_PolyPresentUnlock(int x, int y, int width, int height)

result = device->EndScene();
if (SUCCEEDED(result))
device->Present(nullptr, nullptr, 0, nullptr);
device->PresentEx(nullptr, nullptr, 0, nullptr, CurrentVSync ? 0 : D3DPRESENT_FORCEIMMEDIATE);
}

backbuffer->Release();
Expand Down

0 comments on commit a9e6592

Please sign in to comment.