From 4b63667f31361b92fbe8e0080a881813b638a1ab Mon Sep 17 00:00:00 2001 From: Italo Nicola Date: Fri, 18 Nov 2022 14:38:12 -0300 Subject: [PATCH] hud: add GALLIUM_HUD_ROTATION option The user can use GALLIUM_HUD_ROTATION={0,90,180,270} to rotate the hud by the specified amount. Signed-off-by: Italo Nicola Reviewed-by: Alyssa Rosenzweig Reviewed-by: Erik Faye-Lund Part-of: --- docs/envvars.rst | 5 +++ src/gallium/auxiliary/hud/hud_context.c | 55 +++++++++++++++++++------ src/gallium/auxiliary/hud/hud_private.h | 1 + 3 files changed, 49 insertions(+), 12 deletions(-) diff --git a/docs/envvars.rst b/docs/envvars.rst index 131255709884c..aebd996931b37 100644 --- a/docs/envvars.rst +++ b/docs/envvars.rst @@ -610,6 +610,11 @@ Gallium environment variables Scale HUD by an integer factor, for high DPI displays. Default is 1. +.. envvar:: GALLIUM_HUD_ROTATION + + Rotate the HUD by an integer number of degrees, the specified value must be + a multiple of 90. Default is 0. + .. envvar:: GALLIUM_HUD_DUMP_DIR specifies a directory for writing the displayed HUD values into diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c index 5ff9097fab9d8..49d6856ec71c6 100644 --- a/src/gallium/auxiliary/hud/hud_context.c +++ b/src/gallium/auxiliary/hud/hud_context.c @@ -71,7 +71,7 @@ /* Control the visibility of all HUD contexts */ static boolean huds_visible = TRUE; static int hud_scale = 1; - +static int hud_rotate = 0; #if DETECT_OS_UNIX static void @@ -486,8 +486,21 @@ hud_draw_results(struct hud_context *hud, struct pipe_resource *tex) hud->fb_width = tex->width0; hud->fb_height = tex->height0; - hud->constants.two_div_fb_width = 2.0f / hud->fb_width; - hud->constants.two_div_fb_height = 2.0f / hud->fb_height; + float th = hud_rotate * (M_PI / 180.0f); + hud->constants.rotate[0] = cos(th); + hud->constants.rotate[1] = -sin(th); + hud->constants.rotate[2] = sin(th); + hud->constants.rotate[3] = cos(th); + + /* invert the aspect ratio when we rotate the hud */ + if (hud_rotate % 180 == 90) { + hud->constants.two_div_fb_height = 2.0f / hud->fb_width; + hud->constants.two_div_fb_width = 2.0f / hud->fb_height; + } else { + assert(hud_rotate % 180 == 0); + hud->constants.two_div_fb_width = 2.0f / hud->fb_width; + hud->constants.two_div_fb_height = 2.0f / hud->fb_height; + } cso_save_state(cso, (CSO_BIT_FRAMEBUFFER | CSO_BIT_SAMPLE_MASK | @@ -1721,15 +1734,20 @@ hud_set_draw_context(struct hud_context *hud, struct cso_context *cso, "DCL OUT[2], GENERIC[0]\n" /* texcoord */ /* [0] = color, * [1] = (2/fb_width, 2/fb_height, xoffset, yoffset) - * [2] = (xscale, yscale, 0, 0) */ - "DCL CONST[0][0..2]\n" - "DCL TEMP[0]\n" + * [2] = (xscale, yscale, 0, 0) + * [3] = rotation_matrix */ + "DCL CONST[0][0..3]\n" + "DCL TEMP[0..2]\n" "IMM[0] FLT32 { -1, 0, 0, 1 }\n" /* v = in * (xscale, yscale) + (xoffset, yoffset) */ "MAD TEMP[0].xy, IN[0], CONST[0][2].xyyy, CONST[0][1].zwww\n" - /* pos = v * (2 / fb_width, 2 / fb_height) - (1, 1) */ - "MAD OUT[0].xy, TEMP[0], CONST[0][1].xyyy, IMM[0].xxxx\n" + /* v = v * (2 / fb_width, 2 / fb_height) - (1, 1) */ + "MAD TEMP[1].xy, TEMP[0], CONST[0][1].xyyy, IMM[0].xxxx\n" + + /* pos = rotation_matrix * v */ + "MUL TEMP[2].xyzw, TEMP[1].xyxy, CONST[0][3].xyzw\n" + "ADD OUT[0].xy, TEMP[2].xzzz, TEMP[2].ywww\n" "MOV OUT[0].zw, IMM[0]\n" "MOV OUT[1], CONST[0][0]\n" @@ -1758,16 +1776,21 @@ hud_set_draw_context(struct hud_context *hud, struct cso_context *cso, "DCL OUT[1], GENERIC[0]\n" /* texcoord */ /* [0] = color, * [1] = (2/fb_width, 2/fb_height, xoffset, yoffset) - * [2] = (xscale, yscale, 0, 0) */ - "DCL CONST[0][0..2]\n" - "DCL TEMP[0]\n" + * [2] = (xscale, yscale, 0, 0) + * [3] = rotation_matrix */ + "DCL CONST[0][0..3]\n" + "DCL TEMP[0..2]\n" "IMM[0] FLT32 { -1, 0, 0, 1 }\n" "IMM[1] FLT32 { 0.0078125, 0.00390625, 1, 1 }\n" // 1.0 / 128, 1.0 / 256, 1, 1 /* v = in * (xscale, yscale) + (xoffset, yoffset) */ "MAD TEMP[0].xy, IN[0], CONST[0][2].xyyy, CONST[0][1].zwww\n" /* pos = v * (2 / fb_width, 2 / fb_height) - (1, 1) */ - "MAD OUT[0].xy, TEMP[0], CONST[0][1].xyyy, IMM[0].xxxx\n" + "MAD TEMP[1].xy, TEMP[0], CONST[0][1].xyyy, IMM[0].xxxx\n" + + /* pos = rotation_matrix * v */ + "MUL TEMP[2].xyzw, TEMP[1].xyxy, CONST[0][3].xyzw\n" + "ADD OUT[0].xy, TEMP[2].xzzz, TEMP[2].ywww\n" "MOV OUT[0].zw, IMM[0]\n" "MUL OUT[1], IN[1], IMM[1]\n" @@ -1875,6 +1898,14 @@ hud_create(struct cso_context *cso, struct st_context_iface *st, #endif huds_visible = debug_get_bool_option("GALLIUM_HUD_VISIBLE", TRUE); hud_scale = debug_get_num_option("GALLIUM_HUD_SCALE", 1); + hud_rotate = debug_get_num_option("GALLIUM_HUD_ROTATION", 0) % 360; + if (hud_rotate < 0) { + hud_rotate += 360; + } + if (hud_rotate % 90 != 0) { + fprintf(stderr, "gallium_hud: rotation must be a multiple of 90. Falling back to 0.\n"); + hud_rotate = 0; + } if (!env || !*env) return NULL; diff --git a/src/gallium/auxiliary/hud/hud_private.h b/src/gallium/auxiliary/hud/hud_private.h index 3604760c74f6b..e0ebdf36c00f4 100644 --- a/src/gallium/auxiliary/hud/hud_private.h +++ b/src/gallium/auxiliary/hud/hud_private.h @@ -79,6 +79,7 @@ struct hud_context { float translate[2]; float scale[2]; float padding[2]; + float rotate[4]; } constants; struct pipe_constant_buffer constbuf;