<div dir="ltr">On Sun, Aug 23, 2015 at 4:51 PM, Jason Ekstrand <span dir="ltr"><<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5"><p dir="ltr"><br>
On Aug 23, 2015 3:48 PM, "Marek Olšák" <<a href="mailto:maraeo@gmail.com" target="_blank">maraeo@gmail.com</a>> wrote:<br>
><br>
> On Mon, Aug 24, 2015 at 12:32 AM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>> wrote:<br>
> > On Sun, Aug 23, 2015 at 10:42 AM, Marek Olšák <<a href="mailto:maraeo@gmail.com" target="_blank">maraeo@gmail.com</a>> wrote:<br>
> >> On Fri, Aug 8, 2014 at 8:55 PM, Jason Ekstrand <<a href="mailto:jason@jlekstrand.net" target="_blank">jason@jlekstrand.net</a>> wrote:<br>
> >>> This adds the API entrypoint, error checking logic, and a driver hook for<br>
> >>> the ARB_copy_image extension.<br>
> >>><br>
> >>> v2: Fix a typo in ARB_copy_image.xml and add it to the makefile<br>
> >>> v3: Put ARB_copy_image.xml in the right place alphebetically in the<br>
> >>>     makefile and properly prefix the commit message<br>
> >>> v4: Fixed some line wrapping and added a check for null<br>
> >>> v5: Check for incomplete renderbuffers<br>
> >>><br>
> >>> Signed-off-by: Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com" target="_blank">jason.ekstrand@intel.com</a>><br>
> >>> Reviewed-by: Juha-Pekka Heikkila <<a href="mailto:juhapekka.heikkila@gmail.com" target="_blank">juhapekka.heikkila@gmail.com</a>><br>
> >>> Reviewed-by: Neil Roberts <<a href="mailto:neil@linux.intel.com" target="_blank">neil@linux.intel.com</a>><br>
> >>><br>
> >>> v6: Update dispatch_sanity for the addition of CopyImageSubData<br>
> >>> ---<br>
> >>>  src/mapi/glapi/gen/ARB_copy_image.xml   |  28 +++<br>
> >>>  src/mapi/glapi/gen/Makefile.am          |   1 +<br>
> >>>  src/mapi/glapi/gen/gl_API.xml           |   2 +-<br>
> >>>  src/mapi/glapi/gen/gl_genexec.py        |   1 +<br>
> >>>  src/mesa/Makefile.sources               |   1 +<br>
> >>>  src/mesa/main/copyimage.c               | 356 ++++++++++++++++++++++++++++++++<br>
> >>>  src/mesa/main/copyimage.h               |  49 +++++<br>
> >>>  src/mesa/main/dd.h                      |  16 ++<br>
> >>>  src/mesa/main/extensions.c              |   1 +<br>
> >>>  src/mesa/main/mtypes.h                  |   1 +<br>
> >>>  src/mesa/main/tests/dispatch_sanity.cpp |   2 +-<br>
> >>>  src/mesa/main/textureview.c             |  36 ++--<br>
> >>>  src/mesa/main/textureview.h             |   4 +<br>
> >>>  13 files changed, 477 insertions(+), 21 deletions(-)<br>
> >>>  create mode 100644 src/mapi/glapi/gen/ARB_copy_image.xml<br>
> >>>  create mode 100644 src/mesa/main/copyimage.c<br>
> >>>  create mode 100644 src/mesa/main/copyimage.h<br>
> >>><br>
> >>> diff --git a/src/mapi/glapi/gen/ARB_copy_image.xml b/src/mapi/glapi/gen/ARB_copy_image.xml<br>
> >>> new file mode 100644<br>
> >>> index 0000000..2fbd845<br>
> >>> --- /dev/null<br>
> >>> +++ b/src/mapi/glapi/gen/ARB_copy_image.xml<br>
> >>> @@ -0,0 +1,28 @@<br>
> >>> +<?xml version="1.0"?><br>
> >>> +<!DOCTYPE OpenGLAPI SYSTEM "gl_API.dtd"><br>
> >>> +<br>
> >>> +<OpenGLAPI><br>
> >>> +<br>
> >>> +<category name="GL_ARB_copy_image" number="123"><br>
> >>> +<br>
> >>> +    <function name="CopyImageSubData" offset="assign"><br>
> >>> +        <param name="srcName" type="GLuint"/><br>
> >>> +        <param name="srcTarget" type="GLenum"/><br>
> >>> +        <param name="srcLevel" type="GLint"/><br>
> >>> +        <param name="srcX" type="GLint"/><br>
> >>> +        <param name="srcY" type="GLint"/><br>
> >>> +        <param name="srcZ" type="GLint"/><br>
> >>> +        <param name="dstName" type="GLuint"/><br>
> >>> +        <param name="dstTarget" type="GLenum"/><br>
> >>> +        <param name="dstLevel" type="GLint"/><br>
> >>> +        <param name="dstX" type="GLint"/><br>
> >>> +        <param name="dstY" type="GLint"/><br>
> >>> +        <param name="dstZ" type="GLint"/><br>
> >>> +        <param name="srcWidth" type="GLsizei"/><br>
> >>> +        <param name="srcHeight" type="GLsizei"/><br>
> >>> +        <param name="srcDepth" type="GLsizei"/><br>
> >>> +    </function><br>
> >>> +<br>
> >>> +</category><br>
> >>> +<br>
> >>> +</OpenGLAPI><br>
> >>> diff --git a/src/mapi/glapi/gen/Makefile.am b/src/mapi/glapi/gen/Makefile.am<br>
> >>> index 212731f..645def4 100644<br>
> >>> --- a/src/mapi/glapi/gen/Makefile.am<br>
> >>> +++ b/src/mapi/glapi/gen/Makefile.am<br>
> >>> @@ -117,6 +117,7 @@ API_XML = \<br>
> >>>         ARB_compressed_texture_pixel_storage.xml \<br>
> >>>         ARB_compute_shader.xml \<br>
> >>>         ARB_copy_buffer.xml \<br>
> >>> +       ARB_copy_image.xml \<br>
> >>>         ARB_debug_output.xml \<br>
> >>>         ARB_depth_buffer_float.xml \<br>
> >>>         ARB_depth_clamp.xml \<br>
> >>> diff --git a/src/mapi/glapi/gen/gl_API.xml b/src/mapi/glapi/gen/gl_API.xml<br>
> >>> index e011509..619717d 100644<br>
> >>> --- a/src/mapi/glapi/gen/gl_API.xml<br>
> >>> +++ b/src/mapi/glapi/gen/gl_API.xml<br>
> >>> @@ -8302,7 +8302,7 @@<br>
> >>><br>
> >>>  <xi:include href="ARB_compute_shader.xml" xmlns:xi="<a href="http://www.w3.org/2001/XInclude" target="_blank">http://www.w3.org/2001/XInclude</a>"/><br>
> >>><br>
> >>> -<!-- ARB extension #123 --><br>
> >>> +<xi:include href="ARB_copy_image.xml" xmlns:xi="<a href="http://www.w3.org/2001/XInclude" target="_blank">http://www.w3.org/2001/XInclude</a>"/><br>
> >>><br>
> >>>  <xi:include href="ARB_texture_view.xml" xmlns:xi="<a href="http://www.w3.org/2001/XInclude" target="_blank">http://www.w3.org/2001/XInclude</a>"/><br>
> >>><br>
> >>> diff --git a/src/mapi/glapi/gen/gl_genexec.py b/src/mapi/glapi/gen/gl_genexec.py<br>
> >>> index 4609193..d479e66 100644<br>
> >>> --- a/src/mapi/glapi/gen/gl_genexec.py<br>
> >>> +++ b/src/mapi/glapi/gen/gl_genexec.py<br>
> >>> @@ -62,6 +62,7 @@ header = """/**<br>
> >>>  #include "main/condrender.h"<br>
> >>>  #include "main/context.h"<br>
> >>>  #include "main/convolve.h"<br>
> >>> +#include "main/copyimage.h"<br>
> >>>  #include "main/depth.h"<br>
> >>>  #include "main/dlist.h"<br>
> >>>  #include "main/drawpix.h"<br>
> >>> diff --git a/src/mesa/Makefile.sources b/src/mesa/Makefile.sources<br>
> >>> index 45c53ca..d02c174 100644<br>
> >>> --- a/src/mesa/Makefile.sources<br>
> >>> +++ b/src/mesa/Makefile.sources<br>
> >>> @@ -31,6 +31,7 @@ MAIN_FILES = \<br>
> >>>         $(SRCDIR)main/condrender.c \<br>
> >>>         $(SRCDIR)main/context.c \<br>
> >>>         $(SRCDIR)main/convolve.c \<br>
> >>> +       $(SRCDIR)main/copyimage.c \<br>
> >>>         $(SRCDIR)main/cpuinfo.c \<br>
> >>>         $(SRCDIR)main/debug.c \<br>
> >>>         $(SRCDIR)main/depth.c \<br>
> >>> diff --git a/src/mesa/main/copyimage.c b/src/mesa/main/copyimage.c<br>
> >>> new file mode 100644<br>
> >>> index 0000000..e1110dd<br>
> >>> --- /dev/null<br>
> >>> +++ b/src/mesa/main/copyimage.c<br>
> >>> @@ -0,0 +1,356 @@<br>
> >>> +/*<br>
> >>> + * Mesa 3-D graphics library<br>
> >>> + *<br>
> >>> + * Copyright (C) 2014 Intel Corporation.  All Rights Reserved.<br>
> >>> + *<br>
> >>> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> >>> + * copy of this software and associated documentation files (the "Software"),<br>
> >>> + * to deal in the Software without restriction, including without limitation<br>
> >>> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> >>> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> >>> + * Software is furnished to do so, subject to the following conditions:<br>
> >>> + *<br>
> >>> + * The above copyright notice and this permission notice shall be included<br>
> >>> + * in all copies or substantial portions of the Software.<br>
> >>> + *<br>
> >>> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS<br>
> >>> + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> >>> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
> >>> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR<br>
> >>> + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,<br>
> >>> + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR<br>
> >>> + * OTHER DEALINGS IN THE SOFTWARE.<br>
> >>> + *<br>
> >>> + * Authors:<br>
> >>> + *    Jason Ekstrand <<a href="mailto:jason.ekstrand@intel.com" target="_blank">jason.ekstrand@intel.com</a>><br>
> >>> + */<br>
> >>> +<br>
> >>> +#include "glheader.h"<br>
> >>> +#include "errors.h"<br>
> >>> +#include "enums.h"<br>
> >>> +#include "copyimage.h"<br>
> >>> +#include "teximage.h"<br>
> >>> +#include "texobj.h"<br>
> >>> +#include "fbobject.h"<br>
> >>> +#include "textureview.h"<br>
> >>> +<br>
> >>> +static bool<br>
> >>> +prepare_target(struct gl_context *ctx, GLuint name, GLenum *target, int level,<br>
> >>> +               struct gl_texture_object **tex_obj,<br>
> >>> +               struct gl_texture_image **tex_image, GLuint *tmp_tex,<br>
> >>> +               const char *dbg_prefix)<br>
> >>> +{<br>
> >>> +   struct gl_renderbuffer *rb;<br>
> >>> +<br>
> >>> +   if (name == 0) {<br>
> >>> +      _mesa_error(ctx, GL_INVALID_VALUE,<br>
> >>> +                  "glCopyImageSubData(%sName = %d)", dbg_prefix, name);<br>
> >>> +      return false;<br>
> >>> +   }<br>
> >>> +<br>
> >>> +   /*<br>
> >>> +    * INVALID_ENUM is generated<br>
> >>> +    *  * if either <srcTarget> or <dstTarget><br>
> >>> +    *   - is not RENDERBUFFER or a valid non-proxy texture target<br>
> >>> +    *   - is TEXTURE_BUFFER, or<br>
> >>> +    *   - is one of the cubemap face selectors described in table 3.17,<br>
> >>> +    */<br>
> >>> +   switch (*target) {<br>
> >>> +   case GL_RENDERBUFFER:<br>
> >>> +      /* Not a texture target, but valid */<br>
> >>> +   case GL_TEXTURE_1D:<br>
> >>> +   case GL_TEXTURE_1D_ARRAY:<br>
> >>> +   case GL_TEXTURE_2D:<br>
> >>> +   case GL_TEXTURE_3D:<br>
> >>> +   case GL_TEXTURE_CUBE_MAP:<br>
> >>> +   case GL_TEXTURE_RECTANGLE:<br>
> >>> +   case GL_TEXTURE_2D_ARRAY:<br>
> >>> +   case GL_TEXTURE_CUBE_MAP_ARRAY:<br>
> >>> +   case GL_TEXTURE_2D_MULTISAMPLE:<br>
> >>> +   case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:<br>
> >>> +      /* These are all valid */<br>
> >>> +      break;<br>
> >>> +   case GL_TEXTURE_EXTERNAL_OES:<br>
> >>> +      /* Only exists in ES */<br>
> >>> +   case GL_TEXTURE_BUFFER:<br>
> >>> +   default:<br>
> >>> +      _mesa_error(ctx, GL_INVALID_ENUM,<br>
> >>> +                  "glCopyImageSubData(%sTarget = %s)", dbg_prefix,<br>
> >>> +                  _mesa_lookup_enum_by_nr(*target));<br>
> >>> +      return false;<br>
> >>> +   }<br>
> >>> +<br>
> >>> +   if (*target == GL_RENDERBUFFER) {<br>
> >>> +      rb = _mesa_lookup_renderbuffer(ctx, name);<br>
> >>> +      if (!rb) {<br>
> >>> +         _mesa_error(ctx, GL_INVALID_VALUE,<br>
> >>> +                     "glCopyImageSubData(%sName = %u)", dbg_prefix, name);<br>
> >>> +         return false;<br>
> >>> +      }<br>
> >>> +<br>
> >>> +      if (!rb->Name) {<br>
> >>> +         _mesa_error(ctx, GL_INVALID_OPERATION,<br>
> >>> +                     "glCopyImageSubData(%sName incomplete)", dbg_prefix);<br>
> >>> +         return false;<br>
> >>> +      }<br>
> >>> +<br>
> >>> +      if (level != 0) {<br>
> >>> +         _mesa_error(ctx, GL_INVALID_VALUE,<br>
> >>> +                     "glCopyImageSubData(%sLevel = %u)", dbg_prefix, level);<br>
> >>> +         return false;<br>
> >>> +      }<br>
> >>> +<br>
> >>> +      if (rb->NumSamples > 1)<br>
> >>> +         *target = GL_TEXTURE_2D_MULTISAMPLE;<br>
> >>> +      else<br>
> >>> +         *target = GL_TEXTURE_2D;<br>
> >>> +<br>
> >>> +      *tmp_tex = 0;<br>
> >>> +      _mesa_GenTextures(1, tmp_tex);<br>
> >>> +      if (*tmp_tex == 0)<br>
> >>> +         return false; /* Error already set by GenTextures */<br>
> >>> +<br>
> >>> +      _mesa_BindTexture(*target, *tmp_tex);<br>
> >><br>
> >> Sorry for the very late review, but this is wrong. This changes the<br>
> ><br>
> > This code has been merged for months.  Patches would be better than review. :-)<br>
> ><br>
> >> currently-bound texture object and therefore has a side effect that<br>
> >> the specification doesn't allow. The code later unbinds the texture by<br>
> >> calling _mesa_DeleteTextures. The result is that glCopyImageSubData<br>
> >> unbinds the current texture. Another problem with this is that it<br>
> >> needlessly causes flagging of _NEW_TEXTURE, which can have undesirable<br>
> >> performance impact.<br>
> ><br>
> > Yes, you're correct.  I seem to recall that this may have been fixed.<br>
> > At the very least, I think there is a patch somewhere that fixes it<br>
> > even if it's not merged.  Now that we have DSA, creating a texture<br>
> > with the appropreate target should be pretty trivial.<br>
><br>
> But we don't need (or want) to create a texture. gl_renderbuffer is<br>
> perfectly fine for copying. Yes, CopyImageSubData would need<br>
> parameters srcTex, srcRB, dstTex, dstRB, and one from each pair should<br>
> be NULL.<br>
><br>
> The thing is, if I attempt to do it right without creating a texture,<br>
> it will inevitably break the feature for i965.</p>
</div></div><p dir="ltr">Right... Like I said, I think there was a patch somewhere that cleaned this up. IIRC, it passed both the render buffer and the texture (one of them was null) and punted texture creation to meta. I can try and dig it up some time next week.<span class="HOEnZb"><font color="#888888"></font></span></p></blockquote><div><br></div><div>I've got a patch series for GL_ARB_copy_image.  I'll try to finish cleaning it up this week and post it.  Been on vacation.<br><br></div><div>-Brian<br> <br></div></div></div></div>