brw_wm.c revision 4e7252510976d8d3ff12437ea8842129f24d88f5
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" 369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 3732e03c4a2ff5ef07de892dcd26f6be3b82ab3ba1Brian Paul/** Return number of src args for given instruction */ 389f344b3e7d6e23674dd4747faec253f103563b36Eric AnholtGLuint brw_wm_nr_args( GLuint opcode ) 399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt switch (opcode) { 41699db6d842c52d0b3b98b320f8ef1104a65fa783Eric Anholt case WM_FRONTFACING: 429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case WM_PIXELXY: 4308687c8b402f42eda5e0061112382528836b0fe9Eric Anholt return 0; 44046e88fc0be37d5a3dfbfa9fb8033b549604c74cEric Anholt case WM_CINTERP: 45046e88fc0be37d5a3dfbfa9fb8033b549604c74cEric Anholt case WM_WPOSXY: 4608687c8b402f42eda5e0061112382528836b0fe9Eric Anholt case WM_DELTAXY: 479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return 1; 48046e88fc0be37d5a3dfbfa9fb8033b549604c74cEric Anholt case WM_LINTERP: 499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case WM_PIXELW: 509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return 2; 519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case WM_FB_WRITE: 52046e88fc0be37d5a3dfbfa9fb8033b549604c74cEric Anholt case WM_PINTERP: 539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return 3; 549f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt default: 55046e88fc0be37d5a3dfbfa9fb8033b549604c74cEric Anholt assert(opcode < MAX_OPCODE); 56046e88fc0be37d5a3dfbfa9fb8033b549604c74cEric Anholt return _mesa_num_inst_src_regs(opcode); 579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 619f344b3e7d6e23674dd4747faec253f103563b36Eric AnholtGLuint brw_wm_is_scalar_result( GLuint opcode ) 629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt switch (opcode) { 649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case OPCODE_COS: 659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case OPCODE_EX2: 669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case OPCODE_LG2: 679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case OPCODE_POW: 689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case OPCODE_RCP: 699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case OPCODE_RSQ: 709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case OPCODE_SIN: 71dd5ef33e3c2ac7886ca71344e41201d0be2062c0Eric Anholt case OPCODE_DP2: 729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case OPCODE_DP3: 739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case OPCODE_DP4: 749f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case OPCODE_DPH: 759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt case OPCODE_DST: 769f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return 1; 779f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 789f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt default: 799f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt return 0; 809f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 819f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 829f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 842f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul/** 852f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul * Do GPU code generation for non-GLSL shader. non-GLSL shaders have 862f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul * no flow control instructions so we can more readily do SSA-style 872f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul * optimizations. 882f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul */ 892f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paulstatic void 902f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paulbrw_wm_non_glsl_emit(struct brw_context *brw, struct brw_wm_compile *c) 912f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul{ 922f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul /* Augment fragment program. Add instructions for pre- and 932f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul * post-fragment-program tasks such as interpolation and fogging. 942f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul */ 952f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul brw_wm_pass_fp(c); 962f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul 972f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul /* Translate to intermediate representation. Build register usage 982f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul * chains. 992f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul */ 1002f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul brw_wm_pass0(c); 1012f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul 1022f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul /* Dead code removal. 1032f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul */ 1042f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul brw_wm_pass1(c); 1052f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul 1062f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul /* Register allocation. 1075f1ce6b87e837b9f6bc2a4f3e81cf8feea4af2dfBrian Paul * Divide by two because we operate on 16 pixels at a time and require 1085f1ce6b87e837b9f6bc2a4f3e81cf8feea4af2dfBrian Paul * two GRF entries for each logical shader register. 1092f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul */ 1102f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul c->grf_limit = BRW_WM_MAX_GRF / 2; 1112f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul 1122f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul brw_wm_pass2(c); 1132f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul 1145f1ce6b87e837b9f6bc2a4f3e81cf8feea4af2dfBrian Paul /* how many general-purpose registers are used */ 1152f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul c->prog_data.total_grf = c->max_wm_grf; 1165f1ce6b87e837b9f6bc2a4f3e81cf8feea4af2dfBrian Paul 1172f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul /* Emit GEN4 code. 1182f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul */ 1192f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul brw_wm_emit(c); 1202f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul} 1212f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul 1222f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul 1232f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul/** 1242f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul * All Mesa program -> GPU code generation goes through this function. 1252f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul * Depending on the instructions used (i.e. flow control instructions) 1262f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul * we'll use one of two code generators. 1272f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul */ 1289f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic void do_wm_prog( struct brw_context *brw, 1299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt struct brw_fragment_program *fp, 1309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt struct brw_wm_prog_key *key) 1319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 132d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt struct brw_wm_compile *c; 1339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt const GLuint *program; 1349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint program_size; 1359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 136d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt c = brw->wm.compile_data; 137d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt if (c == NULL) { 13814dc4937336061c4c8d51c75d96fa216d9edcf2aBrian Paul brw->wm.compile_data = calloc(1, sizeof(*brw->wm.compile_data)); 13914dc4937336061c4c8d51c75d96fa216d9edcf2aBrian Paul c = brw->wm.compile_data; 14044a4abfd4f8695809eaec07df8eeb191d6e017d7Robert Ellison if (c == NULL) { 14144a4abfd4f8695809eaec07df8eeb191d6e017d7Robert Ellison /* Ouch - big out of memory problem. Can't continue 14244a4abfd4f8695809eaec07df8eeb191d6e017d7Robert Ellison * without triggering a segfault, no way to signal, 14344a4abfd4f8695809eaec07df8eeb191d6e017d7Robert Ellison * so just return. 14444a4abfd4f8695809eaec07df8eeb191d6e017d7Robert Ellison */ 14544a4abfd4f8695809eaec07df8eeb191d6e017d7Robert Ellison return; 14644a4abfd4f8695809eaec07df8eeb191d6e017d7Robert Ellison } 14732f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg c->instruction = calloc(1, BRW_WM_MAX_INSN * sizeof(*c->instruction)); 14832f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg c->prog_instructions = calloc(1, BRW_WM_MAX_INSN * 149c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt sizeof(*c->prog_instructions)); 15032f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg c->vreg = calloc(1, BRW_WM_MAX_VREG * sizeof(*c->vreg)); 15132f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg c->refs = calloc(1, BRW_WM_MAX_REF * sizeof(*c->refs)); 152d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt } else { 153c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt void *instruction = c->instruction; 154c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt void *prog_instructions = c->prog_instructions; 155c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt void *vreg = c->vreg; 156c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt void *refs = c->refs; 15714dc4937336061c4c8d51c75d96fa216d9edcf2aBrian Paul memset(c, 0, sizeof(*brw->wm.compile_data)); 158c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt c->instruction = instruction; 159c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt c->prog_instructions = prog_instructions; 160c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt c->vreg = vreg; 161c5413839b3e99c7b162f1260142f3c175502b0ceEric Anholt c->refs = refs; 162d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt } 163d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt memcpy(&c->key, key, sizeof(*key)); 1649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 165d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt c->fp = fp; 166d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt c->env_param = brw->intel.ctx.FragmentProgram.Parameters; 1679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 16814dc4937336061c4c8d51c75d96fa216d9edcf2aBrian Paul brw_init_compile(brw, &c->func); 16914dc4937336061c4c8d51c75d96fa216d9edcf2aBrian Paul 1705cbd1170da0a902fdc9c460584bc503b0c4085a6Brian Paul /* temporary sanity check assertion */ 1715cbd1170da0a902fdc9c460584bc503b0c4085a6Brian Paul ASSERT(fp->isGLSL == brw_wm_is_glsl(&c->fp->program)); 1725cbd1170da0a902fdc9c460584bc503b0c4085a6Brian Paul 1739763d0a82a1ee605a8794f199d432824fb972b6aEric Anholt if (!brw_wm_fs_emit(brw, c)) { 1749763d0a82a1ee605a8794f199d432824fb972b6aEric Anholt /* 1759763d0a82a1ee605a8794f199d432824fb972b6aEric Anholt * Shader which use GLSL features such as flow control are handled 1769763d0a82a1ee605a8794f199d432824fb972b6aEric Anholt * differently from "simple" shaders. 1779763d0a82a1ee605a8794f199d432824fb972b6aEric Anholt */ 1789763d0a82a1ee605a8794f199d432824fb972b6aEric Anholt if (fp->isGLSL) { 1799763d0a82a1ee605a8794f199d432824fb972b6aEric Anholt c->dispatch_width = 8; 1809763d0a82a1ee605a8794f199d432824fb972b6aEric Anholt brw_wm_glsl_emit(brw, c); 1819763d0a82a1ee605a8794f199d432824fb972b6aEric Anholt } 1829763d0a82a1ee605a8794f199d432824fb972b6aEric Anholt else { 1839763d0a82a1ee605a8794f199d432824fb972b6aEric Anholt c->dispatch_width = 16; 1849763d0a82a1ee605a8794f199d432824fb972b6aEric Anholt brw_wm_non_glsl_emit(brw, c); 1859763d0a82a1ee605a8794f199d432824fb972b6aEric Anholt } 186d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt } 1872f78d4a2cd009d8d6a5f470d5738586b7f89f3d9Brian Paul 1884e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt /* Scratch space is used for register spilling */ 1894e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt if (c->last_scratch) { 1904e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt /* Per-thread scratch space is power-of-two sized. */ 1914e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt for (c->prog_data.total_scratch = 1024; 1924e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt c->prog_data.total_scratch <= c->last_scratch; 1934e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt c->prog_data.total_scratch *= 2) { 1944e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt /* empty */ 1954e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt } 1964e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt } 1974e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt else { 1984e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt c->prog_data.total_scratch = 0; 1994e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt } 2004e7252510976d8d3ff12437ea8842129f24d88f5Eric Anholt 201fc3971d80051b34836716579fd060dbb122d036bEric Anholt if (INTEL_DEBUG & DEBUG_WM) 202fc3971d80051b34836716579fd060dbb122d036bEric Anholt fprintf(stderr, "\n"); 203fc3971d80051b34836716579fd060dbb122d036bEric Anholt 2049f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* get the program 2059f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 206d7b24fec245f90db4b8c66f4f7c167b8f20a9b9eEric Anholt program = brw_get_program(&c->func, &program_size); 2079f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 20834474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt drm_intel_bo_unreference(brw->wm.prog_bo); 20962a96f74c9a1fd07301d349e4181a7212fc7d45cEric Anholt brw->wm.prog_bo = brw_upload_cache_with_auxdata(&brw->cache, BRW_WM_PROG, 21062a96f74c9a1fd07301d349e4181a7212fc7d45cEric Anholt &c->key, sizeof(c->key), 21162a96f74c9a1fd07301d349e4181a7212fc7d45cEric Anholt NULL, 0, 21262a96f74c9a1fd07301d349e4181a7212fc7d45cEric Anholt program, program_size, 21362a96f74c9a1fd07301d349e4181a7212fc7d45cEric Anholt &c->prog_data, 21462a96f74c9a1fd07301d349e4181a7212fc7d45cEric Anholt sizeof(c->prog_data), 21562a96f74c9a1fd07301d349e4181a7212fc7d45cEric Anholt &brw->wm.prog_data); 2169f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 2179f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2189f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2199f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2209f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtstatic void brw_wm_populate_key( struct brw_context *brw, 2219f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt struct brw_wm_prog_key *key ) 2229f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 223dd9a88f4ddf4e5fa384792f891a1cc3d8ff73946Eric Anholt struct intel_context *intel = &brw->intel; 224f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg struct gl_context *ctx = &brw->intel.ctx; 2259f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* BRW_NEW_FRAGMENT_PROGRAM */ 22655d33e1fa7d231a0cdfce9b9650ae9e136e6c63cBrian Paul const struct brw_fragment_program *fp = 2279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt (struct brw_fragment_program *)brw->fragment_program; 228f44916414ecd2b888c8a680d56b7467ccdff6886Eric Anholt GLboolean uses_depth = (fp->program.Base.InputsRead & (1 << FRAG_ATTRIB_WPOS)) != 0; 2299f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint lookup = 0; 2309f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint line_aa; 2319f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt GLuint i; 2329f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2339f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt memset(key, 0, sizeof(*key)); 2349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* Build the index for table lookup 2369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 2379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* _NEW_COLOR */ 2389f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (fp->program.UsesKill || 239052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt ctx->Color.AlphaEnabled) 2409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt lookup |= IZ_PS_KILL_ALPHATEST_BIT; 2419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2425606dfb572bf4b89b4882265924705bacc8c182bIan Romanick if (fp->program.Base.OutputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) 2439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt lookup |= IZ_PS_COMPUTES_DEPTH_BIT; 2449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* _NEW_DEPTH */ 246052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if (ctx->Depth.Test) 2479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt lookup |= IZ_DEPTH_TEST_ENABLE_BIT; 2489f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 249052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if (ctx->Depth.Test && 250052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt ctx->Depth.Mask) /* ?? */ 2519f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt lookup |= IZ_DEPTH_WRITE_ENABLE_BIT; 2529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* _NEW_STENCIL */ 25491e61f435a71436c209934a0ece165b540aba3e0Brian Paul if (ctx->Stencil._Enabled) { 2559f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt lookup |= IZ_STENCIL_TEST_ENABLE_BIT; 2569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 257052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if (ctx->Stencil.WriteMask[0] || 258052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt ctx->Stencil.WriteMask[ctx->Stencil._BackFace]) 2599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt lookup |= IZ_STENCIL_WRITE_ENABLE_BIT; 2609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2619f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2629f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt line_aa = AA_NEVER; 2639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 2649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* _NEW_LINE, _NEW_POLYGON, BRW_NEW_REDUCED_PRIMITIVE */ 265052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if (ctx->Line.SmoothFlag) { 2669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (brw->intel.reduced_primitive == GL_LINES) { 2679f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt line_aa = AA_ALWAYS; 2689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt else if (brw->intel.reduced_primitive == GL_TRIANGLES) { 270052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if (ctx->Polygon.FrontMode == GL_LINE) { 2719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt line_aa = AA_SOMETIMES; 2729f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 273052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if (ctx->Polygon.BackMode == GL_LINE || 274052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt (ctx->Polygon.CullFlag && 275052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt ctx->Polygon.CullFaceMode == GL_BACK)) 2769f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt line_aa = AA_ALWAYS; 2779f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 278052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt else if (ctx->Polygon.BackMode == GL_LINE) { 2799f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt line_aa = AA_SOMETIMES; 2809f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 281052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt if ((ctx->Polygon.CullFlag && 282052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt ctx->Polygon.CullFaceMode == GL_FRONT)) 2839f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt line_aa = AA_ALWAYS; 2849f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2859f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2869f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 2879f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 288a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt if (intel->gen >= 6) { 289a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R0-1: masks, pixel X/Y coordinates. */ 290a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt key->nr_payload_regs = 2; 291a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R2: only for 32-pixel dispatch.*/ 292a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R3-4: perspective pixel location barycentric */ 293a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt key->nr_payload_regs += 2; 294a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R5-6: perspective pixel location bary for dispatch width != 8 */ 295a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt if (!fp->isGLSL) { /* dispatch_width != 8 */ 296a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt key->nr_payload_regs += 2; 297a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt } 298a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R7-10: perspective centroid barycentric */ 299a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R11-14: perspective sample barycentric */ 300a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R15-18: linear pixel location barycentric */ 301a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R19-22: linear centroid barycentric */ 302a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R23-26: linear sample barycentric */ 303a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt 304a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R27: interpolated depth if uses source depth */ 305a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt if (uses_depth) { 306a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt key->source_depth_reg = key->nr_payload_regs; 307a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt key->nr_payload_regs++; 308a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt if (!fp->isGLSL) { /* dispatch_width != 8 */ 309a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R28: interpolated depth if not 8-wide. */ 310a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt key->nr_payload_regs++; 311a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt } 312a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt } 313a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R29: interpolated W set if GEN6_WM_USES_SOURCE_W. 314a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt */ 315a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt if (uses_depth) { 316a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt key->source_w_reg = key->nr_payload_regs; 317a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt key->nr_payload_regs++; 318a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt if (!fp->isGLSL) { /* dispatch_width != 8 */ 319a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R30: interpolated W if not 8-wide. */ 320a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt key->nr_payload_regs++; 321a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt } 322a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt } 323a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R31: MSAA position offsets. */ 324a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R32-: bary for 32-pixel. */ 325a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt /* R58-59: interp W for 32-pixel. */ 32632573792de559c4dbad766a7cfcf02ea71f5047fEric Anholt 32732573792de559c4dbad766a7cfcf02ea71f5047fEric Anholt if (fp->program.Base.OutputsWritten & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) { 32832573792de559c4dbad766a7cfcf02ea71f5047fEric Anholt key->source_depth_to_render_target = GL_TRUE; 32932573792de559c4dbad766a7cfcf02ea71f5047fEric Anholt key->computes_depth = GL_TRUE; 33032573792de559c4dbad766a7cfcf02ea71f5047fEric Anholt } 33132573792de559c4dbad766a7cfcf02ea71f5047fEric Anholt 332a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt } else { 333a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt brw_wm_lookup_iz(intel, 334a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt line_aa, 335a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt lookup, 336a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt uses_depth, 337a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt key); 338a66e9a4d86d227b65874c43fbf9e299c7a26389fEric Anholt } 3399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 3409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* BRW_NEW_WM_INPUT_DIMENSIONS */ 3416b917d0b1787280f976c2f0d1ead0e5d7587a3e9Brian Paul key->proj_attrib_mask = brw->wm.input_size_masks[4-1]; 3429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 3439f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* _NEW_LIGHT */ 344052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt key->flat_shade = (ctx->Light.ShadeModel == GL_FLAT); 3459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 34618af7c384cf663533f210d95d074c244d4214f29Brian Paul /* _NEW_HINT */ 34718af7c384cf663533f210d95d074c244d4214f29Brian Paul key->linear_color = (ctx->Hint.PerspectiveCorrection == GL_FASTEST); 34818af7c384cf663533f210d95d074c244d4214f29Brian Paul 3499f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* _NEW_TEXTURE */ 3509f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt for (i = 0; i < BRW_MAX_TEX_UNIT; i++) { 351052c1d66a1ab1f2665870dc77dab28d20416cdf1Eric Anholt const struct gl_texture_unit *unit = &ctx->Texture.Unit[i]; 3529f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 3539f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt if (unit->_ReallyEnabled) { 35489fddf978c9d2ab5042f89110015234e979c2686Brian Paul const struct gl_texture_object *t = unit->_Current; 35589fddf978c9d2ab5042f89110015234e979c2686Brian Paul const struct gl_texture_image *img = t->Image[0][t->BaseLevel]; 35614bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt int swizzles[SWIZZLE_NIL + 1] = { 35714bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt SWIZZLE_X, 35814bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt SWIZZLE_Y, 35914bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt SWIZZLE_Z, 36014bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt SWIZZLE_W, 36114bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt SWIZZLE_ZERO, 36214bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt SWIZZLE_ONE, 36314bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt SWIZZLE_NIL 36414bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt }; 365a7fa00dfc5ab5782b2e497fbf4ca292dde69cdbdEric Anholt 366a7fa00dfc5ab5782b2e497fbf4ca292dde69cdbdEric Anholt key->tex_swizzles[i] = SWIZZLE_NOOP; 367a7fa00dfc5ab5782b2e497fbf4ca292dde69cdbdEric Anholt 368a7fa00dfc5ab5782b2e497fbf4ca292dde69cdbdEric Anholt /* GL_DEPTH_TEXTURE_MODE is normally handled through 369a7fa00dfc5ab5782b2e497fbf4ca292dde69cdbdEric Anholt * brw_wm_surface_state, but it applies to shadow compares as 370a7fa00dfc5ab5782b2e497fbf4ca292dde69cdbdEric Anholt * well and our shadow compares always return the result in 371a7fa00dfc5ab5782b2e497fbf4ca292dde69cdbdEric Anholt * all 4 channels. 372a7fa00dfc5ab5782b2e497fbf4ca292dde69cdbdEric Anholt */ 373a7fa00dfc5ab5782b2e497fbf4ca292dde69cdbdEric Anholt if (t->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) { 374a7fa00dfc5ab5782b2e497fbf4ca292dde69cdbdEric Anholt if (t->DepthMode == GL_ALPHA) { 37514bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt swizzles[0] = SWIZZLE_ZERO; 37614bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt swizzles[1] = SWIZZLE_ZERO; 37714bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt swizzles[2] = SWIZZLE_ZERO; 378a7fa00dfc5ab5782b2e497fbf4ca292dde69cdbdEric Anholt } else if (t->DepthMode == GL_LUMINANCE) { 37914bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt swizzles[3] = SWIZZLE_ONE; 380a7fa00dfc5ab5782b2e497fbf4ca292dde69cdbdEric Anholt } 381a7fa00dfc5ab5782b2e497fbf4ca292dde69cdbdEric Anholt } 382a7fa00dfc5ab5782b2e497fbf4ca292dde69cdbdEric Anholt 38389fddf978c9d2ab5042f89110015234e979c2686Brian Paul if (img->InternalFormat == GL_YCBCR_MESA) { 38489fddf978c9d2ab5042f89110015234e979c2686Brian Paul key->yuvtex_mask |= 1 << i; 3851f7c914ad0beea8a29c1a171c7cd1a12f2efe0faBrian Paul if (img->TexFormat == MESA_FORMAT_YCBCR) 38689fddf978c9d2ab5042f89110015234e979c2686Brian Paul key->yuvtex_swap_mask |= 1 << i; 3877676980d38cff417015bca8d23549d567d74228bZou Nan hai } 388c0d3b7679aa90e1a0dca2db152205efaec088b90Brian Paul 38914bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt key->tex_swizzles[i] = 39014bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt MAKE_SWIZZLE4(swizzles[GET_SWZ(t->_Swizzle, 0)], 39114bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt swizzles[GET_SWZ(t->_Swizzle, 1)], 39214bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt swizzles[GET_SWZ(t->_Swizzle, 2)], 39314bf92ba19373d54e9909bbdda5e430e0affea37Eric Anholt swizzles[GET_SWZ(t->_Swizzle, 3)]); 394c0d3b7679aa90e1a0dca2db152205efaec088b90Brian Paul } 395c0d3b7679aa90e1a0dca2db152205efaec088b90Brian Paul else { 396c0d3b7679aa90e1a0dca2db152205efaec088b90Brian Paul key->tex_swizzles[i] = SWIZZLE_NOOP; 3979f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 3989f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt } 3999c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt 400b17b110716936c32d20910cb9589038062b4f527Xiang, Haihao /* Shadow */ 401b17b110716936c32d20910cb9589038062b4f527Xiang, Haihao key->shadowtex_mask = fp->program.Base.ShadowSamplers; 402b17b110716936c32d20910cb9589038062b4f527Xiang, Haihao 4039c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt /* _NEW_BUFFERS */ 4049c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt /* 4059c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * Include the draw buffer origin and height so that we can calculate 4069c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * fragment position values relative to the bottom left of the drawable, 4079c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * from the incoming screen origin relative position we get as part of our 4089c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * payload. 4099c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * 410861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul * This is only needed for the WM_WPOSXY opcode when the fragment program 411861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul * uses the gl_FragCoord input. 412861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul * 4139c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * We could avoid recompiling by including this as a constant referenced by 4149c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * our program, but if we were to do that it would also be nice to handle 4159c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * getting that constant updated at batchbuffer submit time (when we 4169c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * hold the lock and know where the buffer really is) rather than at emit 4179c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * time when we don't hold the lock and are just guessing. We could also 4189c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * just avoid using this as key data if the program doesn't use 4199c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * fragment.position. 4209c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt * 421861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul * For DRI2 the origin_x/y will always be (0,0) but we still need the 422861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul * drawable height in order to invert the Y axis. 4239c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt */ 424861fec163c1ae7e431956db0a08989d841e2b74eBrian Paul if (fp->program.Base.InputsRead & FRAG_BIT_WPOS) { 425f62c2a0bb89041567467a6c01cf1eb27cec01e9eEric Anholt key->drawable_height = ctx->DrawBuffer->Height; 4269c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt } 4279f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 4289ef33b86855c4d000271774030bd1b19b6d79687Brian Paul key->nr_color_regions = brw->state.nr_color_regions; 4299ef33b86855c4d000271774030bd1b19b6d79687Brian Paul 4300f5113deed91611ecdda6596542530b1849bb161Eric Anholt /* CACHE_NEW_VS_PROG */ 4315606dfb572bf4b89b4882265924705bacc8c182bIan Romanick key->vp_outputs_written = brw->vs.prog_data->outputs_written; 4320f5113deed91611ecdda6596542530b1849bb161Eric Anholt 43355d33e1fa7d231a0cdfce9b9650ae9e136e6c63cBrian Paul /* The unique fragment program ID */ 4349f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt key->program_string_id = fp->id; 4359f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 4369f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 4379f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 438f75843a517bd188639e6866db2a7b04de3524e16Dave Airliestatic void brw_prepare_wm_prog(struct brw_context *brw) 4399f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt{ 4409f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt struct brw_wm_prog_key key; 4419f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt struct brw_fragment_program *fp = (struct brw_fragment_program *) 4429f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt brw->fragment_program; 443125bd4cae51c6deaacd2e90f14931c2052f146abEric Anholt 4449f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt brw_wm_populate_key(brw, &key); 4459f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 4469f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt /* Make an early check for the key. 4479f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt */ 44834474fa4119378ef9fbb9fb557cc19c0a1ca1f7eEric Anholt drm_intel_bo_unreference(brw->wm.prog_bo); 44938bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt brw->wm.prog_bo = brw_search_cache(&brw->cache, BRW_WM_PROG, 45038bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt &key, sizeof(key), 45138bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt NULL, 0, 45238bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt &brw->wm.prog_data); 45338bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt if (brw->wm.prog_bo == NULL) 45438bad7677e57d629eeffd4ef39a7fc254db12735Eric Anholt do_wm_prog(brw, fp, &key); 4559f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt} 4569f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 4579f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 4589f344b3e7d6e23674dd4747faec253f103563b36Eric Anholtconst struct brw_tracked_state brw_wm_prog = { 4599f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .dirty = { 4609f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .mesa = (_NEW_COLOR | 4619f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt _NEW_DEPTH | 46218af7c384cf663533f210d95d074c244d4214f29Brian Paul _NEW_HINT | 4639f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt _NEW_STENCIL | 4649f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt _NEW_POLYGON | 4659f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt _NEW_LINE | 4669f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt _NEW_LIGHT | 4679c8f27ba1366da07e20e86a0d48341ea97f5cda4Eric Anholt _NEW_BUFFERS | 4689f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt _NEW_TEXTURE), 4699f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt .brw = (BRW_NEW_FRAGMENT_PROGRAM | 4709f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt BRW_NEW_WM_INPUT_DIMENSIONS | 4719f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt BRW_NEW_REDUCED_PRIMITIVE), 4720f5113deed91611ecdda6596542530b1849bb161Eric Anholt .cache = CACHE_NEW_VS_PROG, 4739f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt }, 474008653ac55776d6b1c6d1627ad20937aa1c4dbdaDave Airlie .prepare = brw_prepare_wm_prog 4759f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt}; 4769f344b3e7d6e23674dd4747faec253f103563b36Eric Anholt 477