brw_wm.c revision 3ebfd3f7743e5c05661eab977b23441e45441b39
19f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt/*
29f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Copyright (C) Intel Corp.  2006.  All Rights Reserved.
39f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
49f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt develop this 3D driver.
59f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
69f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt Permission is hereby granted, free of charge, to any person obtaining
79f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt a copy of this software and associated documentation files (the
89f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt "Software"), to deal in the Software without restriction, including
99f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt without limitation the rights to use, copy, modify, merge, publish,
109f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt distribute, sublicense, and/or sell copies of the Software, and to
119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt permit persons to whom the Software is furnished to do so, subject to
129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt the following conditions:
139f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt The above copyright notice and this permission notice (including the
159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt next paragraph) shall be included in all copies or substantial
169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt portions of the Software.
179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
209f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt **********************************************************************/
279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /*
289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  * Authors:
299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  *   Keith Whitwell <keith@tungstengraphics.com>
309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt  */
319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_context.h"
339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_wm.h"
349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt#include "brw_state.h"
35c374487a54aca2dd1053645092367c1cf0414ef7Eric Anholt#include "main/formats.h"
364433b0302d0aa9dc61002e8bb4fd1b752b0be338Brian Paul#include "main/fbobject.h"
371f32c665c8af0622e2bbf451edb999ffbcd7d0feEric Anholt#include "main/samplerobj.h"
388752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt#include "program/prog_parameter.h"
399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
402f0edc60f4bd2ae5999a6afa656e3bb3f181bf0fChad Versace#include "glsl/ralloc.h"
41774fb90db3e83d5e7326b7a72e05ce805c306b24Kenneth Graunke
4232e03c4a2ff5ef07de892dcd26f6be3b82ab3ba1Brian Paul/** Return number of src args for given instruction */
439f344b3e7d6e23674dd4747faec253f103563b36Eric AnholtGLuint brw_wm_nr_args( GLuint opcode )
449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   switch (opcode) {
46699db6d842c52d0b3b98b320f8ef1104a65fa783Eric Anholt   case WM_FRONTFACING:
479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case WM_PIXELXY:
4808687c8b402f42eda5e0061112382528836b0fe9Eric Anholt      return 0;
49046e88fc0be37d5a3dfbfa9fb8033b549604c74cEric Anholt   case WM_CINTERP:
50046e88fc0be37d5a3dfbfa9fb8033b549604c74cEric Anholt   case WM_WPOSXY:
5108687c8b402f42eda5e0061112382528836b0fe9Eric Anholt   case WM_DELTAXY:
529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      return 1;
53046e88fc0be37d5a3dfbfa9fb8033b549604c74cEric Anholt   case WM_LINTERP:
549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case WM_PIXELW:
559f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      return 2;
569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case WM_FB_WRITE:
57046e88fc0be37d5a3dfbfa9fb8033b549604c74cEric Anholt   case WM_PINTERP:
589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      return 3;
599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   default:
60046e88fc0be37d5a3dfbfa9fb8033b549604c74cEric Anholt      assert(opcode < MAX_OPCODE);
61046e88fc0be37d5a3dfbfa9fb8033b549604c74cEric Anholt      return _mesa_num_inst_src_regs(opcode);
629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
669f344b3e7d6e23674dd4747faec253f103563b36Eric AnholtGLuint brw_wm_is_scalar_result( GLuint opcode )
679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   switch (opcode) {
699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case OPCODE_COS:
709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case OPCODE_EX2:
719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case OPCODE_LG2:
729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case OPCODE_POW:
739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case OPCODE_RCP:
749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case OPCODE_RSQ:
759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case OPCODE_SIN:
76dd5ef33e3c2ac7886ca71344e41201d0be2062c0Eric Anholt   case OPCODE_DP2:
779f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case OPCODE_DP3:
789f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case OPCODE_DP4:
799f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case OPCODE_DPH:
809f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   case OPCODE_DST:
819f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      return 1;
829f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   default:
849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      return 0;
859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
889f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
892f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul/**
902f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul * Do GPU code generation for non-GLSL shader.  non-GLSL shaders have
912f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul * no flow control instructions so we can more readily do SSA-style
922f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul * optimizations.
932f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul */
942f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paulstatic void
952f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paulbrw_wm_non_glsl_emit(struct brw_context *brw, struct brw_wm_compile *c)
962f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul{
972f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul   /* Augment fragment program.  Add instructions for pre- and
982f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul    * post-fragment-program tasks such as interpolation and fogging.
992f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul    */
1002f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul   brw_wm_pass_fp(c);
1012f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul
1022f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul   /* Translate to intermediate representation.  Build register usage
1032f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul    * chains.
1042f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul    */
1052f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul   brw_wm_pass0(c);
1062f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul
1072f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul   /* Dead code removal.
1082f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul    */
1092f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul   brw_wm_pass1(c);
1102f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul
1112f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul   /* Register allocation.
1125f1ce6b87e837b9f6bc2a4f3e81cf8feea4af2dfBrian Paul    * Divide by two because we operate on 16 pixels at a time and require
1135f1ce6b87e837b9f6bc2a4f3e81cf8feea4af2dfBrian Paul    * two GRF entries for each logical shader register.
1142f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul    */
1152f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul   c->grf_limit = BRW_WM_MAX_GRF / 2;
1162f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul
1172f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul   brw_wm_pass2(c);
1182f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul
1195f1ce6b87e837b9f6bc2a4f3e81cf8feea4af2dfBrian Paul   /* how many general-purpose registers are used */
1201791857d7d950d3d2834bbb09b495f51f43ef7c1Eric Anholt   c->prog_data.reg_blocks = brw_register_blocks(c->max_wm_grf);
1215f1ce6b87e837b9f6bc2a4f3e81cf8feea4af2dfBrian Paul
1222f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul   /* Emit GEN4 code.
1232f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul    */
1242f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul   brw_wm_emit(c);
1252f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul}
1262f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul
127e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry
128e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry/**
129e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry * Return a bitfield where bit n is set if barycentric interpolation mode n
130e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry * (see enum brw_wm_barycentric_interp_mode) is needed by the fragment shader.
131e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry */
13271d71d5e891570e8516c65471939a2ebdc07282aEric Anholtstatic unsigned
1338313f44409ceb733e9f8835926364164237b3111Paul Berrybrw_compute_barycentric_interp_modes(struct brw_context *brw,
1348313f44409ceb733e9f8835926364164237b3111Paul Berry                                     bool shade_model_flat,
1355aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry                                     const struct gl_fragment_program *fprog)
136e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry{
1375aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry   unsigned barycentric_interp_modes = 0;
1385aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry   int attr;
1395aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry
1405aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry   /* Loop through all fragment shader inputs to figure out what interpolation
1415aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry    * modes are in use, and set the appropriate bits in
1425aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry    * barycentric_interp_modes.
1435aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry    */
1445aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry   for (attr = 0; attr < FRAG_ATTRIB_MAX; ++attr) {
1455aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry      enum glsl_interp_qualifier interp_qualifier =
1465aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry         fprog->InterpQualifier[attr];
147d1056541e239dfcee0ad6af2fd2d9fab37dbf025Paul Berry      bool is_centroid = fprog->IsCentroid & BITFIELD64_BIT(attr);
1485aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry      bool is_gl_Color = attr == FRAG_ATTRIB_COL0 || attr == FRAG_ATTRIB_COL1;
1495aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry
1505aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry      /* Ignore unused inputs. */
1515aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry      if (!(fprog->Base.InputsRead & BITFIELD64_BIT(attr)))
1525aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry         continue;
1535aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry
1545aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry      /* Ignore WPOS and FACE, because they don't require interpolation. */
1555aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry      if (attr == FRAG_ATTRIB_WPOS || attr == FRAG_ATTRIB_FACE)
1565aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry         continue;
1575aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry
1588313f44409ceb733e9f8835926364164237b3111Paul Berry      /* Determine the set (or sets) of barycentric coordinates needed to
1598313f44409ceb733e9f8835926364164237b3111Paul Berry       * interpolate this variable.  Note that when
1608313f44409ceb733e9f8835926364164237b3111Paul Berry       * brw->needs_unlit_centroid_workaround is set, centroid interpolation
1618313f44409ceb733e9f8835926364164237b3111Paul Berry       * uses PIXEL interpolation for unlit pixels and CENTROID interpolation
1628313f44409ceb733e9f8835926364164237b3111Paul Berry       * for lit pixels, so we need both sets of barycentric coordinates.
1638313f44409ceb733e9f8835926364164237b3111Paul Berry       */
1645aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry      if (interp_qualifier == INTERP_QUALIFIER_NOPERSPECTIVE) {
165d1056541e239dfcee0ad6af2fd2d9fab37dbf025Paul Berry         if (is_centroid) {
166d1056541e239dfcee0ad6af2fd2d9fab37dbf025Paul Berry            barycentric_interp_modes |=
167d1056541e239dfcee0ad6af2fd2d9fab37dbf025Paul Berry               1 << BRW_WM_NONPERSPECTIVE_CENTROID_BARYCENTRIC;
1688313f44409ceb733e9f8835926364164237b3111Paul Berry         }
1698313f44409ceb733e9f8835926364164237b3111Paul Berry         if (!is_centroid || brw->needs_unlit_centroid_workaround) {
170d1056541e239dfcee0ad6af2fd2d9fab37dbf025Paul Berry            barycentric_interp_modes |=
171d1056541e239dfcee0ad6af2fd2d9fab37dbf025Paul Berry               1 << BRW_WM_NONPERSPECTIVE_PIXEL_BARYCENTRIC;
172d1056541e239dfcee0ad6af2fd2d9fab37dbf025Paul Berry         }
1735aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry      } else if (interp_qualifier == INTERP_QUALIFIER_SMOOTH ||
1745aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry                 (!(shade_model_flat && is_gl_Color) &&
1755aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry                  interp_qualifier == INTERP_QUALIFIER_NONE)) {
176d1056541e239dfcee0ad6af2fd2d9fab37dbf025Paul Berry         if (is_centroid) {
177d1056541e239dfcee0ad6af2fd2d9fab37dbf025Paul Berry            barycentric_interp_modes |=
178d1056541e239dfcee0ad6af2fd2d9fab37dbf025Paul Berry               1 << BRW_WM_PERSPECTIVE_CENTROID_BARYCENTRIC;
1798313f44409ceb733e9f8835926364164237b3111Paul Berry         }
1808313f44409ceb733e9f8835926364164237b3111Paul Berry         if (!is_centroid || brw->needs_unlit_centroid_workaround) {
181d1056541e239dfcee0ad6af2fd2d9fab37dbf025Paul Berry            barycentric_interp_modes |=
182d1056541e239dfcee0ad6af2fd2d9fab37dbf025Paul Berry               1 << BRW_WM_PERSPECTIVE_PIXEL_BARYCENTRIC;
183d1056541e239dfcee0ad6af2fd2d9fab37dbf025Paul Berry         }
1845aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry      }
1855aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry   }
1865aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry
1875aa96286e7e1a5380673eb75e8653616b48751fdPaul Berry   return barycentric_interp_modes;
188e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry}
189e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry
190e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry
191662f1b48bd1a02907bb42ecda889a3aa52a5755dEric Anholtvoid
19216f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholtbrw_wm_payload_setup(struct brw_context *brw,
19316f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt		     struct brw_wm_compile *c)
19416f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt{
19516f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt   struct intel_context *intel = &brw->intel;
19616f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt   bool uses_depth = (c->fp->program.Base.InputsRead &
19716f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt		      (1 << FRAG_ATTRIB_WPOS)) != 0;
19871d71d5e891570e8516c65471939a2ebdc07282aEric Anholt   unsigned barycentric_interp_modes = c->prog_data.barycentric_interp_modes;
199e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry   int i;
20016f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt
20116f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt   if (intel->gen >= 6) {
20216f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      /* R0-1: masks, pixel X/Y coordinates. */
20316f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      c->nr_payload_regs = 2;
20416f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      /* R2: only for 32-pixel dispatch.*/
205e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry
206e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry      /* R3-26: barycentric interpolation coordinates.  These appear in the
207e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry       * same order that they appear in the brw_wm_barycentric_interp_mode
208e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry       * enum.  Each set of coordinates occupies 2 registers if dispatch width
209e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry       * == 8 and 4 registers if dispatch width == 16.  Coordinates only
210e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry       * appear if they were enabled using the "Barycentric Interpolation
211e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry       * Mode" bits in WM_STATE.
212e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry       */
213e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry      for (i = 0; i < BRW_WM_BARYCENTRIC_INTERP_MODE_COUNT; ++i) {
214e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry         if (barycentric_interp_modes & (1 << i)) {
215e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry            c->barycentric_coord_reg[i] = c->nr_payload_regs;
216e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry            c->nr_payload_regs += 2;
217e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry            if (c->dispatch_width == 16) {
218e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry               c->nr_payload_regs += 2;
219e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry            }
220e04bdeae82797dbdcf6f544a997a4626fdfd4aeePaul Berry         }
22116f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      }
22216f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt
22316f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      /* R27: interpolated depth if uses source depth */
22416f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      if (uses_depth) {
22516f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt	 c->source_depth_reg = c->nr_payload_regs;
22616f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt	 c->nr_payload_regs++;
2275ba517baa22b05d594b8839ac06fe45b81c1d09fEric Anholt	 if (c->dispatch_width == 16) {
22816f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt	    /* R28: interpolated depth if not 8-wide. */
22916f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt	    c->nr_payload_regs++;
23016f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt	 }
23116f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      }
23216f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      /* R29: interpolated W set if GEN6_WM_USES_SOURCE_W.
23316f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt       */
23416f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      if (uses_depth) {
23516f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt	 c->source_w_reg = c->nr_payload_regs;
23616f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt	 c->nr_payload_regs++;
2375ba517baa22b05d594b8839ac06fe45b81c1d09fEric Anholt	 if (c->dispatch_width == 16) {
23816f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt	    /* R30: interpolated W if not 8-wide. */
23916f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt	    c->nr_payload_regs++;
24016f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt	 }
24116f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      }
24216f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      /* R31: MSAA position offsets. */
24316f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      /* R32-: bary for 32-pixel. */
24416f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      /* R58-59: interp W for 32-pixel. */
24516f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt
24616f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      if (c->fp->program.Base.OutputsWritten &
24716f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt	  BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
2482e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke	 c->source_depth_to_render_target = true;
2492e5a1a254ed81b1d3efa6064f48183eefac784d0Kenneth Graunke	 c->computes_depth = true;
25016f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      }
25116f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt   } else {
25216f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt      brw_wm_lookup_iz(intel, c);
25316f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt   }
25416f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt}
2552f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul
2562f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul/**
2572f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul * All Mesa program -> GPU code generation goes through this function.
2582f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul * Depending on the instructions used (i.e. flow control instructions)
2592f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul * we'll use one of two code generators.
2602f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul */
2618752764076e5b3f052a57e0134424a37bf2e9164Eric Anholtbool do_wm_prog(struct brw_context *brw,
2628752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt		struct gl_shader_program *prog,
2638752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt		struct brw_fragment_program *fp,
2648752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt		struct brw_wm_prog_key *key)
2659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
26659c6b775a6aacfe03c84dae62c2fd45d4af9d70bEric Anholt   struct intel_context *intel = &brw->intel;
267d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt   struct brw_wm_compile *c;
2689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   const GLuint *program;
2699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   GLuint program_size;
2709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
271d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt   c = brw->wm.compile_data;
272d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt   if (c == NULL) {
273774fb90db3e83d5e7326b7a72e05ce805c306b24Kenneth Graunke      brw->wm.compile_data = rzalloc(NULL, struct brw_wm_compile);
27414dc4937336061c4c8d51c75d96fa216d9edcf2aBrian Paul      c = brw->wm.compile_data;
27544a4abfd4f8695809eaec07df8eeb191d6e017d7Robert Ellison      if (c == NULL) {
27644a4abfd4f8695809eaec07df8eeb191d6e017d7Robert Ellison         /* Ouch - big out of memory problem.  Can't continue
27744a4abfd4f8695809eaec07df8eeb191d6e017d7Robert Ellison          * without triggering a segfault, no way to signal,
27844a4abfd4f8695809eaec07df8eeb191d6e017d7Robert Ellison          * so just return.
27944a4abfd4f8695809eaec07df8eeb191d6e017d7Robert Ellison          */
2808752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt         return false;
28144a4abfd4f8695809eaec07df8eeb191d6e017d7Robert Ellison      }
282d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt   } else {
283c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt      void *instruction = c->instruction;
284c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt      void *prog_instructions = c->prog_instructions;
285c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt      void *vreg = c->vreg;
286c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt      void *refs = c->refs;
28714dc4937336061c4c8d51c75d96fa216d9edcf2aBrian Paul      memset(c, 0, sizeof(*brw->wm.compile_data));
288c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt      c->instruction = instruction;
289c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt      c->prog_instructions = prog_instructions;
290c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt      c->vreg = vreg;
291c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt      c->refs = refs;
292d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt   }
293d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt   memcpy(&c->key, key, sizeof(*key));
2949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
295d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt   c->fp = fp;
296d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt   c->env_param = brw->intel.ctx.FragmentProgram.Parameters;
2979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
298774fb90db3e83d5e7326b7a72e05ce805c306b24Kenneth Graunke   brw_init_compile(brw, &c->func, c);
29914dc4937336061c4c8d51c75d96fa216d9edcf2aBrian Paul
30071d71d5e891570e8516c65471939a2ebdc07282aEric Anholt   c->prog_data.barycentric_interp_modes =
3018313f44409ceb733e9f8835926364164237b3111Paul Berry      brw_compute_barycentric_interp_modes(brw, c->key.flat_shade,
3028313f44409ceb733e9f8835926364164237b3111Paul Berry                                           &fp->program);
30371d71d5e891570e8516c65471939a2ebdc07282aEric Anholt
304de772c402215b956ab3aa0875330fc1bf7cdf95bIan Romanick   if (prog && prog->_LinkedShaders[MESA_SHADER_FRAGMENT]) {
3058752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt      if (!brw_wm_fs_emit(brw, c, prog))
3068752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt	 return false;
3078752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt   } else {
3080722edc59cd526437c2d4bad474b934dad84d789Eric Anholt      if (!c->instruction) {
3090722edc59cd526437c2d4bad474b934dad84d789Eric Anholt	 c->instruction = rzalloc_array(c, struct brw_wm_instruction, BRW_WM_MAX_INSN);
3100722edc59cd526437c2d4bad474b934dad84d789Eric Anholt	 c->prog_instructions = rzalloc_array(c, struct prog_instruction, BRW_WM_MAX_INSN);
3110722edc59cd526437c2d4bad474b934dad84d789Eric Anholt	 c->vreg = rzalloc_array(c, struct brw_wm_value, BRW_WM_MAX_VREG);
3120722edc59cd526437c2d4bad474b934dad84d789Eric Anholt	 c->refs = rzalloc_array(c, struct brw_wm_ref, BRW_WM_MAX_REF);
3130722edc59cd526437c2d4bad474b934dad84d789Eric Anholt      }
3140722edc59cd526437c2d4bad474b934dad84d789Eric Anholt
315662f1b48bd1a02907bb42ecda889a3aa52a5755dEric Anholt      /* Fallback for fixed function and ARB_fp shaders. */
3165ba517baa22b05d594b8839ac06fe45b81c1d09fEric Anholt      c->dispatch_width = 16;
3175ba517baa22b05d594b8839ac06fe45b81c1d09fEric Anholt      brw_wm_payload_setup(brw, c);
3185ba517baa22b05d594b8839ac06fe45b81c1d09fEric Anholt      brw_wm_non_glsl_emit(brw, c);
319662f1b48bd1a02907bb42ecda889a3aa52a5755dEric Anholt      c->prog_data.dispatch_width = 16;
320d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt   }
3212f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul
3224e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt   /* Scratch space is used for register spilling */
3234e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt   if (c->last_scratch) {
3244cfb9e30000eea9cb1f316ace9347083b619cdb0Eric Anholt      perf_debug("Fragment shader triggered register spilling.  "
3254cfb9e30000eea9cb1f316ace9347083b619cdb0Eric Anholt                 "Try reducing the number of live scalar values to "
3264cfb9e30000eea9cb1f316ace9347083b619cdb0Eric Anholt                 "improve performance.\n");
3274cfb9e30000eea9cb1f316ace9347083b619cdb0Eric Anholt
3282b224d66a01f3ce867fb05558b25749705bbfe7aEric Anholt      c->prog_data.total_scratch = brw_get_scratch_size(c->last_scratch);
32959c6b775a6aacfe03c84dae62c2fd45d4af9d70bEric Anholt
330abbb8fc3a7d49066ecca10cb9db0b4756a1bbef0Eric Anholt      brw_get_scratch_bo(intel, &brw->wm.scratch_bo,
331db6dd6d88fdc4361193dd063e4f150f01a104faaKenneth Graunke			 c->prog_data.total_scratch * brw->max_wm_threads);
3324e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt   }
3334e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt
334bb1540835056cdea5db6f55b19c0c87358f14cd1Eric Anholt   if (unlikely(INTEL_DEBUG & DEBUG_WM))
335fc3971d80051b34836716579fd060dbb122d036bEric Anholt      fprintf(stderr, "\n");
336fc3971d80051b34836716579fd060dbb122d036bEric Anholt
3379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* get the program
3389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
339d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt   program = brw_get_program(&c->func, &program_size);
3409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
341c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt   brw_upload_cache(&brw->cache, BRW_WM_PROG,
342c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		    &c->key, sizeof(c->key),
343c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		    program, program_size,
344c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		    &c->prog_data, sizeof(c->prog_data),
345c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt		    &brw->wm.prog_offset, &brw->wm.prog_data);
3468752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt
3478752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt   return true;
3489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
3499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
350fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholtstatic bool
351fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholtkey_debug(const char *name, int a, int b)
352fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt{
353fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   if (a != b) {
354fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt      perf_debug("  %s %d->%d\n", name, a, b);
355fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt      return true;
356fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   } else {
357fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt      return false;
358fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   }
359fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt}
360fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt
361fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholtbool
362fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholtbrw_debug_recompile_sampler_key(const struct brw_sampler_prog_key_data *old_key,
363fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt                                const struct brw_sampler_prog_key_data *key)
364fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt{
365fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   bool found = false;
366fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt
367f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke   for (unsigned int i = 0; i < MAX_SAMPLERS; i++) {
368fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt      found |= key_debug("EXT_texture_swizzle or DEPTH_TEXTURE_MODE",
36998211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke                         old_key->swizzles[i], key->swizzles[i]);
370fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   }
371fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   found |= key_debug("GL_CLAMP enabled on any texture unit's 1st coordinate",
37298211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke                      old_key->gl_clamp_mask[0], key->gl_clamp_mask[0]);
373fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   found |= key_debug("GL_CLAMP enabled on any texture unit's 2nd coordinate",
37498211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke                      old_key->gl_clamp_mask[1], key->gl_clamp_mask[1]);
375fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   found |= key_debug("GL_CLAMP enabled on any texture unit's 3rd coordinate",
37698211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke                      old_key->gl_clamp_mask[2], key->gl_clamp_mask[2]);
377fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   found |= key_debug("GL_MESA_ycbcr texturing\n",
37898211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke                      old_key->yuvtex_mask, key->yuvtex_mask);
379fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   found |= key_debug("GL_MESA_ycbcr UV swapping\n",
38098211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke                      old_key->yuvtex_swap_mask, key->yuvtex_swap_mask);
381fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt
382fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   return found;
383fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt}
384fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt
385fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholtvoid
386fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholtbrw_wm_debug_recompile(struct brw_context *brw,
387fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt                       struct gl_shader_program *prog,
388fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt                       const struct brw_wm_prog_key *key)
389fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt{
390fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   struct brw_cache_item *c = NULL;
391fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   const struct brw_wm_prog_key *old_key = NULL;
392fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   bool found = false;
393fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt
394fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   perf_debug("Recompiling fragment shader for program %d\n", prog->Name);
395fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt
396fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   for (unsigned int i = 0; i < brw->cache.size; i++) {
397fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt      for (c = brw->cache.items[i]; c; c = c->next) {
398fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt         if (c->cache_id == BRW_WM_PROG) {
399fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt            old_key = c->key;
400fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt
401fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt            if (old_key->program_string_id == key->program_string_id)
402fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt               break;
403fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt         }
404fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt      }
405fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt      if (c)
406fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt         break;
407fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   }
408fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt
409fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   if (!c) {
410fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt      perf_debug("  Didn't find previous compile in the shader cache for "
411fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt                 "debug\n");
412fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt      return;
413fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   }
414fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt
415fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   found |= key_debug("alphatest, computed depth, depth test, or depth write",
41698211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke                      old_key->iz_lookup, key->iz_lookup);
41798211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke   found |= key_debug("depth statistics", old_key->stats_wm, key->stats_wm);
41898211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke   found |= key_debug("flat shading", old_key->flat_shade, key->flat_shade);
41998211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke   found |= key_debug("number of color buffers", old_key->nr_color_regions, key->nr_color_regions);
42098211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke   found |= key_debug("rendering to FBO", old_key->render_to_fbo, key->render_to_fbo);
42198211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke   found |= key_debug("fragment color clamping", old_key->clamp_fragment_color, key->clamp_fragment_color);
42298211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke   found |= key_debug("line smoothing", old_key->line_aa, key->line_aa);
42398211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke   found |= key_debug("proj_attrib_mask", old_key->proj_attrib_mask, key->proj_attrib_mask);
42498211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke   found |= key_debug("renderbuffer height", old_key->drawable_height, key->drawable_height);
42598211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke   found |= key_debug("vertex shader outputs", old_key->vp_outputs_written, key->vp_outputs_written);
42698211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke
42798211d5af7efa26c350f6191457ab2564847abdeKenneth Graunke   found |= brw_debug_recompile_sampler_key(&old_key->tex, &key->tex);
428fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt
429fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   if (!found) {
430fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt      perf_debug("  Something else\n");
431fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt   }
432fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt}
433fc3b7c9b56701f23b002543de33a8d8c43f9bdc2Eric Anholt
4341b05fc7cdd0e5d77b50bc8ee2f2c851da5884d72Kenneth Graunkevoid
4351b05fc7cdd0e5d77b50bc8ee2f2c851da5884d72Kenneth Graunkebrw_populate_sampler_prog_key_data(struct gl_context *ctx,
436fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke				   const struct gl_program *prog,
437fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke				   struct brw_sampler_prog_key_data *key)
4381b05fc7cdd0e5d77b50bc8ee2f2c851da5884d72Kenneth Graunke{
439f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke   for (int s = 0; s < MAX_SAMPLERS; s++) {
440f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke      key->swizzles[s] = SWIZZLE_NOOP;
44176d1301e8e8e50dc962601a9977bc52148798349Kenneth Graunke
442f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke      if (!(prog->SamplersUsed & (1 << s)))
443fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke	 continue;
444fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke
445f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke      int unit_id = prog->SamplerUnits[s];
446f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke      const struct gl_texture_unit *unit = &ctx->Texture.Unit[unit_id];
447fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke
448fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke      if (unit->_ReallyEnabled && unit->_Current->Target != GL_TEXTURE_BUFFER) {
449fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke	 const struct gl_texture_object *t = unit->_Current;
450fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke	 const struct gl_texture_image *img = t->Image[0][t->BaseLevel];
451f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke	 struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit_id);
4523ebfd3f7743e5c05661eab977b23441e45441b39Kenneth Graunke
4533ebfd3f7743e5c05661eab977b23441e45441b39Kenneth Graunke	 key->swizzles[s] = brw_get_texture_swizzle(t);
4549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
455fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke	 if (img->InternalFormat == GL_YCBCR_MESA) {
456f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke	    key->yuvtex_mask |= 1 << s;
457fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke	    if (img->TexFormat == MESA_FORMAT_YCBCR)
458f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke		key->yuvtex_swap_mask |= 1 << s;
459fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke	 }
4601b05fc7cdd0e5d77b50bc8ee2f2c851da5884d72Kenneth Graunke
461fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke	 if (sampler->MinFilter != GL_NEAREST &&
462fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke	     sampler->MagFilter != GL_NEAREST) {
463fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke	    if (sampler->WrapS == GL_CLAMP)
464f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke	       key->gl_clamp_mask[0] |= 1 << s;
465fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke	    if (sampler->WrapT == GL_CLAMP)
466f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke	       key->gl_clamp_mask[1] |= 1 << s;
467fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke	    if (sampler->WrapR == GL_CLAMP)
468f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke	       key->gl_clamp_mask[2] |= 1 << s;
469fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke	 }
470fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke      }
4711b05fc7cdd0e5d77b50bc8ee2f2c851da5884d72Kenneth Graunke   }
4721b05fc7cdd0e5d77b50bc8ee2f2c851da5884d72Kenneth Graunke}
4739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
4749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic void brw_wm_populate_key( struct brw_context *brw,
4759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt				 struct brw_wm_prog_key *key )
4769f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
477f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg   struct gl_context *ctx = &brw->intel.ctx;
4782f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke   struct intel_context *intel = &brw->intel;
4799f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* BRW_NEW_FRAGMENT_PROGRAM */
48055d33e1fa7d231a0cdfce9b9650ae9e136e6c63cBrian Paul   const struct brw_fragment_program *fp =
4819f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      (struct brw_fragment_program *)brw->fragment_program;
482387a3d43d11cbd3eb1bd8ce787a2c693d575300cKenneth Graunke   const struct gl_program *prog = (struct gl_program *) brw->fragment_program;
4839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   GLuint lookup = 0;
4849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   GLuint line_aa;
485d08fdacd58dfa6b1926e9df4707dd9e8dd5370c5Paul Berry   bool program_uses_dfdy = fp->program.UsesDFdy;
48682d25963a838cfebdeb9b080169979329ee850eaPaul Berry
4879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   memset(key, 0, sizeof(*key));
4889f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
4899f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* Build the index for table lookup
4909f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt    */
4912f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke   if (intel->gen < 6) {
49286e401b771ce4a6f9a728f76c5061c339f012d0aKenneth Graunke      /* _NEW_COLOR */
4932f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke      if (fp->program.UsesKill || ctx->Color.AlphaEnabled)
4942f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke	 lookup |= IZ_PS_KILL_ALPHATEST_BIT;
4952f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke
4962f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke      if (fp->program.Base.OutputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH))
4972f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke	 lookup |= IZ_PS_COMPUTES_DEPTH_BIT;
4989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
4992f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke      /* _NEW_DEPTH */
5002f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke      if (ctx->Depth.Test)
5012f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke	 lookup |= IZ_DEPTH_TEST_ENABLE_BIT;
5029f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
5032f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke      if (ctx->Depth.Test && ctx->Depth.Mask) /* ?? */
5042f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke	 lookup |= IZ_DEPTH_WRITE_ENABLE_BIT;
5059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
5062f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke      /* _NEW_STENCIL */
5072f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke      if (ctx->Stencil._Enabled) {
5082f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke	 lookup |= IZ_STENCIL_TEST_ENABLE_BIT;
5099f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
5102f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke	 if (ctx->Stencil.WriteMask[0] ||
5112f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke	     ctx->Stencil.WriteMask[ctx->Stencil._BackFace])
5122f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke	    lookup |= IZ_STENCIL_WRITE_ENABLE_BIT;
5132f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke      }
5142f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke      key->iz_lookup = lookup;
5159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
5169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
5179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   line_aa = AA_NEVER;
5189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
5199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* _NEW_LINE, _NEW_POLYGON, BRW_NEW_REDUCED_PRIMITIVE */
520052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt   if (ctx->Line.SmoothFlag) {
5219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      if (brw->intel.reduced_primitive == GL_LINES) {
5229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 line_aa = AA_ALWAYS;
5239f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      }
5249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      else if (brw->intel.reduced_primitive == GL_TRIANGLES) {
525052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	 if (ctx->Polygon.FrontMode == GL_LINE) {
5269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    line_aa = AA_SOMETIMES;
5279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
528052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	    if (ctx->Polygon.BackMode == GL_LINE ||
529052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt		(ctx->Polygon.CullFlag &&
530052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt		 ctx->Polygon.CullFaceMode == GL_BACK))
5319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       line_aa = AA_ALWAYS;
5329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 }
533052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	 else if (ctx->Polygon.BackMode == GL_LINE) {
5349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	    line_aa = AA_SOMETIMES;
5359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
536052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt	    if ((ctx->Polygon.CullFlag &&
537052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt		 ctx->Polygon.CullFaceMode == GL_FRONT))
5389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	       line_aa = AA_ALWAYS;
5399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt	 }
5409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      }
5419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   }
5429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
54316f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt   key->line_aa = line_aa;
5446cc14c2493bb6957f2581671020809e90a8d8643Kenneth Graunke
5456cc14c2493bb6957f2581671020809e90a8d8643Kenneth Graunke   if (intel->gen < 6)
5466cc14c2493bb6957f2581671020809e90a8d8643Kenneth Graunke      key->stats_wm = brw->intel.stats_wm;
5479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
5489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* BRW_NEW_WM_INPUT_DIMENSIONS */
549ab17762c70852ca8fc400d7b5c6696d412ff2afeKenneth Graunke   /* Only set this for fixed function.  The optimization it enables isn't
550ab17762c70852ca8fc400d7b5c6696d412ff2afeKenneth Graunke    * useful for programs using shaders.
551ab17762c70852ca8fc400d7b5c6696d412ff2afeKenneth Graunke    */
552ab17762c70852ca8fc400d7b5c6696d412ff2afeKenneth Graunke   if (ctx->Shader.CurrentFragmentProgram)
553ab17762c70852ca8fc400d7b5c6696d412ff2afeKenneth Graunke      key->proj_attrib_mask = 0xffffffff;
554ab17762c70852ca8fc400d7b5c6696d412ff2afeKenneth Graunke   else
555ab17762c70852ca8fc400d7b5c6696d412ff2afeKenneth Graunke      key->proj_attrib_mask = brw->wm.input_size_masks[4-1];
5569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
5579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* _NEW_LIGHT */
558052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt   key->flat_shade = (ctx->Light.ShadeModel == GL_FLAT);
5599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
560d22e2ebe35ef9d33ec5f7a67f903f36bcd9fbc91Eric Anholt   /* _NEW_FRAG_CLAMP | _NEW_BUFFERS */
561d22e2ebe35ef9d33ec5f7a67f903f36bcd9fbc91Eric Anholt   key->clamp_fragment_color = ctx->Color._ClampFragmentColor;
562d22e2ebe35ef9d33ec5f7a67f903f36bcd9fbc91Eric Anholt
5639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   /* _NEW_TEXTURE */
564fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke   brw_populate_sampler_prog_key_data(ctx, prog, &key->tex);
5659c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt
5669c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt   /* _NEW_BUFFERS */
5679c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt   /*
5689c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt    * Include the draw buffer origin and height so that we can calculate
5699c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt    * fragment position values relative to the bottom left of the drawable,
5709c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt    * from the incoming screen origin relative position we get as part of our
5719c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt    * payload.
5729c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt    *
573861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul    * This is only needed for the WM_WPOSXY opcode when the fragment program
574861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul    * uses the gl_FragCoord input.
575861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul    *
5769c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt    * We could avoid recompiling by including this as a constant referenced by
5779c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt    * our program, but if we were to do that it would also be nice to handle
5789c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt    * getting that constant updated at batchbuffer submit time (when we
5799c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt    * hold the lock and know where the buffer really is) rather than at emit
5809c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt    * time when we don't hold the lock and are just guessing.  We could also
5819c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt    * just avoid using this as key data if the program doesn't use
5829c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt    * fragment.position.
5839c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt    *
584861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul    * For DRI2 the origin_x/y will always be (0,0) but we still need the
585861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul    * drawable height in order to invert the Y axis.
5869c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt    */
587861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul   if (fp->program.Base.InputsRead & FRAG_BIT_WPOS) {
588f62c2a0bb89041567467a6c01cf1eb27cec01e9eEric Anholt      key->drawable_height = ctx->DrawBuffer->Height;
58982d25963a838cfebdeb9b080169979329ee850eaPaul Berry   }
59082d25963a838cfebdeb9b080169979329ee850eaPaul Berry
59182d25963a838cfebdeb9b080169979329ee850eaPaul Berry   if ((fp->program.Base.InputsRead & FRAG_BIT_WPOS) || program_uses_dfdy) {
5924433b0302d0aa9dc61002e8bb4fd1b752b0be338Brian Paul      key->render_to_fbo = _mesa_is_user_fbo(ctx->DrawBuffer);
5939c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt   }
5949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
5951b80622c4e94e8c59eb2f7ee9989d99712baff8fEric Anholt   /* _NEW_BUFFERS */
5961b80622c4e94e8c59eb2f7ee9989d99712baff8fEric Anholt   key->nr_color_regions = ctx->DrawBuffer->_NumColorDrawBuffers;
597e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat  /* _NEW_MULTISAMPLE */
598e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat   key->sample_alpha_to_coverage = ctx->Multisample.SampleAlphaToCoverage;
5999ef33b86855c4d000271774030bd1b19b6d79687Brian Paul
6000f5113deed91611ecdda6596542530b1849bb161Eric Anholt   /* CACHE_NEW_VS_PROG */
601b6b1fc1261e86e2aa03ae8d2dd587c88a207354fKenneth Graunke   if (intel->gen < 6)
602b6b1fc1261e86e2aa03ae8d2dd587c88a207354fKenneth Graunke      key->vp_outputs_written = brw->vs.prog_data->outputs_written;
6030f5113deed91611ecdda6596542530b1849bb161Eric Anholt
60455d33e1fa7d231a0cdfce9b9650ae9e136e6c63cBrian Paul   /* The unique fragment program ID */
6059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   key->program_string_id = fp->id;
6069f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
6079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
6089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
609dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholtstatic void
610dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholtbrw_upload_wm_prog(struct brw_context *brw)
6119f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{
6128752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt   struct intel_context *intel = &brw->intel;
6138752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt   struct gl_context *ctx = &intel->ctx;
6149f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   struct brw_wm_prog_key key;
6159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   struct brw_fragment_program *fp = (struct brw_fragment_program *)
6169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      brw->fragment_program;
617662f1b48bd1a02907bb42ecda889a3aa52a5755dEric Anholt
6189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   brw_wm_populate_key(brw, &key);
6199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
620c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt   if (!brw_search_cache(&brw->cache, BRW_WM_PROG,
621c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt			 &key, sizeof(key),
622c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt			 &brw->wm.prog_offset, &brw->wm.prog_data)) {
623b527dd65c830a2b008816cf390d5be906e29bb23Ian Romanick      bool success = do_wm_prog(brw, ctx->Shader._CurrentFragmentProgram, fp,
6248752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt				&key);
6254170227407eea7fd8287b17480a37309bf73f4e4Brian Paul      (void) success;
6268752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt      assert(success);
6278752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt   }
6289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}
6299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
6309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
6319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtconst struct brw_tracked_state brw_wm_prog = {
6329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   .dirty = {
6339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      .mesa  = (_NEW_COLOR |
6349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		_NEW_DEPTH |
6359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		_NEW_STENCIL |
6369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		_NEW_POLYGON |
6379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		_NEW_LINE |
6389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		_NEW_LIGHT |
639d22e2ebe35ef9d33ec5f7a67f903f36bcd9fbc91Eric Anholt		_NEW_FRAG_CLAMP |
6409c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt		_NEW_BUFFERS |
641f8a8f069ee2dae35470c6e2a681e5e110044e6feAnuj Phogat		_NEW_TEXTURE |
642f8a8f069ee2dae35470c6e2a681e5e110044e6feAnuj Phogat		_NEW_MULTISAMPLE),
6439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt      .brw   = (BRW_NEW_FRAGMENT_PROGRAM |
6449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		BRW_NEW_WM_INPUT_DIMENSIONS |
6459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt		BRW_NEW_REDUCED_PRIMITIVE),
6460f5113deed91611ecdda6596542530b1849bb161Eric Anholt      .cache = CACHE_NEW_VS_PROG,
6479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt   },
648dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholt   .emit = brw_upload_wm_prog
6499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt};
6509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt
651