-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert depth buffer to images #41
base: master
Are you sure you want to change the base?
Conversation
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) |
@@ -54,6 +54,30 @@ | |||
X8R8G8B8 = TextureDescription(32, (8, 8, 8), (16, 8, 0)) | |||
|
|||
|
|||
def f16_to_float(f): | |||
if f == 0x0: |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
@@ -516,6 +518,53 @@ def dump_surfaces(self, _data, *_args): | |||
|
|||
self._save_image(img, no_alpha_path, alpha_path) | |||
|
|||
depth_path = "command%d--depth.png" % (self.command_count) |
There was a problem hiding this comment.
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
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
Z24S8 Depth/Stencil
Z16