diff options
| author | Scott Mansell <phiren@gmail.com> | 2023-01-27 15:07:05 +1300 |
|---|---|---|
| committer | Scott Mansell <phiren@gmail.com> | 2023-01-31 19:41:23 +1300 |
| commit | d37f83ffeba218c6ef94b78532aed50b1ebbc4a4 (patch) | |
| tree | 0958778e5ee1693c70a9d66d02f6674e91202fb8 /Source/Core/VideoBackends/Software | |
| parent | f0336a3129ea431862e6e3bf1ccf51a384cf3f57 (diff) | |
Implement AbstractGfx for Software & Null
Diffstat (limited to 'Source/Core/VideoBackends/Software')
| -rw-r--r-- | Source/Core/VideoBackends/Software/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/Software/SWGfx.cpp | 127 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/Software/SWGfx.h | 55 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/Software/SWRenderer.cpp | 125 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/Software/SWRenderer.h | 45 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/Software/SWTexture.cpp | 10 | ||||
| -rw-r--r-- | Source/Core/VideoBackends/Software/SWmain.cpp | 23 |
7 files changed, 196 insertions, 191 deletions
diff --git a/Source/Core/VideoBackends/Software/CMakeLists.txt b/Source/Core/VideoBackends/Software/CMakeLists.txt index f71421cb57..7fc904bbf2 100644 --- a/Source/Core/VideoBackends/Software/CMakeLists.txt +++ b/Source/Core/VideoBackends/Software/CMakeLists.txt @@ -14,6 +14,8 @@ add_library(videosoftware SWmain.cpp SWBoundingBox.cpp SWBoundingBox.h + SWGfx.cpp + SWGfx.h SWOGLWindow.cpp SWOGLWindow.h SWRenderer.cpp diff --git a/Source/Core/VideoBackends/Software/SWGfx.cpp b/Source/Core/VideoBackends/Software/SWGfx.cpp new file mode 100644 index 0000000000..b53b7ae89a --- /dev/null +++ b/Source/Core/VideoBackends/Software/SWGfx.cpp @@ -0,0 +1,127 @@ +// Copyright 2023 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#include "VideoBackends/Software/SWGfx.h" + +#include "Common/GL/GLContext.h" + +#include "VideoBackends/Software/EfbCopy.h" +#include "VideoBackends/Software/Rasterizer.h" +#include "VideoBackends/Software/SWOGLWindow.h" +#include "VideoBackends/Software/SWTexture.h" + +#include "VideoCommon/AbstractPipeline.h" +#include "VideoCommon/AbstractShader.h" +#include "VideoCommon/AbstractTexture.h" +#include "VideoCommon/NativeVertexFormat.h" +#include "VideoCommon/Present.h" + +namespace SW +{ +SWGfx::SWGfx(std::unique_ptr<SWOGLWindow> window) : m_window(std::move(window)) +{ +} + +bool SWGfx::IsHeadless() const +{ + return m_window->IsHeadless(); +} + +std::unique_ptr<AbstractTexture> SWGfx::CreateTexture(const TextureConfig& config, + [[maybe_unused]] std::string_view name) +{ + return std::make_unique<SWTexture>(config); +} + +std::unique_ptr<AbstractStagingTexture> SWGfx::CreateStagingTexture(StagingTextureType type, + const TextureConfig& config) +{ + return std::make_unique<SWStagingTexture>(type, config); +} + +std::unique_ptr<AbstractFramebuffer> SWGfx::CreateFramebuffer(AbstractTexture* color_attachment, + AbstractTexture* depth_attachment) +{ + return SWFramebuffer::Create(static_cast<SWTexture*>(color_attachment), + static_cast<SWTexture*>(depth_attachment)); +} + +void SWGfx::BindBackbuffer(const ClearColor& clear_color) +{ + // Look for framebuffer resizes + if (!g_presenter->SurfaceResizedTestAndClear()) + return; + + GLContext* context = m_window->GetContext(); + context->Update(); + g_presenter->SetBackbuffer(context->GetBackBufferWidth(), context->GetBackBufferHeight()); +} + +class SWShader final : public AbstractShader +{ +public: + explicit SWShader(ShaderStage stage) : AbstractShader(stage) {} + ~SWShader() = default; + + BinaryData GetBinary() const override { return {}; } +}; + +std::unique_ptr<AbstractShader> +SWGfx::CreateShaderFromSource(ShaderStage stage, [[maybe_unused]] std::string_view source, + [[maybe_unused]] std::string_view name) +{ + return std::make_unique<SWShader>(stage); +} + +std::unique_ptr<AbstractShader> +SWGfx::CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length, + [[maybe_unused]] std::string_view name) +{ + return std::make_unique<SWShader>(stage); +} + +class SWPipeline final : public AbstractPipeline +{ +public: + SWPipeline() = default; + ~SWPipeline() override = default; +}; + +std::unique_ptr<AbstractPipeline> SWGfx::CreatePipeline(const AbstractPipelineConfig& config, + const void* cache_data, + size_t cache_data_length) +{ + return std::make_unique<SWPipeline>(); +} + +// Called on the GPU thread +void SWGfx::ShowImage(const AbstractTexture* source_texture, + const MathUtil::Rectangle<int>& source_rc) +{ + if (!IsHeadless()) + m_window->ShowImage(source_texture, source_rc); +} + +void SWGfx::ClearRegion(const MathUtil::Rectangle<int>& rc, + const MathUtil::Rectangle<int>& target_rc, bool colorEnable, + bool alphaEnable, bool zEnable, u32 color, u32 z) +{ + EfbCopy::ClearEfb(); +} + +std::unique_ptr<NativeVertexFormat> +SWGfx::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) +{ + return std::make_unique<NativeVertexFormat>(vtx_decl); +} + +void SWGfx::SetScissorRect(const MathUtil::Rectangle<int>& rc) +{ + // BPFunctions calls SetScissorRect with the "best" scissor rect whenever the viewport or scissor + // changes. However, the software renderer is actually able to use multiple scissor rects (which + // is necessary in a few renderering edge cases, such as with Major Minor's Majestic March). + // Thus, we use this as a signal to update the list of scissor rects, but ignore the parameter. + Rasterizer::ScissorChanged(); +} + +} // namespace SW
\ No newline at end of file diff --git a/Source/Core/VideoBackends/Software/SWGfx.h b/Source/Core/VideoBackends/Software/SWGfx.h new file mode 100644 index 0000000000..48015fda25 --- /dev/null +++ b/Source/Core/VideoBackends/Software/SWGfx.h @@ -0,0 +1,55 @@ +// Copyright 2023 Dolphin Emulator Project +// SPDX-License-Identifier: GPL-2.0-or-later + +#pragma once + +#include "VideoCommon/AbstractGfx.h" + +class SWOGLWindow; + +namespace SW +{ +class SWGfx final : public AbstractGfx +{ +public: + SWGfx(std::unique_ptr<SWOGLWindow> window); + + bool IsHeadless() const override; + + std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config, + std::string_view name) override; + std::unique_ptr<AbstractStagingTexture> + CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override; + std::unique_ptr<AbstractFramebuffer> + CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment) override; + + void BindBackbuffer(const ClearColor& clear_color = {}) override; + + std::unique_ptr<AbstractShader> CreateShaderFromSource(ShaderStage stage, std::string_view source, + std::string_view name) override; + std::unique_ptr<AbstractShader> CreateShaderFromBinary(ShaderStage stage, const void* data, + size_t length, + std::string_view name) override; + std::unique_ptr<NativeVertexFormat> + CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override; + std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config, + const void* cache_data = nullptr, + size_t cache_data_length = 0) override; + + void ShowImage(const AbstractTexture* source_texture, + const MathUtil::Rectangle<int>& source_rc) override; + + void ScaleTexture(AbstractFramebuffer* dst_framebuffer, const MathUtil::Rectangle<int>& dst_rect, + const AbstractTexture* src_texture, + const MathUtil::Rectangle<int>& src_rect) override; + + void SetScissorRect(const MathUtil::Rectangle<int>& rc) override; + + void ClearRegion(const MathUtil::Rectangle<int>& rc, const MathUtil::Rectangle<int>& target_rc, + bool colorEnable, bool alphaEnable, bool zEnable, u32 color, u32 z) override; + +private: + std::unique_ptr<SWOGLWindow> m_window; +}; + +} // namespace SW diff --git a/Source/Core/VideoBackends/Software/SWRenderer.cpp b/Source/Core/VideoBackends/Software/SWRenderer.cpp index 887bce177f..7440fba1b3 100644 --- a/Source/Core/VideoBackends/Software/SWRenderer.cpp +++ b/Source/Core/VideoBackends/Software/SWRenderer.cpp @@ -6,117 +6,17 @@ #include <string> #include "Common/CommonTypes.h" -#include "Common/GL/GLContext.h" #include "Core/HW/Memmap.h" #include "Core/System.h" -#include "VideoBackends/Software/EfbCopy.h" #include "VideoBackends/Software/EfbInterface.h" -#include "VideoBackends/Software/Rasterizer.h" -#include "VideoBackends/Software/SWBoundingBox.h" -#include "VideoBackends/Software/SWOGLWindow.h" -#include "VideoBackends/Software/SWTexture.h" -#include "VideoCommon/AbstractPipeline.h" -#include "VideoCommon/AbstractShader.h" -#include "VideoCommon/AbstractTexture.h" -#include "VideoCommon/NativeVertexFormat.h" #include "VideoCommon/PixelEngine.h" -#include "VideoCommon/Present.h" #include "VideoCommon/VideoBackendBase.h" -#include "VideoCommon/VideoCommon.h" namespace SW { -SWRenderer::SWRenderer(std::unique_ptr<SWOGLWindow> window) - : ::Renderer(static_cast<int>(std::max(window->GetContext()->GetBackBufferWidth(), 1u)), - static_cast<int>(std::max(window->GetContext()->GetBackBufferHeight(), 1u)), 1.0f, - AbstractTextureFormat::RGBA8), - m_window(std::move(window)) -{ -} - -bool SWRenderer::IsHeadless() const -{ - return m_window->IsHeadless(); -} - -std::unique_ptr<AbstractTexture> SWRenderer::CreateTexture(const TextureConfig& config, - [[maybe_unused]] std::string_view name) -{ - return std::make_unique<SWTexture>(config); -} - -std::unique_ptr<AbstractStagingTexture> -SWRenderer::CreateStagingTexture(StagingTextureType type, const TextureConfig& config) -{ - return std::make_unique<SWStagingTexture>(type, config); -} - -std::unique_ptr<AbstractFramebuffer> -SWRenderer::CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment) -{ - return SWFramebuffer::Create(static_cast<SWTexture*>(color_attachment), - static_cast<SWTexture*>(depth_attachment)); -} - -void SWRenderer::BindBackbuffer(const ClearColor& clear_color) -{ - // Look for framebuffer resizes - if (!g_presenter->SurfaceResizedTestAndClear()) - return; - - GLContext* context = m_window->GetContext(); - context->Update(); - g_presenter->SetBackbuffer(context->GetBackBufferWidth(), context->GetBackBufferHeight()); -} - -class SWShader final : public AbstractShader -{ -public: - explicit SWShader(ShaderStage stage) : AbstractShader(stage) {} - ~SWShader() = default; - - BinaryData GetBinary() const override { return {}; } -}; - -std::unique_ptr<AbstractShader> -SWRenderer::CreateShaderFromSource(ShaderStage stage, [[maybe_unused]] std::string_view source, - [[maybe_unused]] std::string_view name) -{ - return std::make_unique<SWShader>(stage); -} - -std::unique_ptr<AbstractShader> -SWRenderer::CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length, - [[maybe_unused]] std::string_view name) -{ - return std::make_unique<SWShader>(stage); -} - -class SWPipeline final : public AbstractPipeline -{ -public: - SWPipeline() = default; - ~SWPipeline() override = default; -}; - -std::unique_ptr<AbstractPipeline> SWRenderer::CreatePipeline(const AbstractPipelineConfig& config, - const void* cache_data, - size_t cache_data_length) -{ - return std::make_unique<SWPipeline>(); -} - -// Called on the GPU thread -void SWRenderer::ShowImage(const AbstractTexture* source_texture, - const MathUtil::Rectangle<int>& source_rc) -{ - if (!IsHeadless()) - m_window->ShowImage(source_texture, source_rc); -} - u32 SWRenderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData) { u32 value = 0; @@ -165,29 +65,4 @@ u32 SWRenderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData) return value; } -std::unique_ptr<BoundingBox> SWRenderer::CreateBoundingBox() const -{ - return std::make_unique<SWBoundingBox>(); -} - -void SWRenderer::ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable, bool alphaEnable, - bool zEnable, u32 color, u32 z) -{ - EfbCopy::ClearEfb(); -} - -std::unique_ptr<NativeVertexFormat> -SWRenderer::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) -{ - return std::make_unique<NativeVertexFormat>(vtx_decl); -} - -void SWRenderer::SetScissorRect(const MathUtil::Rectangle<int>& rc) -{ - // BPFunctions calls SetScissorRect with the "best" scissor rect whenever the viewport or scissor - // changes. However, the software renderer is actually able to use multiple scissor rects (which - // is necessary in a few renderering edge cases, such as with Major Minor's Majestic March). - // Thus, we use this as a signal to update the list of scissor rects, but ignore the parameter. - Rasterizer::ScissorChanged(); -} } // namespace SW diff --git a/Source/Core/VideoBackends/Software/SWRenderer.h b/Source/Core/VideoBackends/Software/SWRenderer.h index 7444834a18..e34a016e15 100644 --- a/Source/Core/VideoBackends/Software/SWRenderer.h +++ b/Source/Core/VideoBackends/Software/SWRenderer.h @@ -10,59 +10,14 @@ #include "VideoCommon/RenderBase.h" -class BoundingBox; -class SWOGLWindow; - namespace SW { class SWRenderer final : public Renderer { public: - SWRenderer(std::unique_ptr<SWOGLWindow> window); - - bool IsHeadless() const override; - - std::unique_ptr<AbstractTexture> CreateTexture(const TextureConfig& config, - std::string_view name) override; - std::unique_ptr<AbstractStagingTexture> - CreateStagingTexture(StagingTextureType type, const TextureConfig& config) override; - std::unique_ptr<AbstractFramebuffer> - CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment) override; - - void BindBackbuffer(const ClearColor& clear_color = {}) override; - - std::unique_ptr<AbstractShader> CreateShaderFromSource(ShaderStage stage, std::string_view source, - std::string_view name) override; - std::unique_ptr<AbstractShader> CreateShaderFromBinary(ShaderStage stage, const void* data, - size_t length, - std::string_view name) override; - std::unique_ptr<NativeVertexFormat> - CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) override; - std::unique_ptr<AbstractPipeline> CreatePipeline(const AbstractPipelineConfig& config, - const void* cache_data = nullptr, - size_t cache_data_length = 0) override; - u32 AccessEFB(EFBAccessType type, u32 x, u32 y, u32 poke_data) override; void PokeEFB(EFBAccessType type, const EfbPokeData* points, size_t num_points) override {} - void ShowImage(const AbstractTexture* source_texture, - const MathUtil::Rectangle<int>& source_rc) override; - - void ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable, bool alphaEnable, - bool zEnable, u32 color, u32 z) override; - void ReinterpretPixelData(EFBReinterpretType convtype) override {} - - void ScaleTexture(AbstractFramebuffer* dst_framebuffer, const MathUtil::Rectangle<int>& dst_rect, - const AbstractTexture* src_texture, - const MathUtil::Rectangle<int>& src_rect) override; - - void SetScissorRect(const MathUtil::Rectangle<int>& rc) override; - -protected: - std::unique_ptr<BoundingBox> CreateBoundingBox() const override; - -private: - std::unique_ptr<SWOGLWindow> m_window; }; } // namespace SW diff --git a/Source/Core/VideoBackends/Software/SWTexture.cpp b/Source/Core/VideoBackends/Software/SWTexture.cpp index 6805ff0eb8..2e925c4686 100644 --- a/Source/Core/VideoBackends/Software/SWTexture.cpp +++ b/Source/Core/VideoBackends/Software/SWTexture.cpp @@ -8,7 +8,7 @@ #include "Common/Assert.h" #include "VideoBackends/Software/CopyRegion.h" -#include "VideoBackends/Software/SWRenderer.h" +#include "VideoBackends/Software/SWGfx.h" namespace SW { @@ -48,10 +48,10 @@ void CopyTextureData(const TextureConfig& src_config, const u8* src_ptr, u32 src } } // namespace -void SWRenderer::ScaleTexture(AbstractFramebuffer* dst_framebuffer, - const MathUtil::Rectangle<int>& dst_rect, - const AbstractTexture* src_texture, - const MathUtil::Rectangle<int>& src_rect) +void SWGfx::ScaleTexture(AbstractFramebuffer* dst_framebuffer, + const MathUtil::Rectangle<int>& dst_rect, + const AbstractTexture* src_texture, + const MathUtil::Rectangle<int>& src_rect) { const SWTexture* software_source_texture = static_cast<const SWTexture*>(src_texture); SWTexture* software_dest_texture = static_cast<SWTexture*>(dst_framebuffer->GetColorAttachment()); diff --git a/Source/Core/VideoBackends/Software/SWmain.cpp b/Source/Core/VideoBackends/Software/SWmain.cpp index b749f447bb..46101afe77 100644 --- a/Source/Core/VideoBackends/Software/SWmain.cpp +++ b/Source/Core/VideoBackends/Software/SWmain.cpp @@ -16,6 +16,8 @@ #include "VideoBackends/Software/Clipper.h" #include "VideoBackends/Software/EfbInterface.h" #include "VideoBackends/Software/Rasterizer.h" +#include "VideoBackends/Software/SWBoundingBox.h" +#include "VideoBackends/Software/SWGfx.h" #include "VideoBackends/Software/SWOGLWindow.h" #include "VideoBackends/Software/SWRenderer.h" #include "VideoBackends/Software/SWTexture.h" @@ -23,6 +25,7 @@ #include "VideoBackends/Software/TextureCache.h" #include "VideoCommon/FramebufferManager.h" +#include "VideoCommon/Present.h" #include "VideoCommon/TextureCacheBase.h" #include "VideoCommon/VideoCommon.h" #include "VideoCommon/VideoConfig.h" @@ -96,8 +99,6 @@ void VideoSoftware::InitBackendInfo() bool VideoSoftware::Initialize(const WindowSystemInfo& wsi) { - InitializeShared(); - std::unique_ptr<SWOGLWindow> window = SWOGLWindow::Create(wsi); if (!window) return false; @@ -105,23 +106,13 @@ bool VideoSoftware::Initialize(const WindowSystemInfo& wsi) Clipper::Init(); Rasterizer::Init(); - g_renderer = std::make_unique<SWRenderer>(std::move(window)); + g_gfx = std::make_unique<SWGfx>(std::move(window)); + g_bounding_box = std::make_unique<SWBoundingBox>(); g_vertex_manager = std::make_unique<SWVertexLoader>(); - g_shader_cache = std::make_unique<VideoCommon::ShaderCache>(); - g_framebuffer_manager = std::make_unique<FramebufferManager>(); g_perf_query = std::make_unique<PerfQuery>(); - g_texture_cache = std::make_unique<TextureCache>(); - - if (!g_vertex_manager->Initialize() || !g_shader_cache->Initialize() || - !g_renderer->Initialize() || !g_framebuffer_manager->Initialize() || - !g_texture_cache->Initialize()) - { - PanicAlertFmt("Failed to initialize renderer classes"); - Shutdown(); - return false; - } - g_shader_cache->InitializeShaderCache(); + InitializeShared(); + return true; } |
