From 8278b236b05b2d2f04439e6bc12766315a95869b Mon Sep 17 00:00:00 2001 From: Icenowy Zheng Date: Sun, 22 Sep 2019 09:37:38 +0800 Subject: [PATCH] lima: fix PLBU viewport configuration 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 Reviewed-by: Qiang Yu --- src/gallium/drivers/lima/lima_context.h | 2 +- src/gallium/drivers/lima/lima_draw.c | 32 ++++++++++++------------- src/gallium/drivers/lima/lima_state.c | 8 +++---- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/gallium/drivers/lima/lima_context.h b/src/gallium/drivers/lima/lima_context.h index cb070f021a2..286f8dc86c2 100644 --- a/src/gallium/drivers/lima/lima_context.h +++ b/src/gallium/drivers/lima/lima_context.h @@ -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; }; diff --git a/src/gallium/drivers/lima/lima_draw.c b/src/gallium/drivers/lima/lima_draw.c index 4fdc10d5ff2..ab7f1b134c2 100644 --- a/src/gallium/drivers/lima/lima_draw.c +++ b/src/gallium/drivers/lima/lima_draw.c @@ -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(); diff --git a/src/gallium/drivers/lima/lima_state.c b/src/gallium/drivers/lima/lima_state.c index 222e21db3fd..fb3b36a4b2b 100644 --- a/src/gallium/drivers/lima/lima_state.c +++ b/src/gallium/drivers/lima/lima_state.c @@ -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]; -- 2.30.2