[1/3] i965: Sweep NIR after linking phase to free held memory

Submitted by Danylo Piliaiev on July 10, 2018, 8:51 a.m.

Details

Message ID 20180710085211.13506-2-danylo.piliaiev@globallogic.com
State New
Headers show
Series "Sweep NIR after linking phase to free held memory" ( rev: 1 ) in Mesa

Not browsing as part of any series.

Commit Message

Danylo Piliaiev July 10, 2018, 8:51 a.m.
After optimization passes and many trasfromations most of memory
NIR holds is a garbage which was being freed only after shader deletion.
Freeing it at the end of linking will save memory which would be useful
in case there are a lot of complex shaders being compiled.
The common case for this issue is 32bit game running under Wine.

The cost of the optimization is around ~3-5% of compilation speed
with complex shaders.

Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103274

Signed-off-by: Danylo Piliaiev <danylo.piliaiev@globallogic.com>
---
 src/mesa/drivers/dri/i965/brw_link.cpp | 9 +++++++++
 1 file changed, 9 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/mesa/drivers/dri/i965/brw_link.cpp b/src/mesa/drivers/dri/i965/brw_link.cpp
index 1071056f14..8f34a58ce7 100644
--- a/src/mesa/drivers/dri/i965/brw_link.cpp
+++ b/src/mesa/drivers/dri/i965/brw_link.cpp
@@ -359,6 +359,15 @@  brw_link_shader(struct gl_context *ctx, struct gl_shader_program *shProg)
       }
    }
 
+   for (stage = 0; stage < ARRAY_SIZE(shProg->_LinkedShaders); stage++) {
+      struct gl_linked_shader *shader = shProg->_LinkedShaders[stage];
+      if (!shader)
+         continue;
+
+      struct gl_program *prog = shader->Program;
+      nir_sweep(prog->nir);
+   }
+
    if (brw->ctx.Cache) {
       for (stage = 0; stage < ARRAY_SIZE(shProg->_LinkedShaders); stage++) {
          struct gl_linked_shader *shader = shProg->_LinkedShaders[stage];

Comments

I think we can just move it up a couple of loops to the place where we do
the final lowering and call gather_info.  Other than that, this seems like
a good idea to me.  NIR passes are pretty sloppy about memory and assume
nir_sweep gets called.  Hanging on to linked shaders with all that garbage
floating around is a bad plan.

On Tue, Jul 10, 2018 at 1:53 AM Danylo Piliaiev <danylo.piliaiev@gmail.com>
wrote:

> After optimization passes and many trasfromations most of memory
> NIR holds is a garbage which was being freed only after shader deletion.
> Freeing it at the end of linking will save memory which would be useful
> in case there are a lot of complex shaders being compiled.
> The common case for this issue is 32bit game running under Wine.
>
> The cost of the optimization is around ~3-5% of compilation speed
> with complex shaders.
>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103274
>
> Signed-off-by: Danylo Piliaiev <danylo.piliaiev@globallogic.com>
> ---
>  src/mesa/drivers/dri/i965/brw_link.cpp | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_link.cpp
> b/src/mesa/drivers/dri/i965/brw_link.cpp
> index 1071056f14..8f34a58ce7 100644
> --- a/src/mesa/drivers/dri/i965/brw_link.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_link.cpp
> @@ -359,6 +359,15 @@ brw_link_shader(struct gl_context *ctx, struct
> gl_shader_program *shProg)
>        }
>     }
>
> +   for (stage = 0; stage < ARRAY_SIZE(shProg->_LinkedShaders); stage++) {
> +      struct gl_linked_shader *shader = shProg->_LinkedShaders[stage];
> +      if (!shader)
> +         continue;
> +
> +      struct gl_program *prog = shader->Program;
> +      nir_sweep(prog->nir);
> +   }
> +
>     if (brw->ctx.Cache) {
>        for (stage = 0; stage < ARRAY_SIZE(shProg->_LinkedShaders);
> stage++) {
>           struct gl_linked_shader *shader = shProg->_LinkedShaders[stage];
> --
> 2.17.1
>
>
Indeed it would be better to move it, will be done.

On 10.07.18 18:04, Jason Ekstrand wrote:
> I think we can just move it up a couple of loops to the place where we 
> do the final lowering and call gather_info. Other than that, this 
> seems like a good idea to me.  NIR passes are pretty sloppy about 
> memory and assume nir_sweep gets called.  Hanging on to linked shaders 
> with all that garbage floating around is a bad plan.
>
> On Tue, Jul 10, 2018 at 1:53 AM Danylo Piliaiev 
> <danylo.piliaiev@gmail.com <mailto:danylo.piliaiev@gmail.com>> wrote:
>
>     After optimization passes and many trasfromations most of memory
>     NIR holds is a garbage which was being freed only after shader
>     deletion.
>     Freeing it at the end of linking will save memory which would be
>     useful
>     in case there are a lot of complex shaders being compiled.
>     The common case for this issue is 32bit game running under Wine.
>
>     The cost of the optimization is around ~3-5% of compilation speed
>     with complex shaders.
>
>     Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=103274
>
>     Signed-off-by: Danylo Piliaiev <danylo.piliaiev@globallogic.com
>     <mailto:danylo.piliaiev@globallogic.com>>
>     ---
>      src/mesa/drivers/dri/i965/brw_link.cpp | 9 +++++++++
>      1 file changed, 9 insertions(+)
>
>     diff --git a/src/mesa/drivers/dri/i965/brw_link.cpp
>     b/src/mesa/drivers/dri/i965/brw_link.cpp
>     index 1071056f14..8f34a58ce7 100644
>     --- a/src/mesa/drivers/dri/i965/brw_link.cpp
>     +++ b/src/mesa/drivers/dri/i965/brw_link.cpp
>     @@ -359,6 +359,15 @@ brw_link_shader(struct gl_context *ctx,
>     struct gl_shader_program *shProg)
>            }
>         }
>
>     +   for (stage = 0; stage < ARRAY_SIZE(shProg->_LinkedShaders);
>     stage++) {
>     +      struct gl_linked_shader *shader =
>     shProg->_LinkedShaders[stage];
>     +      if (!shader)
>     +         continue;
>     +
>     +      struct gl_program *prog = shader->Program;
>     +      nir_sweep(prog->nir);
>     +   }
>     +
>         if (brw->ctx.Cache) {
>            for (stage = 0; stage < ARRAY_SIZE(shProg->_LinkedShaders);
>     stage++) {
>               struct gl_linked_shader *shader =
>     shProg->_LinkedShaders[stage];
>     -- 
>     2.17.1
>