Skip to content

Conversation

@antangelo
Copy link

Produces an image representation of the depth and stencil buffers. I don't have any games that use float mode or swizzling (to my knowledge), so I'm unable to test those formats.

Z24S8 Depth
command1214--depth

Z24S8 Depth/Stencil
command2--depth

command2--stencil

Z16
command211--depth

@abaire
Copy link
Contributor

abaire commented Apr 13, 2022

The pgraph tester has tests for float depth modes (you'll just need to reenable the d24s8 one that can't be run on xemu: https://github.com/abaire/nxdk_pgraph_tests/blob/main/src/tests/depth_format_tests.cpp#L21)



def f16_to_float(f):
if f == 0x0:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: if not f: would be more pythonic (here and below)

depth_img = Image.new("RGB", (width, height))
stencil_img = None

if fmt_depth == 0x2D:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use symbolic names for these rather than the raw values?


assert len(data) == pitch * height

# FIXME: Does this work?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's just remove this since it's never invoked.


for y in range(height):
for x in range(width):
pixel_offset = y * pitch + x * fmt.bpp // 8
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think python implementations do a superb job of optimizing, I'd extract out some of these values that don't change.

E.g., move the y * pitch out of the x loop, move fmt.bpp // 8 out of the loops entirely

depth = fmt.convert_float(depth)

depth_values[x, y] = depth
stencil_values[x, y] = 255 if stencil != 0 else 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think you can drop the explicit != 0

depth_max -= depth_min
depth_scaler = 255 / depth_max if depth_max > 0 else 255
depth_pixels = depth_img.load()
if stencil_img is not None:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I don't think you need to explicitly check against None here, just if stencil_img would be more pythonic since anything falsey is not going to be callable.


self._save_image(img, no_alpha_path, alpha_path)

depth_path = "command%d--depth.png" % (self.command_count)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Depending on whether this goes in before or after #42 we'll want to expand this path to capture the draw count and depth_offset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants