blob: 71118c1ca5987c50722849723e086f2dda842e96 [file] [log] [blame]
Eric Anholt9f344b32006-08-09 19:14:05 +00001/*
Ian Romanick2b81cef2015-06-10 17:09:16 -07002 * Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 * Intel funded Tungsten Graphics to
4 * develop this 3D driver.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
Eric Anholt9f344b32006-08-09 19:14:05 +000026#include "brw_context.h"
Eric Anholt9f344b32006-08-09 19:14:05 +000027#include "brw_wm.h"
28#include "brw_state.h"
Chris Forbescfa3c8a2013-08-11 09:55:30 +120029#include "main/enums.h"
Eric Anholtc3744872010-08-10 22:21:59 -070030#include "main/formats.h"
Brian Paul4433b032012-04-20 07:58:59 -060031#include "main/fbobject.h"
Eric Anholt1f32c662011-04-20 11:48:31 -070032#include "main/samplerobj.h"
Kevin Rogovin41b6db22015-06-17 13:29:55 +030033#include "main/framebuffer.h"
Eric Anholt87527642011-05-16 15:10:26 -070034#include "program/prog_parameter.h"
Anuj Phogat65d04522013-10-24 15:53:05 -070035#include "program/program.h"
Chris Forbes27359b82013-11-30 10:01:12 +130036#include "intel_mipmap_tree.h"
Kristian Høgsberg Kristensen654e9502016-05-01 21:22:54 -070037#include "intel_image.h"
Jason Ekstrand700bebb2017-02-28 09:10:43 -080038#include "compiler/brw_nir.h"
Matt Turnerecac1aa2015-11-22 15:30:59 -080039#include "brw_program.h"
Eric Anholt9f344b32006-08-09 19:14:05 +000040
Kenneth Graunke1e0da622014-02-24 23:39:14 -080041#include "util/ralloc.h"
Kenneth Graunke774fb902011-05-16 11:49:57 -070042
Jason Ekstrandea006c42015-10-01 08:55:20 -070043static void
Jason Ekstrand527f3712016-08-22 15:01:08 -070044assign_fs_binding_table_offsets(const struct gen_device_info *devinfo,
Jason Ekstrandea006c42015-10-01 08:55:20 -070045 const struct gl_program *prog,
46 const struct brw_wm_prog_key *key,
47 struct brw_wm_prog_data *prog_data)
48{
49 uint32_t next_binding_table_offset = 0;
50
51 /* If there are no color regions, we still perform an FB write to a null
52 * renderbuffer, which we place at surface index 0.
53 */
54 prog_data->binding_table.render_target_start = next_binding_table_offset;
55 next_binding_table_offset += MAX2(key->nr_color_regions, 1);
56
Francisco Jerez08705ba2016-07-01 13:46:40 -070057 next_binding_table_offset =
Timothy Arceri9ca14f52016-11-05 09:34:52 +110058 brw_assign_common_binding_table_offsets(devinfo, prog, &prog_data->base,
Francisco Jerez08705ba2016-07-01 13:46:40 -070059 next_binding_table_offset);
60
Jason Ekstrandb86dba82017-05-08 09:20:21 -070061 if (prog->nir->info.outputs_read && !key->coherent_fb_fetch) {
Francisco Jerez08705ba2016-07-01 13:46:40 -070062 prog_data->binding_table.render_target_read_start =
63 next_binding_table_offset;
64 next_binding_table_offset += key->nr_color_regions;
65 }
Jason Ekstrandea006c42015-10-01 08:55:20 -070066}
67
Timothy Arceri6f76ca32016-11-04 14:09:35 +110068static void
69brw_wm_debug_recompile(struct brw_context *brw, struct gl_program *prog,
70 const struct brw_wm_prog_key *key)
71{
Timothy Arceri6f76ca32016-11-04 14:09:35 +110072 perf_debug("Recompiling fragment shader for program %d\n", prog->Id);
73
Kenneth Graunkef9edc552016-11-11 13:31:06 -080074 bool found = false;
75 const struct brw_wm_prog_key *old_key =
76 brw_find_previous_compile(&brw->cache, BRW_CACHE_FS_PROG,
77 key->program_string_id);
Timothy Arceri6f76ca32016-11-04 14:09:35 +110078
Kenneth Graunkef9edc552016-11-11 13:31:06 -080079 if (!old_key) {
Timothy Arceri6f76ca32016-11-04 14:09:35 +110080 perf_debug(" Didn't find previous compile in the shader cache for debug\n");
81 return;
82 }
83
84 found |= key_debug(brw, "alphatest, computed depth, depth test, or "
85 "depth write",
86 old_key->iz_lookup, key->iz_lookup);
87 found |= key_debug(brw, "depth statistics",
88 old_key->stats_wm, key->stats_wm);
89 found |= key_debug(brw, "flat shading",
90 old_key->flat_shade, key->flat_shade);
91 found |= key_debug(brw, "per-sample interpolation",
92 old_key->persample_interp, key->persample_interp);
93 found |= key_debug(brw, "number of color buffers",
94 old_key->nr_color_regions, key->nr_color_regions);
95 found |= key_debug(brw, "MRT alpha test or alpha-to-coverage",
96 old_key->replicate_alpha, key->replicate_alpha);
97 found |= key_debug(brw, "fragment color clamping",
98 old_key->clamp_fragment_color, key->clamp_fragment_color);
99 found |= key_debug(brw, "multisampled FBO",
100 old_key->multisample_fbo, key->multisample_fbo);
101 found |= key_debug(brw, "line smoothing",
102 old_key->line_aa, key->line_aa);
103 found |= key_debug(brw, "input slots valid",
104 old_key->input_slots_valid, key->input_slots_valid);
105 found |= key_debug(brw, "mrt alpha test function",
106 old_key->alpha_test_func, key->alpha_test_func);
107 found |= key_debug(brw, "mrt alpha test reference value",
108 old_key->alpha_test_ref, key->alpha_test_ref);
Kenneth Graunke244c2a52017-06-14 01:52:04 -0700109 found |= key_debug(brw, "force dual color blending",
110 old_key->force_dual_color_blend,
111 key->force_dual_color_blend);
Timothy Arceri6f76ca32016-11-04 14:09:35 +1100112
113 found |= brw_debug_recompile_sampler_key(brw, &old_key->tex, &key->tex);
114
115 if (!found) {
116 perf_debug(" Something else\n");
117 }
118}
119
Brian Paul2f78d4a2009-02-12 15:35:41 -0700120/**
121 * All Mesa program -> GPU code generation goes through this function.
122 * Depending on the instructions used (i.e. flow control instructions)
123 * we'll use one of two code generators.
124 */
Timothy Arceri6e3f6092016-11-04 16:04:01 +1100125static bool
Jason Ekstranda85c4c92015-04-16 11:06:57 -0700126brw_codegen_wm_prog(struct brw_context *brw,
Timothy Arceri13d0cf52016-10-18 16:17:14 +1100127 struct brw_program *fp,
Timothy Arceri91d61fb2016-10-20 09:59:00 +1100128 struct brw_wm_prog_key *key,
129 struct brw_vue_map *vue_map)
Eric Anholt9f344b32006-08-09 19:14:05 +0000130{
Lionel Landwerlin94d0e7d2016-09-23 00:41:23 +0300131 const struct gen_device_info *devinfo = &brw->screen->devinfo;
Kenneth Graunke5a51a262014-01-18 14:48:11 -0800132 struct gl_context *ctx = &brw->ctx;
Kenneth Graunke2d4ac9b2014-05-14 01:21:02 -0700133 void *mem_ctx = ralloc_context(NULL);
Kenneth Graunke09b4f262014-05-14 01:35:30 -0700134 struct brw_wm_prog_data prog_data;
Eric Anholt9f344b32006-08-09 19:14:05 +0000135 const GLuint *program;
136 GLuint program_size;
Kristian Høgsberg Kristensena548c752015-09-04 17:09:40 -0700137 bool start_busy = false;
138 double start_time = 0;
Eric Anholt9f344b32006-08-09 19:14:05 +0000139
Kenneth Graunke09b4f262014-05-14 01:35:30 -0700140 memset(&prog_data, 0, sizeof(prog_data));
Francisco Jerez786e0852015-02-09 21:04:53 +0200141
Kenneth Graunke7b6620f2014-11-30 01:35:14 -0800142 /* Use ALT floating point mode for ARB programs so that 0^0 == 1. */
Timothy Arceri23848682016-11-09 23:44:39 +1100143 if (fp->program.is_arb_asm)
Kenneth Graunke7b6620f2014-11-30 01:35:14 -0800144 prog_data.base.use_alt_mode = true;
145
Timothy Arceri9ca14f52016-11-05 09:34:52 +1100146 assign_fs_binding_table_offsets(devinfo, &fp->program, key, &prog_data);
Jason Ekstrandea006c42015-10-01 08:55:20 -0700147
Eric Anholtf144b782012-08-26 21:19:05 -0700148 /* Allocate the references to the uniforms that will end up in the
149 * prog_data associated with the compiled program, and which will be freed
150 * by the state cache.
151 */
Timothy Arceri34234882016-10-19 13:23:37 +1100152 int param_count = fp->program.nir->num_uniforms / 4;
Timothy Arceriba40c8b2016-10-27 15:59:46 +1100153 prog_data.base.nr_image_params = fp->program.info.num_images;
Eric Anholta43b1072012-11-08 14:02:22 -0800154 /* The backend also sometimes adds params for texture size. */
Kenneth Graunke5a51a262014-01-18 14:48:11 -0800155 param_count += 2 * ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits;
Neil Roberts2c502122014-08-11 12:21:44 +0100156 prog_data.base.param =
157 rzalloc_array(NULL, const gl_constant_value *, param_count);
Kenneth Graunke09b4f262014-05-14 01:35:30 -0700158 prog_data.base.pull_param =
Neil Roberts2c502122014-08-11 12:21:44 +0100159 rzalloc_array(NULL, const gl_constant_value *, param_count);
Francisco Jerez87a3e022015-01-21 17:34:49 +0200160 prog_data.base.image_param =
161 rzalloc_array(NULL, struct brw_image_param,
162 prog_data.base.nr_image_params);
Kenneth Graunke09b4f262014-05-14 01:35:30 -0700163 prog_data.base.nr_params = param_count;
Eric Anholtf144b782012-08-26 21:19:05 -0700164
Timothy Arceri23848682016-11-09 23:44:39 +1100165 if (!fp->program.is_arb_asm) {
Timothy Arceri2a4d1692016-11-07 20:54:45 +1100166 brw_nir_setup_glsl_uniforms(fp->program.nir, &fp->program,
Jason Ekstrand30c63572015-09-30 17:01:03 -0700167 &prog_data.base, true);
168 } else {
Timothy Arceri34234882016-10-19 13:23:37 +1100169 brw_nir_setup_arb_uniforms(fp->program.nir, &fp->program,
Jason Ekstrand30c63572015-09-30 17:01:03 -0700170 &prog_data.base);
Timothy Arceric3b8bf92016-11-03 21:47:04 +1100171
172 if (unlikely(INTEL_DEBUG & DEBUG_WM))
173 brw_dump_arb_asm("fragment", &fp->program);
Jason Ekstrand30c63572015-09-30 17:01:03 -0700174 }
175
Kristian Høgsberg Kristensena548c752015-09-04 17:09:40 -0700176 if (unlikely(brw->perf_debug)) {
177 start_busy = (brw->batch.last_bo &&
Kenneth Graunked30a9272017-04-03 20:13:08 -0700178 brw_bo_busy(brw->batch.last_bo));
Kristian Høgsberg Kristensena548c752015-09-04 17:09:40 -0700179 start_time = get_time();
180 }
181
Kristian Høgsberg Kristensenee0f0102015-10-07 05:06:30 -0700182 int st_index8 = -1, st_index16 = -1;
183 if (INTEL_DEBUG & DEBUG_SHADER_TIME) {
Timothy Arceri6643da62016-12-20 21:37:23 +1100184 st_index8 = brw_get_shader_time_index(brw, &fp->program, ST_FS8,
Timothy Arceri23848682016-11-09 23:44:39 +1100185 !fp->program.is_arb_asm);
Timothy Arceri6643da62016-12-20 21:37:23 +1100186 st_index16 = brw_get_shader_time_index(brw, &fp->program, ST_FS16,
Timothy Arceri23848682016-11-09 23:44:39 +1100187 !fp->program.is_arb_asm);
Kristian Høgsberg Kristensenee0f0102015-10-07 05:06:30 -0700188 }
189
Jason Ekstrand22ad4492015-10-05 19:27:28 -0700190 char *error_str = NULL;
Kenneth Graunke9694b232015-11-30 15:47:13 -0800191 program = brw_compile_fs(brw->screen->compiler, brw, mem_ctx,
Timothy Arceri34234882016-10-19 13:23:37 +1100192 key, &prog_data, fp->program.nir,
193 &fp->program, st_index8, st_index16,
Jason Ekstrandea225d42017-06-03 15:20:32 -0700194 true, false, vue_map,
Jason Ekstrand265487a2016-05-16 14:30:25 -0700195 &program_size, &error_str);
Timothy Arceri91d61fb2016-10-20 09:59:00 +1100196
Kenneth Graunke81b11bf2014-05-14 01:04:02 -0700197 if (program == NULL) {
Timothy Arceri23848682016-11-09 23:44:39 +1100198 if (!fp->program.is_arb_asm) {
Timothy Arceria3fd8bb2017-02-04 10:46:53 +1100199 fp->program.sh.data->LinkStatus = linking_failure;
Timothy Arcerib8802812016-11-08 10:25:57 +1100200 ralloc_strcat(&fp->program.sh.data->InfoLog, error_str);
Jason Ekstrand22ad4492015-10-05 19:27:28 -0700201 }
202
203 _mesa_problem(NULL, "Failed to compile fragment shader: %s\n", error_str);
204
Kenneth Graunke2d4ac9b2014-05-14 01:21:02 -0700205 ralloc_free(mem_ctx);
Kenneth Graunke4d09fe92012-11-20 16:21:27 -0800206 return false;
Kenneth Graunke81b11bf2014-05-14 01:04:02 -0700207 }
Brian Paul2f78d4a2009-02-12 15:35:41 -0700208
Timothy Arceri718a0cf2016-11-04 13:37:21 +1100209 if (unlikely(brw->perf_debug)) {
210 if (fp->compiled_once)
Timothy Arceri6f76ca32016-11-04 14:09:35 +1100211 brw_wm_debug_recompile(brw, &fp->program, key);
Timothy Arceri718a0cf2016-11-04 13:37:21 +1100212 fp->compiled_once = true;
Kristian Høgsberg Kristensena548c752015-09-04 17:09:40 -0700213
Kenneth Graunked30a9272017-04-03 20:13:08 -0700214 if (start_busy && !brw_bo_busy(brw->batch.last_bo)) {
Kristian Høgsberg Kristensena548c752015-09-04 17:09:40 -0700215 perf_debug("FS compile took %.03f ms and stalled the GPU\n",
216 (get_time() - start_time) * 1000);
217 }
218 }
219
Francisco Jerezd9602842016-06-13 14:56:22 -0700220 brw_alloc_stage_scratch(brw, &brw->wm.base,
221 prog_data.base.total_scratch,
Lionel Landwerlin94d0e7d2016-09-23 00:41:23 +0300222 devinfo->max_wm_threads);
Eric Anholt4e725252010-10-21 15:07:45 -0700223
Timothy Arceri23848682016-11-09 23:44:39 +1100224 if (unlikely((INTEL_DEBUG & DEBUG_WM) && fp->program.is_arb_asm))
Eric Anholtfc3971d2009-01-08 19:15:04 -0800225 fprintf(stderr, "\n");
226
Kenneth Graunke67c49802014-09-26 11:38:06 -0700227 brw_upload_cache(&brw->cache, BRW_CACHE_FS_PROG,
Timothy Arceria38c8092016-10-05 15:42:02 +1100228 key, sizeof(struct brw_wm_prog_key),
229 program, program_size,
230 &prog_data, sizeof(prog_data),
231 &brw->wm.base.prog_offset, &brw->wm.base.prog_data);
Eric Anholt87527642011-05-16 15:10:26 -0700232
Kenneth Graunke2d4ac9b2014-05-14 01:21:02 -0700233 ralloc_free(mem_ctx);
Eric Anholt2fcaf4e2012-11-06 09:48:51 -0800234
Eric Anholt87527642011-05-16 15:10:26 -0700235 return true;
Eric Anholt9f344b32006-08-09 19:14:05 +0000236}
237
Eric Anholtfc3b7c92012-07-12 13:19:53 -0700238bool
Kenneth Graunkeca437572013-07-02 23:17:14 -0700239brw_debug_recompile_sampler_key(struct brw_context *brw,
Eric Anholt14cec072013-02-22 13:15:20 -0800240 const struct brw_sampler_prog_key_data *old_key,
Eric Anholtfc3b7c92012-07-12 13:19:53 -0700241 const struct brw_sampler_prog_key_data *key)
242{
243 bool found = false;
244
Kenneth Graunkef3d0daf2012-08-26 00:28:38 -0700245 for (unsigned int i = 0; i < MAX_SAMPLERS; i++) {
Kenneth Graunkeca437572013-07-02 23:17:14 -0700246 found |= key_debug(brw, "EXT_texture_swizzle or DEPTH_TEXTURE_MODE",
Kenneth Graunke98211d52012-08-15 16:35:35 -0700247 old_key->swizzles[i], key->swizzles[i]);
Eric Anholtfc3b7c92012-07-12 13:19:53 -0700248 }
Kenneth Graunkeca437572013-07-02 23:17:14 -0700249 found |= key_debug(brw, "GL_CLAMP enabled on any texture unit's 1st coordinate",
Kenneth Graunke98211d52012-08-15 16:35:35 -0700250 old_key->gl_clamp_mask[0], key->gl_clamp_mask[0]);
Kenneth Graunkeca437572013-07-02 23:17:14 -0700251 found |= key_debug(brw, "GL_CLAMP enabled on any texture unit's 2nd coordinate",
Kenneth Graunke98211d52012-08-15 16:35:35 -0700252 old_key->gl_clamp_mask[1], key->gl_clamp_mask[1]);
Kenneth Graunkeca437572013-07-02 23:17:14 -0700253 found |= key_debug(brw, "GL_CLAMP enabled on any texture unit's 3rd coordinate",
Kenneth Graunke98211d52012-08-15 16:35:35 -0700254 old_key->gl_clamp_mask[2], key->gl_clamp_mask[2]);
Chris Forbescfa3c8a2013-08-11 09:55:30 +1200255 found |= key_debug(brw, "gather channel quirk on any texture unit",
256 old_key->gather_channel_quirk_mask, key->gather_channel_quirk_mask);
Kenneth Graunke30c8d8a2015-04-23 23:17:10 -0700257 found |= key_debug(brw, "compressed multisample layout",
258 old_key->compressed_multisample_layout_mask,
259 key->compressed_multisample_layout_mask);
Neil Roberts1a97cac2015-09-15 16:34:35 +0100260 found |= key_debug(brw, "16x msaa",
261 old_key->msaa_16,
262 key->msaa_16);
Kenneth Graunke30c8d8a2015-04-23 23:17:10 -0700263
Kristian Høgsberg Kristensen654e9502016-05-01 21:22:54 -0700264 found |= key_debug(brw, "y_uv image bound",
265 old_key->y_uv_image_mask,
266 key->y_uv_image_mask);
267 found |= key_debug(brw, "y_u_v image bound",
268 old_key->y_u_v_image_mask,
269 key->y_u_v_image_mask);
270 found |= key_debug(brw, "yx_xuxv image bound",
271 old_key->yx_xuxv_image_mask,
272 key->yx_xuxv_image_mask);
Johnson Lin165e7042017-06-16 13:51:34 +0800273 found |= key_debug(brw, "xy_uxvx image bound",
274 old_key->xy_uxvx_image_mask,
275 key->xy_uxvx_image_mask);
276
Kristian Høgsberg Kristensen654e9502016-05-01 21:22:54 -0700277
Kenneth Graunke30c8d8a2015-04-23 23:17:10 -0700278 for (unsigned int i = 0; i < MAX_SAMPLERS; i++) {
279 found |= key_debug(brw, "textureGather workarounds",
280 old_key->gen6_gather_wa[i], key->gen6_gather_wa[i]);
281 }
Eric Anholtfc3b7c92012-07-12 13:19:53 -0700282
283 return found;
284}
285
Chris Forbes2b7bbd82014-02-03 22:13:03 +1300286static uint8_t
287gen6_gather_workaround(GLenum internalformat)
288{
289 switch (internalformat) {
Ian Romanick2b81cef2015-06-10 17:09:16 -0700290 case GL_R8I: return WA_SIGN | WA_8BIT;
291 case GL_R8UI: return WA_8BIT;
292 case GL_R16I: return WA_SIGN | WA_16BIT;
293 case GL_R16UI: return WA_16BIT;
294 default:
295 /* Note that even though GL_R32I and GL_R32UI have format overrides in
296 * the surface state, there is no shader w/a required.
297 */
298 return 0;
Chris Forbes2b7bbd82014-02-03 22:13:03 +1300299 }
300}
301
Kenneth Graunke1b05fc72011-12-06 15:36:21 -0800302void
303brw_populate_sampler_prog_key_data(struct gl_context *ctx,
Timothy Arceria38c8092016-10-05 15:42:02 +1100304 const struct gl_program *prog,
305 struct brw_sampler_prog_key_data *key)
Kenneth Graunke1b05fc72011-12-06 15:36:21 -0800306{
Kenneth Graunke794de2f2013-07-06 00:15:44 -0700307 struct brw_context *brw = brw_context(ctx);
Timothy Arceri8f1ca0e2016-07-05 17:02:46 +1000308 GLbitfield mask = prog->SamplersUsed;
Kenneth Graunke6d6aef72012-09-21 03:13:36 -0700309
Timothy Arceri8f1ca0e2016-07-05 17:02:46 +1000310 while (mask) {
311 const int s = u_bit_scan(&mask);
312
Kenneth Graunkef3d0daf2012-08-26 00:28:38 -0700313 key->swizzles[s] = SWIZZLE_NOOP;
Kenneth Graunke76d13012012-08-14 11:05:55 -0700314
Kenneth Graunkef3d0daf2012-08-26 00:28:38 -0700315 int unit_id = prog->SamplerUnits[s];
316 const struct gl_texture_unit *unit = &ctx->Texture.Unit[unit_id];
Kenneth Graunke1b05fc72011-12-06 15:36:21 -0800317
Eric Anholtff9c3e82014-04-23 17:14:26 -0700318 if (unit->_Current && unit->_Current->Target != GL_TEXTURE_BUFFER) {
Timothy Arceria38c8092016-10-05 15:42:02 +1100319 const struct gl_texture_object *t = unit->_Current;
320 const struct gl_texture_image *img = t->Image[0][t->BaseLevel];
321 struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit_id);
Kenneth Graunkefe911c12012-06-16 13:50:03 -0700322
Kenneth Graunke6d6aef72012-09-21 03:13:36 -0700323 const bool alpha_depth = t->DepthMode == GL_ALPHA &&
324 (img->_BaseFormat == GL_DEPTH_COMPONENT ||
325 img->_BaseFormat == GL_DEPTH_STENCIL);
326
327 /* Haswell handles texture swizzling as surface format overrides
328 * (except for GL_ALPHA); all other platforms need MOVs in the shader.
329 */
Kenneth Graunke57208322013-01-14 21:43:28 -0800330 if (alpha_depth || (brw->gen < 8 && !brw->is_haswell))
Kenneth Graunke9db20982013-01-23 15:27:39 -0800331 key->swizzles[s] = brw_get_texture_swizzle(ctx, t);
Kenneth Graunkefe911c12012-06-16 13:50:03 -0700332
Timothy Arceria38c8092016-10-05 15:42:02 +1100333 if (brw->gen < 8 &&
Kenneth Graunke22116962014-05-28 23:31:48 -0700334 sampler->MinFilter != GL_NEAREST &&
Timothy Arceria38c8092016-10-05 15:42:02 +1100335 sampler->MagFilter != GL_NEAREST) {
336 if (sampler->WrapS == GL_CLAMP)
337 key->gl_clamp_mask[0] |= 1 << s;
338 if (sampler->WrapT == GL_CLAMP)
339 key->gl_clamp_mask[1] |= 1 << s;
340 if (sampler->WrapR == GL_CLAMP)
341 key->gl_clamp_mask[2] |= 1 << s;
342 }
Chris Forbescfa3c8a2013-08-11 09:55:30 +1200343
Kenneth Graunke99c019e2017-01-05 02:51:38 -0800344 /* gather4 for RG32* is broken in multiple ways on Gen7. */
Jason Ekstrandb86dba82017-05-08 09:20:21 -0700345 if (brw->gen == 7 && prog->nir->info.uses_texture_gather) {
Kenneth Graunke99c019e2017-01-05 02:51:38 -0800346 switch (img->InternalFormat) {
347 case GL_RG32I:
348 case GL_RG32UI: {
349 /* We have to override the format to R32G32_FLOAT_LD.
350 * This means that SCS_ALPHA and SCS_ONE will return 0x3f8
351 * (1.0) rather than integer 1. This needs shader hacks.
352 *
353 * On Ivybridge, we whack W (alpha) to ONE in our key's
354 * swizzle. On Haswell, we look at the original texture
355 * swizzle, and use XYZW with channels overridden to ONE,
356 * leaving normal texture swizzling to SCS.
357 */
358 unsigned src_swizzle =
359 brw->is_haswell ? t->_Swizzle : key->swizzles[s];
360 for (int i = 0; i < 4; i++) {
361 unsigned src_comp = GET_SWZ(src_swizzle, i);
362 if (src_comp == SWIZZLE_ONE || src_comp == SWIZZLE_W) {
363 key->swizzles[i] &= ~(0x7 << (3 * i));
364 key->swizzles[i] |= SWIZZLE_ONE << (3 * i);
365 }
366 }
367 /* fallthrough */
368 }
369 case GL_RG32F:
370 /* The channel select for green doesn't work - we have to
371 * request blue. Haswell can use SCS for this, but Ivybridge
372 * needs a shader workaround.
373 */
374 if (!brw->is_haswell)
375 key->gather_channel_quirk_mask |= 1 << s;
376 break;
377 }
Chris Forbescfa3c8a2013-08-11 09:55:30 +1200378 }
Chris Forbes27359b82013-11-30 10:01:12 +1300379
Chris Forbes2b7bbd82014-02-03 22:13:03 +1300380 /* Gen6's gather4 is broken for UINT/SINT; we treat them as
381 * UNORM/FLOAT instead and fix it in the shader.
382 */
Jason Ekstrandb86dba82017-05-08 09:20:21 -0700383 if (brw->gen == 6 && prog->nir->info.uses_texture_gather) {
Chris Forbes2b7bbd82014-02-03 22:13:03 +1300384 key->gen6_gather_wa[s] = gen6_gather_workaround(img->InternalFormat);
385 }
386
Chris Forbes27359b82013-11-30 10:01:12 +1300387 /* If this is a multisample sampler, and uses the CMS MSAA layout,
388 * then we need to emit slightly different code to first sample the
389 * MCS surface.
390 */
391 struct intel_texture_object *intel_tex =
392 intel_texture_object((struct gl_texture_object *)t);
393
Topi Pohjolainencda8c2a2016-04-18 21:47:23 +0300394 /* From gen9 onwards some single sampled buffers can also be
395 * compressed. These don't need ld2dms sampling along with mcs fetch.
396 */
Chris Forbes27359b82013-11-30 10:01:12 +1300397 if (brw->gen >= 7 &&
Topi Pohjolainencda8c2a2016-04-18 21:47:23 +0300398 intel_tex->mt->msaa_layout == INTEL_MSAA_LAYOUT_CMS &&
399 intel_tex->mt->num_samples > 1) {
Chris Forbes27359b82013-11-30 10:01:12 +1300400 key->compressed_multisample_layout_mask |= 1 << s;
Neil Roberts1a97cac2015-09-15 16:34:35 +0100401
402 if (intel_tex->mt->num_samples >= 16) {
403 assert(brw->gen >= 9);
404 key->msaa_16 |= 1 << s;
405 }
Chris Forbes27359b82013-11-30 10:01:12 +1300406 }
Kristian Høgsberg Kristensen654e9502016-05-01 21:22:54 -0700407
408 if (t->Target == GL_TEXTURE_EXTERNAL_OES && intel_tex->planar_format) {
409 switch (intel_tex->planar_format->components) {
410 case __DRI_IMAGE_COMPONENTS_Y_UV:
411 key->y_uv_image_mask |= 1 << s;
412 break;
413 case __DRI_IMAGE_COMPONENTS_Y_U_V:
414 key->y_u_v_image_mask |= 1 << s;
415 break;
416 case __DRI_IMAGE_COMPONENTS_Y_XUXV:
417 key->yx_xuxv_image_mask |= 1 << s;
418 break;
Johnson Lin165e7042017-06-16 13:51:34 +0800419 case __DRI_IMAGE_COMPONENTS_Y_UXVX:
420 key->xy_uxvx_image_mask |= 1 << s;
421 break;
Kristian Høgsberg Kristensen654e9502016-05-01 21:22:54 -0700422 default:
423 break;
424 }
425 }
426
Kenneth Graunke1b05fc72011-12-06 15:36:21 -0800427 }
Kenneth Graunke1b05fc72011-12-06 15:36:21 -0800428 }
429}
Eric Anholt9f344b32006-08-09 19:14:05 +0000430
Carl Wortha57672f2015-03-20 12:01:33 -0700431static bool
Kenneth Graunkeb23b0992016-04-27 11:26:08 -0700432brw_wm_state_dirty(const struct brw_context *brw)
Carl Wortha57672f2015-03-20 12:01:33 -0700433{
434 return brw_state_dirty(brw,
435 _NEW_BUFFERS |
436 _NEW_COLOR |
437 _NEW_DEPTH |
438 _NEW_FRAG_CLAMP |
439 _NEW_HINT |
440 _NEW_LIGHT |
441 _NEW_LINE |
442 _NEW_MULTISAMPLE |
443 _NEW_POLYGON |
444 _NEW_STENCIL |
445 _NEW_TEXTURE,
446 BRW_NEW_FRAGMENT_PROGRAM |
447 BRW_NEW_REDUCED_PRIMITIVE |
448 BRW_NEW_STATS_WM |
449 BRW_NEW_VUE_MAP_GEOM_OUT);
450}
451
Carl Worth017081a2016-04-14 10:54:38 +1000452void
Ian Romanick2b81cef2015-06-10 17:09:16 -0700453brw_wm_populate_key(struct brw_context *brw, struct brw_wm_prog_key *key)
Eric Anholt9f344b32006-08-09 19:14:05 +0000454{
Kenneth Graunke8c9a54e2013-07-06 00:46:38 -0700455 struct gl_context *ctx = &brw->ctx;
Eric Anholt9f344b32006-08-09 19:14:05 +0000456 /* BRW_NEW_FRAGMENT_PROGRAM */
Timothy Arceri13d0cf52016-10-18 16:17:14 +1100457 const struct brw_program *fp = brw_program_const(brw->fragment_program);
Kenneth Graunke387a3d42011-12-08 12:15:59 -0800458 const struct gl_program *prog = (struct gl_program *) brw->fragment_program;
Eric Anholt9f344b32006-08-09 19:14:05 +0000459 GLuint lookup = 0;
460 GLuint line_aa;
Paul Berry82d25962012-06-20 13:40:45 -0700461
Eric Anholt9f344b32006-08-09 19:14:05 +0000462 memset(key, 0, sizeof(*key));
463
464 /* Build the index for table lookup
465 */
Kenneth Graunke53631be2013-07-06 00:36:46 -0700466 if (brw->gen < 6) {
Kenneth Graunke86e401b2012-07-12 11:25:58 -0700467 /* _NEW_COLOR */
Timothy Arceri17e28a12016-10-19 13:45:18 +1100468 if (prog->info.fs.uses_discard || ctx->Color.AlphaEnabled) {
Jason Ekstrand81234022017-02-28 16:33:49 -0800469 lookup |= BRW_WM_IZ_PS_KILL_ALPHATEST_BIT;
Timothy Arceri556335e2016-10-05 15:13:23 +1100470 }
Eric Anholt9f344b32006-08-09 19:14:05 +0000471
Timothy Arceri17e28a12016-10-19 13:45:18 +1100472 if (prog->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) {
Jason Ekstrand81234022017-02-28 16:33:49 -0800473 lookup |= BRW_WM_IZ_PS_COMPUTES_DEPTH_BIT;
Timothy Arceri7ef82862016-10-05 16:24:56 +1100474 }
Eric Anholt9f344b32006-08-09 19:14:05 +0000475
Kenneth Graunke2f8351a2012-06-16 16:34:50 -0700476 /* _NEW_DEPTH */
477 if (ctx->Depth.Test)
Jason Ekstrand81234022017-02-28 16:33:49 -0800478 lookup |= BRW_WM_IZ_DEPTH_TEST_ENABLE_BIT;
Eric Anholt9f344b32006-08-09 19:14:05 +0000479
Kenneth Graunkeff0253a2016-11-16 18:29:22 -0800480 if (brw_depth_writes_enabled(brw))
Jason Ekstrand81234022017-02-28 16:33:49 -0800481 lookup |= BRW_WM_IZ_DEPTH_WRITE_ENABLE_BIT;
Eric Anholt9f344b32006-08-09 19:14:05 +0000482
Eric Anholt94ecf912013-06-20 09:08:30 -0700483 /* _NEW_STENCIL | _NEW_BUFFERS */
Marek Olšákc2408832017-06-09 20:37:34 +0200484 if (brw->stencil_enabled) {
Jason Ekstrand81234022017-02-28 16:33:49 -0800485 lookup |= BRW_WM_IZ_STENCIL_TEST_ENABLE_BIT;
Kenneth Graunke2f8351a2012-06-16 16:34:50 -0700486
Timothy Arceria38c8092016-10-05 15:42:02 +1100487 if (ctx->Stencil.WriteMask[0] ||
488 ctx->Stencil.WriteMask[ctx->Stencil._BackFace])
Jason Ekstrand81234022017-02-28 16:33:49 -0800489 lookup |= BRW_WM_IZ_STENCIL_WRITE_ENABLE_BIT;
Kenneth Graunke2f8351a2012-06-16 16:34:50 -0700490 }
491 key->iz_lookup = lookup;
Eric Anholt9f344b32006-08-09 19:14:05 +0000492 }
493
Jason Ekstrand81234022017-02-28 16:33:49 -0800494 line_aa = BRW_WM_AA_NEVER;
Eric Anholt9f344b32006-08-09 19:14:05 +0000495
496 /* _NEW_LINE, _NEW_POLYGON, BRW_NEW_REDUCED_PRIMITIVE */
Eric Anholt052c1d62009-01-30 14:32:23 -0800497 if (ctx->Line.SmoothFlag) {
Kenneth Graunkefe0a8cb2013-07-03 11:55:59 -0700498 if (brw->reduced_primitive == GL_LINES) {
Jason Ekstrand81234022017-02-28 16:33:49 -0800499 line_aa = BRW_WM_AA_ALWAYS;
Eric Anholt9f344b32006-08-09 19:14:05 +0000500 }
Kenneth Graunkefe0a8cb2013-07-03 11:55:59 -0700501 else if (brw->reduced_primitive == GL_TRIANGLES) {
Timothy Arceria38c8092016-10-05 15:42:02 +1100502 if (ctx->Polygon.FrontMode == GL_LINE) {
Jason Ekstrand81234022017-02-28 16:33:49 -0800503 line_aa = BRW_WM_AA_SOMETIMES;
Eric Anholt9f344b32006-08-09 19:14:05 +0000504
Timothy Arceria38c8092016-10-05 15:42:02 +1100505 if (ctx->Polygon.BackMode == GL_LINE ||
506 (ctx->Polygon.CullFlag &&
507 ctx->Polygon.CullFaceMode == GL_BACK))
Jason Ekstrand81234022017-02-28 16:33:49 -0800508 line_aa = BRW_WM_AA_ALWAYS;
Timothy Arceria38c8092016-10-05 15:42:02 +1100509 }
510 else if (ctx->Polygon.BackMode == GL_LINE) {
Jason Ekstrand81234022017-02-28 16:33:49 -0800511 line_aa = BRW_WM_AA_SOMETIMES;
Eric Anholt9f344b32006-08-09 19:14:05 +0000512
Timothy Arceria38c8092016-10-05 15:42:02 +1100513 if ((ctx->Polygon.CullFlag &&
514 ctx->Polygon.CullFaceMode == GL_FRONT))
Jason Ekstrand81234022017-02-28 16:33:49 -0800515 line_aa = BRW_WM_AA_ALWAYS;
Timothy Arceria38c8092016-10-05 15:42:02 +1100516 }
Eric Anholt9f344b32006-08-09 19:14:05 +0000517 }
518 }
Eric Anholt9f344b32006-08-09 19:14:05 +0000519
Eric Anholt16f8c822010-11-11 09:30:16 -0800520 key->line_aa = line_aa;
Kenneth Graunke6cc14c22012-08-26 00:47:44 -0700521
Chia-I Wu848c0e72013-09-12 13:00:52 +0800522 /* _NEW_HINT */
Kenneth Graunke2a4f5722014-11-30 21:58:03 -0800523 key->high_quality_derivatives =
524 ctx->Hint.FragmentShaderDerivative == GL_NICEST;
Chia-I Wu848c0e72013-09-12 13:00:52 +0800525
Kenneth Graunke53631be2013-07-06 00:36:46 -0700526 if (brw->gen < 6)
Kenneth Graunkeec995de2013-07-03 14:26:01 -0700527 key->stats_wm = brw->stats_wm;
Eric Anholt9f344b32006-08-09 19:14:05 +0000528
Eric Anholt9f344b32006-08-09 19:14:05 +0000529 /* _NEW_LIGHT */
Eric Anholt052c1d62009-01-30 14:32:23 -0800530 key->flat_shade = (ctx->Light.ShadeModel == GL_FLAT);
Eric Anholt9f344b32006-08-09 19:14:05 +0000531
Eric Anholtd22e2eb2011-04-15 14:40:09 -0700532 /* _NEW_FRAG_CLAMP | _NEW_BUFFERS */
533 key->clamp_fragment_color = ctx->Color._ClampFragmentColor;
534
Eric Anholt9f344b32006-08-09 19:14:05 +0000535 /* _NEW_TEXTURE */
Timothy Arceri8f1ca0e2016-07-05 17:02:46 +1000536 brw_populate_sampler_prog_key_data(ctx, prog, &key->tex);
Eric Anholt9c8f27b2008-02-28 13:18:12 -0800537
538 /* _NEW_BUFFERS */
Eric Anholt1b806222011-01-30 21:13:17 -0800539 key->nr_color_regions = ctx->DrawBuffer->_NumColorDrawBuffers;
Chris Forbes1415a182013-07-01 23:30:55 +1200540
Kenneth Graunkeb3340cd2016-01-20 17:33:14 -0800541 /* _NEW_COLOR */
542 key->force_dual_color_blend = brw->dual_color_blend_by_location &&
543 (ctx->Color.BlendEnabled & 1) && ctx->Color.Blend[0]._UsesDualSrc;
544
Chris Forbes1415a182013-07-01 23:30:55 +1200545 /* _NEW_MULTISAMPLE, _NEW_COLOR, _NEW_BUFFERS */
546 key->replicate_alpha = ctx->DrawBuffer->_NumColorDrawBuffers > 1 &&
Anuj Phogat329ae922016-10-20 11:40:40 -0700547 (_mesa_is_alpha_test_enabled(ctx) ||
548 _mesa_is_alpha_to_coverage_enabled(ctx));
Brian Paul9ef33b82009-10-29 14:53:53 -0600549
Anuj Phogat65d04522013-10-24 15:53:05 -0700550 /* _NEW_BUFFERS _NEW_MULTISAMPLE */
Anuj Phogata92e5f72014-01-06 13:59:18 -0800551 /* Ignore sample qualifier while computing this flag. */
Jason Ekstrand712a9802016-05-09 17:48:24 -0700552 if (ctx->Multisample.Enabled) {
553 key->persample_interp =
554 ctx->Multisample.SampleShading &&
555 (ctx->Multisample.MinSampleShadingValue *
556 _mesa_geometric_samples(ctx->DrawBuffer) > 1);
Anuj Phogata92e5f72014-01-06 13:59:18 -0800557
Jason Ekstrand712a9802016-05-09 17:48:24 -0700558 key->multisample_fbo = _mesa_geometric_samples(ctx->DrawBuffer) > 1;
559 }
Anuj Phogate12bbb52013-10-24 16:17:08 -0700560
Paul Berrybf9bfe82013-03-17 11:29:28 -0700561 /* BRW_NEW_VUE_MAP_GEOM_OUT */
Timothy Arceri17e28a12016-10-19 13:45:18 +1100562 if (brw->gen < 6 || _mesa_bitcount_64(prog->info.inputs_read &
563 BRW_FS_VARYING_INPUT_MASK) > 16) {
Paul Berry0a0deb92013-03-20 10:15:52 -0700564 key->input_slots_valid = brw->vue_map_geom_out.slots_valid;
Timothy Arceri7627fbd2016-10-05 16:45:27 +1100565 }
Eric Anholt0f5113d2009-05-14 09:49:45 -0700566
Chris Forbes1080fc62013-10-27 12:09:51 +1300567 /* _NEW_COLOR | _NEW_BUFFERS */
568 /* Pre-gen6, the hardware alpha test always used each render
569 * target's alpha to do alpha test, as opposed to render target 0's alpha
570 * like GL requires. Fix that by building the alpha test into the
571 * shader, and we'll skip enabling the fixed function alpha test.
572 */
Ian Romanick2b81cef2015-06-10 17:09:16 -0700573 if (brw->gen < 6 && ctx->DrawBuffer->_NumColorDrawBuffers > 1 &&
574 ctx->Color.AlphaEnabled) {
Chris Forbes1080fc62013-10-27 12:09:51 +1300575 key->alpha_test_func = ctx->Color.AlphaFunc;
576 key->alpha_test_ref = ctx->Color.AlphaRef;
577 }
578
Brian Paul55d33e12009-02-20 10:49:30 -0700579 /* The unique fragment program ID */
Eric Anholt9f344b32006-08-09 19:14:05 +0000580 key->program_string_id = fp->id;
Francisco Jerez40b23ad2016-07-21 20:32:12 -0700581
582 /* Whether reads from the framebuffer should behave coherently. */
583 key->coherent_fb_fetch = ctx->Extensions.MESA_shader_framebuffer_fetch;
Eric Anholt9f344b32006-08-09 19:14:05 +0000584}
585
Carl Worth4a6c6c42015-02-11 13:53:31 -0800586void
Eric Anholtdc9a7532011-10-22 11:33:54 -0700587brw_upload_wm_prog(struct brw_context *brw)
Eric Anholt9f344b32006-08-09 19:14:05 +0000588{
589 struct brw_wm_prog_key key;
Timothy Arceri13d0cf52016-10-18 16:17:14 +1100590 struct brw_program *fp = (struct brw_program *) brw->fragment_program;
Eric Anholt662f1b42011-03-11 19:19:01 -0800591
Carl Wortha57672f2015-03-20 12:01:33 -0700592 if (!brw_wm_state_dirty(brw))
Carl Worth4a6c6c42015-02-11 13:53:31 -0800593 return;
594
Eric Anholt9f344b32006-08-09 19:14:05 +0000595 brw_wm_populate_key(brw, &key);
596
Kenneth Graunke67c49802014-09-26 11:38:06 -0700597 if (!brw_search_cache(&brw->cache, BRW_CACHE_FS_PROG,
Timothy Arceria38c8092016-10-05 15:42:02 +1100598 &key, sizeof(key),
599 &brw->wm.base.prog_offset,
Kenneth Graunke16d55362016-09-08 23:48:53 -0700600 &brw->wm.base.prog_data)) {
Timothy Arceri6e3f6092016-11-04 16:04:01 +1100601 bool success = brw_codegen_wm_prog(brw, fp, &key,
Timothy Arceri91d61fb2016-10-20 09:59:00 +1100602 &brw->vue_map_geom_out);
Brian Paul41702272011-10-07 10:38:30 -0600603 (void) success;
Eric Anholt87527642011-05-16 15:10:26 -0700604 assert(success);
605 }
Eric Anholt9f344b32006-08-09 19:14:05 +0000606}
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700607
608bool
Timothy Arceri6e3f6092016-11-04 16:04:01 +1100609brw_fs_precompile(struct gl_context *ctx, struct gl_program *prog)
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700610{
611 struct brw_context *brw = brw_context(ctx);
612 struct brw_wm_prog_key key;
613
Timothy Arceri13d0cf52016-10-18 16:17:14 +1100614 struct brw_program *bfp = brw_program(prog);
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700615
616 memset(&key, 0, sizeof(key));
617
Timothy Arceri17e28a12016-10-19 13:45:18 +1100618 uint64_t outputs_written = prog->info.outputs_written;
Timothy Arceri7ef82862016-10-05 16:24:56 +1100619
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700620 if (brw->gen < 6) {
Timothy Arceri17e28a12016-10-19 13:45:18 +1100621 if (prog->info.fs.uses_discard)
Jason Ekstrand81234022017-02-28 16:33:49 -0800622 key.iz_lookup |= BRW_WM_IZ_PS_KILL_ALPHATEST_BIT;
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700623
Timothy Arceri7ef82862016-10-05 16:24:56 +1100624 if (outputs_written & BITFIELD64_BIT(FRAG_RESULT_DEPTH))
Jason Ekstrand81234022017-02-28 16:33:49 -0800625 key.iz_lookup |= BRW_WM_IZ_PS_COMPUTES_DEPTH_BIT;
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700626
627 /* Just assume depth testing. */
Jason Ekstrand81234022017-02-28 16:33:49 -0800628 key.iz_lookup |= BRW_WM_IZ_DEPTH_TEST_ENABLE_BIT;
629 key.iz_lookup |= BRW_WM_IZ_DEPTH_WRITE_ENABLE_BIT;
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700630 }
631
Timothy Arceri17e28a12016-10-19 13:45:18 +1100632 if (brw->gen < 6 || _mesa_bitcount_64(prog->info.inputs_read &
Timothy Arceri7627fbd2016-10-05 16:45:27 +1100633 BRW_FS_VARYING_INPUT_MASK) > 16) {
Timothy Arceri17e28a12016-10-19 13:45:18 +1100634 key.input_slots_valid = prog->info.inputs_read | VARYING_BIT_POS;
Timothy Arceri7627fbd2016-10-05 16:45:27 +1100635 }
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700636
Timothy Arceri34234882016-10-19 13:23:37 +1100637 brw_setup_tex_for_precompile(brw, &key.tex, prog);
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700638
Timothy Arceri7ef82862016-10-05 16:24:56 +1100639 key.nr_color_regions = _mesa_bitcount_64(outputs_written &
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700640 ~(BITFIELD64_BIT(FRAG_RESULT_DEPTH) |
Francisco Jerezc8f5bd22016-08-22 18:50:41 -0700641 BITFIELD64_BIT(FRAG_RESULT_STENCIL) |
642 BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK)));
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700643
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700644 key.program_string_id = bfp->id;
645
Francisco Jerez40b23ad2016-07-21 20:32:12 -0700646 /* Whether reads from the framebuffer should behave coherently. */
647 key.coherent_fb_fetch = ctx->Extensions.MESA_shader_framebuffer_fetch;
648
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700649 uint32_t old_prog_offset = brw->wm.base.prog_offset;
Kenneth Graunke16d55362016-09-08 23:48:53 -0700650 struct brw_stage_prog_data *old_prog_data = brw->wm.base.prog_data;
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700651
Timothy Arceri91d61fb2016-10-20 09:59:00 +1100652 struct brw_vue_map vue_map;
653 if (brw->gen < 6) {
654 brw_compute_vue_map(&brw->screen->devinfo, &vue_map,
Timothy Arceri17e28a12016-10-19 13:45:18 +1100655 prog->info.inputs_read | VARYING_BIT_POS,
Timothy Arceri91d61fb2016-10-20 09:59:00 +1100656 false);
657 }
658
Timothy Arceri6e3f6092016-11-04 16:04:01 +1100659 bool success = brw_codegen_wm_prog(brw, bfp, &key, &vue_map);
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700660
661 brw->wm.base.prog_offset = old_prog_offset;
Kenneth Graunke16d55362016-09-08 23:48:53 -0700662 brw->wm.base.prog_data = old_prog_data;
Kristian Høgsberg Kristensen84f2ed22015-09-04 16:55:03 -0700663
664 return success;
665}