MainBase.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. // Copyright 2010 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #include "Common/Event.h"
  5. #include "Core/ConfigManager.h"
  6. #include "VideoCommon/AsyncRequests.h"
  7. #include "VideoCommon/BoundingBox.h"
  8. #include "VideoCommon/BPStructs.h"
  9. #include "VideoCommon/CommandProcessor.h"
  10. #include "VideoCommon/Fifo.h"
  11. #include "VideoCommon/FramebufferManagerBase.h"
  12. #include "VideoCommon/MainBase.h"
  13. #include "VideoCommon/OnScreenDisplay.h"
  14. #include "VideoCommon/PixelEngine.h"
  15. #include "VideoCommon/RenderBase.h"
  16. #include "VideoCommon/TextureCacheBase.h"
  17. #include "VideoCommon/VertexLoaderManager.h"
  18. #include "VideoCommon/VideoBackendBase.h"
  19. #include "VideoCommon/VideoConfig.h"
  20. #include "VideoCommon/VideoState.h"
  21. bool s_BackendInitialized = false;
  22. static Common::Flag s_FifoShuttingDown;
  23. static volatile struct
  24. {
  25. u32 xfbAddr;
  26. u32 fbWidth;
  27. u32 fbStride;
  28. u32 fbHeight;
  29. } s_beginFieldArgs;
  30. void VideoBackendHardware::EmuStateChange(EMUSTATE_CHANGE newState)
  31. {
  32. EmulatorState((newState == EMUSTATE_CHANGE_PLAY) ? true : false);
  33. }
  34. // Enter and exit the video loop
  35. void VideoBackendHardware::Video_EnterLoop()
  36. {
  37. RunGpuLoop();
  38. }
  39. void VideoBackendHardware::Video_ExitLoop()
  40. {
  41. ExitGpuLoop();
  42. s_FifoShuttingDown.Set();
  43. }
  44. void VideoBackendHardware::Video_SetRendering(bool bEnabled)
  45. {
  46. Fifo_SetRendering(bEnabled);
  47. }
  48. // Run from the CPU thread (from VideoInterface.cpp)
  49. void VideoBackendHardware::Video_BeginField(u32 xfbAddr, u32 fbWidth, u32 fbStride, u32 fbHeight)
  50. {
  51. if (s_BackendInitialized && g_ActiveConfig.bUseXFB)
  52. {
  53. s_beginFieldArgs.xfbAddr = xfbAddr;
  54. s_beginFieldArgs.fbWidth = fbWidth;
  55. s_beginFieldArgs.fbStride = fbStride;
  56. s_beginFieldArgs.fbHeight = fbHeight;
  57. }
  58. }
  59. // Run from the CPU thread (from VideoInterface.cpp)
  60. void VideoBackendHardware::Video_EndField()
  61. {
  62. if (s_BackendInitialized && g_ActiveConfig.bUseXFB && g_renderer)
  63. {
  64. SyncGPU(SYNC_GPU_SWAP);
  65. AsyncRequests::Event e;
  66. e.time = 0;
  67. e.type = AsyncRequests::Event::SWAP_EVENT;
  68. e.swap_event.xfbAddr = s_beginFieldArgs.xfbAddr;
  69. e.swap_event.fbWidth = s_beginFieldArgs.fbWidth;
  70. e.swap_event.fbStride = s_beginFieldArgs.fbStride;
  71. e.swap_event.fbHeight = s_beginFieldArgs.fbHeight;
  72. AsyncRequests::GetInstance()->PushEvent(e, false);
  73. }
  74. }
  75. void VideoBackendHardware::Video_AddMessage(const std::string& msg, u32 milliseconds)
  76. {
  77. OSD::AddMessage(msg, milliseconds);
  78. }
  79. void VideoBackendHardware::Video_ClearMessages()
  80. {
  81. OSD::ClearMessages();
  82. }
  83. // Screenshot
  84. bool VideoBackendHardware::Video_Screenshot(const std::string& filename)
  85. {
  86. Renderer::SetScreenshot(filename.c_str());
  87. return true;
  88. }
  89. u32 VideoBackendHardware::Video_AccessEFB(EFBAccessType type, u32 x, u32 y, u32 InputData)
  90. {
  91. if (!g_ActiveConfig.bEFBAccessEnable)
  92. {
  93. return 0;
  94. }
  95. if (type == POKE_COLOR || type == POKE_Z)
  96. {
  97. AsyncRequests::Event e;
  98. e.type = type == POKE_COLOR ? AsyncRequests::Event::EFB_POKE_COLOR : AsyncRequests::Event::EFB_POKE_Z;
  99. e.time = 0;
  100. e.efb_poke.data = InputData;
  101. e.efb_poke.x = x;
  102. e.efb_poke.y = y;
  103. AsyncRequests::GetInstance()->PushEvent(e, false);
  104. return 0;
  105. }
  106. else
  107. {
  108. AsyncRequests::Event e;
  109. u32 result;
  110. e.type = type == PEEK_COLOR ? AsyncRequests::Event::EFB_PEEK_COLOR : AsyncRequests::Event::EFB_PEEK_Z;
  111. e.time = 0;
  112. e.efb_peek.x = x;
  113. e.efb_peek.y = y;
  114. e.efb_peek.data = &result;
  115. AsyncRequests::GetInstance()->PushEvent(e, true);
  116. return result;
  117. }
  118. }
  119. u32 VideoBackendHardware::Video_GetQueryResult(PerfQueryType type)
  120. {
  121. if (!g_perf_query->ShouldEmulate())
  122. {
  123. return 0;
  124. }
  125. SyncGPU(SYNC_GPU_PERFQUERY);
  126. AsyncRequests::Event e;
  127. e.time = 0;
  128. e.type = AsyncRequests::Event::PERF_QUERY;
  129. if (!g_perf_query->IsFlushed())
  130. AsyncRequests::GetInstance()->PushEvent(e, true);
  131. return g_perf_query->GetQueryResult(type);
  132. }
  133. u16 VideoBackendHardware::Video_GetBoundingBox(int index)
  134. {
  135. if (!g_ActiveConfig.backend_info.bSupportsBBox)
  136. return 0;
  137. if (!g_ActiveConfig.bBBoxEnable)
  138. {
  139. static bool warn_once = true;
  140. if (warn_once)
  141. ERROR_LOG(VIDEO, "BBox shall be used but it is disabled. Please use a gameini to enable it for this game.");
  142. warn_once = false;
  143. return 0;
  144. }
  145. SyncGPU(SYNC_GPU_BBOX);
  146. AsyncRequests::Event e;
  147. u16 result;
  148. e.time = 0;
  149. e.type = AsyncRequests::Event::BBOX_READ;
  150. e.bbox.index = index;
  151. e.bbox.data = &result;
  152. AsyncRequests::GetInstance()->PushEvent(e, true);
  153. return result;
  154. }
  155. void VideoBackendHardware::InitializeShared()
  156. {
  157. VideoCommon_Init();
  158. s_FifoShuttingDown.Clear();
  159. memset((void*)&s_beginFieldArgs, 0, sizeof(s_beginFieldArgs));
  160. m_invalid = false;
  161. }
  162. // Run from the CPU thread
  163. void VideoBackendHardware::DoState(PointerWrap& p)
  164. {
  165. bool software = false;
  166. p.Do(software);
  167. if (p.GetMode() == PointerWrap::MODE_READ && software == true)
  168. {
  169. // change mode to abort load of incompatible save state.
  170. p.SetMode(PointerWrap::MODE_VERIFY);
  171. }
  172. VideoCommon_DoState(p);
  173. p.DoMarker("VideoCommon");
  174. p.Do(s_beginFieldArgs);
  175. p.DoMarker("VideoBackendHardware");
  176. // Refresh state.
  177. if (p.GetMode() == PointerWrap::MODE_READ)
  178. {
  179. m_invalid = true;
  180. // Clear all caches that touch RAM
  181. // (? these don't appear to touch any emulation state that gets saved. moved to on load only.)
  182. VertexLoaderManager::MarkAllDirty();
  183. }
  184. }
  185. void VideoBackendHardware::CheckInvalidState()
  186. {
  187. if (m_invalid)
  188. {
  189. m_invalid = false;
  190. BPReload();
  191. TextureCache::Invalidate();
  192. }
  193. }
  194. void VideoBackendHardware::PauseAndLock(bool doLock, bool unpauseOnUnlock)
  195. {
  196. Fifo_PauseAndLock(doLock, unpauseOnUnlock);
  197. }
  198. void VideoBackendHardware::RunLoop(bool enable)
  199. {
  200. VideoCommon_RunLoop(enable);
  201. }
  202. void VideoBackendHardware::Video_GatherPipeBursted()
  203. {
  204. CommandProcessor::GatherPipeBursted();
  205. }
  206. int VideoBackendHardware::Video_Sync(int ticks)
  207. {
  208. return Fifo_Update(ticks);
  209. }
  210. void VideoBackendHardware::RegisterCPMMIO(MMIO::Mapping* mmio, u32 base)
  211. {
  212. CommandProcessor::RegisterMMIO(mmio, base);
  213. }
  214. void VideoBackendHardware::UpdateWantDeterminism(bool want)
  215. {
  216. Fifo_UpdateWantDeterminism(want);
  217. }