Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2010 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | */ |
| 23 | |
Kenneth Graunke | ec44d56 | 2013-09-17 23:32:10 -0700 | [diff] [blame] | 24 | /** @file brw_fs_generator.cpp |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 25 | * |
Kenneth Graunke | ec44d56 | 2013-09-17 23:32:10 -0700 | [diff] [blame] | 26 | * This file supports generating code from the FS LIR to the actual |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 27 | * native instructions. |
| 28 | */ |
| 29 | |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 30 | #include "brw_eu.h" |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 31 | #include "brw_fs.h" |
Eric Anholt | 5ed57d9 | 2012-10-03 13:03:12 -0700 | [diff] [blame] | 32 | #include "brw_cfg.h" |
Matt Turner | ecac1aa | 2015-11-22 15:30:59 -0800 | [diff] [blame] | 33 | #include "brw_program.h" |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 34 | |
Matt Turner | d74dd70 | 2015-10-23 13:11:44 -0700 | [diff] [blame] | 35 | static enum brw_reg_file |
| 36 | brw_file_from_reg(fs_reg *reg) |
Matt Turner | c0e26c5 | 2014-12-05 09:53:11 -0800 | [diff] [blame] | 37 | { |
| 38 | switch (reg->file) { |
Matt Turner | b3315a6 | 2015-10-26 17:52:57 -0700 | [diff] [blame] | 39 | case ARF: |
| 40 | return BRW_ARCHITECTURE_REGISTER_FILE; |
| 41 | case FIXED_GRF: |
Matt Turner | b163aa0 | 2015-10-26 17:09:25 -0700 | [diff] [blame] | 42 | case VGRF: |
Matt Turner | c0e26c5 | 2014-12-05 09:53:11 -0800 | [diff] [blame] | 43 | return BRW_GENERAL_REGISTER_FILE; |
| 44 | case MRF: |
| 45 | return BRW_MESSAGE_REGISTER_FILE; |
| 46 | case IMM: |
| 47 | return BRW_IMMEDIATE_VALUE; |
Matt Turner | 7c81a6a | 2015-10-26 06:58:56 -0700 | [diff] [blame] | 48 | case BAD_FILE: |
Matt Turner | 7c81a6a | 2015-10-26 06:58:56 -0700 | [diff] [blame] | 49 | case ATTR: |
| 50 | case UNIFORM: |
Matt Turner | c0e26c5 | 2014-12-05 09:53:11 -0800 | [diff] [blame] | 51 | unreachable("not reached"); |
| 52 | } |
Matt Turner | d74dd70 | 2015-10-23 13:11:44 -0700 | [diff] [blame] | 53 | return BRW_ARCHITECTURE_REGISTER_FILE; |
Matt Turner | c0e26c5 | 2014-12-05 09:53:11 -0800 | [diff] [blame] | 54 | } |
| 55 | |
Matt Turner | db186f2 | 2014-11-28 12:21:03 -0800 | [diff] [blame] | 56 | static struct brw_reg |
Kenneth Graunke | dabaf4f | 2016-05-18 19:02:45 -0700 | [diff] [blame] | 57 | brw_reg_from_fs_reg(fs_inst *inst, fs_reg *reg, unsigned gen, bool compressed) |
Matt Turner | db186f2 | 2014-11-28 12:21:03 -0800 | [diff] [blame] | 58 | { |
| 59 | struct brw_reg brw_reg; |
| 60 | |
| 61 | switch (reg->file) { |
Matt Turner | db186f2 | 2014-11-28 12:21:03 -0800 | [diff] [blame] | 62 | case MRF: |
Matt Turner | 0eb3db1 | 2015-11-02 10:23:12 -0800 | [diff] [blame] | 63 | assert((reg->nr & ~BRW_MRF_COMPR4) < BRW_MAX_MRF(gen)); |
Iago Toral Quiroga | 0858610 | 2015-09-16 09:08:19 +0200 | [diff] [blame] | 64 | /* Fallthrough */ |
Matt Turner | b163aa0 | 2015-10-26 17:09:25 -0700 | [diff] [blame] | 65 | case VGRF: |
Matt Turner | db186f2 | 2014-11-28 12:21:03 -0800 | [diff] [blame] | 66 | if (reg->stride == 0) { |
Matt Turner | 7638e75 | 2015-10-26 04:35:14 -0700 | [diff] [blame] | 67 | brw_reg = brw_vec1_reg(brw_file_from_reg(reg), reg->nr, 0); |
Matt Turner | db186f2 | 2014-11-28 12:21:03 -0800 | [diff] [blame] | 68 | } else { |
| 69 | /* From the Haswell PRM: |
| 70 | * |
Francisco Jerez | 0b4cd91 | 2016-05-19 21:43:48 -0700 | [diff] [blame] | 71 | * "VertStride must be used to cross GRF register boundaries. This |
| 72 | * rule implies that elements within a 'Width' cannot cross GRF |
| 73 | * boundaries." |
Matt Turner | db186f2 | 2014-11-28 12:21:03 -0800 | [diff] [blame] | 74 | * |
Francisco Jerez | 0b4cd91 | 2016-05-19 21:43:48 -0700 | [diff] [blame] | 75 | * The maximum width value that could satisfy this restriction is: |
Matt Turner | db186f2 | 2014-11-28 12:21:03 -0800 | [diff] [blame] | 76 | */ |
Francisco Jerez | 0b4cd91 | 2016-05-19 21:43:48 -0700 | [diff] [blame] | 77 | const unsigned reg_width = REG_SIZE / (reg->stride * type_sz(reg->type)); |
| 78 | |
| 79 | /* Because the hardware can only split source regions at a whole |
| 80 | * multiple of width during decompression (i.e. vertically), clamp |
| 81 | * the value obtained above to the physical execution size of a |
| 82 | * single decompressed chunk of the instruction: |
| 83 | */ |
| 84 | const unsigned phys_width = compressed ? inst->exec_size / 2 : |
| 85 | inst->exec_size; |
| 86 | |
| 87 | /* XXX - The equation above is strictly speaking not correct on |
| 88 | * hardware that supports unbalanced GRF writes -- On Gen9+ |
| 89 | * each decompressed chunk of the instruction may have a |
| 90 | * different execution size when the number of components |
| 91 | * written to each destination GRF is not the same. |
| 92 | */ |
| 93 | const unsigned width = MIN2(reg_width, phys_width); |
| 94 | brw_reg = brw_vecn_reg(width, brw_file_from_reg(reg), reg->nr, 0); |
| 95 | brw_reg = stride(brw_reg, width * reg->stride, width, reg->stride); |
Matt Turner | db186f2 | 2014-11-28 12:21:03 -0800 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | brw_reg = retype(brw_reg, reg->type); |
Francisco Jerez | 1a4b7fd | 2016-09-01 21:25:18 -0700 | [diff] [blame] | 99 | brw_reg = byte_offset(brw_reg, reg->offset); |
Matt Turner | 94b1031 | 2015-10-24 15:29:03 -0700 | [diff] [blame] | 100 | brw_reg.abs = reg->abs; |
| 101 | brw_reg.negate = reg->negate; |
Matt Turner | db186f2 | 2014-11-28 12:21:03 -0800 | [diff] [blame] | 102 | break; |
Matt Turner | b3315a6 | 2015-10-26 17:52:57 -0700 | [diff] [blame] | 103 | case ARF: |
| 104 | case FIXED_GRF: |
Matt Turner | a5b3115 | 2015-11-02 12:25:24 -0800 | [diff] [blame] | 105 | case IMM: |
Francisco Jerez | 1a4b7fd | 2016-09-01 21:25:18 -0700 | [diff] [blame] | 106 | assert(reg->offset == 0); |
Matt Turner | 2d8c529 | 2015-11-19 21:51:37 -0800 | [diff] [blame] | 107 | brw_reg = reg->as_brw_reg(); |
Matt Turner | db186f2 | 2014-11-28 12:21:03 -0800 | [diff] [blame] | 108 | break; |
| 109 | case BAD_FILE: |
| 110 | /* Probably unused. */ |
| 111 | brw_reg = brw_null_reg(); |
| 112 | break; |
Matt Turner | 7c81a6a | 2015-10-26 06:58:56 -0700 | [diff] [blame] | 113 | case ATTR: |
| 114 | case UNIFORM: |
Matt Turner | db186f2 | 2014-11-28 12:21:03 -0800 | [diff] [blame] | 115 | unreachable("not reached"); |
| 116 | } |
Matt Turner | db186f2 | 2014-11-28 12:21:03 -0800 | [diff] [blame] | 117 | |
| 118 | return brw_reg; |
| 119 | } |
| 120 | |
Jason Ekstrand | d7565b7 | 2015-04-16 14:34:04 -0700 | [diff] [blame] | 121 | fs_generator::fs_generator(const struct brw_compiler *compiler, void *log_data, |
Kenneth Graunke | 2d4ac9b | 2014-05-14 01:21:02 -0700 | [diff] [blame] | 122 | void *mem_ctx, |
Kristian Høgsberg | 7bb9d33 | 2014-10-20 22:53:31 -0700 | [diff] [blame] | 123 | const void *key, |
| 124 | struct brw_stage_prog_data *prog_data, |
Matt Turner | b0d422c | 2015-03-16 12:18:31 -0700 | [diff] [blame] | 125 | unsigned promoted_constants, |
Kenneth Graunke | 68ed14d | 2015-01-13 14:28:13 -0800 | [diff] [blame] | 126 | bool runtime_check_aads_emit, |
Jason Ekstrand | 9870f79 | 2016-01-14 20:27:51 -0800 | [diff] [blame] | 127 | gl_shader_stage stage) |
Kenneth Graunke | ea681a0 | 2012-11-09 01:05:47 -0800 | [diff] [blame] | 128 | |
Jason Ekstrand | d7565b7 | 2015-04-16 14:34:04 -0700 | [diff] [blame] | 129 | : compiler(compiler), log_data(log_data), |
| 130 | devinfo(compiler->devinfo), key(key), |
Kristian Høgsberg | 686ef09 | 2014-10-27 19:43:31 -0700 | [diff] [blame] | 131 | prog_data(prog_data), |
Jason Ekstrand | 5e86f5b | 2015-10-05 16:01:33 -0700 | [diff] [blame] | 132 | promoted_constants(promoted_constants), |
Matt Turner | b0d422c | 2015-03-16 12:18:31 -0700 | [diff] [blame] | 133 | runtime_check_aads_emit(runtime_check_aads_emit), debug_flag(false), |
Jason Ekstrand | 9870f79 | 2016-01-14 20:27:51 -0800 | [diff] [blame] | 134 | stage(stage), mem_ctx(mem_ctx) |
Kenneth Graunke | ea681a0 | 2012-11-09 01:05:47 -0800 | [diff] [blame] | 135 | { |
Jason Ekstrand | a85c4c9 | 2015-04-16 11:06:57 -0700 | [diff] [blame] | 136 | p = rzalloc(mem_ctx, struct brw_codegen); |
| 137 | brw_init_codegen(devinfo, p, mem_ctx); |
Kenneth Graunke | ea681a0 | 2012-11-09 01:05:47 -0800 | [diff] [blame] | 138 | } |
| 139 | |
| 140 | fs_generator::~fs_generator() |
| 141 | { |
| 142 | } |
| 143 | |
Matt Turner | 279c1c8 | 2014-11-12 11:01:16 -0800 | [diff] [blame] | 144 | class ip_record : public exec_node { |
| 145 | public: |
| 146 | DECLARE_RALLOC_CXX_OPERATORS(ip_record) |
| 147 | |
| 148 | ip_record(int ip) |
| 149 | { |
| 150 | this->ip = ip; |
| 151 | } |
| 152 | |
| 153 | int ip; |
| 154 | }; |
| 155 | |
Matt Turner | b5fd762 | 2014-05-16 13:06:45 -0700 | [diff] [blame] | 156 | bool |
Eric Anholt | beafced | 2012-12-06 10:15:08 -0800 | [diff] [blame] | 157 | fs_generator::patch_discard_jumps_to_fb_writes() |
| 158 | { |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 159 | if (devinfo->gen < 6 || this->discard_halt_patches.is_empty()) |
Matt Turner | b5fd762 | 2014-05-16 13:06:45 -0700 | [diff] [blame] | 160 | return false; |
Eric Anholt | beafced | 2012-12-06 10:15:08 -0800 | [diff] [blame] | 161 | |
Jason Ekstrand | 4e9c79c | 2015-04-14 18:00:06 -0700 | [diff] [blame] | 162 | int scale = brw_jump_scale(p->devinfo); |
Kenneth Graunke | 82ddd51 | 2014-06-30 08:00:25 -0700 | [diff] [blame] | 163 | |
Eric Anholt | beafced | 2012-12-06 10:15:08 -0800 | [diff] [blame] | 164 | /* There is a somewhat strange undocumented requirement of using |
| 165 | * HALT, according to the simulator. If some channel has HALTed to |
| 166 | * a particular UIP, then by the end of the program, every channel |
| 167 | * must have HALTed to that UIP. Furthermore, the tracking is a |
| 168 | * stack, so you can't do the final halt of a UIP after starting |
| 169 | * halting to a new UIP. |
| 170 | * |
| 171 | * Symptoms of not emitting this instruction on actual hardware |
| 172 | * included GPU hangs and sparkly rendering on the piglit discard |
| 173 | * tests. |
| 174 | */ |
Matt Turner | 7c79608 | 2014-06-13 14:29:25 -0700 | [diff] [blame] | 175 | brw_inst *last_halt = gen6_HALT(p); |
Jason Ekstrand | 4e9c79c | 2015-04-14 18:00:06 -0700 | [diff] [blame] | 176 | brw_inst_set_uip(p->devinfo, last_halt, 1 * scale); |
| 177 | brw_inst_set_jip(p->devinfo, last_halt, 1 * scale); |
Eric Anholt | beafced | 2012-12-06 10:15:08 -0800 | [diff] [blame] | 178 | |
| 179 | int ip = p->nr_insn; |
| 180 | |
Matt Turner | c5030ac | 2014-06-24 15:53:19 -0700 | [diff] [blame] | 181 | foreach_in_list(ip_record, patch_ip, &discard_halt_patches) { |
Matt Turner | 7c79608 | 2014-06-13 14:29:25 -0700 | [diff] [blame] | 182 | brw_inst *patch = &p->store[patch_ip->ip]; |
Eric Anholt | beafced | 2012-12-06 10:15:08 -0800 | [diff] [blame] | 183 | |
Jason Ekstrand | 4e9c79c | 2015-04-14 18:00:06 -0700 | [diff] [blame] | 184 | assert(brw_inst_opcode(p->devinfo, patch) == BRW_OPCODE_HALT); |
Eric Anholt | beafced | 2012-12-06 10:15:08 -0800 | [diff] [blame] | 185 | /* HALT takes a half-instruction distance from the pre-incremented IP. */ |
Jason Ekstrand | 4e9c79c | 2015-04-14 18:00:06 -0700 | [diff] [blame] | 186 | brw_inst_set_uip(p->devinfo, patch, (ip - patch_ip->ip) * scale); |
Eric Anholt | beafced | 2012-12-06 10:15:08 -0800 | [diff] [blame] | 187 | } |
| 188 | |
| 189 | this->discard_halt_patches.make_empty(); |
Matt Turner | b5fd762 | 2014-05-16 13:06:45 -0700 | [diff] [blame] | 190 | return true; |
Eric Anholt | beafced | 2012-12-06 10:15:08 -0800 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | void |
Iago Toral Quiroga | dc2d3a7 | 2014-06-05 15:03:08 +0200 | [diff] [blame] | 194 | fs_generator::fire_fb_write(fs_inst *inst, |
Jason Ekstrand | 8b0e4b3 | 2014-09-16 15:16:20 -0700 | [diff] [blame] | 195 | struct brw_reg payload, |
Iago Toral Quiroga | dc2d3a7 | 2014-06-05 15:03:08 +0200 | [diff] [blame] | 196 | struct brw_reg implied_header, |
| 197 | GLuint nr) |
| 198 | { |
| 199 | uint32_t msg_control; |
| 200 | |
Kenneth Graunke | e51e055 | 2016-09-08 23:48:51 -0700 | [diff] [blame] | 201 | struct brw_wm_prog_data *prog_data = brw_wm_prog_data(this->prog_data); |
Jordan Justen | c43ae40 | 2014-08-29 12:50:46 -0700 | [diff] [blame] | 202 | |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 203 | if (devinfo->gen < 6) { |
Kenneth Graunke | a2ad771 | 2014-06-10 18:50:03 -0700 | [diff] [blame] | 204 | brw_push_insn_state(p); |
Matt Turner | dd5c825 | 2015-04-14 12:40:34 -0700 | [diff] [blame] | 205 | brw_set_default_exec_size(p, BRW_EXECUTE_8); |
Kenneth Graunke | a2ad771 | 2014-06-10 18:50:03 -0700 | [diff] [blame] | 206 | brw_set_default_mask_control(p, BRW_MASK_DISABLE); |
| 207 | brw_set_default_predicate_control(p, BRW_PREDICATE_NONE); |
| 208 | brw_set_default_compression_control(p, BRW_COMPRESSION_NONE); |
Jason Ekstrand | 8b0e4b3 | 2014-09-16 15:16:20 -0700 | [diff] [blame] | 209 | brw_MOV(p, offset(payload, 1), brw_vec8_grf(1, 0)); |
Kenneth Graunke | a2ad771 | 2014-06-10 18:50:03 -0700 | [diff] [blame] | 210 | brw_pop_insn_state(p); |
Iago Toral Quiroga | dc2d3a7 | 2014-06-05 15:03:08 +0200 | [diff] [blame] | 211 | } |
| 212 | |
Kristian Høgsberg | f9dc7aa | 2014-07-07 15:27:17 -0700 | [diff] [blame] | 213 | if (inst->opcode == FS_OPCODE_REP_FB_WRITE) |
| 214 | msg_control = BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE_REPLICATED; |
Iago Toral Quiroga | a72fb69 | 2015-03-05 09:43:38 +0100 | [diff] [blame] | 215 | else if (prog_data->dual_src_blend) { |
Francisco Jerez | ece41df | 2016-05-20 16:14:13 -0700 | [diff] [blame] | 216 | if (!inst->group) |
Iago Toral Quiroga | a72fb69 | 2015-03-05 09:43:38 +0100 | [diff] [blame] | 217 | msg_control = BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01; |
| 218 | else |
| 219 | msg_control = BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN23; |
Francisco Jerez | fa75f2d | 2015-07-13 15:41:34 +0300 | [diff] [blame] | 220 | } else if (inst->exec_size == 16) |
Iago Toral Quiroga | dc2d3a7 | 2014-06-05 15:03:08 +0200 | [diff] [blame] | 221 | msg_control = BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE; |
| 222 | else |
| 223 | msg_control = BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01; |
| 224 | |
| 225 | uint32_t surf_index = |
| 226 | prog_data->binding_table.render_target_start + inst->target; |
| 227 | |
Iago Toral Quiroga | a72fb69 | 2015-03-05 09:43:38 +0100 | [diff] [blame] | 228 | bool last_render_target = inst->eot || |
| 229 | (prog_data->dual_src_blend && dispatch_width == 16); |
| 230 | |
| 231 | |
Iago Toral Quiroga | dc2d3a7 | 2014-06-05 15:03:08 +0200 | [diff] [blame] | 232 | brw_fb_WRITE(p, |
Jason Ekstrand | 8b0e4b3 | 2014-09-16 15:16:20 -0700 | [diff] [blame] | 233 | payload, |
Iago Toral Quiroga | dc2d3a7 | 2014-06-05 15:03:08 +0200 | [diff] [blame] | 234 | implied_header, |
| 235 | msg_control, |
| 236 | surf_index, |
| 237 | nr, |
| 238 | 0, |
| 239 | inst->eot, |
Iago Toral Quiroga | a72fb69 | 2015-03-05 09:43:38 +0100 | [diff] [blame] | 240 | last_render_target, |
Jason Ekstrand | 76c1086 | 2015-03-24 10:17:32 -0700 | [diff] [blame] | 241 | inst->header_size != 0); |
Iago Toral Quiroga | dc2d3a7 | 2014-06-05 15:03:08 +0200 | [diff] [blame] | 242 | |
| 243 | brw_mark_surface_used(&prog_data->base, surf_index); |
| 244 | } |
| 245 | |
| 246 | void |
Jason Ekstrand | 8b0e4b3 | 2014-09-16 15:16:20 -0700 | [diff] [blame] | 247 | fs_generator::generate_fb_write(fs_inst *inst, struct brw_reg payload) |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 248 | { |
Kenneth Graunke | e51e055 | 2016-09-08 23:48:51 -0700 | [diff] [blame] | 249 | struct brw_wm_prog_data *prog_data = brw_wm_prog_data(this->prog_data); |
Jordan Justen | 1f184bc | 2014-08-29 12:50:46 -0700 | [diff] [blame] | 250 | const brw_wm_prog_key * const key = (brw_wm_prog_key * const) this->key; |
Jason Ekstrand | 8b0e4b3 | 2014-09-16 15:16:20 -0700 | [diff] [blame] | 251 | struct brw_reg implied_header; |
| 252 | |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 253 | if (devinfo->gen < 8 && !devinfo->is_haswell) { |
Matt Turner | e4d0299 | 2014-11-11 18:02:23 -0800 | [diff] [blame] | 254 | brw_set_default_predicate_control(p, BRW_PREDICATE_NONE); |
| 255 | } |
| 256 | |
Jason Ekstrand | 8b0e4b3 | 2014-09-16 15:16:20 -0700 | [diff] [blame] | 257 | if (inst->base_mrf >= 0) |
| 258 | payload = brw_message_reg(inst->base_mrf); |
Jordan Justen | c43ae40 | 2014-08-29 12:50:46 -0700 | [diff] [blame] | 259 | |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 260 | /* Header is 2 regs, g0 and g1 are the contents. g0 will be implied |
| 261 | * move, here's g1. |
| 262 | */ |
Jason Ekstrand | 76c1086 | 2015-03-24 10:17:32 -0700 | [diff] [blame] | 263 | if (inst->header_size != 0) { |
Kenneth Graunke | b207caf | 2014-06-10 18:54:09 -0700 | [diff] [blame] | 264 | brw_push_insn_state(p); |
| 265 | brw_set_default_mask_control(p, BRW_MASK_DISABLE); |
| 266 | brw_set_default_predicate_control(p, BRW_PREDICATE_NONE); |
| 267 | brw_set_default_compression_control(p, BRW_COMPRESSION_NONE); |
Kenneth Graunke | efc818e | 2014-08-10 16:15:51 -0700 | [diff] [blame] | 268 | brw_set_default_flag_reg(p, 0, 0); |
Kenneth Graunke | b207caf | 2014-06-10 18:54:09 -0700 | [diff] [blame] | 269 | |
Eric Anholt | d92f593 | 2014-02-13 21:37:50 -0800 | [diff] [blame] | 270 | /* On HSW, the GPU will use the predicate on SENDC, unless the header is |
| 271 | * present. |
| 272 | */ |
Kenneth Graunke | 1332801 | 2014-11-08 02:34:43 -0800 | [diff] [blame] | 273 | if (prog_data->uses_kill) { |
Eric Anholt | d92f593 | 2014-02-13 21:37:50 -0800 | [diff] [blame] | 274 | struct brw_reg pixel_mask; |
| 275 | |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 276 | if (devinfo->gen >= 6) |
Eric Anholt | d92f593 | 2014-02-13 21:37:50 -0800 | [diff] [blame] | 277 | pixel_mask = retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW); |
| 278 | else |
| 279 | pixel_mask = retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW); |
| 280 | |
| 281 | brw_MOV(p, pixel_mask, brw_flag_reg(0, 1)); |
| 282 | } |
| 283 | |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 284 | if (devinfo->gen >= 6) { |
Matt Turner | dd5c825 | 2015-04-14 12:40:34 -0700 | [diff] [blame] | 285 | brw_push_insn_state(p); |
| 286 | brw_set_default_exec_size(p, BRW_EXECUTE_16); |
Kenneth Graunke | e374809 | 2014-05-31 16:57:02 -0700 | [diff] [blame] | 287 | brw_set_default_compression_control(p, BRW_COMPRESSION_COMPRESSED); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 288 | brw_MOV(p, |
Jason Ekstrand | 8b0e4b3 | 2014-09-16 15:16:20 -0700 | [diff] [blame] | 289 | retype(payload, BRW_REGISTER_TYPE_UD), |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 290 | retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD)); |
Matt Turner | dd5c825 | 2015-04-14 12:40:34 -0700 | [diff] [blame] | 291 | brw_pop_insn_state(p); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 292 | |
Kenneth Graunke | c96fdeb | 2014-05-14 00:24:50 -0700 | [diff] [blame] | 293 | if (inst->target > 0 && key->replicate_alpha) { |
Anuj Phogat | e592f7d | 2012-08-01 16:32:06 -0700 | [diff] [blame] | 294 | /* Set "Source0 Alpha Present to RenderTarget" bit in message |
| 295 | * header. |
| 296 | */ |
| 297 | brw_OR(p, |
Jason Ekstrand | 8b0e4b3 | 2014-09-16 15:16:20 -0700 | [diff] [blame] | 298 | vec1(retype(payload, BRW_REGISTER_TYPE_UD)), |
Anuj Phogat | e592f7d | 2012-08-01 16:32:06 -0700 | [diff] [blame] | 299 | vec1(retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD)), |
| 300 | brw_imm_ud(0x1 << 11)); |
| 301 | } |
| 302 | |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 303 | if (inst->target > 0) { |
| 304 | /* Set the render target index for choosing BLEND_STATE. */ |
Jason Ekstrand | 8b0e4b3 | 2014-09-16 15:16:20 -0700 | [diff] [blame] | 305 | brw_MOV(p, retype(vec1(suboffset(payload, 2)), |
| 306 | BRW_REGISTER_TYPE_UD), |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 307 | brw_imm_ud(inst->target)); |
| 308 | } |
| 309 | |
Ben Widawsky | 1db4425 | 2015-10-20 14:29:39 -0700 | [diff] [blame] | 310 | /* Set computes stencil to render target */ |
| 311 | if (prog_data->computed_stencil) { |
| 312 | brw_OR(p, |
| 313 | vec1(retype(payload, BRW_REGISTER_TYPE_UD)), |
| 314 | vec1(retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD)), |
| 315 | brw_imm_ud(0x1 << 14)); |
| 316 | } |
| 317 | |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 318 | implied_header = brw_null_reg(); |
| 319 | } else { |
| 320 | implied_header = retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 321 | } |
Kenneth Graunke | b207caf | 2014-06-10 18:54:09 -0700 | [diff] [blame] | 322 | |
| 323 | brw_pop_insn_state(p); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 324 | } else { |
| 325 | implied_header = brw_null_reg(); |
| 326 | } |
| 327 | |
Iago Toral Quiroga | dc2d3a7 | 2014-06-05 15:03:08 +0200 | [diff] [blame] | 328 | if (!runtime_check_aads_emit) { |
Jason Ekstrand | 8b0e4b3 | 2014-09-16 15:16:20 -0700 | [diff] [blame] | 329 | fire_fb_write(inst, payload, implied_header, inst->mlen); |
Iago Toral Quiroga | dc2d3a7 | 2014-06-05 15:03:08 +0200 | [diff] [blame] | 330 | } else { |
| 331 | /* This can only happen in gen < 6 */ |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 332 | assert(devinfo->gen < 6); |
Iago Toral Quiroga | dc2d3a7 | 2014-06-05 15:03:08 +0200 | [diff] [blame] | 333 | |
| 334 | struct brw_reg v1_null_ud = vec1(retype(brw_null_reg(), BRW_REGISTER_TYPE_UD)); |
| 335 | |
| 336 | /* Check runtime bit to detect if we have to send AA data or not */ |
| 337 | brw_set_default_compression_control(p, BRW_COMPRESSION_NONE); |
| 338 | brw_AND(p, |
| 339 | v1_null_ud, |
| 340 | retype(brw_vec1_grf(1, 6), BRW_REGISTER_TYPE_UD), |
| 341 | brw_imm_ud(1<<26)); |
Jason Ekstrand | 4e9c79c | 2015-04-14 18:00:06 -0700 | [diff] [blame] | 342 | brw_inst_set_cond_modifier(p->devinfo, brw_last_inst, BRW_CONDITIONAL_NZ); |
Iago Toral Quiroga | dc2d3a7 | 2014-06-05 15:03:08 +0200 | [diff] [blame] | 343 | |
| 344 | int jmp = brw_JMPI(p, brw_imm_ud(0), BRW_PREDICATE_NORMAL) - p->store; |
Jason Ekstrand | 4e9c79c | 2015-04-14 18:00:06 -0700 | [diff] [blame] | 345 | brw_inst_set_exec_size(p->devinfo, brw_last_inst, BRW_EXECUTE_1); |
Iago Toral Quiroga | dc2d3a7 | 2014-06-05 15:03:08 +0200 | [diff] [blame] | 346 | { |
| 347 | /* Don't send AA data */ |
Jason Ekstrand | 8b0e4b3 | 2014-09-16 15:16:20 -0700 | [diff] [blame] | 348 | fire_fb_write(inst, offset(payload, 1), implied_header, inst->mlen-1); |
Iago Toral Quiroga | dc2d3a7 | 2014-06-05 15:03:08 +0200 | [diff] [blame] | 349 | } |
| 350 | brw_land_fwd_jump(p, jmp); |
Jason Ekstrand | 8b0e4b3 | 2014-09-16 15:16:20 -0700 | [diff] [blame] | 351 | fire_fb_write(inst, payload, implied_header, inst->mlen); |
Iago Toral Quiroga | dc2d3a7 | 2014-06-05 15:03:08 +0200 | [diff] [blame] | 352 | } |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Topi Pohjolainen | 9927d7a | 2013-12-17 14:00:50 +0200 | [diff] [blame] | 355 | void |
Francisco Jerez | f2f75b0 | 2016-07-21 16:52:33 -0700 | [diff] [blame] | 356 | fs_generator::generate_fb_read(fs_inst *inst, struct brw_reg dst, |
| 357 | struct brw_reg payload) |
| 358 | { |
Francisco Jerez | 69570bb | 2016-09-07 13:38:20 -0700 | [diff] [blame] | 359 | assert(inst->size_written % REG_SIZE == 0); |
Kenneth Graunke | e51e055 | 2016-09-08 23:48:51 -0700 | [diff] [blame] | 360 | struct brw_wm_prog_data *prog_data = brw_wm_prog_data(this->prog_data); |
Francisco Jerez | f2f75b0 | 2016-07-21 16:52:33 -0700 | [diff] [blame] | 361 | const unsigned surf_index = |
| 362 | prog_data->binding_table.render_target_start + inst->target; |
| 363 | |
| 364 | gen9_fb_READ(p, dst, payload, surf_index, |
Francisco Jerez | 69570bb | 2016-09-07 13:38:20 -0700 | [diff] [blame] | 365 | inst->header_size, inst->size_written / REG_SIZE, |
Francisco Jerez | f2f75b0 | 2016-07-21 16:52:33 -0700 | [diff] [blame] | 366 | prog_data->persample_dispatch); |
| 367 | |
| 368 | brw_mark_surface_used(&prog_data->base, surf_index); |
| 369 | } |
| 370 | |
| 371 | void |
Kenneth Graunke | d2f089b | 2015-11-07 18:58:34 -0800 | [diff] [blame] | 372 | fs_generator::generate_mov_indirect(fs_inst *inst, |
| 373 | struct brw_reg dst, |
| 374 | struct brw_reg reg, |
| 375 | struct brw_reg indirect_byte_offset) |
| 376 | { |
| 377 | assert(indirect_byte_offset.type == BRW_REGISTER_TYPE_UD); |
| 378 | assert(indirect_byte_offset.file == BRW_GENERAL_REGISTER_FILE); |
| 379 | |
| 380 | unsigned imm_byte_offset = reg.nr * REG_SIZE + reg.subnr; |
| 381 | |
Jason Ekstrand | 27bd8ac | 2015-11-24 09:01:11 -0800 | [diff] [blame] | 382 | if (indirect_byte_offset.file == BRW_IMMEDIATE_VALUE) { |
| 383 | imm_byte_offset += indirect_byte_offset.ud; |
Kenneth Graunke | d2f089b | 2015-11-07 18:58:34 -0800 | [diff] [blame] | 384 | |
Jason Ekstrand | 27bd8ac | 2015-11-24 09:01:11 -0800 | [diff] [blame] | 385 | reg.nr = imm_byte_offset / REG_SIZE; |
| 386 | reg.subnr = imm_byte_offset % REG_SIZE; |
| 387 | brw_MOV(p, dst, reg); |
| 388 | } else { |
| 389 | /* Prior to Broadwell, there are only 8 address registers. */ |
| 390 | assert(inst->exec_size == 8 || devinfo->gen >= 8); |
Kenneth Graunke | d2f089b | 2015-11-07 18:58:34 -0800 | [diff] [blame] | 391 | |
Jason Ekstrand | 27bd8ac | 2015-11-24 09:01:11 -0800 | [diff] [blame] | 392 | /* We use VxH indirect addressing, clobbering a0.0 through a0.7. */ |
| 393 | struct brw_reg addr = vec8(brw_address_reg(0)); |
Kenneth Graunke | d2f089b | 2015-11-07 18:58:34 -0800 | [diff] [blame] | 394 | |
Jason Ekstrand | 27bd8ac | 2015-11-24 09:01:11 -0800 | [diff] [blame] | 395 | /* The destination stride of an instruction (in bytes) must be greater |
| 396 | * than or equal to the size of the rest of the instruction. Since the |
| 397 | * address register is of type UW, we can't use a D-type instruction. |
| 398 | * In order to get around this, re retype to UW and use a stride. |
| 399 | */ |
| 400 | indirect_byte_offset = |
| 401 | retype(spread(indirect_byte_offset, 2), BRW_REGISTER_TYPE_UW); |
| 402 | |
Jason Ekstrand | 2a4a868 | 2016-10-28 14:48:53 -0700 | [diff] [blame] | 403 | /* There are a number of reasons why we don't use the base offset here. |
| 404 | * One reason is that the field is only 9 bits which means we can only |
| 405 | * use it to access the first 16 GRFs. Also, from the Haswell PRM |
| 406 | * section "Register Region Restrictions": |
| 407 | * |
| 408 | * "The lower bits of the AddressImmediate must not overflow to |
| 409 | * change the register address. The lower 5 bits of Address |
| 410 | * Immediate when added to lower 5 bits of address register gives |
| 411 | * the sub-register offset. The upper bits of Address Immediate |
| 412 | * when added to upper bits of address register gives the register |
| 413 | * address. Any overflow from sub-register offset is dropped." |
| 414 | * |
| 415 | * Since the indirect may cause us to cross a register boundary, this |
| 416 | * makes the base offset almost useless. We could try and do something |
| 417 | * clever where we use a actual base offset if base_offset % 32 == 0 but |
| 418 | * that would mean we were generating different code depending on the |
| 419 | * base offset. Instead, for the sake of consistency, we'll just do the |
| 420 | * add ourselves. This restriction is only listed in the Haswell PRM |
| 421 | * but empirical testing indicates that it applies on all older |
| 422 | * generations and is lifted on Broadwell. |
| 423 | * |
| 424 | * In the end, while base_offset is nice to look at in the generated |
| 425 | * code, using it saves us 0 instructions and would require quite a bit |
| 426 | * of case-by-case work. It's just not worth it. |
| 427 | */ |
| 428 | brw_ADD(p, addr, indirect_byte_offset, brw_imm_uw(imm_byte_offset)); |
| 429 | struct brw_reg ind_src = brw_VxH_indirect(0, 0); |
Jason Ekstrand | 27bd8ac | 2015-11-24 09:01:11 -0800 | [diff] [blame] | 430 | |
| 431 | brw_inst *mov = brw_MOV(p, dst, retype(ind_src, dst.type)); |
| 432 | |
| 433 | if (devinfo->gen == 6 && dst.file == BRW_MESSAGE_REGISTER_FILE && |
| 434 | !inst->get_next()->is_tail_sentinel() && |
| 435 | ((fs_inst *)inst->get_next())->mlen > 0) { |
| 436 | /* From the Sandybridge PRM: |
| 437 | * |
| 438 | * "[Errata: DevSNB(SNB)] If MRF register is updated by any |
| 439 | * instruction that “indexed/indirect” source AND is followed by a |
| 440 | * send, the instruction requires a “Switch”. This is to avoid |
| 441 | * race condition where send may dispatch before MRF is updated." |
| 442 | */ |
| 443 | brw_inst_set_thread_control(devinfo, mov, BRW_THREAD_SWITCH); |
| 444 | } |
| 445 | } |
Kenneth Graunke | d2f089b | 2015-11-07 18:58:34 -0800 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | void |
Kenneth Graunke | ac98888 | 2015-09-29 14:32:02 -0700 | [diff] [blame] | 449 | fs_generator::generate_urb_read(fs_inst *inst, |
| 450 | struct brw_reg dst, |
| 451 | struct brw_reg header) |
| 452 | { |
Francisco Jerez | 69570bb | 2016-09-07 13:38:20 -0700 | [diff] [blame] | 453 | assert(inst->size_written % REG_SIZE == 0); |
Kenneth Graunke | ac98888 | 2015-09-29 14:32:02 -0700 | [diff] [blame] | 454 | assert(header.file == BRW_GENERAL_REGISTER_FILE); |
| 455 | assert(header.type == BRW_REGISTER_TYPE_UD); |
| 456 | |
| 457 | brw_inst *send = brw_next_insn(p, BRW_OPCODE_SEND); |
Kenneth Graunke | ed3ba65 | 2016-06-08 16:24:50 -0700 | [diff] [blame] | 458 | brw_set_dest(p, send, retype(dst, BRW_REGISTER_TYPE_UD)); |
Kenneth Graunke | ac98888 | 2015-09-29 14:32:02 -0700 | [diff] [blame] | 459 | brw_set_src0(p, send, header); |
| 460 | brw_set_src1(p, send, brw_imm_ud(0u)); |
| 461 | |
| 462 | brw_inst_set_sfid(p->devinfo, send, BRW_SFID_URB); |
| 463 | brw_inst_set_urb_opcode(p->devinfo, send, GEN8_URB_OPCODE_SIMD8_READ); |
| 464 | |
Kenneth Graunke | 5480bbd | 2015-11-07 01:37:33 -0800 | [diff] [blame] | 465 | if (inst->opcode == SHADER_OPCODE_URB_READ_SIMD8_PER_SLOT) |
| 466 | brw_inst_set_urb_per_slot_offset(p->devinfo, send, true); |
| 467 | |
Kenneth Graunke | ac98888 | 2015-09-29 14:32:02 -0700 | [diff] [blame] | 468 | brw_inst_set_mlen(p->devinfo, send, inst->mlen); |
Francisco Jerez | 69570bb | 2016-09-07 13:38:20 -0700 | [diff] [blame] | 469 | brw_inst_set_rlen(p->devinfo, send, inst->size_written / REG_SIZE); |
Kenneth Graunke | ac98888 | 2015-09-29 14:32:02 -0700 | [diff] [blame] | 470 | brw_inst_set_header_present(p->devinfo, send, true); |
| 471 | brw_inst_set_urb_global_offset(p->devinfo, send, inst->offset); |
| 472 | } |
| 473 | |
| 474 | void |
Kristian Høgsberg | d9e29f5 | 2014-10-20 23:00:50 -0700 | [diff] [blame] | 475 | fs_generator::generate_urb_write(fs_inst *inst, struct brw_reg payload) |
| 476 | { |
| 477 | brw_inst *insn; |
| 478 | |
| 479 | insn = brw_next_insn(p, BRW_OPCODE_SEND); |
| 480 | |
| 481 | brw_set_dest(p, insn, brw_null_reg()); |
| 482 | brw_set_src0(p, insn, payload); |
| 483 | brw_set_src1(p, insn, brw_imm_d(0)); |
| 484 | |
Jason Ekstrand | 4e9c79c | 2015-04-14 18:00:06 -0700 | [diff] [blame] | 485 | brw_inst_set_sfid(p->devinfo, insn, BRW_SFID_URB); |
| 486 | brw_inst_set_urb_opcode(p->devinfo, insn, GEN8_URB_OPCODE_SIMD8_WRITE); |
Kristian Høgsberg | d9e29f5 | 2014-10-20 23:00:50 -0700 | [diff] [blame] | 487 | |
Kenneth Graunke | bea7522 | 2015-05-06 00:04:10 -0700 | [diff] [blame] | 488 | if (inst->opcode == SHADER_OPCODE_URB_WRITE_SIMD8_PER_SLOT || |
| 489 | inst->opcode == SHADER_OPCODE_URB_WRITE_SIMD8_MASKED_PER_SLOT) |
| 490 | brw_inst_set_urb_per_slot_offset(p->devinfo, insn, true); |
| 491 | |
| 492 | if (inst->opcode == SHADER_OPCODE_URB_WRITE_SIMD8_MASKED || |
| 493 | inst->opcode == SHADER_OPCODE_URB_WRITE_SIMD8_MASKED_PER_SLOT) |
| 494 | brw_inst_set_urb_channel_mask_present(p->devinfo, insn, true); |
| 495 | |
Jason Ekstrand | 4e9c79c | 2015-04-14 18:00:06 -0700 | [diff] [blame] | 496 | brw_inst_set_mlen(p->devinfo, insn, inst->mlen); |
| 497 | brw_inst_set_rlen(p->devinfo, insn, 0); |
| 498 | brw_inst_set_eot(p->devinfo, insn, inst->eot); |
| 499 | brw_inst_set_header_present(p->devinfo, insn, true); |
| 500 | brw_inst_set_urb_global_offset(p->devinfo, insn, inst->offset); |
Kristian Høgsberg | d9e29f5 | 2014-10-20 23:00:50 -0700 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | void |
Jordan Justen | 2a4df9c | 2014-08-27 11:33:25 -0700 | [diff] [blame] | 504 | fs_generator::generate_cs_terminate(fs_inst *inst, struct brw_reg payload) |
| 505 | { |
| 506 | struct brw_inst *insn; |
| 507 | |
| 508 | insn = brw_next_insn(p, BRW_OPCODE_SEND); |
| 509 | |
Jordan Justen | 7428e6f | 2016-01-31 18:28:42 -0800 | [diff] [blame] | 510 | brw_set_dest(p, insn, retype(brw_null_reg(), BRW_REGISTER_TYPE_UW)); |
Kenneth Graunke | 3171578 | 2017-01-24 00:45:53 -0800 | [diff] [blame^] | 511 | brw_set_src0(p, insn, retype(payload, BRW_REGISTER_TYPE_UW)); |
Jordan Justen | 2a4df9c | 2014-08-27 11:33:25 -0700 | [diff] [blame] | 512 | brw_set_src1(p, insn, brw_imm_d(0)); |
| 513 | |
| 514 | /* Terminate a compute shader by sending a message to the thread spawner. |
| 515 | */ |
| 516 | brw_inst_set_sfid(devinfo, insn, BRW_SFID_THREAD_SPAWNER); |
| 517 | brw_inst_set_mlen(devinfo, insn, 1); |
| 518 | brw_inst_set_rlen(devinfo, insn, 0); |
| 519 | brw_inst_set_eot(devinfo, insn, inst->eot); |
| 520 | brw_inst_set_header_present(devinfo, insn, false); |
| 521 | |
| 522 | brw_inst_set_ts_opcode(devinfo, insn, 0); /* Dereference resource */ |
| 523 | brw_inst_set_ts_request_type(devinfo, insn, 0); /* Root thread */ |
| 524 | |
| 525 | /* Note that even though the thread has a URB resource associated with it, |
| 526 | * we set the "do not dereference URB" bit, because the URB resource is |
| 527 | * managed by the fixed-function unit, so it will free it automatically. |
| 528 | */ |
| 529 | brw_inst_set_ts_resource_select(devinfo, insn, 1); /* Do not dereference URB */ |
| 530 | |
| 531 | brw_inst_set_mask_control(devinfo, insn, BRW_MASK_DISABLE); |
| 532 | } |
| 533 | |
| 534 | void |
Jordan Justen | f7ef8ec | 2014-08-27 11:32:08 -0700 | [diff] [blame] | 535 | fs_generator::generate_barrier(fs_inst *inst, struct brw_reg src) |
| 536 | { |
| 537 | brw_barrier(p, src); |
| 538 | brw_WAIT(p); |
| 539 | } |
| 540 | |
| 541 | void |
Kenneth Graunke | ea681a0 | 2012-11-09 01:05:47 -0800 | [diff] [blame] | 542 | fs_generator::generate_linterp(fs_inst *inst, |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 543 | struct brw_reg dst, struct brw_reg *src) |
| 544 | { |
Matt Turner | 5af0604 | 2015-04-06 17:44:40 -0700 | [diff] [blame] | 545 | /* PLN reads: |
| 546 | * / in SIMD16 \ |
| 547 | * ----------------------------------- |
| 548 | * | src1+0 | src1+1 | src1+2 | src1+3 | |
| 549 | * |-----------------------------------| |
| 550 | * |(x0, x1)|(y0, y1)|(x2, x3)|(y2, y3)| |
| 551 | * ----------------------------------- |
| 552 | * |
| 553 | * but for the LINE/MAC pair, the LINE reads Xs and the MAC reads Ys: |
| 554 | * |
| 555 | * ----------------------------------- |
| 556 | * | src1+0 | src1+1 | src1+2 | src1+3 | |
| 557 | * |-----------------------------------| |
| 558 | * |(x0, x1)|(y0, y1)| | | in SIMD8 |
| 559 | * |-----------------------------------| |
| 560 | * |(x0, x1)|(x2, x3)|(y0, y1)|(y2, y3)| in SIMD16 |
| 561 | * ----------------------------------- |
| 562 | * |
| 563 | * See also: emit_interpolation_setup_gen4(). |
| 564 | */ |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 565 | struct brw_reg delta_x = src[0]; |
Francisco Jerez | 448340d | 2016-05-20 00:13:33 -0700 | [diff] [blame] | 566 | struct brw_reg delta_y = offset(src[0], inst->exec_size / 8); |
Matt Turner | 5af0604 | 2015-04-06 17:44:40 -0700 | [diff] [blame] | 567 | struct brw_reg interp = src[1]; |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 568 | |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 569 | if (devinfo->has_pln && |
| 570 | (devinfo->gen >= 7 || (delta_x.nr & 1) == 0)) { |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 571 | brw_PLN(p, dst, interp, delta_x); |
| 572 | } else { |
| 573 | brw_LINE(p, brw_null_reg(), interp, delta_x); |
| 574 | brw_MAC(p, dst, suboffset(interp, 1), delta_y); |
| 575 | } |
| 576 | } |
| 577 | |
| 578 | void |
Samuel Iglesias Gonsalvez | b23eb64 | 2015-04-13 16:55:49 +0200 | [diff] [blame] | 579 | fs_generator::generate_get_buffer_size(fs_inst *inst, |
| 580 | struct brw_reg dst, |
| 581 | struct brw_reg src, |
| 582 | struct brw_reg surf_index) |
| 583 | { |
| 584 | assert(devinfo->gen >= 7); |
| 585 | assert(surf_index.file == BRW_IMMEDIATE_VALUE); |
| 586 | |
| 587 | uint32_t simd_mode; |
| 588 | int rlen = 4; |
| 589 | |
| 590 | switch (inst->exec_size) { |
| 591 | case 8: |
| 592 | simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD8; |
| 593 | break; |
| 594 | case 16: |
| 595 | simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16; |
| 596 | break; |
| 597 | default: |
| 598 | unreachable("Invalid width for texture instruction"); |
| 599 | } |
| 600 | |
| 601 | if (simd_mode == BRW_SAMPLER_SIMD_MODE_SIMD16) { |
| 602 | rlen = 8; |
| 603 | dst = vec16(dst); |
| 604 | } |
| 605 | |
| 606 | brw_SAMPLE(p, |
| 607 | retype(dst, BRW_REGISTER_TYPE_UW), |
| 608 | inst->base_mrf, |
| 609 | src, |
Matt Turner | e42fb0c | 2015-10-22 19:41:30 -0700 | [diff] [blame] | 610 | surf_index.ud, |
Samuel Iglesias Gonsalvez | b23eb64 | 2015-04-13 16:55:49 +0200 | [diff] [blame] | 611 | 0, |
| 612 | GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO, |
| 613 | rlen, /* response length */ |
| 614 | inst->mlen, |
| 615 | inst->header_size > 0, |
| 616 | simd_mode, |
| 617 | BRW_SAMPLER_RETURN_FORMAT_SINT32); |
Matt Turner | e42fb0c | 2015-10-22 19:41:30 -0700 | [diff] [blame] | 618 | |
| 619 | brw_mark_surface_used(prog_data, surf_index.ud); |
Samuel Iglesias Gonsalvez | b23eb64 | 2015-04-13 16:55:49 +0200 | [diff] [blame] | 620 | } |
| 621 | |
| 622 | void |
Chris Forbes | ba5f7a3 | 2014-08-03 21:23:31 +1200 | [diff] [blame] | 623 | fs_generator::generate_tex(fs_inst *inst, struct brw_reg dst, struct brw_reg src, |
Jason Ekstrand | c0c14de | 2015-11-02 15:24:05 -0800 | [diff] [blame] | 624 | struct brw_reg surface_index, |
Chris Forbes | ba5f7a3 | 2014-08-03 21:23:31 +1200 | [diff] [blame] | 625 | struct brw_reg sampler_index) |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 626 | { |
Francisco Jerez | 69570bb | 2016-09-07 13:38:20 -0700 | [diff] [blame] | 627 | assert(inst->size_written % REG_SIZE == 0); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 628 | int msg_type = -1; |
Jason Ekstrand | 30d718c | 2014-08-29 17:22:57 -0700 | [diff] [blame] | 629 | uint32_t simd_mode; |
Eric Anholt | 7e84a64 | 2011-11-09 16:07:57 -0800 | [diff] [blame] | 630 | uint32_t return_format; |
Ben Widawsky | b069f9e | 2015-02-08 13:59:57 -0800 | [diff] [blame] | 631 | bool is_combined_send = inst->eot; |
Eric Anholt | 7e84a64 | 2011-11-09 16:07:57 -0800 | [diff] [blame] | 632 | |
| 633 | switch (dst.type) { |
| 634 | case BRW_REGISTER_TYPE_D: |
| 635 | return_format = BRW_SAMPLER_RETURN_FORMAT_SINT32; |
| 636 | break; |
| 637 | case BRW_REGISTER_TYPE_UD: |
| 638 | return_format = BRW_SAMPLER_RETURN_FORMAT_UINT32; |
| 639 | break; |
| 640 | default: |
| 641 | return_format = BRW_SAMPLER_RETURN_FORMAT_FLOAT32; |
| 642 | break; |
| 643 | } |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 644 | |
Jason Ekstrand | d065a93 | 2015-11-11 15:46:55 -0800 | [diff] [blame] | 645 | /* Stomp the resinfo output type to UINT32. On gens 4-5, the output type |
| 646 | * is set as part of the message descriptor. On gen4, the PRM seems to |
| 647 | * allow UINT32 and FLOAT32 (i965 PRM, Vol. 4 Section 4.8.1.1), but on |
| 648 | * later gens UINT32 is required. Once you hit Sandy Bridge, the bit is |
| 649 | * gone from the message descriptor entirely and you just get UINT32 all |
| 650 | * the time regasrdless. Since we can really only do non-UINT32 on gen4, |
| 651 | * just stomp it to UINT32 all the time. |
| 652 | */ |
| 653 | if (inst->opcode == SHADER_OPCODE_TXS) |
| 654 | return_format = BRW_SAMPLER_RETURN_FORMAT_UINT32; |
| 655 | |
Jason Ekstrand | 30d718c | 2014-08-29 17:22:57 -0700 | [diff] [blame] | 656 | switch (inst->exec_size) { |
| 657 | case 8: |
| 658 | simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD8; |
| 659 | break; |
| 660 | case 16: |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 661 | simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16; |
Jason Ekstrand | 30d718c | 2014-08-29 17:22:57 -0700 | [diff] [blame] | 662 | break; |
| 663 | default: |
| 664 | unreachable("Invalid width for texture instruction"); |
| 665 | } |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 666 | |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 667 | if (devinfo->gen >= 5) { |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 668 | switch (inst->opcode) { |
Kenneth Graunke | febad17 | 2011-10-26 12:58:37 -0700 | [diff] [blame] | 669 | case SHADER_OPCODE_TEX: |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 670 | if (inst->shadow_compare) { |
| 671 | msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_COMPARE; |
| 672 | } else { |
| 673 | msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE; |
| 674 | } |
| 675 | break; |
| 676 | case FS_OPCODE_TXB: |
| 677 | if (inst->shadow_compare) { |
| 678 | msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS_COMPARE; |
| 679 | } else { |
| 680 | msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS; |
| 681 | } |
| 682 | break; |
Kenneth Graunke | febad17 | 2011-10-26 12:58:37 -0700 | [diff] [blame] | 683 | case SHADER_OPCODE_TXL: |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 684 | if (inst->shadow_compare) { |
| 685 | msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE; |
| 686 | } else { |
| 687 | msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LOD; |
| 688 | } |
| 689 | break; |
Matt Turner | 75dccf5 | 2016-05-04 15:46:45 -0700 | [diff] [blame] | 690 | case SHADER_OPCODE_TXL_LZ: |
| 691 | assert(devinfo->gen >= 9); |
| 692 | if (inst->shadow_compare) { |
| 693 | msg_type = GEN9_SAMPLER_MESSAGE_SAMPLE_C_LZ; |
| 694 | } else { |
| 695 | msg_type = GEN9_SAMPLER_MESSAGE_SAMPLE_LZ; |
| 696 | } |
| 697 | break; |
Kenneth Graunke | febad17 | 2011-10-26 12:58:37 -0700 | [diff] [blame] | 698 | case SHADER_OPCODE_TXS: |
Kenneth Graunke | ecf8963 | 2011-06-19 01:47:50 -0700 | [diff] [blame] | 699 | msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO; |
| 700 | break; |
Kenneth Graunke | febad17 | 2011-10-26 12:58:37 -0700 | [diff] [blame] | 701 | case SHADER_OPCODE_TXD: |
Kenneth Graunke | 899017f | 2013-01-04 07:53:09 -0800 | [diff] [blame] | 702 | if (inst->shadow_compare) { |
Iago Toral Quiroga | 44873ad | 2016-11-30 11:45:59 +0100 | [diff] [blame] | 703 | /* Gen7.5+. Otherwise, lowered in NIR */ |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 704 | assert(devinfo->gen >= 8 || devinfo->is_haswell); |
Kenneth Graunke | 899017f | 2013-01-04 07:53:09 -0800 | [diff] [blame] | 705 | msg_type = HSW_SAMPLER_MESSAGE_SAMPLE_DERIV_COMPARE; |
| 706 | } else { |
| 707 | msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS; |
| 708 | } |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 709 | break; |
Kenneth Graunke | febad17 | 2011-10-26 12:58:37 -0700 | [diff] [blame] | 710 | case SHADER_OPCODE_TXF: |
Kenneth Graunke | 30be2cc | 2011-08-25 17:13:37 -0700 | [diff] [blame] | 711 | msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LD; |
| 712 | break; |
Matt Turner | 75dccf5 | 2016-05-04 15:46:45 -0700 | [diff] [blame] | 713 | case SHADER_OPCODE_TXF_LZ: |
| 714 | assert(devinfo->gen >= 9); |
| 715 | msg_type = GEN9_SAMPLER_MESSAGE_SAMPLE_LD_LZ; |
| 716 | break; |
Neil Roberts | e386fb0 | 2015-09-08 15:52:09 +0100 | [diff] [blame] | 717 | case SHADER_OPCODE_TXF_CMS_W: |
| 718 | assert(devinfo->gen >= 9); |
| 719 | msg_type = GEN9_SAMPLER_MESSAGE_SAMPLE_LD2DMS_W; |
| 720 | break; |
Topi Pohjolainen | ce527a6 | 2013-12-10 16:36:31 +0200 | [diff] [blame] | 721 | case SHADER_OPCODE_TXF_CMS: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 722 | if (devinfo->gen >= 7) |
Chris Forbes | f52ce6a | 2013-01-24 21:35:15 +1300 | [diff] [blame] | 723 | msg_type = GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DMS; |
| 724 | else |
| 725 | msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LD; |
| 726 | break; |
Topi Pohjolainen | 41d397f | 2013-12-10 16:38:15 +0200 | [diff] [blame] | 727 | case SHADER_OPCODE_TXF_UMS: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 728 | assert(devinfo->gen >= 7); |
Topi Pohjolainen | 41d397f | 2013-12-10 16:38:15 +0200 | [diff] [blame] | 729 | msg_type = GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DSS; |
| 730 | break; |
Chris Forbes | 7629c48 | 2013-11-30 10:32:16 +1300 | [diff] [blame] | 731 | case SHADER_OPCODE_TXF_MCS: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 732 | assert(devinfo->gen >= 7); |
Chris Forbes | 7629c48 | 2013-11-30 10:32:16 +1300 | [diff] [blame] | 733 | msg_type = GEN7_SAMPLER_MESSAGE_SAMPLE_LD_MCS; |
| 734 | break; |
Matt Turner | b8aa9f7 | 2013-03-06 14:47:01 -0800 | [diff] [blame] | 735 | case SHADER_OPCODE_LOD: |
| 736 | msg_type = GEN5_SAMPLER_MESSAGE_LOD; |
| 737 | break; |
Chris Forbes | fb45550 | 2013-03-31 21:31:12 +1300 | [diff] [blame] | 738 | case SHADER_OPCODE_TG4: |
Chris Forbes | 3c98d77 | 2013-10-10 19:57:29 +1300 | [diff] [blame] | 739 | if (inst->shadow_compare) { |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 740 | assert(devinfo->gen >= 7); |
Chris Forbes | 3c98d77 | 2013-10-10 19:57:29 +1300 | [diff] [blame] | 741 | msg_type = GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_C; |
| 742 | } else { |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 743 | assert(devinfo->gen >= 6); |
Chris Forbes | 3c98d77 | 2013-10-10 19:57:29 +1300 | [diff] [blame] | 744 | msg_type = GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4; |
| 745 | } |
Chris Forbes | fb45550 | 2013-03-31 21:31:12 +1300 | [diff] [blame] | 746 | break; |
Chris Forbes | 6bb2cf2 | 2013-10-08 21:42:10 +1300 | [diff] [blame] | 747 | case SHADER_OPCODE_TG4_OFFSET: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 748 | assert(devinfo->gen >= 7); |
Chris Forbes | 3c98d77 | 2013-10-10 19:57:29 +1300 | [diff] [blame] | 749 | if (inst->shadow_compare) { |
| 750 | msg_type = GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO_C; |
| 751 | } else { |
| 752 | msg_type = GEN7_SAMPLER_MESSAGE_SAMPLE_GATHER4_PO; |
| 753 | } |
Chris Forbes | 6bb2cf2 | 2013-10-08 21:42:10 +1300 | [diff] [blame] | 754 | break; |
Ilia Mirkin | 0b91bce | 2015-08-11 20:37:32 -0400 | [diff] [blame] | 755 | case SHADER_OPCODE_SAMPLEINFO: |
| 756 | msg_type = GEN6_SAMPLER_MESSAGE_SAMPLE_SAMPLEINFO; |
| 757 | break; |
Eric Anholt | 6034b9a | 2011-05-03 10:55:50 -0700 | [diff] [blame] | 758 | default: |
Matt Turner | 3d82672 | 2014-06-29 14:54:01 -0700 | [diff] [blame] | 759 | unreachable("not reached"); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 760 | } |
| 761 | } else { |
| 762 | switch (inst->opcode) { |
Kenneth Graunke | febad17 | 2011-10-26 12:58:37 -0700 | [diff] [blame] | 763 | case SHADER_OPCODE_TEX: |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 764 | /* Note that G45 and older determines shadow compare and dispatch width |
| 765 | * from message length for most messages. |
| 766 | */ |
Francisco Jerez | 8fbb3d3 | 2015-07-13 15:42:20 +0300 | [diff] [blame] | 767 | if (inst->exec_size == 8) { |
Kenneth Graunke | 797d606 | 2015-02-20 15:11:49 -0800 | [diff] [blame] | 768 | msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE; |
| 769 | if (inst->shadow_compare) { |
| 770 | assert(inst->mlen == 6); |
| 771 | } else { |
| 772 | assert(inst->mlen <= 4); |
| 773 | } |
| 774 | } else { |
| 775 | if (inst->shadow_compare) { |
| 776 | msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_COMPARE; |
| 777 | assert(inst->mlen == 9); |
| 778 | } else { |
| 779 | msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE; |
| 780 | assert(inst->mlen <= 7 && inst->mlen % 2 == 1); |
| 781 | } |
| 782 | } |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 783 | break; |
| 784 | case FS_OPCODE_TXB: |
| 785 | if (inst->shadow_compare) { |
Francisco Jerez | 8fbb3d3 | 2015-07-13 15:42:20 +0300 | [diff] [blame] | 786 | assert(inst->exec_size == 8); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 787 | assert(inst->mlen == 6); |
| 788 | msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_BIAS_COMPARE; |
| 789 | } else { |
| 790 | assert(inst->mlen == 9); |
| 791 | msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS; |
| 792 | simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16; |
| 793 | } |
| 794 | break; |
Kenneth Graunke | febad17 | 2011-10-26 12:58:37 -0700 | [diff] [blame] | 795 | case SHADER_OPCODE_TXL: |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 796 | if (inst->shadow_compare) { |
Francisco Jerez | 8fbb3d3 | 2015-07-13 15:42:20 +0300 | [diff] [blame] | 797 | assert(inst->exec_size == 8); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 798 | assert(inst->mlen == 6); |
| 799 | msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_LOD_COMPARE; |
| 800 | } else { |
| 801 | assert(inst->mlen == 9); |
| 802 | msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD; |
| 803 | simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16; |
| 804 | } |
| 805 | break; |
Kenneth Graunke | febad17 | 2011-10-26 12:58:37 -0700 | [diff] [blame] | 806 | case SHADER_OPCODE_TXD: |
Kenneth Graunke | 6430df3 | 2011-06-10 14:48:46 -0700 | [diff] [blame] | 807 | /* There is no sample_d_c message; comparisons are done manually */ |
Francisco Jerez | 8fbb3d3 | 2015-07-13 15:42:20 +0300 | [diff] [blame] | 808 | assert(inst->exec_size == 8); |
Kenneth Graunke | 6c947cf | 2011-06-08 16:05:34 -0700 | [diff] [blame] | 809 | assert(inst->mlen == 7 || inst->mlen == 10); |
| 810 | msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS; |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 811 | break; |
Kenneth Graunke | febad17 | 2011-10-26 12:58:37 -0700 | [diff] [blame] | 812 | case SHADER_OPCODE_TXF: |
Kenneth Graunke | 797d606 | 2015-02-20 15:11:49 -0800 | [diff] [blame] | 813 | assert(inst->mlen <= 9 && inst->mlen % 2 == 1); |
Kenneth Graunke | 47b556f | 2011-09-06 16:39:01 -0700 | [diff] [blame] | 814 | msg_type = BRW_SAMPLER_MESSAGE_SIMD16_LD; |
| 815 | simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16; |
| 816 | break; |
Kenneth Graunke | febad17 | 2011-10-26 12:58:37 -0700 | [diff] [blame] | 817 | case SHADER_OPCODE_TXS: |
Kenneth Graunke | 4eeb4c1 | 2011-08-17 10:45:47 -0700 | [diff] [blame] | 818 | assert(inst->mlen == 3); |
| 819 | msg_type = BRW_SAMPLER_MESSAGE_SIMD16_RESINFO; |
| 820 | simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16; |
| 821 | break; |
Eric Anholt | 6034b9a | 2011-05-03 10:55:50 -0700 | [diff] [blame] | 822 | default: |
Matt Turner | 3d82672 | 2014-06-29 14:54:01 -0700 | [diff] [blame] | 823 | unreachable("not reached"); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 824 | } |
| 825 | } |
| 826 | assert(msg_type != -1); |
| 827 | |
| 828 | if (simd_mode == BRW_SAMPLER_SIMD_MODE_SIMD16) { |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 829 | dst = vec16(dst); |
| 830 | } |
| 831 | |
Jason Ekstrand | 76c1086 | 2015-03-24 10:17:32 -0700 | [diff] [blame] | 832 | assert(devinfo->gen < 7 || inst->header_size == 0 || |
Jason Ekstrand | 7210583 | 2014-08-18 14:27:55 -0700 | [diff] [blame] | 833 | src.file == BRW_GENERAL_REGISTER_FILE); |
Eric Anholt | 36fbe66 | 2013-10-09 17:17:59 -0700 | [diff] [blame] | 834 | |
Chris Forbes | ba5f7a3 | 2014-08-03 21:23:31 +1200 | [diff] [blame] | 835 | assert(sampler_index.type == BRW_REGISTER_TYPE_UD); |
| 836 | |
Kenneth Graunke | 82bfb4b | 2012-08-04 20:33:13 -0700 | [diff] [blame] | 837 | /* Load the message header if present. If there's a texture offset, |
| 838 | * we need to set it up explicitly and load the offset bitfield. |
| 839 | * Otherwise, we can use an implied move from g0 to the first message reg. |
| 840 | */ |
Jason Ekstrand | 76c1086 | 2015-03-24 10:17:32 -0700 | [diff] [blame] | 841 | if (inst->header_size != 0) { |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 842 | if (devinfo->gen < 6 && !inst->offset) { |
Kenneth Graunke | ebfe43d | 2014-01-18 12:48:18 -0800 | [diff] [blame] | 843 | /* Set up an implied move from g0 to the MRF. */ |
| 844 | src = retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW); |
Eric Anholt | 36fbe66 | 2013-10-09 17:17:59 -0700 | [diff] [blame] | 845 | } else { |
Kenneth Graunke | ebfe43d | 2014-01-18 12:48:18 -0800 | [diff] [blame] | 846 | struct brw_reg header_reg; |
Kenneth Graunke | 82bfb4b | 2012-08-04 20:33:13 -0700 | [diff] [blame] | 847 | |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 848 | if (devinfo->gen >= 7) { |
Kenneth Graunke | ebfe43d | 2014-01-18 12:48:18 -0800 | [diff] [blame] | 849 | header_reg = src; |
| 850 | } else { |
| 851 | assert(inst->base_mrf != -1); |
| 852 | header_reg = brw_message_reg(inst->base_mrf); |
| 853 | } |
| 854 | |
Chris Forbes | b38af01 | 2013-10-13 12:20:03 +1300 | [diff] [blame] | 855 | brw_push_insn_state(p); |
Matt Turner | dd5c825 | 2015-04-14 12:40:34 -0700 | [diff] [blame] | 856 | brw_set_default_exec_size(p, BRW_EXECUTE_8); |
Kenneth Graunke | e374809 | 2014-05-31 16:57:02 -0700 | [diff] [blame] | 857 | brw_set_default_mask_control(p, BRW_MASK_DISABLE); |
| 858 | brw_set_default_compression_control(p, BRW_COMPRESSION_NONE); |
Kenneth Graunke | ebfe43d | 2014-01-18 12:48:18 -0800 | [diff] [blame] | 859 | /* Explicitly set up the message header by copying g0 to the MRF. */ |
| 860 | brw_MOV(p, header_reg, brw_vec8_grf(0, 0)); |
| 861 | |
Matt Turner | bd50213 | 2014-11-12 11:28:02 -0800 | [diff] [blame] | 862 | if (inst->offset) { |
Kenneth Graunke | ebfe43d | 2014-01-18 12:48:18 -0800 | [diff] [blame] | 863 | /* Set the offset bits in DWord 2. */ |
| 864 | brw_MOV(p, get_element_ud(header_reg, 2), |
Matt Turner | bd50213 | 2014-11-12 11:28:02 -0800 | [diff] [blame] | 865 | brw_imm_ud(inst->offset)); |
Jason Ekstrand | 61b0cfd | 2016-01-14 20:42:47 -0800 | [diff] [blame] | 866 | } else if (stage != MESA_SHADER_VERTEX && |
| 867 | stage != MESA_SHADER_FRAGMENT) { |
| 868 | /* The vertex and fragment stages have g0.2 set to 0, so |
| 869 | * header0.2 is 0 when g0 is copied. Other stages may not, so we |
| 870 | * must set it to 0 to avoid setting undesirable bits in the |
| 871 | * message. |
| 872 | */ |
| 873 | brw_MOV(p, get_element_ud(header_reg, 2), brw_imm_ud(0)); |
Kenneth Graunke | ebfe43d | 2014-01-18 12:48:18 -0800 | [diff] [blame] | 874 | } |
Kenneth Graunke | 6943ac0 | 2014-01-18 13:29:39 -0800 | [diff] [blame] | 875 | |
Jason Ekstrand | 7de8a3e | 2015-01-22 13:46:44 -0800 | [diff] [blame] | 876 | brw_adjust_sampler_state_pointer(p, header_reg, sampler_index); |
Chris Forbes | b38af01 | 2013-10-13 12:20:03 +1300 | [diff] [blame] | 877 | brw_pop_insn_state(p); |
Chris Forbes | b38af01 | 2013-10-13 12:20:03 +1300 | [diff] [blame] | 878 | } |
Kenneth Graunke | 82bfb4b | 2012-08-04 20:33:13 -0700 | [diff] [blame] | 879 | } |
| 880 | |
Chris Forbes | 4ba5171 | 2014-08-10 11:58:06 +1200 | [diff] [blame] | 881 | uint32_t base_binding_table_index = (inst->opcode == SHADER_OPCODE_TG4 || |
| 882 | inst->opcode == SHADER_OPCODE_TG4_OFFSET) |
Jordan Justen | c43ae40 | 2014-08-29 12:50:46 -0700 | [diff] [blame] | 883 | ? prog_data->binding_table.gather_texture_start |
| 884 | : prog_data->binding_table.texture_start; |
Chris Forbes | dd4c2a5 | 2013-09-15 18:23:14 +1200 | [diff] [blame] | 885 | |
Jason Ekstrand | c0c14de | 2015-11-02 15:24:05 -0800 | [diff] [blame] | 886 | if (surface_index.file == BRW_IMMEDIATE_VALUE && |
| 887 | sampler_index.file == BRW_IMMEDIATE_VALUE) { |
| 888 | uint32_t surface = surface_index.ud; |
Matt Turner | e42fb0c | 2015-10-22 19:41:30 -0700 | [diff] [blame] | 889 | uint32_t sampler = sampler_index.ud; |
Kenneth Graunke | 6d89bc8 | 2013-08-14 19:49:33 -0700 | [diff] [blame] | 890 | |
Chris Forbes | 4ba5171 | 2014-08-10 11:58:06 +1200 | [diff] [blame] | 891 | brw_SAMPLE(p, |
| 892 | retype(dst, BRW_REGISTER_TYPE_UW), |
| 893 | inst->base_mrf, |
| 894 | src, |
Jason Ekstrand | c0c14de | 2015-11-02 15:24:05 -0800 | [diff] [blame] | 895 | surface + base_binding_table_index, |
Chris Forbes | 4ba5171 | 2014-08-10 11:58:06 +1200 | [diff] [blame] | 896 | sampler % 16, |
| 897 | msg_type, |
Francisco Jerez | 69570bb | 2016-09-07 13:38:20 -0700 | [diff] [blame] | 898 | inst->size_written / REG_SIZE, |
Chris Forbes | 4ba5171 | 2014-08-10 11:58:06 +1200 | [diff] [blame] | 899 | inst->mlen, |
Jason Ekstrand | 76c1086 | 2015-03-24 10:17:32 -0700 | [diff] [blame] | 900 | inst->header_size != 0, |
Chris Forbes | 4ba5171 | 2014-08-10 11:58:06 +1200 | [diff] [blame] | 901 | simd_mode, |
| 902 | return_format); |
| 903 | |
Jason Ekstrand | c0c14de | 2015-11-02 15:24:05 -0800 | [diff] [blame] | 904 | brw_mark_surface_used(prog_data, surface + base_binding_table_index); |
Chris Forbes | 4ba5171 | 2014-08-10 11:58:06 +1200 | [diff] [blame] | 905 | } else { |
Chris Forbes | fbfcd67 | 2014-08-10 12:02:22 +1200 | [diff] [blame] | 906 | /* Non-const sampler index */ |
Chris Forbes | fbfcd67 | 2014-08-10 12:02:22 +1200 | [diff] [blame] | 907 | |
| 908 | struct brw_reg addr = vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD)); |
Jason Ekstrand | c0c14de | 2015-11-02 15:24:05 -0800 | [diff] [blame] | 909 | struct brw_reg surface_reg = vec1(retype(surface_index, BRW_REGISTER_TYPE_UD)); |
Chris Forbes | fbfcd67 | 2014-08-10 12:02:22 +1200 | [diff] [blame] | 910 | struct brw_reg sampler_reg = vec1(retype(sampler_index, BRW_REGISTER_TYPE_UD)); |
| 911 | |
| 912 | brw_push_insn_state(p); |
| 913 | brw_set_default_mask_control(p, BRW_MASK_DISABLE); |
| 914 | brw_set_default_access_mode(p, BRW_ALIGN_1); |
| 915 | |
Kenneth Graunke | 59156b2 | 2016-05-13 16:41:13 -0700 | [diff] [blame] | 916 | if (brw_regs_equal(&surface_reg, &sampler_reg)) { |
Jason Ekstrand | c0c14de | 2015-11-02 15:24:05 -0800 | [diff] [blame] | 917 | brw_MUL(p, addr, sampler_reg, brw_imm_uw(0x101)); |
| 918 | } else { |
Jason Ekstrand | 88b5acf | 2016-12-22 15:26:12 -0800 | [diff] [blame] | 919 | if (sampler_reg.file == BRW_IMMEDIATE_VALUE) { |
| 920 | brw_OR(p, addr, surface_reg, brw_imm_ud(sampler_reg.ud << 8)); |
| 921 | } else { |
| 922 | brw_SHL(p, addr, sampler_reg, brw_imm_ud(8)); |
| 923 | brw_OR(p, addr, addr, surface_reg); |
| 924 | } |
Jason Ekstrand | c0c14de | 2015-11-02 15:24:05 -0800 | [diff] [blame] | 925 | } |
Neil Roberts | 7f62fda | 2015-05-29 13:41:48 +0100 | [diff] [blame] | 926 | if (base_binding_table_index) |
| 927 | brw_ADD(p, addr, addr, brw_imm_ud(base_binding_table_index)); |
Neil Roberts | 6c846dc | 2015-05-28 15:27:31 +0100 | [diff] [blame] | 928 | brw_AND(p, addr, addr, brw_imm_ud(0xfff)); |
Chris Forbes | fbfcd67 | 2014-08-10 12:02:22 +1200 | [diff] [blame] | 929 | |
Francisco Jerez | a815cd8 | 2015-02-26 17:24:03 +0200 | [diff] [blame] | 930 | brw_pop_insn_state(p); |
| 931 | |
Francisco Jerez | a902a5d | 2015-03-19 15:44:24 +0200 | [diff] [blame] | 932 | /* dst = send(offset, a0.0 | <descriptor>) */ |
| 933 | brw_inst *insn = brw_send_indirect_message( |
| 934 | p, BRW_SFID_SAMPLER, dst, src, addr); |
| 935 | brw_set_sampler_message(p, insn, |
Chris Forbes | fbfcd67 | 2014-08-10 12:02:22 +1200 | [diff] [blame] | 936 | 0 /* surface */, |
| 937 | 0 /* sampler */, |
| 938 | msg_type, |
Francisco Jerez | 69570bb | 2016-09-07 13:38:20 -0700 | [diff] [blame] | 939 | inst->size_written / REG_SIZE, |
Chris Forbes | fbfcd67 | 2014-08-10 12:02:22 +1200 | [diff] [blame] | 940 | inst->mlen /* mlen */, |
Jason Ekstrand | 76c1086 | 2015-03-24 10:17:32 -0700 | [diff] [blame] | 941 | inst->header_size != 0 /* header */, |
Chris Forbes | fbfcd67 | 2014-08-10 12:02:22 +1200 | [diff] [blame] | 942 | simd_mode, |
| 943 | return_format); |
Chris Forbes | fbfcd67 | 2014-08-10 12:02:22 +1200 | [diff] [blame] | 944 | |
Chris Forbes | fbfcd67 | 2014-08-10 12:02:22 +1200 | [diff] [blame] | 945 | /* visitor knows more than we do about the surface limit required, |
| 946 | * so has already done marking. |
| 947 | */ |
Chris Forbes | 4ba5171 | 2014-08-10 11:58:06 +1200 | [diff] [blame] | 948 | } |
Ben Widawsky | b069f9e | 2015-02-08 13:59:57 -0800 | [diff] [blame] | 949 | |
| 950 | if (is_combined_send) { |
Jason Ekstrand | 4e9c79c | 2015-04-14 18:00:06 -0700 | [diff] [blame] | 951 | brw_inst_set_eot(p->devinfo, brw_last_inst, true); |
| 952 | brw_inst_set_opcode(p->devinfo, brw_last_inst, BRW_OPCODE_SENDC); |
Ben Widawsky | b069f9e | 2015-02-08 13:59:57 -0800 | [diff] [blame] | 953 | } |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 954 | } |
| 955 | |
| 956 | |
| 957 | /* For OPCODE_DDX and OPCODE_DDY, per channel of output we've got input |
| 958 | * looking like: |
| 959 | * |
| 960 | * arg0: ss0.tl ss0.tr ss0.bl ss0.br ss1.tl ss1.tr ss1.bl ss1.br |
| 961 | * |
Chia-I Wu | 848c0e7 | 2013-09-12 13:00:52 +0800 | [diff] [blame] | 962 | * Ideally, we want to produce: |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 963 | * |
| 964 | * DDX DDY |
| 965 | * dst: (ss0.tr - ss0.tl) (ss0.tl - ss0.bl) |
| 966 | * (ss0.tr - ss0.tl) (ss0.tr - ss0.br) |
| 967 | * (ss0.br - ss0.bl) (ss0.tl - ss0.bl) |
| 968 | * (ss0.br - ss0.bl) (ss0.tr - ss0.br) |
| 969 | * (ss1.tr - ss1.tl) (ss1.tl - ss1.bl) |
| 970 | * (ss1.tr - ss1.tl) (ss1.tr - ss1.br) |
| 971 | * (ss1.br - ss1.bl) (ss1.tl - ss1.bl) |
| 972 | * (ss1.br - ss1.bl) (ss1.tr - ss1.br) |
| 973 | * |
| 974 | * and add another set of two more subspans if in 16-pixel dispatch mode. |
| 975 | * |
| 976 | * For DDX, it ends up being easy: width = 2, horiz=0 gets us the same result |
| 977 | * for each pair, and vertstride = 2 jumps us 2 elements after processing a |
Chia-I Wu | 848c0e7 | 2013-09-12 13:00:52 +0800 | [diff] [blame] | 978 | * pair. But the ideal approximation may impose a huge performance cost on |
| 979 | * sample_d. On at least Haswell, sample_d instruction does some |
| 980 | * optimizations if the same LOD is used for all pixels in the subspan. |
| 981 | * |
Paul Berry | 800610f | 2013-09-20 09:04:31 -0700 | [diff] [blame] | 982 | * For DDY, we need to use ALIGN16 mode since it's capable of doing the |
| 983 | * appropriate swizzling. |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 984 | */ |
| 985 | void |
Kenneth Graunke | cea37f0 | 2014-11-08 01:39:14 -0800 | [diff] [blame] | 986 | fs_generator::generate_ddx(enum opcode opcode, |
| 987 | struct brw_reg dst, struct brw_reg src) |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 988 | { |
Chia-I Wu | 848c0e7 | 2013-09-12 13:00:52 +0800 | [diff] [blame] | 989 | unsigned vstride, width; |
| 990 | |
Kenneth Graunke | cea37f0 | 2014-11-08 01:39:14 -0800 | [diff] [blame] | 991 | if (opcode == FS_OPCODE_DDX_FINE) { |
Chia-I Wu | 848c0e7 | 2013-09-12 13:00:52 +0800 | [diff] [blame] | 992 | /* produce accurate derivatives */ |
| 993 | vstride = BRW_VERTICAL_STRIDE_2; |
| 994 | width = BRW_WIDTH_2; |
Kenneth Graunke | cea37f0 | 2014-11-08 01:39:14 -0800 | [diff] [blame] | 995 | } else { |
Chia-I Wu | 848c0e7 | 2013-09-12 13:00:52 +0800 | [diff] [blame] | 996 | /* replicate the derivative at the top-left pixel to other pixels */ |
| 997 | vstride = BRW_VERTICAL_STRIDE_4; |
| 998 | width = BRW_WIDTH_4; |
| 999 | } |
| 1000 | |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1001 | struct brw_reg src0 = brw_reg(src.file, src.nr, 1, |
Andres Gomez | 8517e66 | 2014-12-12 17:19:07 +0100 | [diff] [blame] | 1002 | src.negate, src.abs, |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1003 | BRW_REGISTER_TYPE_F, |
Chia-I Wu | 848c0e7 | 2013-09-12 13:00:52 +0800 | [diff] [blame] | 1004 | vstride, |
| 1005 | width, |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1006 | BRW_HORIZONTAL_STRIDE_0, |
| 1007 | BRW_SWIZZLE_XYZW, WRITEMASK_XYZW); |
| 1008 | struct brw_reg src1 = brw_reg(src.file, src.nr, 0, |
Andres Gomez | 8517e66 | 2014-12-12 17:19:07 +0100 | [diff] [blame] | 1009 | src.negate, src.abs, |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1010 | BRW_REGISTER_TYPE_F, |
Chia-I Wu | 848c0e7 | 2013-09-12 13:00:52 +0800 | [diff] [blame] | 1011 | vstride, |
| 1012 | width, |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1013 | BRW_HORIZONTAL_STRIDE_0, |
| 1014 | BRW_SWIZZLE_XYZW, WRITEMASK_XYZW); |
| 1015 | brw_ADD(p, dst, src0, negate(src1)); |
| 1016 | } |
| 1017 | |
Paul Berry | 82d2596 | 2012-06-20 13:40:45 -0700 | [diff] [blame] | 1018 | /* The negate_value boolean is used to negate the derivative computation for |
| 1019 | * FBOs, since they place the origin at the upper left instead of the lower |
| 1020 | * left. |
| 1021 | */ |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1022 | void |
Kenneth Graunke | cea37f0 | 2014-11-08 01:39:14 -0800 | [diff] [blame] | 1023 | fs_generator::generate_ddy(enum opcode opcode, |
Kenneth Graunke | dac10e8 | 2016-05-17 01:52:16 -0700 | [diff] [blame] | 1024 | struct brw_reg dst, struct brw_reg src) |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1025 | { |
Kenneth Graunke | cea37f0 | 2014-11-08 01:39:14 -0800 | [diff] [blame] | 1026 | if (opcode == FS_OPCODE_DDY_FINE) { |
Paul Berry | 800610f | 2013-09-20 09:04:31 -0700 | [diff] [blame] | 1027 | /* produce accurate derivatives */ |
| 1028 | struct brw_reg src0 = brw_reg(src.file, src.nr, 0, |
Andres Gomez | 8517e66 | 2014-12-12 17:19:07 +0100 | [diff] [blame] | 1029 | src.negate, src.abs, |
Paul Berry | 800610f | 2013-09-20 09:04:31 -0700 | [diff] [blame] | 1030 | BRW_REGISTER_TYPE_F, |
| 1031 | BRW_VERTICAL_STRIDE_4, |
| 1032 | BRW_WIDTH_4, |
| 1033 | BRW_HORIZONTAL_STRIDE_1, |
| 1034 | BRW_SWIZZLE_XYXY, WRITEMASK_XYZW); |
| 1035 | struct brw_reg src1 = brw_reg(src.file, src.nr, 0, |
Andres Gomez | 8517e66 | 2014-12-12 17:19:07 +0100 | [diff] [blame] | 1036 | src.negate, src.abs, |
Paul Berry | 800610f | 2013-09-20 09:04:31 -0700 | [diff] [blame] | 1037 | BRW_REGISTER_TYPE_F, |
| 1038 | BRW_VERTICAL_STRIDE_4, |
| 1039 | BRW_WIDTH_4, |
| 1040 | BRW_HORIZONTAL_STRIDE_1, |
| 1041 | BRW_SWIZZLE_ZWZW, WRITEMASK_XYZW); |
| 1042 | brw_push_insn_state(p); |
Kenneth Graunke | e374809 | 2014-05-31 16:57:02 -0700 | [diff] [blame] | 1043 | brw_set_default_access_mode(p, BRW_ALIGN_16); |
Francisco Jerez | bb89beb | 2016-05-27 23:22:02 -0700 | [diff] [blame] | 1044 | brw_ADD(p, dst, negate(src0), src1); |
Paul Berry | 800610f | 2013-09-20 09:04:31 -0700 | [diff] [blame] | 1045 | brw_pop_insn_state(p); |
| 1046 | } else { |
| 1047 | /* replicate the derivative at the top-left pixel to other pixels */ |
| 1048 | struct brw_reg src0 = brw_reg(src.file, src.nr, 0, |
Andres Gomez | 8517e66 | 2014-12-12 17:19:07 +0100 | [diff] [blame] | 1049 | src.negate, src.abs, |
Paul Berry | 800610f | 2013-09-20 09:04:31 -0700 | [diff] [blame] | 1050 | BRW_REGISTER_TYPE_F, |
| 1051 | BRW_VERTICAL_STRIDE_4, |
| 1052 | BRW_WIDTH_4, |
| 1053 | BRW_HORIZONTAL_STRIDE_0, |
| 1054 | BRW_SWIZZLE_XYZW, WRITEMASK_XYZW); |
| 1055 | struct brw_reg src1 = brw_reg(src.file, src.nr, 2, |
Andres Gomez | 8517e66 | 2014-12-12 17:19:07 +0100 | [diff] [blame] | 1056 | src.negate, src.abs, |
Paul Berry | 800610f | 2013-09-20 09:04:31 -0700 | [diff] [blame] | 1057 | BRW_REGISTER_TYPE_F, |
| 1058 | BRW_VERTICAL_STRIDE_4, |
| 1059 | BRW_WIDTH_4, |
| 1060 | BRW_HORIZONTAL_STRIDE_0, |
| 1061 | BRW_SWIZZLE_XYZW, WRITEMASK_XYZW); |
Kenneth Graunke | 9b8b3f7 | 2016-05-18 10:35:54 -0700 | [diff] [blame] | 1062 | brw_ADD(p, dst, negate(src0), src1); |
Paul Berry | 800610f | 2013-09-20 09:04:31 -0700 | [diff] [blame] | 1063 | } |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
| 1066 | void |
Eric Anholt | beafced | 2012-12-06 10:15:08 -0800 | [diff] [blame] | 1067 | fs_generator::generate_discard_jump(fs_inst *inst) |
| 1068 | { |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1069 | assert(devinfo->gen >= 6); |
Eric Anholt | beafced | 2012-12-06 10:15:08 -0800 | [diff] [blame] | 1070 | |
| 1071 | /* This HALT will be patched up at FB write time to point UIP at the end of |
| 1072 | * the program, and at brw_uip_jip() JIP will be set to the end of the |
| 1073 | * current block (or the program). |
| 1074 | */ |
| 1075 | this->discard_halt_patches.push_tail(new(mem_ctx) ip_record(p->nr_insn)); |
Eric Anholt | beafced | 2012-12-06 10:15:08 -0800 | [diff] [blame] | 1076 | gen6_HALT(p); |
Eric Anholt | beafced | 2012-12-06 10:15:08 -0800 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | void |
Eric Anholt | 6032261 | 2013-10-16 11:45:06 -0700 | [diff] [blame] | 1080 | fs_generator::generate_scratch_write(fs_inst *inst, struct brw_reg src) |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1081 | { |
Francisco Jerez | 1e3c58f | 2016-05-27 23:29:02 -0700 | [diff] [blame] | 1082 | /* The 32-wide messages only respect the first 16-wide half of the channel |
| 1083 | * enable signals which are replicated identically for the second group of |
| 1084 | * 16 channels, so we cannot use them unless the write is marked |
| 1085 | * force_writemask_all. |
| 1086 | */ |
| 1087 | const unsigned lower_size = inst->force_writemask_all ? inst->exec_size : |
| 1088 | MIN2(16, inst->exec_size); |
| 1089 | const unsigned block_size = 4 * lower_size / REG_SIZE; |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1090 | assert(inst->mlen != 0); |
| 1091 | |
Francisco Jerez | 1e3c58f | 2016-05-27 23:29:02 -0700 | [diff] [blame] | 1092 | brw_push_insn_state(p); |
| 1093 | brw_set_default_exec_size(p, cvt(lower_size) - 1); |
| 1094 | brw_set_default_compression(p, lower_size > 8); |
| 1095 | |
| 1096 | for (unsigned i = 0; i < inst->exec_size / lower_size; i++) { |
Francisco Jerez | ece41df | 2016-05-20 16:14:13 -0700 | [diff] [blame] | 1097 | brw_set_default_group(p, inst->group + lower_size * i); |
Francisco Jerez | 1e3c58f | 2016-05-27 23:29:02 -0700 | [diff] [blame] | 1098 | |
| 1099 | brw_MOV(p, brw_uvec_mrf(lower_size, inst->base_mrf + 1, 0), |
| 1100 | retype(offset(src, block_size * i), BRW_REGISTER_TYPE_UD)); |
| 1101 | |
| 1102 | brw_oword_block_write_scratch(p, brw_message_reg(inst->base_mrf), |
| 1103 | block_size, |
| 1104 | inst->offset + block_size * REG_SIZE * i); |
| 1105 | } |
| 1106 | |
| 1107 | brw_pop_insn_state(p); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1108 | } |
| 1109 | |
| 1110 | void |
Eric Anholt | 6032261 | 2013-10-16 11:45:06 -0700 | [diff] [blame] | 1111 | fs_generator::generate_scratch_read(fs_inst *inst, struct brw_reg dst) |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1112 | { |
Francisco Jerez | a7d319c | 2016-05-16 15:47:39 -0700 | [diff] [blame] | 1113 | assert(inst->exec_size <= 16 || inst->force_writemask_all); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1114 | assert(inst->mlen != 0); |
| 1115 | |
Eric Anholt | 0e20051 | 2013-10-16 12:16:51 -0700 | [diff] [blame] | 1116 | brw_oword_block_read_scratch(p, dst, brw_message_reg(inst->base_mrf), |
Jason Ekstrand | 3a5df8b | 2014-10-24 11:35:51 -0700 | [diff] [blame] | 1117 | inst->exec_size / 8, inst->offset); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1118 | } |
| 1119 | |
| 1120 | void |
Eric Anholt | 8dfc9f0 | 2013-10-16 11:51:22 -0700 | [diff] [blame] | 1121 | fs_generator::generate_scratch_read_gen7(fs_inst *inst, struct brw_reg dst) |
| 1122 | { |
Francisco Jerez | a7d319c | 2016-05-16 15:47:39 -0700 | [diff] [blame] | 1123 | assert(inst->exec_size <= 16 || inst->force_writemask_all); |
| 1124 | |
Jason Ekstrand | 3a5df8b | 2014-10-24 11:35:51 -0700 | [diff] [blame] | 1125 | gen7_block_read_scratch(p, dst, inst->exec_size / 8, inst->offset); |
Eric Anholt | 8dfc9f0 | 2013-10-16 11:51:22 -0700 | [diff] [blame] | 1126 | } |
| 1127 | |
| 1128 | void |
Eric Anholt | 29340d0 | 2012-11-07 10:42:34 -0800 | [diff] [blame] | 1129 | fs_generator::generate_uniform_pull_constant_load(fs_inst *inst, |
| 1130 | struct brw_reg dst, |
| 1131 | struct brw_reg index, |
| 1132 | struct brw_reg offset) |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1133 | { |
Francisco Jerez | 9b22a0d | 2016-12-08 20:05:18 -0800 | [diff] [blame] | 1134 | assert(type_sz(dst.type) == 4); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1135 | assert(inst->mlen != 0); |
| 1136 | |
Eric Anholt | 454dc83 | 2012-06-20 15:41:14 -0700 | [diff] [blame] | 1137 | assert(index.file == BRW_IMMEDIATE_VALUE && |
| 1138 | index.type == BRW_REGISTER_TYPE_UD); |
Matt Turner | e42fb0c | 2015-10-22 19:41:30 -0700 | [diff] [blame] | 1139 | uint32_t surf_index = index.ud; |
Eric Anholt | 454dc83 | 2012-06-20 15:41:14 -0700 | [diff] [blame] | 1140 | |
| 1141 | assert(offset.file == BRW_IMMEDIATE_VALUE && |
| 1142 | offset.type == BRW_REGISTER_TYPE_UD); |
Matt Turner | e42fb0c | 2015-10-22 19:41:30 -0700 | [diff] [blame] | 1143 | uint32_t read_offset = offset.ud; |
Eric Anholt | 454dc83 | 2012-06-20 15:41:14 -0700 | [diff] [blame] | 1144 | |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1145 | brw_oword_block_read(p, dst, brw_message_reg(inst->base_mrf), |
Eric Anholt | 454dc83 | 2012-06-20 15:41:14 -0700 | [diff] [blame] | 1146 | read_offset, surf_index); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1147 | } |
| 1148 | |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1149 | void |
Eric Anholt | 461a297 | 2012-12-05 00:06:30 -0800 | [diff] [blame] | 1150 | fs_generator::generate_uniform_pull_constant_load_gen7(fs_inst *inst, |
| 1151 | struct brw_reg dst, |
| 1152 | struct brw_reg index, |
Francisco Jerez | ad38ba1 | 2016-10-26 14:25:06 -0700 | [diff] [blame] | 1153 | struct brw_reg payload) |
Eric Anholt | 461a297 | 2012-12-05 00:06:30 -0800 | [diff] [blame] | 1154 | { |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1155 | assert(index.type == BRW_REGISTER_TYPE_UD); |
Francisco Jerez | ad38ba1 | 2016-10-26 14:25:06 -0700 | [diff] [blame] | 1156 | assert(payload.file == BRW_GENERAL_REGISTER_FILE); |
Francisco Jerez | 9b22a0d | 2016-12-08 20:05:18 -0800 | [diff] [blame] | 1157 | assert(type_sz(dst.type) == 4); |
Kristian Høgsberg | 0ac4c27 | 2014-12-10 14:59:26 -0800 | [diff] [blame] | 1158 | |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1159 | if (index.file == BRW_IMMEDIATE_VALUE) { |
Francisco Jerez | ad38ba1 | 2016-10-26 14:25:06 -0700 | [diff] [blame] | 1160 | const uint32_t surf_index = index.ud; |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1161 | |
| 1162 | brw_push_insn_state(p); |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1163 | brw_set_default_mask_control(p, BRW_MASK_DISABLE); |
| 1164 | brw_inst *send = brw_next_insn(p, BRW_OPCODE_SEND); |
| 1165 | brw_pop_insn_state(p); |
| 1166 | |
Francisco Jerez | 9b22a0d | 2016-12-08 20:05:18 -0800 | [diff] [blame] | 1167 | brw_set_dest(p, send, retype(dst, BRW_REGISTER_TYPE_UD)); |
| 1168 | brw_set_src0(p, send, retype(payload, BRW_REGISTER_TYPE_UD)); |
| 1169 | brw_set_dp_read_message(p, send, surf_index, |
| 1170 | BRW_DATAPORT_OWORD_BLOCK_DWORDS(inst->exec_size), |
Francisco Jerez | ad38ba1 | 2016-10-26 14:25:06 -0700 | [diff] [blame] | 1171 | GEN7_DATAPORT_DC_OWORD_BLOCK_READ, |
| 1172 | GEN6_SFID_DATAPORT_CONSTANT_CACHE, |
| 1173 | 1, /* mlen */ |
| 1174 | true, /* header */ |
Francisco Jerez | 9b22a0d | 2016-12-08 20:05:18 -0800 | [diff] [blame] | 1175 | DIV_ROUND_UP(inst->size_written, REG_SIZE)); |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1176 | |
Francisco Jerez | ad38ba1 | 2016-10-26 14:25:06 -0700 | [diff] [blame] | 1177 | } else { |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1178 | struct brw_reg addr = vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD)); |
| 1179 | |
| 1180 | brw_push_insn_state(p); |
| 1181 | brw_set_default_mask_control(p, BRW_MASK_DISABLE); |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1182 | |
| 1183 | /* a0.0 = surf_index & 0xff */ |
| 1184 | brw_inst *insn_and = brw_next_insn(p, BRW_OPCODE_AND); |
Jason Ekstrand | 4e9c79c | 2015-04-14 18:00:06 -0700 | [diff] [blame] | 1185 | brw_inst_set_exec_size(p->devinfo, insn_and, BRW_EXECUTE_1); |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1186 | brw_set_dest(p, insn_and, addr); |
| 1187 | brw_set_src0(p, insn_and, vec1(retype(index, BRW_REGISTER_TYPE_UD))); |
| 1188 | brw_set_src1(p, insn_and, brw_imm_ud(0x0ff)); |
| 1189 | |
Francisco Jerez | a902a5d | 2015-03-19 15:44:24 +0200 | [diff] [blame] | 1190 | /* dst = send(payload, a0.0 | <descriptor>) */ |
| 1191 | brw_inst *insn = brw_send_indirect_message( |
Francisco Jerez | ad38ba1 | 2016-10-26 14:25:06 -0700 | [diff] [blame] | 1192 | p, GEN6_SFID_DATAPORT_CONSTANT_CACHE, |
Francisco Jerez | 9b22a0d | 2016-12-08 20:05:18 -0800 | [diff] [blame] | 1193 | retype(dst, BRW_REGISTER_TYPE_UD), |
| 1194 | retype(payload, BRW_REGISTER_TYPE_UD), addr); |
| 1195 | brw_set_dp_read_message(p, insn, 0 /* surface */, |
| 1196 | BRW_DATAPORT_OWORD_BLOCK_DWORDS(inst->exec_size), |
Francisco Jerez | ad38ba1 | 2016-10-26 14:25:06 -0700 | [diff] [blame] | 1197 | GEN7_DATAPORT_DC_OWORD_BLOCK_READ, |
| 1198 | GEN6_SFID_DATAPORT_CONSTANT_CACHE, |
| 1199 | 1, /* mlen */ |
| 1200 | true, /* header */ |
Francisco Jerez | 9b22a0d | 2016-12-08 20:05:18 -0800 | [diff] [blame] | 1201 | DIV_ROUND_UP(inst->size_written, REG_SIZE)); |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1202 | |
| 1203 | brw_pop_insn_state(p); |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1204 | } |
Eric Anholt | 461a297 | 2012-12-05 00:06:30 -0800 | [diff] [blame] | 1205 | } |
| 1206 | |
| 1207 | void |
Francisco Jerez | ed4d0e4 | 2016-05-20 13:03:31 -0700 | [diff] [blame] | 1208 | fs_generator::generate_varying_pull_constant_load_gen4(fs_inst *inst, |
| 1209 | struct brw_reg dst, |
| 1210 | struct brw_reg index) |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1211 | { |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1212 | assert(devinfo->gen < 7); /* Should use the gen7 variant. */ |
Jason Ekstrand | 76c1086 | 2015-03-24 10:17:32 -0700 | [diff] [blame] | 1213 | assert(inst->header_size != 0); |
Eric Anholt | 70b27e0 | 2013-03-18 10:16:42 -0700 | [diff] [blame] | 1214 | assert(inst->mlen); |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1215 | |
| 1216 | assert(index.file == BRW_IMMEDIATE_VALUE && |
| 1217 | index.type == BRW_REGISTER_TYPE_UD); |
Matt Turner | e42fb0c | 2015-10-22 19:41:30 -0700 | [diff] [blame] | 1218 | uint32_t surf_index = index.ud; |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1219 | |
Eric Anholt | 70b27e0 | 2013-03-18 10:16:42 -0700 | [diff] [blame] | 1220 | uint32_t simd_mode, rlen, msg_type; |
Francisco Jerez | 448340d | 2016-05-20 00:13:33 -0700 | [diff] [blame] | 1221 | if (inst->exec_size == 16) { |
Eric Anholt | 70b27e0 | 2013-03-18 10:16:42 -0700 | [diff] [blame] | 1222 | simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16; |
| 1223 | rlen = 8; |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1224 | } else { |
Francisco Jerez | 448340d | 2016-05-20 00:13:33 -0700 | [diff] [blame] | 1225 | assert(inst->exec_size == 8); |
Eric Anholt | 70b27e0 | 2013-03-18 10:16:42 -0700 | [diff] [blame] | 1226 | simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD8; |
| 1227 | rlen = 4; |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1228 | } |
| 1229 | |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1230 | if (devinfo->gen >= 5) |
Eric Anholt | 70b27e0 | 2013-03-18 10:16:42 -0700 | [diff] [blame] | 1231 | msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LD; |
| 1232 | else { |
| 1233 | /* We always use the SIMD16 message so that we only have to load U, and |
| 1234 | * not V or R. |
| 1235 | */ |
| 1236 | msg_type = BRW_SAMPLER_MESSAGE_SIMD16_LD; |
| 1237 | assert(inst->mlen == 3); |
Francisco Jerez | 69570bb | 2016-09-07 13:38:20 -0700 | [diff] [blame] | 1238 | assert(inst->size_written == 8 * REG_SIZE); |
Eric Anholt | 70b27e0 | 2013-03-18 10:16:42 -0700 | [diff] [blame] | 1239 | rlen = 8; |
| 1240 | simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16; |
| 1241 | } |
| 1242 | |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1243 | struct brw_reg header = brw_vec8_grf(0, 0); |
| 1244 | gen6_resolve_implied_move(p, &header, inst->base_mrf); |
| 1245 | |
Matt Turner | 7c79608 | 2014-06-13 14:29:25 -0700 | [diff] [blame] | 1246 | brw_inst *send = brw_next_insn(p, BRW_OPCODE_SEND); |
Francisco Jerez | c19c3d3 | 2016-05-18 15:29:27 -0700 | [diff] [blame] | 1247 | brw_inst_set_compression(devinfo, send, false); |
Kenneth Graunke | 71846a9 | 2014-04-16 20:15:23 -0700 | [diff] [blame] | 1248 | brw_set_dest(p, send, retype(dst, BRW_REGISTER_TYPE_UW)); |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1249 | brw_set_src0(p, send, header); |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1250 | if (devinfo->gen < 6) |
Jason Ekstrand | 4e9c79c | 2015-04-14 18:00:06 -0700 | [diff] [blame] | 1251 | brw_inst_set_base_mrf(p->devinfo, send, inst->base_mrf); |
Eric Anholt | 70b27e0 | 2013-03-18 10:16:42 -0700 | [diff] [blame] | 1252 | |
| 1253 | /* Our surface is set up as floats, regardless of what actual data is |
| 1254 | * stored in it. |
| 1255 | */ |
| 1256 | uint32_t return_format = BRW_SAMPLER_RETURN_FORMAT_FLOAT32; |
| 1257 | brw_set_sampler_message(p, send, |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1258 | surf_index, |
Eric Anholt | 70b27e0 | 2013-03-18 10:16:42 -0700 | [diff] [blame] | 1259 | 0, /* sampler (unused) */ |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1260 | msg_type, |
Eric Anholt | 70b27e0 | 2013-03-18 10:16:42 -0700 | [diff] [blame] | 1261 | rlen, |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1262 | inst->mlen, |
Jason Ekstrand | 76c1086 | 2015-03-24 10:17:32 -0700 | [diff] [blame] | 1263 | inst->header_size != 0, |
Eric Anholt | 70b27e0 | 2013-03-18 10:16:42 -0700 | [diff] [blame] | 1264 | simd_mode, |
| 1265 | return_format); |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1266 | } |
| 1267 | |
| 1268 | void |
| 1269 | fs_generator::generate_varying_pull_constant_load_gen7(fs_inst *inst, |
| 1270 | struct brw_reg dst, |
| 1271 | struct brw_reg index, |
| 1272 | struct brw_reg offset) |
| 1273 | { |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1274 | assert(devinfo->gen >= 7); |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1275 | /* Varying-offset pull constant loads are treated as a normal expression on |
| 1276 | * gen7, so the fact that it's a send message is hidden at the IR level. |
| 1277 | */ |
Jason Ekstrand | 76c1086 | 2015-03-24 10:17:32 -0700 | [diff] [blame] | 1278 | assert(inst->header_size == 0); |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1279 | assert(!inst->mlen); |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1280 | assert(index.type == BRW_REGISTER_TYPE_UD); |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1281 | |
Eric Anholt | dca5fc1 | 2013-03-13 14:48:55 -0700 | [diff] [blame] | 1282 | uint32_t simd_mode, rlen, mlen; |
Francisco Jerez | 448340d | 2016-05-20 00:13:33 -0700 | [diff] [blame] | 1283 | if (inst->exec_size == 16) { |
Eric Anholt | dca5fc1 | 2013-03-13 14:48:55 -0700 | [diff] [blame] | 1284 | mlen = 2; |
| 1285 | rlen = 8; |
| 1286 | simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16; |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1287 | } else { |
Francisco Jerez | 448340d | 2016-05-20 00:13:33 -0700 | [diff] [blame] | 1288 | assert(inst->exec_size == 8); |
Eric Anholt | dca5fc1 | 2013-03-13 14:48:55 -0700 | [diff] [blame] | 1289 | mlen = 1; |
| 1290 | rlen = 4; |
| 1291 | simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD8; |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1292 | } |
| 1293 | |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1294 | if (index.file == BRW_IMMEDIATE_VALUE) { |
Kenneth Graunke | 6d89bc8 | 2013-08-14 19:49:33 -0700 | [diff] [blame] | 1295 | |
Matt Turner | e42fb0c | 2015-10-22 19:41:30 -0700 | [diff] [blame] | 1296 | uint32_t surf_index = index.ud; |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1297 | |
| 1298 | brw_inst *send = brw_next_insn(p, BRW_OPCODE_SEND); |
Jason Ekstrand | 1385a4b | 2014-09-08 15:26:24 -0700 | [diff] [blame] | 1299 | brw_set_dest(p, send, retype(dst, BRW_REGISTER_TYPE_UW)); |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1300 | brw_set_src0(p, send, offset); |
| 1301 | brw_set_sampler_message(p, send, |
| 1302 | surf_index, |
| 1303 | 0, /* LD message ignores sampler unit */ |
| 1304 | GEN5_SAMPLER_MESSAGE_SAMPLE_LD, |
| 1305 | rlen, |
| 1306 | mlen, |
| 1307 | false, /* no header */ |
| 1308 | simd_mode, |
| 1309 | 0); |
| 1310 | |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1311 | } else { |
| 1312 | |
| 1313 | struct brw_reg addr = vec1(retype(brw_address_reg(0), BRW_REGISTER_TYPE_UD)); |
| 1314 | |
| 1315 | brw_push_insn_state(p); |
| 1316 | brw_set_default_mask_control(p, BRW_MASK_DISABLE); |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1317 | |
| 1318 | /* a0.0 = surf_index & 0xff */ |
| 1319 | brw_inst *insn_and = brw_next_insn(p, BRW_OPCODE_AND); |
Jason Ekstrand | 4e9c79c | 2015-04-14 18:00:06 -0700 | [diff] [blame] | 1320 | brw_inst_set_exec_size(p->devinfo, insn_and, BRW_EXECUTE_1); |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1321 | brw_set_dest(p, insn_and, addr); |
| 1322 | brw_set_src0(p, insn_and, vec1(retype(index, BRW_REGISTER_TYPE_UD))); |
| 1323 | brw_set_src1(p, insn_and, brw_imm_ud(0x0ff)); |
| 1324 | |
Francisco Jerez | a815cd8 | 2015-02-26 17:24:03 +0200 | [diff] [blame] | 1325 | brw_pop_insn_state(p); |
| 1326 | |
Francisco Jerez | a902a5d | 2015-03-19 15:44:24 +0200 | [diff] [blame] | 1327 | /* dst = send(offset, a0.0 | <descriptor>) */ |
| 1328 | brw_inst *insn = brw_send_indirect_message( |
| 1329 | p, BRW_SFID_SAMPLER, retype(dst, BRW_REGISTER_TYPE_UW), |
| 1330 | offset, addr); |
| 1331 | brw_set_sampler_message(p, insn, |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1332 | 0 /* surface */, |
| 1333 | 0 /* sampler */, |
| 1334 | GEN5_SAMPLER_MESSAGE_SAMPLE_LD, |
| 1335 | rlen /* rlen */, |
| 1336 | mlen /* mlen */, |
| 1337 | false /* header */, |
| 1338 | simd_mode, |
| 1339 | 0); |
Chris Forbes | 3fd359b | 2014-08-02 14:27:21 +1200 | [diff] [blame] | 1340 | } |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1341 | } |
Paul Berry | 3f929ef | 2012-06-18 14:50:04 -0700 | [diff] [blame] | 1342 | |
| 1343 | /** |
| 1344 | * Cause the current pixel/sample mask (from R1.7 bits 15:0) to be transferred |
| 1345 | * into the flags register (f0.0). |
| 1346 | * |
| 1347 | * Used only on Gen6 and above. |
| 1348 | */ |
| 1349 | void |
Eric Anholt | b278f65 | 2012-12-06 10:36:11 -0800 | [diff] [blame] | 1350 | fs_generator::generate_mov_dispatch_to_flags(fs_inst *inst) |
Paul Berry | 3f929ef | 2012-06-18 14:50:04 -0700 | [diff] [blame] | 1351 | { |
Eric Anholt | b278f65 | 2012-12-06 10:36:11 -0800 | [diff] [blame] | 1352 | struct brw_reg flags = brw_flag_reg(0, inst->flag_subreg); |
Eric Anholt | d501649 | 2012-12-06 12:15:13 -0800 | [diff] [blame] | 1353 | struct brw_reg dispatch_mask; |
Paul Berry | 3f929ef | 2012-06-18 14:50:04 -0700 | [diff] [blame] | 1354 | |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1355 | if (devinfo->gen >= 6) |
Eric Anholt | d501649 | 2012-12-06 12:15:13 -0800 | [diff] [blame] | 1356 | dispatch_mask = retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW); |
| 1357 | else |
| 1358 | dispatch_mask = retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW); |
| 1359 | |
Paul Berry | 3f929ef | 2012-06-18 14:50:04 -0700 | [diff] [blame] | 1360 | brw_push_insn_state(p); |
Kenneth Graunke | e374809 | 2014-05-31 16:57:02 -0700 | [diff] [blame] | 1361 | brw_set_default_mask_control(p, BRW_MASK_DISABLE); |
Eric Anholt | d501649 | 2012-12-06 12:15:13 -0800 | [diff] [blame] | 1362 | brw_MOV(p, flags, dispatch_mask); |
Paul Berry | 3f929ef | 2012-06-18 14:50:04 -0700 | [diff] [blame] | 1363 | brw_pop_insn_state(p); |
| 1364 | } |
| 1365 | |
Chris Forbes | 6e91f2d | 2013-11-18 21:13:13 +1300 | [diff] [blame] | 1366 | void |
| 1367 | fs_generator::generate_pixel_interpolator_query(fs_inst *inst, |
| 1368 | struct brw_reg dst, |
| 1369 | struct brw_reg src, |
| 1370 | struct brw_reg msg_data, |
| 1371 | unsigned msg_type) |
| 1372 | { |
Francisco Jerez | 69570bb | 2016-09-07 13:38:20 -0700 | [diff] [blame] | 1373 | assert(inst->size_written % REG_SIZE == 0); |
Neil Roberts | da361ac | 2015-07-17 14:40:03 +0100 | [diff] [blame] | 1374 | assert(msg_data.type == BRW_REGISTER_TYPE_UD); |
Chris Forbes | 6e91f2d | 2013-11-18 21:13:13 +1300 | [diff] [blame] | 1375 | |
| 1376 | brw_pixel_interpolator_query(p, |
| 1377 | retype(dst, BRW_REGISTER_TYPE_UW), |
| 1378 | src, |
| 1379 | inst->pi_noperspective, |
| 1380 | msg_type, |
Neil Roberts | da361ac | 2015-07-17 14:40:03 +0100 | [diff] [blame] | 1381 | msg_data, |
Chris Forbes | 6e91f2d | 2013-11-18 21:13:13 +1300 | [diff] [blame] | 1382 | inst->mlen, |
Francisco Jerez | 69570bb | 2016-09-07 13:38:20 -0700 | [diff] [blame] | 1383 | inst->size_written / REG_SIZE); |
Chris Forbes | 6e91f2d | 2013-11-18 21:13:13 +1300 | [diff] [blame] | 1384 | } |
| 1385 | |
Anuj Phogat | e12bbb5 | 2013-10-24 16:17:08 -0700 | [diff] [blame] | 1386 | /* Sets vstride=1, width=4, hstride=0 of register src1 during |
| 1387 | * the ADD instruction. |
| 1388 | */ |
| 1389 | void |
| 1390 | fs_generator::generate_set_sample_id(fs_inst *inst, |
| 1391 | struct brw_reg dst, |
| 1392 | struct brw_reg src0, |
| 1393 | struct brw_reg src1) |
| 1394 | { |
| 1395 | assert(dst.type == BRW_REGISTER_TYPE_D || |
| 1396 | dst.type == BRW_REGISTER_TYPE_UD); |
| 1397 | assert(src0.type == BRW_REGISTER_TYPE_D || |
| 1398 | src0.type == BRW_REGISTER_TYPE_UD); |
| 1399 | |
Matt Turner | e10fc05 | 2015-10-20 17:51:12 -0700 | [diff] [blame] | 1400 | struct brw_reg reg = stride(src1, 1, 4, 0); |
Francisco Jerez | 448340d | 2016-05-20 00:13:33 -0700 | [diff] [blame] | 1401 | if (devinfo->gen >= 8 || inst->exec_size == 8) { |
Jason Ekstrand | f91b566 | 2014-08-13 12:23:47 -0700 | [diff] [blame] | 1402 | brw_ADD(p, dst, src0, reg); |
Francisco Jerez | 448340d | 2016-05-20 00:13:33 -0700 | [diff] [blame] | 1403 | } else if (inst->exec_size == 16) { |
Matt Turner | 0f74796 | 2015-10-20 18:29:42 -0700 | [diff] [blame] | 1404 | brw_push_insn_state(p); |
| 1405 | brw_set_default_exec_size(p, BRW_EXECUTE_8); |
| 1406 | brw_set_default_compression_control(p, BRW_COMPRESSION_NONE); |
Jason Ekstrand | f91b566 | 2014-08-13 12:23:47 -0700 | [diff] [blame] | 1407 | brw_ADD(p, firsthalf(dst), firsthalf(src0), reg); |
Matt Turner | 0f74796 | 2015-10-20 18:29:42 -0700 | [diff] [blame] | 1408 | brw_set_default_compression_control(p, BRW_COMPRESSION_2NDHALF); |
Jason Ekstrand | f91b566 | 2014-08-13 12:23:47 -0700 | [diff] [blame] | 1409 | brw_ADD(p, sechalf(dst), sechalf(src0), suboffset(reg, 2)); |
Matt Turner | 0f74796 | 2015-10-20 18:29:42 -0700 | [diff] [blame] | 1410 | brw_pop_insn_state(p); |
Jason Ekstrand | f91b566 | 2014-08-13 12:23:47 -0700 | [diff] [blame] | 1411 | } |
Anuj Phogat | e12bbb5 | 2013-10-24 16:17:08 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
Chad Versace | 20dfa50 | 2013-01-09 11:46:42 -0800 | [diff] [blame] | 1414 | void |
| 1415 | fs_generator::generate_pack_half_2x16_split(fs_inst *inst, |
| 1416 | struct brw_reg dst, |
| 1417 | struct brw_reg x, |
| 1418 | struct brw_reg y) |
| 1419 | { |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1420 | assert(devinfo->gen >= 7); |
Chad Versace | 20dfa50 | 2013-01-09 11:46:42 -0800 | [diff] [blame] | 1421 | assert(dst.type == BRW_REGISTER_TYPE_UD); |
Vinson Lee | 1559994 | 2013-01-26 08:27:50 +0100 | [diff] [blame] | 1422 | assert(x.type == BRW_REGISTER_TYPE_F); |
| 1423 | assert(y.type == BRW_REGISTER_TYPE_F); |
Chad Versace | 20dfa50 | 2013-01-09 11:46:42 -0800 | [diff] [blame] | 1424 | |
| 1425 | /* From the Ivybridge PRM, Vol4, Part3, Section 6.27 f32to16: |
| 1426 | * |
| 1427 | * Because this instruction does not have a 16-bit floating-point type, |
| 1428 | * the destination data type must be Word (W). |
| 1429 | * |
| 1430 | * The destination must be DWord-aligned and specify a horizontal stride |
| 1431 | * (HorzStride) of 2. The 16-bit result is stored in the lower word of |
| 1432 | * each destination channel and the upper word is not modified. |
| 1433 | */ |
Francisco Jerez | 509f587 | 2015-02-04 17:58:49 +0200 | [diff] [blame] | 1434 | struct brw_reg dst_w = spread(retype(dst, BRW_REGISTER_TYPE_W), 2); |
Chad Versace | 20dfa50 | 2013-01-09 11:46:42 -0800 | [diff] [blame] | 1435 | |
Francisco Jerez | 509f587 | 2015-02-04 17:58:49 +0200 | [diff] [blame] | 1436 | /* Give each 32-bit channel of dst the form below, where "." means |
Chad Versace | 20dfa50 | 2013-01-09 11:46:42 -0800 | [diff] [blame] | 1437 | * unchanged. |
| 1438 | * 0x....hhhh |
| 1439 | */ |
| 1440 | brw_F32TO16(p, dst_w, y); |
| 1441 | |
| 1442 | /* Now the form: |
| 1443 | * 0xhhhh0000 |
| 1444 | */ |
| 1445 | brw_SHL(p, dst, dst, brw_imm_ud(16u)); |
| 1446 | |
| 1447 | /* And, finally the form of packHalf2x16's output: |
| 1448 | * 0xhhhhllll |
| 1449 | */ |
| 1450 | brw_F32TO16(p, dst_w, x); |
| 1451 | } |
| 1452 | |
| 1453 | void |
| 1454 | fs_generator::generate_unpack_half_2x16_split(fs_inst *inst, |
| 1455 | struct brw_reg dst, |
| 1456 | struct brw_reg src) |
| 1457 | { |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1458 | assert(devinfo->gen >= 7); |
Chad Versace | 20dfa50 | 2013-01-09 11:46:42 -0800 | [diff] [blame] | 1459 | assert(dst.type == BRW_REGISTER_TYPE_F); |
| 1460 | assert(src.type == BRW_REGISTER_TYPE_UD); |
| 1461 | |
| 1462 | /* From the Ivybridge PRM, Vol4, Part3, Section 6.26 f16to32: |
| 1463 | * |
| 1464 | * Because this instruction does not have a 16-bit floating-point type, |
| 1465 | * the source data type must be Word (W). The destination type must be |
| 1466 | * F (Float). |
| 1467 | */ |
Francisco Jerez | 509f587 | 2015-02-04 17:58:49 +0200 | [diff] [blame] | 1468 | struct brw_reg src_w = spread(retype(src, BRW_REGISTER_TYPE_W), 2); |
Chad Versace | 20dfa50 | 2013-01-09 11:46:42 -0800 | [diff] [blame] | 1469 | |
| 1470 | /* Each channel of src has the form of unpackHalf2x16's input: 0xhhhhllll. |
| 1471 | * For the Y case, we wish to access only the upper word; therefore |
| 1472 | * a 16-bit subregister offset is needed. |
| 1473 | */ |
| 1474 | assert(inst->opcode == FS_OPCODE_UNPACK_HALF_2x16_SPLIT_X || |
| 1475 | inst->opcode == FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y); |
| 1476 | if (inst->opcode == FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y) |
Chad Versace | 0974031 | 2013-01-24 21:48:40 -0800 | [diff] [blame] | 1477 | src_w.subnr += 2; |
Chad Versace | 20dfa50 | 2013-01-09 11:46:42 -0800 | [diff] [blame] | 1478 | |
| 1479 | brw_F16TO32(p, dst, src_w); |
| 1480 | } |
| 1481 | |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1482 | void |
Eric Anholt | 5c5218e | 2013-03-19 15:28:11 -0700 | [diff] [blame] | 1483 | fs_generator::generate_shader_time_add(fs_inst *inst, |
| 1484 | struct brw_reg payload, |
| 1485 | struct brw_reg offset, |
| 1486 | struct brw_reg value) |
| 1487 | { |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1488 | assert(devinfo->gen >= 7); |
Eric Anholt | 5c5218e | 2013-03-19 15:28:11 -0700 | [diff] [blame] | 1489 | brw_push_insn_state(p); |
Kenneth Graunke | e374809 | 2014-05-31 16:57:02 -0700 | [diff] [blame] | 1490 | brw_set_default_mask_control(p, true); |
Eric Anholt | 5c5218e | 2013-03-19 15:28:11 -0700 | [diff] [blame] | 1491 | |
| 1492 | assert(payload.file == BRW_GENERAL_REGISTER_FILE); |
| 1493 | struct brw_reg payload_offset = retype(brw_vec1_grf(payload.nr, 0), |
| 1494 | offset.type); |
| 1495 | struct brw_reg payload_value = retype(brw_vec1_grf(payload.nr + 1, 0), |
| 1496 | value.type); |
| 1497 | |
| 1498 | assert(offset.file == BRW_IMMEDIATE_VALUE); |
| 1499 | if (value.file == BRW_GENERAL_REGISTER_FILE) { |
| 1500 | value.width = BRW_WIDTH_1; |
| 1501 | value.hstride = BRW_HORIZONTAL_STRIDE_0; |
| 1502 | value.vstride = BRW_VERTICAL_STRIDE_0; |
| 1503 | } else { |
| 1504 | assert(value.file == BRW_IMMEDIATE_VALUE); |
| 1505 | } |
| 1506 | |
| 1507 | /* Trying to deal with setup of the params from the IR is crazy in the FS8 |
| 1508 | * case, and we don't really care about squeezing every bit of performance |
| 1509 | * out of this path, so we just emit the MOVs from here. |
| 1510 | */ |
| 1511 | brw_MOV(p, payload_offset, offset); |
| 1512 | brw_MOV(p, payload_value, value); |
Eric Anholt | 3c9dc2d | 2013-10-02 14:07:40 -0700 | [diff] [blame] | 1513 | brw_shader_time_add(p, payload, |
Jordan Justen | c43ae40 | 2014-08-29 12:50:46 -0700 | [diff] [blame] | 1514 | prog_data->binding_table.shader_time_start); |
Eric Anholt | 5c5218e | 2013-03-19 15:28:11 -0700 | [diff] [blame] | 1515 | brw_pop_insn_state(p); |
Kenneth Graunke | 6d89bc8 | 2013-08-14 19:49:33 -0700 | [diff] [blame] | 1516 | |
Jordan Justen | c43ae40 | 2014-08-29 12:50:46 -0700 | [diff] [blame] | 1517 | brw_mark_surface_used(prog_data, |
| 1518 | prog_data->binding_table.shader_time_start); |
Eric Anholt | 5c5218e | 2013-03-19 15:28:11 -0700 | [diff] [blame] | 1519 | } |
| 1520 | |
| 1521 | void |
Kristian Høgsberg | 9a1af7b | 2014-10-27 19:40:47 -0700 | [diff] [blame] | 1522 | fs_generator::enable_debug(const char *shader_name) |
| 1523 | { |
| 1524 | debug_flag = true; |
| 1525 | this->shader_name = shader_name; |
| 1526 | } |
| 1527 | |
Kristian Høgsberg | f2bb655 | 2014-11-13 16:28:08 -0800 | [diff] [blame] | 1528 | int |
| 1529 | fs_generator::generate_code(const cfg_t *cfg, int dispatch_width) |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1530 | { |
Kristian Høgsberg | f2bb655 | 2014-11-13 16:28:08 -0800 | [diff] [blame] | 1531 | /* align to 64 byte boundary. */ |
| 1532 | while (p->next_insn_offset % 64) |
| 1533 | brw_NOP(p); |
| 1534 | |
| 1535 | this->dispatch_width = dispatch_width; |
Kristian Høgsberg | f2bb655 | 2014-11-13 16:28:08 -0800 | [diff] [blame] | 1536 | |
Matt Turner | 92b0556 | 2014-05-25 10:42:32 -0700 | [diff] [blame] | 1537 | int start_offset = p->next_insn_offset; |
Matt Turner | b0d422c | 2015-03-16 12:18:31 -0700 | [diff] [blame] | 1538 | int spill_count = 0, fill_count = 0; |
Abdiel Janulgue | f340145 | 2014-08-06 11:27:58 +0300 | [diff] [blame] | 1539 | int loop_count = 0; |
Matt Turner | 92b0556 | 2014-05-25 10:42:32 -0700 | [diff] [blame] | 1540 | |
| 1541 | struct annotation_info annotation; |
| 1542 | memset(&annotation, 0, sizeof(annotation)); |
| 1543 | |
Matt Turner | a3d0ccb | 2014-07-11 21:16:13 -0700 | [diff] [blame] | 1544 | foreach_block_and_inst (block, fs_inst, inst, cfg) { |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1545 | struct brw_reg src[3], dst; |
Kenneth Graunke | 776ad51 | 2014-05-30 16:41:32 -0700 | [diff] [blame] | 1546 | unsigned int last_insn_offset = p->next_insn_offset; |
Matt Turner | 7452f18 | 2014-12-30 12:56:13 -0800 | [diff] [blame] | 1547 | bool multiple_instructions_emitted = false; |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1548 | |
Matt Turner | f01d92f | 2016-05-02 23:32:13 -0700 | [diff] [blame] | 1549 | /* From the Broadwell PRM, Volume 7, "3D-Media-GPGPU", in the |
| 1550 | * "Register Region Restrictions" section: for BDW, SKL: |
| 1551 | * |
| 1552 | * "A POW/FDIV operation must not be followed by an instruction |
| 1553 | * that requires two destination registers." |
| 1554 | * |
| 1555 | * The documentation is often lacking annotations for Atom parts, |
| 1556 | * and empirically this affects CHV as well. |
| 1557 | */ |
| 1558 | if (devinfo->gen >= 8 && |
| 1559 | p->nr_insn > 1 && |
| 1560 | brw_inst_opcode(devinfo, brw_last_inst) == BRW_OPCODE_MATH && |
| 1561 | brw_inst_math_function(devinfo, brw_last_inst) == BRW_MATH_FUNCTION_POW && |
| 1562 | inst->dst.component_size(inst->exec_size) > REG_SIZE) { |
| 1563 | brw_NOP(p); |
| 1564 | last_insn_offset = p->next_insn_offset; |
| 1565 | } |
| 1566 | |
Matt Turner | f0f7fb1 | 2014-05-19 10:20:37 -0700 | [diff] [blame] | 1567 | if (unlikely(debug_flag)) |
Jason Ekstrand | 9c89e47 | 2015-04-15 15:01:25 -0700 | [diff] [blame] | 1568 | annotate(p->devinfo, &annotation, cfg, inst, p->next_insn_offset); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1569 | |
Francisco Jerez | 3340a66 | 2016-05-18 18:48:04 -0700 | [diff] [blame] | 1570 | /* If the instruction writes to more than one register, it needs to be |
| 1571 | * explicitly marked as compressed on Gen <= 5. On Gen >= 6 the |
| 1572 | * hardware figures out by itself what the right compression mode is, |
| 1573 | * but we still need to know whether the instruction is compressed to |
| 1574 | * set up the source register regions appropriately. |
| 1575 | * |
| 1576 | * XXX - This is wrong for instructions that write a single register but |
| 1577 | * read more than one which should strictly speaking be treated as |
| 1578 | * compressed. For instructions that don't write any registers it |
| 1579 | * relies on the destination being a null register of the correct |
| 1580 | * type and regioning so the instruction is considered compressed |
| 1581 | * or not accordingly. |
| 1582 | */ |
Francisco Jerez | 7f28ad8 | 2016-05-20 15:25:28 -0700 | [diff] [blame] | 1583 | const bool compressed = |
| 1584 | inst->dst.component_size(inst->exec_size) > REG_SIZE; |
| 1585 | brw_set_default_compression(p, compressed); |
Francisco Jerez | ece41df | 2016-05-20 16:14:13 -0700 | [diff] [blame] | 1586 | brw_set_default_group(p, inst->group); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1587 | |
Kenneth Graunke | 062ad81 | 2016-05-16 15:09:17 -0700 | [diff] [blame] | 1588 | for (unsigned int i = 0; i < inst->sources; i++) { |
Kenneth Graunke | dabaf4f | 2016-05-18 19:02:45 -0700 | [diff] [blame] | 1589 | src[i] = brw_reg_from_fs_reg(inst, &inst->src[i], devinfo->gen, |
Francisco Jerez | 7f28ad8 | 2016-05-20 15:25:28 -0700 | [diff] [blame] | 1590 | compressed); |
Kenneth Graunke | 062ad81 | 2016-05-16 15:09:17 -0700 | [diff] [blame] | 1591 | |
| 1592 | /* The accumulator result appears to get used for the |
| 1593 | * conditional modifier generation. When negating a UD |
| 1594 | * value, there is a 33rd bit generated for the sign in the |
| 1595 | * accumulator value, so now you can't check, for example, |
| 1596 | * equality with a 32-bit value. See piglit fs-op-neg-uvec4. |
| 1597 | */ |
| 1598 | assert(!inst->conditional_mod || |
| 1599 | inst->src[i].type != BRW_REGISTER_TYPE_UD || |
| 1600 | !inst->src[i].negate); |
| 1601 | } |
Francisco Jerez | 7f28ad8 | 2016-05-20 15:25:28 -0700 | [diff] [blame] | 1602 | dst = brw_reg_from_fs_reg(inst, &inst->dst, devinfo->gen, compressed); |
Kenneth Graunke | 062ad81 | 2016-05-16 15:09:17 -0700 | [diff] [blame] | 1603 | |
Francisco Jerez | 117a9a0 | 2016-05-18 18:41:28 -0700 | [diff] [blame] | 1604 | brw_set_default_access_mode(p, BRW_ALIGN_1); |
Kenneth Graunke | 062ad81 | 2016-05-16 15:09:17 -0700 | [diff] [blame] | 1605 | brw_set_default_predicate_control(p, inst->predicate); |
| 1606 | brw_set_default_predicate_inverse(p, inst->predicate_inverse); |
| 1607 | brw_set_default_flag_reg(p, 0, inst->flag_subreg); |
| 1608 | brw_set_default_saturate(p, inst->saturate); |
| 1609 | brw_set_default_mask_control(p, inst->force_writemask_all); |
| 1610 | brw_set_default_acc_write_control(p, inst->writes_accumulator); |
| 1611 | brw_set_default_exec_size(p, cvt(inst->exec_size) - 1); |
| 1612 | |
Samuel Iglesias Gonsálvez | 9979a3f | 2016-06-20 12:13:14 +0200 | [diff] [blame] | 1613 | assert(inst->force_writemask_all || inst->exec_size >= 4); |
Francisco Jerez | ece41df | 2016-05-20 16:14:13 -0700 | [diff] [blame] | 1614 | assert(inst->force_writemask_all || inst->group % inst->exec_size == 0); |
Kenneth Graunke | 062ad81 | 2016-05-16 15:09:17 -0700 | [diff] [blame] | 1615 | assert(inst->base_mrf + inst->mlen <= BRW_MAX_MRF(devinfo->gen)); |
| 1616 | assert(inst->mlen <= BRW_MAX_MSG_LENGTH); |
| 1617 | |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1618 | switch (inst->opcode) { |
| 1619 | case BRW_OPCODE_MOV: |
| 1620 | brw_MOV(p, dst, src[0]); |
| 1621 | break; |
| 1622 | case BRW_OPCODE_ADD: |
| 1623 | brw_ADD(p, dst, src[0], src[1]); |
| 1624 | break; |
| 1625 | case BRW_OPCODE_MUL: |
| 1626 | brw_MUL(p, dst, src[0], src[1]); |
| 1627 | break; |
Topi Pohjolainen | 8f3e536 | 2013-12-17 16:39:16 +0200 | [diff] [blame] | 1628 | case BRW_OPCODE_AVG: |
| 1629 | brw_AVG(p, dst, src[0], src[1]); |
| 1630 | break; |
Eric Anholt | 3f78f71 | 2011-08-15 22:36:18 -0700 | [diff] [blame] | 1631 | case BRW_OPCODE_MACH: |
Eric Anholt | 3f78f71 | 2011-08-15 22:36:18 -0700 | [diff] [blame] | 1632 | brw_MACH(p, dst, src[0], src[1]); |
Eric Anholt | 3f78f71 | 2011-08-15 22:36:18 -0700 | [diff] [blame] | 1633 | break; |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1634 | |
Matt Turner | 6be863a | 2014-04-01 17:25:12 -0700 | [diff] [blame] | 1635 | case BRW_OPCODE_LINE: |
| 1636 | brw_LINE(p, dst, src[0], src[1]); |
| 1637 | break; |
| 1638 | |
Eric Anholt | 7d55f37 | 2012-02-07 00:59:11 +0100 | [diff] [blame] | 1639 | case BRW_OPCODE_MAD: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1640 | assert(devinfo->gen >= 6); |
Kenneth Graunke | e374809 | 2014-05-31 16:57:02 -0700 | [diff] [blame] | 1641 | brw_set_default_access_mode(p, BRW_ALIGN_16); |
Francisco Jerez | f14b9ea | 2016-05-17 19:51:50 -0700 | [diff] [blame] | 1642 | brw_MAD(p, dst, src[0], src[1], src[2]); |
Eric Anholt | 7d55f37 | 2012-02-07 00:59:11 +0100 | [diff] [blame] | 1643 | break; |
| 1644 | |
Kenneth Graunke | 0a1d145 | 2012-12-02 00:08:15 -0800 | [diff] [blame] | 1645 | case BRW_OPCODE_LRP: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1646 | assert(devinfo->gen >= 6); |
Kenneth Graunke | e374809 | 2014-05-31 16:57:02 -0700 | [diff] [blame] | 1647 | brw_set_default_access_mode(p, BRW_ALIGN_16); |
Francisco Jerez | f14b9ea | 2016-05-17 19:51:50 -0700 | [diff] [blame] | 1648 | brw_LRP(p, dst, src[0], src[1], src[2]); |
Kenneth Graunke | 0a1d145 | 2012-12-02 00:08:15 -0800 | [diff] [blame] | 1649 | break; |
| 1650 | |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1651 | case BRW_OPCODE_FRC: |
| 1652 | brw_FRC(p, dst, src[0]); |
| 1653 | break; |
| 1654 | case BRW_OPCODE_RNDD: |
| 1655 | brw_RNDD(p, dst, src[0]); |
| 1656 | break; |
| 1657 | case BRW_OPCODE_RNDE: |
| 1658 | brw_RNDE(p, dst, src[0]); |
| 1659 | break; |
| 1660 | case BRW_OPCODE_RNDZ: |
| 1661 | brw_RNDZ(p, dst, src[0]); |
| 1662 | break; |
| 1663 | |
| 1664 | case BRW_OPCODE_AND: |
| 1665 | brw_AND(p, dst, src[0], src[1]); |
| 1666 | break; |
| 1667 | case BRW_OPCODE_OR: |
| 1668 | brw_OR(p, dst, src[0], src[1]); |
| 1669 | break; |
| 1670 | case BRW_OPCODE_XOR: |
| 1671 | brw_XOR(p, dst, src[0], src[1]); |
| 1672 | break; |
| 1673 | case BRW_OPCODE_NOT: |
| 1674 | brw_NOT(p, dst, src[0]); |
| 1675 | break; |
| 1676 | case BRW_OPCODE_ASR: |
| 1677 | brw_ASR(p, dst, src[0], src[1]); |
| 1678 | break; |
| 1679 | case BRW_OPCODE_SHR: |
| 1680 | brw_SHR(p, dst, src[0], src[1]); |
| 1681 | break; |
| 1682 | case BRW_OPCODE_SHL: |
| 1683 | brw_SHL(p, dst, src[0], src[1]); |
| 1684 | break; |
Chad Versace | 20dfa50 | 2013-01-09 11:46:42 -0800 | [diff] [blame] | 1685 | case BRW_OPCODE_F32TO16: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1686 | assert(devinfo->gen >= 7); |
Chad Versace | 20dfa50 | 2013-01-09 11:46:42 -0800 | [diff] [blame] | 1687 | brw_F32TO16(p, dst, src[0]); |
| 1688 | break; |
| 1689 | case BRW_OPCODE_F16TO32: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1690 | assert(devinfo->gen >= 7); |
Chad Versace | 20dfa50 | 2013-01-09 11:46:42 -0800 | [diff] [blame] | 1691 | brw_F16TO32(p, dst, src[0]); |
| 1692 | break; |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1693 | case BRW_OPCODE_CMP: |
Francisco Jerez | 95272f5 | 2016-05-17 19:59:18 -0700 | [diff] [blame] | 1694 | if (inst->exec_size >= 16 && devinfo->gen == 7 && !devinfo->is_haswell && |
| 1695 | dst.file == BRW_ARCHITECTURE_REGISTER_FILE) { |
| 1696 | /* For unknown reasons the WaCMPInstFlagDepClearedEarly workaround |
| 1697 | * implemented in the compiler is not sufficient. Overriding the |
| 1698 | * type when the destination is the null register is necessary but |
| 1699 | * not sufficient by itself. |
| 1700 | */ |
| 1701 | assert(dst.nr == BRW_ARF_NULL); |
| 1702 | dst.type = BRW_REGISTER_TYPE_D; |
Matt Turner | 7e60794 | 2015-02-03 17:38:49 -0800 | [diff] [blame] | 1703 | } |
Francisco Jerez | 95272f5 | 2016-05-17 19:59:18 -0700 | [diff] [blame] | 1704 | brw_CMP(p, dst, inst->conditional_mod, src[0], src[1]); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1705 | break; |
| 1706 | case BRW_OPCODE_SEL: |
| 1707 | brw_SEL(p, dst, src[0], src[1]); |
| 1708 | break; |
Matt Turner | 1f0f26d | 2013-04-09 19:22:34 -0700 | [diff] [blame] | 1709 | case BRW_OPCODE_BFREV: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1710 | assert(devinfo->gen >= 7); |
Matt Turner | 1f0f26d | 2013-04-09 19:22:34 -0700 | [diff] [blame] | 1711 | /* BFREV only supports UD type for src and dst. */ |
| 1712 | brw_BFREV(p, retype(dst, BRW_REGISTER_TYPE_UD), |
| 1713 | retype(src[0], BRW_REGISTER_TYPE_UD)); |
| 1714 | break; |
| 1715 | case BRW_OPCODE_FBH: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1716 | assert(devinfo->gen >= 7); |
Matt Turner | 1f0f26d | 2013-04-09 19:22:34 -0700 | [diff] [blame] | 1717 | /* FBH only supports UD type for dst. */ |
| 1718 | brw_FBH(p, retype(dst, BRW_REGISTER_TYPE_UD), src[0]); |
| 1719 | break; |
| 1720 | case BRW_OPCODE_FBL: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1721 | assert(devinfo->gen >= 7); |
Matt Turner | 1f0f26d | 2013-04-09 19:22:34 -0700 | [diff] [blame] | 1722 | /* FBL only supports UD type for dst. */ |
| 1723 | brw_FBL(p, retype(dst, BRW_REGISTER_TYPE_UD), src[0]); |
| 1724 | break; |
Ian Romanick | de20086 | 2016-06-21 15:14:03 -0700 | [diff] [blame] | 1725 | case BRW_OPCODE_LZD: |
| 1726 | brw_LZD(p, dst, src[0]); |
| 1727 | break; |
Matt Turner | 1f0f26d | 2013-04-09 19:22:34 -0700 | [diff] [blame] | 1728 | case BRW_OPCODE_CBIT: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1729 | assert(devinfo->gen >= 7); |
Matt Turner | 1f0f26d | 2013-04-09 19:22:34 -0700 | [diff] [blame] | 1730 | /* CBIT only supports UD type for dst. */ |
| 1731 | brw_CBIT(p, retype(dst, BRW_REGISTER_TYPE_UD), src[0]); |
| 1732 | break; |
Matt Turner | 014cce3 | 2013-09-19 13:01:08 -0700 | [diff] [blame] | 1733 | case BRW_OPCODE_ADDC: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1734 | assert(devinfo->gen >= 7); |
Matt Turner | 014cce3 | 2013-09-19 13:01:08 -0700 | [diff] [blame] | 1735 | brw_ADDC(p, dst, src[0], src[1]); |
Matt Turner | 014cce3 | 2013-09-19 13:01:08 -0700 | [diff] [blame] | 1736 | break; |
| 1737 | case BRW_OPCODE_SUBB: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1738 | assert(devinfo->gen >= 7); |
Matt Turner | 014cce3 | 2013-09-19 13:01:08 -0700 | [diff] [blame] | 1739 | brw_SUBB(p, dst, src[0], src[1]); |
Matt Turner | 014cce3 | 2013-09-19 13:01:08 -0700 | [diff] [blame] | 1740 | break; |
Juha-Pekka Heikkila | da0c3b0 | 2014-03-28 15:28:32 +0200 | [diff] [blame] | 1741 | case BRW_OPCODE_MAC: |
| 1742 | brw_MAC(p, dst, src[0], src[1]); |
| 1743 | break; |
Matt Turner | 1f0f26d | 2013-04-09 19:22:34 -0700 | [diff] [blame] | 1744 | |
| 1745 | case BRW_OPCODE_BFE: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1746 | assert(devinfo->gen >= 7); |
Kenneth Graunke | e374809 | 2014-05-31 16:57:02 -0700 | [diff] [blame] | 1747 | brw_set_default_access_mode(p, BRW_ALIGN_16); |
Francisco Jerez | f14b9ea | 2016-05-17 19:51:50 -0700 | [diff] [blame] | 1748 | brw_BFE(p, dst, src[0], src[1], src[2]); |
Matt Turner | 1f0f26d | 2013-04-09 19:22:34 -0700 | [diff] [blame] | 1749 | break; |
| 1750 | |
| 1751 | case BRW_OPCODE_BFI1: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1752 | assert(devinfo->gen >= 7); |
Francisco Jerez | 982c48d | 2016-05-17 20:02:29 -0700 | [diff] [blame] | 1753 | brw_BFI1(p, dst, src[0], src[1]); |
Matt Turner | 1f0f26d | 2013-04-09 19:22:34 -0700 | [diff] [blame] | 1754 | break; |
| 1755 | case BRW_OPCODE_BFI2: |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1756 | assert(devinfo->gen >= 7); |
Kenneth Graunke | e374809 | 2014-05-31 16:57:02 -0700 | [diff] [blame] | 1757 | brw_set_default_access_mode(p, BRW_ALIGN_16); |
Francisco Jerez | 982c48d | 2016-05-17 20:02:29 -0700 | [diff] [blame] | 1758 | brw_BFI2(p, dst, src[0], src[1], src[2]); |
Matt Turner | 1f0f26d | 2013-04-09 19:22:34 -0700 | [diff] [blame] | 1759 | break; |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1760 | |
| 1761 | case BRW_OPCODE_IF: |
| 1762 | if (inst->src[0].file != BAD_FILE) { |
| 1763 | /* The instruction has an embedded compare (only allowed on gen6) */ |
Jason Ekstrand | 5bda1ff | 2015-04-14 17:45:40 -0700 | [diff] [blame] | 1764 | assert(devinfo->gen == 6); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1765 | gen6_IF(p, inst->conditional_mod, src[0], src[1]); |
| 1766 | } else { |
Francisco Jerez | 8ef5637 | 2016-05-18 19:36:03 -0700 | [diff] [blame] | 1767 | brw_IF(p, brw_inst_exec_size(devinfo, p->current)); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1768 | } |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1769 | break; |
| 1770 | |
| 1771 | case BRW_OPCODE_ELSE: |
| 1772 | brw_ELSE(p); |
| 1773 | break; |
| 1774 | case BRW_OPCODE_ENDIF: |
| 1775 | brw_ENDIF(p); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1776 | break; |
| 1777 | |
| 1778 | case BRW_OPCODE_DO: |
Francisco Jerez | 8ef5637 | 2016-05-18 19:36:03 -0700 | [diff] [blame] | 1779 | brw_DO(p, brw_inst_exec_size(devinfo, p->current)); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1780 | break; |
| 1781 | |
| 1782 | case BRW_OPCODE_BREAK: |
Eric Anholt | f1d8963 | 2011-12-06 12:44:41 -0800 | [diff] [blame] | 1783 | brw_BREAK(p); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1784 | break; |
| 1785 | case BRW_OPCODE_CONTINUE: |
Kenneth Graunke | e64dbd0 | 2014-08-04 14:26:26 -0700 | [diff] [blame] | 1786 | brw_CONT(p); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1787 | break; |
| 1788 | |
Eric Anholt | ce6be33 | 2011-12-06 12:30:03 -0800 | [diff] [blame] | 1789 | case BRW_OPCODE_WHILE: |
Eric Anholt | ce6be33 | 2011-12-06 12:30:03 -0800 | [diff] [blame] | 1790 | brw_WHILE(p); |
Abdiel Janulgue | f340145 | 2014-08-06 11:27:58 +0300 | [diff] [blame] | 1791 | loop_count++; |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1792 | break; |
| 1793 | |
Eric Anholt | 65b5cbb | 2011-08-05 12:38:58 -0700 | [diff] [blame] | 1794 | case SHADER_OPCODE_RCP: |
| 1795 | case SHADER_OPCODE_RSQ: |
| 1796 | case SHADER_OPCODE_SQRT: |
| 1797 | case SHADER_OPCODE_EXP2: |
| 1798 | case SHADER_OPCODE_LOG2: |
Eric Anholt | 65b5cbb | 2011-08-05 12:38:58 -0700 | [diff] [blame] | 1799 | case SHADER_OPCODE_SIN: |
| 1800 | case SHADER_OPCODE_COS: |
Matt Turner | f5bef2d | 2014-11-21 12:34:22 -0800 | [diff] [blame] | 1801 | assert(inst->conditional_mod == BRW_CONDITIONAL_NONE); |
Francisco Jerez | 3a541d0 | 2016-05-17 19:10:48 -0700 | [diff] [blame] | 1802 | if (devinfo->gen >= 6) { |
| 1803 | assert(inst->mlen == 0); |
| 1804 | assert(devinfo->gen >= 7 || inst->exec_size == 8); |
| 1805 | gen6_math(p, dst, brw_math_function(inst->opcode), |
| 1806 | src[0], brw_null_reg()); |
Kenneth Graunke | 74e927b | 2011-08-18 11:55:42 -0700 | [diff] [blame] | 1807 | } else { |
Francisco Jerez | 3a541d0 | 2016-05-17 19:10:48 -0700 | [diff] [blame] | 1808 | assert(inst->mlen >= 1); |
| 1809 | assert(devinfo->gen == 5 || devinfo->is_g4x || inst->exec_size == 8); |
| 1810 | gen4_math(p, dst, |
| 1811 | brw_math_function(inst->opcode), |
| 1812 | inst->base_mrf, src[0], |
| 1813 | BRW_MATH_PRECISION_FULL); |
Kenneth Graunke | 74e927b | 2011-08-18 11:55:42 -0700 | [diff] [blame] | 1814 | } |
| 1815 | break; |
Kenneth Graunke | ff8f272 | 2011-09-28 17:37:54 -0700 | [diff] [blame] | 1816 | case SHADER_OPCODE_INT_QUOTIENT: |
| 1817 | case SHADER_OPCODE_INT_REMAINDER: |
Kenneth Graunke | 74e927b | 2011-08-18 11:55:42 -0700 | [diff] [blame] | 1818 | case SHADER_OPCODE_POW: |
Matt Turner | f5bef2d | 2014-11-21 12:34:22 -0800 | [diff] [blame] | 1819 | assert(inst->conditional_mod == BRW_CONDITIONAL_NONE); |
Francisco Jerez | 3a541d0 | 2016-05-17 19:10:48 -0700 | [diff] [blame] | 1820 | if (devinfo->gen >= 6) { |
| 1821 | assert(inst->mlen == 0); |
| 1822 | assert((devinfo->gen >= 7 && inst->opcode == SHADER_OPCODE_POW) || |
| 1823 | inst->exec_size == 8); |
Kenneth Graunke | 35e48bd | 2014-06-07 02:27:43 -0700 | [diff] [blame] | 1824 | gen6_math(p, dst, brw_math_function(inst->opcode), src[0], src[1]); |
Francisco Jerez | 3a541d0 | 2016-05-17 19:10:48 -0700 | [diff] [blame] | 1825 | } else { |
| 1826 | assert(inst->mlen >= 1); |
| 1827 | assert(inst->exec_size == 8); |
| 1828 | gen4_math(p, dst, brw_math_function(inst->opcode), |
| 1829 | inst->base_mrf, src[0], |
| 1830 | BRW_MATH_PRECISION_FULL); |
Kenneth Graunke | 74e927b | 2011-08-18 11:55:42 -0700 | [diff] [blame] | 1831 | } |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1832 | break; |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1833 | case FS_OPCODE_CINTERP: |
| 1834 | brw_MOV(p, dst, src[0]); |
| 1835 | break; |
| 1836 | case FS_OPCODE_LINTERP: |
| 1837 | generate_linterp(inst, dst, src); |
| 1838 | break; |
Matt Turner | 529064f | 2015-04-14 13:17:38 -0700 | [diff] [blame] | 1839 | case FS_OPCODE_PIXEL_X: |
| 1840 | assert(src[0].type == BRW_REGISTER_TYPE_UW); |
| 1841 | src[0].subnr = 0 * type_sz(src[0].type); |
| 1842 | brw_MOV(p, dst, stride(src[0], 8, 4, 1)); |
| 1843 | break; |
| 1844 | case FS_OPCODE_PIXEL_Y: |
| 1845 | assert(src[0].type == BRW_REGISTER_TYPE_UW); |
| 1846 | src[0].subnr = 4 * type_sz(src[0].type); |
| 1847 | brw_MOV(p, dst, stride(src[0], 8, 4, 1)); |
| 1848 | break; |
Samuel Iglesias Gonsalvez | b23eb64 | 2015-04-13 16:55:49 +0200 | [diff] [blame] | 1849 | case FS_OPCODE_GET_BUFFER_SIZE: |
| 1850 | generate_get_buffer_size(inst, dst, src[0], src[1]); |
| 1851 | break; |
Kenneth Graunke | febad17 | 2011-10-26 12:58:37 -0700 | [diff] [blame] | 1852 | case SHADER_OPCODE_TEX: |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1853 | case FS_OPCODE_TXB: |
Kenneth Graunke | febad17 | 2011-10-26 12:58:37 -0700 | [diff] [blame] | 1854 | case SHADER_OPCODE_TXD: |
| 1855 | case SHADER_OPCODE_TXF: |
Matt Turner | 75dccf5 | 2016-05-04 15:46:45 -0700 | [diff] [blame] | 1856 | case SHADER_OPCODE_TXF_LZ: |
Topi Pohjolainen | ce527a6 | 2013-12-10 16:36:31 +0200 | [diff] [blame] | 1857 | case SHADER_OPCODE_TXF_CMS: |
Neil Roberts | e386fb0 | 2015-09-08 15:52:09 +0100 | [diff] [blame] | 1858 | case SHADER_OPCODE_TXF_CMS_W: |
Topi Pohjolainen | 41d397f | 2013-12-10 16:38:15 +0200 | [diff] [blame] | 1859 | case SHADER_OPCODE_TXF_UMS: |
Chris Forbes | 7629c48 | 2013-11-30 10:32:16 +1300 | [diff] [blame] | 1860 | case SHADER_OPCODE_TXF_MCS: |
Kenneth Graunke | febad17 | 2011-10-26 12:58:37 -0700 | [diff] [blame] | 1861 | case SHADER_OPCODE_TXL: |
Matt Turner | 75dccf5 | 2016-05-04 15:46:45 -0700 | [diff] [blame] | 1862 | case SHADER_OPCODE_TXL_LZ: |
Kenneth Graunke | febad17 | 2011-10-26 12:58:37 -0700 | [diff] [blame] | 1863 | case SHADER_OPCODE_TXS: |
Matt Turner | b8aa9f7 | 2013-03-06 14:47:01 -0800 | [diff] [blame] | 1864 | case SHADER_OPCODE_LOD: |
Chris Forbes | fb45550 | 2013-03-31 21:31:12 +1300 | [diff] [blame] | 1865 | case SHADER_OPCODE_TG4: |
Chris Forbes | 6bb2cf2 | 2013-10-08 21:42:10 +1300 | [diff] [blame] | 1866 | case SHADER_OPCODE_TG4_OFFSET: |
Ilia Mirkin | 0b91bce | 2015-08-11 20:37:32 -0400 | [diff] [blame] | 1867 | case SHADER_OPCODE_SAMPLEINFO: |
Jason Ekstrand | b8ab9c8 | 2016-02-05 18:24:02 -0800 | [diff] [blame] | 1868 | generate_tex(inst, dst, src[0], src[1], src[2]); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1869 | break; |
Kenneth Graunke | cea37f0 | 2014-11-08 01:39:14 -0800 | [diff] [blame] | 1870 | case FS_OPCODE_DDX_COARSE: |
| 1871 | case FS_OPCODE_DDX_FINE: |
| 1872 | generate_ddx(inst->opcode, dst, src[0]); |
| 1873 | break; |
| 1874 | case FS_OPCODE_DDY_COARSE: |
| 1875 | case FS_OPCODE_DDY_FINE: |
Kenneth Graunke | dac10e8 | 2016-05-17 01:52:16 -0700 | [diff] [blame] | 1876 | generate_ddy(inst->opcode, dst, src[0]); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1877 | break; |
| 1878 | |
Eric Anholt | 6032261 | 2013-10-16 11:45:06 -0700 | [diff] [blame] | 1879 | case SHADER_OPCODE_GEN4_SCRATCH_WRITE: |
| 1880 | generate_scratch_write(inst, src[0]); |
Matt Turner | b0d422c | 2015-03-16 12:18:31 -0700 | [diff] [blame] | 1881 | spill_count++; |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1882 | break; |
| 1883 | |
Eric Anholt | 6032261 | 2013-10-16 11:45:06 -0700 | [diff] [blame] | 1884 | case SHADER_OPCODE_GEN4_SCRATCH_READ: |
| 1885 | generate_scratch_read(inst, dst); |
Matt Turner | b0d422c | 2015-03-16 12:18:31 -0700 | [diff] [blame] | 1886 | fill_count++; |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1887 | break; |
| 1888 | |
Eric Anholt | 8dfc9f0 | 2013-10-16 11:51:22 -0700 | [diff] [blame] | 1889 | case SHADER_OPCODE_GEN7_SCRATCH_READ: |
| 1890 | generate_scratch_read_gen7(inst, dst); |
Matt Turner | b0d422c | 2015-03-16 12:18:31 -0700 | [diff] [blame] | 1891 | fill_count++; |
Eric Anholt | 8dfc9f0 | 2013-10-16 11:51:22 -0700 | [diff] [blame] | 1892 | break; |
| 1893 | |
Kenneth Graunke | d2f089b | 2015-11-07 18:58:34 -0800 | [diff] [blame] | 1894 | case SHADER_OPCODE_MOV_INDIRECT: |
| 1895 | generate_mov_indirect(inst, dst, src[0], src[1]); |
| 1896 | break; |
| 1897 | |
Kenneth Graunke | ac98888 | 2015-09-29 14:32:02 -0700 | [diff] [blame] | 1898 | case SHADER_OPCODE_URB_READ_SIMD8: |
Kenneth Graunke | 5480bbd | 2015-11-07 01:37:33 -0800 | [diff] [blame] | 1899 | case SHADER_OPCODE_URB_READ_SIMD8_PER_SLOT: |
Kenneth Graunke | ac98888 | 2015-09-29 14:32:02 -0700 | [diff] [blame] | 1900 | generate_urb_read(inst, dst, src[0]); |
| 1901 | break; |
| 1902 | |
Kristian Høgsberg | d9e29f5 | 2014-10-20 23:00:50 -0700 | [diff] [blame] | 1903 | case SHADER_OPCODE_URB_WRITE_SIMD8: |
Kenneth Graunke | bea7522 | 2015-05-06 00:04:10 -0700 | [diff] [blame] | 1904 | case SHADER_OPCODE_URB_WRITE_SIMD8_PER_SLOT: |
| 1905 | case SHADER_OPCODE_URB_WRITE_SIMD8_MASKED: |
| 1906 | case SHADER_OPCODE_URB_WRITE_SIMD8_MASKED_PER_SLOT: |
Kristian Høgsberg | d9e29f5 | 2014-10-20 23:00:50 -0700 | [diff] [blame] | 1907 | generate_urb_write(inst, src[0]); |
| 1908 | break; |
| 1909 | |
Eric Anholt | 29340d0 | 2012-11-07 10:42:34 -0800 | [diff] [blame] | 1910 | case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD: |
Francisco Jerez | 0150350 | 2016-05-23 14:07:23 -0700 | [diff] [blame] | 1911 | assert(inst->force_writemask_all); |
Eric Anholt | 29340d0 | 2012-11-07 10:42:34 -0800 | [diff] [blame] | 1912 | generate_uniform_pull_constant_load(inst, dst, src[0], src[1]); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1913 | break; |
| 1914 | |
Eric Anholt | 461a297 | 2012-12-05 00:06:30 -0800 | [diff] [blame] | 1915 | case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD_GEN7: |
Francisco Jerez | 0150350 | 2016-05-23 14:07:23 -0700 | [diff] [blame] | 1916 | assert(inst->force_writemask_all); |
Eric Anholt | 461a297 | 2012-12-05 00:06:30 -0800 | [diff] [blame] | 1917 | generate_uniform_pull_constant_load_gen7(inst, dst, src[0], src[1]); |
| 1918 | break; |
| 1919 | |
Francisco Jerez | ed4d0e4 | 2016-05-20 13:03:31 -0700 | [diff] [blame] | 1920 | case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD_GEN4: |
| 1921 | generate_varying_pull_constant_load_gen4(inst, dst, src[0]); |
Eric Anholt | d8214e4 | 2012-11-07 11:18:34 -0800 | [diff] [blame] | 1922 | break; |
| 1923 | |
| 1924 | case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD_GEN7: |
| 1925 | generate_varying_pull_constant_load_gen7(inst, dst, src[0], src[1]); |
| 1926 | break; |
| 1927 | |
Kristian Høgsberg | f9dc7aa | 2014-07-07 15:27:17 -0700 | [diff] [blame] | 1928 | case FS_OPCODE_REP_FB_WRITE: |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1929 | case FS_OPCODE_FB_WRITE: |
Jason Ekstrand | 8b0e4b3 | 2014-09-16 15:16:20 -0700 | [diff] [blame] | 1930 | generate_fb_write(inst, src[0]); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 1931 | break; |
Paul Berry | 3f929ef | 2012-06-18 14:50:04 -0700 | [diff] [blame] | 1932 | |
Francisco Jerez | f2f75b0 | 2016-07-21 16:52:33 -0700 | [diff] [blame] | 1933 | case FS_OPCODE_FB_READ: |
| 1934 | generate_fb_read(inst, dst, src[0]); |
| 1935 | break; |
| 1936 | |
Paul Berry | 3f929ef | 2012-06-18 14:50:04 -0700 | [diff] [blame] | 1937 | case FS_OPCODE_MOV_DISPATCH_TO_FLAGS: |
Eric Anholt | b278f65 | 2012-12-06 10:36:11 -0800 | [diff] [blame] | 1938 | generate_mov_dispatch_to_flags(inst); |
Paul Berry | 3f929ef | 2012-06-18 14:50:04 -0700 | [diff] [blame] | 1939 | break; |
| 1940 | |
Eric Anholt | beafced | 2012-12-06 10:15:08 -0800 | [diff] [blame] | 1941 | case FS_OPCODE_DISCARD_JUMP: |
| 1942 | generate_discard_jump(inst); |
| 1943 | break; |
| 1944 | |
Eric Anholt | 71f0634 | 2012-11-27 14:10:52 -0800 | [diff] [blame] | 1945 | case SHADER_OPCODE_SHADER_TIME_ADD: |
Eric Anholt | 5c5218e | 2013-03-19 15:28:11 -0700 | [diff] [blame] | 1946 | generate_shader_time_add(inst, src[0], src[1], src[2]); |
Eric Anholt | 71f0634 | 2012-11-27 14:10:52 -0800 | [diff] [blame] | 1947 | break; |
| 1948 | |
Francisco Jerez | cfaaa9b | 2013-09-11 14:01:50 -0700 | [diff] [blame] | 1949 | case SHADER_OPCODE_UNTYPED_ATOMIC: |
Francisco Jerez | 3af2623 | 2015-07-20 17:38:15 +0300 | [diff] [blame] | 1950 | assert(src[2].file == BRW_IMMEDIATE_VALUE); |
Matt Turner | e42fb0c | 2015-10-22 19:41:30 -0700 | [diff] [blame] | 1951 | brw_untyped_atomic(p, dst, src[0], src[1], src[2].ud, |
Francisco Jerez | 8865fe3 | 2015-02-26 17:41:46 +0200 | [diff] [blame] | 1952 | inst->mlen, !inst->dst.is_null()); |
Francisco Jerez | cfaaa9b | 2013-09-11 14:01:50 -0700 | [diff] [blame] | 1953 | break; |
| 1954 | |
Francisco Jerez | 5e621cb | 2013-09-11 14:03:13 -0700 | [diff] [blame] | 1955 | case SHADER_OPCODE_UNTYPED_SURFACE_READ: |
Francisco Jerez | 3af2623 | 2015-07-20 17:38:15 +0300 | [diff] [blame] | 1956 | assert(src[2].file == BRW_IMMEDIATE_VALUE); |
Francisco Jerez | 0519a62 | 2015-04-22 21:10:43 +0300 | [diff] [blame] | 1957 | brw_untyped_surface_read(p, dst, src[0], src[1], |
Matt Turner | e42fb0c | 2015-10-22 19:41:30 -0700 | [diff] [blame] | 1958 | inst->mlen, src[2].ud); |
Francisco Jerez | 5e621cb | 2013-09-11 14:03:13 -0700 | [diff] [blame] | 1959 | break; |
| 1960 | |
Francisco Jerez | 0775d88 | 2015-04-23 14:24:14 +0300 | [diff] [blame] | 1961 | case SHADER_OPCODE_UNTYPED_SURFACE_WRITE: |
| 1962 | assert(src[2].file == BRW_IMMEDIATE_VALUE); |
| 1963 | brw_untyped_surface_write(p, src[0], src[1], |
Matt Turner | e42fb0c | 2015-10-22 19:41:30 -0700 | [diff] [blame] | 1964 | inst->mlen, src[2].ud); |
Francisco Jerez | 0775d88 | 2015-04-23 14:24:14 +0300 | [diff] [blame] | 1965 | break; |
| 1966 | |
Francisco Jerez | f118e5d | 2015-04-23 14:28:25 +0300 | [diff] [blame] | 1967 | case SHADER_OPCODE_TYPED_ATOMIC: |
| 1968 | assert(src[2].file == BRW_IMMEDIATE_VALUE); |
| 1969 | brw_typed_atomic(p, dst, src[0], src[1], |
Matt Turner | e42fb0c | 2015-10-22 19:41:30 -0700 | [diff] [blame] | 1970 | src[2].ud, inst->mlen, !inst->dst.is_null()); |
Francisco Jerez | f118e5d | 2015-04-23 14:28:25 +0300 | [diff] [blame] | 1971 | break; |
| 1972 | |
| 1973 | case SHADER_OPCODE_TYPED_SURFACE_READ: |
| 1974 | assert(src[2].file == BRW_IMMEDIATE_VALUE); |
| 1975 | brw_typed_surface_read(p, dst, src[0], src[1], |
Matt Turner | e42fb0c | 2015-10-22 19:41:30 -0700 | [diff] [blame] | 1976 | inst->mlen, src[2].ud); |
Francisco Jerez | f118e5d | 2015-04-23 14:28:25 +0300 | [diff] [blame] | 1977 | break; |
| 1978 | |
| 1979 | case SHADER_OPCODE_TYPED_SURFACE_WRITE: |
| 1980 | assert(src[2].file == BRW_IMMEDIATE_VALUE); |
Matt Turner | e42fb0c | 2015-10-22 19:41:30 -0700 | [diff] [blame] | 1981 | brw_typed_surface_write(p, src[0], src[1], inst->mlen, src[2].ud); |
Francisco Jerez | f118e5d | 2015-04-23 14:28:25 +0300 | [diff] [blame] | 1982 | break; |
| 1983 | |
Francisco Jerez | f1d1d17 | 2015-04-23 14:30:28 +0300 | [diff] [blame] | 1984 | case SHADER_OPCODE_MEMORY_FENCE: |
| 1985 | brw_memory_fence(p, dst); |
| 1986 | break; |
| 1987 | |
Jason Ekstrand | 8a468d1 | 2016-09-14 15:09:33 -0700 | [diff] [blame] | 1988 | case SHADER_OPCODE_FIND_LIVE_CHANNEL: { |
| 1989 | const struct brw_reg mask = |
Francisco Jerez | c05a4f1 | 2016-09-15 17:24:10 -0700 | [diff] [blame] | 1990 | brw_stage_has_packed_dispatch(devinfo, stage, |
| 1991 | prog_data) ? brw_imm_ud(~0u) : |
| 1992 | stage == MESA_SHADER_FRAGMENT ? brw_vmask_reg() : |
| 1993 | brw_dmask_reg(); |
Jason Ekstrand | 8a468d1 | 2016-09-14 15:09:33 -0700 | [diff] [blame] | 1994 | brw_find_live_channel(p, dst, mask); |
Francisco Jerez | 715bc6d | 2015-04-23 14:42:53 +0300 | [diff] [blame] | 1995 | break; |
Jason Ekstrand | 8a468d1 | 2016-09-14 15:09:33 -0700 | [diff] [blame] | 1996 | } |
Francisco Jerez | 715bc6d | 2015-04-23 14:42:53 +0300 | [diff] [blame] | 1997 | |
Francisco Jerez | c74511f | 2015-02-20 20:14:24 +0200 | [diff] [blame] | 1998 | case SHADER_OPCODE_BROADCAST: |
Francisco Jerez | 81bc6de | 2016-05-19 00:10:03 -0700 | [diff] [blame] | 1999 | assert(inst->force_writemask_all); |
Francisco Jerez | c74511f | 2015-02-20 20:14:24 +0200 | [diff] [blame] | 2000 | brw_broadcast(p, dst, src[0], src[1]); |
| 2001 | break; |
| 2002 | |
Anuj Phogat | e12bbb5 | 2013-10-24 16:17:08 -0700 | [diff] [blame] | 2003 | case FS_OPCODE_SET_SAMPLE_ID: |
| 2004 | generate_set_sample_id(inst, dst, src[0], src[1]); |
| 2005 | break; |
| 2006 | |
Chad Versace | 20dfa50 | 2013-01-09 11:46:42 -0800 | [diff] [blame] | 2007 | case FS_OPCODE_PACK_HALF_2x16_SPLIT: |
| 2008 | generate_pack_half_2x16_split(inst, dst, src[0], src[1]); |
| 2009 | break; |
| 2010 | |
| 2011 | case FS_OPCODE_UNPACK_HALF_2x16_SPLIT_X: |
| 2012 | case FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y: |
| 2013 | generate_unpack_half_2x16_split(inst, dst, src[0]); |
| 2014 | break; |
| 2015 | |
Kenneth Graunke | 57a5025 | 2013-03-27 23:19:39 -0700 | [diff] [blame] | 2016 | case FS_OPCODE_PLACEHOLDER_HALT: |
| 2017 | /* This is the place where the final HALT needs to be inserted if |
| 2018 | * we've emitted any discards. If not, this will emit no code. |
| 2019 | */ |
Matt Turner | f0f7fb1 | 2014-05-19 10:20:37 -0700 | [diff] [blame] | 2020 | if (!patch_discard_jumps_to_fb_writes()) { |
Matt Turner | c9fd684 | 2014-05-25 10:30:13 -0700 | [diff] [blame] | 2021 | if (unlikely(debug_flag)) { |
Matt Turner | 92b0556 | 2014-05-25 10:42:32 -0700 | [diff] [blame] | 2022 | annotation.ann_count--; |
Matt Turner | c9fd684 | 2014-05-25 10:30:13 -0700 | [diff] [blame] | 2023 | } |
Matt Turner | f0f7fb1 | 2014-05-19 10:20:37 -0700 | [diff] [blame] | 2024 | } |
Kenneth Graunke | 57a5025 | 2013-03-27 23:19:39 -0700 | [diff] [blame] | 2025 | break; |
| 2026 | |
Chris Forbes | 6e91f2d | 2013-11-18 21:13:13 +1300 | [diff] [blame] | 2027 | case FS_OPCODE_INTERPOLATE_AT_SAMPLE: |
| 2028 | generate_pixel_interpolator_query(inst, dst, src[0], src[1], |
| 2029 | GEN7_PIXEL_INTERPOLATOR_LOC_SAMPLE); |
| 2030 | break; |
| 2031 | |
| 2032 | case FS_OPCODE_INTERPOLATE_AT_SHARED_OFFSET: |
| 2033 | generate_pixel_interpolator_query(inst, dst, src[0], src[1], |
| 2034 | GEN7_PIXEL_INTERPOLATOR_LOC_SHARED_OFFSET); |
| 2035 | break; |
| 2036 | |
| 2037 | case FS_OPCODE_INTERPOLATE_AT_PER_SLOT_OFFSET: |
| 2038 | generate_pixel_interpolator_query(inst, dst, src[0], src[1], |
| 2039 | GEN7_PIXEL_INTERPOLATOR_LOC_PER_SLOT_OFFSET); |
| 2040 | break; |
| 2041 | |
Jordan Justen | 2a4df9c | 2014-08-27 11:33:25 -0700 | [diff] [blame] | 2042 | case CS_OPCODE_CS_TERMINATE: |
| 2043 | generate_cs_terminate(inst, src[0]); |
| 2044 | break; |
| 2045 | |
Jordan Justen | f7ef8ec | 2014-08-27 11:32:08 -0700 | [diff] [blame] | 2046 | case SHADER_OPCODE_BARRIER: |
| 2047 | generate_barrier(inst, src[0]); |
| 2048 | break; |
| 2049 | |
Samuel Iglesias Gonsálvez | 6e28976 | 2016-07-07 08:38:22 +0200 | [diff] [blame] | 2050 | case BRW_OPCODE_DIM: |
| 2051 | assert(devinfo->is_haswell); |
| 2052 | assert(src[0].type == BRW_REGISTER_TYPE_DF); |
| 2053 | assert(dst.type == BRW_REGISTER_TYPE_DF); |
| 2054 | brw_DIM(p, dst, retype(src[0], BRW_REGISTER_TYPE_F)); |
| 2055 | break; |
| 2056 | |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 2057 | default: |
Jason Ekstrand | 5cb91db | 2015-04-15 14:51:18 -0700 | [diff] [blame] | 2058 | unreachable("Unsupported opcode"); |
Matt Turner | b996216 | 2014-05-27 18:47:40 -0700 | [diff] [blame] | 2059 | |
| 2060 | case SHADER_OPCODE_LOAD_PAYLOAD: |
Matt Turner | 3d82672 | 2014-06-29 14:54:01 -0700 | [diff] [blame] | 2061 | unreachable("Should be lowered by lower_load_payload()"); |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 2062 | } |
Kenneth Graunke | 776ad51 | 2014-05-30 16:41:32 -0700 | [diff] [blame] | 2063 | |
Matt Turner | 7452f18 | 2014-12-30 12:56:13 -0800 | [diff] [blame] | 2064 | if (multiple_instructions_emitted) |
| 2065 | continue; |
| 2066 | |
Matt Turner | 6d25363 | 2014-06-28 23:31:04 -0700 | [diff] [blame] | 2067 | if (inst->no_dd_clear || inst->no_dd_check || inst->conditional_mod) { |
| 2068 | assert(p->next_insn_offset == last_insn_offset + 16 || |
| 2069 | !"conditional_mod, no_dd_check, or no_dd_clear set for IR " |
| 2070 | "emitting more than 1 instruction"); |
| 2071 | |
Matt Turner | 7c79608 | 2014-06-13 14:29:25 -0700 | [diff] [blame] | 2072 | brw_inst *last = &p->store[last_insn_offset / 16]; |
Matt Turner | 6d25363 | 2014-06-28 23:31:04 -0700 | [diff] [blame] | 2073 | |
Matt Turner | 56ac259 | 2014-11-21 12:20:53 -0800 | [diff] [blame] | 2074 | if (inst->conditional_mod) |
Jason Ekstrand | 4e9c79c | 2015-04-14 18:00:06 -0700 | [diff] [blame] | 2075 | brw_inst_set_cond_modifier(p->devinfo, last, inst->conditional_mod); |
| 2076 | brw_inst_set_no_dd_clear(p->devinfo, last, inst->no_dd_clear); |
| 2077 | brw_inst_set_no_dd_check(p->devinfo, last, inst->no_dd_check); |
Kenneth Graunke | 776ad51 | 2014-05-30 16:41:32 -0700 | [diff] [blame] | 2078 | } |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 2079 | } |
| 2080 | |
Matt Turner | 90eaf01 | 2016-08-29 15:57:41 -0700 | [diff] [blame] | 2081 | brw_set_uip_jip(p, start_offset); |
Matt Turner | 92b0556 | 2014-05-25 10:42:32 -0700 | [diff] [blame] | 2082 | annotation_finalize(&annotation, p->next_insn_offset); |
| 2083 | |
Matt Turner | 0b45d47 | 2015-06-29 14:08:51 -0700 | [diff] [blame] | 2084 | #ifndef NDEBUG |
| 2085 | bool validated = brw_validate_instructions(p, start_offset, &annotation); |
| 2086 | #else |
| 2087 | if (unlikely(debug_flag)) |
| 2088 | brw_validate_instructions(p, start_offset, &annotation); |
| 2089 | #endif |
| 2090 | |
Matt Turner | 757d7dd | 2014-05-25 14:56:41 -0700 | [diff] [blame] | 2091 | int before_size = p->next_insn_offset - start_offset; |
Matt Turner | 92b0556 | 2014-05-25 10:42:32 -0700 | [diff] [blame] | 2092 | brw_compact_instructions(p, start_offset, annotation.ann_count, |
| 2093 | annotation.ann); |
Matt Turner | 757d7dd | 2014-05-25 14:56:41 -0700 | [diff] [blame] | 2094 | int after_size = p->next_insn_offset - start_offset; |
Matt Turner | 92b0556 | 2014-05-25 10:42:32 -0700 | [diff] [blame] | 2095 | |
| 2096 | if (unlikely(debug_flag)) { |
Kristian Høgsberg | 9a1af7b | 2014-10-27 19:40:47 -0700 | [diff] [blame] | 2097 | fprintf(stderr, "Native code for %s\n" |
Connor Abbott | 45cd76e | 2015-06-06 10:55:21 -0400 | [diff] [blame] | 2098 | "SIMD%d shader: %d instructions. %d loops. %u cycles. %d:%d spills:fills. Promoted %u constants. Compacted %d to %d" |
Kristian Høgsberg | 9a1af7b | 2014-10-27 19:40:47 -0700 | [diff] [blame] | 2099 | " bytes (%.0f%%)\n", |
Connor Abbott | 45cd76e | 2015-06-06 10:55:21 -0400 | [diff] [blame] | 2100 | shader_name, dispatch_width, before_size / 16, loop_count, cfg->cycle_count, |
Matt Turner | b0d422c | 2015-03-16 12:18:31 -0700 | [diff] [blame] | 2101 | spill_count, fill_count, promoted_constants, before_size, after_size, |
Matt Turner | 757d7dd | 2014-05-25 14:56:41 -0700 | [diff] [blame] | 2102 | 100.0f * (before_size - after_size) / before_size); |
Matt Turner | 6fdfe3f | 2014-05-25 10:46:55 -0700 | [diff] [blame] | 2103 | |
Jason Ekstrand | 9c89e47 | 2015-04-15 15:01:25 -0700 | [diff] [blame] | 2104 | dump_assembly(p->store, annotation.ann_count, annotation.ann, |
Jason Ekstrand | e00314b | 2015-10-05 15:49:34 -0700 | [diff] [blame] | 2105 | p->devinfo); |
Matt Turner | 93e371c | 2015-06-29 14:05:27 -0700 | [diff] [blame] | 2106 | ralloc_free(annotation.mem_ctx); |
Matt Turner | 92b0556 | 2014-05-25 10:42:32 -0700 | [diff] [blame] | 2107 | } |
Matt Turner | 0b45d47 | 2015-06-29 14:08:51 -0700 | [diff] [blame] | 2108 | assert(validated); |
Kristian Høgsberg | f2bb655 | 2014-11-13 16:28:08 -0800 | [diff] [blame] | 2109 | |
Jason Ekstrand | e639a6f | 2015-04-16 14:13:52 -0700 | [diff] [blame] | 2110 | compiler->shader_debug_log(log_data, |
Connor Abbott | 45cd76e | 2015-06-06 10:55:21 -0400 | [diff] [blame] | 2111 | "%s SIMD%d shader: %d inst, %d loops, %u cycles, " |
Jason Ekstrand | e639a6f | 2015-04-16 14:13:52 -0700 | [diff] [blame] | 2112 | "%d:%d spills:fills, Promoted %u constants, " |
Matt Turner | 138a7dc | 2016-01-13 16:17:26 -0800 | [diff] [blame] | 2113 | "compacted %d to %d bytes.", |
Jason Ekstrand | 9870f79 | 2016-01-14 20:27:51 -0800 | [diff] [blame] | 2114 | _mesa_shader_stage_to_abbrev(stage), |
| 2115 | dispatch_width, before_size / 16, |
Connor Abbott | 45cd76e | 2015-06-06 10:55:21 -0400 | [diff] [blame] | 2116 | loop_count, cfg->cycle_count, spill_count, |
| 2117 | fill_count, promoted_constants, before_size, |
| 2118 | after_size); |
Matt Turner | 9ed8d00 | 2014-11-14 12:46:44 -0800 | [diff] [blame] | 2119 | |
Kristian Høgsberg | f2bb655 | 2014-11-13 16:28:08 -0800 | [diff] [blame] | 2120 | return start_offset; |
Eric Anholt | 11dd9e9 | 2011-05-24 16:34:27 -0700 | [diff] [blame] | 2121 | } |
Kenneth Graunke | ea681a0 | 2012-11-09 01:05:47 -0800 | [diff] [blame] | 2122 | |
| 2123 | const unsigned * |
Kristian Høgsberg | f2bb655 | 2014-11-13 16:28:08 -0800 | [diff] [blame] | 2124 | fs_generator::get_assembly(unsigned int *assembly_size) |
Kenneth Graunke | ea681a0 | 2012-11-09 01:05:47 -0800 | [diff] [blame] | 2125 | { |
Kenneth Graunke | ea681a0 | 2012-11-09 01:05:47 -0800 | [diff] [blame] | 2126 | return brw_get_program(p, assembly_size); |
| 2127 | } |