BPStructs.cpp 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. // Copyright 2009 Dolphin Emulator Project
  2. // Licensed under GPLv2+
  3. // Refer to the license.txt file included.
  4. #include <cmath>
  5. #include "Common/StringUtil.h"
  6. #include "Common/Thread.h"
  7. #include "Core/ConfigManager.h"
  8. #include "Core/Core.h"
  9. #include "Core/HW/Memmap.h"
  10. #include "VideoCommon/BoundingBox.h"
  11. #include "VideoCommon/BPFunctions.h"
  12. #include "VideoCommon/BPStructs.h"
  13. #include "VideoCommon/Fifo.h"
  14. #include "VideoCommon/GeometryShaderManager.h"
  15. #include "VideoCommon/PerfQueryBase.h"
  16. #include "VideoCommon/PixelEngine.h"
  17. #include "VideoCommon/PixelShaderManager.h"
  18. #include "VideoCommon/RenderBase.h"
  19. #include "VideoCommon/Statistics.h"
  20. #include "VideoCommon/TextureDecoder.h"
  21. #include "VideoCommon/VertexShaderManager.h"
  22. #include "VideoCommon/VideoCommon.h"
  23. #include "VideoCommon/VideoConfig.h"
  24. using namespace BPFunctions;
  25. static const float s_gammaLUT[] =
  26. {
  27. 1.0f,
  28. 1.7f,
  29. 2.2f,
  30. 1.0f
  31. };
  32. void BPInit()
  33. {
  34. memset(&bpmem, 0, sizeof(bpmem));
  35. bpmem.bpMask = 0xFFFFFF;
  36. }
  37. static void BPWritten(const BPCmd& bp)
  38. {
  39. /*
  40. ----------------------------------------------------------------------------------------------------------------
  41. Purpose: Writes to the BP registers
  42. Called: At the end of every: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg
  43. How It Works: First the pipeline is flushed then update the bpmem with the new value.
  44. Some of the BP cases have to call certain functions while others just update the bpmem.
  45. some bp cases check the changes variable, because they might not have to be updated all the time
  46. NOTE: it seems not all bp cases like checking changes, so calling if (bp.changes == 0 ? false : true)
  47. had to be ditched and the games seem to work fine with out it.
  48. NOTE2: Yet Another GameCube Documentation calls them Bypass Raster State Registers but possibly completely wrong
  49. NOTE3: This controls the register groups: RAS1/2, SU, TF, TEV, C/Z, PEC
  50. TODO: Turn into function table. The (future) DisplayList (DL) jit can then call the functions directly,
  51. getting rid of dynamic dispatch. Unfortunately, few games use DLs properly - most\
  52. just stuff geometry in them and don't put state changes there
  53. ----------------------------------------------------------------------------------------------------------------
  54. */
  55. // check for invalid state, else unneeded configuration are built
  56. g_video_backend->CheckInvalidState();
  57. if (((s32*)&bpmem)[bp.address] == bp.newvalue)
  58. {
  59. if (!(bp.address == BPMEM_TRIGGER_EFB_COPY ||
  60. bp.address == BPMEM_CLEARBBOX1 ||
  61. bp.address == BPMEM_CLEARBBOX2 ||
  62. bp.address == BPMEM_SETDRAWDONE ||
  63. bp.address == BPMEM_PE_TOKEN_ID ||
  64. bp.address == BPMEM_PE_TOKEN_INT_ID ||
  65. bp.address == BPMEM_LOADTLUT0 ||
  66. bp.address == BPMEM_LOADTLUT1 ||
  67. bp.address == BPMEM_TEXINVALIDATE ||
  68. bp.address == BPMEM_PRELOAD_MODE ||
  69. bp.address == BPMEM_CLEAR_PIXEL_PERF))
  70. {
  71. return;
  72. }
  73. }
  74. FlushPipeline();
  75. ((u32*)&bpmem)[bp.address] = bp.newvalue;
  76. switch (bp.address)
  77. {
  78. case BPMEM_GENMODE: // Set the Generation Mode
  79. PRIM_LOG("genmode: texgen=%d, col=%d, multisampling=%d, tev=%d, cullmode=%d, ind=%d, zfeeze=%d",
  80. (u32)bpmem.genMode.numtexgens, (u32)bpmem.genMode.numcolchans,
  81. (u32)bpmem.genMode.multisampling, (u32)bpmem.genMode.numtevstages+1, (u32)bpmem.genMode.cullmode,
  82. (u32)bpmem.genMode.numindstages, (u32)bpmem.genMode.zfreeze);
  83. // Only call SetGenerationMode when cull mode changes.
  84. if (bp.changes & 0xC000)
  85. SetGenerationMode();
  86. return;
  87. case BPMEM_IND_MTXA: // Index Matrix Changed
  88. case BPMEM_IND_MTXB:
  89. case BPMEM_IND_MTXC:
  90. case BPMEM_IND_MTXA+3:
  91. case BPMEM_IND_MTXB+3:
  92. case BPMEM_IND_MTXC+3:
  93. case BPMEM_IND_MTXA+6:
  94. case BPMEM_IND_MTXB+6:
  95. case BPMEM_IND_MTXC+6:
  96. if (bp.changes)
  97. PixelShaderManager::SetIndMatrixChanged((bp.address - BPMEM_IND_MTXA) / 3);
  98. return;
  99. case BPMEM_RAS1_SS0: // Index Texture Coordinate Scale 0
  100. if (bp.changes)
  101. PixelShaderManager::SetIndTexScaleChanged(false);
  102. return;
  103. case BPMEM_RAS1_SS1: // Index Texture Coordinate Scale 1
  104. if (bp.changes)
  105. PixelShaderManager::SetIndTexScaleChanged(true);
  106. return;
  107. // ----------------
  108. // Scissor Control
  109. // ----------------
  110. case BPMEM_SCISSORTL: // Scissor Rectable Top, Left
  111. case BPMEM_SCISSORBR: // Scissor Rectable Bottom, Right
  112. case BPMEM_SCISSOROFFSET: // Scissor Offset
  113. SetScissor();
  114. VertexShaderManager::SetViewportChanged();
  115. GeometryShaderManager::SetViewportChanged();
  116. return;
  117. case BPMEM_LINEPTWIDTH: // Line Width
  118. GeometryShaderManager::SetLinePtWidthChanged();
  119. return;
  120. case BPMEM_ZMODE: // Depth Control
  121. PRIM_LOG("zmode: test=%d, func=%d, upd=%d", (int)bpmem.zmode.testenable,
  122. (int)bpmem.zmode.func, (int)bpmem.zmode.updateenable);
  123. SetDepthMode();
  124. return;
  125. case BPMEM_BLENDMODE: // Blending Control
  126. if (bp.changes & 0xFFFF)
  127. {
  128. PRIM_LOG("blendmode: en=%d, open=%d, colupd=%d, alphaupd=%d, dst=%d, src=%d, sub=%d, mode=%d",
  129. (int)bpmem.blendmode.blendenable, (int)bpmem.blendmode.logicopenable, (int)bpmem.blendmode.colorupdate,
  130. (int)bpmem.blendmode.alphaupdate, (int)bpmem.blendmode.dstfactor, (int)bpmem.blendmode.srcfactor,
  131. (int)bpmem.blendmode.subtract, (int)bpmem.blendmode.logicmode);
  132. // Set LogicOp Blending Mode
  133. if (bp.changes & 0xF002) // logicopenable | logicmode
  134. SetLogicOpMode();
  135. // Set Dithering Mode
  136. if (bp.changes & 4) // dither
  137. SetDitherMode();
  138. // Set Blending Mode
  139. if (bp.changes & 0xFF1) // blendenable | alphaupdate | dstfactor | srcfactor | subtract
  140. SetBlendMode();
  141. // Set Color Mask
  142. if (bp.changes & 0x18) // colorupdate | alphaupdate
  143. SetColorMask();
  144. }
  145. return;
  146. case BPMEM_CONSTANTALPHA: // Set Destination Alpha
  147. PRIM_LOG("constalpha: alp=%d, en=%d", bpmem.dstalpha.alpha, bpmem.dstalpha.enable);
  148. if (bp.changes & 0xFF)
  149. PixelShaderManager::SetDestAlpha();
  150. if (bp.changes & 0x100)
  151. SetBlendMode();
  152. return;
  153. // This is called when the game is done drawing the new frame (eg: like in DX: Begin(); Draw(); End();)
  154. // Triggers an interrupt on the PPC side so that the game knows when the GPU has finished drawing.
  155. // Tokens are similar.
  156. case BPMEM_SETDRAWDONE:
  157. switch (bp.newvalue & 0xFF)
  158. {
  159. case 0x02:
  160. if (!g_use_deterministic_gpu_thread)
  161. PixelEngine::SetFinish(); // may generate interrupt
  162. DEBUG_LOG(VIDEO, "GXSetDrawDone SetPEFinish (value: 0x%02X)", (bp.newvalue & 0xFFFF));
  163. return;
  164. default:
  165. WARN_LOG(VIDEO, "GXSetDrawDone ??? (value 0x%02X)", (bp.newvalue & 0xFFFF));
  166. return;
  167. }
  168. return;
  169. case BPMEM_PE_TOKEN_ID: // Pixel Engine Token ID
  170. if (!g_use_deterministic_gpu_thread)
  171. PixelEngine::SetToken(static_cast<u16>(bp.newvalue & 0xFFFF), false);
  172. DEBUG_LOG(VIDEO, "SetPEToken 0x%04x", (bp.newvalue & 0xFFFF));
  173. return;
  174. case BPMEM_PE_TOKEN_INT_ID: // Pixel Engine Interrupt Token ID
  175. if (!g_use_deterministic_gpu_thread)
  176. PixelEngine::SetToken(static_cast<u16>(bp.newvalue & 0xFFFF), true);
  177. DEBUG_LOG(VIDEO, "SetPEToken + INT 0x%04x", (bp.newvalue & 0xFFFF));
  178. return;
  179. // ------------------------
  180. // EFB copy command. This copies a rectangle from the EFB to either RAM in a texture format or to XFB as YUYV.
  181. // It can also optionally clear the EFB while copying from it. To emulate this, we of course copy first and clear afterwards.
  182. case BPMEM_TRIGGER_EFB_COPY: // Copy EFB Region or Render to the XFB or Clear the screen.
  183. {
  184. // The bottom right is within the rectangle
  185. // The values in bpmem.copyTexSrcXY and bpmem.copyTexSrcWH are updated in case 0x49 and 0x4a in this function
  186. u32 destAddr = bpmem.copyTexDest << 5;
  187. EFBRectangle srcRect;
  188. srcRect.left = (int)bpmem.copyTexSrcXY.x;
  189. srcRect.top = (int)bpmem.copyTexSrcXY.y;
  190. // Here Width+1 like Height, otherwise some textures are corrupted already since the native resolution.
  191. // TODO: What's the behavior of out of bound access?
  192. srcRect.right = (int)(bpmem.copyTexSrcXY.x + bpmem.copyTexSrcWH.x + 1);
  193. srcRect.bottom = (int)(bpmem.copyTexSrcXY.y + bpmem.copyTexSrcWH.y + 1);
  194. UPE_Copy PE_copy = bpmem.triggerEFBCopy;
  195. // Check if we are to copy from the EFB or draw to the XFB
  196. if (PE_copy.copy_to_xfb == 0)
  197. {
  198. if (g_ActiveConfig.bShowEFBCopyRegions)
  199. stats.efb_regions.push_back(srcRect);
  200. CopyEFB(destAddr, srcRect,
  201. PE_copy.tp_realFormat(), bpmem.zcontrol.pixel_format,
  202. !!PE_copy.intensity_fmt, !!PE_copy.half_scale);
  203. }
  204. else
  205. {
  206. // We should be able to get away with deactivating the current bbox tracking
  207. // here. Not sure if there's a better spot to put this.
  208. // the number of lines copied is determined by the y scale * source efb height
  209. BoundingBox::active = false;
  210. float yScale;
  211. if (PE_copy.scale_invert)
  212. yScale = 256.0f / (float)bpmem.dispcopyyscale;
  213. else
  214. yScale = (float)bpmem.dispcopyyscale / 256.0f;
  215. float num_xfb_lines = ((bpmem.copyTexSrcWH.y + 1.0f) * yScale);
  216. u32 height = static_cast<u32>(num_xfb_lines);
  217. if (height > MAX_XFB_HEIGHT)
  218. {
  219. INFO_LOG(VIDEO, "Tried to scale EFB to too many XFB lines: %d (%f)",
  220. height, num_xfb_lines);
  221. height = MAX_XFB_HEIGHT;
  222. }
  223. u32 width = bpmem.copyMipMapStrideChannels << 4;
  224. Renderer::RenderToXFB(destAddr, srcRect, width, height, s_gammaLUT[PE_copy.gamma]);
  225. }
  226. // Clear the rectangular region after copying it.
  227. if (PE_copy.clear)
  228. {
  229. ClearScreen(srcRect);
  230. }
  231. return;
  232. }
  233. case BPMEM_LOADTLUT0: // This one updates bpmem.tlutXferSrc, no need to do anything here.
  234. return;
  235. case BPMEM_LOADTLUT1: // Load a Texture Look Up Table
  236. {
  237. u32 tlutTMemAddr = (bp.newvalue & 0x3FF) << 9;
  238. u32 tlutXferCount = (bp.newvalue & 0x1FFC00) >> 5;
  239. u32 addr = bpmem.tmem_config.tlut_src << 5;
  240. // The GameCube ignores the upper bits of this address. Some games (WW, MKDD) set them.
  241. if (!SConfig::GetInstance().m_LocalCoreStartupParameter.bWii)
  242. addr = addr & 0x01FFFFFF;
  243. Memory::CopyFromEmu(texMem + tlutTMemAddr, addr, tlutXferCount);
  244. return;
  245. }
  246. case BPMEM_FOGRANGE: // Fog Settings Control
  247. case BPMEM_FOGRANGE+1:
  248. case BPMEM_FOGRANGE+2:
  249. case BPMEM_FOGRANGE+3:
  250. case BPMEM_FOGRANGE+4:
  251. case BPMEM_FOGRANGE+5:
  252. if (bp.changes)
  253. PixelShaderManager::SetFogRangeAdjustChanged();
  254. return;
  255. case BPMEM_FOGPARAM0:
  256. case BPMEM_FOGBMAGNITUDE:
  257. case BPMEM_FOGBEXPONENT:
  258. case BPMEM_FOGPARAM3:
  259. if (bp.changes)
  260. PixelShaderManager::SetFogParamChanged();
  261. return;
  262. case BPMEM_FOGCOLOR: // Fog Color
  263. if (bp.changes)
  264. PixelShaderManager::SetFogColorChanged();
  265. return;
  266. case BPMEM_ALPHACOMPARE: // Compare Alpha Values
  267. PRIM_LOG("alphacmp: ref0=%d, ref1=%d, comp0=%d, comp1=%d, logic=%d",
  268. (int)bpmem.alpha_test.ref0, (int)bpmem.alpha_test.ref1,
  269. (int)bpmem.alpha_test.comp0, (int)bpmem.alpha_test.comp1,
  270. (int)bpmem.alpha_test.logic);
  271. if (bp.changes & 0xFFFF)
  272. PixelShaderManager::SetAlpha();
  273. if (bp.changes)
  274. g_renderer->SetColorMask();
  275. return;
  276. case BPMEM_BIAS: // BIAS
  277. PRIM_LOG("ztex bias=0x%x", bpmem.ztex1.bias);
  278. if (bp.changes)
  279. PixelShaderManager::SetZTextureBias();
  280. return;
  281. case BPMEM_ZTEX2: // Z Texture type
  282. {
  283. if (bp.changes & 3)
  284. PixelShaderManager::SetZTextureTypeChanged();
  285. #if defined(_DEBUG) || defined(DEBUGFAST)
  286. const char* pzop[] = {"DISABLE", "ADD", "REPLACE", "?"};
  287. const char* pztype[] = {"Z8", "Z16", "Z24", "?"};
  288. PRIM_LOG("ztex op=%s, type=%s", pzop[bpmem.ztex2.op], pztype[bpmem.ztex2.type]);
  289. #endif
  290. }
  291. return;
  292. // ----------------------------------
  293. // Display Copy Filtering Control - GX_SetCopyFilter(u8 aa,u8 sample_pattern[12][2],u8 vf,u8 vfilter[7])
  294. // Fields: Destination, Frame2Field, Gamma, Source
  295. // ----------------------------------
  296. case BPMEM_DISPLAYCOPYFILTER: // if (aa) { use sample_pattern } else { use 666666 }
  297. case BPMEM_DISPLAYCOPYFILTER+1: // if (aa) { use sample_pattern } else { use 666666 }
  298. case BPMEM_DISPLAYCOPYFILTER+2: // if (aa) { use sample_pattern } else { use 666666 }
  299. case BPMEM_DISPLAYCOPYFILTER+3: // if (aa) { use sample_pattern } else { use 666666 }
  300. case BPMEM_COPYFILTER0: // if (vf) { use vfilter } else { use 595000 }
  301. case BPMEM_COPYFILTER1: // if (vf) { use vfilter } else { use 000015 }
  302. return;
  303. // -----------------------------------
  304. // Interlacing Control
  305. // -----------------------------------
  306. case BPMEM_FIELDMASK: // GX_SetFieldMask(u8 even_mask,u8 odd_mask)
  307. case BPMEM_FIELDMODE: // GX_SetFieldMode(u8 field_mode,u8 half_aspect_ratio)
  308. // TODO
  309. return;
  310. // ----------------------------------------
  311. // Unimportant regs (Clock, Perf, ...)
  312. // ----------------------------------------
  313. case BPMEM_BUSCLOCK0: // TB Bus Clock ?
  314. case BPMEM_BUSCLOCK1: // TB Bus Clock ?
  315. case BPMEM_PERF0_TRI: // Perf: Triangles
  316. case BPMEM_PERF0_QUAD: // Perf: Quads
  317. case BPMEM_PERF1: // Perf: Some Clock, Texels, TX, TC
  318. break;
  319. // ----------------
  320. // EFB Copy config
  321. // ----------------
  322. case BPMEM_EFB_TL: // EFB Source Rect. Top, Left
  323. case BPMEM_EFB_BR: // EFB Source Rect. Bottom, Right (w, h - 1)
  324. case BPMEM_EFB_ADDR: // EFB Target Address
  325. return;
  326. // --------------
  327. // Clear Config
  328. // --------------
  329. case BPMEM_CLEAR_AR: // Alpha and Red Components
  330. case BPMEM_CLEAR_GB: // Green and Blue Components
  331. case BPMEM_CLEAR_Z: // Z Components (24-bit Zbuffer)
  332. return;
  333. // -------------------------
  334. // Bounding Box Control
  335. // -------------------------
  336. case BPMEM_CLEARBBOX1:
  337. case BPMEM_CLEARBBOX2:
  338. // Don't compute bounding box if this frame is being skipped!
  339. // Wrong but valid values are better than bogus values...
  340. if (!g_bSkipCurrentFrame)
  341. {
  342. u8 offset = bp.address & 2;
  343. BoundingBox::active = true;
  344. if (g_ActiveConfig.backend_info.bSupportsBBox && g_ActiveConfig.bBBoxEnable)
  345. {
  346. g_renderer->BBoxWrite(offset, bp.newvalue & 0x3ff);
  347. g_renderer->BBoxWrite(offset + 1, bp.newvalue >> 10);
  348. }
  349. }
  350. return;
  351. case BPMEM_TEXINVALIDATE:
  352. // TODO: Needs some restructuring in TextureCacheBase.
  353. return;
  354. case BPMEM_ZCOMPARE: // Set the Z-Compare and EFB pixel format
  355. OnPixelFormatChange();
  356. if (bp.changes & 7)
  357. {
  358. SetBlendMode(); // dual source could be activated by changing to PIXELFMT_RGBA6_Z24
  359. g_renderer->SetColorMask(); // alpha writing needs to be disabled if the new pixel format doesn't have an alpha channel
  360. }
  361. return;
  362. case BPMEM_MIPMAP_STRIDE: // MipMap Stride Channel
  363. case BPMEM_COPYYSCALE: // Display Copy Y Scale
  364. /* 24 RID
  365. * 21 BC3 - Ind. Tex Stage 3 NTexCoord
  366. * 18 BI3 - Ind. Tex Stage 3 NTexMap
  367. * 15 BC2 - Ind. Tex Stage 2 NTexCoord
  368. * 12 BI2 - Ind. Tex Stage 2 NTexMap
  369. * 9 BC1 - Ind. Tex Stage 1 NTexCoord
  370. * 6 BI1 - Ind. Tex Stage 1 NTexMap
  371. * 3 BC0 - Ind. Tex Stage 0 NTexCoord
  372. * 0 BI0 - Ind. Tex Stage 0 NTexMap */
  373. case BPMEM_IREF:
  374. case BPMEM_TEV_KSEL: // Texture Environment Swap Mode Table 0
  375. case BPMEM_TEV_KSEL+1: // Texture Environment Swap Mode Table 1
  376. case BPMEM_TEV_KSEL+2: // Texture Environment Swap Mode Table 2
  377. case BPMEM_TEV_KSEL+3: // Texture Environment Swap Mode Table 3
  378. case BPMEM_TEV_KSEL+4: // Texture Environment Swap Mode Table 4
  379. case BPMEM_TEV_KSEL+5: // Texture Environment Swap Mode Table 5
  380. case BPMEM_TEV_KSEL+6: // Texture Environment Swap Mode Table 6
  381. case BPMEM_TEV_KSEL+7: // Texture Environment Swap Mode Table 7
  382. /* This Register can be used to limit to which bits of BP registers is
  383. * actually written to. The mask is only valid for the next BP write,
  384. * and will reset itself afterwards. It's handled as a special case in
  385. * LoadBPReg. */
  386. case BPMEM_BP_MASK:
  387. case BPMEM_IND_IMASK: // Index Mask ?
  388. case BPMEM_REVBITS: // Always set to 0x0F when GX_InitRevBits() is called.
  389. return;
  390. case BPMEM_CLEAR_PIXEL_PERF:
  391. // GXClearPixMetric writes 0xAAA here, Sunshine alternates this register between values 0x000 and 0xAAA
  392. if (PerfQueryBase::ShouldEmulate())
  393. g_perf_query->ResetQuery();
  394. return;
  395. case BPMEM_PRELOAD_ADDR:
  396. case BPMEM_PRELOAD_TMEMEVEN:
  397. case BPMEM_PRELOAD_TMEMODD: // Used when PRELOAD_MODE is set
  398. return;
  399. case BPMEM_PRELOAD_MODE: // Set to 0 when GX_TexModeSync() is called.
  400. // if this is different from 0, manual TMEM management is used (GX_PreloadEntireTexture).
  401. if (bp.newvalue != 0)
  402. {
  403. // TODO: Not quite sure if this is completely correct (likely not)
  404. // NOTE: libogc's implementation of GX_PreloadEntireTexture seems flawed, so it's not necessarily a good reference for RE'ing this feature.
  405. BPS_TmemConfig& tmem_cfg = bpmem.tmem_config;
  406. u32 src_addr = tmem_cfg.preload_addr << 5; // TODO: Should we add mask here on GC?
  407. u32 size = tmem_cfg.preload_tile_info.count * TMEM_LINE_SIZE;
  408. u32 tmem_addr_even = tmem_cfg.preload_tmem_even * TMEM_LINE_SIZE;
  409. if (tmem_cfg.preload_tile_info.type != 3)
  410. {
  411. if (tmem_addr_even + size > TMEM_SIZE)
  412. size = TMEM_SIZE - tmem_addr_even;
  413. Memory::CopyFromEmu(texMem + tmem_addr_even, src_addr, size);
  414. }
  415. else // RGBA8 tiles (and CI14, but that might just be stupid libogc!)
  416. {
  417. u8* src_ptr = Memory::GetPointer(src_addr);
  418. // AR and GB tiles are stored in separate TMEM banks => can't use a single memcpy for everything
  419. u32 tmem_addr_odd = tmem_cfg.preload_tmem_odd * TMEM_LINE_SIZE;
  420. for (u32 i = 0; i < tmem_cfg.preload_tile_info.count; ++i)
  421. {
  422. if (tmem_addr_even + TMEM_LINE_SIZE > TMEM_SIZE ||
  423. tmem_addr_odd + TMEM_LINE_SIZE > TMEM_SIZE)
  424. return;
  425. // TODO: This isn't very optimised, does a whole lot of small memcpys
  426. memcpy(texMem + tmem_addr_even, src_ptr, TMEM_LINE_SIZE);
  427. memcpy(texMem + tmem_addr_odd, src_ptr + TMEM_LINE_SIZE, TMEM_LINE_SIZE);
  428. tmem_addr_even += TMEM_LINE_SIZE;
  429. tmem_addr_odd += TMEM_LINE_SIZE;
  430. src_ptr += TMEM_LINE_SIZE * 2;
  431. }
  432. }
  433. }
  434. return;
  435. // ---------------------------------------------------
  436. // Set the TEV Color
  437. // ---------------------------------------------------
  438. //
  439. // NOTE: Each of these registers actually maps to two variables internally.
  440. // There's a bit that specifies which one is currently written to.
  441. //
  442. // NOTE: Some games write only to the RA register (or only to the BG register).
  443. // We may not assume that the unwritten register holds a valid value, hence
  444. // both component pairs need to be loaded individually.
  445. case BPMEM_TEV_COLOR_RA:
  446. case BPMEM_TEV_COLOR_RA + 2:
  447. case BPMEM_TEV_COLOR_RA + 4:
  448. case BPMEM_TEV_COLOR_RA + 6:
  449. {
  450. int num = (bp.address >> 1) & 0x3;
  451. if (bpmem.tevregs[num].type_ra)
  452. {
  453. PixelShaderManager::SetTevKonstColor(num, 0, (s32)bpmem.tevregs[num].red);
  454. PixelShaderManager::SetTevKonstColor(num, 3, (s32)bpmem.tevregs[num].alpha);
  455. }
  456. else
  457. {
  458. PixelShaderManager::SetTevColor(num, 0, (s32)bpmem.tevregs[num].red);
  459. PixelShaderManager::SetTevColor(num, 3, (s32)bpmem.tevregs[num].alpha);
  460. }
  461. return;
  462. }
  463. case BPMEM_TEV_COLOR_BG:
  464. case BPMEM_TEV_COLOR_BG + 2:
  465. case BPMEM_TEV_COLOR_BG + 4:
  466. case BPMEM_TEV_COLOR_BG + 6:
  467. {
  468. int num = (bp.address >> 1) & 0x3;
  469. if (bpmem.tevregs[num].type_bg)
  470. {
  471. PixelShaderManager::SetTevKonstColor(num, 1, (s32)bpmem.tevregs[num].green);
  472. PixelShaderManager::SetTevKonstColor(num, 2, (s32)bpmem.tevregs[num].blue);
  473. }
  474. else
  475. {
  476. PixelShaderManager::SetTevColor(num, 1, (s32)bpmem.tevregs[num].green);
  477. PixelShaderManager::SetTevColor(num, 2, (s32)bpmem.tevregs[num].blue);
  478. }
  479. return;
  480. }
  481. default:
  482. break;
  483. }
  484. switch (bp.address & 0xFC) // Texture sampler filter
  485. {
  486. // -------------------------
  487. // Texture Environment Order
  488. // -------------------------
  489. case BPMEM_TREF:
  490. case BPMEM_TREF+4:
  491. return;
  492. // ----------------------
  493. // Set wrap size
  494. // ----------------------
  495. case BPMEM_SU_SSIZE:
  496. case BPMEM_SU_TSIZE:
  497. case BPMEM_SU_SSIZE+2:
  498. case BPMEM_SU_TSIZE+2:
  499. case BPMEM_SU_SSIZE+4:
  500. case BPMEM_SU_TSIZE+4:
  501. case BPMEM_SU_SSIZE+6:
  502. case BPMEM_SU_TSIZE+6:
  503. case BPMEM_SU_SSIZE+8:
  504. case BPMEM_SU_TSIZE+8:
  505. case BPMEM_SU_SSIZE+10:
  506. case BPMEM_SU_TSIZE+10:
  507. case BPMEM_SU_SSIZE+12:
  508. case BPMEM_SU_TSIZE+12:
  509. case BPMEM_SU_SSIZE+14:
  510. case BPMEM_SU_TSIZE+14:
  511. if (bp.changes)
  512. {
  513. PixelShaderManager::SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
  514. GeometryShaderManager::SetTexCoordChanged((bp.address - BPMEM_SU_SSIZE) >> 1);
  515. }
  516. return;
  517. // ------------------------
  518. // BPMEM_TX_SETMODE0 - (Texture lookup and filtering mode) LOD/BIAS Clamp, MaxAnsio, LODBIAS, DiagLoad, Min Filter, Mag Filter, Wrap T, S
  519. // BPMEM_TX_SETMODE1 - (LOD Stuff) - Max LOD, Min LOD
  520. // ------------------------
  521. case BPMEM_TX_SETMODE0: // (0x90 for linear)
  522. case BPMEM_TX_SETMODE0_4:
  523. return;
  524. case BPMEM_TX_SETMODE1:
  525. case BPMEM_TX_SETMODE1_4:
  526. return;
  527. // --------------------------------------------
  528. // BPMEM_TX_SETIMAGE0 - Texture width, height, format
  529. // BPMEM_TX_SETIMAGE1 - even LOD address in TMEM - Image Type, Cache Height, Cache Width, TMEM Offset
  530. // BPMEM_TX_SETIMAGE2 - odd LOD address in TMEM - Cache Height, Cache Width, TMEM Offset
  531. // BPMEM_TX_SETIMAGE3 - Address of Texture in main memory
  532. // --------------------------------------------
  533. case BPMEM_TX_SETIMAGE0:
  534. case BPMEM_TX_SETIMAGE0_4:
  535. case BPMEM_TX_SETIMAGE1:
  536. case BPMEM_TX_SETIMAGE1_4:
  537. case BPMEM_TX_SETIMAGE2:
  538. case BPMEM_TX_SETIMAGE2_4:
  539. case BPMEM_TX_SETIMAGE3:
  540. case BPMEM_TX_SETIMAGE3_4:
  541. return;
  542. // -------------------------------
  543. // Set a TLUT
  544. // BPMEM_TX_SETTLUT - Format, TMEM Offset (offset of TLUT from start of TMEM high bank > > 5)
  545. // -------------------------------
  546. case BPMEM_TX_SETTLUT:
  547. case BPMEM_TX_SETTLUT_4:
  548. return;
  549. default:
  550. break;
  551. }
  552. switch (bp.address & 0xF0)
  553. {
  554. // --------------
  555. // Indirect Tev
  556. // --------------
  557. case BPMEM_IND_CMD:
  558. case BPMEM_IND_CMD+1:
  559. case BPMEM_IND_CMD+2:
  560. case BPMEM_IND_CMD+3:
  561. case BPMEM_IND_CMD+4:
  562. case BPMEM_IND_CMD+5:
  563. case BPMEM_IND_CMD+6:
  564. case BPMEM_IND_CMD+7:
  565. case BPMEM_IND_CMD+8:
  566. case BPMEM_IND_CMD+9:
  567. case BPMEM_IND_CMD+10:
  568. case BPMEM_IND_CMD+11:
  569. case BPMEM_IND_CMD+12:
  570. case BPMEM_IND_CMD+13:
  571. case BPMEM_IND_CMD+14:
  572. case BPMEM_IND_CMD+15:
  573. return;
  574. // --------------------------------------------------
  575. // Set Color/Alpha of a Tev
  576. // BPMEM_TEV_COLOR_ENV - Dest, Shift, Clamp, Sub, Bias, Sel A, Sel B, Sel C, Sel D
  577. // BPMEM_TEV_ALPHA_ENV - Dest, Shift, Clamp, Sub, Bias, Sel A, Sel B, Sel C, Sel D, T Swap, R Swap
  578. // --------------------------------------------------
  579. case BPMEM_TEV_COLOR_ENV: // Texture Environment 1
  580. case BPMEM_TEV_ALPHA_ENV:
  581. case BPMEM_TEV_COLOR_ENV+2: // Texture Environment 2
  582. case BPMEM_TEV_ALPHA_ENV+2:
  583. case BPMEM_TEV_COLOR_ENV+4: // Texture Environment 3
  584. case BPMEM_TEV_ALPHA_ENV+4:
  585. case BPMEM_TEV_COLOR_ENV+6: // Texture Environment 4
  586. case BPMEM_TEV_ALPHA_ENV+6:
  587. case BPMEM_TEV_COLOR_ENV+8: // Texture Environment 5
  588. case BPMEM_TEV_ALPHA_ENV+8:
  589. case BPMEM_TEV_COLOR_ENV+10: // Texture Environment 6
  590. case BPMEM_TEV_ALPHA_ENV+10:
  591. case BPMEM_TEV_COLOR_ENV+12: // Texture Environment 7
  592. case BPMEM_TEV_ALPHA_ENV+12:
  593. case BPMEM_TEV_COLOR_ENV+14: // Texture Environment 8
  594. case BPMEM_TEV_ALPHA_ENV+14:
  595. case BPMEM_TEV_COLOR_ENV+16: // Texture Environment 9
  596. case BPMEM_TEV_ALPHA_ENV+16:
  597. case BPMEM_TEV_COLOR_ENV+18: // Texture Environment 10
  598. case BPMEM_TEV_ALPHA_ENV+18:
  599. case BPMEM_TEV_COLOR_ENV+20: // Texture Environment 11
  600. case BPMEM_TEV_ALPHA_ENV+20:
  601. case BPMEM_TEV_COLOR_ENV+22: // Texture Environment 12
  602. case BPMEM_TEV_ALPHA_ENV+22:
  603. case BPMEM_TEV_COLOR_ENV+24: // Texture Environment 13
  604. case BPMEM_TEV_ALPHA_ENV+24:
  605. case BPMEM_TEV_COLOR_ENV+26: // Texture Environment 14
  606. case BPMEM_TEV_ALPHA_ENV+26:
  607. case BPMEM_TEV_COLOR_ENV+28: // Texture Environment 15
  608. case BPMEM_TEV_ALPHA_ENV+28:
  609. case BPMEM_TEV_COLOR_ENV+30: // Texture Environment 16
  610. case BPMEM_TEV_ALPHA_ENV+30:
  611. return;
  612. default:
  613. break;
  614. }
  615. WARN_LOG(VIDEO, "Unknown BP opcode: address = 0x%08x value = 0x%08x", bp.address, bp.newvalue);
  616. }
  617. // Call browser: OpcodeDecoding.cpp ExecuteDisplayList > Decode() > LoadBPReg()
  618. void LoadBPReg(u32 value0)
  619. {
  620. int regNum = value0 >> 24;
  621. int oldval = ((u32*)&bpmem)[regNum];
  622. int newval = (oldval & ~bpmem.bpMask) | (value0 & bpmem.bpMask);
  623. int changes = (oldval ^ newval) & 0xFFFFFF;
  624. BPCmd bp = {regNum, changes, newval};
  625. // Reset the mask register if we're not trying to set it ourselves.
  626. if (regNum != BPMEM_BP_MASK)
  627. bpmem.bpMask = 0xFFFFFF;
  628. BPWritten(bp);
  629. }
  630. void LoadBPRegPreprocess(u32 value0)
  631. {
  632. int regNum = value0 >> 24;
  633. // masking could hypothetically be a problem
  634. u32 newval = value0 & 0xffffff;
  635. switch (regNum)
  636. {
  637. case BPMEM_SETDRAWDONE:
  638. if ((newval & 0xff) == 0x02)
  639. PixelEngine::SetFinish();
  640. break;
  641. case BPMEM_PE_TOKEN_ID:
  642. PixelEngine::SetToken(newval & 0xffff, false);
  643. break;
  644. case BPMEM_PE_TOKEN_INT_ID: // Pixel Engine Interrupt Token ID
  645. PixelEngine::SetToken(newval & 0xffff, true);
  646. break;
  647. }
  648. }
  649. void GetBPRegInfo(const u8* data, std::string* name, std::string* desc)
  650. {
  651. const char* no_yes[2] = { "No", "Yes" };
  652. u32 cmddata = Common::swap32(*(u32*)data) & 0xFFFFFF;
  653. switch (data[0])
  654. {
  655. // Macro to set the register name and make sure it was written correctly via compile time assertion
  656. #define SetRegName(reg) \
  657. *name = #reg; \
  658. (void)(reg);
  659. case BPMEM_GENMODE: // 0x00
  660. SetRegName(BPMEM_GENMODE);
  661. // TODO: Description
  662. break;
  663. case BPMEM_DISPLAYCOPYFILTER: // 0x01
  664. // TODO: This is actually the sample pattern used for copies from an antialiased EFB
  665. SetRegName(BPMEM_DISPLAYCOPYFILTER);
  666. // TODO: Description
  667. break;
  668. case 0x02: // 0x02
  669. case 0x03: // 0x03
  670. case 0x04: // 0x04
  671. // TODO: same as BPMEM_DISPLAYCOPYFILTER
  672. break;
  673. case BPMEM_IND_MTXA: // 0x06
  674. case BPMEM_IND_MTXA+3:
  675. case BPMEM_IND_MTXA+6:
  676. SetRegName(BPMEM_IND_MTXA);
  677. // TODO: Description
  678. break;
  679. case BPMEM_IND_MTXB: // 0x07
  680. case BPMEM_IND_MTXB+3:
  681. case BPMEM_IND_MTXB+6:
  682. SetRegName(BPMEM_IND_MTXB);
  683. // TODO: Descriptio
  684. break;
  685. case BPMEM_IND_MTXC: // 0x08
  686. case BPMEM_IND_MTXC+3:
  687. case BPMEM_IND_MTXC+6:
  688. SetRegName(BPMEM_IND_MTXC);
  689. // TODO: Description
  690. break;
  691. case BPMEM_IND_IMASK: // 0x0F
  692. SetRegName(BPMEM_IND_IMASK);
  693. // TODO: Description
  694. break;
  695. case BPMEM_IND_CMD: // 0x10
  696. case BPMEM_IND_CMD+1:
  697. case BPMEM_IND_CMD+2:
  698. case BPMEM_IND_CMD+3:
  699. case BPMEM_IND_CMD+4:
  700. case BPMEM_IND_CMD+5:
  701. case BPMEM_IND_CMD+6:
  702. case BPMEM_IND_CMD+7:
  703. case BPMEM_IND_CMD+8:
  704. case BPMEM_IND_CMD+9:
  705. case BPMEM_IND_CMD+10:
  706. case BPMEM_IND_CMD+11:
  707. case BPMEM_IND_CMD+12:
  708. case BPMEM_IND_CMD+13:
  709. case BPMEM_IND_CMD+14:
  710. case BPMEM_IND_CMD+15:
  711. SetRegName(BPMEM_IND_CMD);
  712. // TODO: Description
  713. break;
  714. case BPMEM_SCISSORTL: // 0x20
  715. SetRegName(BPMEM_SCISSORTL);
  716. // TODO: Description
  717. break;
  718. case BPMEM_SCISSORBR: // 0x21
  719. SetRegName(BPMEM_SCISSORBR);
  720. // TODO: Description
  721. break;
  722. case BPMEM_LINEPTWIDTH: // 0x22
  723. SetRegName(BPMEM_LINEPTWIDTH);
  724. // TODO: Description
  725. break;
  726. case BPMEM_PERF0_TRI: // 0x23
  727. SetRegName(BPMEM_PERF0_TRI);
  728. // TODO: Description
  729. break;
  730. case BPMEM_PERF0_QUAD: // 0x24
  731. SetRegName(BPMEM_PERF0_QUAD);
  732. // TODO: Description
  733. break;
  734. case BPMEM_RAS1_SS0: // 0x25
  735. SetRegName(BPMEM_RAS1_SS0);
  736. // TODO: Description
  737. break;
  738. case BPMEM_RAS1_SS1: // 0x26
  739. SetRegName(BPMEM_RAS1_SS1);
  740. // TODO: Description
  741. break;
  742. case BPMEM_IREF: // 0x27
  743. SetRegName(BPMEM_IREF);
  744. // TODO: Description
  745. break;
  746. case BPMEM_TREF: // 0x28
  747. case BPMEM_TREF+1:
  748. case BPMEM_TREF+2:
  749. case BPMEM_TREF+3:
  750. case BPMEM_TREF+4:
  751. case BPMEM_TREF+5:
  752. case BPMEM_TREF+6:
  753. case BPMEM_TREF+7:
  754. SetRegName(BPMEM_TREF);
  755. // TODO: Description
  756. break;
  757. case BPMEM_SU_SSIZE: // 0x30
  758. case BPMEM_SU_SSIZE+2:
  759. case BPMEM_SU_SSIZE+4:
  760. case BPMEM_SU_SSIZE+6:
  761. case BPMEM_SU_SSIZE+8:
  762. case BPMEM_SU_SSIZE+10:
  763. case BPMEM_SU_SSIZE+12:
  764. case BPMEM_SU_SSIZE+14:
  765. SetRegName(BPMEM_SU_SSIZE);
  766. // TODO: Description
  767. break;
  768. case BPMEM_SU_TSIZE: // 0x31
  769. case BPMEM_SU_TSIZE+2:
  770. case BPMEM_SU_TSIZE+4:
  771. case BPMEM_SU_TSIZE+6:
  772. case BPMEM_SU_TSIZE+8:
  773. case BPMEM_SU_TSIZE+10:
  774. case BPMEM_SU_TSIZE+12:
  775. case BPMEM_SU_TSIZE+14:
  776. SetRegName(BPMEM_SU_TSIZE);
  777. // TODO: Description
  778. break;
  779. case BPMEM_ZMODE: // 0x40
  780. SetRegName(BPMEM_ZMODE);
  781. // TODO: Description
  782. break;
  783. case BPMEM_BLENDMODE: // 0x41
  784. {
  785. SetRegName(BPMEM_BLENDMODE);
  786. BlendMode mode; mode.hex = cmddata;
  787. const char* dstfactors[] = { "0", "1", "src_color", "1-src_color", "src_alpha", "1-src_alpha", "dst_alpha", "1-dst_alpha" };
  788. const char* srcfactors[] = { "0", "1", "dst_color", "1-dst_color", "src_alpha", "1-src_alpha", "dst_alpha", "1-dst_alpha" };
  789. const char* logicmodes[] = { "0", "s & d", "s & ~d", "s", "~s & d", "d", "s ^ d", "s | d", "~(s | d)", "~(s ^ d)", "~d", "s | ~d", "~s", "~s | d", "~(s & d)", "1" };
  790. *desc = StringFromFormat("Enable: %s\n"
  791. "Logic ops: %s\n"
  792. "Dither: %s\n"
  793. "Color write: %s\n"
  794. "Alpha write: %s\n"
  795. "Dest factor: %s\n"
  796. "Source factor: %s\n"
  797. "Subtract: %s\n"
  798. "Logic mode: %s\n",
  799. no_yes[mode.blendenable], no_yes[mode.logicopenable], no_yes[mode.dither],
  800. no_yes[mode.colorupdate], no_yes[mode.alphaupdate], dstfactors[mode.dstfactor],
  801. srcfactors[mode.srcfactor], no_yes[mode.subtract], logicmodes[mode.logicmode]);
  802. }
  803. break;
  804. case BPMEM_CONSTANTALPHA: // 0x42
  805. SetRegName(BPMEM_CONSTANTALPHA);
  806. // TODO: Description
  807. break;
  808. case BPMEM_ZCOMPARE: // 0x43
  809. {
  810. SetRegName(BPMEM_ZCOMPARE);
  811. PEControl config; config.hex = cmddata;
  812. const char* pixel_formats[] = { "RGB8_Z24", "RGBA6_Z24", "RGB565_Z16", "Z24", "Y8", "U8", "V8", "YUV420" };
  813. const char* zformats[] = { "linear", "compressed (near)", "compressed (mid)", "compressed (far)", "inv linear", "compressed (inv near)", "compressed (inv mid)", "compressed (inv far)" };
  814. *desc = StringFromFormat("EFB pixel format: %s\n"
  815. "Depth format: %s\n"
  816. "Early depth test: %s\n",
  817. pixel_formats[config.pixel_format], zformats[config.zformat], no_yes[config.early_ztest]);
  818. }
  819. break;
  820. case BPMEM_FIELDMASK: // 0x44
  821. SetRegName(BPMEM_FIELDMASK);
  822. // TODO: Description
  823. break;
  824. case BPMEM_SETDRAWDONE: // 0x45
  825. SetRegName(BPMEM_SETDRAWDONE);
  826. // TODO: Description
  827. break;
  828. case BPMEM_BUSCLOCK0: // 0x46
  829. SetRegName(BPMEM_BUSCLOCK0);
  830. // TODO: Description
  831. break;
  832. case BPMEM_PE_TOKEN_ID: // 0x47
  833. SetRegName(BPMEM_PE_TOKEN_ID);
  834. // TODO: Description
  835. break;
  836. case BPMEM_PE_TOKEN_INT_ID: // 0x48
  837. SetRegName(BPMEM_PE_TOKEN_INT_ID);
  838. // TODO: Description
  839. break;
  840. case BPMEM_EFB_TL: // 0x49
  841. {
  842. SetRegName(BPMEM_EFB_TL);
  843. X10Y10 left_top; left_top.hex = cmddata;
  844. *desc = StringFromFormat("Left: %d\nTop: %d", left_top.x, left_top.y);
  845. }
  846. break;
  847. case BPMEM_EFB_BR: // 0x4A
  848. {
  849. // TODO: Misleading name, should be BPMEM_EFB_WH instead
  850. SetRegName(BPMEM_EFB_BR);
  851. X10Y10 width_height; width_height.hex = cmddata;
  852. *desc = StringFromFormat("Width: %d\nHeight: %d", width_height.x+1, width_height.y+1);
  853. }
  854. break;
  855. case BPMEM_EFB_ADDR: // 0x4B
  856. SetRegName(BPMEM_EFB_ADDR);
  857. *desc = StringFromFormat("Target address (32 byte aligned): 0x%06X", cmddata << 5);
  858. break;
  859. case BPMEM_MIPMAP_STRIDE: // 0x4D
  860. SetRegName(BPMEM_MIPMAP_STRIDE);
  861. // TODO: Description
  862. break;
  863. case BPMEM_COPYYSCALE: // 0x4E
  864. SetRegName(BPMEM_COPYYSCALE);
  865. *desc = StringFromFormat("Scaling factor (XFB copy only): 0x%X (%f or inverted %f)", cmddata, (float)cmddata/256.f, 256.f/(float)cmddata);
  866. break;
  867. case BPMEM_CLEAR_AR: // 0x4F
  868. SetRegName(BPMEM_CLEAR_AR);
  869. *desc = StringFromFormat("Alpha: 0x%02X\nRed: 0x%02X", (cmddata&0xFF00)>>8, cmddata&0xFF);
  870. break;
  871. case BPMEM_CLEAR_GB: // 0x50
  872. SetRegName(BPMEM_CLEAR_GB);
  873. *desc = StringFromFormat("Green: 0x%02X\nBlue: 0x%02X", (cmddata&0xFF00)>>8, cmddata&0xFF);
  874. break;
  875. case BPMEM_CLEAR_Z: // 0x51
  876. SetRegName(BPMEM_CLEAR_Z);
  877. *desc = StringFromFormat("Z value: 0x%06X", cmddata);
  878. break;
  879. case BPMEM_TRIGGER_EFB_COPY: // 0x52
  880. {
  881. SetRegName(BPMEM_TRIGGER_EFB_COPY);
  882. UPE_Copy copy; copy.Hex = cmddata;
  883. *desc = StringFromFormat("Clamping: %s\n"
  884. "Converting from RGB to YUV: %s\n"
  885. "Target pixel format: 0x%X\n"
  886. "Gamma correction: %s\n"
  887. "Mipmap filter: %s\n"
  888. "Vertical scaling: %s\n"
  889. "Clear: %s\n"
  890. "Frame to field: 0x%01X\n"
  891. "Copy to XFB: %s\n"
  892. "Intensity format: %s\n"
  893. "Automatic color conversion: %s",
  894. (copy.clamp0 && copy.clamp1) ? "Top and Bottom" : (copy.clamp0) ? "Top only" : (copy.clamp1) ? "Bottom only" : "None",
  895. no_yes[copy.yuv],
  896. copy.tp_realFormat(),
  897. (copy.gamma==0)?"1.0":(copy.gamma==1)?"1.7":(copy.gamma==2)?"2.2":"Invalid value 0x3?",
  898. no_yes[copy.half_scale],
  899. no_yes[copy.scale_invert],
  900. no_yes[copy.clear],
  901. (u32)copy.frame_to_field,
  902. no_yes[copy.copy_to_xfb],
  903. no_yes[copy.intensity_fmt],
  904. no_yes[copy.auto_conv]);
  905. }
  906. break;
  907. case BPMEM_COPYFILTER0: // 0x53
  908. SetRegName(BPMEM_COPYFILTER0);
  909. // TODO: Description
  910. break;
  911. case BPMEM_COPYFILTER1: // 0x54
  912. SetRegName(BPMEM_COPYFILTER1);
  913. // TODO: Description
  914. break;
  915. case BPMEM_CLEARBBOX1: // 0x55
  916. SetRegName(BPMEM_CLEARBBOX1);
  917. // TODO: Description
  918. break;
  919. case BPMEM_CLEARBBOX2: // 0x56
  920. SetRegName(BPMEM_CLEARBBOX2);
  921. // TODO: Description
  922. break;
  923. case BPMEM_CLEAR_PIXEL_PERF: // 0x57
  924. SetRegName(BPMEM_CLEAR_PIXEL_PERF);
  925. // TODO: Description
  926. break;
  927. case BPMEM_REVBITS: // 0x58
  928. SetRegName(BPMEM_REVBITS);
  929. // TODO: Description
  930. break;
  931. case BPMEM_SCISSOROFFSET: // 0x59
  932. SetRegName(BPMEM_SCISSOROFFSET);
  933. // TODO: Description
  934. break;
  935. case BPMEM_PRELOAD_ADDR: // 0x60
  936. SetRegName(BPMEM_PRELOAD_ADDR);
  937. // TODO: Description
  938. break;
  939. case BPMEM_PRELOAD_TMEMEVEN: // 0x61
  940. SetRegName(BPMEM_PRELOAD_TMEMEVEN);
  941. // TODO: Description
  942. break;
  943. case BPMEM_PRELOAD_TMEMODD: // 0x62
  944. SetRegName(BPMEM_PRELOAD_TMEMODD);
  945. // TODO: Description
  946. break;
  947. case BPMEM_PRELOAD_MODE: // 0x63
  948. SetRegName(BPMEM_PRELOAD_MODE);
  949. // TODO: Description
  950. break;
  951. case BPMEM_LOADTLUT0: // 0x64
  952. SetRegName(BPMEM_LOADTLUT0);
  953. // TODO: Description
  954. break;
  955. case BPMEM_LOADTLUT1: // 0x65
  956. SetRegName(BPMEM_LOADTLUT1);
  957. // TODO: Description
  958. break;
  959. case BPMEM_TEXINVALIDATE: // 0x66
  960. SetRegName(BPMEM_TEXINVALIDATE);
  961. // TODO: Description
  962. break;
  963. case BPMEM_PERF1: // 0x67
  964. SetRegName(BPMEM_PERF1);
  965. // TODO: Description
  966. break;
  967. case BPMEM_FIELDMODE: // 0x68
  968. SetRegName(BPMEM_FIELDMODE);
  969. // TODO: Description
  970. break;
  971. case BPMEM_BUSCLOCK1: // 0x69
  972. SetRegName(BPMEM_BUSCLOCK1);
  973. // TODO: Description
  974. break;
  975. case BPMEM_TX_SETMODE0: // 0x80
  976. case BPMEM_TX_SETMODE0+1:
  977. case BPMEM_TX_SETMODE0+2:
  978. case BPMEM_TX_SETMODE0+3:
  979. SetRegName(BPMEM_TX_SETMODE0);
  980. // TODO: Description
  981. break;
  982. case BPMEM_TX_SETMODE1: // 0x84
  983. case BPMEM_TX_SETMODE1+1:
  984. case BPMEM_TX_SETMODE1+2:
  985. case BPMEM_TX_SETMODE1+3:
  986. SetRegName(BPMEM_TX_SETMODE1);
  987. // TODO: Description
  988. break;
  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. case BPMEM_TX_SETIMAGE0_4: // 0xA8
  994. case BPMEM_TX_SETIMAGE0_4+1:
  995. case BPMEM_TX_SETIMAGE0_4+2:
  996. case BPMEM_TX_SETIMAGE0_4+3:
  997. SetRegName(BPMEM_TX_SETIMAGE0);
  998. // TODO: Description
  999. break;
  1000. case BPMEM_TX_SETIMAGE1: // 0x8C
  1001. case BPMEM_TX_SETIMAGE1+1:
  1002. case BPMEM_TX_SETIMAGE1+2:
  1003. case BPMEM_TX_SETIMAGE1+3:
  1004. case BPMEM_TX_SETIMAGE1_4: // 0xAC
  1005. case BPMEM_TX_SETIMAGE1_4+1:
  1006. case BPMEM_TX_SETIMAGE1_4+2:
  1007. case BPMEM_TX_SETIMAGE1_4+3:
  1008. SetRegName(BPMEM_TX_SETIMAGE1);
  1009. // TODO: Description
  1010. break;
  1011. case BPMEM_TX_SETIMAGE2: // 0x90
  1012. case BPMEM_TX_SETIMAGE2+1:
  1013. case BPMEM_TX_SETIMAGE2+2:
  1014. case BPMEM_TX_SETIMAGE2+3:
  1015. case BPMEM_TX_SETIMAGE2_4: // 0xB0
  1016. case BPMEM_TX_SETIMAGE2_4+1:
  1017. case BPMEM_TX_SETIMAGE2_4+2:
  1018. case BPMEM_TX_SETIMAGE2_4+3:
  1019. SetRegName(BPMEM_TX_SETIMAGE2);
  1020. // TODO: Description
  1021. break;
  1022. case BPMEM_TX_SETIMAGE3: // 0x94
  1023. case BPMEM_TX_SETIMAGE3+1:
  1024. case BPMEM_TX_SETIMAGE3+2:
  1025. case BPMEM_TX_SETIMAGE3+3:
  1026. case BPMEM_TX_SETIMAGE3_4: // 0xB4
  1027. case BPMEM_TX_SETIMAGE3_4+1:
  1028. case BPMEM_TX_SETIMAGE3_4+2:
  1029. case BPMEM_TX_SETIMAGE3_4+3:
  1030. {
  1031. SetRegName(BPMEM_TX_SETIMAGE3);
  1032. TexImage3 teximg; teximg.hex = cmddata;
  1033. *desc = StringFromFormat("Source address (32 byte aligned): 0x%06X", teximg.image_base << 5);
  1034. }
  1035. break;
  1036. case BPMEM_TX_SETTLUT: // 0x98
  1037. case BPMEM_TX_SETTLUT+1:
  1038. case BPMEM_TX_SETTLUT+2:
  1039. case BPMEM_TX_SETTLUT+3:
  1040. case BPMEM_TX_SETTLUT_4: // 0xB8
  1041. case BPMEM_TX_SETTLUT_4+1:
  1042. case BPMEM_TX_SETTLUT_4+2:
  1043. case BPMEM_TX_SETTLUT_4+3:
  1044. SetRegName(BPMEM_TX_SETTLUT);
  1045. // TODO: Description
  1046. break;
  1047. case BPMEM_TEV_COLOR_ENV: // 0xC0
  1048. case BPMEM_TEV_COLOR_ENV+2:
  1049. case BPMEM_TEV_COLOR_ENV+4:
  1050. case BPMEM_TEV_COLOR_ENV+8:
  1051. case BPMEM_TEV_COLOR_ENV+10:
  1052. case BPMEM_TEV_COLOR_ENV+12:
  1053. case BPMEM_TEV_COLOR_ENV+14:
  1054. case BPMEM_TEV_COLOR_ENV+16:
  1055. case BPMEM_TEV_COLOR_ENV+18:
  1056. case BPMEM_TEV_COLOR_ENV+20:
  1057. case BPMEM_TEV_COLOR_ENV+22:
  1058. case BPMEM_TEV_COLOR_ENV+24:
  1059. case BPMEM_TEV_COLOR_ENV+26:
  1060. case BPMEM_TEV_COLOR_ENV+28:
  1061. case BPMEM_TEV_COLOR_ENV+30:
  1062. {
  1063. SetRegName(BPMEM_TEV_COLOR_ENV);
  1064. TevStageCombiner::ColorCombiner cc; cc.hex = cmddata;
  1065. const char* tevin[] =
  1066. {
  1067. "prev.rgb", "prev.aaa",
  1068. "c0.rgb", "c0.aaa",
  1069. "c1.rgb", "c1.aaa",
  1070. "c2.rgb", "c2.aaa",
  1071. "tex.rgb", "tex.aaa",
  1072. "ras.rgb", "ras.aaa",
  1073. "ONE", "HALF", "konst.rgb", "ZERO",
  1074. };
  1075. const char* tevbias[] = { "0", "+0.5", "-0.5", "compare" };
  1076. const char* tevop[] = { "add", "sub" };
  1077. const char* tevscale[] = { "1", "2", "4", "0.5" };
  1078. const char* tevout[] = { "prev.rgb", "c0.rgb", "c1.rgb", "c2.rgb" };
  1079. *desc = StringFromFormat("Tev stage: %d\n"
  1080. "a: %s\n"
  1081. "b: %s\n"
  1082. "c: %s\n"
  1083. "d: %s\n"
  1084. "Bias: %s\n"
  1085. "Op: %s\n"
  1086. "Clamp: %s\n"
  1087. "Scale factor: %s\n"
  1088. "Dest: %s\n",
  1089. (data[0] - BPMEM_TEV_COLOR_ENV)/2, tevin[cc.a], tevin[cc.b], tevin[cc.c], tevin[cc.d],
  1090. tevbias[cc.bias], tevop[cc.op], no_yes[cc.clamp], tevscale[cc.shift], tevout[cc.dest]);
  1091. break;
  1092. }
  1093. case BPMEM_TEV_ALPHA_ENV: // 0xC1
  1094. case BPMEM_TEV_ALPHA_ENV+2:
  1095. case BPMEM_TEV_ALPHA_ENV+4:
  1096. case BPMEM_TEV_ALPHA_ENV+6:
  1097. case BPMEM_TEV_ALPHA_ENV+8:
  1098. case BPMEM_TEV_ALPHA_ENV+10:
  1099. case BPMEM_TEV_ALPHA_ENV+12:
  1100. case BPMEM_TEV_ALPHA_ENV+14:
  1101. case BPMEM_TEV_ALPHA_ENV+16:
  1102. case BPMEM_TEV_ALPHA_ENV+18:
  1103. case BPMEM_TEV_ALPHA_ENV+20:
  1104. case BPMEM_TEV_ALPHA_ENV+22:
  1105. case BPMEM_TEV_ALPHA_ENV+24:
  1106. case BPMEM_TEV_ALPHA_ENV+26:
  1107. case BPMEM_TEV_ALPHA_ENV+28:
  1108. case BPMEM_TEV_ALPHA_ENV+30:
  1109. {
  1110. SetRegName(BPMEM_TEV_ALPHA_ENV);
  1111. TevStageCombiner::AlphaCombiner ac; ac.hex = cmddata;
  1112. const char* tevin[] =
  1113. {
  1114. "prev", "c0", "c1", "c2",
  1115. "tex", "ras", "konst", "ZERO",
  1116. };
  1117. const char* tevbias[] = { "0", "+0.5", "-0.5", "compare" };
  1118. const char* tevop[] = { "add", "sub" };
  1119. const char* tevscale[] = { "1", "2", "4", "0.5" };
  1120. const char* tevout[] = { "prev", "c0", "c1", "c2" };
  1121. *desc = StringFromFormat("Tev stage: %d\n"
  1122. "a: %s\n"
  1123. "b: %s\n"
  1124. "c: %s\n"
  1125. "d: %s\n"
  1126. "Bias: %s\n"
  1127. "Op: %s\n"
  1128. "Clamp: %s\n"
  1129. "Scale factor: %s\n"
  1130. "Dest: %s\n"
  1131. "Ras sel: %d\n"
  1132. "Tex sel: %d\n",
  1133. (data[0] - BPMEM_TEV_ALPHA_ENV)/2, tevin[ac.a], tevin[ac.b], tevin[ac.c], tevin[ac.d],
  1134. tevbias[ac.bias], tevop[ac.op], no_yes[ac.clamp], tevscale[ac.shift], tevout[ac.dest],
  1135. ac.rswap, ac.tswap);
  1136. break;
  1137. }
  1138. case BPMEM_TEV_COLOR_RA: // 0xE0
  1139. case BPMEM_TEV_COLOR_RA + 2: // 0xE2
  1140. case BPMEM_TEV_COLOR_RA + 4: // 0xE4
  1141. case BPMEM_TEV_COLOR_RA + 6: // 0xE6
  1142. SetRegName(BPMEM_TEV_COLOR_RA);
  1143. // TODO: Description
  1144. break;
  1145. case BPMEM_TEV_COLOR_BG: // 0xE1
  1146. case BPMEM_TEV_COLOR_BG + 2: // 0xE3
  1147. case BPMEM_TEV_COLOR_BG + 4: // 0xE5
  1148. case BPMEM_TEV_COLOR_BG + 6: // 0xE7
  1149. SetRegName(BPMEM_TEV_COLOR_BG);
  1150. // TODO: Description
  1151. break;
  1152. case BPMEM_FOGRANGE: // 0xE8
  1153. case BPMEM_FOGRANGE+1:
  1154. case BPMEM_FOGRANGE+2:
  1155. case BPMEM_FOGRANGE+3:
  1156. case BPMEM_FOGRANGE+4:
  1157. case BPMEM_FOGRANGE+5:
  1158. SetRegName(BPMEM_FOGRANGE);
  1159. // TODO: Description
  1160. break;
  1161. case BPMEM_FOGPARAM0: // 0xEE
  1162. SetRegName(BPMEM_FOGPARAM0);
  1163. // TODO: Description
  1164. break;
  1165. case BPMEM_FOGBMAGNITUDE: // 0xEF
  1166. SetRegName(BPMEM_FOGBMAGNITUDE);
  1167. // TODO: Description
  1168. break;
  1169. case BPMEM_FOGBEXPONENT: // 0xF0
  1170. SetRegName(BPMEM_FOGBEXPONENT);
  1171. // TODO: Description
  1172. break;
  1173. case BPMEM_FOGPARAM3: // 0xF1
  1174. SetRegName(BPMEM_FOGPARAM3);
  1175. // TODO: Description
  1176. break;
  1177. case BPMEM_FOGCOLOR: // 0xF2
  1178. SetRegName(BPMEM_FOGCOLOR);
  1179. // TODO: Description
  1180. break;
  1181. case BPMEM_ALPHACOMPARE: // 0xF3
  1182. {
  1183. SetRegName(BPMEM_ALPHACOMPARE);
  1184. AlphaTest test; test.hex = cmddata;
  1185. const char* functions[] = { "NEVER", "LESS", "EQUAL", "LEQUAL", "GREATER", "NEQUAL", "GEQUAL", "ALWAYS" };
  1186. const char* logic[] = { "AND", "OR", "XOR", "XNOR" };
  1187. *desc = StringFromFormat("Test 1: %s (ref: %#02x)\n"
  1188. "Test 2: %s (ref: %#02x)\n"
  1189. "Logic: %s\n",
  1190. functions[test.comp0], (int)test.ref0, functions[test.comp1], (int)test.ref1, logic[test.logic]);
  1191. break;
  1192. }
  1193. case BPMEM_BIAS: // 0xF4
  1194. SetRegName(BPMEM_BIAS);
  1195. // TODO: Description
  1196. break;
  1197. case BPMEM_ZTEX2: // 0xF5
  1198. SetRegName(BPMEM_ZTEX2);
  1199. // TODO: Description
  1200. break;
  1201. case BPMEM_TEV_KSEL: // 0xF6
  1202. case BPMEM_TEV_KSEL+1:
  1203. case BPMEM_TEV_KSEL+2:
  1204. case BPMEM_TEV_KSEL+3:
  1205. case BPMEM_TEV_KSEL+4:
  1206. case BPMEM_TEV_KSEL+5:
  1207. case BPMEM_TEV_KSEL+6:
  1208. case BPMEM_TEV_KSEL+7:
  1209. SetRegName(BPMEM_TEV_KSEL);
  1210. // TODO: Description
  1211. break;
  1212. #undef SetRegName
  1213. }
  1214. }
  1215. // Called when loading a saved state.
  1216. void BPReload()
  1217. {
  1218. // restore anything that goes straight to the renderer.
  1219. // let's not risk actually replaying any writes.
  1220. // note that PixelShaderManager is already covered since it has its own DoState.
  1221. SetGenerationMode();
  1222. SetScissor();
  1223. SetDepthMode();
  1224. SetLogicOpMode();
  1225. SetDitherMode();
  1226. SetBlendMode();
  1227. SetColorMask();
  1228. OnPixelFormatChange();
  1229. }