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{ 43942df904f88a3515bf8bea5c1228380714c9146fbKenneth Graunke struct intel_context *intel = intel_context(ctx); 44042df904f88a3515bf8bea5c1228380714c9146fbKenneth Graunke 441f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke for (int s = 0; s < MAX_SAMPLERS; s++) { 442f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke key->swizzles[s] = SWIZZLE_NOOP; 44376d1301e8e8e50dc962601a9977bc52148798349Kenneth Graunke 444f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke if (!(prog->SamplersUsed & (1 << s))) 445fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke continue; 446fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke 447f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke int unit_id = prog->SamplerUnits[s]; 448f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke const struct gl_texture_unit *unit = &ctx->Texture.Unit[unit_id]; 449fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke 450fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke if (unit->_ReallyEnabled && unit->_Current->Target != GL_TEXTURE_BUFFER) { 451fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke const struct gl_texture_object *t = unit->_Current; 452fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke const struct gl_texture_image *img = t->Image[0][t->BaseLevel]; 453f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit_id); 4543ebfd3f7743e5c05661eab977b23441e45441b39Kenneth Graunke 45542df904f88a3515bf8bea5c1228380714c9146fbKenneth Graunke const bool alpha_depth = t->DepthMode == GL_ALPHA && 45642df904f88a3515bf8bea5c1228380714c9146fbKenneth Graunke (img->_BaseFormat == GL_DEPTH_COMPONENT || 45742df904f88a3515bf8bea5c1228380714c9146fbKenneth Graunke img->_BaseFormat == GL_DEPTH_STENCIL); 45842df904f88a3515bf8bea5c1228380714c9146fbKenneth Graunke 45942df904f88a3515bf8bea5c1228380714c9146fbKenneth Graunke /* Haswell handles texture swizzling as surface format overrides 46042df904f88a3515bf8bea5c1228380714c9146fbKenneth Graunke * (except for GL_ALPHA); all other platforms need MOVs in the shader. 46142df904f88a3515bf8bea5c1228380714c9146fbKenneth Graunke */ 46242df904f88a3515bf8bea5c1228380714c9146fbKenneth Graunke if (!intel->is_haswell || alpha_depth) 46342df904f88a3515bf8bea5c1228380714c9146fbKenneth Graunke key->swizzles[s] = brw_get_texture_swizzle(t); 4649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 465fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke if (img->InternalFormat == GL_YCBCR_MESA) { 466f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke key->yuvtex_mask |= 1 << s; 467fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke if (img->TexFormat == MESA_FORMAT_YCBCR) 468f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke key->yuvtex_swap_mask |= 1 << s; 469fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke } 4701b05fc7cdd0e5d77b50bc8ee2f2c851da5884d72Kenneth Graunke 471fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke if (sampler->MinFilter != GL_NEAREST && 472fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke sampler->MagFilter != GL_NEAREST) { 473fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke if (sampler->WrapS == GL_CLAMP) 474f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke key->gl_clamp_mask[0] |= 1 << s; 475fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke if (sampler->WrapT == GL_CLAMP) 476f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke key->gl_clamp_mask[1] |= 1 << s; 477fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke if (sampler->WrapR == GL_CLAMP) 478f3d0daf7ea7e42ff9ce11e8bd6fba1059a2406e8Kenneth Graunke key->gl_clamp_mask[2] |= 1 << s; 479fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke } 480fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke } 4811b05fc7cdd0e5d77b50bc8ee2f2c851da5884d72Kenneth Graunke } 4821b05fc7cdd0e5d77b50bc8ee2f2c851da5884d72Kenneth Graunke} 4839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 4849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic void brw_wm_populate_key( struct brw_context *brw, 4859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt struct brw_wm_prog_key *key ) 4869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 487f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = &brw->intel.ctx; 4882f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke struct intel_context *intel = &brw->intel; 4899f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* BRW_NEW_FRAGMENT_PROGRAM */ 49055d33e1fa7d231a0cdfce9b9650ae9e136e6c63cBrian Paul const struct brw_fragment_program *fp = 4919f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt (struct brw_fragment_program *)brw->fragment_program; 492387a3d43d11cbd3eb1bd8ce787a2c693d575300cKenneth Graunke const struct gl_program *prog = (struct gl_program *) brw->fragment_program; 4939f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint lookup = 0; 4949f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint line_aa; 495d08fdacd58dfa6b1926e9df4707dd9e8dd5370c5Paul Berry bool program_uses_dfdy = fp->program.UsesDFdy; 49682d25963a838cfebdeb9b080169979329ee850eaPaul Berry 4979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt memset(key, 0, sizeof(*key)); 4989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 4999f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* Build the index for table lookup 5009f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 5012f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke if (intel->gen < 6) { 50286e401b771ce4a6f9a728f76c5061c339f012d0aKenneth Graunke /* _NEW_COLOR */ 5032f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke if (fp->program.UsesKill || ctx->Color.AlphaEnabled) 5042f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke lookup |= IZ_PS_KILL_ALPHATEST_BIT; 5052f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke 5062f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke if (fp->program.Base.OutputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) 5072f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke lookup |= IZ_PS_COMPUTES_DEPTH_BIT; 5089f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 5092f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke /* _NEW_DEPTH */ 5102f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke if (ctx->Depth.Test) 5112f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke lookup |= IZ_DEPTH_TEST_ENABLE_BIT; 5129f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 5132f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke if (ctx->Depth.Test && ctx->Depth.Mask) /* ?? */ 5142f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke lookup |= IZ_DEPTH_WRITE_ENABLE_BIT; 5159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 5162f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke /* _NEW_STENCIL */ 5172f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke if (ctx->Stencil._Enabled) { 5182f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke lookup |= IZ_STENCIL_TEST_ENABLE_BIT; 5199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 5202f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke if (ctx->Stencil.WriteMask[0] || 5212f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke ctx->Stencil.WriteMask[ctx->Stencil._BackFace]) 5222f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke lookup |= IZ_STENCIL_WRITE_ENABLE_BIT; 5232f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke } 5242f8351a5ac7bb04482eebaa73d967f7527df4d18Kenneth Graunke key->iz_lookup = lookup; 5259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 5269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 5279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt line_aa = AA_NEVER; 5289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 5299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* _NEW_LINE, _NEW_POLYGON, BRW_NEW_REDUCED_PRIMITIVE */ 530052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if (ctx->Line.SmoothFlag) { 5319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (brw->intel.reduced_primitive == GL_LINES) { 5329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt line_aa = AA_ALWAYS; 5339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 5349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt else if (brw->intel.reduced_primitive == GL_TRIANGLES) { 535052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if (ctx->Polygon.FrontMode == GL_LINE) { 5369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt line_aa = AA_SOMETIMES; 5379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 538052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if (ctx->Polygon.BackMode == GL_LINE || 539052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt (ctx->Polygon.CullFlag && 540052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt ctx->Polygon.CullFaceMode == GL_BACK)) 5419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt line_aa = AA_ALWAYS; 5429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 543052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt else if (ctx->Polygon.BackMode == GL_LINE) { 5449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt line_aa = AA_SOMETIMES; 5459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 546052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if ((ctx->Polygon.CullFlag && 547052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt ctx->Polygon.CullFaceMode == GL_FRONT)) 5489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt line_aa = AA_ALWAYS; 5499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 5509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 5519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 5529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 55316f8c823898fd71a3545457eacd2dc31ddeb3592Eric Anholt key->line_aa = line_aa; 5546cc14c2493bb6957f2581671020809e90a8d8643Kenneth Graunke 5556cc14c2493bb6957f2581671020809e90a8d8643Kenneth Graunke if (intel->gen < 6) 5566cc14c2493bb6957f2581671020809e90a8d8643Kenneth Graunke key->stats_wm = brw->intel.stats_wm; 5579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 5589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* BRW_NEW_WM_INPUT_DIMENSIONS */ 559ab17762c70852ca8fc400d7b5c6696d412ff2afeKenneth Graunke /* Only set this for fixed function. The optimization it enables isn't 560ab17762c70852ca8fc400d7b5c6696d412ff2afeKenneth Graunke * useful for programs using shaders. 561ab17762c70852ca8fc400d7b5c6696d412ff2afeKenneth Graunke */ 562ab17762c70852ca8fc400d7b5c6696d412ff2afeKenneth Graunke if (ctx->Shader.CurrentFragmentProgram) 563ab17762c70852ca8fc400d7b5c6696d412ff2afeKenneth Graunke key->proj_attrib_mask = 0xffffffff; 564ab17762c70852ca8fc400d7b5c6696d412ff2afeKenneth Graunke else 565ab17762c70852ca8fc400d7b5c6696d412ff2afeKenneth Graunke key->proj_attrib_mask = brw->wm.input_size_masks[4-1]; 5669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 5679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* _NEW_LIGHT */ 568052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt key->flat_shade = (ctx->Light.ShadeModel == GL_FLAT); 5699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 570d22e2ebe35ef9d33ec5f7a67f903f36bcd9fbc91Eric Anholt /* _NEW_FRAG_CLAMP | _NEW_BUFFERS */ 571d22e2ebe35ef9d33ec5f7a67f903f36bcd9fbc91Eric Anholt key->clamp_fragment_color = ctx->Color._ClampFragmentColor; 572d22e2ebe35ef9d33ec5f7a67f903f36bcd9fbc91Eric Anholt 5739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* _NEW_TEXTURE */ 574fe911c1d433c6fddc8f1e1226286b26d635d6ad4Kenneth Graunke brw_populate_sampler_prog_key_data(ctx, prog, &key->tex); 5759c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt 5769c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt /* _NEW_BUFFERS */ 5779c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt /* 5789c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * Include the draw buffer origin and height so that we can calculate 5799c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * fragment position values relative to the bottom left of the drawable, 5809c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * from the incoming screen origin relative position we get as part of our 5819c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * payload. 5829c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * 583861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul * This is only needed for the WM_WPOSXY opcode when the fragment program 584861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul * uses the gl_FragCoord input. 585861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul * 5869c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * We could avoid recompiling by including this as a constant referenced by 5879c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * our program, but if we were to do that it would also be nice to handle 5889c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * getting that constant updated at batchbuffer submit time (when we 5899c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * hold the lock and know where the buffer really is) rather than at emit 5909c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * time when we don't hold the lock and are just guessing. We could also 5919c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * just avoid using this as key data if the program doesn't use 5929c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * fragment.position. 5939c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * 594861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul * For DRI2 the origin_x/y will always be (0,0) but we still need the 595861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul * drawable height in order to invert the Y axis. 5969c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt */ 597861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul if (fp->program.Base.InputsRead & FRAG_BIT_WPOS) { 598f62c2a0bb89041567467a6c01cf1eb27cec01e9eEric Anholt key->drawable_height = ctx->DrawBuffer->Height; 59982d25963a838cfebdeb9b080169979329ee850eaPaul Berry } 60082d25963a838cfebdeb9b080169979329ee850eaPaul Berry 60182d25963a838cfebdeb9b080169979329ee850eaPaul Berry if ((fp->program.Base.InputsRead & FRAG_BIT_WPOS) || program_uses_dfdy) { 6024433b0302d0aa9dc61002e8bb4fd1b752b0be338Brian Paul key->render_to_fbo = _mesa_is_user_fbo(ctx->DrawBuffer); 6039c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt } 6049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 6051b80622c4e94e8c59eb2f7ee9989d99712baff8fEric Anholt /* _NEW_BUFFERS */ 6061b80622c4e94e8c59eb2f7ee9989d99712baff8fEric Anholt key->nr_color_regions = ctx->DrawBuffer->_NumColorDrawBuffers; 607e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat /* _NEW_MULTISAMPLE */ 608e592f7df0361eb8b5c75944f0151c4e6b3f839ddAnuj Phogat key->sample_alpha_to_coverage = ctx->Multisample.SampleAlphaToCoverage; 6099ef33b86855c4d000271774030bd1b19b6d79687Brian Paul 6100f5113deed91611ecdda6596542530b1849bb161Eric Anholt /* CACHE_NEW_VS_PROG */ 611b6b1fc1261e86e2aa03ae8d2dd587c88a207354fKenneth Graunke if (intel->gen < 6) 612b6b1fc1261e86e2aa03ae8d2dd587c88a207354fKenneth Graunke key->vp_outputs_written = brw->vs.prog_data->outputs_written; 6130f5113deed91611ecdda6596542530b1849bb161Eric Anholt 61455d33e1fa7d231a0cdfce9b9650ae9e136e6c63cBrian Paul /* The unique fragment program ID */ 6159f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt key->program_string_id = fp->id; 6169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 6179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 6189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 619dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholtstatic void 620dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholtbrw_upload_wm_prog(struct brw_context *brw) 6219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 6228752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt struct intel_context *intel = &brw->intel; 6238752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt struct gl_context *ctx = &intel->ctx; 6249f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt struct brw_wm_prog_key key; 6259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt struct brw_fragment_program *fp = (struct brw_fragment_program *) 6269f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt brw->fragment_program; 627662f1b48bd1a02907bb42ecda889a3aa52a5755dEric Anholt 6289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt brw_wm_populate_key(brw, &key); 6299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 630c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt if (!brw_search_cache(&brw->cache, BRW_WM_PROG, 631c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt &key, sizeof(key), 632c173541d9769d41a85cc899bc49699a3587df4bfEric Anholt &brw->wm.prog_offset, &brw->wm.prog_data)) { 633b527dd65c830a2b008816cf390d5be906e29bb23Ian Romanick bool success = do_wm_prog(brw, ctx->Shader._CurrentFragmentProgram, fp, 6348752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt &key); 6354170227407eea7fd8287b17480a37309bf73f4e4Brian Paul (void) success; 6368752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt assert(success); 6378752764076e5b3f052a57e0134424a37bf2e9164Eric Anholt } 6389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 6399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 6409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 6419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtconst struct brw_tracked_state brw_wm_prog = { 6429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .dirty = { 6439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .mesa = (_NEW_COLOR | 6449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt _NEW_DEPTH | 6459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt _NEW_STENCIL | 6469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt _NEW_POLYGON | 6479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt _NEW_LINE | 6489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt _NEW_LIGHT | 649d22e2ebe35ef9d33ec5f7a67f903f36bcd9fbc91Eric Anholt _NEW_FRAG_CLAMP | 6509c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt _NEW_BUFFERS | 651f8a8f069ee2dae35470c6e2a681e5e110044e6feAnuj Phogat _NEW_TEXTURE | 652f8a8f069ee2dae35470c6e2a681e5e110044e6feAnuj Phogat _NEW_MULTISAMPLE), 6539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .brw = (BRW_NEW_FRAGMENT_PROGRAM | 6549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt BRW_NEW_WM_INPUT_DIMENSIONS | 6559f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt BRW_NEW_REDUCED_PRIMITIVE), 6560f5113deed91611ecdda6596542530b1849bb161Eric Anholt .cache = CACHE_NEW_VS_PROG, 6579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt }, 658dc9a753f6687133d2d057597e5af86abcdc56781Eric Anholt .emit = brw_upload_wm_prog 6599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}; 6609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 661