| 
									
										
										
										
											2015-05-24 06:55:12 +02:00
										 |  |  | // Copyright 2010 Dolphin Emulator Project
 | 
					
						
							| 
									
										
										
										
											2015-05-18 01:08:10 +02:00
										 |  |  | // Licensed under GPLv2+
 | 
					
						
							| 
									
										
										
										
											2013-04-17 23:09:55 -04:00
										 |  |  | // Refer to the license.txt file included.
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | #include <string>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include "Common/FileUtil.h"
 | 
					
						
							| 
									
										
										
										
											2016-01-17 16:54:31 -05:00
										 |  |  | #include "Common/StringUtil.h"
 | 
					
						
							| 
									
										
										
										
											2015-09-04 02:14:10 -04:00
										 |  |  | #include "Common/Thread.h"
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-01-17 16:54:31 -05:00
										 |  |  | #include "VideoCommon/BPMemory.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-17 05:18:15 -05:00
										 |  |  | #include "VideoCommon/Debugger.h"
 | 
					
						
							|  |  |  | #include "VideoCommon/VideoConfig.h"
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  | GFXDebuggerBase* g_pdebugger = nullptr; | 
					
						
							|  |  |  | volatile bool GFXDebuggerPauseFlag = | 
					
						
							|  |  |  |     false;  // if true, the GFX thread will be spin locked until it's false again
 | 
					
						
							|  |  |  | volatile PauseEvent GFXDebuggerToPauseAtNext = | 
					
						
							|  |  |  |     NOT_PAUSE;  // Event which will trigger spin locking the GFX thread
 | 
					
						
							|  |  |  | volatile int GFXDebuggerEventToPauseCount = | 
					
						
							|  |  |  |     0;  // Number of events to wait for until GFX thread will be paused
 | 
					
						
							| 
									
										
										
										
											2011-02-16 12:09:39 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | void GFXDebuggerUpdateScreen() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // TODO: Implement this in a backend-independent way
 | 
					
						
							|  |  |  |   /*	// update screen
 | 
					
						
							|  |  |  |     if (D3D::bFrameInProgress) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       D3D::dev->SetRenderTarget(0, D3D::GetBackBufferSurface()); | 
					
						
							|  |  |  |       D3D::dev->SetDepthStencilSurface(nullptr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       D3D::dev->StretchRect(FramebufferManager::GetEFBColorRTSurface(), nullptr, | 
					
						
							|  |  |  |         D3D::GetBackBufferSurface(), nullptr, | 
					
						
							|  |  |  |         D3DTEXF_LINEAR); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       D3D::dev->EndScene(); | 
					
						
							|  |  |  |       D3D::dev->Present(nullptr, nullptr, nullptr, nullptr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       D3D::dev->SetRenderTarget(0, FramebufferManager::GetEFBColorRTSurface()); | 
					
						
							|  |  |  |       D3D::dev->SetDepthStencilSurface(FramebufferManager::GetEFBDepthRTSurface()); | 
					
						
							|  |  |  |       D3D::dev->BeginScene(); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       D3D::dev->EndScene(); | 
					
						
							|  |  |  |       D3D::dev->Present(nullptr, nullptr, nullptr, nullptr); | 
					
						
							|  |  |  |       D3D::dev->BeginScene(); | 
					
						
							|  |  |  |     }*/ | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 20:59:57 +00:00
										 |  |  | // GFX thread
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | void GFXDebuggerCheckAndPause(bool update) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   if (GFXDebuggerPauseFlag) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     g_pdebugger->OnPause(); | 
					
						
							|  |  |  |     while (GFXDebuggerPauseFlag) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       if (update) | 
					
						
							|  |  |  |         GFXDebuggerUpdateScreen(); | 
					
						
							|  |  |  |       Common::SleepCurrentThread(5); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     g_pdebugger->OnContinue(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2011-07-01 20:59:57 +00:00
										 |  |  | // GFX thread
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | void GFXDebuggerToPause(bool update) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   GFXDebuggerToPauseAtNext = NOT_PAUSE; | 
					
						
							|  |  |  |   GFXDebuggerPauseFlag = true; | 
					
						
							|  |  |  |   GFXDebuggerCheckAndPause(update); | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ContinueGFXDebugger() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   GFXDebuggerPauseFlag = false; | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | void GFXDebuggerBase::DumpPixelShader(const std::string& path) | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   const std::string filename = StringFromFormat("%sdump_ps.txt", path.c_str()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   std::string output; | 
					
						
							|  |  |  |   bool useDstAlpha = bpmem.dstalpha.enable && bpmem.blendmode.alphaupdate && | 
					
						
							|  |  |  |                      bpmem.zcontrol.pixel_format == PEControl::RGBA6_Z24; | 
					
						
							|  |  |  |   if (!useDstAlpha) | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     output = "Destination alpha disabled:\n"; | 
					
						
							|  |  |  |     ///		output += GeneratePixelShaderCode(DSTALPHA_NONE, g_ActiveConfig.backend_info.APIType,
 | 
					
						
							| 
									
										
										
										
											2016-06-24 12:16:10 +02:00
										 |  |  |     /// g_nativeVertexFmt->m_components);
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   } | 
					
						
							|  |  |  |   else | 
					
						
							|  |  |  |   { | 
					
						
							|  |  |  |     if (g_ActiveConfig.backend_info.bSupportsDualSourceBlend) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       output = "Using dual source blending for destination alpha:\n"; | 
					
						
							|  |  |  |       ///			output += GeneratePixelShaderCode(DSTALPHA_DUAL_SOURCE_BLEND,
 | 
					
						
							| 
									
										
										
										
											2016-06-24 12:16:10 +02:00
										 |  |  |       /// g_ActiveConfig.backend_info.APIType, g_nativeVertexFmt->m_components);
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |       output = "Using two passes for emulating destination alpha:\n"; | 
					
						
							|  |  |  |       ///			output += GeneratePixelShaderCode(DSTALPHA_NONE, g_ActiveConfig.backend_info.APIType,
 | 
					
						
							| 
									
										
										
										
											2016-06-24 12:16:10 +02:00
										 |  |  |       /// g_nativeVertexFmt->m_components);
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |       output += "\n\nDestination alpha pass shader:\n"; | 
					
						
							|  |  |  |       ///			output += GeneratePixelShaderCode(DSTALPHA_ALPHA_PASS,
 | 
					
						
							| 
									
										
										
										
											2016-06-24 12:16:10 +02:00
										 |  |  |       /// g_ActiveConfig.backend_info.APIType, g_nativeVertexFmt->m_components);
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   File::CreateEmptyFile(filename); | 
					
						
							|  |  |  |   File::WriteStringToFile(output, filename); | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | void GFXDebuggerBase::DumpVertexShader(const std::string& path) | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   const std::string filename = StringFromFormat("%sdump_vs.txt", path.c_str()); | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   File::CreateEmptyFile(filename); | 
					
						
							|  |  |  |   ///	File::WriteStringToFile(GenerateVertexShaderCode(g_nativeVertexFmt->m_components,
 | 
					
						
							| 
									
										
										
										
											2016-06-24 12:16:10 +02:00
										 |  |  |   /// g_ActiveConfig.backend_info.APIType), filename);
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | void GFXDebuggerBase::DumpPixelShaderConstants(const std::string& path) | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // TODO
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | void GFXDebuggerBase::DumpVertexShaderConstants(const std::string& path) | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // TODO
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | void GFXDebuggerBase::DumpTextures(const std::string& path) | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // TODO
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | void GFXDebuggerBase::DumpFrameBuffer(const std::string& path) | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // TODO
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | void GFXDebuggerBase::DumpGeometry(const std::string& path) | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // TODO
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | void GFXDebuggerBase::DumpVertexDecl(const std::string& path) | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // TODO
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | void GFXDebuggerBase::DumpMatrices(const std::string& path) | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // TODO
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-12 15:33:41 -04:00
										 |  |  | void GFXDebuggerBase::DumpStats(const std::string& path) | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2016-06-24 10:43:46 +02:00
										 |  |  |   // TODO
 | 
					
						
							| 
									
										
										
										
											2010-12-05 14:15:36 +00:00
										 |  |  | } |