Bug 42334

Summary: [bisected i965]oglc textureNPOT(basic.allCases) segfaults
Product: Mesa Reporter: fangxun <xunx.fang>
Component: Drivers/DRI/i965Assignee: Anuj Phogat <anuj.phogat>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: high CC: eric
Version: git   
Hardware: All   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Bug Depends on:    
Bug Blocks: 42993    

Description fangxun 2011-10-28 02:29:18 UTC
System Environment:
--------------------------
Arch:           i386
Platform:       huronriver
Libdrm:         (master)2.4.26-18-gcc088f1721eaa5f8f1ba1932723882f92e34c39a
Mesa:           (master)27de26073b0ab385e57504d77197a33bb7b6c28f
Xserver:(master)xorg-server-1.11.0-193-gfb84be47db7cdaff406792c08e34670e8e0cbda9
Xf86_video_intel:  (master)2.16.0-205-ga18f559961135fa288dda3b94207abb0b6d4d302
Kernel:    (drm-intel-next)64a742fac3a22f57303d8f1b7e347350a1c48254

Bug detailed description:
------------------------- 
It segfaults on sandybridge and piketon. 
Backtrace:
Breakpoint 1 at 0x7ffff6a05ff6: file intel_tex.c, line 194

Bisect shows the first bad commit is 4ad8a0adec588b4c2c5a8f93265ed46cee5d3ff6.
commit 4ad8a0adec588b4c2c5a8f93265ed46cee5d3ff6
Author:     Eric Anholt <eric@anholt.net>
AuthorDate: Mon Oct 17 14:53:13 2011 -0700
Commit:     Eric Anholt <eric@anholt.net>
CommitDate: Wed Oct 26 12:42:28 2011 -0700

    intel: Drop texture border support code.

    Now that texture borders are gone, we never need to allocate our
    textures through non-miptrees, which simplifies some irritating paths.

    v2: Remove the !mt support case from intel_map_texture_image()

    Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> (v1)
    Reviewed-by: Brian Paul <brianp@vmware.com>

Reproduce steps:
----------------
1. start X
2. ./oglconform -z -s -suite all -v 2 -D 115 -test textureNPOT basic.allCases
Comment 1 Gordon Jin 2011-11-09 16:59:39 UTC
Eric, comments?
Comment 2 Anuj Phogat 2012-01-13 19:08:05 UTC
TestMipMaps() function in src/OGLconform/textureNPOT.c calls glTexImage2D() with width = 0 and height = 24. Zero image width results in to miptree not allocated for the image. This is due to a condition in function _mesa_store_teximage3d(), src/mesa/main/texstore.c

   if (width == 0 || height == 0 || depth == 0)
      return;

   /* allocate storage for texture data */
   if (!ctx->Driver.AllocTextureImageBuffer(ctx, texImage, texImage->TexFormat,
                                            width, height, depth)) {
      _mesa_error(ctx, GL_OUT_OF_MEMORY, "glTexImage3D");
      return;
   }

   store_texsubimage(ctx, texImage,
                     0, 0, 0, width, height, depth,
                     format, type, pixels, packing, "glTexImage3D");

Removing the following statements from _mesa_store_teximage3d function resolve the issue:
   if (width == 0 || height == 0 || depth == 0)
      return;

But i'm not sure if this breaks any other test. I'll send out a patch for review on mesa mailing list.
Comment 3 Anuj Phogat 2012-01-17 17:15:21 UTC
This issue has been resolved by below listed patch:
http://www.mail-archive.com/mesa-dev@lists.freedesktop.org/msg17302.html

commit logs on mesa master:
commit f1a9a9bcd19dcbb8a0a4bd7299400cb418970f99
Author: Anuj Phogat <anuj.phogat@gmail.com>
Date:   Mon Jan 16 16:15:30 2012 -0800

    mesa: Add condition in glGetTexImage for zero size textures
    
    TestMipMaps() function in src/OGLconform/textureNPOT.c calls glTexImage2D()
    with width = 0. Texture with zero size skips miptree allocation due to a
    condition in function _mesa_store_teximage3d(). While calling glGetTexImage()
    it results in assertion failure in intel_map_texture_image() due to null mt
    pointer.
    
    This patch fixes the issue by detecting the zero size texture early in
    glGetTexImage and glGetCompressedTexImage functions. In such a case function
    simply returns doing nothing.
    Verified that below mentioned bug is fixed by this patch.
    
    https://bugs.freedesktop.org/show_bug.cgi?id=42334
    
    NOTE: This is a candidate for stable branches
    
    Signed-off-by: Anuj Phogat <anuj.phogat@gmail.com>
    Reviewed-by: Brian Paul <brianp@vmware.com>
Comment 4 Gordon Jin 2012-01-30 16:31:26 UTC
I see the patch has landed in mesa 8.0 and 7.11 branch. 

Xun, please verify.
Comment 5 fangxun 2012-02-07 02:47:54 UTC
Verified with mesa master branch(aed51e3e) and mesa 8.0 branch(65b50085).

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.