RFC: S3/Virge off-by-ones?

Post new patches here!
Post Reply
rene
Posts: 5
Joined: Wed 05 Sep, 2018 1:30 pm

RFC: S3/Virge off-by-ones?

Post by rene » Sat 03 Nov, 2018 6:45 pm

Hi there, opened a new thread under Patches. As mentioned in my previous s3/virge thread writing some new bare metal virge code I realised at least the hardware clipping appears to be off-by-one in the top-most and right-most line of pixels. I did some initial trivial tweaks that fix my test case, but crash at least w/ Descent 2. As I mentioned the virge.pdf SPEC says last pixel drawn, so I hope I read this right, but looking closely in Descent also appears to have the top scan line missing, and the right filled with random, e.g. not correct pixels, WIP: https://svn.exactcode.de/t2/trunk/packa ... irge.patch

given clip 0,0 639, 479 and a triangle start at 479 y_count 480 this
clipped off-by-one?

- René Rebe <rene@exactcode.de>

--- ./src/vid_s3_virge.c.vanilla 2018-11-02 21:34:23.001923446 +0100
+++ ./src/vid_s3_virge.c 2018-11-02 21:36:33.253917430 +0100
@@ -2975,8 +2975,8 @@
z_offset -= s3d_tri->z_str;
y_count -= diff_y;
}
- if ((state->y - y_count) < s3d_tri->clip_t)
- y_count = state->y - s3d_tri->clip_t;
+ if ((state->y + 1 - y_count) < s3d_tri->clip_t)
+ y_count = state->y - s3d_tri->clip_t + 1;
}

for (; y_count > 0; y_count--)
@@ -2990,7 +2990,7 @@
xe--;
}

- if (x != xe && ((x_dir > 0 && x < xe) || (x_dir < 0 && x > xe)))
+ if ((x_dir > 0 && x <= xe) || (x_dir < 0 && x >= xe))
{
uint32_t dest_addr, z_addr;
int dx = (x_dir > 0) ? ((31 - ((state->x1-1) >> 15)) & 0x1f) : (((state->x1-1) >> 15) & 0x1f);
@@ -3069,7 +3069,7 @@
dest_addr = dest_offset + (x * (bpp + 1));
z_addr = z_offset + (x << 1);

- for (; x != xe; x = (x + x_dir) & 0xfff)
+ for (; (x_dir > 0 && x <= xe) || (x_dir < 0 && x >= xe); x = (x + x_dir) & 0xfff)
{
int update = 1;
uint16_t src_z = 0;

Post Reply