On Sat, Jun 1, 2013 at 8:29 AM, Marek Olšák <span dir="ltr"><<a href="mailto:maraeo@gmail.com" target="_blank">maraeo@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
We have to use pipe->blit, not resource_copy_region, so that the read buffer<br>
is resolved if it's multisampled. I also removed the CPU-based copying,<br>
which just did format conversion (obsoleted by the blit).<br>
<br>
Also, the layer/slice/face of the read buffer is taken into account (this was<br>
ignored).<br>
<br>
Last but not least, the format choosing is improved to take float and integer<br>
read buffers into account.<br>
---<br>
 src/mesa/state_tracker/st_cb_drawpixels.c |  162 +++++++++++++----------------<br>
 1 file changed, 70 insertions(+), 92 deletions(-)<br>
<br>
diff --git a/src/mesa/state_tracker/st_cb_drawpixels.c b/src/mesa/state_tracker/st_cb_drawpixels.c<br>
index eb75500..1c26315 100644<br>
--- a/src/mesa/state_tracker/st_cb_drawpixels.c<br>
+++ b/src/mesa/state_tracker/st_cb_drawpixels.c<br>
@@ -1474,10 +1474,9 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,<br>
    struct pipe_sampler_view *sv[2];<br>
    int num_sampler_view = 1;<br>
    GLfloat *color;<br>
-   enum pipe_format srcFormat, texFormat;<br>
+   enum pipe_format srcFormat;<br>
    GLboolean invertTex = GL_FALSE;<br>
    GLint readX, readY, readW, readH;<br>
-   GLuint sample_count;<br>
    struct gl_pixelstore_attrib pack = ctx->DefaultPacking;<br>
    struct st_fp_variant *fpv;<br>
<br>
@@ -1539,35 +1538,51 @@ st_CopyPixels(struct gl_context *ctx, GLint srcx, GLint srcy,<br>
    /* update fragment program constants */<br>
    st_upload_constants(st, fpv->parameters, PIPE_SHADER_FRAGMENT);<br>
<br>
-   sample_count = rbRead->texture->nr_samples;<br>
-   /* I believe this would be legal, presumably would need to do a resolve<br>
-      for color, and for depth/stencil spec says to just use one of the<br>
-      depth/stencil samples per pixel? Need some transfer clarifications. */<br>
-   assert(sample_count < 2);<br>
-<br>
+   /* Choose the format for the temporary texture. */<br>
    srcFormat = rbRead->texture->format;<br>
<br>
-   if (screen->is_format_supported(screen, srcFormat, st->internal_target,<br>
-                                   sample_count,<br>
-                                   PIPE_BIND_SAMPLER_VIEW)) {<br>
-      texFormat = srcFormat;<br>
-   }<br>
-   else {<br>
-      /* srcFormat can't be used as a texture format */<br>
+   if (!screen->is_format_supported(screen, srcFormat, st->internal_target, 0,<br>
+                                    PIPE_BIND_SAMPLER_VIEW |<br>
+                                    (type == GL_COLOR ? PIPE_BIND_RENDER_TARGET<br>
+                                     : PIPE_BIND_DEPTH_STENCIL))) {<br>
       if (type == GL_DEPTH) {<br>
-         texFormat = st_choose_format(st, GL_DEPTH_COMPONENT,<br>
-                                      GL_NONE, GL_NONE, st->internal_target,<br>
-                                      sample_count, PIPE_BIND_DEPTH_STENCIL,<br>
-                                      FALSE);<br>
-         assert(texFormat != PIPE_FORMAT_NONE);<br>
+         srcFormat = st_choose_format(st, GL_DEPTH_COMPONENT, GL_NONE,<br>
+                                      GL_NONE, st->internal_target, 0,<br>
+                                      PIPE_BIND_SAMPLER_VIEW |<br>
+                                      PIPE_BIND_DEPTH_STENCIL, FALSE);<br>
       }<br>
       else {<br>
-         /* default color format */<br>
-         texFormat = st_choose_format(st, GL_RGBA,<br>
-                                      GL_NONE, GL_NONE, st->internal_target,<br>
-                                      sample_count, PIPE_BIND_SAMPLER_VIEW,<br>
-                                      FALSE);<br>
-         assert(texFormat != PIPE_FORMAT_NONE);<br>
+         assert(type == GL_COLOR);<br>
+<br>
+         if (util_format_is_float(srcFormat)) {<br>
+            srcFormat = st_choose_format(st, GL_RGBA32F, GL_NONE,<br>
+                                         GL_NONE, st->internal_target, 0,<br>
+                                         PIPE_BIND_SAMPLER_VIEW |<br>
+                                         PIPE_BIND_RENDER_TARGET, FALSE);<br>
+         }<br>
+         else if (util_format_is_pure_sint(srcFormat)) {<br>
+            srcFormat = st_choose_format(st, GL_RGBA32I, GL_NONE,<br>
+                                         GL_NONE, st->internal_target, 0,<br>
+                                         PIPE_BIND_SAMPLER_VIEW |<br>
+                                         PIPE_BIND_RENDER_TARGET, FALSE);<br>
+         }<br>
+         else if (util_format_is_pure_uint(srcFormat)) {<br>
+            srcFormat = st_choose_format(st, GL_RGBA32UI, GL_NONE,<br>
+                                         GL_NONE, st->internal_target, 0,<br>
+                                         PIPE_BIND_SAMPLER_VIEW |<br>
+                                         PIPE_BIND_RENDER_TARGET, FALSE);<br>
+         }<br>
+         else {<br>
+            srcFormat = st_choose_format(st, GL_RGBA, GL_NONE,<br>
+                                         GL_NONE, st->internal_target, 0,<br>
+                                         PIPE_BIND_SAMPLER_VIEW |<br>
+                                         PIPE_BIND_RENDER_TARGET, FALSE);<br>
+         }<br>
+      }<br>
</blockquote><div><br>I seem to recall that this "choose a gallium format for a given GL format/type" code appears elsewhere in the state tracker (but haven't double-checked).  In any case, it would be nicer if this code was moved into a separate function.<br>
<br> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">+<br>
+      if (srcFormat == PIPE_FORMAT_NONE) {<br>
+         assert(0 && "cannot choose a format for src of CopyPixels");<br>
+         return;<br>
       }<br>
    }<br>
<br><span class="HOEnZb"></span></blockquote><div><br>Reviewed-by: Brian Paul <<a href="mailto:brianp@vmware.com">brianp@vmware.com</a>><br> <br></div></div>