i965: Stop passing num_samples to intel_miptree_alloc_hiz().
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex.c
index 505e617d7096be8a3b68f159f23ac1f5ba06d315..24f13dfee8993933345666fb0f0847223594978d 100644 (file)
@@ -7,6 +7,7 @@
 #include "intel_context.h"
 #include "intel_mipmap_tree.h"
 #include "intel_tex.h"
+#include "intel_fbo.h"
 
 #define FILE_DEBUG_FLAG DEBUG_TEXTURE
 
@@ -34,8 +35,14 @@ intelNewTextureObject(struct gl_context * ctx, GLuint name, GLenum target)
    (void) ctx;
 
    DBG("%s\n", __FUNCTION__);
+
+   if (obj == NULL)
+      return NULL;
+
    _mesa_initialize_texture_object(&obj->base, name, target);
 
+   obj->needs_validate = true;
+
    return &obj->base;
 }
 
@@ -51,45 +58,37 @@ intelDeleteTextureObject(struct gl_context *ctx,
 
 static GLboolean
 intel_alloc_texture_image_buffer(struct gl_context *ctx,
-                                struct gl_texture_image *image,
-                                gl_format format, GLsizei width,
-                                GLsizei height, GLsizei depth)
+                                struct gl_texture_image *image)
 {
    struct intel_context *intel = intel_context(ctx);
    struct intel_texture_image *intel_image = intel_texture_image(image);
    struct gl_texture_object *texobj = image->TexObject;
    struct intel_texture_object *intel_texobj = intel_texture_object(texobj);
-   GLuint slices;
 
    assert(image->Border == 0);
 
+   /* Quantize sample count */
+   if (image->NumSamples) {
+      image->NumSamples = intel_quantize_num_samples(intel->intelScreen, image->NumSamples);
+      if (!image->NumSamples)
+         return false;
+   }
+
    /* Because the driver uses AllocTextureImageBuffer() internally, it may end
     * up mismatched with FreeTextureImageBuffer(), but that is safe to call
     * multiple times.
     */
    ctx->Driver.FreeTextureImageBuffer(ctx, image);
 
-   /* Allocate the swrast_texture_image::ImageOffsets array now */
-   switch (texobj->Target) {
-   case GL_TEXTURE_3D:
-   case GL_TEXTURE_2D_ARRAY:
-      slices = image->Depth;
-      break;
-   case GL_TEXTURE_1D_ARRAY:
-      slices = image->Height;
-      break;
-   default:
-      slices = 1;
-   }
-   assert(!intel_image->base.ImageOffsets);
-   intel_image->base.ImageOffsets = malloc(slices * sizeof(GLuint));
+   if (!_swrast_init_texture_image(image))
+      return false;
 
    if (intel_texobj->mt &&
        intel_miptree_match_image(intel_texobj->mt, image)) {
       intel_miptree_reference(&intel_image->mt, intel_texobj->mt);
       DBG("%s: alloc obj %p level %d %dx%dx%d using object's miptree %p\n",
           __FUNCTION__, texobj, image->Level,
-          width, height, depth, intel_texobj->mt);
+          image->Width, image->Height, image->Depth, intel_texobj->mt);
    } else {
       intel_image->mt = intel_miptree_create_for_teximage(intel, intel_texobj,
                                                           intel_image,
@@ -104,9 +103,11 @@ intel_alloc_texture_image_buffer(struct gl_context *ctx,
 
       DBG("%s: alloc obj %p level %d %dx%dx%d using new miptree %p\n",
           __FUNCTION__, texobj, image->Level,
-          width, height, depth, intel_image->mt);
+          image->Width, image->Height, image->Depth, intel_image->mt);
    }
 
+   intel_texobj->needs_validate = true;
+
    return true;
 }
 
@@ -120,15 +121,7 @@ intel_free_texture_image_buffer(struct gl_context * ctx,
 
    intel_miptree_release(&intelImage->mt);
 
-   if (intelImage->base.Buffer) {
-      _mesa_align_free(intelImage->base.Buffer);
-      intelImage->base.Buffer = NULL;
-   }
-
-   if (intelImage->base.ImageOffsets) {
-      free(intelImage->base.ImageOffsets);
-      intelImage->base.ImageOffsets = NULL;
-   }
+   _swrast_free_texture_image_buffer(ctx, texImage);
 }
 
 /**
@@ -150,9 +143,6 @@ intel_map_texture_image(struct gl_context *ctx,
    struct intel_context *intel = intel_context(ctx);
    struct intel_texture_image *intel_image = intel_texture_image(tex_image);
    struct intel_mipmap_tree *mt = intel_image->mt;
-   unsigned int bw, bh;
-   void *base;
-   unsigned int image_x, image_y;
 
    /* Our texture data is always stored in a miptree. */
    assert(mt);
@@ -161,36 +151,14 @@ intel_map_texture_image(struct gl_context *ctx,
    assert(tex_image->TexObject->Target != GL_TEXTURE_1D_ARRAY ||
          h == 1);
 
-   if (mt->stencil_mt) {
-      /* The miptree has depthstencil format, but uses separate stencil. The
-       * embedded stencil miptree contains the real stencil data, so gather
-       * that into the depthstencil miptree.
-       *
-       * FIXME: Avoid the gather if the texture is mapped as write-only.
-       */
-      intel_miptree_s8z24_gather(intel, mt, tex_image->Level, slice);
-   }
-
-   /* For compressed formats, the stride is the number of bytes per
-    * row of blocks.  intel_miptree_get_image_offset() already does
-    * the divide.
+   /* intel_miptree_map operates on a unified "slice" number that references the
+    * cube face, since it's all just slices to the miptree code.
     */
-   _mesa_get_format_block_size(tex_image->TexFormat, &bw, &bh);
-   assert(y % bh == 0);
-   y /= bh;
-
-   base = intel_region_map(intel, mt->region, mode);
-   intel_miptree_get_image_offset(mt, tex_image->Level, tex_image->Face,
-                                 slice, &image_x, &image_y);
-   x += image_x;
-   y += image_y;
-
-   *stride = mt->region->pitch * mt->cpp;
-   *map = base + y * *stride + x * mt->cpp;
-
-   DBG("%s: %d,%d %dx%d from mt %p %d,%d = %p/%d\n", __FUNCTION__,
-       x - image_x, y - image_y, w, h,
-       mt, x, y, *map, *stride);
+   if (tex_image->TexObject->Target == GL_TEXTURE_CUBE_MAP)
+      slice = tex_image->Face;
+
+   intel_miptree_map(intel, mt, tex_image->Level, slice, x, y, w, h, mode,
+                    (void **)map, stride);
 }
 
 static void
@@ -201,18 +169,10 @@ intel_unmap_texture_image(struct gl_context *ctx,
    struct intel_texture_image *intel_image = intel_texture_image(tex_image);
    struct intel_mipmap_tree *mt = intel_image->mt;
 
-   intel_region_unmap(intel, intel_image->mt->region);
+   if (tex_image->TexObject->Target == GL_TEXTURE_CUBE_MAP)
+      slice = tex_image->Face;
 
-   if (mt->stencil_mt) {
-      /* The miptree has depthstencil format, but uses separate stencil. The
-       * embedded stencil miptree must contain the real stencil data after
-       * unmapping, so copy it from the depthstencil miptree into the stencil
-       * miptree.
-       *
-       * FIXME: Avoid the scatter if the texture was mapped as read-only.
-       */
-      intel_miptree_s8z24_scatter(intel, mt, tex_image->Level, slice);
-   }
+   intel_miptree_unmap(intel, mt, tex_image->Level, slice);
 }
 
 void