diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2f5ea71d3..b50b19f9d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,3 +1,7 @@ +if(BUILD_LIBRETRO_CORE) + add_definitions("-DLIBRETRO=1") +endif() + add_subdirectory(common) add_subdirectory(core) add_subdirectory(scmversion) diff --git a/src/core/namco_guncon.cpp b/src/core/namco_guncon.cpp index bd90dc434..e98268caa 100644 --- a/src/core/namco_guncon.cpp +++ b/src/core/namco_guncon.cpp @@ -1,5 +1,6 @@ #include "namco_guncon.h" #include "common/assert.h" +#include "common/log.h" #include "common/state_wrapper.h" #include "gpu.h" #include "host_display.h" @@ -7,6 +8,7 @@ #include "resources.h" #include "system.h" #include +Log_SetChannel(NamcoGunCon); NamcoGunCon::NamcoGunCon(System* system) : m_system(system) {} diff --git a/src/frontend-common/d3d11_host_display.cpp b/src/frontend-common/d3d11_host_display.cpp index e8ea92a51..62ba425cd 100644 --- a/src/frontend-common/d3d11_host_display.cpp +++ b/src/frontend-common/d3d11_host_display.cpp @@ -6,11 +6,11 @@ #include "display_ps.hlsl.h" #include "display_vs.hlsl.h" #include -#if defined(__has_include) && __has_include() +#ifndef LIBRETRO #include -#endif #include #include +#endif Log_SetChannel(D3D11HostDisplay); namespace FrontendCommon { @@ -72,7 +72,9 @@ D3D11HostDisplay::D3D11HostDisplay() = default; D3D11HostDisplay::~D3D11HostDisplay() { AssertMsg(!m_context, "Context should have been destroyed by now"); +#ifndef LIBRETRO AssertMsg(!m_swap_chain, "Swap chain should have been destroyed by now"); +#endif } HostDisplay::RenderAPI D3D11HostDisplay::GetRenderAPI() const @@ -97,7 +99,11 @@ bool D3D11HostDisplay::HasRenderDevice() const bool D3D11HostDisplay::HasRenderSurface() const { +#ifndef LIBRETRO return static_cast(m_swap_chain); +#else + return true; +#endif } std::unique_ptr 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) { +#ifndef LIBRETRO m_vsync = enabled; +#endif } bool D3D11HostDisplay::CreateRenderDevice(const WindowInfo& wi, std::string_view adapter_name, bool debug_device) { +#ifndef LIBRETRO UINT create_flags = 0; if (debug_device) create_flags |= D3D11_CREATE_DEVICE_DEBUG; @@ -260,7 +269,6 @@ bool D3D11HostDisplay::CreateRenderDevice(const WindowInfo& wi, std::string_view } m_allow_tearing_supported = false; -#if defined(__has_include) && __has_include() ComPtr dxgi_factory5; hr = m_dxgi_factory.As(&dxgi_factory5); 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) { +#ifndef LIBRETRO if (m_window_info.type != WindowInfo::Type::Surfaceless && m_window_info.type != WindowInfo::Type::Libretro && !CreateSwapChain()) { return false; } +#endif if (!CreateResources()) return false; +#ifndef LIBRETRO if (ImGui::GetCurrentContext() && !CreateImGuiContext()) return false; +#endif return true; } void D3D11HostDisplay::DestroyRenderDevice() { +#ifndef LIBRETRO if (ImGui::GetCurrentContext()) DestroyImGuiContext(); +#endif DestroyResources(); DestroyRenderSurface(); @@ -315,12 +329,14 @@ bool D3D11HostDisplay::DoneRenderContextCurrent() return true; } +#ifndef LIBRETRO + bool D3D11HostDisplay::CreateSwapChain() { if (m_window_info.type != WindowInfo::Type::Win32) return false; - m_using_flip_model_swap_chain = UseFlipModelSwapChain(); + m_using_flip_model_swap_chain = true; const HWND window_hwnd = reinterpret_cast(m_window_info.window_handle); RECT client_rc{}; @@ -405,22 +421,32 @@ bool D3D11HostDisplay::CreateSwapChainRTV() return true; } +#endif + bool D3D11HostDisplay::ChangeRenderWindow(const WindowInfo& new_wi) { +#ifndef LIBRETRO DestroyRenderSurface(); m_window_info = new_wi; return CreateSwapChain(); +#else + m_window_info = new_wi; + return true; +#endif } void D3D11HostDisplay::DestroyRenderSurface() { +#ifndef LIBRETRO m_swap_chain_rtv.Reset(); m_swap_chain.Reset(); +#endif } void D3D11HostDisplay::ResizeRenderWindow(s32 new_window_width, s32 new_window_height) { +#ifndef LIBRETRO if (!m_swap_chain) return; @@ -433,6 +459,7 @@ void D3D11HostDisplay::ResizeRenderWindow(s32 new_window_width, s32 new_window_h if (!CreateSwapChainRTV()) Panic("Failed to recreate swap chain RTV after resize"); +#endif } bool D3D11HostDisplay::CreateResources() @@ -496,7 +523,6 @@ bool D3D11HostDisplay::CreateResources() void D3D11HostDisplay::DestroyResources() { m_display_uniform_buffer.Release(); - m_swap_chain_rtv.Reset(); m_linear_sampler.Reset(); m_point_sampler.Reset(); m_display_pixel_shader.Reset(); @@ -506,6 +532,7 @@ void D3D11HostDisplay::DestroyResources() m_display_rasterizer_state.Reset(); } +#ifndef LIBRETRO bool D3D11HostDisplay::CreateImGuiContext() { ImGui::GetIO().DisplaySize.x = static_cast(m_window_info.surface_width); @@ -522,9 +549,11 @@ void D3D11HostDisplay::DestroyImGuiContext() { ImGui_ImplDX11_Shutdown(); } +#endif bool D3D11HostDisplay::Render() { +#ifndef LIBRETRO static constexpr std::array clear_color = {}; m_context->ClearRenderTargetView(m_swap_chain_rtv.Get(), clear_color.data()); m_context->OMSetRenderTargets(1, m_swap_chain_rtv.GetAddressOf(), nullptr); @@ -543,16 +572,24 @@ bool D3D11HostDisplay::Render() if (ImGui::GetCurrentContext()) ImGui_ImplDX11_NewFrame(); +#else + RenderDisplay(); + RenderSoftwareCursor(); +#endif return true; } +#ifndef LIBRETRO + void D3D11HostDisplay::RenderImGui() { ImGui::Render(); ImGui_ImplDX11_RenderDrawData(ImGui::GetDrawData()); } +#endif + void D3D11HostDisplay::RenderDisplay() { if (!HasDisplayTexture()) @@ -627,6 +664,8 @@ void D3D11HostDisplay::RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 he m_context->Draw(3, 0); } +#ifndef LIBRETRO + std::vector D3D11HostDisplay::EnumerateAdapterNames() { ComPtr dxgi_factory; @@ -683,9 +722,6 @@ std::vector D3D11HostDisplay::EnumerateAdapterNames(IDXGIFactory* d return adapter_names; } -bool D3D11HostDisplay::UseFlipModelSwapChain() const -{ - return true; -} +#endif } // namespace FrontendCommon diff --git a/src/frontend-common/d3d11_host_display.h b/src/frontend-common/d3d11_host_display.h index b882b8dac..4ce4bba34 100644 --- a/src/frontend-common/d3d11_host_display.h +++ b/src/frontend-common/d3d11_host_display.h @@ -53,39 +53,46 @@ public: virtual bool Render() override; +#ifndef LIBRETRO static std::vector EnumerateAdapterNames(); +#endif protected: static constexpr u32 DISPLAY_UNIFORM_BUFFER_SIZE = 16; - virtual bool UseFlipModelSwapChain() const; - static std::vector EnumerateAdapterNames(IDXGIFactory* dxgi_factory); virtual bool CreateResources(); virtual void DestroyResources(); +#ifndef LIBRETRO virtual bool CreateImGuiContext(); virtual void DestroyImGuiContext(); bool CreateSwapChain(); bool CreateSwapChainRTV(); +#endif void RenderDisplay(); - void RenderImGui(); void RenderSoftwareCursor(); +#ifndef LIBRETRO + void RenderImGui(); +#endif + 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_view_height, bool linear_filter); void RenderSoftwareCursor(s32 left, s32 top, s32 width, s32 height, HostDisplayTexture* texture_handle); - ComPtr m_dxgi_factory; - ComPtr m_device; ComPtr m_context; + +#ifndef LIBRETRO + ComPtr m_dxgi_factory; ComPtr m_swap_chain; ComPtr m_swap_chain_rtv; +#endif ComPtr m_display_rasterizer_state; ComPtr m_display_depth_stencil_state; @@ -100,10 +107,12 @@ protected: D3D11::StreamBuffer m_display_uniform_buffer; D3D11::AutoStagingTexture m_readback_staging_texture; +#ifdef LIBRETRO bool m_allow_tearing_supported = false; bool m_using_flip_model_swap_chain = true; bool m_using_allow_tearing = false; bool m_vsync = true; +#endif }; } // namespace FrontendCommon