Mesa (master): mesa/prog_to_nir: Factor out the texture-target-to-sampler-dim helper.

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Dec 24 00:55:08 UTC 2020


Module: Mesa
Branch: master
Commit: 06a081c631959eba7fc2356fcd831eeb967f481b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=06a081c631959eba7fc2356fcd831eeb967f481b

Author: Eric Anholt <eric at anholt.net>
Date:   Thu Dec 10 17:20:12 2020 -0800

mesa/prog_to_nir: Factor out the texture-target-to-sampler-dim helper.

I'll be using this switch statement and extending it for
ATI_fragment_shader.

Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8118>

---

 src/mesa/program/prog_to_nir.c | 40 ++++++++++++++++++++--------------------
 src/mesa/program/prog_to_nir.h |  3 +++
 2 files changed, 23 insertions(+), 20 deletions(-)

diff --git a/src/mesa/program/prog_to_nir.c b/src/mesa/program/prog_to_nir.c
index 98daed1b777..7bd503363e8 100644
--- a/src/mesa/program/prog_to_nir.c
+++ b/src/mesa/program/prog_to_nir.c
@@ -467,6 +467,25 @@ ptn_kil(nir_builder *b, nir_ssa_def **src)
    nir_builder_instr_insert(b, &discard->instr);
 }
 
+enum glsl_sampler_dim
+_mesa_texture_index_to_sampler_dim(gl_texture_index index)
+{
+   switch (index) {
+   case TEXTURE_1D_INDEX:
+      return GLSL_SAMPLER_DIM_1D;
+   case TEXTURE_2D_INDEX:
+      return GLSL_SAMPLER_DIM_2D;
+   case TEXTURE_3D_INDEX:
+      return GLSL_SAMPLER_DIM_3D;
+   case TEXTURE_CUBE_INDEX:
+      return GLSL_SAMPLER_DIM_CUBE;
+   case TEXTURE_RECT_INDEX:
+      return GLSL_SAMPLER_DIM_RECT;
+   default:
+      unreachable("unknown texture target");
+   }
+}
+
 static void
 ptn_tex(struct ptn_compile *c, nir_alu_dest dest, nir_ssa_def **src,
         struct prog_instruction *prog_inst)
@@ -513,26 +532,7 @@ ptn_tex(struct ptn_compile *c, nir_alu_dest dest, nir_ssa_def **src,
    instr->dest_type = nir_type_float;
    instr->is_shadow = prog_inst->TexShadow;
 
-   switch (prog_inst->TexSrcTarget) {
-   case TEXTURE_1D_INDEX:
-      instr->sampler_dim = GLSL_SAMPLER_DIM_1D;
-      break;
-   case TEXTURE_2D_INDEX:
-      instr->sampler_dim = GLSL_SAMPLER_DIM_2D;
-      break;
-   case TEXTURE_3D_INDEX:
-      instr->sampler_dim = GLSL_SAMPLER_DIM_3D;
-      break;
-   case TEXTURE_CUBE_INDEX:
-      instr->sampler_dim = GLSL_SAMPLER_DIM_CUBE;
-      break;
-   case TEXTURE_RECT_INDEX:
-      instr->sampler_dim = GLSL_SAMPLER_DIM_RECT;
-      break;
-   default:
-      fprintf(stderr, "Unknown texture target %d\n", prog_inst->TexSrcTarget);
-      abort();
-   }
+   instr->sampler_dim = _mesa_texture_index_to_sampler_dim(prog_inst->TexSrcTarget);
 
    instr->coord_components =
       glsl_get_sampler_dim_coordinate_components(instr->sampler_dim);
diff --git a/src/mesa/program/prog_to_nir.h b/src/mesa/program/prog_to_nir.h
index 22a2b420cf5..2d8c7c7a5e5 100644
--- a/src/mesa/program/prog_to_nir.h
+++ b/src/mesa/program/prog_to_nir.h
@@ -24,6 +24,7 @@
 #ifndef PROG_TO_NIR_H
 #define PROG_TO_NIR_H
 
+#include "main/mtypes.h"
 #include "compiler/nir/nir.h"
 
 #ifdef __cplusplus
@@ -33,6 +34,8 @@ extern "C" {
 struct nir_shader *prog_to_nir(const struct gl_program *prog,
                                const nir_shader_compiler_options *options);
 
+enum glsl_sampler_dim _mesa_texture_index_to_sampler_dim(gl_texture_index index);
+
 #ifdef __cplusplus
 }
 #endif



More information about the mesa-commit mailing list