<p dir="ltr"><br>
On May 5, 2015 10:17 PM, "Tapani Pälli" <<a href="mailto:tapani.palli@intel.com">tapani.palli@intel.com</a>> wrote:<br>
><br>
><br>
> On 05/06/2015 04:57 AM, Kenneth Graunke wrote:<br>
>><br>
>> Vertex shader attribute and fragment shader output queries rely on being<br>
>> able to inspect top-level ir_variable objects. So, we have to keep<br>
>> those. However, functions and global temporary variables can be deleted<br>
>> with impunity.<br>
>><br>
>> Saves 58MB of memory when replaying a Dota 2 trace on Broadwell.<br>
>><br>
>> Signed-off-by: Kenneth Graunke <<a href="mailto:kenneth@whitecape.org">kenneth@whitecape.org</a>><br>
>> ---<br>
>> src/mesa/drivers/dri/i965/brw_shader.cpp | 43 +++++++++++++++++++++++++++++++-<br>
>> 1 file changed, 42 insertions(+), 1 deletion(-)<br>
>><br>
>> diff --git a/src/mesa/drivers/dri/i965/brw_shader.cpp b/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
>> index c1fd859..6e4abb2 100644<br>
>> --- a/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
>> +++ b/src/mesa/drivers/dri/i965/brw_shader.cpp<br>
>> @@ -138,6 +138,45 @@ brw_lower_packing_builtins(struct brw_context *brw,<br>
>> lower_packing_builtins(ir, ops);<br>
>> }<br>
>><br>
>> +static bool<br>
>> +is_vert_input_or_frag_output(gl_shader_stage stage, ir_variable *var)<br>
><br>
><br>
> I believe you'll need to save any input and output independent of shader stage as with GL_ARB_program_interface_query application can query if some input or output is referenced by a given stage. Did you encounter any failures on Piglit tests?<br>
><br>
> I've been working to get rid of ir_variable on the background but it has taken a bit of time as there seems to be always something else to be worked first 'priority wise' ... but I think this is a nice start anyways to get rid of most IR in memory.</p>
<p dir="ltr">Do you have a branch somewhere with that work in it? I would be interested in taking a look at it. I probably won't really work on it but i would, at the very least, like to see where all the ir_variable's end up getting tied in.<br>
--Jason</p>
<p dir="ltr">>> +{<br>
>> + if (var) {<br>
>> + if (stage == MESA_SHADER_VERTEX) {<br>
>> + return var->data.mode == ir_var_shader_in ||<br>
>> + var->data.mode == ir_var_system_value;<br>
>> + }<br>
>> +<br>
>> + if (stage == MESA_SHADER_FRAGMENT) {<br>
>> + return var->data.mode == ir_var_shader_out;<br>
>> + }<br>
>> + }<br>
>> + return false;<br>
>> +}<br>
>> +<br>
>> +/**<br>
>> + * Delete GLSL IR except for VS inputs and FS outputs.<br>
>> + *<br>
>> + * Once we've translated to NIR, we don't need most of the linked GLSL IR anymore.<br>
>> + * However, GL API calls for introspecting certain shader inputs/outputs<br>
>> + * (shader_query.cpp) require us to keep some top-level ir_variables.<br>
>> + */<br>
>> +static void<br>
>> +delete_most_glsl_ir(struct gl_shader *shader)<br>
>> +{<br>
>> + void *mem_ctx = ralloc_context(NULL);<br>
>> + ralloc_adopt(mem_ctx, shader->ir);<br>
>> +<br>
>> + foreach_in_list_safe(ir_instruction, ir, shader->ir) {<br>
>> + if (!is_vert_input_or_frag_output(shader->Stage, ir->as_variable()))<br>
>> + ir->remove();<br>
>> + }<br>
>> +<br>
>> + reparent_ir(shader->ir, shader->ir);<br>
>> + ralloc_free(mem_ctx);<br>
>> +}<br>
>> +<br>
>> +<br>
>> static void<br>
>> process_glsl_ir(struct brw_context *brw,<br>
>> struct gl_shader_program *shader_prog,<br>
>> @@ -297,8 +336,10 @@ brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)<br>
>><br>
>> brw_add_texrect_params(prog);<br>
>><br>
>> - if (options->NirOptions)<br>
>> + if (options->NirOptions) {<br>
>> prog->nir = brw_create_nir(brw, shProg, prog, (gl_shader_stage) stage);<br>
>> + delete_most_glsl_ir(shader);<br>
>> + }<br>
>><br>
>> _mesa_reference_program(ctx, &prog, NULL);<br>
>> }<br>
>><br>
> _______________________________________________<br>
> mesa-dev mailing list<br>
> <a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</p>