From d5254601c919d6f16e4624a893c11c928002e608 Mon Sep 17 00:00:00 2001 From: Emma Anholt Date: Thu, 2 Sep 2021 17:03:17 -0700 Subject: [PATCH] i915g: Simplify the process of texcoord mapping to TGSI semantics. Custom index-as-semantic defines and extra bool flags at state update time are unnecessary if we just store the semantics and index that each texcoord should be. Part-of: --- src/gallium/drivers/i915/i915_context.h | 7 +- src/gallium/drivers/i915/i915_fpc.h | 4 -- src/gallium/drivers/i915/i915_fpc_translate.c | 25 +++---- src/gallium/drivers/i915/i915_state_derived.c | 68 ++++++------------- 4 files changed, 37 insertions(+), 67 deletions(-) diff --git a/src/gallium/drivers/i915/i915_context.h b/src/gallium/drivers/i915/i915_context.h index 00f892861af..0ad22f8b286 100644 --- a/src/gallium/drivers/i915/i915_context.h +++ b/src/gallium/drivers/i915/i915_context.h @@ -122,10 +122,13 @@ struct i915_fragment_shader { ubyte constant_flags[I915_MAX_CONSTANT]; /** - * The mapping between generics and hw texture coords. + * The mapping between TGSI inputs and hw texture coords. * We need to share this between the vertex and fragment stages. **/ - int generic_mapping[I915_TEX_UNITS]; + struct { + enum tgsi_semantic semantic; + int index; + } texcoords[I915_TEX_UNITS]; }; struct i915_cache_context; diff --git a/src/gallium/drivers/i915/i915_fpc.h b/src/gallium/drivers/i915/i915_fpc.h index 4c8c77e299f..c223599400c 100644 --- a/src/gallium/drivers/i915/i915_fpc.h +++ b/src/gallium/drivers/i915/i915_fpc.h @@ -39,10 +39,6 @@ struct nir_shader; #define I915_PROGRAM_SIZE 192 -/* Use those indices for pos/face routing, must be >= num of inputs */ -#define I915_SEMANTIC_POS 100 -#define I915_SEMANTIC_FACE 101 - /** * Program translation state */ diff --git a/src/gallium/drivers/i915/i915_fpc_translate.c b/src/gallium/drivers/i915/i915_fpc_translate.c index 940bfa53026..b1e7c84bba3 100644 --- a/src/gallium/drivers/i915/i915_fpc_translate.c +++ b/src/gallium/drivers/i915/i915_fpc_translate.c @@ -108,15 +108,18 @@ i915_program_error(struct i915_fp_compile *p, const char *msg, ...) } static uint32_t -get_mapping(struct i915_fragment_shader *fs, int unit) +get_mapping(struct i915_fragment_shader *fs, enum tgsi_semantic semantic, + int index) { int i; for (i = 0; i < I915_TEX_UNITS; i++) { - if (fs->generic_mapping[i] == -1) { - fs->generic_mapping[i] = unit; + if (fs->texcoords[i].semantic == -1) { + fs->texcoords[i].semantic = semantic; + fs->texcoords[i].index = index; return i; } - if (fs->generic_mapping[i] == unit) + if (fs->texcoords[i].semantic == semantic && + fs->texcoords[i].index == index) return i; } debug_printf("Exceeded max generics\n"); @@ -158,9 +161,9 @@ src_vector(struct i915_fp_compile *p, sem_ind = p->shader->info.input_semantic_index[index]; switch (sem_name) { + case TGSI_SEMANTIC_GENERIC: case TGSI_SEMANTIC_POSITION: { - /* for fragcoord */ - int real_tex_unit = get_mapping(fs, I915_SEMANTIC_POS); + int real_tex_unit = get_mapping(fs, sem_name, sem_ind); src = i915_emit_decl(p, REG_TYPE_T, T_TEX0 + real_tex_unit, D0_CHANNEL_ALL); break; @@ -179,15 +182,9 @@ src_vector(struct i915_fp_compile *p, src = i915_emit_decl(p, REG_TYPE_T, T_FOG_W, D0_CHANNEL_W); src = swizzle(src, W, W, W, W); break; - case TGSI_SEMANTIC_GENERIC: { - int real_tex_unit = get_mapping(fs, sem_ind); - src = i915_emit_decl(p, REG_TYPE_T, T_TEX0 + real_tex_unit, - D0_CHANNEL_ALL); - break; - } case TGSI_SEMANTIC_FACE: { /* for back/front faces */ - int real_tex_unit = get_mapping(fs, I915_SEMANTIC_FACE); + int real_tex_unit = get_mapping(fs, sem_name, sem_ind); src = i915_emit_decl(p, REG_TYPE_T, T_TEX0 + real_tex_unit, D0_CHANNEL_X); break; @@ -875,7 +872,7 @@ i915_init_compile(struct i915_context *i915, struct i915_fragment_shader *ifs) memset(&p->register_phases, 0, sizeof(p->register_phases)); for (i = 0; i < I915_TEX_UNITS; i++) - ifs->generic_mapping[i] = -1; + ifs->texcoords[i].semantic = -1; p->log_program_errors = !i915->no_log_program_errors; diff --git a/src/gallium/drivers/i915/i915_state_derived.c b/src/gallium/drivers/i915/i915_state_derived.c index db565e80ff8..51e02e0ecec 100644 --- a/src/gallium/drivers/i915/i915_state_derived.c +++ b/src/gallium/drivers/i915/i915_state_derived.c @@ -28,6 +28,7 @@ #include "draw/draw_context.h" #include "draw/draw_vertex.h" #include "pipe/p_shader_tokens.h" +#include "util/log.h" #include "util/u_memory.h" #include "i915_context.h" #include "i915_debug.h" @@ -35,17 +36,6 @@ #include "i915_reg.h" #include "i915_state.h" -static uint32_t -find_mapping(const struct i915_fragment_shader *fs, int unit) -{ - int i; - for (i = 0; i < I915_TEX_UNITS; i++) { - if (fs->generic_mapping[i] == unit) - return i; - } - debug_printf("Mapping not found\n"); - return 0; -} /*********************************************************************** * Determine the hardware vertex layout. @@ -56,11 +46,10 @@ calculate_vertex_layout(struct i915_context *i915) { const struct i915_fragment_shader *fs = i915->fs; struct vertex_info vinfo; - bool texCoords[I915_TEX_UNITS], colors[2], fog, needW, face; + bool colors[2], fog, needW, face; uint32_t i; int src; - memset(texCoords, 0, sizeof(texCoords)); colors[0] = colors[1] = fog = needW = face = false; memset(&vinfo, 0, sizeof(vinfo)); @@ -69,27 +58,21 @@ calculate_vertex_layout(struct i915_context *i915) */ for (i = 0; i < fs->info.num_inputs; i++) { switch (fs->info.input_semantic_name[i]) { - case TGSI_SEMANTIC_POSITION: { - uint32_t unit = I915_SEMANTIC_POS; - texCoords[find_mapping(fs, unit)] = true; - } break; + case TGSI_SEMANTIC_POSITION: + case TGSI_SEMANTIC_FACE: + /* Handled as texcoord inputs below */ + break; case TGSI_SEMANTIC_COLOR: assert(fs->info.input_semantic_index[i] < 2); colors[fs->info.input_semantic_index[i]] = true; break; - case TGSI_SEMANTIC_GENERIC: { + case TGSI_SEMANTIC_GENERIC: /* texcoords/varyings/other generic */ - uint32_t unit = fs->info.input_semantic_index[i]; - - texCoords[find_mapping(fs, unit)] = true; needW = true; - } break; + break; case TGSI_SEMANTIC_FOG: fog = true; break; - case TGSI_SEMANTIC_FACE: - face = true; - break; default: debug_printf("Unknown input type %d\n", fs->info.input_semantic_name[i]); @@ -142,36 +125,27 @@ calculate_vertex_layout(struct i915_context *i915) /* texcoords/varyings */ for (i = 0; i < I915_TEX_UNITS; i++) { uint32_t hwtc; - if (texCoords[i]) { - hwtc = TEXCOORDFMT_4D; - if (fs->generic_mapping[i] == I915_SEMANTIC_POS) { - src = - draw_find_shader_output(i915->draw, TGSI_SEMANTIC_POSITION, 0); + if (fs->texcoords[i].semantic != -1) { + src = draw_find_shader_output(i915->draw, fs->texcoords[i].semantic, + fs->texcoords[i].index); + if (fs->texcoords[i].semantic == TGSI_SEMANTIC_FACE) { + /* XXX Because of limitations in the draw module, currently src will + * be 0 for SEMANTIC_FACE, so this aliases to POS. We need to fix in + * the draw module by adding an extra shader output. + */ + mesa_loge("Front/back face is broken\n"); + draw_emit_vertex_attr(&vinfo, EMIT_1F, src); + hwtc = TEXCOORDFMT_1D; } else { - src = draw_find_shader_output(i915->draw, TGSI_SEMANTIC_GENERIC, - fs->generic_mapping[i]); + hwtc = TEXCOORDFMT_4D; + draw_emit_vertex_attr(&vinfo, EMIT_4F, src); } - draw_emit_vertex_attr(&vinfo, EMIT_4F, src); } else { hwtc = TEXCOORDFMT_NOT_PRESENT; } vinfo.hwfmt[1] |= hwtc << (i * 4); } - /* front/back face */ - if (face) { - uint32_t slot = find_mapping(fs, I915_SEMANTIC_FACE); - debug_printf("Front/back face is broken\n"); - /* XXX Because of limitations in the draw module, currently src will be 0 - * for SEMANTIC_FACE, so this aliases to POS. We need to fix in the draw - * module by adding an extra shader output. - */ - src = draw_find_shader_output(i915->draw, TGSI_SEMANTIC_FACE, 0); - draw_emit_vertex_attr(&vinfo, EMIT_1F, src); - vinfo.hwfmt[1] &= ~(TEXCOORDFMT_NOT_PRESENT << (slot * 4)); - vinfo.hwfmt[1] |= TEXCOORDFMT_1D << (slot * 4); - } - draw_compute_vertex_size(&vinfo); if (memcmp(&i915->current.vertex_info, &vinfo, sizeof(vinfo))) {