[Mesa-dev] [PATCH] mesa/state_tracker: Fix draw-pixel-with-texture piglit test.

Matthew Dawson matthew at mjdsystems.ca
Sat Mar 21 09:09:45 PDT 2015


When glDrawPixels was used with an external texture, the pixels passed in
were sampled instead of the texture.  Change gallium to instead move the user
texture to a new sampler below the glDrawPixels samplers.

While the piglit test now works, the texture coordinates that are used to
sample the texture are not the ones provided by the user, and need to be
updated as well.

Tested on llvmpipe, r600, and radeonsi.
---
 src/mesa/state_tracker/st_cb_drawpixels.c  | 11 ++++++++++-
 src/mesa/state_tracker/st_glsl_to_tgsi.cpp | 14 ++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c 
b/src/mesa/state_tracker/st_cb_drawpixels.c
index 3edf31b..09d4b9d 100644
--- a/src/mesa/state_tracker/st_cb_drawpixels.c
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c
@@ -676,6 +676,7 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint 
y, GLfloat z,
    GLfloat x0, y0, x1, y1;
    GLsizei maxSize;
    boolean normalized = sv[0]->texture->target != PIPE_TEXTURE_RECT;
+   int num_user_sampers = st->state.num_samplers[PIPE_SHADER_FRAGMENT];
 
    /* limit checks */
    /* XXX if DrawPixels image is larger than max texture size, break
@@ -765,6 +766,9 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint 
y, GLfloat z,
       if (num_sampler_view > 1) {
          cso_single_sampler(cso, PIPE_SHADER_FRAGMENT, 1, &sampler);
       }
+      for(int i = 0; i < num_user_sampers; ++i) {
+         cso_single_sampler(cso, PIPE_SHADER_FRAGMENT, i+num_sampler_view, 
&st->state.samplers[PIPE_SHADER_FRAGMENT][i]);
+      }
       cso_single_sampler_done(cso, PIPE_SHADER_FRAGMENT);
    }
 
@@ -786,7 +790,12 @@ draw_textured_quad(struct gl_context *ctx, GLint x, GLint 
y, GLfloat z,
    cso_set_stream_outputs(st->cso_context, 0, NULL, NULL);
 
    /* texture state: */
-   cso_set_sampler_views(cso, PIPE_SHADER_FRAGMENT, num_sampler_view, sv);
+   {
+      struct pipe_sampler_view *lsv[PIPE_MAX_SAMPLERS];
+      memcpy(lsv, sv, num_sampler_view*sizeof(struct pipe_sampler_view*));
+      memcpy(lsv+num_sampler_view, st-
>state.sampler_views[PIPE_SHADER_FRAGMENT], num_user_sampers*sizeof(struct 
pipe_sampler_view*));
+      cso_set_sampler_views(cso, PIPE_SHADER_FRAGMENT, 
num_sampler_view+num_user_sampers, lsv);
+   }
 
    /* Compute Gallium window coords (y=0=top) with pixel zoom.
     * Recall that these coords are transformed by the current
diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp 
b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
index efee4b2..bbb13ae 100644
--- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
+++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
@@ -4254,6 +4254,7 @@ get_pixel_transfer_visitor(struct st_fragment_program 
*fp,
    st_src_reg coord, src0;
    st_dst_reg dst0;
    glsl_to_tgsi_instruction *inst;
+   unsigned int count_samplers_used = 0;
 
    /* Copy attributes of the glsl_to_tgsi_visitor in the original shader. */
    v->ctx = original->ctx;
@@ -4284,6 +4285,7 @@ get_pixel_transfer_visitor(struct st_fragment_program 
*fp,
    prog->InputsRead |= VARYING_BIT_TEX0;
    prog->SamplersUsed |= (1 << 0); /* mark sampler 0 as used */
    v->samplers_used |= (1 << 0);
+   count_samplers_used++;
 
    if (scale_and_bias) {
       static const gl_state_index scale_state[STATE_LENGTH] =
@@ -4331,6 +4333,7 @@ get_pixel_transfer_visitor(struct st_fragment_program 
*fp,
 
       prog->SamplersUsed |= (1 << 1); /* mark sampler 1 as used */
       v->samplers_used |= (1 << 1);
+      count_samplers_used++;
 
       /* MOV colorTemp, temp; */
       inst = v->emit(NULL, TGSI_OPCODE_MOV, dst0, temp);
@@ -4359,6 +4362,17 @@ get_pixel_transfer_visitor(struct st_fragment_program 
*fp,
       newinst = v->emit(NULL, inst->op, inst->dst[0], src_regs[0], 
src_regs[1], src_regs[2]);
       newinst->tex_target = inst->tex_target;
       newinst->sampler_array_size = inst->sampler_array_size;
+
+      if (newinst->tex_target != 0) {
+         int new_sampler_index = newinst->sampler.index + 
count_samplers_used;
+         newinst->sampler.index = new_sampler_index;
+
+         if ((prog->SamplersUsed & (1 << new_sampler_index)) == 0) {
+            _mesa_add_parameter(params, PROGRAM_SAMPLER, "sampler_1", 4, 
35678, 0, 0);
+         }
+         prog->SamplersUsed |= (1 << new_sampler_index);
+         v->samplers_used |= (1 << new_sampler_index);
+      }
    }
 
    /* Make modifications to fragment program info. */
-- 
2.0.5


More information about the mesa-dev mailing list