i965: Avoid unnecessary recompiles for shaders that don't use dFdy().
authorPaul Berry <stereotype441@gmail.com>
Wed, 20 Jun 2012 20:40:45 +0000 (13:40 -0700)
committerPaul Berry <stereotype441@gmail.com>
Thu, 19 Jul 2012 17:02:25 +0000 (10:02 -0700)
The i965 back-end needs to compile dFdy() differently for FBOs and
window system framebuffers, because Y coordinates are flipped between
the two (see commit 82d2596: i965: Compute dFdy() correctly for FBOs).
This patch avoids unnecessarily recompiling shaders that don't use
dFdy(), by only setting render_to_fbo in the wm program key if the
shader actually uses dFdy().

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/drivers/dri/i965/brw_fs.cpp
src/mesa/drivers/dri/i965/brw_fs_emit.cpp
src/mesa/drivers/dri/i965/brw_wm.c
src/mesa/drivers/dri/i965/brw_wm_emit.c

index 630150dbffdb7e0156791111552f88f874877e73..85345efc0a4b5e70d1fd1ce992c2a197d3795301 100644 (file)
@@ -2119,19 +2119,13 @@ brw_fs_precompile(struct gl_context *ctx, struct gl_shader_program *prog)
    struct brw_context *brw = brw_context(ctx);
    struct brw_wm_prog_key key;
 
-   /* As a temporary measure we assume that all programs use dFdy() (and hence
-    * need to be compiled differently depending on whether we're rendering to
-    * an FBO).  FIXME: set this bool correctly based on the contents of the
-    * program.
-    */
-   bool program_uses_dfdy = true;
-
    if (!prog->_LinkedShaders[MESA_SHADER_FRAGMENT])
       return true;
 
    struct gl_fragment_program *fp = (struct gl_fragment_program *)
       prog->_LinkedShaders[MESA_SHADER_FRAGMENT]->Program;
    struct brw_fragment_program *bfp = brw_fragment_program(fp);
+   bool program_uses_dfdy = fp->UsesDFdy;
 
    memset(&key, 0, sizeof(key));
 
index bfa62c31781dc73e05787bf1bb1ad6e23a347e77..dc5f3e16134c036e8a9ee7bbaab78bc586220f2d 100644 (file)
@@ -931,6 +931,10 @@ fs_visitor::generate_code()
         generate_ddx(inst, dst, src[0]);
         break;
       case FS_OPCODE_DDY:
+         /* Make sure fp->UsesDFdy flag got set (otherwise there's no
+          * guarantee that c->key.render_to_fbo is set).
+          */
+         assert(fp->UsesDFdy);
         generate_ddy(inst, dst, src[0], c->key.render_to_fbo);
         break;
 
index 587cc35c4b8f943d96420b6a6800bb71d228a1af..37bc1148ae691dd8716b6f5c3427019894f4aaa1 100644 (file)
@@ -441,13 +441,7 @@ static void brw_wm_populate_key( struct brw_context *brw,
    const struct gl_program *prog = (struct gl_program *) brw->fragment_program;
    GLuint lookup = 0;
    GLuint line_aa;
-
-   /* As a temporary measure we assume that all programs use dFdy() (and hence
-    * need to be compiled differently depending on whether we're rendering to
-    * an FBO).  FIXME: set this bool correctly based on the contents of the
-    * program.
-    */
-   bool program_uses_dfdy = true;
+   bool program_uses_dfdy = fp->program.UsesDFdy;
 
    memset(key, 0, sizeof(*key));
 
index 1258efe08bb764485541ccfdc9f4f2cc8719c2d0..61f66e7ccddb6a8bd2c3c585887b040147483da2 100644 (file)
@@ -1757,6 +1757,10 @@ void brw_wm_emit( struct brw_wm_compile *c )
         break;
 
       case OPCODE_DDY:
+         /* Make sure fp->program.UsesDFdy flag got set (otherwise there's no
+          * guarantee that c->key.render_to_fbo is set).
+          */
+         assert(c->fp->program.UsesDFdy);
         emit_ddxy(p, dst, dst_flags, false, args[0], c->key.render_to_fbo);
         break;