There is a fail path in r300g that has been working very well for us. If shader compilation fails, a dummy shader emitting one instruction is used (usually outputting (0,0,0,1) into the first output). This approach allows the applications with failing shaders to run with misrendering on specific objects (in case of a fragment shader failure) or with missing objects (in case of a vertex shader failure). The fact there is no crash or abort or anything preventing the apps from running makes some of them usable. It also makes debugging easier, because all failing shaders must go through the r300 compiler and we can analyze whether the compiler is doing a good job in reducing the number of instructions and temporaries, and whether we can do something about it to make it better.<br>


<br>If we are about to introduce new shader error enums, I&#39;d like to preserve the current r300g behavior for OpenGL apps, because it appears to be a win in most cases.<br><br>Marek<br><br><div class="gmail_quote">On Tue, Mar 15, 2011 at 1:31 AM, Brian Paul <span dir="ltr">&lt;<a href="mailto:brian.e.paul@gmail.com" target="_blank">brian.e.paul@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><div><div></div><div>On Mon, Mar 14, 2011 at 1:07 PM, José Fonseca &lt;<a href="mailto:jfonseca@vmware.com" target="_blank">jfonseca@vmware.com</a>&gt; wrote:<br>



&gt; On Mon, 2011-03-14 at 11:23 -0700, Brian Paul wrote:<br>
&gt;&gt; On 03/12/2011 07:44 PM, Marek Olšák wrote:<br>
&gt;&gt; &gt; The r300 compiler can eliminate unused uniforms and remap uniform locations<br>
&gt;&gt; &gt; if their number surpasses hardware limits, so the limit is actually<br>
&gt;&gt; &gt; NumParameters + NumUnusedParameters. This is important for some apps<br>
&gt;&gt; &gt; under Wine to run.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Wine sometimes declares a uniform array of 256 vec4&#39;s and some Wine-specific<br>
&gt;&gt; &gt; constants on top of that, so in total there is more uniforms than r300 can<br>
&gt;&gt; &gt; handle. This was the main motivation for implementing the elimination<br>
&gt;&gt; &gt; of unused constants.<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; We should allow drivers to implement fail&amp;  recovery paths where it makes<br>
&gt;&gt; &gt; sense, so giving up too early especially when comes to uniforms is not<br>
&gt;&gt; &gt; so good idea, though I agree there should be some hard limit for all drivers.<br>
&gt;&gt;<br>
&gt;&gt; I added the check_resources() code to fix an issue with the SVGA<br>
&gt;&gt; driver.  If we can&#39;t do resource checking against the<br>
&gt;&gt; ctx-&gt;Const.Vertex/FragmentProgram limits we need something else.<br>
&gt;&gt;<br>
&gt;&gt; In Gallium we have the PIPE_SHADER_CAP_MAX_x queries.  Are you saying<br>
&gt;&gt; we shouldn&#39;t check shaders against those limits either?<br>
&gt;&gt;<br>
&gt;&gt; If we were to push all the shader resource checking down into the<br>
&gt;&gt; Gallium drivers we&#39;ll need a new way to propagate error messages back<br>
&gt;&gt; to the user (we can only return NULL from create_X_state() now).<br>
&gt;&gt; Another other problem would be instituting consistant error reporting<br>
&gt;&gt; across all the drivers.<br>
&gt;&gt;<br>
&gt;&gt; We&#39;ve kind of tiptoed around this issue in the past.  It&#39;s probably<br>
&gt;&gt; time to come up with some real solutions.<br>
&gt;<br>
&gt; Not only some drivers are able to optimize away declared-yet-unused<br>
&gt; registers; but other drivers drivers may actually need to add extra<br>
&gt; temps/const regs to implement certain opcodes/state. Both issues make it<br>
&gt; difficult to make guarantees around PIPE_SHADER_CAP_MAX_x, as we can<br>
&gt; easily end up advertising too little or too much.<br>
&gt;<br>
&gt; It looks there&#39;s not much alternative to mimicking GLSL here, i.e.,<br>
&gt; advertise these as limits but allow concrete shaders to pass/fail to<br>
&gt; compile on a case-by-case basis.<br>
&gt;<br>
&gt; I&#39;m not sure what&#39;s the best what to convey errors from the drivers: to<br>
&gt; return pipe_error and extend it to include things like<br>
&gt;    PIPE_ERROR_TOO_MANY_CONSTS<br>
&gt;    PIPE_ERROR_TOO_MANY_TEMPS<br>
&gt;    PIPE_ERROR_TOO_MANY_INSTRUCTIONS<br>
&gt;    etc.<br>
&gt; and translate them in the state tracker; or use message strings. At a<br>
&gt; glance, it looks like an error enum would be expressive enough for most<br>
&gt; stuff.<br>
<br>
</div></div>That would probably be a good first step.  We should probably think a<br>
bit more to see if we could get by with a simple set of enumerated<br>
error codes or if we need a way to convey details.<br>
<br>
Probably the least Gallium interface change would be to add a simple<br>
pipe-&gt;get_shader_error() that would return PIPE_ERROR_x if the<br>
previous create_fs/vs/gs_state() call returned NULL.<br>
<br>
I think we can still do some resource checking at a high level in Mesa<br>
and the state tracker.  For example, the number of texture units and<br>
the number of constant buffers seem to be pretty solid limits.<br>
<font color="#888888"><br>
-Brian<br>
</font><div><div></div><div>_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br>