From 105592d979b333ff4d99d47a06aba964e97ea9c4 Mon Sep 17 00:00:00 2001 From: Erik Abair Date: Fri, 11 Feb 2022 16:37:57 -0800 Subject: [PATCH] Responses to code review comments. --- NV2ALog.py | 2 +- Trace.py | 61 ++++++++++++++++++++++++++++---------------------- XboxHelper.py | 21 ++++++++--------- kick_fifo | Bin 92 -> 84 bytes kick_fifo.asm | 19 +--------------- nv2a-trace.py | 12 ++++++++-- 6 files changed, 57 insertions(+), 58 deletions(-) diff --git a/NV2ALog.py b/NV2ALog.py index f58a195..c03193b 100644 --- a/NV2ALog.py +++ b/NV2ALog.py @@ -13,7 +13,7 @@ def __init__(self, path): self.path = path with open(self.path, "w", encoding="utf8") as logfile: - logfile.write("xemu style NV2A log from nv2a-trace.py\n\n") + logfile.write("pgraph method log from nv2a-trace.py\n\n") def log(self, message): """Append the given string to the nv2a log.""" diff --git a/Trace.py b/Trace.py index afc86f2..a70c511 100644 --- a/Trace.py +++ b/Trace.py @@ -55,18 +55,28 @@ def _dump_pfb(xbox): return bytes(buffer) -def _read_pgraph_rdi(xbox: Xbox, offset: int, count: int) -> bytes: +def _read_pgraph_rdi(xbox: Xbox, offset: int, count: int): # FIXME: Assert pusher access is disabled # FIXME: Assert PGRAPH idle NV10_PGRAPH_RDI_INDEX = 0xFD400750 NV10_PGRAPH_RDI_DATA = 0xFD400754 - original_offset = ExchangeU32.exchange_u32(xbox, NV10_PGRAPH_RDI_INDEX, offset) - - data = xbox.read(NV10_PGRAPH_RDI_DATA, count * 4) - - xbox.write_u32(NV10_PGRAPH_RDI_INDEX, original_offset) + # JFR: Reading the DATA register 4 times returns X,Y,Z,W (not in that order as far + # as I remember), but during that time the INDEX register will stay constant, only + # on the final read I think it auto-increments the INDEX. + # It is not safe and likely incorrect to do a bulk read so this must be done + # individualy despite the interface communication overhead. + xbox.write_u32(NV10_PGRAPH_RDI_INDEX, offset) + data = bytearray() + for _ in range(count): + word = xbox.read_u32(NV10_PGRAPH_RDI_DATA) + data += struct.pack("> 16 pitch = 0 fmt = self.xbox.read_u32(XboxHelper.PGRAPH_TEXFMT0 + reg_offset) @@ -335,7 +341,7 @@ def _dump_texture(self, index): depth = 1 << depth_shift self._dbg_print( - "Texture %d [0x%08X, %d x %d x %d (pitch: 0x%X ), format 0x%X]" + "Texture %d [0x%08X, %d x %d x %d (pitch register: 0x%X), format 0x%X]" % (index, offset, width, height, depth, reg_pitch, fmt_color) ) @@ -390,7 +396,7 @@ def dump(img_tags, adjusted_offset, layer): return img_tags - def dump_textures(self, data, *args): + def dump_textures(self, _data, *_args): if not self.enable_texture_dumping: return [] @@ -430,18 +436,19 @@ def dump_surfaces(self, _data, *_args): 0x80000000 | params.depth_offset, params.depth_pitch * params.height ), ) - self._write( - "pgraph-rdi-vp-instructions.bin", - _read_pgraph_rdi(self.xbox, 0x100000, 136 * 4), - ) - self._write( - "pgraph-rdi-vp-constants0.bin", - _read_pgraph_rdi(self.xbox, 0x170000, 192 * 4), - ) - self._write( - "pgraph-rdi-vp-constants1.bin", - _read_pgraph_rdi(self.xbox, 0xCC0000, 192 * 4), - ) + if self.enable_rdi: + self._write( + "pgraph-rdi-vp-instructions.bin", + _read_pgraph_rdi(self.xbox, 0x100000, 136 * 4), + ) + self._write( + "pgraph-rdi-vp-constants0.bin", + _read_pgraph_rdi(self.xbox, 0x170000, 192 * 4), + ) + self._write( + "pgraph-rdi-vp-constants1.bin", + _read_pgraph_rdi(self.xbox, 0xCC0000, 192 * 4), + ) # FIXME: Respect anti-aliasing img_tags = "" diff --git a/XboxHelper.py b/XboxHelper.py index 5aabb47..52d33fc 100644 --- a/XboxHelper.py +++ b/XboxHelper.py @@ -5,7 +5,6 @@ # pylint: disable=chained-comparison import atexit -import struct from collections import namedtuple from typing import Optional from typing import Tuple @@ -91,6 +90,9 @@ def _PGRAPH(addr): NV_PFIFO_CACHE1_METHOD = 0x00001800 CACHE1_METHOD = _PFIFO(NV_PFIFO_CACHE1_METHOD) +NV_PFIFO_CACHE1_DATA = 0xFD003804 +CACHE1_DATA = _PFIFO(NV_PFIFO_CACHE1_DATA) + NV_PFIFO_RAMHT = 0x00000210 RAM_HASHTABLE = _PFIFO(NV_PFIFO_RAMHT) @@ -262,15 +264,14 @@ def resume_fifo_pusher(self): if self.delay(): pass - def allow_populate_fifo_cache(self, wait_time=0.05): + def allow_populate_fifo_cache(self): """Temporarily enable the PFIFO pusher to populate the CACHE It is assumed that the pusher was previously paused, and it will be paused on exit. """ self.resume_fifo_pusher() - if wait_time: - time.sleep(wait_time) + time.sleep(0.05) self.pause_fifo_pusher() def _dump_pb(self, start, end): @@ -318,12 +319,12 @@ def print_cache_state(self, print_contents=False): if print_contents: print("Cache:") - # Each CACHE entry is a pair of 32-bit integers and there are 128 entries. - methods_and_data = self.xbox.read(CACHE1_METHOD, 8 * 128) - + # JFR: This is intentionally read in a loop as behavior is dependent on the + # implementation of xboxpy's `read`. for i in range(128): - cache1_method, cache1_data = struct.unpack("