Bug 21354

Summary: Better optimize loading constants in VertexShaders
Product: Mesa Reporter: Francois Gouget <fgouget>
Component: Drivers/DRI/i915Assignee: Default DRI bug account <dri-devel>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: medium    
Version: unspecified   
Hardware: x86 (IA32)   
OS: Linux (All)   
URL: http://www.gamershell.com/download_16702.shtml
Whiteboard:
i915 platform: i915 features:
Attachments: patch for constant reuse

Description Francois Gouget 2009-04-23 06:56:49 UTC
So running FlatOut 2 on Linux with Wine 1.1.19 I got the following error:

fixme:d3d_shader:shader_arb_generate_vshader HW VertexShader Error at position
1543: "Too many parameter variables"

It turns out it is caused by this VertexShader fragment:

   PARAM helper_const = { 2.0, -1.0, %d.0, 0.0 };
   ...
   MOV result.fogcoord, 0.0;

From what I have been told (I'm not a 3D expert), the MOV causes the driver to use a shader constant for the 0.0, thus going over the limit. We've worked around this issue by rewriting the above as:

   MOV result.fogcoord, helper_const.w;

But it has been pointed out that the driver should be able to figure this out by itself and do the optimization itself. Hence this report.

Packages:
 * From Debian Testing
 * libgl1-mesa-dri 7.0.3-7
 * linux-image-2.6.26-2-686 2.6.26-15
 * xserver-xorg-video-intel 2:2.3.2-2+lenny6. 

See also:
 * WineHQ Bug 17528 - 3D Mark 2001 SE Dragothic: Textures not rendered on running humans
   http://bugs.winehq.org/show_bug.cgi?id=17528

To reproduce:
 * Go to http://www.winehq.org/announce/1.1.19 and grab Wine 1.1.19 (later versions will have the workaround I mentioned above and thus not be suitable for reproducing this issue)
 * Compile / Install it.
 * Install DirectX 9 or copy d3dx9_36.dll to ~/.wine/drive_c/windows/system32.
 * Download the FlatOut 2 Demo from:
   http://www.gamershell.com/download_16702.shtml
 * Unzip that file and chdir to that directory.
 * Then run:
   wine FlatOut2.exe

The game should crash on startup and print the above HW VertexShader error on stderr.
Comment 1 Francois Gouget 2009-04-23 07:10:31 UTC
For reference, this happened with an Intel 945GME graphics card on an EeePC 1000H:

00:02.1 Display controller: Intel Corporation Mobile 945GM/GMS/GME, 943/940GML Express Integrated Graphics Controller (rev 03)
Comment 2 Brian Paul 2009-04-23 09:44:08 UTC
Created attachment 25068 [details] [review]
patch for constant reuse

Can you try the attached patch?  It tries to re-use existing constants when possible.
I've only tested this a little bit but it should work.
Comment 3 Brian Paul 2009-05-06 07:47:53 UTC
I've committed my patch (16baef336ddf6c5b9449ffa0555785b4b2b19718).  The problem should be solved.  Re-open if not.

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.