summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2020-12-10 17:20:12 -0800
committerMarge Bot <eric+marge@anholt.net>2020-12-24 00:18:19 +0000
commit06a081c631959eba7fc2356fcd831eeb967f481b (patch)
treeb0bb960317a6ff8525c8ba5e6e494dcbf9b4c29e
parentf0606cafe8330b10ad205b29267b4fba1dfbe7b2 (diff)
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@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8118>
-rw-r--r--src/mesa/program/prog_to_nir.c40
-rw-r--r--src/mesa/program/prog_to_nir.h3
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