tgsi/ureg: remove index parameter from ureg_DECL_system_value
[mesa.git] / src / mesa / state_tracker / st_texture.c
index f664ef5f140b8c99794579df1387474a080c3704..52b094330b9b28f0e553350792afb052bbc80e9a 100644 (file)
@@ -74,7 +74,7 @@ st_texture_create(struct st_context *st,
    if (target == PIPE_TEXTURE_CUBE)
       assert(layers == 6);
 
-   DBG("%s target %d format %s last_level %d\n", __FUNCTION__,
+   DBG("%s target %d format %s last_level %d\n", __func__,
        (int) target, util_format_name(format), last_level);
 
    assert(format);
@@ -88,7 +88,7 @@ st_texture_create(struct st_context *st,
    pt.width0 = width0;
    pt.height0 = height0;
    pt.depth0 = depth0;
-   pt.array_size = (target == PIPE_TEXTURE_CUBE ? 6 : layers);
+   pt.array_size = layers;
    pt.usage = PIPE_USAGE_DEFAULT;
    pt.bind = bind;
    pt.flags = 0;
@@ -177,7 +177,7 @@ st_gl_texture_dims_to_pipe_dims(GLenum texture,
       *widthOut = widthIn;
       *heightOut = heightIn;
       *depthOut = 1;
-      *layersOut = depthIn;
+      *layersOut = util_align_npot(depthIn, 6);
       break;
    default:
       assert(0 && "Unexpected texture in st_gl_texture_dims_to_pipe_dims()");
@@ -197,7 +197,8 @@ st_gl_texture_dims_to_pipe_dims(GLenum texture,
  * Check if a texture image can be pulled into a unified mipmap texture.
  */
 GLboolean
-st_texture_match_image(const struct pipe_resource *pt,
+st_texture_match_image(struct st_context *st,
+                       const struct pipe_resource *pt,
                        const struct gl_texture_image *image)
 {
    GLuint ptWidth, ptHeight, ptDepth, ptLayers;
@@ -209,7 +210,7 @@ st_texture_match_image(const struct pipe_resource *pt,
 
    /* Check if this image's format matches the established texture's format.
     */
-   if (st_mesa_format_to_pipe_format(image->TexFormat) != pt->format)
+   if (st_mesa_format_to_pipe_format(st, image->TexFormat) != pt->format)
       return GL_FALSE;
 
    st_gl_texture_dims_to_pipe_dims(image->TexObject->Target,
@@ -249,7 +250,7 @@ st_texture_image_map(struct st_context *st, struct st_texture_image *stImage,
    GLuint level;
    void *map;
 
-   DBG("%s \n", __FUNCTION__);
+   DBG("%s \n", __func__);
 
    if (!stImage->pt)
       return NULL;
@@ -259,6 +260,13 @@ st_texture_image_map(struct st_context *st, struct st_texture_image *stImage,
    else
       level = stImage->base.Level;
 
+   if (stObj->base.Immutable) {
+      level += stObj->base.MinLevel;
+      z += stObj->base.MinLayer;
+      if (stObj->pt->array_size > 1)
+         d = MIN2(d, stObj->base.NumLayers);
+   }
+
    z += stImage->base.Face;
 
    map = pipe_transfer_map_3d(st->pipe, stImage->pt, level, usage,
@@ -269,14 +277,15 @@ st_texture_image_map(struct st_context *st, struct st_texture_image *stImage,
          unsigned new_size = z + 1;
 
          stImage->transfer = realloc(stImage->transfer,
-                                     new_size * sizeof(void*));
+                     new_size * sizeof(struct st_texture_image_transfer));
          memset(&stImage->transfer[stImage->num_transfers], 0,
-               (new_size - stImage->num_transfers) * sizeof(void*));
+                (new_size - stImage->num_transfers) *
+                sizeof(struct st_texture_image_transfer));
          stImage->num_transfers = new_size;
       }
 
-      assert(!stImage->transfer[z]);
-      stImage->transfer[z] = *transfer;
+      assert(!stImage->transfer[z].transfer);
+      stImage->transfer[z].transfer = *transfer;
    }
    return map;
 }
@@ -287,55 +296,20 @@ st_texture_image_unmap(struct st_context *st,
                        struct st_texture_image *stImage, unsigned slice)
 {
    struct pipe_context *pipe = st->pipe;
-   struct pipe_transfer **transfer =
-      &stImage->transfer[slice + stImage->base.Face];
+   struct st_texture_object *stObj =
+      st_texture_object(stImage->base.TexObject);
+   struct pipe_transfer **transfer;
+
+   if (stObj->base.Immutable)
+      slice += stObj->base.MinLayer;
+   transfer = &stImage->transfer[slice + stImage->base.Face].transfer;
 
-   DBG("%s\n", __FUNCTION__);
+   DBG("%s\n", __func__);
 
    pipe_transfer_unmap(pipe, *transfer);
    *transfer = NULL;
 }
 
-
-/* Upload data for a particular image.
- */
-void
-st_texture_image_data(struct st_context *st,
-                      struct pipe_resource *dst,
-                      GLuint face,
-                      GLuint level,
-                      void *src,
-                      GLuint src_row_stride, GLuint src_image_stride)
-{
-   struct pipe_context *pipe = st->pipe;
-   GLuint i;
-   const GLubyte *srcUB = src;
-   GLuint layers;
-
-   if (dst->target == PIPE_TEXTURE_1D_ARRAY ||
-       dst->target == PIPE_TEXTURE_2D_ARRAY ||
-       dst->target == PIPE_TEXTURE_CUBE_ARRAY)
-      layers = dst->array_size;
-   else
-      layers = u_minify(dst->depth0, level);
-
-   DBG("%s\n", __FUNCTION__);
-
-   for (i = 0; i < layers; i++) {
-      struct pipe_box box;
-      u_box_2d_zslice(0, 0, face + i,
-                      u_minify(dst->width0, level),
-                      u_minify(dst->height0, level),
-                      &box);
-
-      pipe->transfer_inline_write(pipe, dst, level, PIPE_TRANSFER_WRITE,
-                                  &box, srcUB, src_row_stride, 0);
-
-      srcUB += src_image_stride;
-   }
-}
-
-
 /**
  * For debug only: get/print center pixel in the src resource.
  */
@@ -394,6 +368,14 @@ st_texture_image_copy(struct pipe_context *pipe,
    src_box.width = width;
    src_box.height = height;
    src_box.depth = 1;
+
+   if (src->target == PIPE_TEXTURE_1D_ARRAY ||
+       src->target == PIPE_TEXTURE_2D_ARRAY ||
+       src->target == PIPE_TEXTURE_CUBE_ARRAY) {
+      face = 0;
+      depth = src->array_size;
+   }
+
    /* Loop over 3D image slices */
    /* could (and probably should) use "true" 3d box here -
       but drivers can't quite handle it yet */
@@ -443,7 +425,7 @@ struct pipe_sampler_view **
 st_texture_get_sampler_view(struct st_context *st,
                             struct st_texture_object *stObj)
 {
-   struct pipe_sampler_view **used = NULL, **free = NULL;
+   struct pipe_sampler_view *used = NULL, **free = NULL;
    GLuint i;
 
    for (i = 0; i < stObj->num_sampler_views; ++i) {
@@ -455,7 +437,7 @@ st_texture_get_sampler_view(struct st_context *st,
             return sv;
 
          /* Wasn't the right one, but remember it as template */
-         used = sv;
+         used = *sv;
       } else {
          /* Found a free slot, remember that */
          free = sv;
@@ -475,11 +457,16 @@ st_texture_get_sampler_view(struct st_context *st,
 
    /* Add just any sampler view to be used as a template */
    if (used)
-      pipe_sampler_view_reference(free, *used);
+      pipe_sampler_view_reference(free, used);
 
    return free;
 }
 
+
+/**
+ * For the given texture object, release any sampler views which belong
+ * to the calling context.
+ */
 void
 st_texture_release_sampler_view(struct st_context *st,
                                 struct st_texture_object *stObj)
@@ -496,13 +483,20 @@ st_texture_release_sampler_view(struct st_context *st,
    }
 }
 
+
+/**
+ * Release all sampler views attached to the given texture object, regardless
+ * of the context.
+ */
 void
-st_texture_release_all_sampler_views(struct st_texture_object *stObj)
+st_texture_release_all_sampler_views(struct st_context *st,
+                                     struct st_texture_object *stObj)
 {
    GLuint i;
 
+   /* XXX This should use sampler_views[i]->pipe, not st->pipe */
    for (i = 0; i < stObj->num_sampler_views; ++i)
-      pipe_sampler_view_reference(&stObj->sampler_views[i], NULL);
+      pipe_sampler_view_release(st->pipe, &stObj->sampler_views[i]);
 }