[Mesa-dev] [PATCH 10.5/24] st/mesa: don't set sampler states for TBOs

Marek Olšák maraeo at gmail.com
Thu Jun 15 01:08:09 UTC 2017


From: Marek Olšák <marek.olsak at amd.com>

---

This prevents a crash later in the series, and it's generally a good
thing to do.

 src/mesa/state_tracker/st_atom_sampler.c | 11 +++++++++--
 src/mesa/state_tracker/st_texture.c      |  5 +++--
 2 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/src/mesa/state_tracker/st_atom_sampler.c b/src/mesa/state_tracker/st_atom_sampler.c
index 21af5ef..7a85a55 100644
--- a/src/mesa/state_tracker/st_atom_sampler.c
+++ b/src/mesa/state_tracker/st_atom_sampler.c
@@ -227,20 +227,21 @@ void
 st_convert_sampler_from_unit(const struct st_context *st,
                              struct pipe_sampler_state *sampler,
                              GLuint texUnit)
 {
    const struct gl_texture_object *texobj;
    struct gl_context *ctx = st->ctx;
    const struct gl_sampler_object *msamp;
 
    texobj = ctx->Texture.Unit[texUnit]._Current;
    assert(texobj);
+   assert(texobj->Target != GL_TEXTURE_BUFFER);
 
    msamp = _mesa_get_samplerobj(ctx, texUnit);
 
    st_convert_sampler(st, texobj, msamp, sampler);
 
    sampler->lod_bias += ctx->Texture.Unit[texUnit].LodBias;
    sampler->seamless_cube_map |= ctx->Texture.CubeMapSeamless;
 }
 
 
@@ -248,37 +249,43 @@ st_convert_sampler_from_unit(const struct st_context *st,
  * Update the gallium driver's sampler state for fragment, vertex or
  * geometry shader stage.
  */
 static void
 update_shader_samplers(struct st_context *st,
                        enum pipe_shader_type shader_stage,
                        const struct gl_program *prog,
                        struct pipe_sampler_state *samplers,
                        unsigned *out_num_samplers)
 {
+   struct gl_context *ctx = st->ctx;
    GLbitfield samplers_used = prog->SamplersUsed;
    GLbitfield free_slots = ~prog->SamplersUsed;
    GLbitfield external_samplers_used = prog->ExternalSamplersUsed;
    unsigned unit, num_samplers;
    const struct pipe_sampler_state *states[PIPE_MAX_SAMPLERS];
 
    if (samplers_used == 0x0)
       return;
 
    num_samplers = util_last_bit(samplers_used);
 
    /* loop over sampler units (aka tex image units) */
    for (unit = 0; samplers_used; unit++, samplers_used >>= 1) {
       struct pipe_sampler_state *sampler = samplers + unit;
+      unsigned tex_unit = prog->SamplerUnits[unit];
 
-      if (samplers_used & 1) {
-         st_convert_sampler_from_unit(st, sampler, prog->SamplerUnits[unit]);
+      /* Don't update the sampler for TBOs. cso_context will not bind sampler
+       * states that are NULL.
+       */
+      if (samplers_used & 1 &&
+          ctx->Texture.Unit[tex_unit]._Current->Target != GL_TEXTURE_BUFFER) {
+         st_convert_sampler_from_unit(st, sampler, tex_unit);
          states[unit] = sampler;
       } else {
          states[unit] = NULL;
       }
    }
 
    /* For any external samplers with multiplaner YUV, stuff the additional
     * sampler states we need at the end.
     *
     * Just re-use the existing sampler-state from the primary slot.
diff --git a/src/mesa/state_tracker/st_texture.c b/src/mesa/state_tracker/st_texture.c
index 9de3b9a..07c3844 100644
--- a/src/mesa/state_tracker/st_texture.c
+++ b/src/mesa/state_tracker/st_texture.c
@@ -505,26 +505,27 @@ st_destroy_bound_image_handles(struct st_context *st)
  * Create a texture handle from a texture unit.
  */
 static GLuint64
 st_create_texture_handle_from_unit(struct st_context *st,
                                    struct gl_program *prog, GLuint texUnit)
 {
    struct gl_context *ctx = st->ctx;
    struct gl_texture_object *texObj;
    struct pipe_context *pipe = st->pipe;
    struct pipe_sampler_view *view;
-   struct pipe_sampler_state sampler;
+   struct pipe_sampler_state sampler = {0};
 
    if (!st_update_single_texture(st, &view, texUnit, prog->sh.data->Version))
       return 0;
 
-   st_convert_sampler_from_unit(st, &sampler, texUnit);
+   if (view->target != PIPE_BUFFER)
+      st_convert_sampler_from_unit(st, &sampler, texUnit);
 
    texObj = ctx->Texture.Unit[texUnit]._Current;
    assert(texObj);
 
    return pipe->create_texture_handle(pipe, view, &sampler);
 }
 
 
 /**
  * Create an image handle from an image unit.
-- 
2.7.4



More information about the mesa-dev mailing list