From 6998c48f778127760def06b6542e17f47899f9c5 Mon Sep 17 00:00:00 2001 From: Vasily Khoruzhick Date: Wed, 23 Aug 2023 11:51:07 -0700 Subject: [PATCH] lima: ppir: use dummy program if FS has empty body As per spec, any colors, or color components, associated with a fragment that are not written by the fragment shader are undefined. So we might as well just write vec4(1.0) to output, since HW doesn't allow us to have an empty FS. Backport-to: 23.3 Backport-to: 24.0 Reviewed-by: Erico Nunes Part-of: --- src/gallium/drivers/lima/lima_program.c | 14 ++++++++++++-- src/gallium/drivers/lima/lima_screen.c | 4 +--- src/gallium/drivers/lima/lima_screen.h | 5 +++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/gallium/drivers/lima/lima_program.c b/src/gallium/drivers/lima/lima_program.c index 2d6dd4c9944..0ef3ebbfc98 100644 --- a/src/gallium/drivers/lima/lima_program.c +++ b/src/gallium/drivers/lima/lima_program.c @@ -323,15 +323,25 @@ static bool lima_fs_upload_shader(struct lima_context *ctx, struct lima_fs_compiled_shader *fs) { + static const uint32_t pp_clear_program[] = { + PP_CLEAR_PROGRAM + }; + int shader_size = sizeof(pp_clear_program); + void *shader = (void *)pp_clear_program; struct lima_screen *screen = lima_screen(ctx->base.screen); - fs->bo = lima_bo_create(screen, fs->state.shader_size, 0); + if (fs->state.shader_size) { + shader_size = fs->state.shader_size; + shader = fs->shader; + } + + fs->bo = lima_bo_create(screen, shader_size, 0); if (!fs->bo) { fprintf(stderr, "lima: create fs shader bo fail\n"); return false; } - memcpy(lima_bo_map(fs->bo), fs->shader, fs->state.shader_size); + memcpy(lima_bo_map(fs->bo), shader, shader_size); return true; } diff --git a/src/gallium/drivers/lima/lima_screen.c b/src/gallium/drivers/lima/lima_screen.c index 8a58b5c6b2b..2e779693d0e 100644 --- a/src/gallium/drivers/lima/lima_screen.c +++ b/src/gallium/drivers/lima/lima_screen.c @@ -692,11 +692,9 @@ lima_screen_create(int fd, const struct pipe_screen_config *config, screen->pp_buffer->cacheable = false; /* fs program for clear buffer? - * const0 1 0 0 -1.67773, mov.v0 $0 ^const0.xxxx, stop */ static const uint32_t pp_clear_program[] = { - 0x00020425, 0x0000000c, 0x01e007cf, 0xb0000000, - 0x000005f5, 0x00000000, 0x00000000, 0x00000000, + PP_CLEAR_PROGRAM }; memcpy(lima_bo_map(screen->pp_buffer) + pp_clear_program_offset, pp_clear_program, sizeof(pp_clear_program)); diff --git a/src/gallium/drivers/lima/lima_screen.h b/src/gallium/drivers/lima/lima_screen.h index 82800052b15..5f76edd551a 100644 --- a/src/gallium/drivers/lima/lima_screen.h +++ b/src/gallium/drivers/lima/lima_screen.h @@ -60,6 +60,11 @@ struct ra_regs; #define NR_BO_CACHE_BUCKETS (MAX_BO_CACHE_BUCKET - MIN_BO_CACHE_BUCKET + 1) +/* const0 1 0 0 -1.67773, mov.v0 $0 ^const0.xxxx, stop */ +#define PP_CLEAR_PROGRAM \ + 0x00020425, 0x0000000c, 0x01e007cf, 0xb0000000, \ + 0x000005f5, 0x00000000, 0x00000000, 0x00000000, \ + struct lima_screen { struct pipe_screen base; struct renderonly *ro;