Define LIBRETRO macro when building core, skip swap chain

This commit is contained in:
Connor McLaughlin 2020-07-10 14:01:48 +10:00
parent 69f3128b07
commit c01854e9d1
4 changed files with 65 additions and 14 deletions

View File

@ -1,3 +1,7 @@
if(BUILD_LIBRETRO_CORE)
add_definitions("-DLIBRETRO=1")
endif()
add_subdirectory(common) add_subdirectory(common)
add_subdirectory(core) add_subdirectory(core)
add_subdirectory(scmversion) add_subdirectory(scmversion)

View File

@ -1,5 +1,6 @@
#include "namco_guncon.h" #include "namco_guncon.h"
#include "common/assert.h" #include "common/assert.h"
#include "common/log.h"
#include "common/state_wrapper.h" #include "common/state_wrapper.h"
#include "gpu.h" #include "gpu.h"
#include "host_display.h" #include "host_display.h"
@ -7,6 +8,7 @@
#include "resources.h" #include "resources.h"
#include "system.h" #include "system.h"
#include <array> #include <array>
Log_SetChannel(NamcoGunCon);
NamcoGunCon::NamcoGunCon(System* system) : m_system(system) {} NamcoGunCon::NamcoGunCon(System* system) : m_system(system) {}

View File

@ -6,11 +6,11 @@
#include "display_ps.hlsl.h" #include "display_ps.hlsl.h"
#include "display_vs.hlsl.h" #include "display_vs.hlsl.h"
#include <array> #include <array>
#if defined(__has_include) && __has_include(<dxgi1_5.h>) #ifndef LIBRETRO
#include <dxgi1_5.h> #include <dxgi1_5.h>
#endif
#include <imgui.h> #include <imgui.h>
#include <imgui_impl_dx11.h> #include <imgui_impl_dx11.h>
#endif
Log_SetChannel(D3D11HostDisplay); Log_SetChannel(D3D11HostDisplay);
namespace FrontendCommon { namespace FrontendCommon {
@ -72,7 +72,9 @@ D3D11HostDisplay::D3D11HostDisplay() = default;
D3D11HostDisplay::~D3D11HostDisplay() D3D11HostDisplay::~D3D11HostDisplay()
{ {
AssertMsg(!m_context, "Context should have been destroyed by now"); AssertMsg(!m_context, "Context should have been destroyed by now");
#ifndef LIBRETRO
AssertMsg(!m_swap_chain, "Swap chain should have been destroyed by now"); AssertMsg(!m_swap_chain, "Swap chain should have been destroyed by now");
#endif
} }
HostDisplay::RenderAPI D3D11HostDisplay::GetRenderAPI() const HostDisplay::RenderAPI D3D11HostDisplay::GetRenderAPI() const
@ -97,7 +99,11 @@ bool D3D11HostDisplay::HasRenderDevice() const
bool D3D11HostDisplay::HasRenderSurface() const bool D3D11HostDisplay::HasRenderSurface() const
{ {
#ifndef LIBRETRO
return static_cast<bool>(m_swap_chain); return static_cast<bool>(m_swap_chain);
#else
return true;
#endif
} }
std::unique_ptr<HostDisplayTexture> D3D11HostDisplay::CreateTexture(u32 width, u32 height, const void* initial_data, std::unique_ptr<HostDisplayTexture> D3D11HostDisplay::CreateTexture(u32 width, u32 height, const void* initial_data,
@ -163,11 +169,14 @@ bool D3D11HostDisplay::DownloadTexture(const void* texture_handle, u32 x, u32 y,
void D3D11HostDisplay::SetVSync(bool enabled) void D3D11HostDisplay::SetVSync(bool enabled)
{ {
#ifndef LIBRETRO
m_vsync = enabled; m_vsync = enabled;
#endif
} }
bool D3D11HostDisplay::CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, bool debug_device) bool D3D11HostDisplay::CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, bool debug_device)
{ {
#ifndef LIBRETRO
UINT create_flags = 0; UINT create_flags = 0;
if (debug_device) if (debug_device)
create_flags |= D3D11_CREATE_DEVICE_DEBUG; create_flags |= D3D11_CREATE_DEVICE_DEBUG;
@ -260,7 +269,6 @@ bool D3D11HostDisplay::CreateRenderDevice(const WindowInfo& wi, std::string_view
} }
m_allow_tearing_supported = false; m_allow_tearing_supported = false;
#if defined(__has_include) && __has_include(<dxgi1_5.h>)
ComPtr<IDXGIFactory5> dxgi_factory5; ComPtr<IDXGIFactory5> dxgi_factory5;
hr = m_dxgi_factory.As(&dxgi_factory5); hr = m_dxgi_factory.As(&dxgi_factory5);
if (SUCCEEDED(hr)) if (SUCCEEDED(hr))
@ -279,25 +287,31 @@ bool D3D11HostDisplay::CreateRenderDevice(const WindowInfo& wi, std::string_view
bool D3D11HostDisplay::InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device) bool D3D11HostDisplay::InitializeRenderDevice(std::string_view shader_cache_directory, bool debug_device)
{ {
#ifndef LIBRETRO
if (m_window_info.type != WindowInfo::Type::Surfaceless && m_window_info.type != WindowInfo::Type::Libretro && if (m_window_info.type != WindowInfo::Type::Surfaceless && m_window_info.type != WindowInfo::Type::Libretro &&
!CreateSwapChain()) !CreateSwapChain())
{ {
return false; return false;
} }
#endif
if (!CreateResources()) if (!CreateResources())
return false; return false;
#ifndef LIBRETRO
if (ImGui::GetCurrentContext() && !CreateImGuiContext()) if (ImGui::GetCurrentContext() && !CreateImGuiContext())
return false; return false;
#endif
return true; return true;
} }
void D3D11HostDisplay::DestroyRenderDevice() void D3D11HostDisplay::DestroyRenderDevice()
{ {
#ifndef LIBRETRO
if (ImGui::GetCurrentContext()) if (ImGui::GetCurrentContext())
DestroyImGuiContext(); DestroyImGuiContext();
#endif
DestroyResources(); DestroyResources();
DestroyRenderSurface(); DestroyRenderSurface();
@ -315,12 +329,14 @@ bool D3D11HostDisplay::DoneRenderContextCurrent()
return true; return true;
} }
#ifndef LIBRETRO
bool D3D11HostDisplay::CreateSwapChain() bool D3D11HostDisplay::CreateSwapChain()
{ {
if (m_window_info.type != WindowInfo::Type::Win32) if (m_window_info.type != WindowInfo::Type::Win32)
return false; return false;
m_using_flip_model_swap_chain = UseFlipModelSwapChain(); m_using_flip_model_swap_chain = true;
const HWND window_hwnd = reinterpret_cast<HWND>(m_window_info.window_handle); const HWND window_hwnd = reinterpret_cast<HWND>(m_window_info.window_handle);
RECT client_rc{}; RECT client_rc{};
@ -405,22 +421,32 @@ bool D3D11HostDisplay::CreateSwapChainRTV()
return true; return true;
} }
#endif
bool D3D11HostDisplay::ChangeRenderWindow(const WindowInfo& new_wi) bool D3D11HostDisplay::ChangeRenderWindow(const WindowInfo& new_wi)
{ {
#ifndef LIBRETRO
DestroyRenderSurface(); DestroyRenderSurface();
m_window_info = new_wi; m_window_info = new_wi;
return CreateSwapChain(); return CreateSwapChain();
#else
m_window_info = new_wi;
return true;
#endif
} }
void D3D11HostDisplay::DestroyRenderSurface() void D3D11HostDisplay::DestroyRenderSurface()
{ {
#ifndef LIBRETRO
m_swap_chain_rtv.Reset(); m_swap_chain_rtv.Reset();
m_swap_chain.Reset(); m_swap_chain.Reset();
#endif
} }
void D3D11HostDisplay::ResizeRenderWindow(s32 new_window_width, s32 new_window_height) void D3D11HostDisplay::ResizeRenderWindow(s32 new_window_width, s32 new_window_height)
{ {
#ifndef LIBRETRO
if (!m_swap_chain) if (!m_swap_chain)
return; return;
@ -433,6 +459,7 @@ void D3D11HostDisplay::ResizeRenderWindow(s32 new_window_width, s32 new_window_h
if (!CreateSwapChainRTV()) if (!CreateSwapChainRTV())
Panic("Failed to recreate swap chain RTV after resize"); Panic("Failed to recreate swap chain RTV after resize");
#endif
} }
bool D3D11HostDisplay::CreateResources() bool D3D11HostDisplay::CreateResources()
@ -496,7 +523,6 @@ bool D3D11HostDisplay::CreateResources()
void D3D11HostDisplay::DestroyResources() void D3D11HostDisplay::DestroyResources()
{ {
m_display_uniform_buffer.Release(); m_display_uniform_buffer.Release();
m_swap_chain_rtv.Reset();
m_linear_sampler.Reset(); m_linear_sampler.Reset();
m_point_sampler.Reset(); m_point_sampler.Reset();
m_display_pixel_shader.Reset(); m_display_pixel_shader.Reset();
@ -506,6 +532,7 @@ void D3D11HostDisplay::DestroyResources()
m_display_rasterizer_state.Reset(); m_display_rasterizer_state.Reset();
} }
#ifndef LIBRETRO
bool D3D11HostDisplay::CreateImGuiContext() bool D3D11HostDisplay::CreateImGuiContext()
{ {
ImGui::GetIO().DisplaySize.x = static_cast<float>(m_window_info.surface_width); ImGui::GetIO().DisplaySize.x = static_cast<float>(m_window_info.surface_width);
@ -522,9 +549,11 @@ void D3D11HostDisplay::DestroyImGuiContext()
{ {
ImGui_ImplDX11_Shutdown(); ImGui_ImplDX11_Shutdown();
} }
#endif
bool D3D11HostDisplay::Render() bool D3D11HostDisplay::Render()
{ {
#ifndef LIBRETRO
static constexpr std::array<float, 4> clear_color = {}; static constexpr std::array<float, 4> clear_color = {};
m_context->ClearRenderTargetView(m_swap_chain_rtv.Get(), clear_color.data()); m_context->ClearRenderTargetView(m_swap_chain_rtv.Get(), clear_color.data());
m_context->OMSetRenderTargets(1, m_swap_chain_rtv.GetAddressOf(), nullptr); m_context->OMSetRenderTargets(1, m_swap_chain_rtv.GetAddressOf(), nullptr);
@ -543,16 +572,24 @@ bool D3D11HostDisplay::Render()
if (ImGui::GetCurrentContext()) if (ImGui::GetCurrentContext())
ImGui_ImplDX11_NewFrame(); ImGui_ImplDX11_NewFrame();
#else
RenderDisplay();
RenderSoftwareCursor();
#endif
return true; return true;
} }
#ifndef LIBRETRO
void D3D11HostDisplay::RenderImGui() void D3D11HostDisplay::RenderImGui()
{ {
ImGui::Render(); ImGui::Render();
ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData());
} }
#endif
void D3D11HostDisplay::RenderDisplay() void D3D11HostDisplay::RenderDisplay()
{ {
if (!HasDisplayTexture()) if (!HasDisplayTexture())
@ -627,6 +664,8 @@ void D3D11HostDisplay::RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 he
m_context->Draw(3, 0); m_context->Draw(3, 0);
} }
#ifndef LIBRETRO
std::vector<std::string> D3D11HostDisplay::EnumerateAdapterNames() std::vector<std::string> D3D11HostDisplay::EnumerateAdapterNames()
{ {
ComPtr<IDXGIFactory> dxgi_factory; ComPtr<IDXGIFactory> dxgi_factory;
@ -683,9 +722,6 @@ std::vector<std::string> D3D11HostDisplay::EnumerateAdapterNames(IDXGIFactory* d
return adapter_names; return adapter_names;
} }
bool D3D11HostDisplay::UseFlipModelSwapChain() const #endif
{
return true;
}
} // namespace FrontendCommon } // namespace FrontendCommon

View File

@ -53,39 +53,46 @@ public:
virtual bool Render() override; virtual bool Render() override;
#ifndef LIBRETRO
static std::vector<std::string> EnumerateAdapterNames(); static std::vector<std::string> EnumerateAdapterNames();
#endif
protected: protected:
static constexpr u32 DISPLAY_UNIFORM_BUFFER_SIZE = 16; static constexpr u32 DISPLAY_UNIFORM_BUFFER_SIZE = 16;
virtual bool UseFlipModelSwapChain() const;
static std::vector<std::string> EnumerateAdapterNames(IDXGIFactory* dxgi_factory); static std::vector<std::string> EnumerateAdapterNames(IDXGIFactory* dxgi_factory);
virtual bool CreateResources(); virtual bool CreateResources();
virtual void DestroyResources(); virtual void DestroyResources();
#ifndef LIBRETRO
virtual bool CreateImGuiContext(); virtual bool CreateImGuiContext();
virtual void DestroyImGuiContext(); virtual void DestroyImGuiContext();
bool CreateSwapChain(); bool CreateSwapChain();
bool CreateSwapChainRTV(); bool CreateSwapChainRTV();
#endif
void RenderDisplay(); void RenderDisplay();
void RenderImGui();
void RenderSoftwareCursor(); void RenderSoftwareCursor();
#ifndef LIBRETRO
void RenderImGui();
#endif
void RenderDisplay(s32 left, s32 top, s32 width, s32 height, void* texture_handle, u32 texture_width, void RenderDisplay(s32 left, s32 top, s32 width, s32 height, void* texture_handle, u32 texture_width,
s32 texture_height, s32 texture_view_x, s32 texture_view_y, s32 texture_view_width, s32 texture_height, s32 texture_view_x, s32 texture_view_y, s32 texture_view_width,
s32 texture_view_height, bool linear_filter); s32 texture_view_height, bool linear_filter);
void RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 height, HostDisplayTexture* texture_handle); void RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 height, HostDisplayTexture* texture_handle);
ComPtr<IDXGIFactory> m_dxgi_factory;
ComPtr<ID3D11Device> m_device; ComPtr<ID3D11Device> m_device;
ComPtr<ID3D11DeviceContext> m_context; ComPtr<ID3D11DeviceContext> m_context;
#ifndef LIBRETRO
ComPtr<IDXGIFactory> m_dxgi_factory;
ComPtr<IDXGISwapChain> m_swap_chain; ComPtr<IDXGISwapChain> m_swap_chain;
ComPtr<ID3D11RenderTargetView> m_swap_chain_rtv; ComPtr<ID3D11RenderTargetView> m_swap_chain_rtv;
#endif
ComPtr<ID3D11RasterizerState> m_display_rasterizer_state; ComPtr<ID3D11RasterizerState> m_display_rasterizer_state;
ComPtr<ID3D11DepthStencilState> m_display_depth_stencil_state; ComPtr<ID3D11DepthStencilState> m_display_depth_stencil_state;
@ -100,10 +107,12 @@ protected:
D3D11::StreamBuffer m_display_uniform_buffer; D3D11::StreamBuffer m_display_uniform_buffer;
D3D11::AutoStagingTexture m_readback_staging_texture; D3D11::AutoStagingTexture m_readback_staging_texture;
#ifdef LIBRETRO
bool m_allow_tearing_supported = false; bool m_allow_tearing_supported = false;
bool m_using_flip_model_swap_chain = true; bool m_using_flip_model_swap_chain = true;
bool m_using_allow_tearing = false; bool m_using_allow_tearing = false;
bool m_vsync = true; bool m_vsync = true;
#endif
}; };
} // namespace FrontendCommon } // namespace FrontendCommon