static int bind_sampler_locs(struct vrend_linked_shader_program *sprog,
                             int shader_type, int next_sampler_id)
{
   const struct vrend_shader_info *sinfo = &sprog->ss[shader_type]->sel->sinfo;

   if (sinfo->samplers_used_mask) {
      uint32_t mask = sinfo->samplers_used_mask;
      sprog->shadow_samp_mask[shader_type] = sinfo->shadow_samp_mask;
      if (sinfo->shadow_samp_mask) {
         unsigned nsamp = util_bitcount(sinfo->samplers_used_mask);
         sprog->shadow_samp_mask_locs[shader_type] = calloc(nsamp, sizeof(uint32_t));
         sprog->shadow_samp_add_locs[shader_type] = calloc(nsamp, sizeof(uint32_t));
      } else {
         sprog->shadow_samp_mask_locs[shader_type] = sprog->shadow_samp_add_locs[shader_type] = NULL;
      }
      const char *prefix = pipe_shader_to_prefix(shader_type);
      int sampler_index = 0;
      while(mask) {
         uint32_t i = u_bit_scan(&mask);
         char name[64];
         if (sinfo->num_sampler_arrays) {
            int arr_idx = vrend_shader_lookup_sampler_array(sinfo, i);
            snprintf(name, 32, "%ssamp%d[%d]", prefix, arr_idx, i - arr_idx);
         } else
            snprintf(name, 32, "%ssamp%d", prefix, i);

         glUniform1i(glGetUniformLocation(sprog->id, name), next_sampler_id++);

         if (sinfo->shadow_samp_mask & (1 << i)) {
            snprintf(name, 32, "%sshadmask%d", prefix, i);
            sprog->shadow_samp_mask_locs[shader_type][sampler_index] = glGetUniformLocation(sprog->id, name);
            snprintf(name, 32, "%sshadadd%d", prefix, i);
            sprog->shadow_samp_add_locs[shader_type][sampler_index] = glGetUniformLocation(sprog->id, name);
         }
         sampler_index++;
      }
   } else {
      sprog->shadow_samp_mask_locs[shader_type] = NULL;
      sprog->shadow_samp_add_locs[shader_type] = NULL;
      sprog->shadow_samp_mask[shader_type] = 0;
   }
   sprog->samplers_used_mask[shader_type] = sinfo->samplers_used_mask;

   return next_sampler_id;
}
static int bind_sampler_locs(struct vrend_linked_shader_program *sprog,
                             int shader_type, int next_sampler_id)
{
   const struct vrend_shader_info *sinfo = &sprog->ss[shader_type]->sel->sinfo;

   if (sinfo->samplers_used_mask) {
      uint32_t mask = sinfo->samplers_used_mask;
      sprog->shadow_samp_mask[shader_type] = sinfo->shadow_samp_mask;
      if (sinfo->shadow_samp_mask) {
         unsigned nsamp = util_bitcount(sinfo->samplers_used_mask);
         sprog->shadow_samp_mask_locs[shader_type] = calloc(nsamp, sizeof(uint32_t));
         sprog->shadow_samp_add_locs[shader_type] = calloc(nsamp, sizeof(uint32_t));
      } else {
         sprog->shadow_samp_mask_locs[shader_type] = sprog->shadow_samp_add_locs[shader_type] = NULL;
      }
      const char *prefix = pipe_shader_to_prefix(shader_type);
      int sampler_index = 0;
      while(mask) {
         uint32_t i = u_bit_scan(&mask);
         char name[64];
         if (sinfo->num_sampler_arrays) {
            int arr_idx = vrend_shader_lookup_sampler_array(sinfo, i);
            snprintf(name, 32, "%ssamp%d[%d]", prefix, arr_idx, i - arr_idx);
         } else
            snprintf(name, 32, "%ssamp%d", prefix, i);

         glUniform1i(glGetUniformLocation(sprog->id, name), next_sampler_id++);

         if (sinfo->shadow_samp_mask & (1 << i)) {
            snprintf(name, 32, "%sshadmask%d", prefix, i);
            sprog->shadow_samp_mask_locs[shader_type][sampler_index] = glGetUniformLocation(sprog->id, name);
            snprintf(name, 32, "%sshadadd%d", prefix, i);
            sprog->shadow_samp_add_locs[shader_type][sampler_index] = glGetUniformLocation(sprog->id, name);
         }
         sampler_index++;
      }
   } else {
      sprog->shadow_samp_mask_locs[shader_type] = NULL;
      sprog->shadow_samp_add_locs[shader_type] = NULL;
      sprog->shadow_samp_mask[shader_type] = 0;
   }
   sprog->samplers_used_mask[shader_type] = sinfo->samplers_used_mask;

   return next_sampler_id;
}