static void bind_image_locs(struct vrend_linked_shader_program *sprog,
                            int shader_type)
{
   int i;
   char name[32];
   const char *prefix = pipe_shader_to_prefix(shader_type);
   const struct vrend_shader_info *sinfo = &sprog->ss[shader_type]->sel->sinfo;

   uint32_t mask = sinfo->images_used_mask;
   if (!mask && !sinfo->num_image_arrays)
      return;

   if (!has_feature(feat_images))
      return;

   int nsamp = util_last_bit(mask);
   if (nsamp) {
      sprog->img_locs[shader_type] = calloc(nsamp, sizeof(GLint));
      if (!sprog->img_locs[shader_type])
         return;
   } else
      sprog->img_locs[shader_type] = NULL;

   if (sinfo->num_image_arrays) {
      for (i = 0; i < sinfo->num_image_arrays; i++) {
         struct vrend_array *img_array = &sinfo->image_arrays[i];
         for (int j = 0; j < img_array->array_size; j++) {
            snprintf(name, 32, "%simg%d[%d]", prefix, img_array->first, j);
            sprog->img_locs[shader_type][img_array->first + j] = glGetUniformLocation(sprog->id, name);
            if (sprog->img_locs[shader_type][img_array->first + j] == -1)
               vrend_printf( "failed to get uniform loc for image %s\n", name);
         }
      }
   } else if (mask) {
      for (i = 0; i < nsamp; i++) {
         if (mask & (1 << i)) {
            snprintf(name, 32, "%simg%d", prefix, i);
            sprog->img_locs[shader_type][i] = glGetUniformLocation(sprog->id, name);
            if (sprog->img_locs[shader_type][i] == -1)
               vrend_printf( "failed to get uniform loc for image %s\n", name);
         } else {
            sprog->img_locs[shader_type][i] = -1;
         }
      }
   }
   sprog->images_used_mask[shader_type] = mask;
}
static void bind_image_locs(struct vrend_linked_shader_program *sprog,
                            int shader_type)
{
   int i;
   char name[32];
   const char *prefix = pipe_shader_to_prefix(shader_type);
   const struct vrend_shader_info *sinfo = &sprog->ss[shader_type]->sel->sinfo;

   uint32_t mask = sinfo->images_used_mask;
   if (!mask && !sinfo->num_image_arrays)
      return;

   if (!has_feature(feat_images))
      return;

   int nsamp = util_last_bit(mask);
   if (nsamp) {
      sprog->img_locs[shader_type] = calloc(nsamp, sizeof(GLint));
      if (!sprog->img_locs[shader_type])
         return;
   } else
      sprog->img_locs[shader_type] = NULL;

   if (sinfo->num_image_arrays) {
      for (i = 0; i < sinfo->num_image_arrays; i++) {
         struct vrend_array *img_array = &sinfo->image_arrays[i];
         for (int j = 0; j < img_array->array_size; j++) {
            snprintf(name, 32, "%simg%d[%d]", prefix, img_array->first, j);
            sprog->img_locs[shader_type][img_array->first + j] = glGetUniformLocation(sprog->id, name);
            if (sprog->img_locs[shader_type][img_array->first + j] == -1)
               vrend_printf( "failed to get uniform loc for image %s\n", name);
         }
      }
   } else if (mask) {
      for (i = 0; i < nsamp; i++) {
         if (mask & (1 << i)) {
            snprintf(name, 32, "%simg%d", prefix, i);
            sprog->img_locs[shader_type][i] = glGetUniformLocation(sprog->id, name);
            if (sprog->img_locs[shader_type][i] == -1)
               vrend_printf( "failed to get uniform loc for image %s\n", name);
         } else {
            sprog->img_locs[shader_type][i] = -1;
         }
      }
   }
   sprog->images_used_mask[shader_type] = mask;
}