[Mesa-dev] [PATCH 14/14] st/mesa: implement PBO downloads for ReadPixels

Marek Olšák maraeo at gmail.com
Mon May 23 14:33:38 UTC 2016


On Wed, May 18, 2016 at 5:25 PM, Nicolai Hähnle <nhaehnle at gmail.com> wrote:
> From: Nicolai Hähnle <nicolai.haehnle at amd.com>
>
> ---
>  src/mesa/state_tracker/st_cb_readpixels.c | 142 +++++++++++++++++++++++++++++-
>  src/mesa/state_tracker/st_pbo.c           |  16 ++++
>  src/mesa/state_tracker/st_pbo.h           |   4 +
>  3 files changed, 159 insertions(+), 3 deletions(-)
>
> diff --git a/src/mesa/state_tracker/st_cb_readpixels.c b/src/mesa/state_tracker/st_cb_readpixels.c
> index 62ddc99..6df3a39 100644
> --- a/src/mesa/state_tracker/st_cb_readpixels.c
> +++ b/src/mesa/state_tracker/st_cb_readpixels.c
> @@ -34,6 +34,7 @@
>  #include "main/framebuffer.h"
>  #include "util/u_inlines.h"
>  #include "util/u_format.h"
> +#include "cso_cache/cso_context.h"
>
>  #include "st_cb_fbo.h"
>  #include "st_atom.h"
> @@ -42,6 +43,7 @@
>  #include "st_cb_readpixels.h"
>  #include "state_tracker/st_cb_texture.h"
>  #include "state_tracker/st_format.h"
> +#include "state_tracker/st_pbo.h"
>  #include "state_tracker/st_texture.h"
>
>  static boolean
> @@ -71,11 +73,143 @@ needs_integer_signed_unsigned_conversion(const struct gl_context *ctx,
>
>  static bool
>  try_pbo_readpixels(struct st_context *st, struct st_renderbuffer *strb,
> +                   bool invert_y,
>                     GLint x, GLint y, GLsizei width, GLsizei height,
>                     enum pipe_format src_format, enum pipe_format dst_format,
>                     const struct gl_pixelstore_attrib *pack, void *pixels)
>  {
> -   return false;
> +   struct pipe_context *pipe = st->pipe;
> +   struct cso_context *cso = st->cso_context;
> +   struct pipe_surface *surface = strb->surface;
> +   struct pipe_resource *texture = strb->texture;
> +   const struct util_format_description *desc;
> +   struct st_pbo_addresses addr;
> +   struct pipe_framebuffer_state fb;
> +   enum pipe_texture_target view_target;
> +   bool success = false;
> +
> +   if (texture->nr_samples > 1)
> +      return false;
> +
> +   desc = util_format_description(dst_format);
> +
> +   /* Compute PBO addresses */
> +   addr.bytes_per_pixel = desc->block.bits / 8;
> +   addr.xoffset = x;
> +   addr.yoffset = y;
> +   addr.width = width;
> +   addr.height = height;
> +   addr.depth = 1;
> +   if (!st_pbo_addresses_pixelstore(st, GL_TEXTURE_2D, false, pack, pixels, &addr))
> +      return false;
> +
> +   cso_save_state(cso, (CSO_BIT_FRAGMENT_SAMPLER_VIEWS |
> +                        CSO_BIT_FRAGMENT_SAMPLERS |
> +                        CSO_BIT_FRAGMENT_IMAGE0 |
> +                        CSO_BIT_VERTEX_ELEMENTS |
> +                        CSO_BIT_AUX_VERTEX_BUFFER_SLOT |
> +                        CSO_BIT_FRAMEBUFFER |
> +                        CSO_BIT_VIEWPORT |
> +                        CSO_BIT_RASTERIZER |
> +                        CSO_BIT_DEPTH_STENCIL_ALPHA |
> +                        CSO_BIT_STREAM_OUTPUTS |
> +                        CSO_BIT_PAUSE_QUERIES |
> +                        CSO_BITS_ALL_SHADERS));
> +   cso_save_constant_buffer_slot0(cso, PIPE_SHADER_FRAGMENT);
> +
> +   /* Set up the sampler_view */
> +   {
> +      struct pipe_sampler_view templ;
> +      struct pipe_sampler_view *sampler_view;
> +      struct pipe_sampler_state sampler = {0};
> +      const struct pipe_sampler_state *samplers[1] = {&sampler};
> +
> +      u_sampler_view_default_template(&templ, texture, src_format);
> +
> +      switch (texture->target) {
> +      case PIPE_TEXTURE_CUBE:
> +      case PIPE_TEXTURE_CUBE_ARRAY:
> +         view_target = PIPE_TEXTURE_2D_ARRAY;

This requires PIPE_CAP_SAMPLER_VIEW_TARGET.

Other than that and my other comments, the series is:

Reviewed-by: Marek Olšák <marek.olsak at amd.com>

Marek


More information about the mesa-dev mailing list