st/mesa: add st_create_{texture,image}_handle_from_unit() helper
authorSamuel Pitoiset <samuel.pitoiset@gmail.com>
Tue, 9 May 2017 12:32:06 +0000 (14:32 +0200)
committerSamuel Pitoiset <samuel.pitoiset@gmail.com>
Wed, 14 Jun 2017 08:04:36 +0000 (10:04 +0200)
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_texture.c

index 2e9856dcdfdfc33cf5410232a2c4b94881135b00..7da111f39f3bf6016a050d6e8ebfe6ceadaa7044 100644 (file)
@@ -420,3 +420,44 @@ st_create_color_map_texture(struct gl_context *ctx)
                           texSize, texSize, 1, 1, 0, PIPE_BIND_SAMPLER_VIEW);
    return pt;
 }
+
+
+/**
+ * Create a texture handle from a texture unit.
+ */
+static GLuint64
+st_create_texture_handle_from_unit(struct st_context *st,
+                                   struct gl_program *prog, GLuint texUnit)
+{
+   struct gl_context *ctx = st->ctx;
+   struct gl_texture_object *texObj;
+   struct pipe_context *pipe = st->pipe;
+   struct pipe_sampler_view *view;
+   struct pipe_sampler_state sampler;
+
+   if (!st_update_single_texture(st, &view, texUnit, prog->sh.data->Version))
+      return 0;
+
+   st_convert_sampler_from_unit(st, &sampler, texUnit);
+
+   texObj = ctx->Texture.Unit[texUnit]._Current;
+   assert(texObj);
+
+   return pipe->create_texture_handle(pipe, view, &sampler);
+}
+
+
+/**
+ * Create an image handle from an image unit.
+ */
+static GLuint64
+st_create_image_handle_from_unit(struct st_context *st,
+                                 struct gl_program *prog, GLuint imgUnit)
+{
+   struct pipe_context *pipe = st->pipe;
+   struct pipe_image_view img;
+
+   st_convert_image_from_unit(st, &img, imgUnit);
+
+   return pipe->create_image_handle(pipe, &img);
+}