Mesa (master): i965/fs: Only emit FS_OPCODE_PLACEHOLDER_HALT if there are discards

Ben Widawsky bwidawsk at kemper.freedesktop.org
Tue Apr 14 22:23:01 UTC 2015


Module: Mesa
Branch: master
Commit: 6866378cf42c86d03f38616804e6714a932ab70b
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=6866378cf42c86d03f38616804e6714a932ab70b

Author: Ben Widawsky <benjamin.widawsky at intel.com>
Date:   Fri Apr 10 10:04:55 2015 -0700

i965/fs: Only emit FS_OPCODE_PLACEHOLDER_HALT if there are discards

Based originally on a patch from Ken in May 2014 of the same title. Things
changed enough that I didn't feel comfortable leaving his authorship.

v2: Replace fp->UsesKill with wm_prog_data->uses_kill. Since Ken took the time
to also explain the difference to me, here is his explanation for posterity:

"fp->UsesKill indicates that a ARB_fragment_program shader uses the KIL
instruction, or that a GLSL shader uses the "discard" insntruction
(which are analogous).

On Gen4-5, we sometimes have to simulate OpenGL's "Alpha Test" feature
by emitting shader code that implicitly does a "discard" instruction.

In the key setup, we do:

   /* key->alpha_test_func means simulating alpha testing via discards,
    * so the shader definitely kills pixels.
    */
   prog_data.uses_kill = fp->program.UsesKill || key->alpha_test_func;

Even though the shader may not technically contain a "discard", we need
to act as if it does.

I've also been trying to move the i965 state setup code to use
brw_wm_prog_key for everything, rather than poking at core Mesa's
gl_program/gl_fragment_program/gl_shader/gl_shader_program structures.

--Ken"

Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
Reviewed-by: Matt Turner <mattst88 at gmail.com>
Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/mesa/drivers/dri/i965/brw_fs.cpp |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/src/mesa/drivers/dri/i965/brw_fs.cpp b/src/mesa/drivers/dri/i965/brw_fs.cpp
index aea1ebb..f04fb59 100644
--- a/src/mesa/drivers/dri/i965/brw_fs.cpp
+++ b/src/mesa/drivers/dri/i965/brw_fs.cpp
@@ -1699,6 +1699,8 @@ fs_visitor::emit_math(enum opcode opcode, fs_reg dst, fs_reg src0, fs_reg src1)
 void
 fs_visitor::emit_discard_jump()
 {
+   assert(((brw_wm_prog_data*) this->prog_data)->uses_kill);
+
    /* For performance, after a discard, jump to the end of the
     * shader if all relevant channels have been discarded.
     */
@@ -3958,7 +3960,8 @@ fs_visitor::run_fs()
       if (failed)
 	 return false;
 
-      emit(FS_OPCODE_PLACEHOLDER_HALT);
+      if (wm_prog_data->uses_kill)
+         emit(FS_OPCODE_PLACEHOLDER_HALT);
 
       if (wm_key->alpha_test_func)
          emit_alpha_test();




More information about the mesa-commit mailing list