From 159b7067326535632a2d6491a6c9c9df853bb1ad Mon Sep 17 00:00:00 2001 From: Erik Abair Date: Wed, 9 Feb 2022 21:25:56 -0800 Subject: [PATCH] Read surfaces via AGP --- Texture.py | 16 ++++++++++++---- nv2a-trace.py | 3 ++- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/Texture.py b/Texture.py index 1a54999..daeda77 100644 --- a/Texture.py +++ b/Texture.py @@ -15,6 +15,11 @@ import XboxHelper from xboxpy import nv2a +# Value that may be added to contiguous memory addresses to access as ADDR_AGPMEM, which +# is guaranteed to be linear (and thus may be slower than tiled ADDR_FBMEM but can be +# manipulated directly). +AGP_MEMORY_BASE = 0xF0000000 + TextureParameters = namedtuple( "TextureParameters", [ @@ -75,6 +80,9 @@ def get_bits(bits, offset, length): img = Image.new(mode, (width, height)) + # TODO: Is unswizzling actually necessary if textures are read via AGP? + # Need to set up a swizzled test case and verify behavior. + # FIXME: Unswizzle data on the fly instead if swizzled: data = nv2a.Unswizzle(data, bits_per_pixel, (width, height), pitch) @@ -251,13 +259,13 @@ def dump_texture(xbox, offset, pitch, fmt_color, width, height): "RGB", (width, height), (255, 0, 255, 255) ) # FIXME! Palette mode! elif fmt_color == 0xC: # DXT1 - data = xbox.read(0x80000000 | offset, width * height // 2) + data = xbox.read(AGP_MEMORY_BASE | offset, width * height // 2) img = Image.frombytes("RGBA", (width, height), data, "bcn", 1) # DXT1 elif fmt_color == 0xE: # DXT3 - data = xbox.read(0x80000000 | offset, width * height * 1) + data = xbox.read(AGP_MEMORY_BASE | offset, width * height * 1) img = Image.frombytes("RGBA", (width, height), data, "bcn", 2) # DXT3 elif fmt_color == 0xF: # DXT5 - data = xbox.read(0x80000000 | offset, width * height * 1) + data = xbox.read(AGP_MEMORY_BASE | offset, width * height * 1) img = Image.frombytes("RGBA", (width, height), data, "bcn", 3) # DXT5 elif fmt_color == 0x10: tex_info = (False, A1R5G5B5) @@ -304,7 +312,7 @@ def dump_texture(xbox, offset, pitch, fmt_color, width, height): pitch = width * bits_per_pixel // 8 # FIXME: Might want to skip the empty area if pitch and width diverge? - data = xbox.read(0x80000000 | offset, pitch * height) + data = xbox.read(AGP_MEMORY_BASE | offset, pitch * height) img = _decode_texture( data, (width, height), diff --git a/nv2a-trace.py b/nv2a-trace.py index ff360a4..2d66336 100755 --- a/nv2a-trace.py +++ b/nv2a-trace.py @@ -19,7 +19,8 @@ import Trace # pylint: disable=invalid-name -_enable_experimental_disable_z_compression_and_tiling = True +# TODO: Remove tiling suppression once AGP read in Texture.py is fully proven. +_enable_experimental_disable_z_compression_and_tiling = False # pylint: enable=invalid-name