lima: fix PLBU viewport configuration
authorIcenowy Zheng <icenowy@aosc.io>
Sun, 22 Sep 2019 01:37:38 +0000 (09:37 +0800)
committerIcenowy Zheng <icenowy@aosc.io>
Sun, 22 Sep 2019 07:22:38 +0000 (15:22 +0800)
The PLBU expects the viewport's 4 borders' coordinates, however
currently we're feeding the coordinate of the left-bottom point and the
size to it, which leads to misrendering when the left-bottom point is
not (0,0).

Change the macros for the viewport PLBU command, and the data feed to
it. The code to calculate the 4 borders is ported from Panfrost.

Signed-off-by: Icenowy Zheng <icenowy@aosc.io>
Reviewed-by: Qiang Yu <yuq825@gmail.com>
src/gallium/drivers/lima/lima_context.h
src/gallium/drivers/lima/lima_draw.c
src/gallium/drivers/lima/lima_state.c

index cb070f021a2b2b6c152a020d51877f75298afaf5..286f8dc86c21b2ce690dea142c39a6f042534d16 100644 (file)
@@ -107,7 +107,7 @@ struct lima_context_vertex_buffer {
 
 struct lima_context_viewport_state {
    struct pipe_viewport_state transform;
-   float x, y, width, height;
+   float left, right, bottom, top;
    float near, far;
 };
 
index 4fdc10d5ff25873dfffcc2bc5c913edf9db3bb68..ab7f1b134c243b0732d2fc26cfb40c220b13ad65 100644 (file)
@@ -141,10 +141,10 @@ struct lima_render_state {
 #define PLBU_CMD_BLOCK_STRIDE(block_w) PLBU_CMD((block_w) & 0xff, 0x30000000)
 #define PLBU_CMD_ARRAY_ADDRESS(gp_stream, block_num) \
    PLBU_CMD(gp_stream, 0x28000000 | ((block_num) - 1) | 1)
-#define PLBU_CMD_VIEWPORT_X(v) PLBU_CMD(v, 0x10000107)
-#define PLBU_CMD_VIEWPORT_W(v) PLBU_CMD(v, 0x10000108)
-#define PLBU_CMD_VIEWPORT_Y(v) PLBU_CMD(v, 0x10000105)
-#define PLBU_CMD_VIEWPORT_H(v) PLBU_CMD(v, 0x10000106)
+#define PLBU_CMD_VIEWPORT_LEFT(v) PLBU_CMD(v, 0x10000107)
+#define PLBU_CMD_VIEWPORT_RIGHT(v) PLBU_CMD(v, 0x10000108)
+#define PLBU_CMD_VIEWPORT_BOTTOM(v) PLBU_CMD(v, 0x10000105)
+#define PLBU_CMD_VIEWPORT_TOP(v) PLBU_CMD(v, 0x10000106)
 #define PLBU_CMD_ARRAYS_SEMAPHORE_BEGIN() PLBU_CMD(0x00010002, 0x60000000)
 #define PLBU_CMD_ARRAYS_SEMAPHORE_END() PLBU_CMD(0x00010001, 0x60000000)
 #define PLBU_CMD_PRIMITIVE_SETUP(low_prim, cull, index_size) \
@@ -307,10 +307,10 @@ lima_pack_reload_plbu_cmd(struct lima_context *ctx)
 
    PLBU_CMD_BEGIN(20);
 
-   PLBU_CMD_VIEWPORT_X(0);
-   PLBU_CMD_VIEWPORT_W(fui(fb->base.width));
-   PLBU_CMD_VIEWPORT_Y(0);
-   PLBU_CMD_VIEWPORT_H(fui(fb->base.height));
+   PLBU_CMD_VIEWPORT_LEFT(0);
+   PLBU_CMD_VIEWPORT_RIGHT(fui(fb->base.width));
+   PLBU_CMD_VIEWPORT_BOTTOM(0);
+   PLBU_CMD_VIEWPORT_TOP(fui(fb->base.height));
 
    PLBU_CMD_RSW_VERTEX_ARRAY(
       va + lima_reload_render_state_offset,
@@ -374,10 +374,10 @@ lima_pack_clear_plbu_cmd(struct lima_context *ctx)
 
    PLBU_CMD_BEGIN(22);
 
-   PLBU_CMD_VIEWPORT_X(0);
-   PLBU_CMD_VIEWPORT_W(0x45800000);
-   PLBU_CMD_VIEWPORT_Y(0);
-   PLBU_CMD_VIEWPORT_H(0x45800000);
+   PLBU_CMD_VIEWPORT_LEFT(0);
+   PLBU_CMD_VIEWPORT_RIGHT(0x45800000);
+   PLBU_CMD_VIEWPORT_TOP(0);
+   PLBU_CMD_VIEWPORT_BOTTOM(0x45800000);
 
    struct pipe_scissor_state *scissor = &ctx->scissor;
    PLBU_CMD_SCISSORS(scissor->minx, scissor->maxx, scissor->miny, scissor->maxy);
@@ -858,10 +858,10 @@ lima_pack_plbu_cmd(struct lima_context *ctx, const struct pipe_draw_info *info)
 
    PLBU_CMD_BEGIN(30);
 
-   PLBU_CMD_VIEWPORT_X(fui(ctx->viewport.x));
-   PLBU_CMD_VIEWPORT_W(fui(ctx->viewport.width));
-   PLBU_CMD_VIEWPORT_Y(fui(ctx->viewport.y));
-   PLBU_CMD_VIEWPORT_H(fui(ctx->viewport.height));
+   PLBU_CMD_VIEWPORT_LEFT(fui(ctx->viewport.left));
+   PLBU_CMD_VIEWPORT_RIGHT(fui(ctx->viewport.right));
+   PLBU_CMD_VIEWPORT_BOTTOM(fui(ctx->viewport.bottom));
+   PLBU_CMD_VIEWPORT_TOP(fui(ctx->viewport.top));
 
    if (!info->index_size)
       PLBU_CMD_ARRAYS_SEMAPHORE_BEGIN();
index 222e21db3fdcb2a7402befa6b2aa0d2867f2d108..fb3b36a4b2b8b4c3ef28104ef393e6ea36ee02c1 100644 (file)
@@ -242,10 +242,10 @@ lima_set_viewport_states(struct pipe_context *pctx,
    struct lima_context *ctx = lima_context(pctx);
 
    /* reverse calculate the parameter of glViewport */
-   ctx->viewport.x = viewport->translate[0] - viewport->scale[0];
-   ctx->viewport.y = fabsf(viewport->translate[1] - fabsf(viewport->scale[1]));
-   ctx->viewport.width = viewport->scale[0] * 2;
-   ctx->viewport.height = fabsf(viewport->scale[1] * 2);
+   ctx->viewport.left = viewport->translate[0] - fabsf(viewport->scale[0]);
+   ctx->viewport.right = viewport->translate[0] + fabsf(viewport->scale[0]);
+   ctx->viewport.bottom = viewport->translate[1] - fabsf(viewport->scale[1]);
+   ctx->viewport.top = viewport->translate[1] + fabsf(viewport->scale[1]);
 
    /* reverse calculate the parameter of glDepthRange */
    ctx->viewport.near = viewport->translate[2] - viewport->scale[2];