i965: Add support for GL_EXT_texture_array and GL_MESA_texture_array.
authorEric Anholt <eric@anholt.net>
Tue, 6 Sep 2011 17:21:54 +0000 (10:21 -0700)
committerEric Anholt <eric@anholt.net>
Mon, 3 Oct 2011 20:29:38 +0000 (13:29 -0700)
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/brw_tex_layout.c
src/mesa/drivers/dri/i965/brw_wm_emit.c
src/mesa/drivers/dri/i965/brw_wm_pass1.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c
src/mesa/drivers/dri/intel/intel_extensions.c
src/mesa/drivers/dri/intel/intel_mipmap_tree.c
src/mesa/drivers/dri/intel/intel_tex_layout.c
src/mesa/drivers/dri/intel/intel_tex_validate.c

index 9aabb7a1d7032422984d72d9332b1651e7aad405..dc91852753fd708e9ccb9748badc426c0a5ce7af 100644 (file)
@@ -100,6 +100,11 @@ GLboolean brwCreateContext( int api,
           ctx->Const.MaxTextureLevels = MAX_TEXTURE_LEVELS;
    ctx->Const.Max3DTextureLevels = 9;
    ctx->Const.MaxCubeTextureLevels = 12;
+   /* minimum maximum.  Users are likely to run into memory problems
+    * even at this size, since 64 * 2048 * 2048 * 4 = 1GB and we can't
+    * address that much.
+    */
+   ctx->Const.MaxArrayTextureLayers = 64;
    ctx->Const.MaxTextureRectSize = (1<<12);
    
    ctx->Const.MaxTextureMaxAnisotropy = 16.0;
index e030ffcd21f89c6e9c4c26cb05aa3b46d5bc8bd4..d77bf4d7cd97d3139f48f18aeea02eab173f94e4 100644 (file)
@@ -168,6 +168,11 @@ brw_miptree_layout(struct intel_context *intel, struct intel_mipmap_tree *mt)
       break;
    }
 
+   case GL_TEXTURE_2D_ARRAY:
+   case GL_TEXTURE_1D_ARRAY:
+      brw_miptree_layout_texture_array(intel, mt, mt->depth0);
+      break;
+
    default:
       i945_miptree_layout_2d(mt, 1);
       break;
index 6ea4a7d6e501535516137eb6d99cebf14cf359ee..c20b07997fe671329c207cb657207bb578c2dcbc 100644 (file)
@@ -1076,11 +1076,13 @@ void emit_tex(struct brw_wm_compile *c,
       nr_texcoords = 1;
       break;
    case TEXTURE_2D_INDEX:
+   case TEXTURE_1D_ARRAY_INDEX:
    case TEXTURE_RECT_INDEX:
       emit = WRITEMASK_XY;
       nr_texcoords = 2;
       break;
    case TEXTURE_3D_INDEX:
+   case TEXTURE_2D_ARRAY_INDEX:
    case TEXTURE_CUBE_INDEX:
       emit = WRITEMASK_XYZ;
       nr_texcoords = 3;
index 7d6a3fa9f12e38fd3640b26a141a8b45c687508e..ee7a627455f9b3762c004d3234ea1cc3d78ad4dc 100644 (file)
@@ -93,8 +93,10 @@ static GLuint get_texcoord_mask( GLuint tex_idx )
    case TEXTURE_1D_INDEX:
       return WRITEMASK_X;
    case TEXTURE_2D_INDEX:
+   case TEXTURE_1D_ARRAY_INDEX:
       return WRITEMASK_XY;
    case TEXTURE_3D_INDEX:
+   case TEXTURE_2D_ARRAY_INDEX:
       return WRITEMASK_XYZ;
    case TEXTURE_CUBE_INDEX:
       return WRITEMASK_XYZ;
index 452ee4e7926e8f648dd2025803203253b1b05a38..d6cea7d19e9462fe73693a36f2aaf8392a50d6dc 100644 (file)
@@ -50,12 +50,14 @@ translate_tex_target(GLenum target)
 {
    switch (target) {
    case GL_TEXTURE_1D: 
+   case GL_TEXTURE_1D_ARRAY_EXT:
       return BRW_SURFACE_1D;
 
    case GL_TEXTURE_RECTANGLE_NV: 
       return BRW_SURFACE_2D;
 
    case GL_TEXTURE_2D: 
+   case GL_TEXTURE_2D_ARRAY_EXT:
       return BRW_SURFACE_2D;
 
    case GL_TEXTURE_3D: 
index c69c285b176eabf95c1b5d7c4e3bd50aec2d5d33..7a5ef3e5f05bd8e538d110f7a98649e44564e68d 100644 (file)
@@ -116,12 +116,14 @@ intelInitExtensions(struct gl_context *ctx)
       ctx->Extensions.ARB_texture_rg = true;
       ctx->Extensions.EXT_draw_buffers2 = true;
       ctx->Extensions.EXT_framebuffer_sRGB = true;
+      ctx->Extensions.EXT_texture_array = true;
       ctx->Extensions.EXT_texture_snorm = true;
       ctx->Extensions.EXT_texture_sRGB = true;
       ctx->Extensions.EXT_texture_sRGB_decode = true;
       ctx->Extensions.EXT_texture_swizzle = true;
       ctx->Extensions.EXT_vertex_array_bgra = true;
       ctx->Extensions.ATI_envmap_bumpmap = true;
+      ctx->Extensions.MESA_texture_array = true;
       ctx->Extensions.NV_conditional_render = true;
    }
 
index 683dfb9a045ae1616bceaf62e01530754369a2d3..dbdc5efeae94fd3f3f1e4ae28acce5db7ccdba7c 100644 (file)
@@ -319,15 +319,22 @@ intel_miptree_get_image_offset(struct intel_mipmap_tree *mt,
                               GLuint level, GLuint face, GLuint depth,
                               GLuint *x, GLuint *y)
 {
-   if (mt->target == GL_TEXTURE_CUBE_MAP_ARB) {
+   switch (mt->target) {
+   case GL_TEXTURE_CUBE_MAP_ARB:
       *x = mt->level[level].x_offset[face];
       *y = mt->level[level].y_offset[face];
-   } else if (mt->target == GL_TEXTURE_3D) {
+      break;
+   case GL_TEXTURE_3D:
+   case GL_TEXTURE_2D_ARRAY_EXT:
+   case GL_TEXTURE_1D_ARRAY_EXT:
+      assert(depth < mt->level[level].nr_images);
       *x = mt->level[level].x_offset[depth];
       *y = mt->level[level].y_offset[depth];
-   } else {
+      break;
+   default:
       *x = mt->level[level].x_offset[0];
       *y = mt->level[level].y_offset[0];
+      break;
    }
 }
 
index e796aaf00450ca74b27dff60de5b766252d6ec97..64f4a70c52cc2bb3b4b06f459acbbf956a2df12d 100644 (file)
@@ -58,6 +58,7 @@ void i945_miptree_layout_2d(struct intel_mipmap_tree *mt, int nr_images)
    GLuint y = 0;
    GLuint width = mt->width0;
    GLuint height = mt->height0;
+   GLuint depth = mt->depth0; /* number of array layers. */
 
    mt->total_width = mt->width0;
    intel_get_texture_alignment_unit(mt->format, &align_w, &align_h);
@@ -93,7 +94,7 @@ void i945_miptree_layout_2d(struct intel_mipmap_tree *mt, int nr_images)
       GLuint img_height;
 
       intel_miptree_set_level_info(mt, level, nr_images, x, y, width,
-                                  height, 1);
+                                  height, depth);
 
       img_height = ALIGN(height, align_h);
       if (mt->compressed)
index c06279ce25ea68b9f0ff23f93481b4d27731e479..50dc8c0b58dbbfc46fdb7b72333a546ecfd9781a 100644 (file)
@@ -138,9 +138,21 @@ intel_tex_map_image_for_swrast(struct intel_context *intel,
 
    mt = intel_image->mt;
 
-   if (mt->target == GL_TEXTURE_3D) {
+   if (mt->target == GL_TEXTURE_3D ||
+       mt->target == GL_TEXTURE_2D_ARRAY ||
+       mt->target == GL_TEXTURE_1D_ARRAY) {
       int i;
 
+      if (mt->target == GL_TEXTURE_2D_ARRAY ||
+          mt->target == GL_TEXTURE_1D_ARRAY) {
+         /* Mesa only allocates one entry for these, but we really do have an
+          * offset per depth.
+          */
+         free(intel_image->base.Base.ImageOffsets);
+         intel_image->base.Base.ImageOffsets = malloc(mt->level[level].depth *
+                                                      sizeof(GLuint));
+      }
+
       /* ImageOffsets[] is only used for swrast's fetch_texel_3d, so we can't
        * share code with the normal path.
        */