r300: remove support for tgsi_texcoord
We no longer need finalize_nir and thus we don't need to support
texcoord as well. This is a nice rs state cleanup.
This effectivelly reverts commits
0ac6801970f88402f4f98455652448bc5ca97096 and
d4b8e8a48144f4b899d48c271558f0dc613632cb. Also import the previous
location fixup from the state tracker, which was removed when the
unconditional nir_opt_varying pass was introduced.
Signed-off-by: Pavel Ondračka <pavel.ondracka@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33961>
diff --git a/src/gallium/drivers/r300/compiler/nir_to_rc.c b/src/gallium/drivers/r300/compiler/nir_to_rc.c
index 1ddd3c4..eca3377 100644
--- a/src/gallium/drivers/r300/compiler/nir_to_rc.c
+++ b/src/gallium/drivers/r300/compiler/nir_to_rc.c
@@ -1942,6 +1942,30 @@
NIR_PASS(_, s, nir_lower_tex, &lower_tex_options);
}
+/* There are some issues with the tgsi_texcoord = false support in the state
+ * tracker, specifically we are still getting texcoords and pointcoord in some cases
+ * and ocassionally (with fixed function shaders) there are some inconsistencies
+ * like vs using generics and fs using texcoords. This function tries to fix it.
+ * See https://gitlab.freedesktop.org/mesa/mesa/-/issues/12749 for more details.
+ */
+static void
+ntr_fixup_varying_slots(nir_shader *s, nir_variable_mode mode)
+{
+ if (s->info.name && !strcmp(s->info.name, "st/drawtex VS"))
+ return;
+
+ nir_foreach_variable_with_modes (var, s, mode) {
+ if (var->data.location >= VARYING_SLOT_VAR0 && var->data.location < VARYING_SLOT_PATCH0) {
+ var->data.location += 9;
+ } else if (var->data.location == VARYING_SLOT_PNTC) {
+ var->data.location = VARYING_SLOT_VAR8;
+ } else if ((var->data.location >= VARYING_SLOT_TEX0) &&
+ (var->data.location <= VARYING_SLOT_TEX7)) {
+ var->data.location += VARYING_SLOT_VAR0 - VARYING_SLOT_TEX0;
+ }
+ }
+}
+
/**
* Translates the NIR shader to TGSI.
*
@@ -1960,6 +1984,8 @@
c->screen = screen;
c->lower_fabs = !is_r500 && s->info.stage == MESA_SHADER_VERTEX;
+ ntr_fixup_varying_slots(s, s->info.stage == MESA_SHADER_FRAGMENT ? nir_var_shader_in : nir_var_shader_out);
+
if (s->info.stage == MESA_SHADER_FRAGMENT) {
if (is_r500) {
NIR_PASS(_, s, r300_transform_fs_trig_input);
diff --git a/src/gallium/drivers/r300/r300_fs.c b/src/gallium/drivers/r300/r300_fs.c
index e5b48a1..2f67965 100644
--- a/src/gallium/drivers/r300/r300_fs.c
+++ b/src/gallium/drivers/r300/r300_fs.c
@@ -43,16 +43,6 @@
fs_inputs->color[index] = i;
break;
- case TGSI_SEMANTIC_PCOORD:
- fs_inputs->pcoord = i;
- break;
-
- case TGSI_SEMANTIC_TEXCOORD:
- assert(index < ATTR_TEXCOORD_COUNT);
- fs_inputs->texcoord[index] = i;
- fs_inputs->num_texcoord++;
- break;
-
case TGSI_SEMANTIC_GENERIC:
assert(index < ATTR_GENERIC_COUNT);
fs_inputs->generic[index] = i;
@@ -129,14 +119,6 @@
allocate(mydata, inputs->generic[i], reg++);
}
}
- for (i = 0; i < ATTR_TEXCOORD_COUNT; i++) {
- if (inputs->texcoord[i] != ATTR_UNUSED) {
- allocate(mydata, inputs->texcoord[i], reg++);
- }
- }
- if (inputs->pcoord != ATTR_UNUSED) {
- allocate(mydata, inputs->pcoord, reg++);
- }
if (inputs->fog != ATTR_UNUSED) {
allocate(mydata, inputs->fog, reg++);
}
diff --git a/src/gallium/drivers/r300/r300_render.c b/src/gallium/drivers/r300/r300_render.c
index a220f17..c5e6d98 100644
--- a/src/gallium/drivers/r300/r300_render.c
+++ b/src/gallium/drivers/r300/r300_render.c
@@ -24,7 +24,6 @@
#include "r300_emit.h"
#include "r300_reg.h"
#include "r300_vs.h"
-#include "r300_fs.h"
#include <limits.h>
@@ -794,13 +793,11 @@
return;
}
- if (r300->sprite_coord_enable != 0 ||
- r300_fs(r300)->shader->inputs.pcoord != ATTR_UNUSED) {
+ if (r300->sprite_coord_enable != 0)
if ((info.mode == MESA_PRIM_POINTS) != r300->is_point) {
r300->is_point = !r300->is_point;
r300_mark_atom_dirty(r300, &r300->rs_block_state);
}
- }
r300_update_derived_state(r300);
@@ -883,14 +880,11 @@
info->index_size, ~0);
}
- if (r300->sprite_coord_enable != 0 ||
- r300_fs(r300)->shader->inputs.pcoord != ATTR_UNUSED) {
+ if (r300->sprite_coord_enable != 0)
if ((info->mode == MESA_PRIM_POINTS) != r300->is_point) {
r300->is_point = !r300->is_point;
r300_mark_atom_dirty(r300, &r300->rs_block_state);
}
- }
-
r300_update_derived_state(r300);
diff --git a/src/gallium/drivers/r300/r300_screen.c b/src/gallium/drivers/r300/r300_screen.c
index a90a2e2..0ef1daf 100644
--- a/src/gallium/drivers/r300/r300_screen.c
+++ b/src/gallium/drivers/r300/r300_screen.c
@@ -541,7 +541,6 @@
caps->clip_halfz = true;
caps->allow_mapped_buffers_during_execution = true;
caps->legacy_math_rules = true;
- caps->tgsi_texcoord = true;
caps->texture_transfer_modes = PIPE_TEXTURE_TRANSFER_BLIT;
diff --git a/src/gallium/drivers/r300/r300_shader_semantics.h b/src/gallium/drivers/r300/r300_shader_semantics.h
index 7ac2d83..a7f6db8 100644
--- a/src/gallium/drivers/r300/r300_shader_semantics.h
+++ b/src/gallium/drivers/r300/r300_shader_semantics.h
@@ -9,7 +9,6 @@
#define ATTR_UNUSED (-1)
#define ATTR_COLOR_COUNT 2
#define ATTR_GENERIC_COUNT 32
-#define ATTR_TEXCOORD_COUNT 8
/* This structure contains information about what attributes are written by VS
* or read by FS. (but not both) It's much easier to work with than
@@ -23,13 +22,10 @@
int color[ATTR_COLOR_COUNT];
int bcolor[ATTR_COLOR_COUNT];
int face;
- int texcoord[ATTR_TEXCOORD_COUNT];
int generic[ATTR_GENERIC_COUNT];
int fog;
int wpos;
- int pcoord;
- int num_texcoord;
int num_generic;
};
@@ -43,22 +39,16 @@
info->face = ATTR_UNUSED;
info->fog = ATTR_UNUSED;
info->wpos = ATTR_UNUSED;
- info->pcoord = ATTR_UNUSED;
for (i = 0; i < ATTR_COLOR_COUNT; i++) {
info->color[i] = ATTR_UNUSED;
info->bcolor[i] = ATTR_UNUSED;
}
- for (i = 0; i < ATTR_TEXCOORD_COUNT; i++) {
- info->texcoord[i] = ATTR_UNUSED;
- }
-
for (i = 0; i < ATTR_GENERIC_COUNT; i++) {
info->generic[i] = ATTR_UNUSED;
}
- info->num_texcoord = 0;
info->num_generic = 0;
}
diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c
index 1154fa7..655a532 100644
--- a/src/gallium/drivers/r300/r300_state.c
+++ b/src/gallium/drivers/r300/r300_state.c
@@ -1307,15 +1307,17 @@
clip_rule = state->scissor ? 0xAAAA : 0xFFFF;
/* Point sprites coord mode */
- switch (state->sprite_coord_mode) {
- case PIPE_SPRITE_COORD_UPPER_LEFT:
- point_texcoord_top = 0.0f;
- point_texcoord_bottom = 1.0f;
- break;
- case PIPE_SPRITE_COORD_LOWER_LEFT:
- point_texcoord_top = 1.0f;
- point_texcoord_bottom = 0.0f;
- break;
+ if (rs->rs.sprite_coord_enable) {
+ switch (state->sprite_coord_mode) {
+ case PIPE_SPRITE_COORD_UPPER_LEFT:
+ point_texcoord_top = 0.0f;
+ point_texcoord_bottom = 1.0f;
+ break;
+ case PIPE_SPRITE_COORD_LOWER_LEFT:
+ point_texcoord_top = 1.0f;
+ point_texcoord_bottom = 0.0f;
+ break;
+ }
}
if (r300_screen(pipe->screen)->caps.has_tcl) {
diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c
index 92af861..9df4f7e 100644
--- a/src/gallium/drivers/r300/r300_state_derived.c
+++ b/src/gallium/drivers/r300/r300_state_derived.c
@@ -91,15 +91,6 @@
}
}
- /* Texcoords */
- for (i = 0; i < ATTR_TEXCOORD_COUNT && gen_count < 8; i++) {
- if (vs_outputs->texcoord[i] != ATTR_UNUSED &&
- (!(r300->sprite_coord_enable & (1U << i)) || !r300->is_point)) {
- r300_draw_emit_attrib(r300, EMIT_4F, vs_outputs->texcoord[i]);
- gen_count++;
- }
- }
-
/* Fog coordinates. */
if (gen_count < 8 && vs_outputs->fog != ATTR_UNUSED) {
r300_draw_emit_attrib(r300, EMIT_4F, vs_outputs->fog);
@@ -422,16 +413,13 @@
}
/* Reuse color varyings for generics if possible.
- *
* The colors are interpolated as 20-bit floats (reduced precision),
* Use this hack only if there are too many generic varyings.
- * (number of generics + texcoords + fog + wpos + pcoord > 8) */
+ * (number of generic varyings + fog + wpos > 8) */
if (r300->screen->caps.is_r500 && !any_bcolor_used && !r300->flatshade &&
- fs_inputs->face == ATTR_UNUSED &&
- vs_outputs->num_texcoord + vs_outputs->num_generic +
- (vs_outputs->fog != ATTR_UNUSED) + (fs_inputs->wpos != ATTR_UNUSED) +
- (vs_outputs->pcoord != ATTR_UNUSED) > 8 &&
- fs_inputs->num_generic > fs_inputs->num_texcoord) {
+ fs_inputs->face == ATTR_UNUSED &&
+ vs_outputs->num_generic + (vs_outputs->fog != ATTR_UNUSED) +
+ (fs_inputs->wpos != ATTR_UNUSED) > 8) {
for (i = 0; i < ATTR_GENERIC_COUNT && col_count < 2; i++) {
/* Cannot use color varyings for sprite coords. */
if (fs_inputs->generic[i] != ATTR_UNUSED &&
@@ -475,7 +463,7 @@
gen_offset = i;
}
- /* Rasterize generics. */
+ /* Rasterize texture coordinates. */
for (i = gen_offset; i < ATTR_GENERIC_COUNT && tex_count < 8; i++) {
bool sprite_coord = false;
@@ -532,139 +520,6 @@
}
}
- gen_offset = 0;
- /* Reuse color varyings for texcoords if possible.
- *
- * The colors are interpolated as 20-bit floats (reduced precision),
- * Use this hack only if there are too many generic varyings.
- * (number of generics + texcoords + fog + wpos + pcoord > 8) */
- if (r300->screen->caps.is_r500 && !any_bcolor_used && !r300->flatshade &&
- fs_inputs->face == ATTR_UNUSED &&
- vs_outputs->num_texcoord + vs_outputs->num_generic +
- (vs_outputs->fog != ATTR_UNUSED) + (fs_inputs->wpos != ATTR_UNUSED) +
- (vs_outputs->pcoord != ATTR_UNUSED) > 8 &&
- fs_inputs->num_generic <= fs_inputs->num_texcoord) {
- for (i = 0; i < ATTR_TEXCOORD_COUNT && col_count < 2; i++) {
- /* Cannot use color varyings for sprite coords. */
- if (fs_inputs->texcoord[i] != ATTR_UNUSED &&
- (r300->sprite_coord_enable & (1U << i)) && r300->is_point) {
- break;
- }
-
- if (vs_outputs->texcoord[i] != ATTR_UNUSED) {
- /* Set up the color in VAP. */
- rs.vap_vsm_vtx_assm |= R300_INPUT_CNTL_COLOR;
- rs.vap_out_vtx_fmt[0] |=
- R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT << col_count;
- stream_loc_notcl[loc++] = 2 + col_count;
-
- /* Rasterize it. */
- rX00_rs_col(&rs, col_count, col_count, SWIZ_XYZW);
-
- /* Write it to the FS input register if it's needed by the FS. */
- if (fs_inputs->texcoord[i] != ATTR_UNUSED) {
- rX00_rs_col_write(&rs, col_count, fp_offset, WRITE_COLOR);
- fp_offset++;
-
- DBG(r300, DBG_RS,
- "r300: Rasterized texcoord %i redirected to color %i and written to FS.\n",
- i, col_count);
- } else {
- DBG(r300, DBG_RS, "r300: Rasterized texcoord %i redirected to color %i unused.\n",
- i, col_count);
- }
- col_count++;
- } else {
- /* Skip the FS input register, leave it uninitialized. */
- /* If we try to set it to (0,0,0,1), it will lock up. */
- if (fs_inputs->texcoord[i] != ATTR_UNUSED) {
- fp_offset++;
-
- DBG(r300, DBG_RS, "r300: FS input texcoord %i unassigned.\n", i);
- }
- }
- }
- gen_offset = i;
- }
-
- /* Rasterize texcords. */
- for (i = gen_offset; i < ATTR_TEXCOORD_COUNT && tex_count < 8; i++) {
- bool sprite_coord = false;
-
- if (fs_inputs->texcoord[i] != ATTR_UNUSED) {
- sprite_coord = !!(r300->sprite_coord_enable & (1 << i)) && r300->is_point;
- }
-
- if (vs_outputs->texcoord[i] != ATTR_UNUSED || sprite_coord) {
- if (!sprite_coord) {
- /* Set up the texture coordinates in VAP. */
- rs.vap_vsm_vtx_assm |= (R300_INPUT_CNTL_TC0 << tex_count);
- rs.vap_out_vtx_fmt[1] |= (4 << (3 * tex_count));
- stream_loc_notcl[loc++] = 6 + tex_count;
- } else
- stuffing_enable |=
- R300_GB_TEX_ST << (R300_GB_TEX0_SOURCE_SHIFT + (tex_count*2));
-
- /* Rasterize it. */
- rX00_rs_tex(&rs, tex_count, tex_ptr,
- sprite_coord ? SWIZ_XY01 : SWIZ_XYZW);
-
- /* Write it to the FS input register if it's needed by the FS. */
- if (fs_inputs->texcoord[i] != ATTR_UNUSED) {
- rX00_rs_tex_write(&rs, tex_count, fp_offset);
- fp_offset++;
-
- DBG(r300, DBG_RS,
- "r300: Rasterized texcoord %i written to FS%s in texcoord %d.\n",
- i, sprite_coord ? " (sprite coord)" : "", tex_count);
- } else {
- DBG(r300, DBG_RS,
- "r300: Rasterized texcoord %i unused%s.\n",
- i, sprite_coord ? " (sprite coord)" : "");
- }
- tex_count++;
- tex_ptr += sprite_coord ? 2 : 4;
- } else {
- /* Skip the FS input register, leave it uninitialized. */
- /* If we try to set it to (0,0,0,1), it will lock up. */
- if (fs_inputs->texcoord[i] != ATTR_UNUSED) {
- fp_offset++;
-
- DBG(r300, DBG_RS, "r300: FS input texcoord %i unassigned%s.\n",
- i, sprite_coord ? " (sprite coord)" : "");
- }
- }
- }
-
- for (; i < ATTR_TEXCOORD_COUNT; i++) {
- if (fs_inputs->texcoord[i] != ATTR_UNUSED) {
- fprintf(stderr, "r300: ERROR: FS input texcoord %i unassigned, "
- "not enough hardware slots (it's not a bug, do not "
- "report it).\n", i);
- }
- }
-
- /* Rasterize pointcoord. */
- if (fs_inputs->pcoord != ATTR_UNUSED && tex_count < 8) {
-
- stuffing_enable |=
- R300_GB_TEX_ST << (R300_GB_TEX0_SOURCE_SHIFT + (tex_count*2));
-
- /* Rasterize it. */
- rX00_rs_tex(&rs, tex_count, tex_ptr, SWIZ_XY01);
-
- /* Write it to the FS input register if it's needed by the FS. */
- rX00_rs_tex_write(&rs, tex_count, fp_offset);
- fp_offset++;
-
- DBG(r300, DBG_RS,
- "r300: Rasterized pointcoord %i written to FS%s in texcoord %d.\n",
- i, " (sprite coord)", tex_count);
-
- tex_count++;
- tex_ptr += 2;
- }
-
/* Rasterize fog coordinates. */
if (vs_outputs->fog != ATTR_UNUSED && tex_count < 8) {
/* Set up the fog coordinates in VAP. */
@@ -752,10 +607,8 @@
rs.inst_count = count - 1;
/* set the GB enable flags */
- if ((r300->sprite_coord_enable || fs_inputs->pcoord != ATTR_UNUSED) &&
- r300->is_point) {
+ if (r300->sprite_coord_enable && r300->is_point)
stuffing_enable |= R300_GB_POINT_STUFF_ENABLE;
- }
rs.gb_enable = stuffing_enable;
diff --git a/src/gallium/drivers/r300/r300_vs.c b/src/gallium/drivers/r300/r300_vs.c
index 19529f4..4c0d8ad 100644
--- a/src/gallium/drivers/r300/r300_vs.c
+++ b/src/gallium/drivers/r300/r300_vs.c
@@ -50,12 +50,6 @@
vs_outputs->bcolor[index] = i;
break;
- case TGSI_SEMANTIC_TEXCOORD:
- assert(index < ATTR_TEXCOORD_COUNT);
- vs_outputs->texcoord[index] = i;
- vs_outputs->num_texcoord++;
- break;
-
case TGSI_SEMANTIC_GENERIC:
assert(index < ATTR_GENERIC_COUNT);
vs_outputs->generic[index] = i;
@@ -141,20 +135,13 @@
}
}
- /* Generics. */
+ /* Texture coordinates. */
for (i = 0; i < ATTR_GENERIC_COUNT; i++) {
if (outputs->generic[i] != ATTR_UNUSED) {
c->code->outputs[outputs->generic[i]] = reg++;
}
}
- /* Texture coordinates. */
- for (i = 0; i < ATTR_TEXCOORD_COUNT; i++) {
- if (outputs->texcoord[i] != ATTR_UNUSED) {
- c->code->outputs[outputs->texcoord[i]] = reg++;
- }
- }
-
/* Fog coordinates. */
if (outputs->fog != ATTR_UNUSED) {
c->code->outputs[outputs->fog] = reg++;