[Mesa-dev] [PATCH 04/14] meta: Create temporary pbo in _mesa_meta_pbo_GetTexSubImage()

Anuj Phogat anuj.phogat at gmail.com
Mon Feb 23 14:36:41 PST 2015


using a flag passed in as function parameter. This will enable
_mesa_meta_pbo_GetTexSubImage to be used for reading in to
non-pbo buffers.

This will be useful to support reading from YF/YS tiled surfaces
in Skylake.

Signed-off-by: Anuj Phogat <anuj.phogat at gmail.com>
---
 src/mesa/drivers/common/meta.h               |  1 +
 src/mesa/drivers/common/meta_tex_subimage.c  | 18 ++++++++++++++++--
 src/mesa/drivers/dri/i965/intel_pixel_read.c |  9 ++++-----
 src/mesa/drivers/dri/i965/intel_tex_image.c  |  3 ++-
 4 files changed, 23 insertions(+), 8 deletions(-)

diff --git a/src/mesa/drivers/common/meta.h b/src/mesa/drivers/common/meta.h
index e7d894d..3de0d87 100644
--- a/src/mesa/drivers/common/meta.h
+++ b/src/mesa/drivers/common/meta.h
@@ -542,6 +542,7 @@ _mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims,
                               int xoffset, int yoffset, int zoffset,
                               int width, int height, int depth,
                               GLenum format, GLenum type, const void *pixels,
+                              bool create_pbo,
                               const struct gl_pixelstore_attrib *packing);
 
 extern void
diff --git a/src/mesa/drivers/common/meta_tex_subimage.c b/src/mesa/drivers/common/meta_tex_subimage.c
index 68c8273..cd87a72 100644
--- a/src/mesa/drivers/common/meta_tex_subimage.c
+++ b/src/mesa/drivers/common/meta_tex_subimage.c
@@ -34,6 +34,7 @@
 #include "macros.h"
 #include "meta.h"
 #include "pbo.h"
+#include "readpix.h"
 #include "shaderapi.h"
 #include "state.h"
 #include "teximage.h"
@@ -246,6 +247,7 @@ _mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims,
                               int xoffset, int yoffset, int zoffset,
                               int width, int height, int depth,
                               GLenum format, GLenum type, const void *pixels,
+                              bool create_pbo,
                               const struct gl_pixelstore_attrib *packing)
 {
    GLuint pbo = 0, pbo_tex = 0, fbos[2] = { 0, 0 };
@@ -257,7 +259,7 @@ _mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims,
    /* XXX: This should probably be passed in from somewhere */
    const char *where = "_mesa_meta_pbo_GetTexSubImage";
 
-   if (!_mesa_is_bufferobj(packing->BufferObj))
+   if (!_mesa_is_bufferobj(packing->BufferObj) && !create_pbo)
       return false;
 
    if (format == GL_DEPTH_COMPONENT ||
@@ -282,7 +284,7 @@ _mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims,
       return true;
    }
 
-   pbo_tex_image = create_texture_for_pbo(ctx, false, GL_PIXEL_PACK_BUFFER,
+   pbo_tex_image = create_texture_for_pbo(ctx, create_pbo, GL_PIXEL_PACK_BUFFER,
                                           width, height, depth,
                                           format, type, pixels, packing,
                                           &pbo, &pbo_tex);
@@ -348,6 +350,18 @@ _mesa_meta_pbo_GetTexSubImage(struct gl_context *ctx, GLuint dims,
                                  GL_COLOR_BUFFER_BIT, GL_NEAREST);
    }
 
+   /* If we created a temporary pbo in meta to read the pixel data, that
+    * data will now get copied to memory allocated by client.
+    */
+   if (create_pbo) {
+      /* Unbind the pbo from pack binding. */
+      _mesa_BindBuffer(GL_PIXEL_PACK_BUFFER, 0);
+      _mesa_BindFramebuffer(GL_READ_FRAMEBUFFER, fbos[1]);
+      _mesa_update_state(ctx);
+      _mesa_readpixels(ctx, 0, 0, width, height, format, type,
+                       packing, (void *) pixels);
+   }
+
    success = true;
 
 fail:
diff --git a/src/mesa/drivers/dri/i965/intel_pixel_read.c b/src/mesa/drivers/dri/i965/intel_pixel_read.c
index df22a63..ce6b2ef 100644
--- a/src/mesa/drivers/dri/i965/intel_pixel_read.c
+++ b/src/mesa/drivers/dri/i965/intel_pixel_read.c
@@ -223,13 +223,12 @@ intelReadPixels(struct gl_context * ctx,
 
    DBG("%s\n", __FUNCTION__);
 
-   if (_mesa_is_bufferobj(pack->BufferObj)) {
-      if (_mesa_meta_pbo_GetTexSubImage(ctx, 2, NULL, x, y, 0, width, height, 1,
-                                        format, type, pixels, pack))
-         return;
+   if (_mesa_meta_pbo_GetTexSubImage(ctx, 2, NULL, x, y, 0, width, height, 1,
+                                     format, type, pixels, false, pack))
+      return;
 
+   if (_mesa_is_bufferobj(ctx->Pack.BufferObj))
       perf_debug("%s: fallback to CPU mapping in PBO case\n", __FUNCTION__);
-   }
 
    ok = intel_readpixels_tiled_memcpy(ctx, x, y, width, height,
                                       format, type, pixels, pack);
diff --git a/src/mesa/drivers/dri/i965/intel_tex_image.c b/src/mesa/drivers/dri/i965/intel_tex_image.c
index 6eebfc4..ae7753e 100644
--- a/src/mesa/drivers/dri/i965/intel_tex_image.c
+++ b/src/mesa/drivers/dri/i965/intel_tex_image.c
@@ -475,7 +475,8 @@ intel_get_tex_image(struct gl_context *ctx,
       if (_mesa_meta_pbo_GetTexSubImage(ctx, 3, texImage, 0, 0, 0,
                                         texImage->Width, texImage->Height,
                                         texImage->Depth, format, type,
-                                        pixels, &ctx->Pack))
+                                        pixels, false /* create_pbo */,
+                                        &ctx->Pack))
          return;
 
       perf_debug("%s: fallback to CPU mapping in PBO case\n", __FUNCTION__);
-- 
1.9.3



More information about the mesa-dev mailing list