[Mesa-dev] [PATCH] mesa: Free the compiled shader IR after it has been linked.

Eric Anholt eric at anholt.net
Sat May 31 14:39:42 PDT 2014


Ian Romanick <idr at freedesktop.org> writes:

> On 05/28/2014 01:57 PM, Eric Anholt wrote:
>> If the shader compiled once, then we can compile it again.  Compiled
>> shaders almost always get used in just one program, so holding that
>> compiled IR until the program is freed is just a waste of memory.
>
> Would this work with some madness like:
>
>    glAttachShader(prog, sh1);
>    glAttachShader(prog, sh2);
>    glLinkProgram(prog);
>
>    GLchar *empty = "";
>    glShaderSource(sh1, 1, &empty, NULL);

When we get the shadersource call here on a previously linked-and-freed
shader, the lazy recompile call present in shadersource ensures that we
have the right IR.

>    glBindAttribLocation(prog, 0, "foo");
>    glLinkProgram(prog);

> There are some things like this that I think would work very nicely with
> glCreateShaderProgramv, but it may be difficult to get all the corner
> cases right otherwise.
>
>> On the other hand, if they are either reusing shader objects to compile
>> multiple times, or linking the same shader into multiple programs, we turn
>> off this memory savings hack to avoid spending CPU on recompiling.
>> 
>> Reduces peak memory allocation of glretrace of a trace of dolphin-emu by
>> 5.5MB.  It seems like this should be a big deal to DOTA2, but it was
>> triggering RecompiledAnyShader, and I failed to see a benefit even if I
>> removed the RecompiledAnyShader check (which confuses me).
>
> I think they use the same vertex shader with multiple fragment
> shaders... but it does seem weird that disabling the check didn't change
> the memory usage.  Did it change anything (bad rendering)?

Not that I noticed, not that I was paying close attention when it took
so long to run.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 818 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20140531/2d517046/attachment.sig>


More information about the mesa-dev mailing list