diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp index cb1ea4298d..7454d229c0 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.cpp @@ -38,8 +38,19 @@ D3D12GSRender::D3D12GSRender() check(m_device->CreateCommandQueue(©QueueDesc, IID_PPV_ARGS(&m_commandQueueCopy))); check(m_device->CreateCommandQueue(&graphicQueueDesc, IID_PPV_ARGS(&m_commandQueueGraphic))); - GSFrameBase2 *tmp = GetGSFrame(); - tmp->Show(); + m_frame = GetGSFrame(); + + DXGI_SWAP_CHAIN_DESC swapChain = {}; + swapChain.BufferCount = 2; + swapChain.Windowed = true; + swapChain.OutputWindow = m_frame->getHandle(); + swapChain.BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; + swapChain.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + swapChain.SampleDesc.Count = 1; + swapChain.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH; + swapChain.SwapEffect = DXGI_SWAP_EFFECT_FLIP_SEQUENTIAL; + + check(dxgiFactory->CreateSwapChain(m_commandQueueGraphic, &swapChain, (IDXGISwapChain**)&m_swapChain)); } D3D12GSRender::~D3D12GSRender() @@ -48,13 +59,14 @@ D3D12GSRender::~D3D12GSRender() m_commandQueueGraphic->Release(); m_commandQueueCopy->Release(); m_device->Release(); + m_swapChain->Release(); } void D3D12GSRender::Close() { + m_frame->Hide(); } - void D3D12GSRender::InitDrawBuffers() { if (!m_fbo.IsCreated() || RSXThread::m_width != m_lastWidth || RSXThread::m_height != m_lastHeight || m_lastDepth != m_surface_depth_format) @@ -221,6 +233,7 @@ void D3D12GSRender::InitDrawBuffers() void D3D12GSRender::OnInit() { + m_frame->Show(); } void D3D12GSRender::OnInitThread() @@ -606,4 +619,5 @@ void D3D12GSRender::ExecCMD() void D3D12GSRender::Flip() { + check(m_swapChain->Present(1, 0)); } diff --git a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h index 4439ed8f47..12e1c253a4 100644 --- a/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h +++ b/rpcs3/Emu/RSX/D3D12/D3D12GSRender.h @@ -31,7 +31,7 @@ public: virtual void SetCurrent(void* ctx) = 0; virtual void DeleteContext(void* ctx) = 0; virtual void Flip(void* ctx) = 0; - + virtual HWND getHandle() const = 0; }; typedef GSFrameBase2*(*GetGSFrameCb2)(); @@ -65,13 +65,14 @@ private: ID3D12Device* m_device; ID3D12CommandQueue *m_commandQueueCopy; ID3D12CommandQueue *m_commandQueueGraphic; + struct IDXGISwapChain3 *m_swapChain; size_t m_lastWidth, m_lastHeight, m_lastDepth; void* m_context; public: - // GSFrameBase* m_frame; + GSFrameBase2 *m_frame; u32 m_draw_frames; u32 m_skip_frames; diff --git a/rpcs3/Gui/D3DGSFrame.cpp b/rpcs3/Gui/D3DGSFrame.cpp index 6d38812a8e..c2ede93df7 100644 --- a/rpcs3/Gui/D3DGSFrame.cpp +++ b/rpcs3/Gui/D3DGSFrame.cpp @@ -92,4 +92,9 @@ void D3DGSFrame::SetViewport(int x, int y, u32 w, u32 h) glViewport(vx + x, vy + y, viewport.GetWidth(), viewport.GetHeight()); */ -} \ No newline at end of file +} + +HWND D3DGSFrame::getHandle() const +{ + return canvas->GetHandle(); +} diff --git a/rpcs3/Gui/D3DGSFrame.h b/rpcs3/Gui/D3DGSFrame.h index 4925eeb7fa..51c395eee1 100644 --- a/rpcs3/Gui/D3DGSFrame.h +++ b/rpcs3/Gui/D3DGSFrame.h @@ -24,7 +24,8 @@ struct D3DGSFrame : public GSFrame, public GSFrameBase2 wxWindow* GetCanvas() const { return canvas; } - virtual void SetViewport(int x, int y, u32 w, u32 h); + virtual void SetViewport(int x, int y, u32 w, u32 h) override; + virtual HWND getHandle() const override; private: virtual void OnSize(wxSizeEvent& event);