Bug 9829 - [i965] Segfault with maximum texture units
Summary: [i965] Segfault with maximum texture units
Status: VERIFIED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: Drivers/DRI/i965 (show other bugs)
Version: git
Hardware: x86 (IA32) Linux (All)
: medium normal
Assignee: haihao
QA Contact:
URL:
Whiteboard:
Keywords:
: 9913 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-01-31 19:08 UTC by WuNian
Modified: 2009-08-24 12:25 UTC (History)
3 users (show)

See Also:
i915 platform:
i915 features:


Attachments
test case (3.03 KB, text/plain)
2007-01-31 19:11 UTC, WuNian
Details

Description WuNian 2007-01-31 19:08:31 UTC
By calling glGetIntegerv(GL_MAX_TEXTURE_UNITS, &numTextures), the max texture units is 8 in my i965 or i915 machines. If I create 8 textures and use them to draw a polygon, it will crash X when DRI is disabled, below is the error info:

Backtrace:
0: X(xf86SigHandler+0x81) [0x80b6da1]
1: [0xb7ffb420]
2: /opt/X11R7/lib/dri/i965_dri.so(_mesa_UpdateTexEnvProgram+0x124e) [0xa7afc24e]
3: /opt/X11R7/lib/dri/i965_dri.so(_mesa_update_state_locked+0x625) [0xa7af28a5]
4: /opt/X11R7/lib/dri/i965_dri.so(_mesa_update_state+0x2a) [0xa7af2928]
5: /opt/X11R7/lib/dri/i965_dri.so [0xa7a7cefc]
6: /opt/X11R7/lib/xorg/modules/extensions//libglx.so [0xb7e96a05]
7: /opt/X11R7/lib/xorg/modules/extensions//libglx.so(DoRender+0x155) [0xb7e91285]
8: /opt/X11R7/lib/xorg/modules/extensions//libglx.so [0xb7e9131c]
9: /opt/X11R7/lib/xorg/modules/extensions//libglx.so [0xb7e9576c]
10: X [0x813c81e]
11: X(Dispatch+0x19f) [0x808700f]
12: X(main+0x495) [0x806f155]
13: /lib/libc.so.6(__libc_start_main+0xdc) [0x95c7e4]
14: X(FontFileCompleteXLFD+0xa1) [0x806e481]

Fatal server error:
Caught signal 11.  Server aborting

If I use 7 texture to draw a polygon, it is OK.

If DRI is enable, it will result in segment fault, the error occurs in same  above location(_mesa_UpdateTexEnvProgram).

This bug do not exist in mesa-6.5.2.
Comment 1 WuNian 2007-01-31 19:11:53 UTC
Created attachment 8555 [details]
test case

You can change the Macro: "#define MAX_TEXTURES 8" to control how much texture units to be used.
If change the Macro value to 7, the case will pass.
Comment 2 Eric Anholt 2007-02-01 12:25:01 UTC
Changed the subject and moved to 965 driver, since sounds like just a segfault in the DRI driver.
Comment 3 Wei Wang 2007-02-01 21:52:26 UTC
It would be better to paste the stack info provided by gdb (bt), which may tell the exact calling path :)
Comment 4 Wei Wang 2007-02-08 04:25:37 UTC
I gave a quick try of this attached code (named as multitex.c) and found that the code break at " _XSend(dpy, (char *)ctx->buf, size) " (line 1372, glx/x11/glxext.c) which is called by __glXFlushRenderBuffer(), here is the calling stack:


#0  __glXFlushRenderBuffer (ctx=0x8050ef0, pc=0xb7bff2d4 "") at glxext.c:1374
#1  0xb7ee567d in __indirect_glFlush () at single2.c:507
#2  0xb7ef81ea in glFlush () at ../../../src/mesa/glapi/glapitemp.h:1170
#3  0x08048d4d in test () at multitex.c:55
#4  0x08048f69 in display () at multitex.c:101
#5  0xb7e161ff in processWindowWorkList (window=0x804fcf8) at glut_event.c:1302
#6  0xb7e16cd2 in glutMainLoop () at glut_event.c:1349
#7  0x08048fe5 in main (argc=1, argv=0xbfc905b4) at multitex.c:113
Comment 5 WuNian 2007-02-08 18:01:24 UTC
Below is GDB info when DRI is enabled:

(gdb) p p->program->NumAluInstructions 
$4 = 15
(gdb) c
Continuing.

Breakpoint 2, emit_arith (p=0xbfab9e80, op=OPCODE_END, dest=
      {file = 10, idx = 255, negatebase = 0, abs = 0, negateabs = 0, swz = 0, pad = 0}, mask=15, saturate=0 '\0', src0=
      {file = 10, idx = 255, negatebase = 0, abs = 0, negateabs = 0, swz = 0, pad = 0}, src1=
      {file = 10, idx = 255, negatebase = 0, abs = 0, negateabs = 0, swz = 0, pad = 0}, src2=
      {file = 10, idx = 255, negatebase = 0, abs = 0, negateabs = 0, swz = 0, pad = 0}) at main/texenvprogram.c:509
509     {
(gdb) c
Continuing.

Breakpoint 3, emit_arith (p=0xbfab9e80, op=Variable "op" is not available.
) at main/texenvprogram.c:526
526        p->program->NumAluInstructions++;
(gdb) bt
#0  emit_arith (p=0xbfab9e80, op=Variable "op" is not available.
) at main/texenvprogram.c:526
#1  0xb7b7024e in _mesa_UpdateTexEnvProgram (ctx=0x8057a08)
    at main/texenvprogram.c:1076
#2  0xb7b668a5 in _mesa_update_state_locked (ctx=0x8057a08)
    at main/state.c:1141
#3  0xb7b66928 in _mesa_update_state (ctx=0x8057a08) at main/state.c:1178
#4  0xb7c3b8d9 in _mesa_Clear (mask=16384) at main/buffers.c:134
#5  0xb7ee91da in glClear (mask=16384)
    at ../../../src/mesa/glapi/glapitemp.h:1100
#6  0x08048d0b in test () at multitex.c:35
#7  0x08049099 in display () at multitex.c:101
#8  0xb7f924bf in processWindowWorkList (window=0x804fce8) at glut_event.c:1302
#9  0xb7f92f92 in glutMainLoop () at glut_event.c:1349
#10 0x08049115 in main (argc=1, argv=0xbfaba364) at multitex.c:113
(gdb) p p->program->NumAluInstructions 
Cannot access memory at address 0x880
(gdb) c
Continuing.

Program received signal SIGSEGV, Segmentation fault.
0xb7b6d70a in emit_arith (p=0xbfab9e80, op=Variable "op" is not available.
) at main/texenvprogram.c:526
526        p->program->NumAluInstructions++;
(gdb) 

Above info is simiarly with bug #9913. But in bug #9913, it applied texture combiner operations (GL_INTERPOLATE_ARB for GL_COMBINE_RGB_ARB;
GL_ADD_SIGNED_ARB for GL_COMBINE_ALPHA_ARB). If it do not applied texture combiner operation, it can pass.
Comment 6 Roland Scheidegger 2007-03-22 03:16:34 UTC
Looks to me like the buffer holding the instructions is too small (#define MAX_INSTRUCTIONS 24), despite the comment 21 would be enough. At first sight, it looks like the maximum number of instructions could be as high as 6 per unit (1 tex load, 2 * 2 + 1 arithmetic (some modes require 2 arithmetic instructions, can have different mode for RGB and A, plus 1 for shift), plus the final 3 for separate specular and the END opcode respectively. That's 51.
Comment 7 Brian Paul 2007-03-22 06:46:45 UTC
The comment about 21 instructions was mine.  I could be wrong though.  Roland's analysis sounds correct.  Does this fix things?

#define MAX_INSTRUCTIONS ((MAX_TEXTURE_UNITS * 6) + 10)

Adding 10 just to be safe.
Comment 8 WuNian 2007-07-02 20:19:59 UTC
With i915 driver, the bug also exists.
Comment 9 Roland Scheidegger 2007-07-03 05:02:02 UTC
(In reply to comment #8)
> With i915 driver, the bug also exists.

The bug should be driver-independant (as long as the driver uses mesa's code to convert texture state to fragment programs).
So, does Brian's fix help?
Comment 10 haihao 2007-08-16 22:19:56 UTC
*** Bug 9913 has been marked as a duplicate of this bug. ***
Comment 11 haihao 2007-08-16 22:27:15 UTC
(In reply to comment #7)
> The comment about 21 instructions was mine.  I could be wrong though.  Roland's
> analysis sounds correct.  Does this fix things?
> 
> #define MAX_INSTRUCTIONS ((MAX_TEXTURE_UNITS * 6) + 10)

It works well. I check it into git

Comment 12 haihao 2007-08-16 22:30:01 UTC
mesa commit dcfdb63b9fde8134562cb3a4e779a36e0abb4ae5
Comment 13 Adam Jackson 2009-08-24 12:25:40 UTC
Mass version move, cvs -> git


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.