Bug 18477

Summary: game nexuiz crashes with assertion "oldSampNum < 8" in slang_link.c
Product: Mesa Reporter: lin, jiewen <jiewen.lin>
Component: Mesa coreAssignee: Ian Romanick <idr>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: medium CC: brian.paul, sa
Version: unspecified   
Hardware: x86 (IA32)   
OS: Linux (All)   
Whiteboard:
i915 platform: i915 features:
Attachments: log
conf
Patch to progs/glsl/multitex.frag to reproduce bug
Patch to fix assertion in slang linker

Description lin, jiewen 2008-11-10 22:43:30 UTC
Created attachment 20206 [details]
log

System Environment:
--------------------------

--Platform: gm45 965
--Architecture(32-bit,64-bit,compatiblity): 32-bit
--2D driver: (master)a5b1e62337d4e8840347bb186db48697f0690a19
--3D driver: (master)f1c9016af16aefc08a3e4e859a897009652dac23
--DRM:shipped with kernel 2.6.28-rc3(drm-intel-next)
--libdrm: (master)930c0e7cf4f4776f7a69e7acc6fedeed7addb235
--Xserver: (master)24383056d0513cc588cee5cee78f1cba2c0fbe89
--Kernel: 2.6.28-rc3(drm-intel-next)

Bug detailed description:
--------------------------
Start X,then run nexuiz,When attempting to load a level to play, Nexuiz crashes with the following console message:
nexuiz-glx: shader/slang/slang_link.c:203: link_uniform_vars: Assertion `oldSampNum < 8' failed.
Received signal 6, exiting...
Client "Player" dropped
OpenGL Backend shutting down
Reproduce steps:
----------------
1. startx&
2. ./nexuiz-glx
Comment 1 lin, jiewen 2008-11-10 22:44:35 UTC
Created attachment 20207 [details]
conf
Comment 2 lin, jiewen 2008-11-10 22:48:03 UTC
The same issue reported on the other website:https://bugs.launchpad.net/ubuntu/+source/nexuiz/+bug/272657 Nexuiz crashes on Intel x4500 video chip.
Comment 3 Ian Romanick 2008-12-08 18:28:22 UTC
The problem seems to be that the shader contains 17 samplers, but the driver only supports 8.  It looks like the shader uses a lot of conditionally compiled code, so it probably only uses 8.  I'm not sure if this is valid GLSL.

I constructed a similar test (added 34 extra, unused sampler declarations).  The test works on Nvidia but fails on Mesa.  It even fails on the software rasterizer.
Comment 4 Ian Romanick 2008-12-08 18:29:06 UTC
Created attachment 20930 [details] [review]
Patch to progs/glsl/multitex.frag to reproduce bug
Comment 5 Brian Paul 2008-12-09 07:57:27 UTC
Created attachment 20956 [details] [review]
Patch to fix assertion in slang linker

Please try the attached patch.  It replaces the assertion with a link-time error.
Comment 6 Ian Romanick 2008-12-09 10:59:42 UTC
(In reply to comment #5)
> Created an attachment (id=20956) [details]
> Patch to fix assertion in slang linker
> 
> Please try the attached patch.  It replaces the assertion with a link-time
> error.

I spent some time looking at the GLSL spec last night.  I think Mesa is just plain wrong here.  I see no reason that a shader cannot have as many sampler uniforms as it wants.  It can even use all of them.  The only restriction is on the texture units that can be assigned to those uniforms.

What's not clear to me (yet) is what is supposed to happen if a sampler uniform is set to an invalid value.  What is the "correct" behavior if, for example, the multitex test is changed to set tex1 to 99?  On Nvidia's driver it behaves as if it is sampling from a disabled texture unit (i.e., returns {0, 0, 0, 1}).  On Mesa with 965 it explodes (crashes the GPU).

I'm inclined to punt on really fixing this in the current compiler.  For now, I would suggest:

1. Apply a patch #20956 or something similar.

2. Increase MAX_SAMPLERS to 32.  This will allow Nexuiz to work.  We want to support 16 image units on 965 anyway (see bug #16655).

3. Fix the 965 driver to not crash if a sampler uniform is set to an invalid value.  I'll put together a test case and submit a separate bug.
Comment 7 lin, jiewen 2009-01-16 00:24:15 UTC
This issue still eixsts with current build.
Comment 8 Brian Paul 2009-01-16 07:09:30 UTC
Nexuiz seems to work fine for me on i965 with Mesa git/master.

If you're still seeing:

nexuiz-glx: shader/slang/slang_link.c:203: link_uniform_vars: Assertion
`oldSampNum < 8' failed.

then you may not be using the latest code.  Could you please double-check?

Comment 9 Sven Arvidsson 2009-01-16 07:36:42 UTC
It works for me on G45 using mesa 4497a5a57d0fdb5c5ec15750e477aeb49f5e453d.
Comment 10 Gordon Jin 2009-01-18 01:39:03 UTC
Jiewen, I guess you were trying with intel-2008-q4 branch. Please try master.
Comment 11 lin, jiewen 2009-01-18 17:45:28 UTC
Yes, it is fine with master branch.
Comment 12 Gordon Jin 2009-01-18 22:10:13 UTC
Then this can be considered as fixed.

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.