2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2009 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2010-06-09 01:37:08 +00:00
|
|
|
|
2017-01-23 16:20:20 +00:00
|
|
|
#include "VideoBackends/Software/SWRenderer.h"
|
|
|
|
|
2014-06-03 05:08:54 +00:00
|
|
|
#include <string>
|
2014-05-03 02:47:04 +00:00
|
|
|
|
2014-09-08 01:06:58 +00:00
|
|
|
#include "Common/CommonTypes.h"
|
2018-10-03 13:03:13 +00:00
|
|
|
#include "Common/GL/GLContext.h"
|
2015-09-18 16:40:00 +00:00
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
#include "Core/HW/Memmap.h"
|
2015-09-18 16:40:00 +00:00
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
#include "VideoBackends/Software/EfbCopy.h"
|
2017-11-19 05:16:22 +00:00
|
|
|
#include "VideoBackends/Software/EfbInterface.h"
|
2021-06-09 11:42:21 +00:00
|
|
|
#include "VideoBackends/Software/SWBoundingBox.h"
|
2015-09-26 08:07:48 +00:00
|
|
|
#include "VideoBackends/Software/SWOGLWindow.h"
|
2017-09-30 06:25:36 +00:00
|
|
|
#include "VideoBackends/Software/SWTexture.h"
|
2015-09-18 16:40:00 +00:00
|
|
|
|
2017-09-08 09:42:56 +00:00
|
|
|
#include "VideoCommon/AbstractPipeline.h"
|
|
|
|
#include "VideoCommon/AbstractShader.h"
|
2019-02-15 01:59:50 +00:00
|
|
|
#include "VideoCommon/AbstractTexture.h"
|
|
|
|
#include "VideoCommon/NativeVertexFormat.h"
|
2017-01-23 16:20:20 +00:00
|
|
|
#include "VideoCommon/VideoBackendBase.h"
|
2019-07-17 00:18:48 +00:00
|
|
|
#include "VideoCommon/VideoCommon.h"
|
2013-04-13 05:48:53 +00:00
|
|
|
|
2019-02-15 01:59:50 +00:00
|
|
|
namespace SW
|
|
|
|
{
|
2018-10-03 13:03:26 +00:00
|
|
|
SWRenderer::SWRenderer(std::unique_ptr<SWOGLWindow> window)
|
2021-05-23 02:58:27 +00:00
|
|
|
: ::Renderer(static_cast<int>(std::max(window->GetContext()->GetBackBufferWidth(), 1u)),
|
|
|
|
static_cast<int>(std::max(window->GetContext()->GetBackBufferHeight(), 1u)), 1.0f,
|
2017-09-09 06:09:24 +00:00
|
|
|
AbstractTextureFormat::RGBA8),
|
2018-10-03 13:03:26 +00:00
|
|
|
m_window(std::move(window))
|
2017-03-04 06:40:08 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2018-10-03 13:03:13 +00:00
|
|
|
bool SWRenderer::IsHeadless() const
|
|
|
|
{
|
2018-10-03 13:03:26 +00:00
|
|
|
return m_window->IsHeadless();
|
2018-10-03 13:03:13 +00:00
|
|
|
}
|
|
|
|
|
2021-08-28 05:30:05 +00:00
|
|
|
std::unique_ptr<AbstractTexture> SWRenderer::CreateTexture(const TextureConfig& config,
|
|
|
|
[[maybe_unused]] std::string_view name)
|
2017-09-30 06:25:36 +00:00
|
|
|
{
|
2019-02-15 01:59:50 +00:00
|
|
|
return std::make_unique<SWTexture>(config);
|
2017-09-30 06:25:36 +00:00
|
|
|
}
|
|
|
|
|
2017-10-21 14:49:40 +00:00
|
|
|
std::unique_ptr<AbstractStagingTexture>
|
|
|
|
SWRenderer::CreateStagingTexture(StagingTextureType type, const TextureConfig& config)
|
|
|
|
{
|
2019-02-15 01:59:50 +00:00
|
|
|
return std::make_unique<SWStagingTexture>(type, config);
|
2017-10-21 14:49:40 +00:00
|
|
|
}
|
|
|
|
|
2018-01-21 10:22:45 +00:00
|
|
|
std::unique_ptr<AbstractFramebuffer>
|
2019-02-15 01:59:50 +00:00
|
|
|
SWRenderer::CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment)
|
2018-01-21 10:22:45 +00:00
|
|
|
{
|
2019-02-15 01:59:50 +00:00
|
|
|
return SWFramebuffer::Create(static_cast<SWTexture*>(color_attachment),
|
|
|
|
static_cast<SWTexture*>(depth_attachment));
|
2018-01-21 10:22:45 +00:00
|
|
|
}
|
|
|
|
|
2021-05-23 02:58:27 +00:00
|
|
|
void SWRenderer::BindBackbuffer(const ClearColor& clear_color)
|
|
|
|
{
|
|
|
|
// Look for framebuffer resizes
|
|
|
|
if (!m_surface_resized.TestAndClear())
|
|
|
|
return;
|
|
|
|
|
|
|
|
GLContext* context = m_window->GetContext();
|
|
|
|
context->Update();
|
|
|
|
m_backbuffer_width = context->GetBackBufferWidth();
|
|
|
|
m_backbuffer_height = context->GetBackBufferHeight();
|
|
|
|
}
|
|
|
|
|
2017-09-08 09:42:56 +00:00
|
|
|
class SWShader final : public AbstractShader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
explicit SWShader(ShaderStage stage) : AbstractShader(stage) {}
|
|
|
|
~SWShader() = default;
|
|
|
|
|
|
|
|
BinaryData GetBinary() const override { return {}; }
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<AbstractShader>
|
2021-08-28 05:30:05 +00:00
|
|
|
SWRenderer::CreateShaderFromSource(ShaderStage stage, [[maybe_unused]] std::string_view source,
|
|
|
|
[[maybe_unused]] std::string_view name)
|
2017-09-08 09:42:56 +00:00
|
|
|
{
|
|
|
|
return std::make_unique<SWShader>(stage);
|
|
|
|
}
|
|
|
|
|
2021-08-28 05:30:05 +00:00
|
|
|
std::unique_ptr<AbstractShader>
|
|
|
|
SWRenderer::CreateShaderFromBinary(ShaderStage stage, const void* data, size_t length,
|
|
|
|
[[maybe_unused]] std::string_view name)
|
2017-09-08 09:42:56 +00:00
|
|
|
{
|
|
|
|
return std::make_unique<SWShader>(stage);
|
|
|
|
}
|
|
|
|
|
|
|
|
class SWPipeline final : public AbstractPipeline
|
|
|
|
{
|
|
|
|
public:
|
2019-03-02 18:42:25 +00:00
|
|
|
SWPipeline() = default;
|
2017-09-08 09:42:56 +00:00
|
|
|
~SWPipeline() override = default;
|
|
|
|
};
|
|
|
|
|
2019-04-15 11:55:26 +00:00
|
|
|
std::unique_ptr<AbstractPipeline> SWRenderer::CreatePipeline(const AbstractPipelineConfig& config,
|
|
|
|
const void* cache_data,
|
|
|
|
size_t cache_data_length)
|
2017-09-08 09:42:56 +00:00
|
|
|
{
|
|
|
|
return std::make_unique<SWPipeline>();
|
|
|
|
}
|
|
|
|
|
2013-08-20 11:51:39 +00:00
|
|
|
// Called on the GPU thread
|
2019-04-28 07:00:18 +00:00
|
|
|
void SWRenderer::RenderXFBToScreen(const MathUtil::Rectangle<int>& target_rc,
|
|
|
|
const AbstractTexture* source_texture,
|
|
|
|
const MathUtil::Rectangle<int>& source_rc)
|
2013-08-20 11:51:39 +00:00
|
|
|
{
|
2017-11-23 06:53:44 +00:00
|
|
|
if (!IsHeadless())
|
2019-04-28 07:00:18 +00:00
|
|
|
m_window->ShowImage(source_texture, source_rc);
|
2015-10-09 18:50:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
u32 SWRenderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
|
|
|
|
{
|
|
|
|
u32 value = 0;
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
switch (type)
|
|
|
|
{
|
2017-01-23 07:51:46 +00:00
|
|
|
case EFBAccessType::PeekZ:
|
2015-10-09 18:50:36 +00:00
|
|
|
{
|
|
|
|
value = EfbInterface::GetDepth(x, y);
|
|
|
|
break;
|
|
|
|
}
|
2017-01-23 07:51:46 +00:00
|
|
|
case EFBAccessType::PeekColor:
|
2015-10-09 18:50:36 +00:00
|
|
|
{
|
2016-09-21 22:53:13 +00:00
|
|
|
const u32 color = EfbInterface::GetColor(x, y);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
// rgba to argb
|
|
|
|
value = (color >> 8) | (color & 0xff) << 24;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2015-10-09 18:50:36 +00:00
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
2021-06-09 11:42:21 +00:00
|
|
|
std::unique_ptr<BoundingBox> SWRenderer::CreateBoundingBox() const
|
2015-10-09 18:50:36 +00:00
|
|
|
{
|
2021-06-09 11:42:21 +00:00
|
|
|
return std::make_unique<SWBoundingBox>();
|
2015-10-09 18:50:36 +00:00
|
|
|
}
|
|
|
|
|
2019-04-15 14:47:46 +00:00
|
|
|
void SWRenderer::ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable, bool alphaEnable,
|
2015-10-09 18:50:36 +00:00
|
|
|
bool zEnable, u32 color, u32 z)
|
|
|
|
{
|
|
|
|
EfbCopy::ClearEfb();
|
2009-10-12 00:48:24 +00:00
|
|
|
}
|
2019-02-15 01:59:50 +00:00
|
|
|
|
|
|
|
std::unique_ptr<NativeVertexFormat>
|
|
|
|
SWRenderer::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl)
|
|
|
|
{
|
|
|
|
return std::make_unique<NativeVertexFormat>(vtx_decl);
|
|
|
|
}
|
|
|
|
} // namespace SW
|