BPStructs.cpp 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  1. // Copyright 2009 Dolphin Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #include "VideoCommon/BPStructs.h"
  4. #include <algorithm>
  5. #include <cmath>
  6. #include <cstring>
  7. #include <string>
  8. #include <fmt/format.h>
  9. #include "Common/CommonTypes.h"
  10. #include "Common/EnumMap.h"
  11. #include "Common/Logging/Log.h"
  12. #include "Core/CoreTiming.h"
  13. #include "Core/DolphinAnalytics.h"
  14. #include "Core/FifoPlayer/FifoPlayer.h"
  15. #include "Core/FifoPlayer/FifoRecorder.h"
  16. #include "Core/HW/Memmap.h"
  17. #include "Core/HW/VideoInterface.h"
  18. #include "Core/System.h"
  19. #include "VideoCommon/BPFunctions.h"
  20. #include "VideoCommon/BPMemory.h"
  21. #include "VideoCommon/BoundingBox.h"
  22. #include "VideoCommon/Fifo.h"
  23. #include "VideoCommon/FramebufferManager.h"
  24. #include "VideoCommon/GeometryShaderManager.h"
  25. #include "VideoCommon/OpcodeDecoding.h"
  26. #include "VideoCommon/PerfQueryBase.h"
  27. #include "VideoCommon/PixelEngine.h"
  28. #include "VideoCommon/PixelShaderManager.h"
  29. #include "VideoCommon/Present.h"
  30. #include "VideoCommon/Statistics.h"
  31. #include "VideoCommon/TMEM.h"
  32. #include "VideoCommon/TextureCacheBase.h"
  33. #include "VideoCommon/TextureDecoder.h"
  34. #include "VideoCommon/VideoBackendBase.h"
  35. #include "VideoCommon/VideoCommon.h"
  36. #include "VideoCommon/VideoConfig.h"
  37. #include "VideoCommon/VideoEvents.h"
  38. #include "VideoCommon/XFStateManager.h"
  39. using namespace BPFunctions;
  40. static constexpr Common::EnumMap<float, GammaCorrection::Invalid2_2> s_gammaLUT = {1.0f, 1.7f, 2.2f,
  41. 2.2f};
  42. void BPInit()
  43. {
  44. memset(reinterpret_cast<u8*>(&bpmem), 0, sizeof(bpmem));
  45. bpmem.bpMask = 0xFFFFFF;
  46. }
  47. static void BPWritten(PixelShaderManager& pixel_shader_manager, XFStateManager& xf_state_manager,
  48. GeometryShaderManager& geometry_shader_manager, const BPCmd& bp,
  49. int cycles_into_future)
  50. {
  51. /*
  52. ----------------------------------------------------------------------------------------------------------------
  53. Purpose: Writes to the BP registers
  54. Called: At the end of every: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg
  55. How It Works: First the pipeline is flushed then update the bpmem with the new value.
  56. Some of the BP cases have to call certain functions while others just update the bpmem.
  57. some bp cases check the changes variable, because they might not have to be updated all
  58. the time
  59. NOTE: it seems not all bp cases like checking changes, so calling if (bp.changes == 0 ? false :
  60. true)
  61. had to be ditched and the games seem to work fine with out it.
  62. NOTE2: Yet Another GameCube Documentation calls them Bypass Raster State Registers but possibly
  63. completely wrong
  64. NOTE3: This controls the register groups: RAS1/2, SU, TF, TEV, C/Z, PEC
  65. TODO: Turn into function table. The (future) DisplayList (DL) jit can then call the functions
  66. directly,
  67. getting rid of dynamic dispatch. Unfortunately, few games use DLs properly - most\
  68. just stuff geometry in them and don't put state changes there
  69. ----------------------------------------------------------------------------------------------------------------
  70. */
  71. if (((s32*)&bpmem)[bp.address] == bp.newvalue)
  72. {
  73. if (!(bp.address == BPMEM_TRIGGER_EFB_COPY || bp.address == BPMEM_CLEARBBOX1 ||
  74. bp.address == BPMEM_CLEARBBOX2 || bp.address == BPMEM_SETDRAWDONE ||
  75. bp.address == BPMEM_PE_TOKEN_ID || bp.address == BPMEM_PE_TOKEN_INT_ID ||
  76. bp.address == BPMEM_LOADTLUT0 || bp.address == BPMEM_LOADTLUT1 ||
  77. bp.address == BPMEM_TEXINVALIDATE || bp.address == BPMEM_PRELOAD_MODE ||
  78. bp.address == BPMEM_CLEAR_PIXEL_PERF))
  79. {
  80. return;
  81. }
  82. }
  83. FlushPipeline();
  84. ((u32*)&bpmem)[bp.address] = bp.newvalue;
  85. switch (bp.address)
  86. {
  87. case BPMEM_GENMODE: // Set the Generation Mode
  88. PRIM_LOG("genmode: texgen={}, col={}, multisampling={}, tev={}, cullmode={}, ind={}, zfeeze={}",
  89. bpmem.genMode.numtexgens, bpmem.genMode.numcolchans, bpmem.genMode.multisampling,
  90. bpmem.genMode.numtevstages + 1, bpmem.genMode.cullmode, bpmem.genMode.numindstages,
  91. bpmem.genMode.zfreeze);
  92. if (bp.changes)
  93. pixel_shader_manager.SetGenModeChanged();
  94. // Only call SetGenerationMode when cull mode changes.
  95. if (bp.changes & 0xC000)
  96. SetGenerationMode();
  97. return;
  98. case BPMEM_IND_MTXA: // Index Matrix Changed
  99. case BPMEM_IND_MTXB:
  100. case BPMEM_IND_MTXC:
  101. case BPMEM_IND_MTXA + 3:
  102. case BPMEM_IND_MTXB + 3:
  103. case BPMEM_IND_MTXC + 3:
  104. case BPMEM_IND_MTXA + 6:
  105. case BPMEM_IND_MTXB + 6:
  106. case BPMEM_IND_MTXC + 6:
  107. if (bp.changes)
  108. pixel_shader_manager.SetIndMatrixChanged((bp.address - BPMEM_IND_MTXA) / 3);
  109. return;
  110. case BPMEM_RAS1_SS0: // Index Texture Coordinate Scale 0
  111. if (bp.changes)
  112. pixel_shader_manager.SetIndTexScaleChanged(false);
  113. return;
  114. case BPMEM_RAS1_SS1: // Index Texture Coordinate Scale 1
  115. if (bp.changes)
  116. pixel_shader_manager.SetIndTexScaleChanged(true);
  117. return;
  118. // ----------------
  119. // Scissor Control
  120. // ----------------
  121. case BPMEM_SCISSORTL: // Scissor Rectable Top, Left
  122. case BPMEM_SCISSORBR: // Scissor Rectable Bottom, Right
  123. case BPMEM_SCISSOROFFSET: // Scissor Offset
  124. xf_state_manager.SetViewportChanged();
  125. geometry_shader_manager.SetViewportChanged();
  126. return;
  127. case BPMEM_LINEPTWIDTH: // Line Width
  128. geometry_shader_manager.SetLinePtWidthChanged();
  129. return;
  130. case BPMEM_ZMODE: // Depth Control
  131. PRIM_LOG("zmode: test={}, func={}, upd={}", bpmem.zmode.testenable, bpmem.zmode.func,
  132. bpmem.zmode.updateenable);
  133. SetDepthMode();
  134. pixel_shader_manager.SetZModeControl();
  135. return;
  136. case BPMEM_BLENDMODE: // Blending Control
  137. if (bp.changes & 0xFFFF)
  138. {
  139. PRIM_LOG("blendmode: en={}, open={}, colupd={}, alphaupd={}, dst={}, src={}, sub={}, mode={}",
  140. bpmem.blendmode.blendenable, bpmem.blendmode.logicopenable,
  141. bpmem.blendmode.colorupdate, bpmem.blendmode.alphaupdate, bpmem.blendmode.dstfactor,
  142. bpmem.blendmode.srcfactor, bpmem.blendmode.subtract, bpmem.blendmode.logicmode);
  143. SetBlendMode();
  144. pixel_shader_manager.SetBlendModeChanged();
  145. }
  146. return;
  147. case BPMEM_CONSTANTALPHA: // Set Destination Alpha
  148. PRIM_LOG("constalpha: alp={}, en={}", bpmem.dstalpha.alpha, bpmem.dstalpha.enable);
  149. if (bp.changes)
  150. {
  151. pixel_shader_manager.SetAlpha();
  152. pixel_shader_manager.SetDestAlphaChanged();
  153. }
  154. if (bp.changes & 0x100)
  155. SetBlendMode();
  156. return;
  157. // This is called when the game is done drawing the new frame (eg: like in DX: Begin(); Draw();
  158. // End();)
  159. // Triggers an interrupt on the PPC side so that the game knows when the GPU has finished drawing.
  160. // Tokens are similar.
  161. case BPMEM_SETDRAWDONE:
  162. switch (bp.newvalue & 0xFF)
  163. {
  164. case 0x02:
  165. {
  166. INCSTAT(g_stats.this_frame.num_draw_done);
  167. g_texture_cache->FlushEFBCopies();
  168. g_texture_cache->FlushStaleBinds();
  169. g_framebuffer_manager->InvalidatePeekCache(false);
  170. g_framebuffer_manager->RefreshPeekCache();
  171. auto& system = Core::System::GetInstance();
  172. if (!system.GetFifo().UseDeterministicGPUThread())
  173. system.GetPixelEngine().SetFinish(cycles_into_future); // may generate interrupt
  174. DEBUG_LOG_FMT(VIDEO, "GXSetDrawDone SetPEFinish (value: {:#04X})", bp.newvalue & 0xFFFF);
  175. return;
  176. }
  177. default:
  178. WARN_LOG_FMT(VIDEO, "GXSetDrawDone ??? (value {:#04X})", bp.newvalue & 0xFFFF);
  179. return;
  180. }
  181. return;
  182. case BPMEM_PE_TOKEN_ID: // Pixel Engine Token ID
  183. {
  184. INCSTAT(g_stats.this_frame.num_token);
  185. g_texture_cache->FlushEFBCopies();
  186. g_texture_cache->FlushStaleBinds();
  187. g_framebuffer_manager->InvalidatePeekCache(false);
  188. g_framebuffer_manager->RefreshPeekCache();
  189. auto& system = Core::System::GetInstance();
  190. if (!system.GetFifo().UseDeterministicGPUThread())
  191. {
  192. system.GetPixelEngine().SetToken(static_cast<u16>(bp.newvalue & 0xFFFF), false,
  193. cycles_into_future);
  194. }
  195. DEBUG_LOG_FMT(VIDEO, "SetPEToken {:#06X}", bp.newvalue & 0xFFFF);
  196. return;
  197. }
  198. case BPMEM_PE_TOKEN_INT_ID: // Pixel Engine Interrupt Token ID
  199. {
  200. INCSTAT(g_stats.this_frame.num_token_int);
  201. g_texture_cache->FlushEFBCopies();
  202. g_texture_cache->FlushStaleBinds();
  203. g_framebuffer_manager->InvalidatePeekCache(false);
  204. g_framebuffer_manager->RefreshPeekCache();
  205. auto& system = Core::System::GetInstance();
  206. if (!system.GetFifo().UseDeterministicGPUThread())
  207. {
  208. system.GetPixelEngine().SetToken(static_cast<u16>(bp.newvalue & 0xFFFF), true,
  209. cycles_into_future);
  210. }
  211. DEBUG_LOG_FMT(VIDEO, "SetPEToken + INT {:#06X}", bp.newvalue & 0xFFFF);
  212. return;
  213. }
  214. // ------------------------
  215. // EFB copy command. This copies a rectangle from the EFB to either RAM in a texture format or to
  216. // XFB as YUYV.
  217. // It can also optionally clear the EFB while copying from it. To emulate this, we of course copy
  218. // first and clear afterwards.
  219. case BPMEM_TRIGGER_EFB_COPY: // Copy EFB Region or Render to the XFB or Clear the screen.
  220. {
  221. // The bottom right is within the rectangle
  222. // The values in bpmem.copyTexSrcXY and bpmem.copyTexSrcWH are updated in case 0x49 and 0x4a in
  223. // this function
  224. u32 destAddr = bpmem.copyTexDest << 5;
  225. u32 destStride = bpmem.copyDestStride << 5;
  226. MathUtil::Rectangle<s32> srcRect;
  227. srcRect.left = bpmem.copyTexSrcXY.x;
  228. srcRect.top = bpmem.copyTexSrcXY.y;
  229. // Here Width+1 like Height, otherwise some textures are corrupted already since the native
  230. // resolution.
  231. srcRect.right = bpmem.copyTexSrcXY.x + bpmem.copyTexSrcWH.x + 1;
  232. srcRect.bottom = bpmem.copyTexSrcXY.y + bpmem.copyTexSrcWH.y + 1;
  233. const UPE_Copy PE_copy = bpmem.triggerEFBCopy;
  234. // Since the copy X and Y coordinates/sizes are 10-bit, the game can configure a copy region up
  235. // to 1024x1024. Hardware tests have found that the number of bytes written does not depend on
  236. // the configured stride, instead it is based on the size registers, writing beyond the length
  237. // of a single row. The data written for the pixels which lie outside the EFB bounds does not
  238. // wrap around instead returning different colors based on the pixel format of the EFB. This
  239. // suggests it's not based on coordinates, but instead on memory addresses. The effect of a
  240. // within-bounds size but out-of-bounds offset (e.g. offset 320,0, size 640,480) are the same.
  241. // As it would be difficult to emulate the exact behavior of out-of-bounds reads, instead of
  242. // writing the junk data, we don't write anything to RAM at all for over-sized copies, and clamp
  243. // to the EFB borders for over-offset copies. The arcade virtual console games (e.g. 1942) are
  244. // known for configuring these out-of-range copies.
  245. if (u32(srcRect.right) > EFB_WIDTH || u32(srcRect.bottom) > EFB_HEIGHT)
  246. {
  247. WARN_LOG_FMT(VIDEO, "Oversized EFB copy: {}x{} (offset {},{} stride {})", srcRect.GetWidth(),
  248. srcRect.GetHeight(), srcRect.left, srcRect.top, destStride);
  249. if (u32(srcRect.left) >= EFB_WIDTH || u32(srcRect.top) >= EFB_HEIGHT)
  250. {
  251. // This is not a sane src rectangle, it doesn't touch any valid image data at all
  252. // Just ignore it
  253. // Apparently Mario Kart Wii in wifi mode can generate a deformed EFB copy of size 4x4
  254. // at offset (328,1020)
  255. if (PE_copy.copy_to_xfb == 1)
  256. {
  257. // Make sure we disable Bounding box to match the side effects of the non-failure path
  258. g_bounding_box->Disable(pixel_shader_manager);
  259. }
  260. return;
  261. }
  262. // Clamp the copy region to fit within EFB. So that we don't end up with a stretched image.
  263. srcRect.right = std::clamp<int>(srcRect.right, 0, EFB_WIDTH);
  264. srcRect.bottom = std::clamp<int>(srcRect.bottom, 0, EFB_HEIGHT);
  265. }
  266. const u32 copy_width = srcRect.GetWidth();
  267. const u32 copy_height = srcRect.GetHeight();
  268. // Check if we are to copy from the EFB or draw to the XFB
  269. if (PE_copy.copy_to_xfb == 0)
  270. {
  271. // bpmem.zcontrol.pixel_format to PixelFormat::Z24 is when the game wants to copy from ZBuffer
  272. // (Zbuffer uses 24-bit Format)
  273. bool is_depth_copy = bpmem.zcontrol.pixel_format == PixelFormat::Z24;
  274. g_texture_cache->CopyRenderTargetToTexture(
  275. destAddr, PE_copy.tp_realFormat(), copy_width, copy_height, destStride, is_depth_copy,
  276. srcRect, PE_copy.intensity_fmt && PE_copy.auto_conv, PE_copy.half_scale, 1.0f,
  277. s_gammaLUT[PE_copy.gamma], bpmem.triggerEFBCopy.clamp_top,
  278. bpmem.triggerEFBCopy.clamp_bottom, bpmem.copyfilter.GetCoefficients());
  279. }
  280. else
  281. {
  282. // We should be able to get away with deactivating the current bbox tracking
  283. // here. Not sure if there's a better spot to put this.
  284. // the number of lines copied is determined by the y scale * source efb height
  285. g_bounding_box->Disable(pixel_shader_manager);
  286. float yScale;
  287. if (PE_copy.scale_invert)
  288. yScale = 256.0f / static_cast<float>(bpmem.dispcopyyscale);
  289. else
  290. yScale = static_cast<float>(bpmem.dispcopyyscale) / 256.0f;
  291. float num_xfb_lines = 1.0f + bpmem.copyTexSrcWH.y * yScale;
  292. u32 height = static_cast<u32>(num_xfb_lines);
  293. DEBUG_LOG_FMT(VIDEO,
  294. "RenderToXFB: destAddr: {:08x} | srcRect [{} {} {} {}] | fbWidth: {} | "
  295. "fbStride: {} | fbHeight: {} | yScale: {}",
  296. destAddr, srcRect.left, srcRect.top, srcRect.right, srcRect.bottom,
  297. bpmem.copyTexSrcWH.x + 1, destStride, height, yScale);
  298. bool is_depth_copy = bpmem.zcontrol.pixel_format == PixelFormat::Z24;
  299. g_texture_cache->CopyRenderTargetToTexture(
  300. destAddr, EFBCopyFormat::XFB, copy_width, height, destStride, is_depth_copy, srcRect,
  301. false, false, yScale, s_gammaLUT[PE_copy.gamma], bpmem.triggerEFBCopy.clamp_top,
  302. bpmem.triggerEFBCopy.clamp_bottom, bpmem.copyfilter.GetCoefficients());
  303. // This is as closest as we have to an "end of the frame"
  304. // It works 99% of the time.
  305. // But sometimes games want to render an XFB larger than the EFB's 640x528 pixel resolution
  306. // (especially when using the 3xMSAA mode, which cuts EFB resolution to 640x264). So they
  307. // render multiple sub-frames and arrange the XFB copies in next to each-other in main memory
  308. // so they form a single completed XFB.
  309. // See https://dolphin-emu.org/blog/2017/11/19/hybridxfb/ for examples and more detail.
  310. AfterFrameEvent::Trigger(Core::System::GetInstance());
  311. // Note: Theoretically, in the future we could track the VI configuration and try to detect
  312. // when an XFB is the last XFB copy of a frame. Not only would we get a clean "end of
  313. // the frame", but we would also be able to use ImmediateXFB even for these games.
  314. // Might also clean up some issues with games doing XFB copies they don't intend to
  315. // display.
  316. auto& system = Core::System::GetInstance();
  317. if (g_ActiveConfig.bImmediateXFB)
  318. {
  319. // below div two to convert from bytes to pixels - it expects width, not stride
  320. u64 ticks = system.GetCoreTiming().GetTicks();
  321. g_presenter->ImmediateSwap(destAddr, destStride / 2, destStride, height, ticks);
  322. }
  323. else
  324. {
  325. if (system.GetFifoPlayer().IsRunningWithFakeVideoInterfaceUpdates())
  326. {
  327. auto& vi = system.GetVideoInterface();
  328. vi.FakeVIUpdate(destAddr, srcRect.GetWidth(), destStride, height);
  329. }
  330. }
  331. }
  332. // Clear the rectangular region after copying it.
  333. if (PE_copy.clear)
  334. {
  335. ClearScreen(srcRect);
  336. }
  337. return;
  338. }
  339. case BPMEM_LOADTLUT0: // This updates bpmem.tmem_config.tlut_src, no need to do anything here.
  340. return;
  341. case BPMEM_LOADTLUT1: // Load a Texture Look Up Table
  342. {
  343. u32 tmem_addr = bpmem.tmem_config.tlut_dest.tmem_addr << 9;
  344. u32 tmem_transfer_count = bpmem.tmem_config.tlut_dest.tmem_line_count * TMEM_LINE_SIZE;
  345. u32 addr = bpmem.tmem_config.tlut_src << 5;
  346. // The GameCube ignores the upper bits of this address. Some games (WW, MKDD) set them.
  347. auto& system = Core::System::GetInstance();
  348. if (!system.IsWii())
  349. addr = addr & 0x01FFFFFF;
  350. // The copy below will always be in bounds as tmem is bigger than the maximum address a TLUT can
  351. // be loaded to.
  352. static constexpr u32 MAX_LOADABLE_TMEM_ADDR =
  353. (1 << bpmem.tmem_config.tlut_dest.tmem_addr.NumBits()) << 9;
  354. static constexpr u32 MAX_TMEM_LINE_COUNT =
  355. (1 << bpmem.tmem_config.tlut_dest.tmem_line_count.NumBits()) * TMEM_LINE_SIZE;
  356. static_assert(MAX_LOADABLE_TMEM_ADDR + MAX_TMEM_LINE_COUNT < TMEM_SIZE);
  357. auto& memory = system.GetMemory();
  358. memory.CopyFromEmu(s_tex_mem.data() + tmem_addr, addr, tmem_transfer_count);
  359. if (OpcodeDecoder::g_record_fifo_data)
  360. system.GetFifoRecorder().UseMemory(addr, tmem_transfer_count, MemoryUpdate::Type::TMEM);
  361. TMEM::InvalidateAll();
  362. return;
  363. }
  364. case BPMEM_FOGRANGE: // Fog Settings Control
  365. case BPMEM_FOGRANGE + 1:
  366. case BPMEM_FOGRANGE + 2:
  367. case BPMEM_FOGRANGE + 3:
  368. case BPMEM_FOGRANGE + 4:
  369. case BPMEM_FOGRANGE + 5:
  370. if (bp.changes)
  371. pixel_shader_manager.SetFogRangeAdjustChanged();
  372. return;
  373. case BPMEM_FOGPARAM0:
  374. case BPMEM_FOGBMAGNITUDE:
  375. case BPMEM_FOGBEXPONENT:
  376. case BPMEM_FOGPARAM3:
  377. if (bp.changes)
  378. pixel_shader_manager.SetFogParamChanged();
  379. return;
  380. case BPMEM_FOGCOLOR: // Fog Color
  381. if (bp.changes)
  382. pixel_shader_manager.SetFogColorChanged();
  383. return;
  384. case BPMEM_ALPHACOMPARE: // Compare Alpha Values
  385. PRIM_LOG("alphacmp: ref0={}, ref1={}, comp0={}, comp1={}, logic={}", bpmem.alpha_test.ref0,
  386. bpmem.alpha_test.ref1, bpmem.alpha_test.comp0, bpmem.alpha_test.comp1,
  387. bpmem.alpha_test.logic);
  388. if (bp.changes & 0xFFFF)
  389. pixel_shader_manager.SetAlpha();
  390. if (bp.changes)
  391. {
  392. pixel_shader_manager.SetAlphaTestChanged();
  393. SetBlendMode();
  394. }
  395. return;
  396. case BPMEM_BIAS: // BIAS
  397. PRIM_LOG("ztex bias={:#x}", bpmem.ztex1.bias);
  398. if (bp.changes)
  399. pixel_shader_manager.SetZTextureBias();
  400. return;
  401. case BPMEM_ZTEX2: // Z Texture type
  402. {
  403. if (bp.changes & 3)
  404. pixel_shader_manager.SetZTextureTypeChanged();
  405. if (bp.changes & 12)
  406. pixel_shader_manager.SetZTextureOpChanged();
  407. PRIM_LOG("ztex op={}, type={}", bpmem.ztex2.op, bpmem.ztex2.type);
  408. }
  409. return;
  410. // ----------------------------------
  411. // Display Copy Filtering Control - GX_SetCopyFilter(u8 aa,u8 sample_pattern[12][2],u8 vf,u8
  412. // vfilter[7])
  413. // Fields: Destination, Frame2Field, Gamma, Source
  414. // ----------------------------------
  415. case BPMEM_DISPLAYCOPYFILTER: // if (aa) { use sample_pattern } else { use 666666 }
  416. case BPMEM_DISPLAYCOPYFILTER + 1: // if (aa) { use sample_pattern } else { use 666666 }
  417. case BPMEM_DISPLAYCOPYFILTER + 2: // if (aa) { use sample_pattern } else { use 666666 }
  418. case BPMEM_DISPLAYCOPYFILTER + 3: // if (aa) { use sample_pattern } else { use 666666 }
  419. case BPMEM_COPYFILTER0: // if (vf) { use vfilter } else { use 595000 }
  420. case BPMEM_COPYFILTER1: // if (vf) { use vfilter } else { use 000015 }
  421. return;
  422. // -----------------------------------
  423. // Interlacing Control
  424. // -----------------------------------
  425. case BPMEM_FIELDMASK: // GX_SetFieldMask(u8 even_mask,u8 odd_mask)
  426. case BPMEM_FIELDMODE: // GX_SetFieldMode(u8 field_mode,u8 half_aspect_ratio)
  427. // TODO
  428. return;
  429. // ----------------------------------------
  430. // Unimportant regs (Clock, Perf, ...)
  431. // ----------------------------------------
  432. case BPMEM_BUSCLOCK0: // TB Bus Clock ?
  433. case BPMEM_BUSCLOCK1: // TB Bus Clock ?
  434. case BPMEM_PERF0_TRI: // Perf: Triangles
  435. case BPMEM_PERF0_QUAD: // Perf: Quads
  436. case BPMEM_PERF1: // Perf: Some Clock, Texels, TX, TC
  437. return;
  438. // ----------------
  439. // EFB Copy config
  440. // ----------------
  441. case BPMEM_EFB_TL: // EFB Source Rect. Top, Left
  442. case BPMEM_EFB_WH: // EFB Source Rect. Width, Height - 1
  443. case BPMEM_EFB_ADDR: // EFB Target Address
  444. return;
  445. // --------------
  446. // Clear Config
  447. // --------------
  448. case BPMEM_CLEAR_AR: // Alpha and Red Components
  449. case BPMEM_CLEAR_GB: // Green and Blue Components
  450. case BPMEM_CLEAR_Z: // Z Components (24-bit Zbuffer)
  451. return;
  452. // -------------------------
  453. // Bounding Box Control
  454. // -------------------------
  455. case BPMEM_CLEARBBOX1:
  456. case BPMEM_CLEARBBOX2:
  457. {
  458. const u8 offset = bp.address & 2;
  459. g_bounding_box->Enable(pixel_shader_manager);
  460. g_bounding_box->Set(offset, bp.newvalue & 0x3ff);
  461. g_bounding_box->Set(offset + 1, bp.newvalue >> 10);
  462. }
  463. return;
  464. case BPMEM_TEXINVALIDATE:
  465. TMEM::Invalidate(bp.newvalue);
  466. return;
  467. case BPMEM_ZCOMPARE: // Set the Z-Compare and EFB pixel format
  468. OnPixelFormatChange();
  469. if (bp.changes & 7)
  470. SetBlendMode(); // dual source could be activated by changing to PIXELFMT_RGBA6_Z24
  471. pixel_shader_manager.SetZModeControl();
  472. return;
  473. case BPMEM_EFB_STRIDE: // Display Copy Stride
  474. case BPMEM_COPYYSCALE: // Display Copy Y Scale
  475. return;
  476. /* 24 RID
  477. * 21 BC3 - Ind. Tex Stage 3 NTexCoord
  478. * 18 BI3 - Ind. Tex Stage 3 NTexMap
  479. * 15 BC2 - Ind. Tex Stage 2 NTexCoord
  480. * 12 BI2 - Ind. Tex Stage 2 NTexMap
  481. * 9 BC1 - Ind. Tex Stage 1 NTexCoord
  482. * 6 BI1 - Ind. Tex Stage 1 NTexMap
  483. * 3 BC0 - Ind. Tex Stage 0 NTexCoord
  484. * 0 BI0 - Ind. Tex Stage 0 NTexMap */
  485. case BPMEM_IREF:
  486. {
  487. if (bp.changes)
  488. pixel_shader_manager.SetTevIndirectChanged();
  489. return;
  490. }
  491. case BPMEM_TEV_KSEL: // Texture Environment Swap Mode Table 0
  492. case BPMEM_TEV_KSEL + 1: // Texture Environment Swap Mode Table 1
  493. case BPMEM_TEV_KSEL + 2: // Texture Environment Swap Mode Table 2
  494. case BPMEM_TEV_KSEL + 3: // Texture Environment Swap Mode Table 3
  495. case BPMEM_TEV_KSEL + 4: // Texture Environment Swap Mode Table 4
  496. case BPMEM_TEV_KSEL + 5: // Texture Environment Swap Mode Table 5
  497. case BPMEM_TEV_KSEL + 6: // Texture Environment Swap Mode Table 6
  498. case BPMEM_TEV_KSEL + 7: // Texture Environment Swap Mode Table 7
  499. pixel_shader_manager.SetTevKSel(bp.address - BPMEM_TEV_KSEL, bp.newvalue);
  500. return;
  501. /* This Register can be used to limit to which bits of BP registers is
  502. * actually written to. The mask is only valid for the next BP write,
  503. * and will reset itself afterwards. It's handled as a special case in
  504. * LoadBPReg. */
  505. case BPMEM_BP_MASK:
  506. case BPMEM_IND_IMASK: // Index Mask ?
  507. case BPMEM_REVBITS: // Always set to 0x0F when GX_InitRevBits() is called.
  508. return;
  509. case BPMEM_CLEAR_PIXEL_PERF:
  510. // GXClearPixMetric writes 0xAAA here, Sunshine alternates this register between values 0x000
  511. // and 0xAAA
  512. if (PerfQueryBase::ShouldEmulate())
  513. g_perf_query->ResetQuery();
  514. return;
  515. case BPMEM_PRELOAD_ADDR:
  516. case BPMEM_PRELOAD_TMEMEVEN:
  517. case BPMEM_PRELOAD_TMEMODD: // Used when PRELOAD_MODE is set
  518. return;
  519. case BPMEM_PRELOAD_MODE: // Set to 0 when GX_TexModeSync() is called.
  520. // if this is different from 0, manual TMEM management is used (GX_PreloadEntireTexture).
  521. if (bp.newvalue != 0)
  522. {
  523. // TODO: Not quite sure if this is completely correct (likely not)
  524. // NOTE: libogc's implementation of GX_PreloadEntireTexture seems flawed, so it's not
  525. // necessarily a good reference for RE'ing this feature.
  526. BPS_TmemConfig& tmem_cfg = bpmem.tmem_config;
  527. u32 src_addr = tmem_cfg.preload_addr << 5; // TODO: Should we add mask here on GC?
  528. u32 bytes_read = 0;
  529. u32 tmem_addr_even = tmem_cfg.preload_tmem_even * TMEM_LINE_SIZE;
  530. if (tmem_cfg.preload_tile_info.type != 3)
  531. {
  532. if (tmem_addr_even < TMEM_SIZE)
  533. {
  534. bytes_read = tmem_cfg.preload_tile_info.count * TMEM_LINE_SIZE;
  535. if (tmem_addr_even + bytes_read > TMEM_SIZE)
  536. bytes_read = TMEM_SIZE - tmem_addr_even;
  537. auto& system = Core::System::GetInstance();
  538. auto& memory = system.GetMemory();
  539. memory.CopyFromEmu(s_tex_mem.data() + tmem_addr_even, src_addr, bytes_read);
  540. }
  541. }
  542. else // RGBA8 tiles (and CI14, but that might just be stupid libogc!)
  543. {
  544. auto& system = Core::System::GetInstance();
  545. auto& memory = system.GetMemory();
  546. // AR and GB tiles are stored in separate TMEM banks => can't use a single memcpy for
  547. // everything
  548. u32 tmem_addr_odd = tmem_cfg.preload_tmem_odd * TMEM_LINE_SIZE;
  549. for (u32 i = 0; i < tmem_cfg.preload_tile_info.count; ++i)
  550. {
  551. if (tmem_addr_even + TMEM_LINE_SIZE > TMEM_SIZE ||
  552. tmem_addr_odd + TMEM_LINE_SIZE > TMEM_SIZE)
  553. {
  554. break;
  555. }
  556. memory.CopyFromEmu(s_tex_mem.data() + tmem_addr_even, src_addr + bytes_read,
  557. TMEM_LINE_SIZE);
  558. memory.CopyFromEmu(s_tex_mem.data() + tmem_addr_odd,
  559. src_addr + bytes_read + TMEM_LINE_SIZE, TMEM_LINE_SIZE);
  560. tmem_addr_even += TMEM_LINE_SIZE;
  561. tmem_addr_odd += TMEM_LINE_SIZE;
  562. bytes_read += TMEM_LINE_SIZE * 2;
  563. }
  564. }
  565. if (OpcodeDecoder::g_record_fifo_data)
  566. {
  567. Core::System::GetInstance().GetFifoRecorder().UseMemory(src_addr, bytes_read,
  568. MemoryUpdate::Type::TMEM);
  569. }
  570. TMEM::InvalidateAll();
  571. }
  572. return;
  573. // ---------------------------------------------------
  574. // Set the TEV Color
  575. // ---------------------------------------------------
  576. //
  577. // NOTE: Each of these registers actually maps to two variables internally.
  578. // There's a bit that specifies which one is currently written to.
  579. //
  580. // NOTE: Some games write only to the RA register (or only to the BG register).
  581. // We may not assume that the unwritten register holds a valid value, hence
  582. // both component pairs need to be loaded individually.
  583. case BPMEM_TEV_COLOR_RA:
  584. case BPMEM_TEV_COLOR_RA + 2:
  585. case BPMEM_TEV_COLOR_RA + 4:
  586. case BPMEM_TEV_COLOR_RA + 6:
  587. {
  588. int num = (bp.address >> 1) & 0x3;
  589. if (bpmem.tevregs[num].ra.type == TevRegType::Constant)
  590. {
  591. pixel_shader_manager.SetTevKonstColor(num, 0, bpmem.tevregs[num].ra.red);
  592. pixel_shader_manager.SetTevKonstColor(num, 3, bpmem.tevregs[num].ra.alpha);
  593. }
  594. else
  595. {
  596. pixel_shader_manager.SetTevColor(num, 0, bpmem.tevregs[num].ra.red);
  597. pixel_shader_manager.SetTevColor(num, 3, bpmem.tevregs[num].ra.alpha);
  598. }
  599. return;
  600. }
  601. case BPMEM_TEV_COLOR_BG:
  602. case BPMEM_TEV_COLOR_BG + 2:
  603. case BPMEM_TEV_COLOR_BG + 4:
  604. case BPMEM_TEV_COLOR_BG + 6:
  605. {
  606. int num = (bp.address >> 1) & 0x3;
  607. if (bpmem.tevregs[num].bg.type == TevRegType::Constant)
  608. {
  609. pixel_shader_manager.SetTevKonstColor(num, 1, bpmem.tevregs[num].bg.green);
  610. pixel_shader_manager.SetTevKonstColor(num, 2, bpmem.tevregs[num].bg.blue);
  611. }
  612. else
  613. {
  614. pixel_shader_manager.SetTevColor(num, 1, bpmem.tevregs[num].bg.green);
  615. pixel_shader_manager.SetTevColor(num, 2, bpmem.tevregs[num].bg.blue);
  616. }
  617. return;
  618. }
  619. default:
  620. break;
  621. }
  622. switch (bp.address & 0xFC) // Texture sampler filter
  623. {
  624. // -------------------------
  625. // Texture Environment Order
  626. // -------------------------
  627. case BPMEM_TREF:
  628. case BPMEM_TREF + 4:
  629. pixel_shader_manager.SetTevOrder(bp.address - BPMEM_TREF, bp.newvalue);
  630. return;
  631. // ----------------------
  632. // Set wrap size
  633. // ----------------------
  634. case BPMEM_SU_SSIZE: // Matches BPMEM_SU_TSIZE too
  635. case BPMEM_SU_SSIZE + 4:
  636. case BPMEM_SU_SSIZE + 8:
  637. case BPMEM_SU_SSIZE + 12:
  638. if (bp.changes)
  639. {
  640. pixel_shader_manager.SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
  641. geometry_shader_manager.SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
  642. }
  643. return;
  644. }
  645. if ((bp.address & 0xc0) == 0x80)
  646. {
  647. auto tex_address = TexUnitAddress::FromBPAddress(bp.address);
  648. switch (tex_address.Reg)
  649. {
  650. // ------------------------
  651. // BPMEM_TX_SETMODE0 - (Texture lookup and filtering mode) LOD/BIAS Clamp, MaxAnsio, LODBIAS,
  652. // DiagLoad, Min Filter, Mag Filter, Wrap T, S
  653. // BPMEM_TX_SETMODE1 - (LOD Stuff) - Max LOD, Min LOD
  654. // ------------------------
  655. case TexUnitAddress::Register::SETMODE0:
  656. case TexUnitAddress::Register::SETMODE1:
  657. TMEM::ConfigurationChanged(tex_address, bp.newvalue);
  658. return;
  659. // --------------------------------------------
  660. // BPMEM_TX_SETIMAGE0 - Texture width, height, format
  661. // BPMEM_TX_SETIMAGE1 - even LOD address in TMEM - Image Type, Cache Height, Cache Width,
  662. // TMEM Offset
  663. // BPMEM_TX_SETIMAGE2 - odd LOD address in TMEM - Cache Height, Cache Width, TMEM Offset
  664. // BPMEM_TX_SETIMAGE3 - Address of Texture in main memory
  665. // --------------------------------------------
  666. case TexUnitAddress::Register::SETIMAGE0:
  667. case TexUnitAddress::Register::SETIMAGE1:
  668. case TexUnitAddress::Register::SETIMAGE2:
  669. case TexUnitAddress::Register::SETIMAGE3:
  670. TMEM::ConfigurationChanged(tex_address, bp.newvalue);
  671. return;
  672. // -------------------------------
  673. // Set a TLUT
  674. // BPMEM_TX_SETTLUT - Format, TMEM Offset (offset of TLUT from start of TMEM high bank > > 5)
  675. // -------------------------------
  676. case TexUnitAddress::Register::SETTLUT:
  677. TMEM::ConfigurationChanged(tex_address, bp.newvalue);
  678. return;
  679. case TexUnitAddress::Register::UNKNOWN:
  680. break; // Not handled
  681. }
  682. }
  683. switch (bp.address & 0xF0)
  684. {
  685. // --------------
  686. // Indirect Tev
  687. // --------------
  688. case BPMEM_IND_CMD:
  689. pixel_shader_manager.SetTevIndirectChanged();
  690. return;
  691. // --------------------------------------------------
  692. // Set Color/Alpha of a Tev
  693. // BPMEM_TEV_COLOR_ENV - Dest, Shift, Clamp, Sub, Bias, Sel A, Sel B, Sel C, Sel D
  694. // BPMEM_TEV_ALPHA_ENV - Dest, Shift, Clamp, Sub, Bias, Sel A, Sel B, Sel C, Sel D, T Swap, R Swap
  695. // --------------------------------------------------
  696. case BPMEM_TEV_COLOR_ENV: // Texture Environment 1
  697. case BPMEM_TEV_COLOR_ENV + 16:
  698. pixel_shader_manager.SetTevCombiner((bp.address - BPMEM_TEV_COLOR_ENV) >> 1,
  699. (bp.address - BPMEM_TEV_COLOR_ENV) & 1, bp.newvalue);
  700. return;
  701. default:
  702. break;
  703. }
  704. DolphinAnalytics::Instance().ReportGameQuirk(GameQuirk::USES_UNKNOWN_BP_COMMAND);
  705. WARN_LOG_FMT(VIDEO, "Unknown BP opcode: address = {:#010x} value = {:#010x}", bp.address,
  706. bp.newvalue);
  707. }
  708. // Call browser: OpcodeDecoding.cpp RunCallback::OnBP()
  709. void LoadBPReg(u8 reg, u32 value, int cycles_into_future)
  710. {
  711. auto& system = Core::System::GetInstance();
  712. int oldval = ((u32*)&bpmem)[reg];
  713. int newval = (oldval & ~bpmem.bpMask) | (value & bpmem.bpMask);
  714. int changes = (oldval ^ newval) & 0xFFFFFF;
  715. BPCmd bp = {reg, changes, newval};
  716. // Reset the mask register if we're not trying to set it ourselves.
  717. if (reg != BPMEM_BP_MASK)
  718. bpmem.bpMask = 0xFFFFFF;
  719. BPWritten(system.GetPixelShaderManager(), system.GetXFStateManager(),
  720. system.GetGeometryShaderManager(), bp, cycles_into_future);
  721. }
  722. void LoadBPRegPreprocess(u8 reg, u32 value, int cycles_into_future)
  723. {
  724. auto& system = Core::System::GetInstance();
  725. // masking via BPMEM_BP_MASK could hypothetically be a problem
  726. u32 newval = value & 0xffffff;
  727. switch (reg)
  728. {
  729. case BPMEM_SETDRAWDONE:
  730. if ((newval & 0xff) == 0x02)
  731. system.GetPixelEngine().SetFinish(cycles_into_future);
  732. break;
  733. case BPMEM_PE_TOKEN_ID:
  734. system.GetPixelEngine().SetToken(newval & 0xffff, false, cycles_into_future);
  735. break;
  736. case BPMEM_PE_TOKEN_INT_ID: // Pixel Engine Interrupt Token ID
  737. system.GetPixelEngine().SetToken(newval & 0xffff, true, cycles_into_future);
  738. break;
  739. }
  740. }
  741. std::pair<std::string, std::string> GetBPRegInfo(u8 cmd, u32 cmddata)
  742. {
  743. // Macro to set the register name and make sure it was written correctly via compile time assertion
  744. #define RegName(reg) ((void)(reg), #reg)
  745. #define DescriptionlessReg(reg) std::make_pair(RegName(reg), "");
  746. switch (cmd)
  747. {
  748. case BPMEM_GENMODE: // 0x00
  749. return std::make_pair(RegName(BPMEM_GENMODE), fmt::to_string(GenMode{.hex = cmddata}));
  750. case BPMEM_DISPLAYCOPYFILTER: // 0x01
  751. case BPMEM_DISPLAYCOPYFILTER + 1:
  752. case BPMEM_DISPLAYCOPYFILTER + 2:
  753. case BPMEM_DISPLAYCOPYFILTER + 3:
  754. // TODO: This is actually the sample pattern used for copies from an antialiased EFB
  755. return DescriptionlessReg(BPMEM_DISPLAYCOPYFILTER);
  756. // TODO: Description
  757. case BPMEM_IND_MTXA: // 0x06
  758. case BPMEM_IND_MTXA + 3:
  759. case BPMEM_IND_MTXA + 6:
  760. return std::make_pair(fmt::format("BPMEM_IND_MTXA Matrix {}", (cmd - BPMEM_IND_MTXA) / 3),
  761. fmt::format("Matrix {} column A\n{}", (cmd - BPMEM_IND_MTXA) / 3,
  762. IND_MTXA{.hex = cmddata}));
  763. case BPMEM_IND_MTXB: // 0x07
  764. case BPMEM_IND_MTXB + 3:
  765. case BPMEM_IND_MTXB + 6:
  766. return std::make_pair(fmt::format("BPMEM_IND_MTXB Matrix {}", (cmd - BPMEM_IND_MTXB) / 3),
  767. fmt::format("Matrix {} column B\n{}", (cmd - BPMEM_IND_MTXB) / 3,
  768. IND_MTXB{.hex = cmddata}));
  769. case BPMEM_IND_MTXC: // 0x08
  770. case BPMEM_IND_MTXC + 3:
  771. case BPMEM_IND_MTXC + 6:
  772. return std::make_pair(fmt::format("BPMEM_IND_MTXC Matrix {}", (cmd - BPMEM_IND_MTXC) / 3),
  773. fmt::format("Matrix {} column C\n{}", (cmd - BPMEM_IND_MTXC) / 3,
  774. IND_MTXC{.hex = cmddata}));
  775. case BPMEM_IND_IMASK: // 0x0F
  776. return DescriptionlessReg(BPMEM_IND_IMASK);
  777. // TODO: Description
  778. case BPMEM_IND_CMD: // 0x10
  779. case BPMEM_IND_CMD + 1:
  780. case BPMEM_IND_CMD + 2:
  781. case BPMEM_IND_CMD + 3:
  782. case BPMEM_IND_CMD + 4:
  783. case BPMEM_IND_CMD + 5:
  784. case BPMEM_IND_CMD + 6:
  785. case BPMEM_IND_CMD + 7:
  786. case BPMEM_IND_CMD + 8:
  787. case BPMEM_IND_CMD + 9:
  788. case BPMEM_IND_CMD + 10:
  789. case BPMEM_IND_CMD + 11:
  790. case BPMEM_IND_CMD + 12:
  791. case BPMEM_IND_CMD + 13:
  792. case BPMEM_IND_CMD + 14:
  793. case BPMEM_IND_CMD + 15:
  794. return std::make_pair(fmt::format("BPMEM_IND_CMD number {}", cmd - BPMEM_IND_CMD),
  795. fmt::to_string(TevStageIndirect{.fullhex = cmddata}));
  796. case BPMEM_SCISSORTL: // 0x20
  797. return std::make_pair(RegName(BPMEM_SCISSORTL), fmt::to_string(ScissorPos{.hex = cmddata}));
  798. case BPMEM_SCISSORBR: // 0x21
  799. return std::make_pair(RegName(BPMEM_SCISSORBR), fmt::to_string(ScissorPos{.hex = cmddata}));
  800. case BPMEM_LINEPTWIDTH: // 0x22
  801. return std::make_pair(RegName(BPMEM_LINEPTWIDTH), fmt::to_string(LPSize{.hex = cmddata}));
  802. case BPMEM_PERF0_TRI: // 0x23
  803. return DescriptionlessReg(BPMEM_PERF0_TRI);
  804. // TODO: Description
  805. case BPMEM_PERF0_QUAD: // 0x24
  806. return DescriptionlessReg(BPMEM_PERF0_QUAD);
  807. // TODO: Description
  808. case BPMEM_RAS1_SS0: // 0x25
  809. return std::make_pair(RegName(BPMEM_RAS1_SS0),
  810. fmt::to_string(std::make_pair(cmd, TEXSCALE{.hex = cmddata})));
  811. case BPMEM_RAS1_SS1: // 0x26
  812. return std::make_pair(RegName(BPMEM_RAS1_SS1),
  813. fmt::to_string(std::make_pair(cmd, TEXSCALE{.hex = cmddata})));
  814. case BPMEM_IREF: // 0x27
  815. return std::make_pair(RegName(BPMEM_IREF), fmt::to_string(RAS1_IREF{.hex = cmddata}));
  816. case BPMEM_TREF: // 0x28
  817. case BPMEM_TREF + 1:
  818. case BPMEM_TREF + 2:
  819. case BPMEM_TREF + 3:
  820. case BPMEM_TREF + 4:
  821. case BPMEM_TREF + 5:
  822. case BPMEM_TREF + 6:
  823. case BPMEM_TREF + 7:
  824. return std::make_pair(fmt::format("BPMEM_TREF number {}", cmd - BPMEM_TREF),
  825. fmt::to_string(std::make_pair(cmd, TwoTevStageOrders{.hex = cmddata})));
  826. case BPMEM_SU_SSIZE: // 0x30
  827. case BPMEM_SU_SSIZE + 2:
  828. case BPMEM_SU_SSIZE + 4:
  829. case BPMEM_SU_SSIZE + 6:
  830. case BPMEM_SU_SSIZE + 8:
  831. case BPMEM_SU_SSIZE + 10:
  832. case BPMEM_SU_SSIZE + 12:
  833. case BPMEM_SU_SSIZE + 14:
  834. return std::make_pair(fmt::format("BPMEM_SU_SSIZE number {}", (cmd - BPMEM_SU_SSIZE) / 2),
  835. fmt::to_string(std::make_pair(true, TCInfo{.hex = cmddata})));
  836. case BPMEM_SU_TSIZE: // 0x31
  837. case BPMEM_SU_TSIZE + 2:
  838. case BPMEM_SU_TSIZE + 4:
  839. case BPMEM_SU_TSIZE + 6:
  840. case BPMEM_SU_TSIZE + 8:
  841. case BPMEM_SU_TSIZE + 10:
  842. case BPMEM_SU_TSIZE + 12:
  843. case BPMEM_SU_TSIZE + 14:
  844. return std::make_pair(fmt::format("BPMEM_SU_TSIZE number {}", (cmd - BPMEM_SU_TSIZE) / 2),
  845. fmt::to_string(std::make_pair(false, TCInfo{.hex = cmddata})));
  846. case BPMEM_ZMODE: // 0x40
  847. return std::make_pair(RegName(BPMEM_ZMODE), fmt::format("Z mode: {}", ZMode{.hex = cmddata}));
  848. case BPMEM_BLENDMODE: // 0x41
  849. return std::make_pair(RegName(BPMEM_BLENDMODE), fmt::to_string(BlendMode{.hex = cmddata}));
  850. case BPMEM_CONSTANTALPHA: // 0x42
  851. return std::make_pair(RegName(BPMEM_CONSTANTALPHA),
  852. fmt::to_string(ConstantAlpha{.hex = cmddata}));
  853. case BPMEM_ZCOMPARE: // 0x43
  854. return std::make_pair(RegName(BPMEM_ZCOMPARE), fmt::to_string(PEControl{.hex = cmddata}));
  855. case BPMEM_FIELDMASK: // 0x44
  856. return std::make_pair(RegName(BPMEM_FIELDMASK), fmt::to_string(FieldMask{.hex = cmddata}));
  857. case BPMEM_SETDRAWDONE: // 0x45
  858. return DescriptionlessReg(BPMEM_SETDRAWDONE);
  859. // TODO: Description
  860. case BPMEM_BUSCLOCK0: // 0x46
  861. return DescriptionlessReg(BPMEM_BUSCLOCK0);
  862. // TODO: Description
  863. case BPMEM_PE_TOKEN_ID: // 0x47
  864. return DescriptionlessReg(BPMEM_PE_TOKEN_ID);
  865. // TODO: Description
  866. case BPMEM_PE_TOKEN_INT_ID: // 0x48
  867. return DescriptionlessReg(BPMEM_PE_TOKEN_INT_ID);
  868. // TODO: Description
  869. case BPMEM_EFB_TL: // 0x49
  870. {
  871. const X10Y10 left_top{.hex = cmddata};
  872. return std::make_pair(RegName(BPMEM_EFB_TL),
  873. fmt::format("EFB Left: {}\nEFB Top: {}", left_top.x, left_top.y));
  874. }
  875. case BPMEM_EFB_WH: // 0x4A
  876. {
  877. const X10Y10 width_height{.hex = cmddata};
  878. return std::make_pair(
  879. RegName(BPMEM_EFB_WH),
  880. fmt::format("EFB Width: {}\nEFB Height: {}", width_height.x + 1, width_height.y + 1));
  881. }
  882. case BPMEM_EFB_ADDR: // 0x4B
  883. return std::make_pair(
  884. RegName(BPMEM_EFB_ADDR),
  885. fmt::format("EFB Target address (32 byte aligned): 0x{:06X}", cmddata << 5));
  886. case BPMEM_EFB_STRIDE: // 0x4D
  887. return std::make_pair(
  888. RegName(BPMEM_EFB_STRIDE),
  889. fmt::format("EFB destination stride (32 byte aligned): 0x{:06X}", cmddata << 5));
  890. case BPMEM_COPYYSCALE: // 0x4E
  891. return std::make_pair(
  892. RegName(BPMEM_COPYYSCALE),
  893. fmt::format("Y scaling factor (XFB copy only): 0x{:X} ({}, reciprocal {})", cmddata,
  894. static_cast<float>(cmddata) / 256.f, 256.f / static_cast<float>(cmddata)));
  895. case BPMEM_CLEAR_AR: // 0x4F
  896. return std::make_pair(RegName(BPMEM_CLEAR_AR),
  897. fmt::format("Clear color alpha: 0x{:02X}\nClear color red: 0x{:02X}",
  898. (cmddata & 0xFF00) >> 8, cmddata & 0xFF));
  899. case BPMEM_CLEAR_GB: // 0x50
  900. return std::make_pair(RegName(BPMEM_CLEAR_GB),
  901. fmt::format("Clear color green: 0x{:02X}\nClear color blue: 0x{:02X}",
  902. (cmddata & 0xFF00) >> 8, cmddata & 0xFF));
  903. case BPMEM_CLEAR_Z: // 0x51
  904. return std::make_pair(RegName(BPMEM_CLEAR_Z), fmt::format("Clear Z value: 0x{:06X}", cmddata));
  905. case BPMEM_TRIGGER_EFB_COPY: // 0x52
  906. return std::make_pair(RegName(BPMEM_TRIGGER_EFB_COPY),
  907. fmt::to_string(UPE_Copy{.Hex = cmddata}));
  908. case BPMEM_COPYFILTER0: // 0x53
  909. {
  910. const u32 w0 = (cmddata & 0x00003f);
  911. const u32 w1 = (cmddata & 0x000fc0) >> 6;
  912. const u32 w2 = (cmddata & 0x03f000) >> 12;
  913. const u32 w3 = (cmddata & 0xfc0000) >> 18;
  914. return std::make_pair(RegName(BPMEM_COPYFILTER0),
  915. fmt::format("w0: {}\nw1: {}\nw2: {}\nw3: {}", w0, w1, w2, w3));
  916. }
  917. case BPMEM_COPYFILTER1: // 0x54
  918. {
  919. const u32 w4 = (cmddata & 0x00003f);
  920. const u32 w5 = (cmddata & 0x000fc0) >> 6;
  921. const u32 w6 = (cmddata & 0x03f000) >> 12;
  922. // There is no w7
  923. return std::make_pair(RegName(BPMEM_COPYFILTER1),
  924. fmt::format("w4: {}\nw5: {}\nw6: {}", w4, w5, w6));
  925. }
  926. case BPMEM_CLEARBBOX1: // 0x55
  927. return std::make_pair(RegName(BPMEM_CLEARBBOX1),
  928. fmt::format("Bounding Box index 0: {}\nBounding Box index 1: {}",
  929. cmddata & 0x3ff, (cmddata >> 10) & 0x3ff));
  930. case BPMEM_CLEARBBOX2: // 0x56
  931. return std::make_pair(RegName(BPMEM_CLEARBBOX2),
  932. fmt::format("Bounding Box index 2: {}\nBounding Box index 3: {}",
  933. cmddata & 0x3ff, (cmddata >> 10) & 0x3ff));
  934. case BPMEM_CLEAR_PIXEL_PERF: // 0x57
  935. return DescriptionlessReg(BPMEM_CLEAR_PIXEL_PERF);
  936. // TODO: Description
  937. case BPMEM_REVBITS: // 0x58
  938. return DescriptionlessReg(BPMEM_REVBITS);
  939. // TODO: Description
  940. case BPMEM_SCISSOROFFSET: // 0x59
  941. return std::make_pair(RegName(BPMEM_SCISSOROFFSET),
  942. fmt::to_string(ScissorOffset{.hex = cmddata}));
  943. case BPMEM_PRELOAD_ADDR: // 0x60
  944. return std::make_pair(
  945. RegName(BPMEM_PRELOAD_ADDR),
  946. fmt::format("Tmem preload address (32 byte aligned, in main memory): 0x{:06x}",
  947. cmddata << 5));
  948. case BPMEM_PRELOAD_TMEMEVEN: // 0x61
  949. return std::make_pair(RegName(BPMEM_PRELOAD_TMEMEVEN),
  950. fmt::format("Tmem preload even line: 0x{:04x} (byte 0x{:05x})", cmddata,
  951. cmddata * TMEM_LINE_SIZE));
  952. case BPMEM_PRELOAD_TMEMODD: // 0x62
  953. return std::make_pair(RegName(BPMEM_PRELOAD_TMEMODD),
  954. fmt::format("Tmem preload odd line: 0x{:04x} (byte 0x{:05x})", cmddata,
  955. cmddata * TMEM_LINE_SIZE));
  956. case BPMEM_PRELOAD_MODE: // 0x63
  957. return std::make_pair(RegName(BPMEM_PRELOAD_MODE),
  958. fmt::to_string(BPU_PreloadTileInfo{.hex = cmddata}));
  959. case BPMEM_LOADTLUT0: // 0x64
  960. return std::make_pair(
  961. RegName(BPMEM_LOADTLUT0),
  962. fmt::format("TLUT load address (32 byte aligned, in main memory): 0x{:06x}", cmddata << 5));
  963. case BPMEM_LOADTLUT1: // 0x65
  964. return std::make_pair(RegName(BPMEM_LOADTLUT1),
  965. fmt::to_string(BPU_LoadTlutInfo{.hex = cmddata}));
  966. case BPMEM_TEXINVALIDATE: // 0x66
  967. return DescriptionlessReg(BPMEM_TEXINVALIDATE);
  968. // TODO: Description
  969. case BPMEM_PERF1: // 0x67
  970. return DescriptionlessReg(BPMEM_PERF1);
  971. // TODO: Description
  972. case BPMEM_FIELDMODE: // 0x68
  973. return std::make_pair(RegName(BPMEM_FIELDMODE), fmt::to_string(FieldMode{.hex = cmddata}));
  974. case BPMEM_BUSCLOCK1: // 0x69
  975. return DescriptionlessReg(BPMEM_BUSCLOCK1);
  976. // TODO: Description
  977. case BPMEM_TX_SETMODE0: // 0x80
  978. case BPMEM_TX_SETMODE0 + 1:
  979. case BPMEM_TX_SETMODE0 + 2:
  980. case BPMEM_TX_SETMODE0 + 3:
  981. return std::make_pair(fmt::format("BPMEM_TX_SETMODE0 Texture Unit {}", cmd - BPMEM_TX_SETMODE0),
  982. fmt::to_string(TexMode0{.hex = cmddata}));
  983. case BPMEM_TX_SETMODE1: // 0x84
  984. case BPMEM_TX_SETMODE1 + 1:
  985. case BPMEM_TX_SETMODE1 + 2:
  986. case BPMEM_TX_SETMODE1 + 3:
  987. return std::make_pair(fmt::format("BPMEM_TX_SETMODE1 Texture Unit {}", cmd - BPMEM_TX_SETMODE1),
  988. fmt::to_string(TexMode1{.hex = cmddata}));
  989. case BPMEM_TX_SETIMAGE0: // 0x88
  990. case BPMEM_TX_SETIMAGE0 + 1:
  991. case BPMEM_TX_SETIMAGE0 + 2:
  992. case BPMEM_TX_SETIMAGE0 + 3:
  993. return std::make_pair(
  994. fmt::format("BPMEM_TX_SETIMAGE0 Texture Unit {}", cmd - BPMEM_TX_SETIMAGE0),
  995. fmt::to_string(TexImage0{.hex = cmddata}));
  996. case BPMEM_TX_SETIMAGE1: // 0x8C
  997. case BPMEM_TX_SETIMAGE1 + 1:
  998. case BPMEM_TX_SETIMAGE1 + 2:
  999. case BPMEM_TX_SETIMAGE1 + 3:
  1000. return std::make_pair(
  1001. fmt::format("BPMEM_TX_SETIMAGE1 Texture Unit {}", cmd - BPMEM_TX_SETIMAGE1),
  1002. fmt::to_string(TexImage1{.hex = cmddata}));
  1003. case BPMEM_TX_SETIMAGE2: // 0x90
  1004. case BPMEM_TX_SETIMAGE2 + 1:
  1005. case BPMEM_TX_SETIMAGE2 + 2:
  1006. case BPMEM_TX_SETIMAGE2 + 3:
  1007. return std::make_pair(
  1008. fmt::format("BPMEM_TX_SETIMAGE2 Texture Unit {}", cmd - BPMEM_TX_SETIMAGE2),
  1009. fmt::to_string(TexImage2{.hex = cmddata}));
  1010. case BPMEM_TX_SETIMAGE3: // 0x94
  1011. case BPMEM_TX_SETIMAGE3 + 1:
  1012. case BPMEM_TX_SETIMAGE3 + 2:
  1013. case BPMEM_TX_SETIMAGE3 + 3:
  1014. return std::make_pair(
  1015. fmt::format("BPMEM_TX_SETIMAGE3 Texture Unit {}", cmd - BPMEM_TX_SETIMAGE3),
  1016. fmt::to_string(TexImage3{.hex = cmddata}));
  1017. case BPMEM_TX_SETTLUT: // 0x98
  1018. case BPMEM_TX_SETTLUT + 1:
  1019. case BPMEM_TX_SETTLUT + 2:
  1020. case BPMEM_TX_SETTLUT + 3:
  1021. return std::make_pair(fmt::format("BPMEM_TX_SETTLUT Texture Unit {}", cmd - BPMEM_TX_SETTLUT),
  1022. fmt::to_string(TexTLUT{.hex = cmddata}));
  1023. case BPMEM_TX_SETMODE0_4: // 0xA0
  1024. case BPMEM_TX_SETMODE0_4 + 1:
  1025. case BPMEM_TX_SETMODE0_4 + 2:
  1026. case BPMEM_TX_SETMODE0_4 + 3:
  1027. return std::make_pair(
  1028. fmt::format("BPMEM_TX_SETMODE0_4 Texture Unit {}", cmd - BPMEM_TX_SETMODE0_4 + 4),
  1029. fmt::to_string(TexMode0{.hex = cmddata}));
  1030. case BPMEM_TX_SETMODE1_4: // 0xA4
  1031. case BPMEM_TX_SETMODE1_4 + 1:
  1032. case BPMEM_TX_SETMODE1_4 + 2:
  1033. case BPMEM_TX_SETMODE1_4 + 3:
  1034. return std::make_pair(
  1035. fmt::format("BPMEM_TX_SETMODE1_4 Texture Unit {}", cmd - BPMEM_TX_SETMODE1_4 + 4),
  1036. fmt::to_string(TexMode1{.hex = cmddata}));
  1037. case BPMEM_TX_SETIMAGE0_4: // 0xA8
  1038. case BPMEM_TX_SETIMAGE0_4 + 1:
  1039. case BPMEM_TX_SETIMAGE0_4 + 2:
  1040. case BPMEM_TX_SETIMAGE0_4 + 3:
  1041. return std::make_pair(
  1042. fmt::format("BPMEM_TX_SETIMAGE0_4 Texture Unit {}", cmd - BPMEM_TX_SETIMAGE0_4 + 4),
  1043. fmt::to_string(TexImage0{.hex = cmddata}));
  1044. case BPMEM_TX_SETIMAGE1_4: // 0xAC
  1045. case BPMEM_TX_SETIMAGE1_4 + 1:
  1046. case BPMEM_TX_SETIMAGE1_4 + 2:
  1047. case BPMEM_TX_SETIMAGE1_4 + 3:
  1048. return std::make_pair(
  1049. fmt::format("BPMEM_TX_SETIMAGE1_4 Texture Unit {}", cmd - BPMEM_TX_SETIMAGE1_4 + 4),
  1050. fmt::to_string(TexImage1{.hex = cmddata}));
  1051. case BPMEM_TX_SETIMAGE2_4: // 0xB0
  1052. case BPMEM_TX_SETIMAGE2_4 + 1:
  1053. case BPMEM_TX_SETIMAGE2_4 + 2:
  1054. case BPMEM_TX_SETIMAGE2_4 + 3:
  1055. return std::make_pair(
  1056. fmt::format("BPMEM_TX_SETIMAGE2_4 Texture Unit {}", cmd - BPMEM_TX_SETIMAGE2_4 + 4),
  1057. fmt::to_string(TexImage2{.hex = cmddata}));
  1058. case BPMEM_TX_SETIMAGE3_4: // 0xB4
  1059. case BPMEM_TX_SETIMAGE3_4 + 1:
  1060. case BPMEM_TX_SETIMAGE3_4 + 2:
  1061. case BPMEM_TX_SETIMAGE3_4 + 3:
  1062. return std::make_pair(
  1063. fmt::format("BPMEM_TX_SETIMAGE3_4 Texture Unit {}", cmd - BPMEM_TX_SETIMAGE3_4 + 4),
  1064. fmt::to_string(TexImage3{.hex = cmddata}));
  1065. case BPMEM_TX_SETTLUT_4: // 0xB8
  1066. case BPMEM_TX_SETTLUT_4 + 1:
  1067. case BPMEM_TX_SETTLUT_4 + 2:
  1068. case BPMEM_TX_SETTLUT_4 + 3:
  1069. return std::make_pair(
  1070. fmt::format("BPMEM_TX_SETTLUT_4 Texture Unit {}", cmd - BPMEM_TX_SETTLUT_4 + 4),
  1071. fmt::to_string(TexTLUT{.hex = cmddata}));
  1072. case BPMEM_TEV_COLOR_ENV: // 0xC0
  1073. case BPMEM_TEV_COLOR_ENV + 2:
  1074. case BPMEM_TEV_COLOR_ENV + 4:
  1075. case BPMEM_TEV_COLOR_ENV + 6:
  1076. case BPMEM_TEV_COLOR_ENV + 8:
  1077. case BPMEM_TEV_COLOR_ENV + 10:
  1078. case BPMEM_TEV_COLOR_ENV + 12:
  1079. case BPMEM_TEV_COLOR_ENV + 14:
  1080. case BPMEM_TEV_COLOR_ENV + 16:
  1081. case BPMEM_TEV_COLOR_ENV + 18:
  1082. case BPMEM_TEV_COLOR_ENV + 20:
  1083. case BPMEM_TEV_COLOR_ENV + 22:
  1084. case BPMEM_TEV_COLOR_ENV + 24:
  1085. case BPMEM_TEV_COLOR_ENV + 26:
  1086. case BPMEM_TEV_COLOR_ENV + 28:
  1087. case BPMEM_TEV_COLOR_ENV + 30:
  1088. return std::make_pair(
  1089. fmt::format("BPMEM_TEV_COLOR_ENV Tev stage {}", (cmd - BPMEM_TEV_COLOR_ENV) / 2),
  1090. fmt::to_string(TevStageCombiner::ColorCombiner{.hex = cmddata}));
  1091. case BPMEM_TEV_ALPHA_ENV: // 0xC1
  1092. case BPMEM_TEV_ALPHA_ENV + 2:
  1093. case BPMEM_TEV_ALPHA_ENV + 4:
  1094. case BPMEM_TEV_ALPHA_ENV + 6:
  1095. case BPMEM_TEV_ALPHA_ENV + 8:
  1096. case BPMEM_TEV_ALPHA_ENV + 10:
  1097. case BPMEM_TEV_ALPHA_ENV + 12:
  1098. case BPMEM_TEV_ALPHA_ENV + 14:
  1099. case BPMEM_TEV_ALPHA_ENV + 16:
  1100. case BPMEM_TEV_ALPHA_ENV + 18:
  1101. case BPMEM_TEV_ALPHA_ENV + 20:
  1102. case BPMEM_TEV_ALPHA_ENV + 22:
  1103. case BPMEM_TEV_ALPHA_ENV + 24:
  1104. case BPMEM_TEV_ALPHA_ENV + 26:
  1105. case BPMEM_TEV_ALPHA_ENV + 28:
  1106. case BPMEM_TEV_ALPHA_ENV + 30:
  1107. return std::make_pair(
  1108. fmt::format("BPMEM_TEV_ALPHA_ENV Tev stage {}", (cmd - BPMEM_TEV_ALPHA_ENV) / 2),
  1109. fmt::to_string(TevStageCombiner::AlphaCombiner{.hex = cmddata}));
  1110. case BPMEM_TEV_COLOR_RA: // 0xE0
  1111. case BPMEM_TEV_COLOR_RA + 2: // 0xE2
  1112. case BPMEM_TEV_COLOR_RA + 4: // 0xE4
  1113. case BPMEM_TEV_COLOR_RA + 6: // 0xE6
  1114. return std::make_pair(
  1115. fmt::format("BPMEM_TEV_COLOR_RA Tev register {}", (cmd - BPMEM_TEV_COLOR_RA) / 2),
  1116. fmt::to_string(TevReg::RA{.hex = cmddata}));
  1117. case BPMEM_TEV_COLOR_BG: // 0xE1
  1118. case BPMEM_TEV_COLOR_BG + 2: // 0xE3
  1119. case BPMEM_TEV_COLOR_BG + 4: // 0xE5
  1120. case BPMEM_TEV_COLOR_BG + 6: // 0xE7
  1121. return std::make_pair(
  1122. fmt::format("BPMEM_TEV_COLOR_BG Tev register {}", (cmd - BPMEM_TEV_COLOR_BG) / 2),
  1123. fmt::to_string(TevReg::BG{.hex = cmddata}));
  1124. case BPMEM_FOGRANGE: // 0xE8
  1125. return std::make_pair("BPMEM_FOGRANGE Base",
  1126. fmt::to_string(FogRangeParams::RangeBase{.hex = cmddata}));
  1127. case BPMEM_FOGRANGE + 1:
  1128. case BPMEM_FOGRANGE + 2:
  1129. case BPMEM_FOGRANGE + 3:
  1130. case BPMEM_FOGRANGE + 4:
  1131. case BPMEM_FOGRANGE + 5:
  1132. return std::make_pair(fmt::format("BPMEM_FOGRANGE K element {}", cmd - BPMEM_FOGRANGE),
  1133. fmt::to_string(FogRangeKElement{.HEX = cmddata}));
  1134. case BPMEM_FOGPARAM0: // 0xEE
  1135. return std::make_pair(RegName(BPMEM_FOGPARAM0), fmt::to_string(FogParam0{.hex = cmddata}));
  1136. case BPMEM_FOGBMAGNITUDE: // 0xEF
  1137. return std::make_pair(RegName(BPMEM_FOGBMAGNITUDE), fmt::format("B magnitude: {}", cmddata));
  1138. case BPMEM_FOGBEXPONENT: // 0xF0
  1139. return std::make_pair(RegName(BPMEM_FOGBEXPONENT),
  1140. fmt::format("B shift: 1>>{} (1/{})", cmddata, 1 << cmddata));
  1141. case BPMEM_FOGPARAM3: // 0xF1
  1142. return std::make_pair(RegName(BPMEM_FOGPARAM3), fmt::to_string(FogParam3{.hex = cmddata}));
  1143. case BPMEM_FOGCOLOR: // 0xF2
  1144. return std::make_pair(RegName(BPMEM_FOGCOLOR),
  1145. fmt::to_string(FogParams::FogColor{.hex = cmddata}));
  1146. case BPMEM_ALPHACOMPARE: // 0xF3
  1147. return std::make_pair(RegName(BPMEM_ALPHACOMPARE), fmt::to_string(AlphaTest{.hex = cmddata}));
  1148. case BPMEM_BIAS: // 0xF4
  1149. return std::make_pair(RegName(BPMEM_BIAS), fmt::to_string(ZTex1{.hex = cmddata}));
  1150. case BPMEM_ZTEX2: // 0xF5
  1151. return std::make_pair(RegName(BPMEM_ZTEX2), fmt::to_string(ZTex2{.hex = cmddata}));
  1152. case BPMEM_TEV_KSEL: // 0xF6
  1153. case BPMEM_TEV_KSEL + 1:
  1154. case BPMEM_TEV_KSEL + 2:
  1155. case BPMEM_TEV_KSEL + 3:
  1156. case BPMEM_TEV_KSEL + 4:
  1157. case BPMEM_TEV_KSEL + 5:
  1158. case BPMEM_TEV_KSEL + 6:
  1159. case BPMEM_TEV_KSEL + 7:
  1160. return std::make_pair(fmt::format("BPMEM_TEV_KSEL number {}", cmd - BPMEM_TEV_KSEL),
  1161. fmt::to_string(std::make_pair(cmd, TevKSel{.hex = cmddata})));
  1162. case BPMEM_BP_MASK: // 0xFE
  1163. return std::make_pair(RegName(BPMEM_BP_MASK),
  1164. fmt::format("The next BP command will only update these bits; others "
  1165. "will retain their prior values: {:06x}",
  1166. cmddata));
  1167. default:
  1168. return std::make_pair(fmt::format("Unknown BP Reg: {:02x}={:06x}", cmd, cmddata), "");
  1169. #undef DescriptionlessReg
  1170. #undef RegName
  1171. }
  1172. }
  1173. // Called when loading a saved state.
  1174. void BPReload()
  1175. {
  1176. // restore anything that goes straight to the renderer.
  1177. // let's not risk actually replaying any writes.
  1178. // note that PixelShaderManager is already covered since it has its own DoState.
  1179. SetGenerationMode();
  1180. SetScissorAndViewport();
  1181. SetDepthMode();
  1182. SetBlendMode();
  1183. OnPixelFormatChange();
  1184. }