| 
									
										
										
										
											2015-05-24 06:55:12 +02:00
										 |  |  | // Copyright 2009 Dolphin Emulator Project
 | 
					
						
							| 
									
										
										
										
											2015-05-18 01:08:10 +02:00
										 |  |  | // Licensed under GPLv2+
 | 
					
						
							| 
									
										
										
										
											2013-04-17 23:29:41 -04:00
										 |  |  | // Refer to the license.txt file included.
 | 
					
						
							| 
									
										
										
										
											2010-06-09 01:37:08 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-01-23 11:20:20 -05:00
										 |  |  | #include "VideoBackends/Software/SWRenderer.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-06-03 01:08:54 -04:00
										 |  |  | #include <string>
 | 
					
						
							| 
									
										
										
										
											2014-05-02 22:47:04 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-09-07 20:06:58 -05:00
										 |  |  | #include "Common/CommonTypes.h"
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:03:13 +10:00
										 |  |  | #include "Common/GL/GLContext.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-19 04:40:00 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-18 13:59:38 +01:00
										 |  |  | #include "Core/Config/GraphicsSettings.h"
 | 
					
						
							| 
									
										
										
										
											2015-10-09 20:50:36 +02:00
										 |  |  | #include "Core/HW/Memmap.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-19 04:40:00 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-09 20:50:36 +02:00
										 |  |  | #include "VideoBackends/Software/EfbCopy.h"
 | 
					
						
							| 
									
										
										
										
											2017-11-19 00:16:22 -05:00
										 |  |  | #include "VideoBackends/Software/EfbInterface.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-26 10:07:48 +02:00
										 |  |  | #include "VideoBackends/Software/SWOGLWindow.h"
 | 
					
						
							| 
									
										
										
										
											2017-09-30 16:25:36 +10:00
										 |  |  | #include "VideoBackends/Software/SWTexture.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-19 04:40:00 +12:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 19:42:56 +10:00
										 |  |  | #include "VideoCommon/AbstractPipeline.h"
 | 
					
						
							|  |  |  | #include "VideoCommon/AbstractShader.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-15 11:59:50 +10:00
										 |  |  | #include "VideoCommon/AbstractTexture.h"
 | 
					
						
							| 
									
										
										
										
											2015-10-09 20:50:36 +02:00
										 |  |  | #include "VideoCommon/BoundingBox.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-15 11:59:50 +10:00
										 |  |  | #include "VideoCommon/NativeVertexFormat.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include "VideoCommon/OnScreenDisplay.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-23 11:20:20 -05:00
										 |  |  | #include "VideoCommon/VideoBackendBase.h"
 | 
					
						
							| 
									
										
										
										
											2015-10-09 20:50:36 +02:00
										 |  |  | #include "VideoCommon/VideoConfig.h"
 | 
					
						
							| 
									
										
										
										
											2013-04-13 00:48:53 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-15 11:59:50 +10:00
										 |  |  | namespace SW | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-03 23:03:26 +10:00
										 |  |  | SWRenderer::SWRenderer(std::unique_ptr<SWOGLWindow> window) | 
					
						
							| 
									
										
										
										
											2019-01-19 00:35:00 +10:00
										 |  |  |     : ::Renderer(static_cast<int>(MAX_XFB_WIDTH), static_cast<int>(MAX_XFB_HEIGHT), 1.0f, | 
					
						
							| 
									
										
										
										
											2017-09-09 16:09:24 +10:00
										 |  |  |                  AbstractTextureFormat::RGBA8), | 
					
						
							| 
									
										
										
										
											2018-10-03 23:03:26 +10:00
										 |  |  |       m_window(std::move(window)) | 
					
						
							| 
									
										
										
										
											2017-03-04 16:40:08 +10:00
										 |  |  | { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-03 23:03:13 +10:00
										 |  |  | bool SWRenderer::IsHeadless() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-10-03 23:03:26 +10:00
										 |  |  |   return m_window->IsHeadless(); | 
					
						
							| 
									
										
										
										
											2018-10-03 23:03:13 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-30 16:25:36 +10:00
										 |  |  | std::unique_ptr<AbstractTexture> SWRenderer::CreateTexture(const TextureConfig& config) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-15 11:59:50 +10:00
										 |  |  |   return std::make_unique<SWTexture>(config); | 
					
						
							| 
									
										
										
										
											2017-09-30 16:25:36 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-22 00:49:40 +10:00
										 |  |  | std::unique_ptr<AbstractStagingTexture> | 
					
						
							|  |  |  | SWRenderer::CreateStagingTexture(StagingTextureType type, const TextureConfig& config) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-15 11:59:50 +10:00
										 |  |  |   return std::make_unique<SWStagingTexture>(type, config); | 
					
						
							| 
									
										
										
										
											2017-10-22 00:49:40 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-21 20:22:45 +10:00
										 |  |  | std::unique_ptr<AbstractFramebuffer> | 
					
						
							| 
									
										
										
										
											2019-02-15 11:59:50 +10:00
										 |  |  | SWRenderer::CreateFramebuffer(AbstractTexture* color_attachment, AbstractTexture* depth_attachment) | 
					
						
							| 
									
										
										
										
											2018-01-21 20:22:45 +10:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-02-15 11:59:50 +10:00
										 |  |  |   return SWFramebuffer::Create(static_cast<SWTexture*>(color_attachment), | 
					
						
							|  |  |  |                                static_cast<SWTexture*>(depth_attachment)); | 
					
						
							| 
									
										
										
										
											2018-01-21 20:22:45 +10:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-08 19:42:56 +10:00
										 |  |  | 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, const char* source, size_t length) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return std::make_unique<SWShader>(stage); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | std::unique_ptr<AbstractShader> SWRenderer::CreateShaderFromBinary(ShaderStage stage, | 
					
						
							|  |  |  |                                                                    const void* data, size_t length) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return std::make_unique<SWShader>(stage); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SWPipeline final : public AbstractPipeline | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |   SWPipeline() : AbstractPipeline() {} | 
					
						
							|  |  |  |   ~SWPipeline() override = default; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-15 21:55:26 +10:00
										 |  |  | std::unique_ptr<AbstractPipeline> SWRenderer::CreatePipeline(const AbstractPipelineConfig& config, | 
					
						
							|  |  |  |                                                              const void* cache_data, | 
					
						
							|  |  |  |                                                              size_t cache_data_length) | 
					
						
							| 
									
										
										
										
											2017-09-08 19:42:56 +10:00
										 |  |  | { | 
					
						
							|  |  |  |   return std::make_unique<SWPipeline>(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-20 23:51:39 +12:00
										 |  |  | // Called on the GPU thread
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:47:46 +10:00
										 |  |  | void SWRenderer::RenderXFBToScreen(const AbstractTexture* texture, | 
					
						
							|  |  |  |                                    const MathUtil::Rectangle<int>& xfb_region) | 
					
						
							| 
									
										
										
										
											2013-08-20 23:51:39 +12:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2017-11-23 16:53:44 +10:00
										 |  |  |   if (!IsHeadless()) | 
					
						
							| 
									
										
										
										
											2018-10-03 23:03:26 +10:00
										 |  |  |     m_window->ShowImage(texture, xfb_region); | 
					
						
							| 
									
										
										
										
											2015-10-09 20:50:36 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | u32 SWRenderer::AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   u32 value = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   switch (type) | 
					
						
							|  |  |  |   { | 
					
						
							| 
									
										
										
										
											2017-01-23 02:51:46 -05:00
										 |  |  |   case EFBAccessType::PeekZ: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   { | 
					
						
							|  |  |  |     value = EfbInterface::GetDepth(x, y); | 
					
						
							|  |  |  |     break; | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2017-01-23 02:51:46 -05:00
										 |  |  |   case EFBAccessType::PeekColor: | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   { | 
					
						
							| 
									
										
										
										
											2016-09-21 18:53:13 -04:00
										 |  |  |     const u32 color = EfbInterface::GetColor(x, y); | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // rgba to argb
 | 
					
						
							|  |  |  |     value = (color >> 8) | (color & 0xff) << 24; | 
					
						
							|  |  |  |     break; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  |   default: | 
					
						
							|  |  |  |     break; | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   return value; | 
					
						
							| 
									
										
										
										
											2015-10-09 20:50:36 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | u16 SWRenderer::BBoxRead(int index) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   return BoundingBox::coords[index]; | 
					
						
							| 
									
										
										
										
											2015-10-09 20:50:36 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SWRenderer::BBoxWrite(int index, u16 value) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   BoundingBox::coords[index] = value; | 
					
						
							| 
									
										
										
										
											2015-10-09 20:50:36 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-04-16 00:47:46 +10:00
										 |  |  | void SWRenderer::ClearScreen(const MathUtil::Rectangle<int>& rc, bool colorEnable, bool alphaEnable, | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |                              bool zEnable, u32 color, u32 z) | 
					
						
							| 
									
										
										
										
											2015-10-09 20:50:36 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   EfbCopy::ClearEfb(); | 
					
						
							| 
									
										
										
										
											2010-06-09 01:37:08 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-02-15 11:59:50 +10:00
										 |  |  | 
 | 
					
						
							|  |  |  | std::unique_ptr<NativeVertexFormat> | 
					
						
							|  |  |  | SWRenderer::CreateNativeVertexFormat(const PortableVertexDeclaration& vtx_decl) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   return std::make_unique<NativeVertexFormat>(vtx_decl); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | }  // namespace SW
 |