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