i965: Stop passing num_samples to intel_miptree_alloc_hiz().
[mesa.git] / src / mesa / drivers / dri / intel / intel_tex.c
index 4ab618ad7365189ab4eee0e5a89f4a2252c1b44c..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,34 +58,38 @@ 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);
 
+   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);
 
-   if (intel->must_use_separate_stencil
-       && image->TexFormat == MESA_FORMAT_S8_Z24) {
-      intel_tex_image_s8z24_create_renderbuffers(intel, intel_image);
-   }
+   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);
-      return true;
-   } else if (image->Border == 0) {
+          image->Width, image->Height, image->Depth, intel_texobj->mt);
+   } else {
       intel_image->mt = intel_miptree_create_for_teximage(intel, intel_texobj,
                                                           intel_image,
                                                           false);
@@ -92,15 +103,12 @@ 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);
-      return true;
+          image->Width, image->Height, image->Depth, intel_image->mt);
    }
 
-   DBG("%s: alloc obj %p level %d %dx%dx%d using swrast\n",
-       __FUNCTION__, texobj, image->Level, width, height, depth);
+   intel_texobj->needs_validate = true;
 
-   return _swrast_alloc_texture_image_buffer(ctx, image, format,
-                                            width, height, depth);
+   return true;
 }
 
 static void
@@ -113,18 +121,13 @@ intel_free_texture_image_buffer(struct gl_context * ctx,
 
    intel_miptree_release(&intelImage->mt);
 
-   if (texImage->Data) {
-      _mesa_free_texmemory(texImage->Data);
-      texImage->Data = NULL;
-   }
-
-   _mesa_reference_renderbuffer(&intelImage->depth_rb, NULL);
-   _mesa_reference_renderbuffer(&intelImage->stencil_rb, NULL);
+   _swrast_free_texture_image_buffer(ctx, texImage);
 }
 
 /**
  * Map texture memory/buffer into user space.
  * Note: the region of interest parameters are ignored here.
+ * \param mode  bitmask of GL_MAP_READ_BIT, GL_MAP_WRITE_BIT
  * \param mapOut  returns start of mapping of region of interest
  * \param rowStrideOut  returns row stride in bytes
  */
@@ -140,55 +143,22 @@ 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;
 
-   if (intel_image->stencil_rb) {
-      /*
-       * The texture has packed depth/stencil format, but uses separate
-       * stencil. The texture's embedded stencil buffer contains the real
-       * stencil data, so copy that into the miptree.
-       */
-      intel_tex_image_s8z24_gather(intel, intel_image);
-   }
-
-   /* For compressed formats, the stride is the number of bytes per
-    * row of blocks.  intel_miptree_get_image_offset() already does
-    * the divide.
-    */
-   _mesa_get_format_block_size(tex_image->TexFormat, &bw, &bh);
-   assert(y % bh == 0);
-   y /= bh;
+   /* Our texture data is always stored in a miptree. */
+   assert(mt);
 
-   if (likely(mt)) {
-      void *base = intel_region_map(intel, mt->region);
-      unsigned int image_x, image_y;
-
-      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);
-   } else {
-      /* texture data is in malloc'd memory */
-      GLuint width = tex_image->Width;
-      GLuint height = ALIGN(tex_image->Height, bh) / bh;
-      GLuint texelSize = _mesa_get_format_bytes(tex_image->TexFormat);
+   /* Check that our caller wasn't confused about how to map a 1D texture. */
+   assert(tex_image->TexObject->Target != GL_TEXTURE_1D_ARRAY ||
+         h == 1);
 
-      assert(map);
-
-      *stride = _mesa_format_row_stride(tex_image->TexFormat, width);
-      *map = tex_image->Data + (slice * height + y) * *stride + x * texelSize;
+   /* intel_miptree_map operates on a unified "slice" number that references the
+    * cube face, since it's all just slices to the miptree code.
+    */
+   if (tex_image->TexObject->Target == GL_TEXTURE_CUBE_MAP)
+      slice = tex_image->Face;
 
-      DBG("%s: %d,%d %dx%d from data %p = %p/%d\n", __FUNCTION__,
-         x, y, w, h,
-         tex_image->Data, *map, *stride);
-   }
+   intel_miptree_map(intel, mt, tex_image->Level, slice, x, y, w, h, mode,
+                    (void **)map, stride);
 }
 
 static void
@@ -197,46 +167,17 @@ intel_unmap_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;
 
-   if (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 (intel_image->stencil_rb) {
-      /*
-       * The texture has packed depth/stencil format, but uses separate
-       * stencil. The texture's embedded stencil buffer contains the real
-       * stencil data, so copy that into the miptree.
-       */
-      intel_tex_image_s8z24_scatter(intel, intel_image);
-   }
+   intel_miptree_unmap(intel, mt, tex_image->Level, slice);
 }
 
-/**
- * Called via ctx->Driver.GenerateMipmap()
- * This is basically a wrapper for _mesa_meta_GenerateMipmap() which checks
- * if we'll be using software mipmap generation.  In that case, we need to
- * map/unmap the base level texture image.
- */
-static void
-intelGenerateMipmap(struct gl_context *ctx, GLenum target,
-                    struct gl_texture_object *texObj)
-{
-   if (_mesa_meta_check_generate_mipmap_fallback(ctx, target, texObj)) {
-      fallback_debug("%s - fallback to swrast\n", __FUNCTION__);
-
-      _mesa_generate_mipmap(ctx, target, texObj);
-   }
-   else {
-      _mesa_meta_GenerateMipmap(ctx, target, texObj);
-   }
-}
-
-
 void
 intelInitTextureFuncs(struct dd_function_table *functions)
 {
-   functions->GenerateMipmap = intelGenerateMipmap;
-
    functions->NewTextureObject = intelNewTextureObject;
    functions->NewTextureImage = intelNewTextureImage;
    functions->DeleteTextureImage = intelDeleteTextureImage;