From ba2146f93fea07f60279984a42bc6346aede74c9 Mon Sep 17 00:00:00 2001 From: Erik Faye-Lund Date: Fri, 22 Jul 2022 09:14:09 +0200 Subject: [PATCH] gallium/hud: do not use texture-rect for font MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit RECT textures used to be required to be supported by drivers. But since the state-tracker learned how to lower these to 2D textures, some drivers no longer support them. While we have lowering in place for this, lowering it involves some needless overhead. So let's just use a 2D texture instead of a RECT texture. Because having two versions and switching between them is more complicated than it needs to be, let's just always use a 2D texture. Similarly, let's just always multiply the reciprocal here, so we don't have to test for PIPE_CAP_TGSI_DIV first. Cc: mesa-stable Reviewed-by: Christian Gmeiner Reviewed-by: Marek Olšák Part-of: --- src/gallium/auxiliary/hud/font.c | 4 ++-- src/gallium/auxiliary/hud/font.h | 2 +- src/gallium/auxiliary/hud/hud_context.c | 9 +++++---- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/gallium/auxiliary/hud/font.c b/src/gallium/auxiliary/hud/font.c index a372410b109..0173808f9f7 100644 --- a/src/gallium/auxiliary/hud/font.c +++ b/src/gallium/auxiliary/hud/font.c @@ -390,7 +390,7 @@ util_font_create_fixed_8x13(struct pipe_context *pipe, for (i = 0; i < ARRAY_SIZE(formats); i++) { if (screen->is_format_supported(screen, formats[i], - PIPE_TEXTURE_RECT, 0, 0, + PIPE_TEXTURE_2D, 0, 0, PIPE_BIND_SAMPLER_VIEW)) { tex_format = formats[i]; break; @@ -403,7 +403,7 @@ util_font_create_fixed_8x13(struct pipe_context *pipe, } memset(&tex_templ, 0, sizeof(tex_templ)); - tex_templ.target = PIPE_TEXTURE_RECT; + tex_templ.target = PIPE_TEXTURE_2D; tex_templ.format = tex_format; tex_templ.width0 = 128; tex_templ.height0 = 256; diff --git a/src/gallium/auxiliary/hud/font.h b/src/gallium/auxiliary/hud/font.h index cf1c8798403..5269c1456a1 100644 --- a/src/gallium/auxiliary/hud/font.h +++ b/src/gallium/auxiliary/hud/font.h @@ -37,7 +37,7 @@ enum util_font_name { UTIL_FONT_FIXED_8X13 }; -/* The font is stored in a RECT texture. There are 256 glyphs +/* The font is stored in a 2D texture. There are 256 glyphs * drawn in a 16x16 matrix. The texture coordinates of a glyph * within the matrix should be calculated as follows: * diff --git a/src/gallium/auxiliary/hud/hud_context.c b/src/gallium/auxiliary/hud/hud_context.c index 56af41552ca..5fd3cdfea8d 100644 --- a/src/gallium/auxiliary/hud/hud_context.c +++ b/src/gallium/auxiliary/hud/hud_context.c @@ -1682,11 +1682,11 @@ hud_set_draw_context(struct hud_context *hud, struct cso_context *cso, "FRAG\n" "DCL IN[0], GENERIC[0], LINEAR\n" "DCL SAMP[0]\n" - "DCL SVIEW[0], RECT, FLOAT\n" + "DCL SVIEW[0], 2D, FLOAT\n" "DCL OUT[0], COLOR[0]\n" "DCL TEMP[0]\n" - "TEX TEMP[0], IN[0], SAMP[0], RECT\n" + "TEX TEMP[0], IN[0], SAMP[0], 2D\n" "MOV OUT[0], TEMP[0].xxxx\n" "END\n" }; @@ -1753,6 +1753,7 @@ hud_set_draw_context(struct hud_context *hud, struct cso_context *cso, "DCL CONST[0][0..2]\n" "DCL TEMP[0]\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" @@ -1760,7 +1761,7 @@ hud_set_draw_context(struct hud_context *hud, struct cso_context *cso, "MAD OUT[0].xy, TEMP[0], CONST[0][1].xyyy, IMM[0].xxxx\n" "MOV OUT[0].zw, IMM[0]\n" - "MOV OUT[1], IN[1]\n" + "MUL OUT[1], IN[1], IMM[1]\n" "END\n" }; @@ -1935,7 +1936,7 @@ hud_create(struct cso_context *cso, struct st_context_iface *st, hud->font_sampler_state.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE; hud->font_sampler_state.wrap_t = PIPE_TEX_WRAP_CLAMP_TO_EDGE; hud->font_sampler_state.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE; - hud->font_sampler_state.normalized_coords = 0; + hud->font_sampler_state.normalized_coords = 1; /* constants */ hud->constbuf.buffer_size = sizeof(hud->constants);