From 40497ca3a907e734b2dab95c83540bb7bfec14dc Mon Sep 17 00:00:00 2001 From: sarbes Date: Sat, 24 May 2025 01:58:07 +0200 Subject: [PATCH] lima: genxml-ify PP frame registers Most (all?) PP frame registers are now documented in genxml. Most of the magic values written to the registers are gone. v2: - moved default values out of genxml - commented on stencil truncation v3: - fixed comment typo Reviewed-by: Vasily Khoruzhick Part-of: --- src/gallium/drivers/lima/genxml/common.xml | 65 +++++++++++++ src/gallium/drivers/lima/lima_draw.c | 18 ++-- src/gallium/drivers/lima/lima_format.c | 42 +++++---- src/gallium/drivers/lima/lima_format.h | 3 +- src/gallium/drivers/lima/lima_job.c | 101 +++++++++++---------- src/gallium/drivers/lima/lima_job.h | 8 +- 6 files changed, 155 insertions(+), 82 deletions(-) diff --git a/src/gallium/drivers/lima/genxml/common.xml b/src/gallium/drivers/lima/genxml/common.xml index 80c809c273b..d28897fcf7a 100644 --- a/src/gallium/drivers/lima/genxml/common.xml +++ b/src/gallium/drivers/lima/genxml/common.xml @@ -54,6 +54,11 @@ + + + + + @@ -101,4 +106,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/gallium/drivers/lima/lima_draw.c b/src/gallium/drivers/lima/lima_draw.c index c12f2dbc6a0..378cb7bd0cc 100644 --- a/src/gallium/drivers/lima/lima_draw.c +++ b/src/gallium/drivers/lima/lima_draw.c @@ -172,17 +172,10 @@ lima_clear(struct pipe_context *pctx, unsigned buffers, const struct pipe_scisso clear->buffers = buffers; if (buffers & PIPE_CLEAR_COLOR0) { - clear->color_8pc = - ((uint32_t)float_to_ubyte(color->f[3]) << 24) | - ((uint32_t)float_to_ubyte(color->f[2]) << 16) | - ((uint32_t)float_to_ubyte(color->f[1]) << 8) | - float_to_ubyte(color->f[0]); - - clear->color_16pc = - ((uint64_t)float_to_ushort(color->f[3]) << 48) | - ((uint64_t)float_to_ushort(color->f[2]) << 32) | - ((uint64_t)float_to_ushort(color->f[1]) << 16) | - float_to_ushort(color->f[0]); + clear->color[0] = color->f[0]; + clear->color[1] = color->f[1]; + clear->color[2] = color->f[2]; + clear->color[3] = color->f[3]; } struct lima_surface *zsbuf = lima_surface(ctx->framebuffer.fb_zsbuf); @@ -194,7 +187,8 @@ lima_clear(struct pipe_context *pctx, unsigned buffers, const struct pipe_scisso } if (buffers & PIPE_CLEAR_STENCIL) { - clear->stencil = stencil; + // the provided stencil value seems to be 16 bit, truncate + clear->stencil = stencil & 0xFF; if (zsbuf) zsbuf->reload &= ~PIPE_CLEAR_STENCIL; } diff --git a/src/gallium/drivers/lima/lima_format.c b/src/gallium/drivers/lima/lima_format.c index ff09ab3b8b2..0c7e0691acc 100644 --- a/src/gallium/drivers/lima/lima_format.c +++ b/src/gallium/drivers/lima/lima_format.c @@ -49,7 +49,7 @@ struct lima_format { int format; bool swap_r_b; union { - uint32_t channel_layout; + struct LIMA_TILEBUFFER_CHANNEL_LAYOUT channel_layout; uint8_t swizzle[4]; }; }; @@ -61,6 +61,10 @@ struct lima_format { PIPE_SWIZZLE_##w \ } +#define LAYOUT(a,b,g,r) { \ + r, g, b, a \ +} + #define LIMA_TEXEL_FORMAT(pipe, tex, swap, swiz) \ [PIPE_FORMAT_##pipe] = { \ .present = true, .format = LIMA_TEXEL_FORMAT_##tex, \ @@ -105,23 +109,23 @@ static const struct lima_format lima_texel_formats[] = { }; static const struct lima_format lima_pixel_formats[] = { - LIMA_PIXEL_FORMAT(R8G8B8A8_UNORM, B8G8R8A8, true, 0x8888), - LIMA_PIXEL_FORMAT(B8G8R8A8_UNORM, B8G8R8A8, false, 0x8888), - LIMA_PIXEL_FORMAT(R8G8B8A8_SRGB, B8G8R8A8, true, 0x8888), - LIMA_PIXEL_FORMAT(B8G8R8A8_SRGB, B8G8R8A8, false, 0x8888), - LIMA_PIXEL_FORMAT(R8G8B8X8_UNORM, B8G8R8A8, true, 0x8888), - LIMA_PIXEL_FORMAT(B8G8R8X8_UNORM, B8G8R8A8, false, 0x8888), - LIMA_PIXEL_FORMAT(B5G6R5_UNORM, B5G6R5, false, 0x8565), - LIMA_PIXEL_FORMAT(B5G5R5A1_UNORM, B5G5R5A1, false, 0x8565), - LIMA_PIXEL_FORMAT(B4G4R4A4_UNORM, B4G4R4A4, false, 0x8444), - LIMA_PIXEL_FORMAT(R8_UNORM, B8, true, 0x8888), - LIMA_PIXEL_FORMAT(R8G8_UNORM, G8B8, true, 0x8888), - LIMA_PIXEL_FORMAT(Z16_UNORM, Z16, false, 0x0000), - LIMA_PIXEL_FORMAT(Z24_UNORM_S8_UINT, Z24S8, false, 0x0000), - LIMA_PIXEL_FORMAT(Z24X8_UNORM, Z24S8, false, 0x0000), - LIMA_PIXEL_FORMAT(R16G16B16A16_FLOAT, B16G16R16A16_FLOAT, true, 0x0000), - LIMA_PIXEL_FORMAT(R16_FLOAT, B16_FLOAT, true, 0x0000), - LIMA_PIXEL_FORMAT(R16G16_FLOAT, G16B16_FLOAT, true, 0x0000), + LIMA_PIXEL_FORMAT(R8G8B8A8_UNORM, B8G8R8A8, true, LAYOUT(8, 8, 8, 8)), + LIMA_PIXEL_FORMAT(B8G8R8A8_UNORM, B8G8R8A8, false, LAYOUT(8, 8, 8, 8)), + LIMA_PIXEL_FORMAT(R8G8B8A8_SRGB, B8G8R8A8, true, LAYOUT(8, 8, 8, 8)), + LIMA_PIXEL_FORMAT(B8G8R8A8_SRGB, B8G8R8A8, false, LAYOUT(8, 8, 8, 8)), + LIMA_PIXEL_FORMAT(R8G8B8X8_UNORM, B8G8R8A8, true, LAYOUT(8, 8, 8, 8)), + LIMA_PIXEL_FORMAT(B8G8R8X8_UNORM, B8G8R8A8, false, LAYOUT(8, 8, 8, 8)), + LIMA_PIXEL_FORMAT(B5G6R5_UNORM, B5G6R5, false, LAYOUT(8, 5, 6, 5)), + LIMA_PIXEL_FORMAT(B5G5R5A1_UNORM, B5G5R5A1, false, LAYOUT(8, 5, 6, 5)), + LIMA_PIXEL_FORMAT(B4G4R4A4_UNORM, B4G4R4A4, false, LAYOUT(8, 4, 4, 4)), + LIMA_PIXEL_FORMAT(R8_UNORM, B8, true, LAYOUT(8, 8, 8, 8)), + LIMA_PIXEL_FORMAT(R8G8_UNORM, G8B8, true, LAYOUT(0, 0, 0, 0)), + LIMA_PIXEL_FORMAT(Z16_UNORM, Z16, false, LAYOUT(0, 0, 0, 0)), + LIMA_PIXEL_FORMAT(Z24_UNORM_S8_UINT, Z24S8, false, LAYOUT(0, 0, 0, 0)), + LIMA_PIXEL_FORMAT(Z24X8_UNORM, Z24S8, false, LAYOUT(0, 0, 0, 0)), + LIMA_PIXEL_FORMAT(R16G16B16A16_FLOAT, B16G16R16A16_FLOAT, true, LAYOUT(0, 0, 0, 0)), + LIMA_PIXEL_FORMAT(R16_FLOAT, B16_FLOAT, true, LAYOUT(0, 0, 0, 0)), + LIMA_PIXEL_FORMAT(R16G16_FLOAT, G16B16_FLOAT, true, LAYOUT(0, 0, 0, 0)), }; static const struct lima_format * @@ -208,7 +212,7 @@ lima_format_get_texel_swizzle(enum pipe_format f) return lima_texel_formats[f].swizzle; } -uint32_t +struct LIMA_TILEBUFFER_CHANNEL_LAYOUT lima_format_get_channel_layout(enum pipe_format f) { return lima_pixel_formats[f].channel_layout; diff --git a/src/gallium/drivers/lima/lima_format.h b/src/gallium/drivers/lima/lima_format.h index 781f77e38e9..8eec2800296 100644 --- a/src/gallium/drivers/lima/lima_format.h +++ b/src/gallium/drivers/lima/lima_format.h @@ -27,6 +27,7 @@ #include #include +#include "lima_pack.h" bool lima_format_texel_supported(enum pipe_format f); bool lima_format_pixel_supported(enum pipe_format f); @@ -36,6 +37,6 @@ int lima_format_get_texel_reload(enum pipe_format f); bool lima_format_get_texel_swap_rb(enum pipe_format f); bool lima_format_get_pixel_swap_rb(enum pipe_format f); const uint8_t *lima_format_get_texel_swizzle(enum pipe_format f); -uint32_t lima_format_get_channel_layout(enum pipe_format f); +struct LIMA_TILEBUFFER_CHANNEL_LAYOUT lima_format_get_channel_layout(enum pipe_format f); #endif diff --git a/src/gallium/drivers/lima/lima_job.c b/src/gallium/drivers/lima/lima_job.c index 5084910f9c5..da786db16d2 100644 --- a/src/gallium/drivers/lima/lima_job.c +++ b/src/gallium/drivers/lima/lima_job.c @@ -47,6 +47,7 @@ #include "lima_fence.h" #include "lima_gpu.h" #include "lima_blit.h" +#include "lima_pack.h" #define VOID2U64(x) ((uint64_t)(unsigned long)(x)) @@ -763,8 +764,7 @@ lima_pack_wb_zsbuf_reg(struct lima_job *job, uint32_t *wb_reg, int wb_idx) } static void -lima_pack_wb_cbuf_reg(struct lima_job *job, uint32_t *frame_reg, - uint32_t *wb_reg, int wb_idx) +lima_pack_wb_cbuf_reg(struct lima_job *job, uint32_t *wb_reg, int wb_idx) { struct lima_job_fb_info *fb = &job->fb; struct pipe_surface *cbuf = job->key.cbuf; @@ -774,9 +774,6 @@ lima_pack_wb_cbuf_reg(struct lima_job *job, uint32_t *frame_reg, uint32_t format = lima_format_get_pixel(cbuf->format); bool swap_channels = lima_format_get_pixel_swap_rb(cbuf->format); - struct lima_pp_frame_reg *frame = (void *)frame_reg; - frame->channel_layout = lima_format_get_channel_layout(cbuf->format); - struct lima_pp_wb_reg *wb = (void *)wb_reg; wb[wb_idx].type = 0x02; /* 2 for color buffer */ wb[wb_idx].address = res->bo->va + res->levels[level].offset + layer * res->levels[level].layer_stride; @@ -804,53 +801,61 @@ lima_pack_pp_frame_reg(struct lima_job *job, uint32_t *frame_reg, struct lima_context *ctx = job->ctx; struct lima_job_fb_info *fb = &job->fb; struct pipe_surface *cbuf = job->key.cbuf; - struct lima_pp_frame_reg *frame = (void *)frame_reg; struct lima_screen *screen = lima_screen(ctx->base.screen); int wb_idx = 0; - frame->render_address = screen->pp_buffer->va + pp_frame_rsw_offset; - frame->flags = 0x02; - if (cbuf && util_format_is_float(cbuf->format)) { - frame->flags |= 0x01; /* enable fp16 */ - frame->clear_value_color = (uint32_t)(job->clear.color_16pc & 0xffffffffUL); - frame->clear_value_color_1 = (uint32_t)(job->clear.color_16pc >> 32); - frame->clear_value_color_2 = 0; - frame->clear_value_color_3 = 0; + lima_pack(frame_reg, PP_FRAME, frame) { + frame.render_address = screen->pp_buffer->va + pp_frame_rsw_offset; + frame.early_z = true; + if (cbuf && util_format_is_float(cbuf->format)) { + frame.fp16_tilebuffer = true; + frame.clear_value_16bpc_color = job->clear.color_16bpc; + } + else { + frame.clear_value_8bpc_color_0 = job->clear.color_8bpc; + frame.clear_value_8bpc_color_1 = job->clear.color_8bpc; + frame.clear_value_8bpc_color_2 = job->clear.color_8bpc; + frame.clear_value_8bpc_color_3 = job->clear.color_8bpc; + } + + frame.clear_value_depth = job->clear.depth; + frame.clear_value_stencil = job->clear.stencil; + frame.origin_x = 1; + + frame.bounding_box_right = fb->width; + frame.bounding_box_bottom = fb->height; + + /* frame.fragment_stack_address is overwritten per-pp in the kernel + * by the values of pp_frame.fragment_stack_address[i] */ + + /* "stack size" and "stack offset" are assumed to be always the same. */ + frame.fragment_stack_size = job->pp_max_stack_size; + frame.fragment_stack_pointer_initial_value = job->pp_max_stack_size; + + /* related with MSAA and different value when r4p0/r7p0 */ + frame.origin_y = fb->height * 2; + frame.scale_fragcoord = true; + frame.scale_derivatives = true; + frame.flip_dithering_matrix = true; + frame.flip_fragcoord = true; + frame.flip_derivatives = true; + + frame.subpixel_specifier = 0x77; + frame.tiebreak_mode = 1; + frame.polygon_tile_amount_x = fb->shift_w; + frame.polygon_tile_amount_y = fb->shift_h; + frame.polygon_tile_size = fb->shift_min; + + frame.tilebuffer_channel_layout.red = 8; + frame.tilebuffer_channel_layout.green = 8; + frame.tilebuffer_channel_layout.blue = 8; + frame.tilebuffer_channel_layout.alpha = 8; + + if (cbuf && (job->resolve & PIPE_CLEAR_COLOR0)) { + frame.tilebuffer_channel_layout = lima_format_get_channel_layout(cbuf->format); + lima_pack_wb_cbuf_reg(job, wb_reg, wb_idx++); + } } - else { - frame->clear_value_color = job->clear.color_8pc; - frame->clear_value_color_1 = job->clear.color_8pc; - frame->clear_value_color_2 = job->clear.color_8pc; - frame->clear_value_color_3 = job->clear.color_8pc; - } - - frame->clear_value_depth = job->clear.depth; - frame->clear_value_stencil = job->clear.stencil; - frame->one = 1; - - frame->width = fb->width - 1; - frame->height = fb->height - 1; - - /* frame->fragment_stack_address is overwritten per-pp in the kernel - * by the values of pp_frame.fragment_stack_address[i] */ - - /* These are "stack size" and "stack offset" shifted, - * here they are assumed to be always the same. */ - frame->fragment_stack_size = job->pp_max_stack_size << 16 | job->pp_max_stack_size; - - /* related with MSAA and different value when r4p0/r7p0 */ - frame->supersampled_height = fb->height * 2 - 1; - frame->scale = 0xE0C; - - frame->dubya = 0x77; - frame->onscreen = 1; - frame->blocking = (fb->shift_min << 28) | (fb->shift_h << 16) | fb->shift_w; - - /* Set default layout to 8888 */ - frame->channel_layout = 0x8888; - - if (cbuf && (job->resolve & PIPE_CLEAR_COLOR0)) - lima_pack_wb_cbuf_reg(job, frame_reg, wb_reg, wb_idx++); if (job->key.zsbuf && (job->resolve & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL))) diff --git a/src/gallium/drivers/lima/lima_job.h b/src/gallium/drivers/lima/lima_job.h index 0eb05a5378c..9c066620ab5 100644 --- a/src/gallium/drivers/lima/lima_job.h +++ b/src/gallium/drivers/lima/lima_job.h @@ -30,6 +30,7 @@ #include #include +#include "lima_pack.h" #define MAX_DRAWS_PER_JOB 2500 @@ -45,10 +46,13 @@ struct lima_job_key { struct lima_job_clear { unsigned buffers; - uint32_t color_8pc; uint32_t depth; uint32_t stencil; - uint64_t color_16pc; + union { + float color[4]; + struct LIMA_CLEAR_VALUE_8BPC_COLOR color_8bpc; + struct LIMA_CLEAR_VALUE_16BPC_COLOR color_16bpc; + }; }; struct lima_job_fb_info {