st/mesa: add st_convert_image()
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Fri, 31 Mar 2017 10:48:03 +0000 (12:48 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Mon, 3 Apr 2017 09:29:31 +0000 (11:29 +0200)
Should be used by the state tracker when glGetImageHandleARB()
is called in order to create a pipe_image_view template.

v3: - move the comment to *.c
v2: - make 'st' const
    - describe the function

Signed-off-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
src/mesa/state_tracker/st_atom_image.c
src/mesa/state_tracker/st_texture.h

index 4101552dff4e5bb9bc7204ac94cc47dc3bc980a4..077bafd09a233123d2f1ec3d772bd968942a80c7 100644 (file)
 #include "st_program.h"
 #include "st_format.h"
 
+/**
+ * Convert a gl_image_unit object to a pipe_image_view object.
+ */
+void
+st_convert_image(const struct st_context *st, const struct gl_image_unit *u,
+                 struct pipe_image_view *img)
+{
+   struct st_texture_object *stObj = st_texture_object(u->TexObj);
+
+   img->resource = stObj->pt;
+   img->format = st_mesa_format_to_pipe_format(st, u->_ActualFormat);
+
+   switch (u->Access) {
+   case GL_READ_ONLY:
+      img->access = PIPE_IMAGE_ACCESS_READ;
+      break;
+   case GL_WRITE_ONLY:
+      img->access = PIPE_IMAGE_ACCESS_WRITE;
+      break;
+   case GL_READ_WRITE:
+      img->access = PIPE_IMAGE_ACCESS_READ_WRITE;
+      break;
+   default:
+      unreachable("bad gl_image_unit::Access");
+   }
+
+   if (stObj->pt->target == PIPE_BUFFER) {
+      unsigned base, size;
+
+      base = stObj->base.BufferOffset;
+      assert(base < stObj->pt->width0);
+      size = MIN2(stObj->pt->width0 - base, (unsigned)stObj->base.BufferSize);
+
+      img->u.buf.offset = base;
+      img->u.buf.size = size;
+   } else {
+      img->u.tex.level = u->Level + stObj->base.MinLevel;
+      if (stObj->pt->target == PIPE_TEXTURE_3D) {
+         if (u->Layered) {
+            img->u.tex.first_layer = 0;
+            img->u.tex.last_layer = u_minify(stObj->pt->depth0, img->u.tex.level) - 1;
+         } else {
+            img->u.tex.first_layer = u->_Layer;
+            img->u.tex.last_layer = u->_Layer;
+         }
+      } else {
+         img->u.tex.first_layer = u->_Layer + stObj->base.MinLayer;
+         img->u.tex.last_layer = u->_Layer + stObj->base.MinLayer;
+         if (u->Layered && img->resource->array_size > 1) {
+            if (stObj->base.Immutable)
+               img->u.tex.last_layer += stObj->base.NumLayers - 1;
+            else
+               img->u.tex.last_layer += img->resource->array_size - 1;
+         }
+      }
+   }
+}
+
 static void
 st_bind_images(struct st_context *st, struct gl_program *prog,
                enum pipe_shader_type shader_type)
@@ -70,53 +128,7 @@ st_bind_images(struct st_context *st, struct gl_program *prog,
          continue;
       }
 
-      img->resource = stObj->pt;
-      img->format = st_mesa_format_to_pipe_format(st, u->_ActualFormat);
-
-      switch (u->Access) {
-      case GL_READ_ONLY:
-         img->access = PIPE_IMAGE_ACCESS_READ;
-         break;
-      case GL_WRITE_ONLY:
-         img->access = PIPE_IMAGE_ACCESS_WRITE;
-         break;
-      case GL_READ_WRITE:
-         img->access = PIPE_IMAGE_ACCESS_READ_WRITE;
-         break;
-      default:
-         unreachable("bad gl_image_unit::Access");
-      }
-
-      if (stObj->pt->target == PIPE_BUFFER) {
-         unsigned base, size;
-
-         base = stObj->base.BufferOffset;
-         assert(base < stObj->pt->width0);
-         size = MIN2(stObj->pt->width0 - base, (unsigned)stObj->base.BufferSize);
-
-         img->u.buf.offset = base;
-         img->u.buf.size = size;
-      } else {
-         img->u.tex.level = u->Level + stObj->base.MinLevel;
-         if (stObj->pt->target == PIPE_TEXTURE_3D) {
-            if (u->Layered) {
-               img->u.tex.first_layer = 0;
-               img->u.tex.last_layer = u_minify(stObj->pt->depth0, img->u.tex.level) - 1;
-            } else {
-               img->u.tex.first_layer = u->_Layer;
-               img->u.tex.last_layer = u->_Layer;
-            }
-         } else {
-            img->u.tex.first_layer = u->_Layer + stObj->base.MinLayer;
-            img->u.tex.last_layer = u->_Layer + stObj->base.MinLayer;
-            if (u->Layered && img->resource->array_size > 1) {
-               if (stObj->base.Immutable)
-                  img->u.tex.last_layer += stObj->base.NumLayers - 1;
-               else
-                  img->u.tex.last_layer += img->resource->array_size - 1;
-            }
-         }
-      }
+      st_convert_image(st, u, img);
    }
    cso_set_shader_images(st->cso_context, shader_type, 0,
                          prog->info.num_images, images);
index 0ce79895625a98c6b45e1ea36f2831a38ff71b92..00c30f06cf38ac94e76486bb20741471e8bc82b3 100644 (file)
@@ -254,4 +254,8 @@ st_create_color_map_texture(struct gl_context *ctx);
 bool
 st_etc_fallback(struct st_context *st, struct gl_texture_image *texImage);
 
+void
+st_convert_image(const struct st_context *st, const struct gl_image_unit *u,
+                 struct pipe_image_view *img);
+
 #endif