mesa/ati_fs: Move NIR translation to ATI_fs compile time.
authorEmma Anholt <emma@anholt.net>
Wed, 17 May 2023 00:07:31 +0000 (17:07 -0700)
committerMarge Bot <emma+marge@anholt.net>
Thu, 1 Jun 2023 23:57:32 +0000 (23:57 +0000)
Now ati_fs takes the same basic path as prog_to_nir, and we don't have to
think about it so much.  Also, the ATI_fs frontend can skip shader info
setup since nir_shader_gather_info does it.

Reviewed-by: Alyssa Rosenzweig <alyssa@rosenzweig.io>
Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/23111>

src/mesa/state_tracker/st_atifs_to_nir.c
src/mesa/state_tracker/st_atifs_to_nir.h
src/mesa/state_tracker/st_program.c

index 0173e8e..fefe59d 100644 (file)
@@ -38,7 +38,6 @@
 struct st_translate {
    nir_builder *b;
    struct ati_fragment_shader *atifs;
-   const struct st_fp_variant_key *key;
 
    nir_ssa_def *temps[MAX_PROGRAM_TEMPS];
 
@@ -433,7 +432,6 @@ st_atifs_setup_uniforms(struct st_translate *t, struct gl_program *program)
  */
 nir_shader *
 st_translate_atifs_program(struct ati_fragment_shader *atifs,
-                           const struct st_fp_variant_key *key,
                            struct gl_program *program,
                            const nir_shader_compiler_options *options)
 {
@@ -442,7 +440,6 @@ st_translate_atifs_program(struct ati_fragment_shader *atifs,
    struct st_translate translate = {
       .atifs = atifs,
       .b = &b,
-      .key = key,
    };
    struct st_translate *t = &translate;
 
@@ -540,57 +537,24 @@ st_init_atifs_prog(struct gl_context *ctx, struct gl_program *prog)
    /* we know this is st_fragment_program, because of st_new_ati_fs() */
    struct ati_fragment_shader *atifs = prog->ati_fs;
 
-   unsigned pass, i, r, optype, arg;
+   unsigned pass, i, r;
 
-   prog->info.inputs_read = 0;
-   prog->info.outputs_written = BITFIELD64_BIT(FRAG_RESULT_COLOR);
    prog->SamplersUsed = 0;
    prog->Parameters = _mesa_new_parameter_list();
 
-   /* fill in inputs_read, SamplersUsed, TexturesUsed */
+   /* fill in SamplersUsed, TexturesUsed */
    for (pass = 0; pass < atifs->NumPasses; pass++) {
       for (r = 0; r < MAX_NUM_FRAGMENT_REGISTERS_ATI; r++) {
          struct atifs_setupinst *texinst = &atifs->SetupInst[pass][r];
-         GLuint pass_tex = texinst->src;
 
          if (texinst->Opcode == ATI_FRAGMENT_SHADER_SAMPLE_OP) {
-            /* mark which texcoords are used */
-            prog->info.inputs_read |= BITFIELD64_BIT(VARYING_SLOT_TEX0 + pass_tex - GL_TEXTURE0_ARB);
             /* by default there is 1:1 mapping between samplers and textures */
             prog->SamplersUsed |= (1 << r);
             /* the target is unknown here, it will be fixed in the draw call */
             prog->TexturesUsed[r] = TEXTURE_2D_BIT;
-         } else if (texinst->Opcode == ATI_FRAGMENT_SHADER_PASS_OP) {
-            if (pass_tex >= GL_TEXTURE0_ARB && pass_tex <= GL_TEXTURE7_ARB) {
-               prog->info.inputs_read |= BITFIELD64_BIT(VARYING_SLOT_TEX0 + pass_tex - GL_TEXTURE0_ARB);
-            }
          }
       }
    }
-   for (pass = 0; pass < atifs->NumPasses; pass++) {
-      for (i = 0; i < atifs->numArithInstr[pass]; i++) {
-         struct atifs_instruction *inst = &atifs->Instructions[pass][i];
-
-         for (optype = 0; optype < 2; optype++) { /* color, alpha */
-            if (inst->Opcode[optype]) {
-               for (arg = 0; arg < inst->ArgCount[optype]; arg++) {
-                  GLint index = inst->SrcReg[optype][arg].Index;
-                  if (index == GL_PRIMARY_COLOR_EXT) {
-                     prog->info.inputs_read |= BITFIELD64_BIT(VARYING_SLOT_COL0);
-                  } else if (index == GL_SECONDARY_INTERPOLATOR_ATI) {
-                     /* note: ATI_fragment_shader.txt never specifies what
-                      * GL_SECONDARY_INTERPOLATOR_ATI is, swrast uses
-                      * VARYING_SLOT_COL1 for this input */
-                     prog->info.inputs_read |= BITFIELD64_BIT(VARYING_SLOT_COL1);
-                  }
-               }
-            }
-         }
-      }
-   }
-
-   /* we may need fog */
-   prog->info.inputs_read |= BITFIELD64_BIT(VARYING_SLOT_FOGC);
 
    /* we always have the ATI_fs constants */
    for (i = 0; i < MAX_NUM_FRAGMENT_CONSTANTS_ATI; i++) {
index 6e725b2..d393eaf 100644 (file)
@@ -38,7 +38,6 @@ struct st_fp_variant_key;
 
 nir_shader *
 st_translate_atifs_program(struct ati_fragment_shader *atifs,
-                           const struct st_fp_variant_key *key,
                            struct gl_program *program,
                            const nir_shader_compiler_options *options);
 
index 19381d0..504742c 100644 (file)
@@ -856,22 +856,35 @@ st_translate_fragment_program(struct st_context *st,
                                   ST_NEW_FS_SAMPLERS;
    }
 
-   /* Translate to NIR.  ATI_fs translates at variant time. */
-   if (!prog->ati_fs) {
-      if (prog->nir && prog->arb.Instructions)
-         ralloc_free(prog->nir);
-
-      if (prog->serialized_nir) {
-         free(prog->serialized_nir);
-         prog->serialized_nir = NULL;
-      }
+   /* Translate to NIR. */
+   if (prog->nir && prog->arb.Instructions)
+      ralloc_free(prog->nir);
+
+   if (prog->serialized_nir) {
+      free(prog->serialized_nir);
+      prog->serialized_nir = NULL;
+   }
+
+   prog->state.type = PIPE_SHADER_IR_NIR;
+   if (prog->arb.Instructions) {
+      prog->nir = st_translate_prog_to_nir(st, prog,
+                                          MESA_SHADER_FRAGMENT);
+   } else if (prog->ati_fs) {
+      const struct nir_shader_compiler_options *options =
+         st_get_nir_compiler_options(st, MESA_SHADER_FRAGMENT);
+
+      assert(!prog->nir);
+      prog->nir = st_translate_atifs_program(prog->ati_fs, prog, options);
+   }
+   st_prog_to_nir_postprocess(st, prog->nir, prog);
 
-      prog->state.type = PIPE_SHADER_IR_NIR;
-      if (prog->arb.Instructions)
-         prog->nir = st_translate_prog_to_nir(st, prog,
-                                             MESA_SHADER_FRAGMENT);
-      st_prog_to_nir_postprocess(st, prog->nir, prog);
-      prog->info = prog->nir->info;
+   prog->info = prog->nir->info;
+   if (prog->ati_fs) {
+      /* ATI_fs will lower fixed function fog at variant time, after the FF vertex
+       * prog has been generated.  So we have to always declare a read of FOGC so
+       * that FF vp feeds it to us just in case.
+       */
+      prog->info.inputs_read |= VARYING_BIT_FOGC;
    }
 
    return true;
@@ -902,18 +915,7 @@ st_create_fp_variant(struct st_context *st,
    /* Translate ATI_fs to NIR at variant time because that's when we have the
     * texture types.
     */
-   if (fp->ati_fs) {
-      const struct nir_shader_compiler_options *options =
-         st_get_nir_compiler_options(st, MESA_SHADER_FRAGMENT);
-
-      nir_shader *s = st_translate_atifs_program(fp->ati_fs, key, fp, options);
-
-      st_prog_to_nir_postprocess(st, s, fp);
-
-      state.ir.nir = s;
-   } else {
-      state.ir.nir = get_nir_shader(st, fp);
-   }
+   state.ir.nir = get_nir_shader(st, fp);
    state.type = PIPE_SHADER_IR_NIR;
 
    bool finalize = false;