summaryrefslogtreecommitdiffstats
path: root/src/compiler/nir
diff options
context:
space:
mode:
authorJason Ekstrand <[email protected]>2016-05-18 14:56:19 -0700
committerJason Ekstrand <[email protected]>2016-05-23 19:12:34 -0700
commit66e137ecf1e6a77374c0278a02246cff3cab0355 (patch)
treec5ffea1ed91dc81df65ed3d0337ab21584ed00df /src/compiler/nir
parent27b9481d03959a7bee6d906c62b4a519b6b1dc38 (diff)
nir/lower_samplers: Protect against sampler index overflow
Reviewed-by: Kenneth Graunke <[email protected]>
Diffstat (limited to 'src/compiler/nir')
-rw-r--r--src/compiler/nir/nir_lower_samplers.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/compiler/nir/nir_lower_samplers.c b/src/compiler/nir/nir_lower_samplers.c
index 0de9eb88dfc..4a4326983a6 100644
--- a/src/compiler/nir/nir_lower_samplers.c
+++ b/src/compiler/nir/nir_lower_samplers.c
@@ -89,7 +89,7 @@ calc_sampler_offsets(nir_deref *tail, nir_tex_instr *instr,
static void
lower_sampler(nir_tex_instr *instr, const struct gl_shader_program *shader_program,
- gl_shader_stage stage, nir_builder *builder)
+ gl_shader_stage stage, nir_builder *b)
{
if (instr->texture == NULL)
return;
@@ -102,11 +102,14 @@ lower_sampler(nir_tex_instr *instr, const struct gl_shader_program *shader_progr
unsigned array_elements = 1;
nir_ssa_def *indirect = NULL;
- builder->cursor = nir_before_instr(&instr->instr);
+ b->cursor = nir_before_instr(&instr->instr);
calc_sampler_offsets(&instr->texture->deref, instr, &array_elements,
- &indirect, builder, &location);
+ &indirect, b, &location);
if (indirect) {
+ assert(array_elements >= 1);
+ indirect = nir_umin(b, indirect, nir_imm_int(b, array_elements - 1));
+
/* First, we have to resize the array of texture sources */
nir_tex_src *new_srcs = rzalloc_array(instr, nir_tex_src,
instr->num_srcs + 2);