<div dir="ltr">On 6 November 2013 09:35, Erik Faye-Lund <span dir="ltr"><<a href="mailto:kusmabite@gmail.com" target="_blank">kusmabite@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Sorry for the late reply.<br>
<div><div><br>
On Fri, Nov 1, 2013 at 4:14 PM, Tapani <<a href="mailto:tapani.palli@intel.com" target="_blank">tapani.palli@intel.com</a>> wrote:<br>
> On 11/01/2013 03:31 PM, Erik Faye-Lund wrote:<br>
>><br>
>><br>
>> Won't using the git-sha1 as a compatibility-criteria cause issues for<br>
>> developers with local changes? I'm not so worried about this for<br>
>> OES_get_program_binary itself, but once the shader-cache is in place<br>
>> it sounds like a potential source of difficult to track down<br>
>> misbehavior...<br>
>>>>><br>
>>>>><br>
>>>>> I agree it might be too aggressive criteria but it is hard to come up<br>
>>>>> with<br>
>>>>> better and as simple.<br>
>>>><br>
>>>> That's not my objection. My objection is that this might give<br>
>>>> headaches for people with local modifications to the glsl-compiler.<br>
>>>> Local modifications does not affect the git-sha1.<br>
>>><br>
>>><br>
>>> For the automatic shader cache this headache could be helped a bit with a<br>
>>> environment variable or drirc setting that can be used during<br>
>>> development.<br>
>>> On the other hand an automatic cache must work in a transparent way so it<br>
>>> should be always able to recover when it fails, so one should only see it<br>
>>> as<br>
>>> 'slower than usual' (since recompilation/relink required) sort of<br>
>>> behaviour.<br>
>>> The WIP of the automatic cache I sent some time earlier also marked<br>
>>> (renamed) these 'problematic' cached shaders so that they can be detected<br>
>>> on<br>
>>> further runs and cache can ignore those.<br>
>>><br>
>>> I agree that it might become problematic, on the other hand it is also<br>
>>> easy<br>
>>> to just wipe ~/.cache/mesa and disable cache.<br>
>><br>
>> That won't help for programs that maintain their own (explicit)<br>
>> shader-cache, which was the intention of introducing binary shaders to<br>
>> OpenGL ES in the first place.<br>
><br>
><br>
> Ok, we are talking about the extension, I thought you referred to the<br>
> automatic caching. For extension to work, we need at least more Piglit tests<br>
> to ensure that it does not break.<br>
<br>
</div></div>I was actually of talking about both. But for the caching, it's<br>
probably more forgivable, as developers probably know they changed the<br>
compiler and can step around it by flushing the cache. Especially if<br>
the build time gets included, like Pauls suggested.<br>
<div><br>
> Of course every time you go and touch the<br>
> code, some functionality may break, be it this extension or something else.<br>
<br>
</div>That's completely irrelevant here. The rejection mechanism isn't<br>
intended to catch bugs, but to detect intentional format changes. So<br>
let's not confuse the issue.<br>
<div><br>
> I'm not sure if Chromium, Qt or other users expect glBinaryProgram call to<br>
> always succeed, hopefully not.<br>
<br>
</div>If they do, they're buggy. But there is a chance for that, yes. But<br>
I'm actually talking about that they might get *told* that everything<br>
went well, and still get a broken shader. Or even a crash. Of course,<br>
this only applies when mesa is build with local modifications, but<br>
that happens a *lot* while debugging application issues. Perhaps bugs<br>
start to disappear, because applications take another non-buggy<br>
code-path? It'll probably only affect developers, and not happen in<br>
the wild. But I still don't think that's a good excuse.<br>
<br>
However, by a strict reading of the spec, I don't even yhink we're<br>
allowed to break the shaders for just any reason. The wording of the<br>
spec is "An implementation may reject a program binary if it<br>
<div>determines the program binary was produced by an incompatible or<br>
</div>outdated version of the compiler". The way I read that, changes that<br>
doesn't modify the compiler aren't really allowed to reject previous<br>
shaders. While diverging from the spec on this *might* not have many<br>
real-world implications, at the very best your solution goes against<br>
the intention of this rejection-mechanism.<br></blockquote><div><br></div><div>We have to regard any bug fix, feature improvement, or performance optimization that's applied to the parser, ast, optimization passes, or lowering passes as constituting a change to the compiler. Otherwise when the user upgrades Mesa, any apps that use get_program_binary will fail to get the advantage of the upgraded code. As a practical matter, nearly every sMesa release makes changes to one of those components, even point releases. So allowing old program binaries in the event that the compiler hasn't changed really wouldn't produce any end user benefit. And it would risk big developer headaches if we ever make a change that affects compilation without realizing it. IMHO the risks outweigh the benefits.<br>
<br></div><div>And as far as whether we're strictly conforming to the spec, the spec is vague here since it doesn't define what constitutes the "version of the compiler" vs the "version of the driver". I think it's an entirely defensible interpretation to consider the compiler version and the driver version to be the same thing; so whenever the driver is upgraded, the client application needs to be prepared for the possibility that the shader binary might be rejected.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<div><br>
>>> Not sure if Nvidia or<br>
>>> Imagination try to handles these cases with their cache implementations.<br>
>><br>
>> I would assume they simply piggie-backed on their binary-shader<br>
>> support. But I somehow doubt they have such a "lazy" approach to<br>
>> binary shaders as this series attempts. I worked on<br>
>> ARM_mali_shader_binary for the Mali-200 drivers myself, and our<br>
>> approach was quite different from this, and surely much more robust.<br>
><br>
><br>
> With such strong opinion It would be nice to have some more technical<br>
> explanation. Why it was "surely more robust"?<br>
<br>
</div>Easy; it didn't break compatibility for every change to the driver. It<br>
didn't even break when we updated the compiler. As a matter of fact,<br>
I'm not even aware of *any* compatibility breakages (apart from if you<br>
change the hardware, of course), ever.<br>
<div><br>
> The implementation itself can<br>
> be likely very different as it targets only a particular GPU while the<br>
> approach here is meant to be more generic.<br>
<br>
</div>Our implementation did also support multiple GPUs, however I was only<br>
involved in the initial Mali-200 work. But the Mali-200 does not have<br>
a unified ISA, so we had to touch on this area anyway.<br>
<div><br>
>> To be honest, I find the whole idea of serializing the IR quite<br>
>> repelling, as it goes against almost every intention of the extension.<br>
>> Add to that mesa's IR not at all being stable, well.... yeah, that's a<br>
>> super-highway to disaster.<br>
><br>
><br>
> Again, I would appreciate a bit more technical approach if possible. I can't<br>
> tell from this paragraph if you have a better idea for the architecture or<br>
> not.<br>
<br>
</div>So, what we did was to create a container-format for the shaders and<br>
programs, including all the information needed to use these. We stored<br>
binary machine-code, symbol-tables, plus information needed to do<br>
binary-patching (IIRC this was only needed for the linking of binary<br>
shaders, not for already-linked binary programs. I think we still kept<br>
it, though, but mostly as an implementation-detail). The container<br>
format was common for all cores, and so was the symbol-table. In<br>
addition, each core had some dedicated code to read and write a blob<br>
of their own, containing whatever information they needed to do their<br>
job.<br>
<br>
This is pretty much the same thing as NVIDIA did for their Tegra-driver.<br>
<br>
Storing halfway compiled code rather than fully compiled code seems<br>
quite sketchy to me, as it introduces the need for compatibility at a<br>
point where flexibility is needed. The result is a program-binary that<br>
1) must still perform register allocation and scheduling when loading,<br>
so the time-saving is limited, and 2) fails to reload even for trivial<br>
bugfixes in unrelated code. To me, it sounds like it would be better<br>
to simply not have the extension exposed than this middle-ground. I'd<br>
hate to see applications having to do vendor detection for mesa to<br>
disable caching that turned out to be more of a burden than a gain.<br></blockquote><div><br></div><div>A key piece of discussion that I feel like we're missing is the fact that on i965 at least, the shader sometimes needs to be recompiled as a result of changes to GL state. The get_program_binary spec requires these state-based recompiles to work properly, even if the GL state machine is placed in a state that hadn't been seen at the time the program binary was saved. Therefore, the program binary format needs to include the IR, since that's what we use as a starting point when we do state-based recompiles. Given that the IR format is defined in core mesa, it makes sense that the serialization code for it should go in core mesa as well.<br>
<br></div><div>I agree with you that in order to implement the full intent of the extension, this mechanism needs to also store the fully-compiled machine code for the shader. I brought this up in my comments on patch 5/6, and it sounds like Tapani is on board with doing that, but he has some more research to do before he can implement that part of the feature.<br>
<br>If in the future we have a back end that doesn't need to do state-based
recompiles (or that can do state-based recompiles without needing access
to the IR), then we can always add a mechanism that allows the back end
to opt out of storing the IR in the shader binary. But since Tapani is
targeting i965, which needs the IR, I think it's reasonable to get that part of things working first.<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
I'd like to add that this last piece of criticism is only about the<br>
extension, and not of a shader cache. A shader-cache probably isn't<br>
really exposed to developers with some expectation of what it will do.<br>
<br>
An approach that seems much more sane to me would be to simply have<br>
the different drivers deal entirely with the binary programs, and have<br>
them default to not supporting any at all. Perhaps the drivers can<br>
share some helper-code to serialize symbol tables and whatnot. Or even<br>
have a common format for all high-level stuff, and let the drivers<br>
serialize a blob of their own for each shader. It's more work, but IMO<br>
the extension would become much more useful.<br>
<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></div></div>