Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 1 | /* |
Ian Romanick | 2b81cef | 2015-06-10 17:09:16 -0700 | [diff] [blame] | 2 | * 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 Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 26 | #include "brw_context.h" |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 27 | #include "brw_wm.h" |
| 28 | #include "brw_state.h" |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 29 | #include "brw_shader.h" |
Chris Forbes | cfa3c8a | 2013-08-11 09:55:30 +1200 | [diff] [blame] | 30 | #include "main/enums.h" |
Eric Anholt | c374487 | 2010-08-10 22:21:59 -0700 | [diff] [blame] | 31 | #include "main/formats.h" |
Brian Paul | 4433b03 | 2012-04-20 07:58:59 -0600 | [diff] [blame] | 32 | #include "main/fbobject.h" |
Eric Anholt | 1f32c66 | 2011-04-20 11:48:31 -0700 | [diff] [blame] | 33 | #include "main/samplerobj.h" |
Kevin Rogovin | 41b6db2 | 2015-06-17 13:29:55 +0300 | [diff] [blame] | 34 | #include "main/framebuffer.h" |
Eric Anholt | 8752764 | 2011-05-16 15:10:26 -0700 | [diff] [blame] | 35 | #include "program/prog_parameter.h" |
Anuj Phogat | 65d0452 | 2013-10-24 15:53:05 -0700 | [diff] [blame] | 36 | #include "program/program.h" |
Chris Forbes | 27359b8 | 2013-11-30 10:01:12 +1300 | [diff] [blame] | 37 | #include "intel_mipmap_tree.h" |
Kristian Høgsberg Kristensen | 654e950 | 2016-05-01 21:22:54 -0700 | [diff] [blame] | 38 | #include "intel_image.h" |
Jason Ekstrand | 30c6357 | 2015-09-30 17:01:03 -0700 | [diff] [blame] | 39 | #include "brw_nir.h" |
Matt Turner | ecac1aa | 2015-11-22 15:30:59 -0800 | [diff] [blame] | 40 | #include "brw_program.h" |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 41 | |
Kenneth Graunke | 1e0da62 | 2014-02-24 23:39:14 -0800 | [diff] [blame] | 42 | #include "util/ralloc.h" |
Kenneth Graunke | 774fb90 | 2011-05-16 11:49:57 -0700 | [diff] [blame] | 43 | |
Jason Ekstrand | ea006c4 | 2015-10-01 08:55:20 -0700 | [diff] [blame] | 44 | static void |
Jason Ekstrand | 527f371 | 2016-08-22 15:01:08 -0700 | [diff] [blame] | 45 | assign_fs_binding_table_offsets(const struct gen_device_info *devinfo, |
Jason Ekstrand | ea006c4 | 2015-10-01 08:55:20 -0700 | [diff] [blame] | 46 | const struct gl_program *prog, |
| 47 | const struct brw_wm_prog_key *key, |
| 48 | struct brw_wm_prog_data *prog_data) |
| 49 | { |
| 50 | uint32_t next_binding_table_offset = 0; |
| 51 | |
| 52 | /* If there are no color regions, we still perform an FB write to a null |
| 53 | * renderbuffer, which we place at surface index 0. |
| 54 | */ |
| 55 | prog_data->binding_table.render_target_start = next_binding_table_offset; |
| 56 | next_binding_table_offset += MAX2(key->nr_color_regions, 1); |
| 57 | |
Francisco Jerez | 08705ba | 2016-07-01 13:46:40 -0700 | [diff] [blame] | 58 | next_binding_table_offset = |
Timothy Arceri | 9ca14f5 | 2016-11-05 09:34:52 +1100 | [diff] [blame] | 59 | brw_assign_common_binding_table_offsets(devinfo, prog, &prog_data->base, |
Francisco Jerez | 08705ba | 2016-07-01 13:46:40 -0700 | [diff] [blame] | 60 | next_binding_table_offset); |
| 61 | |
Timothy Arceri | e1af20f | 2016-10-13 11:41:23 +1100 | [diff] [blame] | 62 | if (prog->nir->info->outputs_read && !key->coherent_fb_fetch) { |
Francisco Jerez | 08705ba | 2016-07-01 13:46:40 -0700 | [diff] [blame] | 63 | prog_data->binding_table.render_target_read_start = |
| 64 | next_binding_table_offset; |
| 65 | next_binding_table_offset += key->nr_color_regions; |
| 66 | } |
Jason Ekstrand | ea006c4 | 2015-10-01 08:55:20 -0700 | [diff] [blame] | 67 | } |
| 68 | |
Timothy Arceri | 6f76ca3 | 2016-11-04 14:09:35 +1100 | [diff] [blame] | 69 | static void |
| 70 | brw_wm_debug_recompile(struct brw_context *brw, struct gl_program *prog, |
| 71 | const struct brw_wm_prog_key *key) |
| 72 | { |
Timothy Arceri | 6f76ca3 | 2016-11-04 14:09:35 +1100 | [diff] [blame] | 73 | perf_debug("Recompiling fragment shader for program %d\n", prog->Id); |
| 74 | |
Kenneth Graunke | f9edc55 | 2016-11-11 13:31:06 -0800 | [diff] [blame] | 75 | bool found = false; |
| 76 | const struct brw_wm_prog_key *old_key = |
| 77 | brw_find_previous_compile(&brw->cache, BRW_CACHE_FS_PROG, |
| 78 | key->program_string_id); |
Timothy Arceri | 6f76ca3 | 2016-11-04 14:09:35 +1100 | [diff] [blame] | 79 | |
Kenneth Graunke | f9edc55 | 2016-11-11 13:31:06 -0800 | [diff] [blame] | 80 | if (!old_key) { |
Timothy Arceri | 6f76ca3 | 2016-11-04 14:09:35 +1100 | [diff] [blame] | 81 | perf_debug(" Didn't find previous compile in the shader cache for debug\n"); |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | found |= key_debug(brw, "alphatest, computed depth, depth test, or " |
| 86 | "depth write", |
| 87 | old_key->iz_lookup, key->iz_lookup); |
| 88 | found |= key_debug(brw, "depth statistics", |
| 89 | old_key->stats_wm, key->stats_wm); |
| 90 | found |= key_debug(brw, "flat shading", |
| 91 | old_key->flat_shade, key->flat_shade); |
| 92 | found |= key_debug(brw, "per-sample interpolation", |
| 93 | old_key->persample_interp, key->persample_interp); |
| 94 | found |= key_debug(brw, "number of color buffers", |
| 95 | old_key->nr_color_regions, key->nr_color_regions); |
| 96 | found |= key_debug(brw, "MRT alpha test or alpha-to-coverage", |
| 97 | old_key->replicate_alpha, key->replicate_alpha); |
| 98 | found |= key_debug(brw, "fragment color clamping", |
| 99 | old_key->clamp_fragment_color, key->clamp_fragment_color); |
| 100 | found |= key_debug(brw, "multisampled FBO", |
| 101 | old_key->multisample_fbo, key->multisample_fbo); |
| 102 | found |= key_debug(brw, "line smoothing", |
| 103 | old_key->line_aa, key->line_aa); |
| 104 | found |= key_debug(brw, "input slots valid", |
| 105 | old_key->input_slots_valid, key->input_slots_valid); |
| 106 | found |= key_debug(brw, "mrt alpha test function", |
| 107 | old_key->alpha_test_func, key->alpha_test_func); |
| 108 | found |= key_debug(brw, "mrt alpha test reference value", |
| 109 | old_key->alpha_test_ref, key->alpha_test_ref); |
| 110 | |
| 111 | found |= brw_debug_recompile_sampler_key(brw, &old_key->tex, &key->tex); |
| 112 | |
| 113 | if (!found) { |
| 114 | perf_debug(" Something else\n"); |
| 115 | } |
| 116 | } |
| 117 | |
Brian Paul | 2f78d4a | 2009-02-12 15:35:41 -0700 | [diff] [blame] | 118 | /** |
| 119 | * All Mesa program -> GPU code generation goes through this function. |
| 120 | * Depending on the instructions used (i.e. flow control instructions) |
| 121 | * we'll use one of two code generators. |
| 122 | */ |
Timothy Arceri | 6e3f609 | 2016-11-04 16:04:01 +1100 | [diff] [blame] | 123 | static bool |
Jason Ekstrand | a85c4c9 | 2015-04-16 11:06:57 -0700 | [diff] [blame] | 124 | brw_codegen_wm_prog(struct brw_context *brw, |
Timothy Arceri | 13d0cf5 | 2016-10-18 16:17:14 +1100 | [diff] [blame] | 125 | struct brw_program *fp, |
Timothy Arceri | 91d61fb | 2016-10-20 09:59:00 +1100 | [diff] [blame] | 126 | struct brw_wm_prog_key *key, |
| 127 | struct brw_vue_map *vue_map) |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 128 | { |
Lionel Landwerlin | 94d0e7d | 2016-09-23 00:41:23 +0300 | [diff] [blame] | 129 | const struct gen_device_info *devinfo = &brw->screen->devinfo; |
Kenneth Graunke | 5a51a26 | 2014-01-18 14:48:11 -0800 | [diff] [blame] | 130 | struct gl_context *ctx = &brw->ctx; |
Kenneth Graunke | 2d4ac9b | 2014-05-14 01:21:02 -0700 | [diff] [blame] | 131 | void *mem_ctx = ralloc_context(NULL); |
Kenneth Graunke | 09b4f26 | 2014-05-14 01:35:30 -0700 | [diff] [blame] | 132 | struct brw_wm_prog_data prog_data; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 133 | const GLuint *program; |
| 134 | GLuint program_size; |
Kristian Høgsberg Kristensen | a548c75 | 2015-09-04 17:09:40 -0700 | [diff] [blame] | 135 | bool start_busy = false; |
| 136 | double start_time = 0; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 137 | |
Kenneth Graunke | 09b4f26 | 2014-05-14 01:35:30 -0700 | [diff] [blame] | 138 | memset(&prog_data, 0, sizeof(prog_data)); |
Francisco Jerez | 786e085 | 2015-02-09 21:04:53 +0200 | [diff] [blame] | 139 | |
Kenneth Graunke | 7b6620f | 2014-11-30 01:35:14 -0800 | [diff] [blame] | 140 | /* Use ALT floating point mode for ARB programs so that 0^0 == 1. */ |
Timothy Arceri | 2384868 | 2016-11-09 23:44:39 +1100 | [diff] [blame] | 141 | if (fp->program.is_arb_asm) |
Kenneth Graunke | 7b6620f | 2014-11-30 01:35:14 -0800 | [diff] [blame] | 142 | prog_data.base.use_alt_mode = true; |
| 143 | |
Timothy Arceri | 9ca14f5 | 2016-11-05 09:34:52 +1100 | [diff] [blame] | 144 | assign_fs_binding_table_offsets(devinfo, &fp->program, key, &prog_data); |
Jason Ekstrand | ea006c4 | 2015-10-01 08:55:20 -0700 | [diff] [blame] | 145 | |
Eric Anholt | f144b78 | 2012-08-26 21:19:05 -0700 | [diff] [blame] | 146 | /* Allocate the references to the uniforms that will end up in the |
| 147 | * prog_data associated with the compiled program, and which will be freed |
| 148 | * by the state cache. |
| 149 | */ |
Timothy Arceri | 3423488 | 2016-10-19 13:23:37 +1100 | [diff] [blame] | 150 | int param_count = fp->program.nir->num_uniforms / 4; |
Timothy Arceri | ba40c8b | 2016-10-27 15:59:46 +1100 | [diff] [blame] | 151 | prog_data.base.nr_image_params = fp->program.info.num_images; |
Eric Anholt | a43b107 | 2012-11-08 14:02:22 -0800 | [diff] [blame] | 152 | /* The backend also sometimes adds params for texture size. */ |
Kenneth Graunke | 5a51a26 | 2014-01-18 14:48:11 -0800 | [diff] [blame] | 153 | param_count += 2 * ctx->Const.Program[MESA_SHADER_FRAGMENT].MaxTextureImageUnits; |
Neil Roberts | 2c50212 | 2014-08-11 12:21:44 +0100 | [diff] [blame] | 154 | prog_data.base.param = |
| 155 | rzalloc_array(NULL, const gl_constant_value *, param_count); |
Kenneth Graunke | 09b4f26 | 2014-05-14 01:35:30 -0700 | [diff] [blame] | 156 | prog_data.base.pull_param = |
Neil Roberts | 2c50212 | 2014-08-11 12:21:44 +0100 | [diff] [blame] | 157 | rzalloc_array(NULL, const gl_constant_value *, param_count); |
Francisco Jerez | 87a3e02 | 2015-01-21 17:34:49 +0200 | [diff] [blame] | 158 | prog_data.base.image_param = |
| 159 | rzalloc_array(NULL, struct brw_image_param, |
| 160 | prog_data.base.nr_image_params); |
Kenneth Graunke | 09b4f26 | 2014-05-14 01:35:30 -0700 | [diff] [blame] | 161 | prog_data.base.nr_params = param_count; |
Eric Anholt | f144b78 | 2012-08-26 21:19:05 -0700 | [diff] [blame] | 162 | |
Timothy Arceri | 2384868 | 2016-11-09 23:44:39 +1100 | [diff] [blame] | 163 | if (!fp->program.is_arb_asm) { |
Timothy Arceri | 2a4d169 | 2016-11-07 20:54:45 +1100 | [diff] [blame] | 164 | brw_nir_setup_glsl_uniforms(fp->program.nir, &fp->program, |
Jason Ekstrand | 30c6357 | 2015-09-30 17:01:03 -0700 | [diff] [blame] | 165 | &prog_data.base, true); |
| 166 | } else { |
Timothy Arceri | 3423488 | 2016-10-19 13:23:37 +1100 | [diff] [blame] | 167 | brw_nir_setup_arb_uniforms(fp->program.nir, &fp->program, |
Jason Ekstrand | 30c6357 | 2015-09-30 17:01:03 -0700 | [diff] [blame] | 168 | &prog_data.base); |
Timothy Arceri | c3b8bf9 | 2016-11-03 21:47:04 +1100 | [diff] [blame] | 169 | |
| 170 | if (unlikely(INTEL_DEBUG & DEBUG_WM)) |
| 171 | brw_dump_arb_asm("fragment", &fp->program); |
Jason Ekstrand | 30c6357 | 2015-09-30 17:01:03 -0700 | [diff] [blame] | 172 | } |
| 173 | |
Kristian Høgsberg Kristensen | a548c75 | 2015-09-04 17:09:40 -0700 | [diff] [blame] | 174 | if (unlikely(brw->perf_debug)) { |
| 175 | start_busy = (brw->batch.last_bo && |
| 176 | drm_intel_bo_busy(brw->batch.last_bo)); |
| 177 | start_time = get_time(); |
| 178 | } |
| 179 | |
Kristian Høgsberg Kristensen | ee0f010 | 2015-10-07 05:06:30 -0700 | [diff] [blame] | 180 | int st_index8 = -1, st_index16 = -1; |
| 181 | if (INTEL_DEBUG & DEBUG_SHADER_TIME) { |
Timothy Arceri | 6643da6 | 2016-12-20 21:37:23 +1100 | [diff] [blame] | 182 | st_index8 = brw_get_shader_time_index(brw, &fp->program, ST_FS8, |
Timothy Arceri | 2384868 | 2016-11-09 23:44:39 +1100 | [diff] [blame] | 183 | !fp->program.is_arb_asm); |
Timothy Arceri | 6643da6 | 2016-12-20 21:37:23 +1100 | [diff] [blame] | 184 | st_index16 = brw_get_shader_time_index(brw, &fp->program, ST_FS16, |
Timothy Arceri | 2384868 | 2016-11-09 23:44:39 +1100 | [diff] [blame] | 185 | !fp->program.is_arb_asm); |
Kristian Høgsberg Kristensen | ee0f010 | 2015-10-07 05:06:30 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Jason Ekstrand | 22ad449 | 2015-10-05 19:27:28 -0700 | [diff] [blame] | 188 | char *error_str = NULL; |
Kenneth Graunke | 9694b23 | 2015-11-30 15:47:13 -0800 | [diff] [blame] | 189 | program = brw_compile_fs(brw->screen->compiler, brw, mem_ctx, |
Timothy Arceri | 3423488 | 2016-10-19 13:23:37 +1100 | [diff] [blame] | 190 | key, &prog_data, fp->program.nir, |
| 191 | &fp->program, st_index8, st_index16, |
Timothy Arceri | 91d61fb | 2016-10-20 09:59:00 +1100 | [diff] [blame] | 192 | true, brw->use_rep_send, vue_map, |
Jason Ekstrand | 265487a | 2016-05-16 14:30:25 -0700 | [diff] [blame] | 193 | &program_size, &error_str); |
Timothy Arceri | 91d61fb | 2016-10-20 09:59:00 +1100 | [diff] [blame] | 194 | |
Kenneth Graunke | 81b11bf | 2014-05-14 01:04:02 -0700 | [diff] [blame] | 195 | if (program == NULL) { |
Timothy Arceri | 2384868 | 2016-11-09 23:44:39 +1100 | [diff] [blame] | 196 | if (!fp->program.is_arb_asm) { |
Timothy Arceri | a3fd8bb | 2017-02-04 10:46:53 +1100 | [diff] [blame] | 197 | fp->program.sh.data->LinkStatus = linking_failure; |
Timothy Arceri | b880281 | 2016-11-08 10:25:57 +1100 | [diff] [blame] | 198 | ralloc_strcat(&fp->program.sh.data->InfoLog, error_str); |
Jason Ekstrand | 22ad449 | 2015-10-05 19:27:28 -0700 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | _mesa_problem(NULL, "Failed to compile fragment shader: %s\n", error_str); |
| 202 | |
Kenneth Graunke | 2d4ac9b | 2014-05-14 01:21:02 -0700 | [diff] [blame] | 203 | ralloc_free(mem_ctx); |
Kenneth Graunke | 4d09fe9 | 2012-11-20 16:21:27 -0800 | [diff] [blame] | 204 | return false; |
Kenneth Graunke | 81b11bf | 2014-05-14 01:04:02 -0700 | [diff] [blame] | 205 | } |
Brian Paul | 2f78d4a | 2009-02-12 15:35:41 -0700 | [diff] [blame] | 206 | |
Timothy Arceri | 718a0cf | 2016-11-04 13:37:21 +1100 | [diff] [blame] | 207 | if (unlikely(brw->perf_debug)) { |
| 208 | if (fp->compiled_once) |
Timothy Arceri | 6f76ca3 | 2016-11-04 14:09:35 +1100 | [diff] [blame] | 209 | brw_wm_debug_recompile(brw, &fp->program, key); |
Timothy Arceri | 718a0cf | 2016-11-04 13:37:21 +1100 | [diff] [blame] | 210 | fp->compiled_once = true; |
Kristian Høgsberg Kristensen | a548c75 | 2015-09-04 17:09:40 -0700 | [diff] [blame] | 211 | |
| 212 | if (start_busy && !drm_intel_bo_busy(brw->batch.last_bo)) { |
| 213 | perf_debug("FS compile took %.03f ms and stalled the GPU\n", |
| 214 | (get_time() - start_time) * 1000); |
| 215 | } |
| 216 | } |
| 217 | |
Francisco Jerez | d960284 | 2016-06-13 14:56:22 -0700 | [diff] [blame] | 218 | brw_alloc_stage_scratch(brw, &brw->wm.base, |
| 219 | prog_data.base.total_scratch, |
Lionel Landwerlin | 94d0e7d | 2016-09-23 00:41:23 +0300 | [diff] [blame] | 220 | devinfo->max_wm_threads); |
Eric Anholt | 4e72525 | 2010-10-21 15:07:45 -0700 | [diff] [blame] | 221 | |
Timothy Arceri | 2384868 | 2016-11-09 23:44:39 +1100 | [diff] [blame] | 222 | if (unlikely((INTEL_DEBUG & DEBUG_WM) && fp->program.is_arb_asm)) |
Eric Anholt | fc3971d | 2009-01-08 19:15:04 -0800 | [diff] [blame] | 223 | fprintf(stderr, "\n"); |
| 224 | |
Kenneth Graunke | 67c4980 | 2014-09-26 11:38:06 -0700 | [diff] [blame] | 225 | brw_upload_cache(&brw->cache, BRW_CACHE_FS_PROG, |
Timothy Arceri | a38c809 | 2016-10-05 15:42:02 +1100 | [diff] [blame] | 226 | key, sizeof(struct brw_wm_prog_key), |
| 227 | program, program_size, |
| 228 | &prog_data, sizeof(prog_data), |
| 229 | &brw->wm.base.prog_offset, &brw->wm.base.prog_data); |
Eric Anholt | 8752764 | 2011-05-16 15:10:26 -0700 | [diff] [blame] | 230 | |
Kenneth Graunke | 2d4ac9b | 2014-05-14 01:21:02 -0700 | [diff] [blame] | 231 | ralloc_free(mem_ctx); |
Eric Anholt | 2fcaf4e | 2012-11-06 09:48:51 -0800 | [diff] [blame] | 232 | |
Eric Anholt | 8752764 | 2011-05-16 15:10:26 -0700 | [diff] [blame] | 233 | return true; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 234 | } |
| 235 | |
Eric Anholt | fc3b7c9 | 2012-07-12 13:19:53 -0700 | [diff] [blame] | 236 | bool |
Kenneth Graunke | ca43757 | 2013-07-02 23:17:14 -0700 | [diff] [blame] | 237 | brw_debug_recompile_sampler_key(struct brw_context *brw, |
Eric Anholt | 14cec07 | 2013-02-22 13:15:20 -0800 | [diff] [blame] | 238 | const struct brw_sampler_prog_key_data *old_key, |
Eric Anholt | fc3b7c9 | 2012-07-12 13:19:53 -0700 | [diff] [blame] | 239 | const struct brw_sampler_prog_key_data *key) |
| 240 | { |
| 241 | bool found = false; |
| 242 | |
Kenneth Graunke | f3d0daf | 2012-08-26 00:28:38 -0700 | [diff] [blame] | 243 | for (unsigned int i = 0; i < MAX_SAMPLERS; i++) { |
Kenneth Graunke | ca43757 | 2013-07-02 23:17:14 -0700 | [diff] [blame] | 244 | found |= key_debug(brw, "EXT_texture_swizzle or DEPTH_TEXTURE_MODE", |
Kenneth Graunke | 98211d5 | 2012-08-15 16:35:35 -0700 | [diff] [blame] | 245 | old_key->swizzles[i], key->swizzles[i]); |
Eric Anholt | fc3b7c9 | 2012-07-12 13:19:53 -0700 | [diff] [blame] | 246 | } |
Kenneth Graunke | ca43757 | 2013-07-02 23:17:14 -0700 | [diff] [blame] | 247 | found |= key_debug(brw, "GL_CLAMP enabled on any texture unit's 1st coordinate", |
Kenneth Graunke | 98211d5 | 2012-08-15 16:35:35 -0700 | [diff] [blame] | 248 | old_key->gl_clamp_mask[0], key->gl_clamp_mask[0]); |
Kenneth Graunke | ca43757 | 2013-07-02 23:17:14 -0700 | [diff] [blame] | 249 | found |= key_debug(brw, "GL_CLAMP enabled on any texture unit's 2nd coordinate", |
Kenneth Graunke | 98211d5 | 2012-08-15 16:35:35 -0700 | [diff] [blame] | 250 | old_key->gl_clamp_mask[1], key->gl_clamp_mask[1]); |
Kenneth Graunke | ca43757 | 2013-07-02 23:17:14 -0700 | [diff] [blame] | 251 | found |= key_debug(brw, "GL_CLAMP enabled on any texture unit's 3rd coordinate", |
Kenneth Graunke | 98211d5 | 2012-08-15 16:35:35 -0700 | [diff] [blame] | 252 | old_key->gl_clamp_mask[2], key->gl_clamp_mask[2]); |
Chris Forbes | cfa3c8a | 2013-08-11 09:55:30 +1200 | [diff] [blame] | 253 | found |= key_debug(brw, "gather channel quirk on any texture unit", |
| 254 | old_key->gather_channel_quirk_mask, key->gather_channel_quirk_mask); |
Kenneth Graunke | 30c8d8a | 2015-04-23 23:17:10 -0700 | [diff] [blame] | 255 | found |= key_debug(brw, "compressed multisample layout", |
| 256 | old_key->compressed_multisample_layout_mask, |
| 257 | key->compressed_multisample_layout_mask); |
Neil Roberts | 1a97cac | 2015-09-15 16:34:35 +0100 | [diff] [blame] | 258 | found |= key_debug(brw, "16x msaa", |
| 259 | old_key->msaa_16, |
| 260 | key->msaa_16); |
Kenneth Graunke | 30c8d8a | 2015-04-23 23:17:10 -0700 | [diff] [blame] | 261 | |
Kristian Høgsberg Kristensen | 654e950 | 2016-05-01 21:22:54 -0700 | [diff] [blame] | 262 | found |= key_debug(brw, "y_uv image bound", |
| 263 | old_key->y_uv_image_mask, |
| 264 | key->y_uv_image_mask); |
| 265 | found |= key_debug(brw, "y_u_v image bound", |
| 266 | old_key->y_u_v_image_mask, |
| 267 | key->y_u_v_image_mask); |
| 268 | found |= key_debug(brw, "yx_xuxv image bound", |
| 269 | old_key->yx_xuxv_image_mask, |
| 270 | key->yx_xuxv_image_mask); |
| 271 | |
Kenneth Graunke | 30c8d8a | 2015-04-23 23:17:10 -0700 | [diff] [blame] | 272 | for (unsigned int i = 0; i < MAX_SAMPLERS; i++) { |
| 273 | found |= key_debug(brw, "textureGather workarounds", |
| 274 | old_key->gen6_gather_wa[i], key->gen6_gather_wa[i]); |
| 275 | } |
Eric Anholt | fc3b7c9 | 2012-07-12 13:19:53 -0700 | [diff] [blame] | 276 | |
| 277 | return found; |
| 278 | } |
| 279 | |
Chris Forbes | 2b7bbd8 | 2014-02-03 22:13:03 +1300 | [diff] [blame] | 280 | static uint8_t |
| 281 | gen6_gather_workaround(GLenum internalformat) |
| 282 | { |
| 283 | switch (internalformat) { |
Ian Romanick | 2b81cef | 2015-06-10 17:09:16 -0700 | [diff] [blame] | 284 | case GL_R8I: return WA_SIGN | WA_8BIT; |
| 285 | case GL_R8UI: return WA_8BIT; |
| 286 | case GL_R16I: return WA_SIGN | WA_16BIT; |
| 287 | case GL_R16UI: return WA_16BIT; |
| 288 | default: |
| 289 | /* Note that even though GL_R32I and GL_R32UI have format overrides in |
| 290 | * the surface state, there is no shader w/a required. |
| 291 | */ |
| 292 | return 0; |
Chris Forbes | 2b7bbd8 | 2014-02-03 22:13:03 +1300 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
Kenneth Graunke | 1b05fc7 | 2011-12-06 15:36:21 -0800 | [diff] [blame] | 296 | void |
| 297 | brw_populate_sampler_prog_key_data(struct gl_context *ctx, |
Timothy Arceri | a38c809 | 2016-10-05 15:42:02 +1100 | [diff] [blame] | 298 | const struct gl_program *prog, |
| 299 | struct brw_sampler_prog_key_data *key) |
Kenneth Graunke | 1b05fc7 | 2011-12-06 15:36:21 -0800 | [diff] [blame] | 300 | { |
Kenneth Graunke | 794de2f | 2013-07-06 00:15:44 -0700 | [diff] [blame] | 301 | struct brw_context *brw = brw_context(ctx); |
Timothy Arceri | 8f1ca0e | 2016-07-05 17:02:46 +1000 | [diff] [blame] | 302 | GLbitfield mask = prog->SamplersUsed; |
Kenneth Graunke | 6d6aef7 | 2012-09-21 03:13:36 -0700 | [diff] [blame] | 303 | |
Timothy Arceri | 8f1ca0e | 2016-07-05 17:02:46 +1000 | [diff] [blame] | 304 | while (mask) { |
| 305 | const int s = u_bit_scan(&mask); |
| 306 | |
Kenneth Graunke | f3d0daf | 2012-08-26 00:28:38 -0700 | [diff] [blame] | 307 | key->swizzles[s] = SWIZZLE_NOOP; |
Kenneth Graunke | 76d1301 | 2012-08-14 11:05:55 -0700 | [diff] [blame] | 308 | |
Kenneth Graunke | f3d0daf | 2012-08-26 00:28:38 -0700 | [diff] [blame] | 309 | int unit_id = prog->SamplerUnits[s]; |
| 310 | const struct gl_texture_unit *unit = &ctx->Texture.Unit[unit_id]; |
Kenneth Graunke | 1b05fc7 | 2011-12-06 15:36:21 -0800 | [diff] [blame] | 311 | |
Eric Anholt | ff9c3e8 | 2014-04-23 17:14:26 -0700 | [diff] [blame] | 312 | if (unit->_Current && unit->_Current->Target != GL_TEXTURE_BUFFER) { |
Timothy Arceri | a38c809 | 2016-10-05 15:42:02 +1100 | [diff] [blame] | 313 | const struct gl_texture_object *t = unit->_Current; |
| 314 | const struct gl_texture_image *img = t->Image[0][t->BaseLevel]; |
| 315 | struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit_id); |
Kenneth Graunke | fe911c1 | 2012-06-16 13:50:03 -0700 | [diff] [blame] | 316 | |
Kenneth Graunke | 6d6aef7 | 2012-09-21 03:13:36 -0700 | [diff] [blame] | 317 | const bool alpha_depth = t->DepthMode == GL_ALPHA && |
| 318 | (img->_BaseFormat == GL_DEPTH_COMPONENT || |
| 319 | img->_BaseFormat == GL_DEPTH_STENCIL); |
| 320 | |
| 321 | /* Haswell handles texture swizzling as surface format overrides |
| 322 | * (except for GL_ALPHA); all other platforms need MOVs in the shader. |
| 323 | */ |
Kenneth Graunke | 5720832 | 2013-01-14 21:43:28 -0800 | [diff] [blame] | 324 | if (alpha_depth || (brw->gen < 8 && !brw->is_haswell)) |
Kenneth Graunke | 9db2098 | 2013-01-23 15:27:39 -0800 | [diff] [blame] | 325 | key->swizzles[s] = brw_get_texture_swizzle(ctx, t); |
Kenneth Graunke | fe911c1 | 2012-06-16 13:50:03 -0700 | [diff] [blame] | 326 | |
Timothy Arceri | a38c809 | 2016-10-05 15:42:02 +1100 | [diff] [blame] | 327 | if (brw->gen < 8 && |
Kenneth Graunke | 2211696 | 2014-05-28 23:31:48 -0700 | [diff] [blame] | 328 | sampler->MinFilter != GL_NEAREST && |
Timothy Arceri | a38c809 | 2016-10-05 15:42:02 +1100 | [diff] [blame] | 329 | sampler->MagFilter != GL_NEAREST) { |
| 330 | if (sampler->WrapS == GL_CLAMP) |
| 331 | key->gl_clamp_mask[0] |= 1 << s; |
| 332 | if (sampler->WrapT == GL_CLAMP) |
| 333 | key->gl_clamp_mask[1] |= 1 << s; |
| 334 | if (sampler->WrapR == GL_CLAMP) |
| 335 | key->gl_clamp_mask[2] |= 1 << s; |
| 336 | } |
Chris Forbes | cfa3c8a | 2013-08-11 09:55:30 +1200 | [diff] [blame] | 337 | |
Kenneth Graunke | 99c019e | 2017-01-05 02:51:38 -0800 | [diff] [blame] | 338 | /* gather4 for RG32* is broken in multiple ways on Gen7. */ |
| 339 | if (brw->gen == 7 && prog->nir->info->uses_texture_gather) { |
| 340 | switch (img->InternalFormat) { |
| 341 | case GL_RG32I: |
| 342 | case GL_RG32UI: { |
| 343 | /* We have to override the format to R32G32_FLOAT_LD. |
| 344 | * This means that SCS_ALPHA and SCS_ONE will return 0x3f8 |
| 345 | * (1.0) rather than integer 1. This needs shader hacks. |
| 346 | * |
| 347 | * On Ivybridge, we whack W (alpha) to ONE in our key's |
| 348 | * swizzle. On Haswell, we look at the original texture |
| 349 | * swizzle, and use XYZW with channels overridden to ONE, |
| 350 | * leaving normal texture swizzling to SCS. |
| 351 | */ |
| 352 | unsigned src_swizzle = |
| 353 | brw->is_haswell ? t->_Swizzle : key->swizzles[s]; |
| 354 | for (int i = 0; i < 4; i++) { |
| 355 | unsigned src_comp = GET_SWZ(src_swizzle, i); |
| 356 | if (src_comp == SWIZZLE_ONE || src_comp == SWIZZLE_W) { |
| 357 | key->swizzles[i] &= ~(0x7 << (3 * i)); |
| 358 | key->swizzles[i] |= SWIZZLE_ONE << (3 * i); |
| 359 | } |
| 360 | } |
| 361 | /* fallthrough */ |
| 362 | } |
| 363 | case GL_RG32F: |
| 364 | /* The channel select for green doesn't work - we have to |
| 365 | * request blue. Haswell can use SCS for this, but Ivybridge |
| 366 | * needs a shader workaround. |
| 367 | */ |
| 368 | if (!brw->is_haswell) |
| 369 | key->gather_channel_quirk_mask |= 1 << s; |
| 370 | break; |
| 371 | } |
Chris Forbes | cfa3c8a | 2013-08-11 09:55:30 +1200 | [diff] [blame] | 372 | } |
Chris Forbes | 27359b8 | 2013-11-30 10:01:12 +1300 | [diff] [blame] | 373 | |
Chris Forbes | 2b7bbd8 | 2014-02-03 22:13:03 +1300 | [diff] [blame] | 374 | /* Gen6's gather4 is broken for UINT/SINT; we treat them as |
| 375 | * UNORM/FLOAT instead and fix it in the shader. |
| 376 | */ |
Timothy Arceri | e1af20f | 2016-10-13 11:41:23 +1100 | [diff] [blame] | 377 | if (brw->gen == 6 && prog->nir->info->uses_texture_gather) { |
Chris Forbes | 2b7bbd8 | 2014-02-03 22:13:03 +1300 | [diff] [blame] | 378 | key->gen6_gather_wa[s] = gen6_gather_workaround(img->InternalFormat); |
| 379 | } |
| 380 | |
Chris Forbes | 27359b8 | 2013-11-30 10:01:12 +1300 | [diff] [blame] | 381 | /* If this is a multisample sampler, and uses the CMS MSAA layout, |
| 382 | * then we need to emit slightly different code to first sample the |
| 383 | * MCS surface. |
| 384 | */ |
| 385 | struct intel_texture_object *intel_tex = |
| 386 | intel_texture_object((struct gl_texture_object *)t); |
| 387 | |
Topi Pohjolainen | cda8c2a | 2016-04-18 21:47:23 +0300 | [diff] [blame] | 388 | /* From gen9 onwards some single sampled buffers can also be |
| 389 | * compressed. These don't need ld2dms sampling along with mcs fetch. |
| 390 | */ |
Chris Forbes | 27359b8 | 2013-11-30 10:01:12 +1300 | [diff] [blame] | 391 | if (brw->gen >= 7 && |
Topi Pohjolainen | cda8c2a | 2016-04-18 21:47:23 +0300 | [diff] [blame] | 392 | intel_tex->mt->msaa_layout == INTEL_MSAA_LAYOUT_CMS && |
| 393 | intel_tex->mt->num_samples > 1) { |
Chris Forbes | 27359b8 | 2013-11-30 10:01:12 +1300 | [diff] [blame] | 394 | key->compressed_multisample_layout_mask |= 1 << s; |
Neil Roberts | 1a97cac | 2015-09-15 16:34:35 +0100 | [diff] [blame] | 395 | |
| 396 | if (intel_tex->mt->num_samples >= 16) { |
| 397 | assert(brw->gen >= 9); |
| 398 | key->msaa_16 |= 1 << s; |
| 399 | } |
Chris Forbes | 27359b8 | 2013-11-30 10:01:12 +1300 | [diff] [blame] | 400 | } |
Kristian Høgsberg Kristensen | 654e950 | 2016-05-01 21:22:54 -0700 | [diff] [blame] | 401 | |
| 402 | if (t->Target == GL_TEXTURE_EXTERNAL_OES && intel_tex->planar_format) { |
| 403 | switch (intel_tex->planar_format->components) { |
| 404 | case __DRI_IMAGE_COMPONENTS_Y_UV: |
| 405 | key->y_uv_image_mask |= 1 << s; |
| 406 | break; |
| 407 | case __DRI_IMAGE_COMPONENTS_Y_U_V: |
| 408 | key->y_u_v_image_mask |= 1 << s; |
| 409 | break; |
| 410 | case __DRI_IMAGE_COMPONENTS_Y_XUXV: |
| 411 | key->yx_xuxv_image_mask |= 1 << s; |
| 412 | break; |
| 413 | default: |
| 414 | break; |
| 415 | } |
| 416 | } |
| 417 | |
Kenneth Graunke | 1b05fc7 | 2011-12-06 15:36:21 -0800 | [diff] [blame] | 418 | } |
Kenneth Graunke | 1b05fc7 | 2011-12-06 15:36:21 -0800 | [diff] [blame] | 419 | } |
| 420 | } |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 421 | |
Carl Worth | a57672f | 2015-03-20 12:01:33 -0700 | [diff] [blame] | 422 | static bool |
Kenneth Graunke | b23b099 | 2016-04-27 11:26:08 -0700 | [diff] [blame] | 423 | brw_wm_state_dirty(const struct brw_context *brw) |
Carl Worth | a57672f | 2015-03-20 12:01:33 -0700 | [diff] [blame] | 424 | { |
| 425 | return brw_state_dirty(brw, |
| 426 | _NEW_BUFFERS | |
| 427 | _NEW_COLOR | |
| 428 | _NEW_DEPTH | |
| 429 | _NEW_FRAG_CLAMP | |
| 430 | _NEW_HINT | |
| 431 | _NEW_LIGHT | |
| 432 | _NEW_LINE | |
| 433 | _NEW_MULTISAMPLE | |
| 434 | _NEW_POLYGON | |
| 435 | _NEW_STENCIL | |
| 436 | _NEW_TEXTURE, |
| 437 | BRW_NEW_FRAGMENT_PROGRAM | |
| 438 | BRW_NEW_REDUCED_PRIMITIVE | |
| 439 | BRW_NEW_STATS_WM | |
| 440 | BRW_NEW_VUE_MAP_GEOM_OUT); |
| 441 | } |
| 442 | |
Carl Worth | 017081a | 2016-04-14 10:54:38 +1000 | [diff] [blame] | 443 | void |
Ian Romanick | 2b81cef | 2015-06-10 17:09:16 -0700 | [diff] [blame] | 444 | brw_wm_populate_key(struct brw_context *brw, struct brw_wm_prog_key *key) |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 445 | { |
Kenneth Graunke | 8c9a54e | 2013-07-06 00:46:38 -0700 | [diff] [blame] | 446 | struct gl_context *ctx = &brw->ctx; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 447 | /* BRW_NEW_FRAGMENT_PROGRAM */ |
Timothy Arceri | 13d0cf5 | 2016-10-18 16:17:14 +1100 | [diff] [blame] | 448 | const struct brw_program *fp = brw_program_const(brw->fragment_program); |
Kenneth Graunke | 387a3d4 | 2011-12-08 12:15:59 -0800 | [diff] [blame] | 449 | const struct gl_program *prog = (struct gl_program *) brw->fragment_program; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 450 | GLuint lookup = 0; |
| 451 | GLuint line_aa; |
Paul Berry | 82d2596 | 2012-06-20 13:40:45 -0700 | [diff] [blame] | 452 | |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 453 | memset(key, 0, sizeof(*key)); |
| 454 | |
| 455 | /* Build the index for table lookup |
| 456 | */ |
Kenneth Graunke | 53631be | 2013-07-06 00:36:46 -0700 | [diff] [blame] | 457 | if (brw->gen < 6) { |
Kenneth Graunke | 86e401b | 2012-07-12 11:25:58 -0700 | [diff] [blame] | 458 | /* _NEW_COLOR */ |
Timothy Arceri | 17e28a1 | 2016-10-19 13:45:18 +1100 | [diff] [blame] | 459 | if (prog->info.fs.uses_discard || ctx->Color.AlphaEnabled) { |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 460 | lookup |= BRW_WM_IZ_PS_KILL_ALPHATEST_BIT; |
Timothy Arceri | 556335e | 2016-10-05 15:13:23 +1100 | [diff] [blame] | 461 | } |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 462 | |
Timothy Arceri | 17e28a1 | 2016-10-19 13:45:18 +1100 | [diff] [blame] | 463 | if (prog->info.outputs_written & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) { |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 464 | lookup |= BRW_WM_IZ_PS_COMPUTES_DEPTH_BIT; |
Timothy Arceri | 7ef8286 | 2016-10-05 16:24:56 +1100 | [diff] [blame] | 465 | } |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 466 | |
Kenneth Graunke | 2f8351a | 2012-06-16 16:34:50 -0700 | [diff] [blame] | 467 | /* _NEW_DEPTH */ |
| 468 | if (ctx->Depth.Test) |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 469 | lookup |= BRW_WM_IZ_DEPTH_TEST_ENABLE_BIT; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 470 | |
Kenneth Graunke | ff0253a | 2016-11-16 18:29:22 -0800 | [diff] [blame] | 471 | if (brw_depth_writes_enabled(brw)) |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 472 | lookup |= BRW_WM_IZ_DEPTH_WRITE_ENABLE_BIT; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 473 | |
Eric Anholt | 94ecf91 | 2013-06-20 09:08:30 -0700 | [diff] [blame] | 474 | /* _NEW_STENCIL | _NEW_BUFFERS */ |
Kenneth Graunke | 2f8351a | 2012-06-16 16:34:50 -0700 | [diff] [blame] | 475 | if (ctx->Stencil._Enabled) { |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 476 | lookup |= BRW_WM_IZ_STENCIL_TEST_ENABLE_BIT; |
Kenneth Graunke | 2f8351a | 2012-06-16 16:34:50 -0700 | [diff] [blame] | 477 | |
Timothy Arceri | a38c809 | 2016-10-05 15:42:02 +1100 | [diff] [blame] | 478 | if (ctx->Stencil.WriteMask[0] || |
| 479 | ctx->Stencil.WriteMask[ctx->Stencil._BackFace]) |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 480 | lookup |= BRW_WM_IZ_STENCIL_WRITE_ENABLE_BIT; |
Kenneth Graunke | 2f8351a | 2012-06-16 16:34:50 -0700 | [diff] [blame] | 481 | } |
| 482 | key->iz_lookup = lookup; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 483 | } |
| 484 | |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 485 | line_aa = BRW_WM_AA_NEVER; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 486 | |
| 487 | /* _NEW_LINE, _NEW_POLYGON, BRW_NEW_REDUCED_PRIMITIVE */ |
Eric Anholt | 052c1d6 | 2009-01-30 14:32:23 -0800 | [diff] [blame] | 488 | if (ctx->Line.SmoothFlag) { |
Kenneth Graunke | fe0a8cb | 2013-07-03 11:55:59 -0700 | [diff] [blame] | 489 | if (brw->reduced_primitive == GL_LINES) { |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 490 | line_aa = BRW_WM_AA_ALWAYS; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 491 | } |
Kenneth Graunke | fe0a8cb | 2013-07-03 11:55:59 -0700 | [diff] [blame] | 492 | else if (brw->reduced_primitive == GL_TRIANGLES) { |
Timothy Arceri | a38c809 | 2016-10-05 15:42:02 +1100 | [diff] [blame] | 493 | if (ctx->Polygon.FrontMode == GL_LINE) { |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 494 | line_aa = BRW_WM_AA_SOMETIMES; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 495 | |
Timothy Arceri | a38c809 | 2016-10-05 15:42:02 +1100 | [diff] [blame] | 496 | if (ctx->Polygon.BackMode == GL_LINE || |
| 497 | (ctx->Polygon.CullFlag && |
| 498 | ctx->Polygon.CullFaceMode == GL_BACK)) |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 499 | line_aa = BRW_WM_AA_ALWAYS; |
Timothy Arceri | a38c809 | 2016-10-05 15:42:02 +1100 | [diff] [blame] | 500 | } |
| 501 | else if (ctx->Polygon.BackMode == GL_LINE) { |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 502 | line_aa = BRW_WM_AA_SOMETIMES; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 503 | |
Timothy Arceri | a38c809 | 2016-10-05 15:42:02 +1100 | [diff] [blame] | 504 | if ((ctx->Polygon.CullFlag && |
| 505 | ctx->Polygon.CullFaceMode == GL_FRONT)) |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 506 | line_aa = BRW_WM_AA_ALWAYS; |
Timothy Arceri | a38c809 | 2016-10-05 15:42:02 +1100 | [diff] [blame] | 507 | } |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 508 | } |
| 509 | } |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 510 | |
Eric Anholt | 16f8c82 | 2010-11-11 09:30:16 -0800 | [diff] [blame] | 511 | key->line_aa = line_aa; |
Kenneth Graunke | 6cc14c2 | 2012-08-26 00:47:44 -0700 | [diff] [blame] | 512 | |
Chia-I Wu | 848c0e7 | 2013-09-12 13:00:52 +0800 | [diff] [blame] | 513 | /* _NEW_HINT */ |
Kenneth Graunke | 2a4f572 | 2014-11-30 21:58:03 -0800 | [diff] [blame] | 514 | key->high_quality_derivatives = |
| 515 | ctx->Hint.FragmentShaderDerivative == GL_NICEST; |
Chia-I Wu | 848c0e7 | 2013-09-12 13:00:52 +0800 | [diff] [blame] | 516 | |
Kenneth Graunke | 53631be | 2013-07-06 00:36:46 -0700 | [diff] [blame] | 517 | if (brw->gen < 6) |
Kenneth Graunke | ec995de | 2013-07-03 14:26:01 -0700 | [diff] [blame] | 518 | key->stats_wm = brw->stats_wm; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 519 | |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 520 | /* _NEW_LIGHT */ |
Eric Anholt | 052c1d6 | 2009-01-30 14:32:23 -0800 | [diff] [blame] | 521 | key->flat_shade = (ctx->Light.ShadeModel == GL_FLAT); |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 522 | |
Eric Anholt | d22e2eb | 2011-04-15 14:40:09 -0700 | [diff] [blame] | 523 | /* _NEW_FRAG_CLAMP | _NEW_BUFFERS */ |
| 524 | key->clamp_fragment_color = ctx->Color._ClampFragmentColor; |
| 525 | |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 526 | /* _NEW_TEXTURE */ |
Timothy Arceri | 8f1ca0e | 2016-07-05 17:02:46 +1000 | [diff] [blame] | 527 | brw_populate_sampler_prog_key_data(ctx, prog, &key->tex); |
Eric Anholt | 9c8f27b | 2008-02-28 13:18:12 -0800 | [diff] [blame] | 528 | |
| 529 | /* _NEW_BUFFERS */ |
Eric Anholt | 1b80622 | 2011-01-30 21:13:17 -0800 | [diff] [blame] | 530 | key->nr_color_regions = ctx->DrawBuffer->_NumColorDrawBuffers; |
Chris Forbes | 1415a18 | 2013-07-01 23:30:55 +1200 | [diff] [blame] | 531 | |
Kenneth Graunke | b3340cd | 2016-01-20 17:33:14 -0800 | [diff] [blame] | 532 | /* _NEW_COLOR */ |
| 533 | key->force_dual_color_blend = brw->dual_color_blend_by_location && |
| 534 | (ctx->Color.BlendEnabled & 1) && ctx->Color.Blend[0]._UsesDualSrc; |
| 535 | |
Chris Forbes | 1415a18 | 2013-07-01 23:30:55 +1200 | [diff] [blame] | 536 | /* _NEW_MULTISAMPLE, _NEW_COLOR, _NEW_BUFFERS */ |
| 537 | key->replicate_alpha = ctx->DrawBuffer->_NumColorDrawBuffers > 1 && |
Anuj Phogat | 329ae92 | 2016-10-20 11:40:40 -0700 | [diff] [blame] | 538 | (_mesa_is_alpha_test_enabled(ctx) || |
| 539 | _mesa_is_alpha_to_coverage_enabled(ctx)); |
Brian Paul | 9ef33b8 | 2009-10-29 14:53:53 -0600 | [diff] [blame] | 540 | |
Anuj Phogat | 65d0452 | 2013-10-24 15:53:05 -0700 | [diff] [blame] | 541 | /* _NEW_BUFFERS _NEW_MULTISAMPLE */ |
Anuj Phogat | a92e5f7 | 2014-01-06 13:59:18 -0800 | [diff] [blame] | 542 | /* Ignore sample qualifier while computing this flag. */ |
Jason Ekstrand | 712a980 | 2016-05-09 17:48:24 -0700 | [diff] [blame] | 543 | if (ctx->Multisample.Enabled) { |
| 544 | key->persample_interp = |
| 545 | ctx->Multisample.SampleShading && |
| 546 | (ctx->Multisample.MinSampleShadingValue * |
| 547 | _mesa_geometric_samples(ctx->DrawBuffer) > 1); |
Anuj Phogat | a92e5f7 | 2014-01-06 13:59:18 -0800 | [diff] [blame] | 548 | |
Jason Ekstrand | 712a980 | 2016-05-09 17:48:24 -0700 | [diff] [blame] | 549 | key->multisample_fbo = _mesa_geometric_samples(ctx->DrawBuffer) > 1; |
| 550 | } |
Anuj Phogat | e12bbb5 | 2013-10-24 16:17:08 -0700 | [diff] [blame] | 551 | |
Paul Berry | bf9bfe8 | 2013-03-17 11:29:28 -0700 | [diff] [blame] | 552 | /* BRW_NEW_VUE_MAP_GEOM_OUT */ |
Timothy Arceri | 17e28a1 | 2016-10-19 13:45:18 +1100 | [diff] [blame] | 553 | if (brw->gen < 6 || _mesa_bitcount_64(prog->info.inputs_read & |
| 554 | BRW_FS_VARYING_INPUT_MASK) > 16) { |
Paul Berry | 0a0deb9 | 2013-03-20 10:15:52 -0700 | [diff] [blame] | 555 | key->input_slots_valid = brw->vue_map_geom_out.slots_valid; |
Timothy Arceri | 7627fbd | 2016-10-05 16:45:27 +1100 | [diff] [blame] | 556 | } |
Eric Anholt | 0f5113d | 2009-05-14 09:49:45 -0700 | [diff] [blame] | 557 | |
Chris Forbes | 1080fc6 | 2013-10-27 12:09:51 +1300 | [diff] [blame] | 558 | /* _NEW_COLOR | _NEW_BUFFERS */ |
| 559 | /* Pre-gen6, the hardware alpha test always used each render |
| 560 | * target's alpha to do alpha test, as opposed to render target 0's alpha |
| 561 | * like GL requires. Fix that by building the alpha test into the |
| 562 | * shader, and we'll skip enabling the fixed function alpha test. |
| 563 | */ |
Ian Romanick | 2b81cef | 2015-06-10 17:09:16 -0700 | [diff] [blame] | 564 | if (brw->gen < 6 && ctx->DrawBuffer->_NumColorDrawBuffers > 1 && |
| 565 | ctx->Color.AlphaEnabled) { |
Chris Forbes | 1080fc6 | 2013-10-27 12:09:51 +1300 | [diff] [blame] | 566 | key->alpha_test_func = ctx->Color.AlphaFunc; |
| 567 | key->alpha_test_ref = ctx->Color.AlphaRef; |
| 568 | } |
| 569 | |
Brian Paul | 55d33e1 | 2009-02-20 10:49:30 -0700 | [diff] [blame] | 570 | /* The unique fragment program ID */ |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 571 | key->program_string_id = fp->id; |
Francisco Jerez | 40b23ad | 2016-07-21 20:32:12 -0700 | [diff] [blame] | 572 | |
| 573 | /* Whether reads from the framebuffer should behave coherently. */ |
| 574 | key->coherent_fb_fetch = ctx->Extensions.MESA_shader_framebuffer_fetch; |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Carl Worth | 4a6c6c4 | 2015-02-11 13:53:31 -0800 | [diff] [blame] | 577 | void |
Eric Anholt | dc9a753 | 2011-10-22 11:33:54 -0700 | [diff] [blame] | 578 | brw_upload_wm_prog(struct brw_context *brw) |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 579 | { |
| 580 | struct brw_wm_prog_key key; |
Timothy Arceri | 13d0cf5 | 2016-10-18 16:17:14 +1100 | [diff] [blame] | 581 | struct brw_program *fp = (struct brw_program *) brw->fragment_program; |
Eric Anholt | 662f1b4 | 2011-03-11 19:19:01 -0800 | [diff] [blame] | 582 | |
Carl Worth | a57672f | 2015-03-20 12:01:33 -0700 | [diff] [blame] | 583 | if (!brw_wm_state_dirty(brw)) |
Carl Worth | 4a6c6c4 | 2015-02-11 13:53:31 -0800 | [diff] [blame] | 584 | return; |
| 585 | |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 586 | brw_wm_populate_key(brw, &key); |
| 587 | |
Kenneth Graunke | 67c4980 | 2014-09-26 11:38:06 -0700 | [diff] [blame] | 588 | if (!brw_search_cache(&brw->cache, BRW_CACHE_FS_PROG, |
Timothy Arceri | a38c809 | 2016-10-05 15:42:02 +1100 | [diff] [blame] | 589 | &key, sizeof(key), |
| 590 | &brw->wm.base.prog_offset, |
Kenneth Graunke | 16d5536 | 2016-09-08 23:48:53 -0700 | [diff] [blame] | 591 | &brw->wm.base.prog_data)) { |
Timothy Arceri | 6e3f609 | 2016-11-04 16:04:01 +1100 | [diff] [blame] | 592 | bool success = brw_codegen_wm_prog(brw, fp, &key, |
Timothy Arceri | 91d61fb | 2016-10-20 09:59:00 +1100 | [diff] [blame] | 593 | &brw->vue_map_geom_out); |
Brian Paul | 4170227 | 2011-10-07 10:38:30 -0600 | [diff] [blame] | 594 | (void) success; |
Eric Anholt | 8752764 | 2011-05-16 15:10:26 -0700 | [diff] [blame] | 595 | assert(success); |
| 596 | } |
Eric Anholt | 9f344b3 | 2006-08-09 19:14:05 +0000 | [diff] [blame] | 597 | } |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 598 | |
| 599 | bool |
Timothy Arceri | 6e3f609 | 2016-11-04 16:04:01 +1100 | [diff] [blame] | 600 | brw_fs_precompile(struct gl_context *ctx, struct gl_program *prog) |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 601 | { |
| 602 | struct brw_context *brw = brw_context(ctx); |
| 603 | struct brw_wm_prog_key key; |
| 604 | |
Timothy Arceri | 13d0cf5 | 2016-10-18 16:17:14 +1100 | [diff] [blame] | 605 | struct brw_program *bfp = brw_program(prog); |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 606 | |
| 607 | memset(&key, 0, sizeof(key)); |
| 608 | |
Timothy Arceri | 17e28a1 | 2016-10-19 13:45:18 +1100 | [diff] [blame] | 609 | uint64_t outputs_written = prog->info.outputs_written; |
Timothy Arceri | 7ef8286 | 2016-10-05 16:24:56 +1100 | [diff] [blame] | 610 | |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 611 | if (brw->gen < 6) { |
Timothy Arceri | 17e28a1 | 2016-10-19 13:45:18 +1100 | [diff] [blame] | 612 | if (prog->info.fs.uses_discard) |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 613 | key.iz_lookup |= BRW_WM_IZ_PS_KILL_ALPHATEST_BIT; |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 614 | |
Timothy Arceri | 7ef8286 | 2016-10-05 16:24:56 +1100 | [diff] [blame] | 615 | if (outputs_written & BITFIELD64_BIT(FRAG_RESULT_DEPTH)) |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 616 | key.iz_lookup |= BRW_WM_IZ_PS_COMPUTES_DEPTH_BIT; |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 617 | |
| 618 | /* Just assume depth testing. */ |
Jason Ekstrand | 8123402 | 2017-02-28 16:33:49 -0800 | [diff] [blame^] | 619 | key.iz_lookup |= BRW_WM_IZ_DEPTH_TEST_ENABLE_BIT; |
| 620 | key.iz_lookup |= BRW_WM_IZ_DEPTH_WRITE_ENABLE_BIT; |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 621 | } |
| 622 | |
Timothy Arceri | 17e28a1 | 2016-10-19 13:45:18 +1100 | [diff] [blame] | 623 | if (brw->gen < 6 || _mesa_bitcount_64(prog->info.inputs_read & |
Timothy Arceri | 7627fbd | 2016-10-05 16:45:27 +1100 | [diff] [blame] | 624 | BRW_FS_VARYING_INPUT_MASK) > 16) { |
Timothy Arceri | 17e28a1 | 2016-10-19 13:45:18 +1100 | [diff] [blame] | 625 | key.input_slots_valid = prog->info.inputs_read | VARYING_BIT_POS; |
Timothy Arceri | 7627fbd | 2016-10-05 16:45:27 +1100 | [diff] [blame] | 626 | } |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 627 | |
Timothy Arceri | 3423488 | 2016-10-19 13:23:37 +1100 | [diff] [blame] | 628 | brw_setup_tex_for_precompile(brw, &key.tex, prog); |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 629 | |
Timothy Arceri | 7ef8286 | 2016-10-05 16:24:56 +1100 | [diff] [blame] | 630 | key.nr_color_regions = _mesa_bitcount_64(outputs_written & |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 631 | ~(BITFIELD64_BIT(FRAG_RESULT_DEPTH) | |
Francisco Jerez | c8f5bd2 | 2016-08-22 18:50:41 -0700 | [diff] [blame] | 632 | BITFIELD64_BIT(FRAG_RESULT_STENCIL) | |
| 633 | BITFIELD64_BIT(FRAG_RESULT_SAMPLE_MASK))); |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 634 | |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 635 | key.program_string_id = bfp->id; |
| 636 | |
Francisco Jerez | 40b23ad | 2016-07-21 20:32:12 -0700 | [diff] [blame] | 637 | /* Whether reads from the framebuffer should behave coherently. */ |
| 638 | key.coherent_fb_fetch = ctx->Extensions.MESA_shader_framebuffer_fetch; |
| 639 | |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 640 | uint32_t old_prog_offset = brw->wm.base.prog_offset; |
Kenneth Graunke | 16d5536 | 2016-09-08 23:48:53 -0700 | [diff] [blame] | 641 | struct brw_stage_prog_data *old_prog_data = brw->wm.base.prog_data; |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 642 | |
Timothy Arceri | 91d61fb | 2016-10-20 09:59:00 +1100 | [diff] [blame] | 643 | struct brw_vue_map vue_map; |
| 644 | if (brw->gen < 6) { |
| 645 | brw_compute_vue_map(&brw->screen->devinfo, &vue_map, |
Timothy Arceri | 17e28a1 | 2016-10-19 13:45:18 +1100 | [diff] [blame] | 646 | prog->info.inputs_read | VARYING_BIT_POS, |
Timothy Arceri | 91d61fb | 2016-10-20 09:59:00 +1100 | [diff] [blame] | 647 | false); |
| 648 | } |
| 649 | |
Timothy Arceri | 6e3f609 | 2016-11-04 16:04:01 +1100 | [diff] [blame] | 650 | bool success = brw_codegen_wm_prog(brw, bfp, &key, &vue_map); |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 651 | |
| 652 | brw->wm.base.prog_offset = old_prog_offset; |
Kenneth Graunke | 16d5536 | 2016-09-08 23:48:53 -0700 | [diff] [blame] | 653 | brw->wm.base.prog_data = old_prog_data; |
Kristian Høgsberg Kristensen | 84f2ed2 | 2015-09-04 16:55:03 -0700 | [diff] [blame] | 654 | |
| 655 | return success; |
| 656 | } |