diff options
author | Vito Caputo <vcaputo@pengaru.com> | 2022-09-04 23:13:36 -0700 |
---|---|---|
committer | Vito Caputo <vcaputo@pengaru.com> | 2022-09-04 23:13:36 -0700 |
commit | b5a2667f6c94d5a275251bf6cc359480100a651c (patch) | |
tree | e68c50d4503a0a063894251b055b4a9a7e6a6713 /src/til_fb.c | |
parent | 7d174878cc27b1319c246913e71cf6ab8fefcb31 (diff) |
til: fixup til_fb_fragment_t.texture fragmenting
Until now when fragmenting with a texture present the texture
pointer was simply copied through to the new logical fragment.
The problem with that is when sampling pixels from the texture in
a nested frame scenario, the locations didn't align with the
placement of the logical fragment.
With this change when the incoming fragment has a texture, the
output fragment gets some uninitialized memory attached in the
outgoing fragment's texture pointer. Then the fragmenter is
expected to do the same populating of res_fragment->texture it
already did for res_fragment, just relative to
fragment->texture->{buf,stride,pitch} etc.
It's a bit hairy/janky because til_fb_fragment_t.texture is just
a pointer to another til_fb_fragment_t. So the ephemeral/logical
fragments fragmenting/tiling produces which tend to just be
sitting on the stack need to get another til_fb_fragment_t
instance somewhere and made available at the ephemeral
til_fb_fragment_t's .texture member. We don't want to be
allocating and freeing these things constantly, so for now I'm
just ad-hoc stowing the pointer of an adjacent on-stack texture
fragment in the .texture member when the incoming fragment has a
texture. But this is gross because the rest of the fragment
contents don't get initialized _at_all_, and currently if the
incoming fragment has no texture the res_fragment->texture member
isn't even initialized. The fragmenters aren't really supposed
to be expecting anything sensible in *res_fragment, but now we're
making use of res_fragment->texture *if* fragment->texture is
set. This is just gross.
So there's a bunch of asserts sprinkled around to help police
this fragility for now, but if someone writes new fragmenters
there's a good chance this will trip them up.
Diffstat (limited to 'src/til_fb.c')
-rw-r--r-- | src/til_fb.c | 58 |
1 files changed, 56 insertions, 2 deletions
diff --git a/src/til_fb.c b/src/til_fb.c index 99bf4d3..536a6f2 100644 --- a/src/til_fb.c +++ b/src/til_fb.c @@ -575,11 +575,38 @@ int til_fb_fragment_slice_single(const til_fb_fragment_t *fragment, unsigned n_f unsigned slice = fragment->height / n_fragments; unsigned yoff = slice * number; + assert(fragment); + assert(res_fragment); + if (yoff >= fragment->height) return 0; + if (fragment->texture) { + assert(res_fragment->texture); + assert(fragment->frame_width == fragment->texture->frame_width); + assert(fragment->frame_height == fragment->texture->frame_height); + assert(fragment->width == fragment->texture->width); + assert(fragment->height == fragment->texture->height); + assert(fragment->x == fragment->texture->x); + assert(fragment->y == fragment->texture->y); + + *(res_fragment->texture) = (til_fb_fragment_t){ + .buf = fragment->texture->buf + yoff * fragment->texture->pitch, + .x = fragment->x, + .y = yoff, + .width = fragment->width, + .height = MIN(fragment->height - yoff, slice), + .frame_width = fragment->frame_width, + .frame_height = fragment->frame_height, + .stride = fragment->texture->stride, + .pitch = fragment->texture->pitch, + .cleared = fragment->texture->cleared, + }; + + } + *res_fragment = (til_fb_fragment_t){ - .texture = fragment->texture, + .texture = fragment->texture ? res_fragment->texture : NULL, .buf = fragment->buf + yoff * fragment->pitch, .x = fragment->x, .y = yoff, @@ -602,6 +629,9 @@ int til_fb_fragment_tile_single(const til_fb_fragment_t *fragment, unsigned tile unsigned w = fragment->width / tile_size, h = fragment->height / tile_size; unsigned x, y, xoff, yoff; + assert(fragment); + assert(res_fragment); + if (w * tile_size < fragment->width) w++; @@ -617,8 +647,32 @@ int til_fb_fragment_tile_single(const til_fb_fragment_t *fragment, unsigned tile xoff = x * tile_size; yoff = y * tile_size; + if (fragment->texture) { + assert(res_fragment->texture); + assert(fragment->frame_width == fragment->texture->frame_width); + assert(fragment->frame_height == fragment->texture->frame_height); + assert(fragment->width == fragment->texture->width); + assert(fragment->height == fragment->texture->height); + assert(fragment->x == fragment->texture->x); + assert(fragment->y == fragment->texture->y); + + *(res_fragment->texture) = (til_fb_fragment_t){ + .buf = fragment->texture->buf + (yoff * fragment->texture->pitch) + (xoff), + .x = fragment->x + xoff, + .y = fragment->y + yoff, + .width = MIN(fragment->width - xoff, tile_size), + .height = MIN(fragment->height - yoff, tile_size), + .frame_width = fragment->frame_width, + .frame_height = fragment->frame_height, + .stride = fragment->texture->stride + (fragment->width - MIN(fragment->width - xoff, tile_size)), + .pitch = fragment->texture->pitch, + .cleared = fragment->texture->cleared, + }; + + } + *res_fragment = (til_fb_fragment_t){ - .texture = fragment->texture, + .texture = fragment->texture ? res_fragment->texture : NULL, .buf = fragment->buf + (yoff * fragment->pitch) + (xoff), .x = fragment->x + xoff, .y = fragment->y + yoff, |