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 <anarsoul@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34210>
This commit is contained in:
sarbes
2025-05-24 01:58:07 +02:00
committed by Marge Bot
parent eb61a607d8
commit 40497ca3a9
6 changed files with 155 additions and 82 deletions

View File

@@ -54,6 +54,11 @@
<value name="Linear" value="0"/>
<value name="Tiled" value="3"/>
</enum>
<enum name="Polygon Tile Size">
<value name="1x1" value="0"/>
<value name="2x2" value="1"/>
<value name="4x4" value="2"/>
</enum>
<struct name="Texture Descriptor" size="64">
<field name="Texel Format" start="0:0" size="6" type="Texel Format"/>
<field name="Reverse Component Order" start="0:6" size="1" type="bool"/>
@@ -101,4 +106,64 @@
<field name="Mip 10" start="15:2" size="26" type="hex" modifier="shr(6)"/>
<field name="Unknown 6" start="15:28" size="4" type="hex"/>
</struct>
<struct name="Clear Value 8bpc Color" size="4">
<field name="Red" start="0" size="8" type="unorm8"/>
<field name="Green" start="8" size="8" type="unorm8"/>
<field name="Blue" start="16" size="8" type="unorm8"/>
<field name="Alpha" start="24" size="8" type="unorm8"/>
</struct>
<struct name="Clear Value 16bpc Color" size="8">
<field name="Red" start="0:0" size="16" type="unorm16"/>
<field name="Green" start="0:16" size="16" type="unorm16"/>
<field name="Blue" start="1:0" size="16" type="unorm16"/>
<field name="Alpha" start="1:16" size="16" type="unorm16"/>
</struct>
<struct name="Tilebuffer Channel Layout" size="2">
<field name="Red" start="0" size="4" type="uint"/>
<field name="Green" start="4" size="4" type="uint"/>
<field name="Blue" start="8" size="4" type="uint"/>
<field name="Alpha" start="12" size="4" type="uint"/>
</struct>
<struct name="PP Frame" size="92">
<field name="PLBU Array Address" start="0:3" size="29" type="uint" modifier="shr(3)"/>
<field name="Render Address" start="1:6" size="26" type="uint" modifier="shr(6)"/>
<field name="Vertex Address" start="2:6" size="26" type="uint" modifier="shr(6)"/>
<field name="FP16 Tilebuffer" start="3:0" size="1" type="bool"/>
<field name="Early Z" start="3:1" size="1" type="bool"/>
<field name="Early Z 1 Disable" start="3:3" size="1" type="bool"/>
<field name="Early Z 2 Disable" start="3:4" size="1" type="bool"/>
<field name="Origin Lower Left" start="3:5" size="1" type="bool"/>
<field name="Quad Cover Summation" start="3:6" size="1" type="bool"/>
<field name="Clear Value Depth" start="4:0" size="24" type="uint"/>
<field name="Clear Value Stencil" start="5:0" size="8" type="uint"/>
<field name="Clear Value 16bpc Color" start="6:0" size="64" type="Clear Value 16bpc Color"/>
<field name="Clear Value 8bpc Color 0" start="6:0" size="32" type="Clear Value 8bpc Color"/>
<field name="Clear Value 8bpc Color 1" start="7:0" size="32" type="Clear Value 8bpc Color"/>
<field name="Clear Value 8bpc Color 2" start="8:0" size="32" type="Clear Value 8bpc Color"/>
<field name="Clear Value 8bpc Color 3" start="9:0" size="32" type="Clear Value 8bpc Color"/>
<field name="Bounding Box Right" start="10:0" size="14" type="uint" modifier="minus(1)"/>
<field name="Bounding Box Left" start="10:16" size="4" type="uint"/>
<field name="Bounding Box Bottom" start="11:0" size="14" type="uint" modifier="minus(1)"/>
<field name="Fragment Stack Address" start="12:6" size="26" type="hex" modifier="shr(6)"/>
<field name="Fragment Stack Size" start="13:0" size="16" type="uint"/>
<field name="Fragment Stack Pointer Initial Value" start="13:16" size="16" type="hex"/>
<field name="Origin X" start="16:0" size="16" type="uint"/>
<field name="Origin Y" start="17:0" size="16" type="uint" modifier="minus(1)"/>
<field name="Subpixel Specifier" start="18:0" size="8" type="uint"/>
<field name="Tiebreak Mode" start="19:0" size="2" type="uint"/>
<field name="Polygon Tile Amount X" start="20:0" size="6" type="uint"/>
<field name="Polygon Tile Amount Y" start="20:16" size="6" type="uint"/>
<field name="Polygon Tile Size" start="20:28" size="2" type="Polygon Tile Size"/>
<field name="Scale Points and Lines" start="21:0" size="1" type="bool"/>
<field name="Scale Dithering Matrix" start="21:1" size="1" type="bool"/>
<field name="Scale Fragcoord" start="21:2" size="1" type="bool"/>
<field name="Scale Derivatives" start="21:3" size="1" type="bool"/>
<field name="Flip Sprites" start="21:8" size="1" type="bool"/>
<field name="Flip Dithering Matrix" start="21:9" size="1" type="bool"/>
<field name="Flip Fragcoord" start="21:10" size="1" type="bool"/>
<field name="Flip Derivatives" start="21:11" size="1" type="bool"/>
<field name="Scale Factor X" start="21:16" size="3" type="uint"/>
<field name="Scale Factor Y" start="21:20" size="3" type="uint"/>
<field name="Tilebuffer Channel Layout" start="22:0" size="16" type="Tilebuffer Channel Layout"/>
</struct>
</genxml>

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -27,6 +27,7 @@
#include <stdbool.h>
#include <util/format/u_formats.h>
#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

View File

@@ -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)))

View File

@@ -30,6 +30,7 @@
#include <util/u_dynarray.h>
#include <pipe/p_state.h>
#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 {