Esempio n. 1
0
void
softpipe_set_sampler_views(struct pipe_context *pipe,
                           unsigned shader,
                           unsigned start,
                           unsigned num,
                           struct pipe_sampler_view **views)
{
   struct softpipe_context *softpipe = softpipe_context(pipe);
   uint i;

   assert(shader < PIPE_SHADER_TYPES);
   assert(start + num <= ARRAY_SIZE(softpipe->sampler_views[shader]));

   draw_flush(softpipe->draw);

   /* set the new sampler views */
   for (i = 0; i < num; i++) {
      struct sp_sampler_view *sp_sviewsrc;
      struct sp_sampler_view *sp_sviewdst =
         &softpipe->tgsi.sampler[shader]->sp_sview[start + i];
      struct pipe_sampler_view **pview = &softpipe->sampler_views[shader][start + i];
      pipe_sampler_view_reference(pview, views[i]);
      sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[shader][start + i],
                                         views[i]);
      /*
       * We don't really have variants, however some bits are different per shader,
       * so just copy?
       */
      sp_sviewsrc = (struct sp_sampler_view *)*pview;
      if (sp_sviewsrc) {
         memcpy(sp_sviewdst, sp_sviewsrc, sizeof(*sp_sviewsrc));
         sp_sviewdst->compute_lambda = softpipe_get_lambda_func(&sp_sviewdst->base, shader);
         sp_sviewdst->cache = softpipe->tex_cache[shader][start + i];
      }
      else {
         memset(sp_sviewdst, 0,  sizeof(*sp_sviewsrc));
      }
   }


   /* find highest non-null sampler_views[] entry */
   {
      unsigned j = MAX2(softpipe->num_sampler_views[shader], start + num);
      while (j > 0 && softpipe->sampler_views[shader][j - 1] == NULL)
         j--;
      softpipe->num_sampler_views[shader] = j;
   }

   if (shader == PIPE_SHADER_VERTEX || shader == PIPE_SHADER_GEOMETRY) {
      draw_set_sampler_views(softpipe->draw,
                             shader,
                             softpipe->sampler_views[shader],
                             softpipe->num_sampler_views[shader]);
   }

   softpipe->dirty |= SP_NEW_TEXTURE;
}
Esempio n. 2
0
static void
softpipe_set_sampler_views(struct pipe_context *pipe,
                           unsigned shader,
                           unsigned start,
                           unsigned num,
                           struct pipe_sampler_view **views)
{
    struct softpipe_context *softpipe = softpipe_context(pipe);
    uint i;

    assert(shader < PIPE_SHADER_TYPES);
    assert(start + num <= Elements(softpipe->sampler_views[shader]));

    /* Check for no-op */
    if (start + num <= softpipe->num_sampler_views[shader] &&
            !memcmp(softpipe->sampler_views[shader] + start, views,
                    num * sizeof(struct pipe_sampler_view *))) {
        return;
    }

    draw_flush(softpipe->draw);

    /* set the new sampler views */
    for (i = 0; i < num; i++) {
        pipe_sampler_view_reference(&softpipe->sampler_views[shader][start + i],
                                    views[i]);
        sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[shader][start + i],
                                           views[i]);
    }

    /* find highest non-null sampler_views[] entry */
    {
        unsigned j = MAX2(softpipe->num_sampler_views[shader], start + num);
        while (j > 0 && softpipe->sampler_views[shader][j - 1] == NULL)
            j--;
        softpipe->num_sampler_views[shader] = j;
    }

    if (shader == PIPE_SHADER_VERTEX || shader == PIPE_SHADER_GEOMETRY) {
        draw_set_sampler_views(softpipe->draw,
                               shader,
                               softpipe->sampler_views[shader],
                               softpipe->num_sampler_views[shader]);
    }

    softpipe->dirty |= SP_NEW_TEXTURE;
}
/**
 * Should be called when polygon stipple is enabled/disabled or when
 * the fragment shader changes.
 * We add/update the fragment sampler and sampler views to sample from
 * the polygon stipple texture.  The texture unit that we use depends on
 * the fragment shader (we need to use a unit not otherwise used by the
 * shader).
 */
static void
update_polygon_stipple_enable(struct softpipe_context *softpipe, unsigned prim)
{
   if (prim == PIPE_PRIM_TRIANGLES &&
       softpipe->fs_variant->key.polygon_stipple) {
      const unsigned unit = softpipe->fs_variant->stipple_sampler_unit;

      /* sampler state */
      softpipe->samplers[PIPE_SHADER_FRAGMENT][unit] = softpipe->pstipple.sampler;

      /* sampler view */
      pipe_sampler_view_reference(&softpipe->sampler_views[PIPE_SHADER_FRAGMENT][unit],
                                  softpipe->pstipple.sampler_view);

      sp_tex_tile_cache_set_sampler_view(softpipe->tex_cache[PIPE_SHADER_FRAGMENT][unit],
                                         softpipe->pstipple.sampler_view);

      softpipe->dirty |= SP_NEW_SAMPLER;
   }
}