glsl: add temporary copy_shader_info() function
authorTimothy Arceri <timothy.arceri@collabora.com>
Tue, 18 Oct 2016 22:15:57 +0000 (09:15 +1100)
committerTimothy Arceri <timothy.arceri@collabora.com>
Wed, 26 Oct 2016 03:29:36 +0000 (14:29 +1100)
This function is added here to ease refactoring towards using the new shared
shader_info. Once refactoring is complete and values are set directly it
will be removed.

We call it from _mesa_copy_linked_program_data() rather than glsl_to_nir()
so that the values will be set for all drivers. In order to do this some
calls need to be moved around so that we make sure to call
do_set_program_inouts() before _mesa_copy_linked_program_data()

Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
src/compiler/Makefile.sources
src/compiler/glsl/glsl_to_nir.cpp
src/compiler/shader_info.c [new file with mode: 0644]
src/compiler/shader_info.h
src/mesa/drivers/dri/i965/brw_link.cpp
src/mesa/main/shaderapi.c
src/mesa/state_tracker/st_glsl_to_nir.cpp
src/mesa/state_tracker/st_glsl_to_tgsi.cpp

index a30443da544a39d91c3c688a15029c72afa50429..df1db0c3ec2e866bfaca94f099dfb76ba084d31b 100644 (file)
@@ -5,7 +5,9 @@ LIBCOMPILER_FILES = \
        nir_types.cpp \
        nir_types.h \
        shader_enums.c \
-       shader_enums.h
+       shader_enums.h \
+       shader_info.c \
+       shader_info.h
 
 # libglsl
 
index 934c9d14f9478aa78edb15d661b7437dd1360b08..096ab4c5e2a3098b727ef4bdb3de44f365997d76 100644 (file)
@@ -152,57 +152,12 @@ glsl_to_nir(const struct gl_shader_program *shader_prog,
    shader->info->num_abos = shader_prog->NumAtomicBuffers;
    shader->info->num_ssbos = sh->NumShaderStorageBlocks;
    shader->info->num_images = sh->NumImages;
-   shader->info->inputs_read = sh->Program->InputsRead;
-   shader->info->double_inputs_read = sh->Program->DoubleInputsRead;
-   shader->info->outputs_written = sh->Program->OutputsWritten;
-   shader->info->outputs_read = sh->Program->OutputsRead;
-   shader->info->patch_inputs_read = sh->Program->PatchInputsRead;
-   shader->info->patch_outputs_written = sh->Program->PatchOutputsWritten;
-   shader->info->system_values_read = sh->Program->SystemValuesRead;
-   shader->info->uses_texture_gather = sh->Program->UsesGather;
    shader->info->uses_clip_distance_out =
       sh->Program->ClipDistanceArraySize != 0;
    shader->info->separate_shader = shader_prog->SeparateShader;
    shader->info->has_transform_feedback_varyings =
       shader_prog->TransformFeedback.NumVarying > 0;
 
-   switch (stage) {
-   case MESA_SHADER_TESS_CTRL:
-      shader->info->tcs.vertices_out = sh->info.TessCtrl.VerticesOut;
-      break;
-
-   case MESA_SHADER_GEOMETRY:
-      shader->info->gs.vertices_in = shader_prog->Geom.VerticesIn;
-      shader->info->gs.output_primitive = sh->info.Geom.OutputType;
-      shader->info->gs.vertices_out = sh->info.Geom.VerticesOut;
-      shader->info->gs.invocations = sh->info.Geom.Invocations;
-      shader->info->gs.uses_end_primitive = shader_prog->Geom.UsesEndPrimitive;
-      shader->info->gs.uses_streams = shader_prog->Geom.UsesStreams;
-      break;
-
-   case MESA_SHADER_FRAGMENT: {
-      struct gl_fragment_program *fp =
-         (struct gl_fragment_program *)sh->Program;
-
-      shader->info->fs.uses_discard = fp->UsesKill;
-      shader->info->fs.uses_sample_qualifier = fp->IsSample != 0;
-      shader->info->fs.early_fragment_tests = sh->info.EarlyFragmentTests;
-      shader->info->fs.depth_layout = fp->FragDepthLayout;
-      break;
-   }
-
-   case MESA_SHADER_COMPUTE: {
-      struct gl_compute_program *cp = (struct gl_compute_program *)sh->Program;
-      shader->info->cs.local_size[0] = cp->LocalSize[0];
-      shader->info->cs.local_size[1] = cp->LocalSize[1];
-      shader->info->cs.local_size[2] = cp->LocalSize[2];
-      break;
-   }
-
-   default:
-      break; /* No stage-specific info */
-   }
-
    return shader;
 }
 
diff --git a/src/compiler/shader_info.c b/src/compiler/shader_info.c
new file mode 100644 (file)
index 0000000..ebd9caf
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright © 2016 Intel Corporation
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ *
+ */
+
+#include "mesa/main/mtypes.h"
+
+void
+copy_shader_info(const struct gl_shader_program *shader_prog,
+                 struct gl_linked_shader *sh)
+{
+   shader_info *info = &sh->Program->info;
+
+   info->inputs_read = sh->Program->InputsRead;
+   info->double_inputs_read = sh->Program->DoubleInputsRead;
+   info->outputs_written = sh->Program->OutputsWritten;
+   info->outputs_read = sh->Program->OutputsRead;
+   info->patch_inputs_read = sh->Program->PatchInputsRead;
+   info->patch_outputs_written = sh->Program->PatchOutputsWritten;
+   info->system_values_read = sh->Program->SystemValuesRead;
+   info->uses_texture_gather = sh->Program->UsesGather;
+
+   switch (sh->Stage) {
+   case MESA_SHADER_TESS_CTRL:
+      info->tcs.vertices_out = sh->info.TessCtrl.VerticesOut;
+      break;
+
+   case MESA_SHADER_GEOMETRY:
+      info->gs.vertices_in = shader_prog->Geom.VerticesIn;
+      info->gs.output_primitive = sh->info.Geom.OutputType;
+      info->gs.vertices_out = sh->info.Geom.VerticesOut;
+      info->gs.invocations = sh->info.Geom.Invocations;
+      info->gs.uses_end_primitive = shader_prog->Geom.UsesEndPrimitive;
+      info->gs.uses_streams = shader_prog->Geom.UsesStreams;
+      break;
+
+   case MESA_SHADER_FRAGMENT: {
+      struct gl_fragment_program *fp =
+         (struct gl_fragment_program *)sh->Program;
+
+      info->fs.uses_discard = fp->UsesKill;
+      info->fs.uses_sample_qualifier = fp->IsSample != 0;
+      info->fs.early_fragment_tests = sh->info.EarlyFragmentTests;
+      info->fs.depth_layout = fp->FragDepthLayout;
+      break;
+   }
+
+   case MESA_SHADER_COMPUTE: {
+      struct gl_compute_program *cp = (struct gl_compute_program *)sh->Program;
+      info->cs.local_size[0] = cp->LocalSize[0];
+      info->cs.local_size[1] = cp->LocalSize[1];
+      info->cs.local_size[2] = cp->LocalSize[2];
+      break;
+   }
+
+   default:
+      break; /* No stage-specific info */
+   }
+}
index ab38562d95e943446d1535d784ad8c7b7ced9d24..7624008dedcd3ef95b08ae2eced3445144a2f2d2 100644 (file)
@@ -124,6 +124,13 @@ typedef struct shader_info {
    };
 } shader_info;
 
+struct gl_shader_program;
+struct gl_linked_shader;
+
+void
+copy_shader_info(const struct gl_shader_program *shader_prog,
+                 struct gl_linked_shader *sh);
+
 #ifdef __cplusplus
 }
 #endif
index f0e504d99abeee0989fde901a1e2e9dfb7bbb818..f75b384d67356fe093390c7e0bcfc118767a9222 100644 (file)
@@ -231,10 +231,12 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
 
       prog->Parameters = _mesa_new_parameter_list();
 
-      _mesa_copy_linked_program_data(shProg, shader);
-
       process_glsl_ir(brw, shProg, shader);
 
+      do_set_program_inouts(shader->ir, prog, shader->Stage);
+
+      _mesa_copy_linked_program_data(shProg, shader);
+
       /* Make a pass over the IR to add state references for any built-in
        * uniforms that are used.  This has to be done now (during linking).
        * Code generation doesn't happen until the first time this shader is
@@ -258,8 +260,6 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
          }
       }
 
-      do_set_program_inouts(shader->ir, prog, shader->Stage);
-
       prog->SamplersUsed = shader->active_samplers;
       prog->ShadowSamplers = shader->shadow_samplers;
       _mesa_update_shader_textures_used(shProg, prog);
index 358969b082cc4c99af63b991398330e5ebc10aee..bbaf77064072032dafef4d04ec5cf8deee4f968a 100644 (file)
@@ -2218,6 +2218,8 @@ _mesa_copy_linked_program_data(const struct gl_shader_program *src,
    default:
       break;
    }
+
+   copy_shader_info(src, dst_sh);
 }
 
 /**
index 97fef082c0458d08422dabfdb6283db50aeacd1c..303b36e9467ae58428f8a506aa57f0c624a88366 100644 (file)
@@ -382,6 +382,8 @@ st_nir_get_mesa_program(struct gl_context *ctx,
 
    prog->Parameters = _mesa_new_parameter_list();
 
+   do_set_program_inouts(shader->ir, prog, shader->Stage);
+
    _mesa_copy_linked_program_data(shader_program, shader);
    _mesa_generate_parameters_list_for_uniforms(shader_program, shader,
                                                prog->Parameters);
@@ -421,8 +423,6 @@ st_nir_get_mesa_program(struct gl_context *ctx,
    prog->Instructions = NULL;
    prog->NumInstructions = 0;
 
-   do_set_program_inouts(shader->ir, prog, shader->Stage);
-
    prog->SamplersUsed = shader->active_samplers;
    prog->ShadowSamplers = shader->shadow_samplers;
    prog->ExternalSamplersUsed = gl_external_samplers(shader);
index b2bd21524885ecb9b65d48abedb84b23f433570f..4d2b1f60ebbd450a2f4d9ab75b475b52c47da2c4 100644 (file)
@@ -6397,7 +6397,6 @@ get_mesa_program_tgsi(struct gl_context *ctx,
    v->have_fma = pscreen->get_shader_param(pscreen, ptarget,
                                            PIPE_SHADER_CAP_TGSI_FMA_SUPPORTED);
 
-   _mesa_copy_linked_program_data(shader_program, shader);
    _mesa_generate_parameters_list_for_uniforms(shader_program, shader,
                                                prog->Parameters);
 
@@ -6467,6 +6466,7 @@ get_mesa_program_tgsi(struct gl_context *ctx,
    prog->NumInstructions = 0;
 
    do_set_program_inouts(shader->ir, prog, shader->Stage);
+   _mesa_copy_linked_program_data(shader_program, shader);
    shrink_array_declarations(v->inputs, v->num_inputs,
                              &prog->InputsRead, prog->DoubleInputsRead, &prog->PatchInputsRead);
    shrink_array_declarations(v->outputs, v->num_outputs,