Skip to content

Commit

Permalink
Read surfaces via AGP
Browse files Browse the repository at this point in the history
  • Loading branch information
abaire authored and mborgerson committed Feb 24, 2022
1 parent bf95d77 commit 159b706
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 12 additions & 4 deletions Texture.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
[
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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),
Expand Down
3 changes: 2 additions & 1 deletion nv2a-trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 159b706

Please sign in to comment.