Bug 7266

Summary: Segfault in update_input_ptrs (tnl/t_vertex.c:387) with GLSL code enabled.
Product: Mesa Reporter: Oliver McFadden <z3ro.geek>
Component: Mesa coreAssignee: mesa-dev
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: high    
Version: git   
Hardware: x86 (IA32)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: Diff to Mesa CVS
GDB backtrace

Description Oliver McFadden 2006-06-18 07:23:16 UTC
I've enabled the GLSL code in the r300 driver, which seems to mostly work except
for a segfault in grammar.c and update_input_ptrs (tnl/t_vertex.c:387)

I fixed the grammar.c segfault, though I'm not sure my solution is the best or
correct one... I'm not sure what's causing the segfault in update_input_ptrs,
though.

Here is the GDB backtrace, and the diff against Mesa CVS (minus the changes I
made in glslnoise.c, which are just printf's before each gl call.)

If anyone knows a better way to enable the GLSL code, or has actually managed to
get it working (with or without acceleration), I'd like to look at a diff or any
information about this.


z3ro@opteron ~/Mesa/progs/demos $ R300_SPAN_DISABLE_LOCKING=1 gdb ./glslnoise
GNU gdb 6.4
Copyright 2005 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "x86_64-pc-linux-gnu"...Using host libthread_db
library "/lib/libthread_db.so.1".

(gdb) run
Starting program: /home/z3ro/Mesa/progs/demos/glslnoise 
[Thread debugging using libthread_db enabled]
[New Thread 47636194510064 (LWP 6121)]
glCreateShaderObjectARB
glShaderSourceARB
glCompileShaderARB
glCreateProgramObjectARB
glAttachObjectARB
glLinkProgramARB
glUseProgramObjectARB
glGetUniformLocationARB
glUniform1fARB
glShaderSourceARB
glCompileShaderARB
glShaderSourceARB
glCompileShaderARB
glAttachObjectARB
glAttachObjectARB
glLinkProgramARB
glUseProgramObjectARB
glClearColor
glEnable
glEnable
GL_RENDERER = Mesa DRI R300 20040924 AGP 1x TCL
glViewport
glMatrixMode
glLoadIdentity
glFrustum
glMatrixMode
glLoadIdentity
glTranslatef
glClear
glUniform1fARB
glPushMatrix

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 47636194510064 (LWP 6121)]
0x00002b532a82a620 in update_input_ptrs (ctx=0x0, start=0) at tnl/t_vertex.c:387
387           a[j].inputptr = ((GLubyte *)vptr->data) + start * vptr->stride;
(gdb) bt
#0  0x00002b532a82a620 in update_input_ptrs (ctx=0x0, start=0) at
tnl/t_vertex.c:387 #1  0x00002b532a82a6de in _tnl_build_vertices (ctx=0x51dd50,
start=0, end=341, newinputs=0) at tnl/t_vertex.c:409 #2  0x00002b532a81c73c in
run_render (ctx=0x51dd50, stage=0x0) at tnl/t_vb_render.c:290 #3 
0x00002b532a80ca64 in _tnl_run_pipeline (ctx=0x51dd50) at tnl/t_pipeline.c:159 #4
 0x00002b532a834863 in _tnl_flush_vtx (ctx=0x51dd50) at tnl/t_vtx_exec.c:281 #5 
0x00002b532a82d712 in _tnl_wrap_buffers (ctx=0x51dd50) at tnl/t_vtx_api.c:85 #6 
0x00002b532a82d7c6 in _tnl_wrap_filled_vertex (ctx=0x0) at tnl/t_vtx_api.c:122 #7
 0x00002b532a83046a in attrib_0_3 (v=0x7fff81e5fda0) at tnl/t_vtx_generic.c:100
#8  0x00002b532a8327aa in _tnl_Vertex3f (x=0, y=1, z=0) at
tnl/t_vtx_generic.c:235 #9  0x00002b53290766f8 in glVertex3f (x=0.190983027,
y=0.587785363, z=-1.90211296) at glapitemp.h:755 #10 0x00002b5328edd671 in
gluSphere (qobj=0xbea5f0, radius=2, slices=20, stacks=-1076945986) at
libutil/quad.c:992 #11 0x00002b5328d8923a in glutSolidSphere (radius=2,
slices=20, stacks=10) at glut_shapes.c:89 #12 0x0000000000401442 in Redisplay ()
at glslnoise.c:55 #13 0x00002b5328d82a33 in processWindowWorkList
(window=0x509640) at glut_event.c:1302 #14 0x00002b5328d82ad1 in
__glutProcessWindowWorkLists () at glut_event.c:1349 #15 0x00002b5328d82b2f in
glutMainLoop () at glut_event.c:1370 #16 0x0000000000401972 in main (argc=1,
argv=0x7fff81e62e18) at glslnoise.c:214 (gdb) 


Index: src/mesa/drivers/dri/r300/r300_context.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r300/r300_context.c,v
retrieving revision 1.54
diff -u -r1.54 r300_context.c
--- src/mesa/drivers/dri/r300/r300_context.c	11 Jun 2006 09:12:27 -0000	1.54
+++ src/mesa/drivers/dri/r300/r300_context.c	18 Jun 2006 11:26:06 -0000
@@ -83,9 +83,20 @@
 #define need_GL_EXT_blend_equation_separate
 #define need_GL_EXT_blend_func_separate
 #define need_GL_NV_vertex_program
+
+#define need_GL_ARB_shader_objects
+#define need_GL_ARB_shading_language_100
+#define need_GL_ARB_vertex_shader
+#define need_GL_ARB_fragment_shader
+
 #include "extension_helper.h"
 
 const struct dri_extension card_extensions[] = {
+  {"GL_ARB_shader_objects", GL_ARB_shader_objects_functions},
+  {"GL_ARB_shading_language_100", NULL},
+  {"GL_ARB_vertex_shader", GL_ARB_vertex_shader_functions},
+  {"GL_ARB_fragment_shader", GL_ARB_vertex_shader_functions},
+
   {"GL_ARB_multisample",		GL_ARB_multisample_functions},
   {"GL_ARB_multitexture",		NULL},
   {"GL_ARB_texture_border_clamp",	NULL},
Index: src/mesa/drivers/dri/r300/r300_render.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/drivers/dri/r300/r300_render.c,v
retrieving revision 1.106
diff -u -r1.106 r300_render.c
--- src/mesa/drivers/dri/r300/r300_render.c	23 Apr 2006 08:04:50 -0000	1.106
+++ src/mesa/drivers/dri/r300/r300_render.c	18 Jun 2006 11:26:22 -0000
@@ -462,6 +462,11 @@
 {
 	int i;
 
+	if (ctx->ShaderObjects._FragmentShaderPresent)
+		return R300_FALLBACK_RAST;
+	if (ctx->ShaderObjects._VertexShaderPresent)
+		return R300_FALLBACK_TCL;
+
 	FALLBACK_IF(ctx->RenderMode != GL_RENDER);  // We do not do SELECT or FEEDBACK
(yet ?)  	
 #if 0 /* These should work now.. */
Index: src/mesa/shader/grammar/grammar.c
===================================================================
RCS file: /cvs/mesa/Mesa/src/mesa/shader/grammar/grammar.c,v
retrieving revision 1.3
diff -u -r1.3 grammar.c
--- src/mesa/shader/grammar/grammar.c	28 Jul 2005 00:11:11 -0000	1.3
+++ src/mesa/shader/grammar/grammar.c	18 Jun 2006 11:37:52 -0000
@@ -2410,7 +2410,7 @@
                     }
                     else if (result == mr_matched)
                     {
-                        if (barray_push (ba, sp->m_emits, text[ind - 1],
save_ind, &ctx) || +                        if (barray_push (ba, sp->m_emits,
text[ind > 0 ? ind - 1 : ind], save_ind, &ctx) ||                             
barray_append (ba, &array))                          {
                             free_regbyte_ctx_stack (ctx, *rbc);
@@ -2469,7 +2469,7 @@
         if (status == mr_matched)
         {
             if (sp->m_emits)
-                if (barray_push (ba, sp->m_emits, text[ind - 1], save_ind,
&ctx)) +                if (barray_push (ba, sp->m_emits, text[ind > 0 ? ind - 1
: ind], save_ind, &ctx))                  {
                     free_regbyte_ctx_stack (ctx, *rbc);
                     barray_destroy (&array);
@@ -2629,7 +2629,7 @@
                         {
                             if (sp->m_emits != NULL)
                             {
-                                if (emit_push (sp->m_emits, _BP->_F + _P,
text[ind - 1], save_ind, &ctx)) +                                if (emit_push
(sp->m_emits, _BP->_F + _P, text[ind > 0 ? ind - 1 : ind], save_ind, &ctx))      
                           {                                     
free_regbyte_ctx_stack (ctx, *rbc);                                      return
mr_internal_error; @@ -2686,7 +2686,7 @@
         if (status == mr_matched)
         {
             if (sp->m_emits != NULL)
-                if (emit_push (sp->m_emits, _BP->_F + _P, text[ind - 1],
save_ind, &ctx)) +                if (emit_push (sp->m_emits, _BP->_F + _P,
text[ind > 0 ? ind - 1 : ind], save_ind, &ctx))                  {
                     free_regbyte_ctx_stack (ctx, *rbc);
                     return mr_internal_error;
Comment 1 Oliver McFadden 2006-06-18 07:28:12 UTC
Created attachment 5963 [details] [review]
Diff to Mesa CVS

The formatting of the diff was destroyed when included in the bug report, so
I've attached the same diff here.
Comment 2 Oliver McFadden 2006-06-18 07:30:24 UTC
Created attachment 5964 [details]
GDB backtrace

The formatting of the GDB backtrace was destroyed when included in the bug
report, so I've attached the same GDB backtrace here.
Comment 3 mjkrol 2006-06-18 08:28:21 UTC
Just shooting in the dark: replace the following line
{"GL_ARB_fragment_shader", GL_ARB_vertex_shader_functions},
to:
{"GL_ARB_fragment_shader", NULL},

Try to compile against pure software mesa - linux-x86 works
fine for me.
Comment 4 Oliver McFadden 2006-06-18 11:14:23 UTC
I managed to fix the segfault with aet's help. I needed to add
_tnl_arb_vertex_shader_stage to the r300_pipeline struct in r300_context.c. This
works with DRI enabled Mesa, but if you use the GLSL extensions Mesa must
fallback to software rendering.

The arbfslight demo from Mesa now runs, although it's incredibly slow; about
0.4fps. I think that there would need to be DRI acceleration for this to
actually be usable for anything...
Comment 5 Oliver McFadden 2007-02-17 01:07:43 UTC
I'm going to close this bug now because a lot has changed with Brian's new GLSL
compiler branch, so I'm not sure this is valid anymore.

It can be reopened later once the GLSL compiler branch has been merged to
master, and if the problem still exists then.
Comment 6 Oliver McFadden 2007-02-17 01:10:16 UTC
Oops; forgot to close the bug.
Comment 7 Adam Jackson 2009-08-24 12:24:00 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.