llvmpipe: asst. clean-ups in lp_linear.c
authorBrian Paul <brianp@vmware.com>
Tue, 17 May 2022 04:02:00 +0000 (22:02 -0600)
committerMarge Bot <emma+marge@anholt.net>
Wed, 15 Jun 2022 12:30:04 +0000 (12:30 +0000)
Signed-off-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Roland Scheidegger <sroland@vmware.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16937>

src/gallium/drivers/llvmpipe/lp_linear.c

index 41970d2..a93de4a 100644 (file)
@@ -68,7 +68,10 @@ linear_fallback(const struct lp_rast_state *state,
 }
 
 
-/* Run our configurable linear shader pipeline:
+/*
+ * Run our configurable linear shader pipeline:
+ * x,y is the surface position of the linear region, width, height is the size.
+ * Return TRUE for success, FALSE otherwise.
  */
 static boolean
 lp_fs_linear_run(const struct lp_rast_state *state,
@@ -83,18 +86,7 @@ lp_fs_linear_run(const struct lp_rast_state *state,
    const struct lp_fragment_shader_variant *variant = state->variant;
    const struct lp_tgsi_info *info = &variant->shader->info;
    struct lp_jit_linear_context jit;
-   lp_jit_linear_llvm_func jit_func = variant->jit_linear_llvm;
-
-   struct lp_linear_sampler samp[LP_MAX_LINEAR_TEXTURES];
-   struct lp_linear_interp interp[LP_MAX_LINEAR_INPUTS];
-
-   const float w0 = a0[0][3];
-   float oow = 1.0f/w0;
-
-   unsigned input_mask = variant->linear_input_mask;
    int nr_consts = info->base.file_max[TGSI_FILE_CONSTANT]+1;
-   int nr_tex = info->num_texs;
-   int i, j;
 
    LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__);
 
@@ -112,8 +104,8 @@ lp_fs_linear_run(const struct lp_rast_state *state,
    if (variant->shader->base.type == PIPE_SHADER_IR_TGSI) {
       uint8_t constants[LP_MAX_LINEAR_CONSTANTS][4];
 
-      for (i = 0; i < nr_consts; i++) {
-         for (j = 0; j < 4; j++) {
+      for (int i = 0; i < nr_consts; i++) {
+         for (int j = 0; j < 4; j++) {
             float val = state->jit_context.constants[0][i*4+j];
             if (val < 0.0f || val > 1.0f) {
                if (LP_DEBUG & DEBUG_LINEAR2)
@@ -127,7 +119,7 @@ lp_fs_linear_run(const struct lp_rast_state *state,
    } else {
       uint8_t nir_constants[LP_MAX_LINEAR_CONSTANTS * 4];
 
-      for (i = 0; i < state->jit_context.num_constants[0]; i++){
+      for (int i = 0; i < state->jit_context.num_constants[0]; i++){
          float val = state->jit_context.constants[0][i];
          if (val < 0.0f || val > 1.0f) {
             if (LP_DEBUG & DEBUG_LINEAR2)
@@ -153,6 +145,9 @@ lp_fs_linear_run(const struct lp_rast_state *state,
 
    /* XXX: Per primitive:
     */
+   struct lp_linear_interp interp[LP_MAX_LINEAR_INPUTS];
+   const float oow = 1.0f / a0[0][3];
+   unsigned input_mask = variant->linear_input_mask;
    while (input_mask) {
       int i = u_bit_scan(&input_mask);
       unsigned usage_mask = info->base.input_usage_mask[i];
@@ -160,7 +155,6 @@ lp_fs_linear_run(const struct lp_rast_state *state,
             info->base.input_interpolate[i] == TGSI_INTERPOLATE_PERSPECTIVE ||
             (info->base.input_interpolate[i] == TGSI_INTERPOLATE_COLOR &&
              !variant->key.flatshade);
-
       if (!lp_linear_init_interp(&interp[i],
                                  x, y, width, height,
                                  usage_mask,
@@ -177,24 +171,30 @@ lp_fs_linear_run(const struct lp_rast_state *state,
       jit.inputs[i] = &interp[i].base;
    }
 
-
    /* XXX: Per primitive: Initialize linear or nearest samplers:
     */
-   for (i = 0; i < nr_tex; i++) {
+   struct lp_linear_sampler samp[LP_MAX_LINEAR_TEXTURES];
+   const int nr_tex = info->num_texs;
+   for (int i = 0; i < nr_tex; i++) {
       const struct lp_tgsi_texture_info *tex_info = &info->tex[i];
-      unsigned unit = tex_info->sampler_unit;
+      const unsigned tex_unit = tex_info->texture_unit;
+      const unsigned samp_unit = tex_info->sampler_unit;
+      //const unsigned fs_s_input = tex_info->coord[0].u.index;
+      //const unsigned fs_t_input = tex_info->coord[1].u.index;
+
+      // xxx investigate why these fail in deqp-vk
+      //assert(variant->linear_input_mask & (1 << fs_s_input));
+      //assert(variant->linear_input_mask & (1 << fs_t_input));
 
       /* XXX: some texture coordinates are linear!
        */
       //boolean perspective = (info->base.input_interpolate[i] ==
       //                       TGSI_INTERPOLATE_PERSPECTIVE);
 
-      if (!lp_linear_init_sampler(&samp[i],
-                                  tex_info,
-                                  lp_fs_variant_key_sampler_idx(&variant->key, unit),
-                                  &state->jit_context.textures[unit],
-                                  x, y, width, height,
-                                  a0, dadx, dady)) {
+      if (!lp_linear_init_sampler(&samp[i], tex_info,
+                  lp_fs_variant_key_sampler_idx(&variant->key, samp_unit),
+                  &state->jit_context.textures[tex_unit],
+                  x, y, width, height, a0, dadx, dady)) {
          if (LP_DEBUG & DEBUG_LINEAR2)
             debug_printf("  -- init_sampler(%d) failed\n", i);
          goto fail;
@@ -205,8 +205,10 @@ lp_fs_linear_run(const struct lp_rast_state *state,
 
    /* JIT function already does blending */
    jit.color0 = color + x * 4 + y * stride;
-   for (y = 0; y < height; y++) {
-      jit_func(&jit, 0, 0, width);
+   lp_jit_linear_llvm_func jit_func = variant->jit_linear_llvm;
+
+   for (unsigned iy = 0; iy < height; iy++) {
+      jit_func(&jit, 0, 0, width);  // x=0, y=0
       jit.color0 += stride;
    }
 
@@ -234,20 +236,19 @@ check_linear_interp_mask_a(struct lp_fragment_shader_variant *variant)
    uint8_t constants[LP_MAX_LINEAR_CONSTANTS][4];
    alignas(16) uint8_t color0[TILE_SIZE*4];
 
-   int nr_inputs = info->base.file_max[TGSI_FILE_INPUT]+1;
-   int nr_tex = info->num_texs;
-   int i;
+   const int nr_inputs = info->base.file_max[TGSI_FILE_INPUT]+1;
+   const int nr_tex = info->num_texs;
 
    LP_DBG(DEBUG_RAST, "%s\n", __FUNCTION__);
 
    jit.constants = (const uint8_t (*)[4])constants;
 
-   for (i = 0; i < nr_tex; i++) {
+   for (int i = 0; i < nr_tex; i++) {
       lp_linear_init_noop_sampler(&samp[i]);
       jit.tex[i] = &samp[i].base;
    }
 
-   for (i = 0; i < nr_inputs; i++) {
+   for (int i = 0; i < nr_inputs; i++) {
       lp_linear_init_noop_interp(&interp[i]);
       jit.inputs[i] = &interp[i].base;
    }
@@ -259,8 +260,9 @@ check_linear_interp_mask_a(struct lp_fragment_shader_variant *variant)
    /* Find out which interpolators were called, and store this as a
     * mask:
     */
-   for (i = 0; i < nr_inputs; i++)
+   for (int i = 0; i < nr_inputs; i++) {
       variant->linear_input_mask |= (interp[i].row[0] << i);
+   }
 }
 
 
@@ -297,7 +299,6 @@ lp_linear_check_variant(struct lp_fragment_shader_variant *variant)
    const struct lp_fragment_shader_variant_key *key = &variant->key;
    const struct lp_fragment_shader *shader = variant->shader;
    const struct lp_tgsi_info *info = &shader->info;
-   int i;
 
    if (info->base.file_max[TGSI_FILE_CONSTANT] >= LP_MAX_LINEAR_CONSTANTS ||
        info->base.file_max[TGSI_FILE_INPUT] >= LP_MAX_LINEAR_INPUTS) {
@@ -306,7 +307,7 @@ lp_linear_check_variant(struct lp_fragment_shader_variant *variant)
       goto fail;
    }
 
-   /* If we have a fastpath which implements the entire varient, use
+   /* If we have a fastpath which implements the entire variant, use
     * that.
     */
    if (lp_linear_check_fastpath(variant)) {
@@ -319,9 +320,9 @@ lp_linear_check_variant(struct lp_fragment_shader_variant *variant)
 
    /* Check static sampler state.
     */
-   for (i = 0; i < info->num_texs; i++) {
+   for (unsigned i = 0; i < info->num_texs; i++) {
       const struct lp_tgsi_texture_info *tex_info = &info->tex[i];
-      unsigned unit = tex_info->sampler_unit;
+      const unsigned unit = tex_info->sampler_unit;
 
       /* XXX: Relax this once setup premultiplies by oow:
        */
@@ -331,7 +332,8 @@ lp_linear_check_variant(struct lp_fragment_shader_variant *variant)
          goto fail;
       }
 
-      struct lp_sampler_static_state *samp = lp_fs_variant_key_sampler_idx(key, unit);
+      struct lp_sampler_static_state *samp =
+         lp_fs_variant_key_sampler_idx(key, unit);
       if (!lp_linear_check_sampler(samp, tex_info)) {
          if (LP_DEBUG & DEBUG_LINEAR)
             debug_printf(" -- samp[%d]: check_sampler failed\n", i);