From 4a35d4743722911ffa487f135d82eeda6d70b0d2 Mon Sep 17 00:00:00 2001 From: pgm1207 <104554896+pgm1207@users.noreply.github.com> Date: Sat, 21 Nov 2026 13:14:24 +0100 Subject: [PATCH 1/6] vk/soft: apply Vulkan's top-left fill rule on shared edges A sample exactly on an edge was covered by the triangle regardless of which edge it was (w0 == 0 passed the `w0 < 0` test), so two triangles sharing a diagonal both shaded the seam: with blending that is a line along every shared edge, and with the depth test off (translucent UI layers) nothing else settled the tie. Measured on the full-screen quad: 65792 fragments for 65536 pixels, 256 seam samples shaded twice. An edge now owns its samples only when it is a top or left edge in framebuffer coordinates (ey*s > 0, or ey*s == 0 && ex*s > 0), which is the Vulkan fill rule; the seam is covered exactly once (65536). t_soft_frame: full-screen quad with the depth test off must shade 65536 fragments (fails with 65792 before). Golden soft-frame.txt re-blessed: only the `frags` counts change (1056->1024, 4160->4096, 8256->8192 = the non-top-left boundary samples that are no longer double counted); no tile colour changes. Answers CodeRabbit PR #243 (mali_soft.c:445): "assign shared-edge samples to only one triangle". --- vk/src/mali_soft.c | 17 +++++++++++++++++ vk/tests/golden/soft-frame.txt | 10 +++++----- vk/tests/t_soft_frame.c | 15 +++++++++++++++ 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/vk/src/mali_soft.c b/vk/src/mali_soft.c index 12215e0f..1322e63d 100644 --- a/vk/src/mali_soft.c +++ b/vk/src/mali_soft.c @@ -363,6 +363,16 @@ bop(VkBlendOp op, float src, float dst) } } +/* An edge of the triangle as the weight functions traverse it (v_a -> v_b), already multiplied by the sign that makes + * the interior weights positive. In framebuffer coordinates (y grows down) a top edge is horizontal with the interior + * below it, and a left edge runs downwards: those own the samples that lie exactly on them. The other edges must not, + * or the neighbour on the shared edge covers the same sample too. */ +static bool +edge_is_top_left(float ex, float ey) +{ + return ey > 0.0f || (ey == 0.0f && ex > 0.0f); +} + /* ---- one triangle: viewport, cull, scissor, depth, fragment, blend, store ---- */ struct rctx { const struct mali_frame *f; @@ -450,6 +460,13 @@ raster_tri(struct rctx *c, const float clip[3][4], const float vary[3][MALI_SOFT w0 *= iarea; w1 *= iarea; w2 *= iarea; if (w0 < 0 || w1 < 0 || w2 < 0) continue; + /* Vulkan's fill rule: a sample exactly on an edge is covered only when that edge is a top or left edge, so + * two triangles sharing a diagonal cover the seam exactly once instead of both (with blending that is a + * line along every shared edge; with the depth test on the second write usually hid it). */ + if ((w0 == 0 && !edge_is_top_left((sx[2] - sx[1]) * s, (sy[2] - sy[1]) * s)) || + (w1 == 0 && !edge_is_top_left((sx[0] - sx[2]) * s, (sy[0] - sy[2]) * s)) || + (w2 == 0 && !edge_is_top_left((sx[1] - sx[0]) * s, (sy[1] - sy[0]) * s))) + continue; const float zn = w0 * sz[0] + w1 * sz[1] + w2 * sz[2]; /* NDC depth, clipped against [0, 1] */ if (depth_clip && (zn < 0.0f || zn > 1.0f)) continue; diff --git a/vk/tests/golden/soft-frame.txt b/vk/tests/golden/soft-frame.txt index 4018d9c7..6ad52b35 100644 --- a/vk/tests/golden/soft-frame.txt +++ b/vk/tests/golden/soft-frame.txt @@ -81,25 +81,25 @@ case mrt-rt1 128x128 case mrt4-rt1-bgra8 64x64 row0: 000000 000000 row1: 000000 00bf80 - stats draws=1 tris=2 frags=1056 unsupported=0 + stats draws=1 tris=2 frags=1024 unsupported=0 case mrt4-rt2-rgba16f 64x64 row0: 000000 000000 row1: 000000 8040ff - stats draws=1 tris=2 frags=1056 unsupported=0 + stats draws=1 tris=2 frags=1024 unsupported=0 case mrt4-rt3-load-rgba32f 64x64 row0: 4080bf 4080bf row1: 4080bf 808080 - stats draws=1 tris=2 frags=1056 unsupported=0 + stats draws=1 tris=2 frags=1024 unsupported=0 case load-partial 128x128 row0: 0000ff 008080 008080 0000ff row1: 0000ff 008080 008080 0000ff row2: 0000ff 008080 ff0000 ff0000 row3: 0000ff 008080 ff0000 ff0000 - stats draws=1 tris=2 frags=4160 unsupported=0 + stats draws=1 tris=2 frags=4096 unsupported=0 case halves 128x128 row0: 202080 602080 9f2080 df2080 row1: 206080 606080 9f6080 df6080 row2: 209f80 609f80 9f9f80 df9f80 row3: 20df80 60df80 9fdf80 dfdf80 - stats draws=1 tris=2 frags=8256 unsupported=0 + stats draws=1 tris=2 frags=8192 unsupported=0 PASS diff --git a/vk/tests/t_soft_frame.c b/vk/tests/t_soft_frame.c index ba222878..abfd5b8d 100644 --- a/vk/tests/t_soft_frame.c +++ b/vk/tests/t_soft_frame.c @@ -414,6 +414,21 @@ case_rgba8(void) CHECK(scene_init(&s, 256, 256, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_D32_SFLOAT, clear, 1.0f), "init"); CHECK(scene_pipe(&s, &PROG_GRAD, 0, 0, 1, 0xf), "pipe gradient"); CHECK(scene_draw(&s, 0, 6), "draw quad"); + + + /* The quad is two triangles sharing the diagonal through the pixel centres. A sample exactly on a shared edge + * belongs to one triangle only (Vulkan's top-left rule), so with the depth test off - the translucent UI case, + * where nothing else settles the tie - the pass must shade every pixel once: 65536 fragments. Both triangles + * claiming the seam shades the 256 diagonal samples twice (65792), a visible line with blending on. */ + { + CHECK(scene_pipe(&s, &PROG_GRAD, 0, 0, 0, 0xf), "pipe seam"); + CHECK(scene_draw(&s, 0, 6), "draw quad, depth off"); + const struct mali_soft_stats *stq = mali_soft_last(); + CHECK(stq->frags == 256u * 256u, "shared edge shaded once: %u fragments, want 65536 " + "(%u = the shared-edge samples shaded twice)", stq->frags, stq->frags - 256u * 256u + 256u * 256u); + p_DestroyPipeline(dev, s.pipe, NULL); s.pipe = 0; + CHECK(scene_pipe(&s, &PROG_GRAD, 0, 0, 1, 0xf), "pipe gradient again"); + } float c[4]; /* every 32-row band must carry the gradient: a store that drops a block row shows up here */ for (unsigned band = 0; band < 8; band++) { From 38ed0ce34d5e11f4e9d04c83cf7672f541725bf3 Mon Sep 17 00:00:00 2001 From: pgm1207 <104554896+pgm1207@users.noreply.github.com> Date: Sun, 22 Nov 2026 01:02:07 +0100 Subject: [PATCH 2/6] vk/soft: an on-edge sample is decided by the top-left rule, not by a float sign Weights within 1e-6 of zero count as on the edge, so the w<0 reject no longer drops a shared-edge sample that one triangle rounds to -1e-8 while the other sees exactly 0 and its top-left rule also refuses it. Answers the thread on vk/src/mali_soft.c:468. --- vk/src/mali_soft.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/vk/src/mali_soft.c b/vk/src/mali_soft.c index 1322e63d..314f2573 100644 --- a/vk/src/mali_soft.c +++ b/vk/src/mali_soft.c @@ -458,14 +458,20 @@ raster_tri(struct rctx *c, const float clip[3][4], const float vary[3][MALI_SOFT float w1 = ((sx[0] - sx[2]) * (py - sy[2]) - (sy[0] - sy[2]) * (px - sx[2])) * s; float w2 = ((sx[1] - sx[0]) * (py - sy[0]) - (sy[1] - sy[0]) * (px - sx[0])) * s; w0 *= iarea; w1 *= iarea; w2 *= iarea; - if (w0 < 0 || w1 < 0 || w2 < 0) + /* A weight this close to zero is "on the edge", whether the rounding gave it 0 or a few ulps either side: + * the two triangles of a shared edge evaluate that edge from different base vertices, so one can see -1e-8 + * where the other sees exactly 0 - rejecting the first on its sign and the second on the top-left rule left + * the sample covered by neither (CR thread, vk/src/mali_soft.c:468). Every on-edge sample then goes through + * the top-left rule below, which is complementary for the two windings, so exactly one triangle keeps it. */ + const float weps = 1e-6f; + if (w0 < -weps || w1 < -weps || w2 < -weps) continue; /* Vulkan's fill rule: a sample exactly on an edge is covered only when that edge is a top or left edge, so * two triangles sharing a diagonal cover the seam exactly once instead of both (with blending that is a * line along every shared edge; with the depth test on the second write usually hid it). */ - if ((w0 == 0 && !edge_is_top_left((sx[2] - sx[1]) * s, (sy[2] - sy[1]) * s)) || - (w1 == 0 && !edge_is_top_left((sx[0] - sx[2]) * s, (sy[0] - sy[2]) * s)) || - (w2 == 0 && !edge_is_top_left((sx[1] - sx[0]) * s, (sy[1] - sy[0]) * s))) + if ((fabsf(w0) <= weps && !edge_is_top_left((sx[2] - sx[1]) * s, (sy[2] - sy[1]) * s)) || + (fabsf(w1) <= weps && !edge_is_top_left((sx[0] - sx[2]) * s, (sy[0] - sy[2]) * s)) || + (fabsf(w2) <= weps && !edge_is_top_left((sx[1] - sx[0]) * s, (sy[1] - sy[0]) * s))) continue; const float zn = w0 * sz[0] + w1 * sz[1] + w2 * sz[2]; /* NDC depth, clipped against [0, 1] */ if (depth_clip && (zn < 0.0f || zn > 1.0f)) From 523521135b3deadc1824d782525a87f393ea3f9f Mon Sep 17 00:00:00 2001 From: pgm1207 <104554896+pgm1207@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:03:34 +0100 Subject: [PATCH 3/6] vk: classify shared edges before barycentric normalization --- vk/src/mali_soft.c | 34 ++++++++++++++++++++-------------- vk/tests/t_soft_frame.c | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 55 insertions(+), 17 deletions(-) diff --git a/vk/src/mali_soft.c b/vk/src/mali_soft.c index 314f2573..d05dc731 100644 --- a/vk/src/mali_soft.c +++ b/vk/src/mali_soft.c @@ -373,6 +373,18 @@ edge_is_top_left(float ex, float ey) return ey > 0.0f || (ey == 0.0f && ex > 0.0f); } +/* Always evaluate shared endpoints in the same order, so reversed edges are exact + * negatives even when floating-point evaluation rounds. Use framebuffer-space + * values before normalizing by the (different) triangle areas. */ +static double +edge_value(float ax, float ay, float bx, float by, float px, float py) +{ + if (ax > bx || (ax == bx && ay > by)) + return -edge_value(bx, by, ax, ay, px, py); + return ((double)bx - ax) * ((double)py - ay) - + ((double)by - ay) * ((double)px - ax); +} + /* ---- one triangle: viewport, cull, scissor, depth, fragment, blend, store ---- */ struct rctx { const struct mali_frame *f; @@ -454,25 +466,19 @@ raster_tri(struct rctx *c, const float clip[3][4], const float vary[3][MALI_SOFT for (unsigned y = (unsigned)y0; y < ye; y++) { for (unsigned x = (unsigned)x0; x < xe; x++) { const float px = (float)x + 0.5f, py = (float)y + 0.5f; - float w0 = ((sx[2] - sx[1]) * (py - sy[1]) - (sy[2] - sy[1]) * (px - sx[1])) * s; - float w1 = ((sx[0] - sx[2]) * (py - sy[2]) - (sy[0] - sy[2]) * (px - sx[2])) * s; - float w2 = ((sx[1] - sx[0]) * (py - sy[0]) - (sy[1] - sy[0]) * (px - sx[0])) * s; - w0 *= iarea; w1 *= iarea; w2 *= iarea; - /* A weight this close to zero is "on the edge", whether the rounding gave it 0 or a few ulps either side: - * the two triangles of a shared edge evaluate that edge from different base vertices, so one can see -1e-8 - * where the other sees exactly 0 - rejecting the first on its sign and the second on the top-left rule left - * the sample covered by neither (CR thread, vk/src/mali_soft.c:468). Every on-edge sample then goes through - * the top-left rule below, which is complementary for the two windings, so exactly one triangle keeps it. */ - const float weps = 1e-6f; - if (w0 < -weps || w1 < -weps || w2 < -weps) + const double e0 = edge_value(sx[1], sy[1], sx[2], sy[2], px, py) * s; + const double e1 = edge_value(sx[2], sy[2], sx[0], sy[0], px, py) * s; + const double e2 = edge_value(sx[0], sy[0], sx[1], sy[1], px, py) * s; + if (e0 < 0 || e1 < 0 || e2 < 0) continue; /* Vulkan's fill rule: a sample exactly on an edge is covered only when that edge is a top or left edge, so * two triangles sharing a diagonal cover the seam exactly once instead of both (with blending that is a * line along every shared edge; with the depth test on the second write usually hid it). */ - if ((fabsf(w0) <= weps && !edge_is_top_left((sx[2] - sx[1]) * s, (sy[2] - sy[1]) * s)) || - (fabsf(w1) <= weps && !edge_is_top_left((sx[0] - sx[2]) * s, (sy[0] - sy[2]) * s)) || - (fabsf(w2) <= weps && !edge_is_top_left((sx[1] - sx[0]) * s, (sy[1] - sy[0]) * s))) + if ((e0 == 0 && !edge_is_top_left((sx[2] - sx[1]) * s, (sy[2] - sy[1]) * s)) || + (e1 == 0 && !edge_is_top_left((sx[0] - sx[2]) * s, (sy[0] - sy[2]) * s)) || + (e2 == 0 && !edge_is_top_left((sx[1] - sx[0]) * s, (sy[1] - sy[0]) * s))) continue; + const float w0 = (float)(e0 * iarea), w1 = (float)(e1 * iarea), w2 = (float)(e2 * iarea); const float zn = w0 * sz[0] + w1 * sz[1] + w2 * sz[2]; /* NDC depth, clipped against [0, 1] */ if (depth_clip && (zn < 0.0f || zn > 1.0f)) continue; diff --git a/vk/tests/t_soft_frame.c b/vk/tests/t_soft_frame.c index abfd5b8d..8f1300dc 100644 --- a/vk/tests/t_soft_frame.c +++ b/vk/tests/t_soft_frame.c @@ -559,7 +559,7 @@ static const struct mali_soft_program PROG_MRT = {.name = "mrt", .vs = vs_gradie * c == NULL: the corner colours differ so every 32x32 tile of a covered area has its own value). */ static int hand_quad(struct mali_frame *f, const struct mali_hw *hw, const void *vskey, const void *fskey, float x0, float y0, - float x1, float y1, const float *c) + float x1, float y1, const float *c, const float (*vertices)[2]) { uint64_t va; float (*v)[8] = hw->alloc(hw->user, 6 * sizeof *v, 64, &va); @@ -568,7 +568,7 @@ hand_quad(struct mali_frame *f, const struct mali_hw *hw, const void *vskey, con const float cc[4][4] = {{1, 0, 0, 1}, {0, 1, 0, 1}, {0, 0, 1, 1}, {1, 1, 1, 1}}; const unsigned ci[6] = {0, 1, 2, 2, 1, 3}; for (unsigned i = 0; i < 6; i++) { - v[i][0] = px[i][0]; v[i][1] = px[i][1]; v[i][2] = 0.5f; v[i][3] = 1; + v[i][0] = vertices ? vertices[i][0] : px[i][0]; v[i][1] = vertices ? vertices[i][1] : px[i][1]; v[i][2] = 0.5f; v[i][3] = 1; memcpy(&v[i][4], c ? c : cc[ci[i]], 4 * sizeof(float)); if (c) v[i][7] = 1; } @@ -611,13 +611,44 @@ hand_frame(const struct scene *const *rt, unsigned n, const struct mali_att *att } f.area[0] = ax; f.area[1] = ay; f.area[2] = aw; f.area[3] = ah; mali_soft_bind_program(vk, fk, prog); - if (!hand_quad(&f, hw, vk, fk, qx0, qy0, qx1, qy1, col)) { mali_frame_finish(&f); return 0; } + if (!hand_quad(&f, hw, vk, fk, qx0, qy0, qx1, qy1, col, NULL)) { mali_frame_finish(&f); return 0; } const bool ok = mali_soft_frame(hw, &f); mali_frame_finish(&f); CHECK(ok, "soft frame: %s", mali_soft_last()->why); return 1; } +static int +case_unequal_edges(void) +{ + struct scene s; + const float black[4] = {0, 0, 0, 1}, white[4] = {1, 1, 1, 1}; + CHECK(scene_init(&s, 4096, 4, VK_FORMAT_R8G8B8A8_UNORM, 0, black, 1), "init edge scene"); + const struct mali_hw *hw = mali_soft_device_hw(dev); + CHECK(hw, "device hw context"); + struct mali_frame f = {.width = 4096, .height = 4, .samples = 1, .has_colour = true, .ncolour = 1, + .area = {0, 0, 4096, 4}, .colour = {.clear = true, .clear_color = {0, 0, 0, 1}}}; + CHECK(hand_target(&s, &f.colour), "target"); + /* A,C,B and A,B,D: the sample (1024.5,0.5) is just inside the large triangle. */ + const float xy[6][2] = { + {1024.4990234375f, 0}, {3072.5f, 0}, {1024.4990234375f, 4}, + {1024.4990234375f, 0}, {1024.4990234375f, 4}, {1023.4990234375f, 0} + }; + float clip[6][2]; + for (unsigned i = 0; i < 6; i++) { + clip[i][0] = xy[i][0] / 2048.0f - 1.0f; + clip[i][1] = xy[i][1] / 2.0f - 1.0f; + } + mali_soft_bind_program((const void *)&key_mrt_vs, (const void *)&key_mrt_fs, &PROG_MRT); + CHECK(hand_quad(&f, hw, &key_mrt_vs, &key_mrt_fs, 0, 0, 0, 0, white, clip), "triangles"); + CHECK(mali_soft_frame(hw, &f), "edge frame"); + mali_frame_finish(&f); + float c[4]; readpx(&s, 1024, 0, c); + CHECK(c[0] > 0.9f, "unequal-area shared edge lost interior sample: %f", c[0]); + scene_free(&s); + return 1; +} + static int near4(const float c[4], float r, float g, float b) { @@ -785,6 +816,7 @@ main(int argc, char **argv) if (!only || !strcmp(only, "mrt4")) ok &= case_mrt4(); if (!only || !strcmp(only, "load")) ok &= case_load(); if (!only || !strcmp(only, "halves")) ok &= case_halves(); + if (!only || !strcmp(only, "unequal-edges")) ok &= case_unequal_edges(); p_DeviceWaitIdle(dev); printf("%s\n", ok && !g_fail ? "PASS" : "FAILED"); return ok && !g_fail ? 0 : 1; From 8e093f1975f7155c927fcdb596382a8f6a91650a Mon Sep 17 00:00:00 2001 From: pgm1207 <104554896+pgm1207@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:22:12 +0100 Subject: [PATCH 4/6] vk/soft: round the far plane consistently (CodeRabbit #338) --- vk/src/mali_soft.c | 10 ++++++---- vk/tests/t_soft_frame.c | 40 +++++++++++++++++++++++++++++++++++----- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/vk/src/mali_soft.c b/vk/src/mali_soft.c index de7dc580..ad3caee7 100644 --- a/vk/src/mali_soft.c +++ b/vk/src/mali_soft.c @@ -419,8 +419,8 @@ raster_tri(struct rctx *c, const float clip[3][4], const float vary[3][MALI_SOFT sz[i] = clip[i][2] / clip[i][3]; iw[i] = 1.0f / clip[i][3]; } - const float area = (sx[1] - sx[0]) * (sy[2] - sy[0]) - (sx[2] - sx[0]) * (sy[1] - sy[0]); - if (fabsf(area) < 1e-9f) + const double area = edge_value(sx[0], sy[0], sx[1], sy[1], sx[2], sy[2]); + if (fabs(area) < 1e-9) return; /* signed area in framebuffer coordinates (y down): the positive winding is counter-clockwise in NDC */ const bool front = (area > 0.0f) == front_ccw; @@ -435,7 +435,7 @@ raster_tri(struct rctx *c, const float clip[3][4], const float vary[3][MALI_SOFT d->vp[4] + sz[1] * (d->vp[5] - d->vp[4]), d->vp[4] + sz[2] * (d->vp[5] - d->vp[4])}; const float s = area > 0 ? 1.0f : -1.0f; /* make the edge functions positive inside */ - const float iarea = 1.0f / (area * s); + const double iarea = 1.0 / (area * s); int x0 = (int)floorf(fminf(sx[0], fminf(sx[1], sx[2]))); int x1 = (int)ceilf(fmaxf(sx[0], fmaxf(sx[1], sx[2]))); @@ -479,7 +479,9 @@ raster_tri(struct rctx *c, const float clip[3][4], const float vary[3][MALI_SOFT (e2 == 0 && !edge_is_top_left((sx[1] - sx[0]) * s, (sy[1] - sy[0]) * s))) continue; const float w0 = (float)(e0 * iarea), w1 = (float)(e1 * iarea), w2 = (float)(e2 * iarea); - const float zn = w0 * sz[0] + w1 * sz[1] + w2 * sz[2]; /* NDC depth, clipped against [0, 1] */ + /* Anchor interpolation at vertex 0: a constant far-plane depth stays + * exactly 1 even if normalized weights round away from a sum of 1. */ + const float zn = (float)(sz[0] + e1 * iarea * (sz[1] - sz[0]) + e2 * iarea * (sz[2] - sz[0])); if (depth_clip && (zn < 0.0f || zn > 1.0f)) continue; /* the framebuffer depth the test and the store see is the viewport transform of the NDC depth */ diff --git a/vk/tests/t_soft_frame.c b/vk/tests/t_soft_frame.c index 54f451e9..84767567 100644 --- a/vk/tests/t_soft_frame.c +++ b/vk/tests/t_soft_frame.c @@ -559,7 +559,7 @@ static const struct mali_soft_program PROG_MRT = {.name = "mrt", .vs = vs_gradie * c == NULL: the corner colours differ so every 32x32 tile of a covered area has its own value). */ static int hand_quad(struct mali_frame *f, const struct mali_hw *hw, const void *vskey, const void *fskey, float x0, float y0, - float x1, float y1, const float *c, const float (*vertices)[2]) + float x1, float y1, const float *c, const float (*vertices)[2], const float *viewport) { uint64_t va; float (*v)[8] = hw->alloc(hw->user, 6 * sizeof *v, 64, &va); @@ -568,7 +568,7 @@ hand_quad(struct mali_frame *f, const struct mali_hw *hw, const void *vskey, con const float cc[4][4] = {{1, 0, 0, 1}, {0, 1, 0, 1}, {0, 0, 1, 1}, {1, 1, 1, 1}}; const unsigned ci[6] = {0, 1, 2, 2, 1, 3}; for (unsigned i = 0; i < 6; i++) { - v[i][0] = vertices ? vertices[i][0] : px[i][0]; v[i][1] = vertices ? vertices[i][1] : px[i][1]; v[i][2] = 0.5f; v[i][3] = 1; + v[i][0] = vertices ? vertices[i][0] : px[i][0]; v[i][1] = vertices ? vertices[i][1] : px[i][1]; v[i][2] = viewport ? 1.0f : 0.5f; v[i][3] = 1; memcpy(&v[i][4], c ? c : cc[ci[i]], 4 * sizeof(float)); if (c) v[i][7] = 1; } @@ -577,7 +577,8 @@ hand_quad(struct mali_frame *f, const struct mali_hw *hw, const void *vskey, con d.gfx.vs = vskey; d.gfx.fs = fskey; d.gfx.prim = 8; d.gfx.nattr = 2; d.gfx.attr[0] = (struct mali_attr){.binding = 0, .offset = 0, .stride = 32, .vk_format = VK_FORMAT_R32G32B32A32_SFLOAT}; d.gfx.attr[1] = (struct mali_attr){.binding = 0, .offset = 16, .stride = 32, .vk_format = VK_FORMAT_R32G32B32A32_SFLOAT}; - d.vp[2] = (float)f->width; d.vp[3] = (float)f->height; d.vp[5] = 1.0f; + d.vp[2] = (float)f->width; d.vp[3] = (float)f->height; d.vp[5] = 1.0f; + if (viewport) memcpy(d.vp, viewport, 4 * sizeof(float)); d.sc[2] = (int32_t)f->width; d.sc[3] = (int32_t)f->height; d.vb_va[0] = va; d.vb_size[0] = 6 * sizeof *v; d.count = 6; d.instance_count = 1; @@ -611,7 +612,7 @@ hand_frame(const struct scene *const *rt, unsigned n, const struct mali_att *att } f.area[0] = ax; f.area[1] = ay; f.area[2] = aw; f.area[3] = ah; mali_soft_bind_program(vk, fk, prog); - if (!hand_quad(&f, hw, vk, fk, qx0, qy0, qx1, qy1, col, NULL)) { mali_frame_finish(&f); return 0; } + if (!hand_quad(&f, hw, vk, fk, qx0, qy0, qx1, qy1, col, NULL, NULL)) { mali_frame_finish(&f); return 0; } const bool ok = mali_soft_frame(hw, &f); mali_frame_finish(&f); CHECK(ok, "soft frame: %s", mali_soft_last()->why); @@ -640,7 +641,7 @@ case_unequal_edges(void) clip[i][1] = xy[i][1] / 2.0f - 1.0f; } mali_soft_bind_program((const void *)&key_mrt_vs, (const void *)&key_mrt_fs, &PROG_MRT); - CHECK(hand_quad(&f, hw, &key_mrt_vs, &key_mrt_fs, 0, 0, 0, 0, white, clip), "triangles"); + CHECK(hand_quad(&f, hw, &key_mrt_vs, &key_mrt_fs, 0, 0, 0, 0, white, clip, NULL), "triangles"); CHECK(mali_soft_frame(hw, &f), "edge frame"); mali_frame_finish(&f); float c[4]; readpx(&s, 1024, 0, c); @@ -649,6 +650,34 @@ case_unequal_edges(void) return 1; } +static int +case_far_depth_edge(void) +{ + struct scene s; + const float black[4] = {0, 0, 0, 1}, white[4] = {1, 1, 1, 1}; + CHECK(scene_init(&s, 1, 1, VK_FORMAT_R8G8B8A8_UNORM, 0, black, 1), "init far depth scene"); + const struct mali_hw *hw = mali_soft_device_hw(dev); + struct mali_frame f = {.width = 1, .height = 1, .samples = 1, .has_colour = true, .ncolour = 1, + .area = {0, 0, 1, 1}, .colour = {.clear = true, .clear_color = {0, 0, 0, 1}}}; + CHECK(hw && hand_target(&s, &f.colour), "target"); + const float viewport[4] = {-6002, -6001, 8192, 8192}; + const float xy[6][2] = {{0, 0}, {8192, 8191}, {8191, 8189.5f}, + {0, 0}, {8192, 8191}, {8191, 8189.5f}}; + float clip[6][2]; + for (unsigned i = 0; i < 6; i++) { + clip[i][0] = xy[i][0] / 4096.0f - 1.0f; + clip[i][1] = xy[i][1] / 4096.0f - 1.0f; + } + mali_soft_bind_program((const void *)&key_mrt_vs, (const void *)&key_mrt_fs, &PROG_MRT); + CHECK(hand_quad(&f, hw, &key_mrt_vs, &key_mrt_fs, 0, 0, 0, 0, white, clip, viewport), "far triangle"); + CHECK(mali_soft_frame(hw, &f), "far depth frame"); + mali_frame_finish(&f); + float c[4]; readpx(&s, 0, 0, c); + CHECK(c[0] > 0.9f, "far-plane interior sample was clipped: %f", c[0]); + scene_free(&s); + return 1; +} + static int near4(const float c[4], float r, float g, float b) { @@ -910,6 +939,7 @@ main(int argc, char **argv) if (!only || !strcmp(only, "load")) ok &= case_load(); if (!only || !strcmp(only, "halves")) ok &= case_halves(); if (!only || !strcmp(only, "unequal-edges")) ok &= case_unequal_edges(); + if (!only || !strcmp(only, "far-depth-edge")) ok &= case_far_depth_edge(); if (!only || !strcmp(only, "fan")) ok &= case_fan(); p_DeviceWaitIdle(dev); printf("%s\n", ok && !g_fail ? "PASS" : "FAILED"); From 1cf6c725104e43820936914467f912521067fad5 Mon Sep 17 00:00:00 2001 From: pgm1207 <104554896+pgm1207@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:47:54 +0100 Subject: [PATCH 5/6] Test top-left boundary and refresh soft frame goldens --- vk/tests/golden/soft-frame.txt | 20 ++++++++++---------- vk/tests/t_soft_frame.c | 23 +++++++++++++++++++++++ 2 files changed, 33 insertions(+), 10 deletions(-) diff --git a/vk/tests/golden/soft-frame.txt b/vk/tests/golden/soft-frame.txt index 3d4f0739..95c0f8be 100644 --- a/vk/tests/golden/soft-frame.txt +++ b/vk/tests/golden/soft-frame.txt @@ -81,37 +81,37 @@ case mrt-rt1 128x128 case mrt4-rt1-bgra8 64x64 row0: 000000 000000 row1: 000000 00bf80 - stats draws=1 tris=2 frags=1056 unsupported=0 + stats draws=1 tris=2 frags=1024 unsupported=0 case mrt4-rt2-rgba16f 64x64 row0: 000000 000000 row1: 000000 8040ff - stats draws=1 tris=2 frags=1056 unsupported=0 + stats draws=1 tris=2 frags=1024 unsupported=0 case mrt4-rt3-load-rgba32f 64x64 row0: 4080bf 4080bf row1: 4080bf 808080 - stats draws=1 tris=2 frags=1056 unsupported=0 + stats draws=1 tris=2 frags=1024 unsupported=0 case mrt-blend-rt1-rgba16f 64x64 row0: 804020 804020 - row1: 804020 b4daff - stats draws=1 tris=2 frags=1056 unsupported=0 + row1: 804020 b2d9ff + stats draws=1 tris=2 frags=1024 unsupported=0 case mrt-blend-rt2-constant 64x64 row0: 0d2640 0d2640 row1: 0d2640 592d08 - stats draws=1 tris=2 frags=1056 unsupported=0 + stats draws=1 tris=2 frags=1024 unsupported=0 case mrt-blend-rt3-subtract 64x64 row0: e6e6e6 e6e6e6 - row1: e6e6e6 e6e698 - stats draws=1 tris=2 frags=1056 unsupported=0 + row1: e6e6e6 e6e69a + stats draws=1 tris=2 frags=1024 unsupported=0 case load-partial 128x128 row0: 0000ff 008080 008080 0000ff row1: 0000ff 008080 008080 0000ff row2: 0000ff 008080 ff0000 ff0000 row3: 0000ff 008080 ff0000 ff0000 - stats draws=1 tris=2 frags=4160 unsupported=0 + stats draws=1 tris=2 frags=4096 unsupported=0 case halves 128x128 row0: 202080 602080 9f2080 df2080 row1: 206080 606080 9f6080 df6080 row2: 209f80 609f80 9f9f80 df9f80 row3: 20df80 60df80 9fdf80 dfdf80 - stats draws=1 tris=2 frags=8256 unsupported=0 + stats draws=1 tris=2 frags=8192 unsupported=0 PASS diff --git a/vk/tests/t_soft_frame.c b/vk/tests/t_soft_frame.c index a69704d4..9a18499f 100644 --- a/vk/tests/t_soft_frame.c +++ b/vk/tests/t_soft_frame.c @@ -669,6 +669,28 @@ case_unequal_edges(void) return 1; } +static int +case_left_edge(void) +{ + struct scene s; + const float black[4] = {0, 0, 0, 1}, white[4] = {1, 1, 1, 1}; + CHECK(scene_init(&s, 4, 4, VK_FORMAT_R8G8B8A8_UNORM, 0, black, 1), "init left edge scene"); + const struct mali_hw *hw = mali_soft_device_hw(dev); + struct mali_frame f = {.width = 4, .height = 4, .samples = 1, .has_colour = true, .ncolour = 1, + .area = {0, 0, 4, 4}, .colour = {.clear = true, .clear_color = {0, 0, 0, 1}}}; + CHECK(hw && hand_target(&s, &f.colour), "target"); + mali_soft_bind_program((const void *)&key_mrt_vs, (const void *)&key_mrt_fs, &PROG_MRT); + CHECK(hand_quad(&f, hw, &key_mrt_vs, &key_mrt_fs, -.75f, -.75f, .25f, .25f, + white, NULL, 0, NULL, NULL), "quad"); + CHECK(mali_soft_frame(hw, &f), "left edge frame"); + mali_frame_finish(&f); + float c[4]; + readpx(&s, 0, 1, c); CHECK(c[0] > .9f, "left edge excluded: %f", c[0]); + readpx(&s, 2, 1, c); CHECK(c[0] < .1f, "right edge included: %f", c[0]); + scene_free(&s); + return 1; +} + static int case_far_depth_edge(void) { @@ -1036,6 +1058,7 @@ main(int argc, char **argv) if (!only || !strcmp(only, "halves")) ok &= case_halves(); if (!only || !strcmp(only, "unequal-edges")) ok &= case_unequal_edges(); if (!only || !strcmp(only, "far-depth-edge")) ok &= case_far_depth_edge(); + if (!only || !strcmp(only, "left-edge")) ok &= case_left_edge(); if (!only || !strcmp(only, "fan")) ok &= case_fan(); p_DeviceWaitIdle(dev); printf("%s\n", ok && !g_fail ? "PASS" : "FAILED"); From 4cb6f2d624d282e372c9cea2ea565e824404e9b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pablo=20Gonz=C3=A1lez?= <104554896+pablogonz12@users.noreply.github.com> Date: Thu, 3 Dec 2026 14:38:48 +0000 Subject: [PATCH 6/6] vk/tests: verify the depth-enabled gradient before the seam draw --- vk/tests/t_soft_frame.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/vk/tests/t_soft_frame.c b/vk/tests/t_soft_frame.c index 9a18499f..ccd968d3 100644 --- a/vk/tests/t_soft_frame.c +++ b/vk/tests/t_soft_frame.c @@ -414,21 +414,6 @@ case_rgba8(void) CHECK(scene_init(&s, 256, 256, VK_FORMAT_R8G8B8A8_UNORM, VK_FORMAT_D32_SFLOAT, clear, 1.0f), "init"); CHECK(scene_pipe(&s, &PROG_GRAD, 0, 0, 1, 0xf), "pipe gradient"); CHECK(scene_draw(&s, 0, 6), "draw quad"); - - - /* The quad is two triangles sharing the diagonal through the pixel centres. A sample exactly on a shared edge - * belongs to one triangle only (Vulkan's top-left rule), so with the depth test off - the translucent UI case, - * where nothing else settles the tie - the pass must shade every pixel once: 65536 fragments. Both triangles - * claiming the seam shades the 256 diagonal samples twice (65792), a visible line with blending on. */ - { - CHECK(scene_pipe(&s, &PROG_GRAD, 0, 0, 0, 0xf), "pipe seam"); - CHECK(scene_draw(&s, 0, 6), "draw quad, depth off"); - const struct mali_soft_stats *stq = mali_soft_last(); - CHECK(stq->frags == 256u * 256u, "shared edge shaded once: %u fragments, want 65536 " - "(%u = the shared-edge samples shaded twice)", stq->frags, stq->frags - 256u * 256u + 256u * 256u); - p_DestroyPipeline(dev, s.pipe, NULL); s.pipe = 0; - CHECK(scene_pipe(&s, &PROG_GRAD, 0, 0, 1, 0xf), "pipe gradient again"); - } float c[4]; /* every 32-row band must carry the gradient: a store that drops a block row shows up here */ for (unsigned band = 0; band < 8; band++) { @@ -441,6 +426,15 @@ case_rgba8(void) CHECK(c[1] > 0.9f && c[0] < 0.1f, "bottom-left is not the green gradient corner: %f,%f,%f", c[0], c[1], c[2]); tilemap("rgba8-gradient", &s); p_DestroyPipeline(dev, s.pipe, NULL); s.pipe = 0; + + /* The shared diagonal crosses 256 pixel centres. With depth testing off, shading it twice yields 65792 + * fragments, while Vulkan's top-left rule gives exactly one fragment per pixel. */ + CHECK(scene_pipe(&s, &PROG_GRAD, 0, 0, 0, 0xf), "pipe seam"); + CHECK(scene_draw(&s, 0, 6), "draw quad, depth off"); + const unsigned seam_frags = mali_soft_last()->frags; + CHECK(seam_frags == s.w * s.h, "shared edge shaded once: %u fragments, want %u", seam_frags, s.w * s.h); + p_DestroyPipeline(dev, s.pipe, NULL); s.pipe = 0; + /* depth, one pass: far red (z .9), near green (z .1), far blue (z .9) again -> the centre stays green */ CHECK(scene_pipe(&s, &PROG_COL, 0, 0, 1, 0xf), "pipe colour"); const unsigned df[3] = {RED, GREEN, BLUE}, dc[3] = {3, 3, 3};