blob: 5fe231df2b43a739cb9a648e117c6c8d6b08fe5c [file] [log] [blame]
Eric Anholt11dd9e92011-05-24 16:34:27 -07001/*
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
24/** @file brw_fs_emit.cpp
25 *
26 * This file supports emitting code from the FS LIR to the actual
27 * native instructions.
28 */
29
30extern "C" {
31#include "main/macros.h"
32#include "brw_context.h"
33#include "brw_eu.h"
34} /* extern "C" */
35
36#include "brw_fs.h"
Eric Anholt5ed57d92012-10-03 13:03:12 -070037#include "brw_cfg.h"
Eric Anholt11dd9e92011-05-24 16:34:27 -070038
Kenneth Graunkeea681a02012-11-09 01:05:47 -080039fs_generator::fs_generator(struct brw_context *brw,
40 struct brw_wm_compile *c,
41 struct gl_shader_program *prog,
42 struct gl_fragment_program *fp,
43 bool dual_source_output)
44
45 : brw(brw), c(c), prog(prog), fp(fp), dual_source_output(dual_source_output)
46{
Kenneth Graunkeea681a02012-11-09 01:05:47 -080047 intel = &brw->intel;
48 ctx = &intel->ctx;
49
50 shader = prog ? prog->_LinkedShaders[MESA_SHADER_FRAGMENT] : NULL;
51
52 mem_ctx = c;
Kenneth Graunke91367232012-11-20 19:26:52 -080053
54 p = rzalloc(mem_ctx, struct brw_compile);
55 brw_init_compile(brw, p, mem_ctx);
Kenneth Graunkeea681a02012-11-09 01:05:47 -080056}
57
58fs_generator::~fs_generator()
59{
60}
61
Eric Anholt11dd9e92011-05-24 16:34:27 -070062void
Eric Anholtbeafced2012-12-06 10:15:08 -080063fs_generator::patch_discard_jumps_to_fb_writes()
64{
65 if (intel->gen < 6 || this->discard_halt_patches.is_empty())
66 return;
67
68 /* There is a somewhat strange undocumented requirement of using
69 * HALT, according to the simulator. If some channel has HALTed to
70 * a particular UIP, then by the end of the program, every channel
71 * must have HALTed to that UIP. Furthermore, the tracking is a
72 * stack, so you can't do the final halt of a UIP after starting
73 * halting to a new UIP.
74 *
75 * Symptoms of not emitting this instruction on actual hardware
76 * included GPU hangs and sparkly rendering on the piglit discard
77 * tests.
78 */
79 struct brw_instruction *last_halt = gen6_HALT(p);
80 last_halt->bits3.break_cont.uip = 2;
81 last_halt->bits3.break_cont.jip = 2;
82
83 int ip = p->nr_insn;
84
85 foreach_list(node, &this->discard_halt_patches) {
86 ip_record *patch_ip = (ip_record *)node;
87 struct brw_instruction *patch = &p->store[patch_ip->ip];
88
89 assert(patch->header.opcode == BRW_OPCODE_HALT);
90 /* HALT takes a half-instruction distance from the pre-incremented IP. */
91 patch->bits3.break_cont.uip = (ip - patch_ip->ip) * 2;
92 }
93
94 this->discard_halt_patches.make_empty();
95}
96
97void
Kenneth Graunkeea681a02012-11-09 01:05:47 -080098fs_generator::generate_fb_write(fs_inst *inst)
Eric Anholt11dd9e92011-05-24 16:34:27 -070099{
Kenneth Graunke2e5a1a22011-10-07 12:26:50 -0700100 bool eot = inst->eot;
Eric Anholt11dd9e92011-05-24 16:34:27 -0700101 struct brw_reg implied_header;
Eric Anholt29362872012-04-25 13:58:07 -0700102 uint32_t msg_control;
Eric Anholt11dd9e92011-05-24 16:34:27 -0700103
104 /* Header is 2 regs, g0 and g1 are the contents. g0 will be implied
105 * move, here's g1.
106 */
107 brw_push_insn_state(p);
108 brw_set_mask_control(p, BRW_MASK_DISABLE);
109 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
110
Eric Anholtd5016492012-12-06 12:15:13 -0800111 if (fp->UsesKill) {
112 struct brw_reg pixel_mask;
113
114 if (intel->gen >= 6)
115 pixel_mask = retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW);
116 else
117 pixel_mask = retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW);
118
119 brw_MOV(p, pixel_mask, brw_flag_reg(0, 1));
120 }
121
Eric Anholt11dd9e92011-05-24 16:34:27 -0700122 if (inst->header_present) {
123 if (intel->gen >= 6) {
124 brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
125 brw_MOV(p,
126 retype(brw_message_reg(inst->base_mrf), BRW_REGISTER_TYPE_UD),
127 retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD));
128 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
129
Chris Forbes1415a182013-07-01 23:30:55 +1200130 if (inst->target > 0 && c->key.replicate_alpha) {
Anuj Phogate592f7d2012-08-01 16:32:06 -0700131 /* Set "Source0 Alpha Present to RenderTarget" bit in message
132 * header.
133 */
134 brw_OR(p,
135 vec1(retype(brw_message_reg(inst->base_mrf), BRW_REGISTER_TYPE_UD)),
136 vec1(retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD)),
137 brw_imm_ud(0x1 << 11));
138 }
139
Eric Anholt11dd9e92011-05-24 16:34:27 -0700140 if (inst->target > 0) {
141 /* Set the render target index for choosing BLEND_STATE. */
Eric Anholt3daa2d92011-07-25 15:39:03 -0700142 brw_MOV(p, retype(brw_vec1_reg(BRW_MESSAGE_REGISTER_FILE,
143 inst->base_mrf, 2),
Eric Anholt11dd9e92011-05-24 16:34:27 -0700144 BRW_REGISTER_TYPE_UD),
145 brw_imm_ud(inst->target));
146 }
147
148 implied_header = brw_null_reg();
149 } else {
150 implied_header = retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW);
151
152 brw_MOV(p,
153 brw_message_reg(inst->base_mrf + 1),
154 brw_vec8_grf(1, 0));
155 }
156 } else {
157 implied_header = brw_null_reg();
158 }
159
Kenneth Graunkeea681a02012-11-09 01:05:47 -0800160 if (this->dual_source_output)
Eric Anholt29362872012-04-25 13:58:07 -0700161 msg_control = BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_DUAL_SOURCE_SUBSPAN01;
Kenneth Graunkea303df82012-11-20 13:50:52 -0800162 else if (dispatch_width == 16)
Eric Anholt29362872012-04-25 13:58:07 -0700163 msg_control = BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD16_SINGLE_SOURCE;
164 else
165 msg_control = BRW_DATAPORT_RENDER_TARGET_WRITE_SIMD8_SINGLE_SOURCE_SUBSPAN01;
166
Eric Anholt11dd9e92011-05-24 16:34:27 -0700167 brw_pop_insn_state(p);
168
169 brw_fb_WRITE(p,
Kenneth Graunkea303df82012-11-20 13:50:52 -0800170 dispatch_width,
Eric Anholt11dd9e92011-05-24 16:34:27 -0700171 inst->base_mrf,
172 implied_header,
Eric Anholt29362872012-04-25 13:58:07 -0700173 msg_control,
Eric Anholt11dd9e92011-05-24 16:34:27 -0700174 inst->target,
175 inst->mlen,
176 0,
177 eot,
178 inst->header_present);
179}
180
181/* Computes the integer pixel x,y values from the origin.
182 *
183 * This is the basis of gl_FragCoord computation, but is also used
184 * pre-gen6 for computing the deltas from v0 for computing
185 * interpolation.
186 */
187void
Kenneth Graunkeea681a02012-11-09 01:05:47 -0800188fs_generator::generate_pixel_xy(struct brw_reg dst, bool is_x)
Eric Anholt11dd9e92011-05-24 16:34:27 -0700189{
190 struct brw_reg g1_uw = retype(brw_vec1_grf(1, 0), BRW_REGISTER_TYPE_UW);
191 struct brw_reg src;
192 struct brw_reg deltas;
193
194 if (is_x) {
195 src = stride(suboffset(g1_uw, 4), 2, 4, 0);
196 deltas = brw_imm_v(0x10101010);
197 } else {
198 src = stride(suboffset(g1_uw, 5), 2, 4, 0);
199 deltas = brw_imm_v(0x11001100);
200 }
201
Kenneth Graunkea303df82012-11-20 13:50:52 -0800202 if (dispatch_width == 16) {
Eric Anholt11dd9e92011-05-24 16:34:27 -0700203 dst = vec16(dst);
204 }
205
206 /* We do this 8 or 16-wide, but since the destination is UW we
207 * don't do compression in the 16-wide case.
208 */
209 brw_push_insn_state(p);
210 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
211 brw_ADD(p, dst, src, deltas);
212 brw_pop_insn_state(p);
213}
214
215void
Kenneth Graunkeea681a02012-11-09 01:05:47 -0800216fs_generator::generate_linterp(fs_inst *inst,
Eric Anholt11dd9e92011-05-24 16:34:27 -0700217 struct brw_reg dst, struct brw_reg *src)
218{
219 struct brw_reg delta_x = src[0];
220 struct brw_reg delta_y = src[1];
221 struct brw_reg interp = src[2];
222
223 if (brw->has_pln &&
224 delta_y.nr == delta_x.nr + 1 &&
225 (intel->gen >= 6 || (delta_x.nr & 1) == 0)) {
226 brw_PLN(p, dst, interp, delta_x);
227 } else {
228 brw_LINE(p, brw_null_reg(), interp, delta_x);
229 brw_MAC(p, dst, suboffset(interp, 1), delta_y);
230 }
231}
232
233void
Kenneth Graunkeea681a02012-11-09 01:05:47 -0800234fs_generator::generate_math1_gen7(fs_inst *inst,
Kenneth Graunkea73c65c2011-10-18 12:24:47 -0700235 struct brw_reg dst,
236 struct brw_reg src0)
237{
238 assert(inst->mlen == 0);
239 brw_math(p, dst,
240 brw_math_function(inst->opcode),
Kenneth Graunkea73c65c2011-10-18 12:24:47 -0700241 0, src0,
242 BRW_MATH_DATA_VECTOR,
243 BRW_MATH_PRECISION_FULL);
244}
245
246void
Kenneth Graunkeea681a02012-11-09 01:05:47 -0800247fs_generator::generate_math2_gen7(fs_inst *inst,
Kenneth Graunkea73c65c2011-10-18 12:24:47 -0700248 struct brw_reg dst,
249 struct brw_reg src0,
250 struct brw_reg src1)
251{
252 assert(inst->mlen == 0);
253 brw_math2(p, dst, brw_math_function(inst->opcode), src0, src1);
254}
255
256void
Kenneth Graunkeea681a02012-11-09 01:05:47 -0800257fs_generator::generate_math1_gen6(fs_inst *inst,
Kenneth Graunke74e927b2011-08-18 11:55:42 -0700258 struct brw_reg dst,
259 struct brw_reg src0)
Eric Anholt11dd9e92011-05-24 16:34:27 -0700260{
Eric Anholtaf3c9802011-05-02 09:45:40 -0700261 int op = brw_math_function(inst->opcode);
Eric Anholt11dd9e92011-05-24 16:34:27 -0700262
Kenneth Graunke74e927b2011-08-18 11:55:42 -0700263 assert(inst->mlen == 0);
Eric Anholt11dd9e92011-05-24 16:34:27 -0700264
Kenneth Graunke74e927b2011-08-18 11:55:42 -0700265 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
266 brw_math(p, dst,
267 op,
Kenneth Graunke74e927b2011-08-18 11:55:42 -0700268 0, src0,
269 BRW_MATH_DATA_VECTOR,
270 BRW_MATH_PRECISION_FULL);
Eric Anholt11dd9e92011-05-24 16:34:27 -0700271
Kenneth Graunkea303df82012-11-20 13:50:52 -0800272 if (dispatch_width == 16) {
Kenneth Graunke74e927b2011-08-18 11:55:42 -0700273 brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
274 brw_math(p, sechalf(dst),
Eric Anholt11dd9e92011-05-24 16:34:27 -0700275 op,
Kenneth Graunke74e927b2011-08-18 11:55:42 -0700276 0, sechalf(src0),
277 BRW_MATH_DATA_VECTOR,
278 BRW_MATH_PRECISION_FULL);
279 brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
280 }
281}
282
283void
Kenneth Graunkeea681a02012-11-09 01:05:47 -0800284fs_generator::generate_math2_gen6(fs_inst *inst,
Kenneth Graunke74e927b2011-08-18 11:55:42 -0700285 struct brw_reg dst,
286 struct brw_reg src0,
287 struct brw_reg src1)
288{
289 int op = brw_math_function(inst->opcode);
290
291 assert(inst->mlen == 0);
292
293 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
294 brw_math2(p, dst, op, src0, src1);
295
Kenneth Graunkea303df82012-11-20 13:50:52 -0800296 if (dispatch_width == 16) {
Kenneth Graunke74e927b2011-08-18 11:55:42 -0700297 brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
298 brw_math2(p, sechalf(dst), op, sechalf(src0), sechalf(src1));
299 brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
300 }
301}
302
303void
Kenneth Graunkeea681a02012-11-09 01:05:47 -0800304fs_generator::generate_math_gen4(fs_inst *inst,
Kenneth Graunke74e927b2011-08-18 11:55:42 -0700305 struct brw_reg dst,
306 struct brw_reg src)
307{
308 int op = brw_math_function(inst->opcode);
309
310 assert(inst->mlen >= 1);
311
312 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
313 brw_math(p, dst,
314 op,
Kenneth Graunke74e927b2011-08-18 11:55:42 -0700315 inst->base_mrf, src,
316 BRW_MATH_DATA_VECTOR,
317 BRW_MATH_PRECISION_FULL);
318
Kenneth Graunkea303df82012-11-20 13:50:52 -0800319 if (dispatch_width == 16) {
Kenneth Graunke74e927b2011-08-18 11:55:42 -0700320 brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
321 brw_math(p, sechalf(dst),
322 op,
Kenneth Graunke74e927b2011-08-18 11:55:42 -0700323 inst->base_mrf + 1, sechalf(src),
Eric Anholt11dd9e92011-05-24 16:34:27 -0700324 BRW_MATH_DATA_VECTOR,
325 BRW_MATH_PRECISION_FULL);
326
Kenneth Graunke74e927b2011-08-18 11:55:42 -0700327 brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
Eric Anholt11dd9e92011-05-24 16:34:27 -0700328 }
329}
330
331void
Kenneth Graunke1b77d212013-03-30 00:15:54 -0700332fs_generator::generate_math_g45(fs_inst *inst,
333 struct brw_reg dst,
334 struct brw_reg src)
335{
336 if (inst->opcode == SHADER_OPCODE_POW ||
337 inst->opcode == SHADER_OPCODE_INT_QUOTIENT ||
338 inst->opcode == SHADER_OPCODE_INT_REMAINDER) {
339 generate_math_gen4(inst, dst, src);
340 return;
341 }
342
343 int op = brw_math_function(inst->opcode);
344
345 assert(inst->mlen >= 1);
346
347 brw_math(p, dst,
348 op,
349 inst->base_mrf, src,
350 BRW_MATH_DATA_VECTOR,
351 BRW_MATH_PRECISION_FULL);
352}
353
354void
Kenneth Graunkeea681a02012-11-09 01:05:47 -0800355fs_generator::generate_tex(fs_inst *inst, struct brw_reg dst, struct brw_reg src)
Eric Anholt11dd9e92011-05-24 16:34:27 -0700356{
357 int msg_type = -1;
358 int rlen = 4;
359 uint32_t simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD8;
Eric Anholt7e84a642011-11-09 16:07:57 -0800360 uint32_t return_format;
361
362 switch (dst.type) {
363 case BRW_REGISTER_TYPE_D:
364 return_format = BRW_SAMPLER_RETURN_FORMAT_SINT32;
365 break;
366 case BRW_REGISTER_TYPE_UD:
367 return_format = BRW_SAMPLER_RETURN_FORMAT_UINT32;
368 break;
369 default:
370 return_format = BRW_SAMPLER_RETURN_FORMAT_FLOAT32;
371 break;
372 }
Eric Anholt11dd9e92011-05-24 16:34:27 -0700373
Kenneth Graunkea303df82012-11-20 13:50:52 -0800374 if (dispatch_width == 16)
Eric Anholt11dd9e92011-05-24 16:34:27 -0700375 simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16;
376
377 if (intel->gen >= 5) {
378 switch (inst->opcode) {
Kenneth Graunkefebad172011-10-26 12:58:37 -0700379 case SHADER_OPCODE_TEX:
Eric Anholt11dd9e92011-05-24 16:34:27 -0700380 if (inst->shadow_compare) {
381 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_COMPARE;
382 } else {
383 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE;
384 }
385 break;
386 case FS_OPCODE_TXB:
387 if (inst->shadow_compare) {
388 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS_COMPARE;
389 } else {
390 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_BIAS;
391 }
392 break;
Kenneth Graunkefebad172011-10-26 12:58:37 -0700393 case SHADER_OPCODE_TXL:
Eric Anholt11dd9e92011-05-24 16:34:27 -0700394 if (inst->shadow_compare) {
395 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LOD_COMPARE;
396 } else {
397 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LOD;
398 }
399 break;
Kenneth Graunkefebad172011-10-26 12:58:37 -0700400 case SHADER_OPCODE_TXS:
Kenneth Graunkeecf89632011-06-19 01:47:50 -0700401 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_RESINFO;
402 break;
Kenneth Graunkefebad172011-10-26 12:58:37 -0700403 case SHADER_OPCODE_TXD:
Kenneth Graunke899017f2013-01-04 07:53:09 -0800404 if (inst->shadow_compare) {
405 /* Gen7.5+. Otherwise, lowered by brw_lower_texture_gradients(). */
Kenneth Graunke794de2f2013-07-06 00:15:44 -0700406 assert(brw->is_haswell);
Kenneth Graunke899017f2013-01-04 07:53:09 -0800407 msg_type = HSW_SAMPLER_MESSAGE_SAMPLE_DERIV_COMPARE;
408 } else {
409 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_DERIVS;
410 }
Eric Anholt11dd9e92011-05-24 16:34:27 -0700411 break;
Kenneth Graunkefebad172011-10-26 12:58:37 -0700412 case SHADER_OPCODE_TXF:
Kenneth Graunke30be2cc2011-08-25 17:13:37 -0700413 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LD;
414 break;
Chris Forbesf52ce6a2013-01-24 21:35:15 +1300415 case SHADER_OPCODE_TXF_MS:
416 if (intel->gen >= 7)
417 msg_type = GEN7_SAMPLER_MESSAGE_SAMPLE_LD2DMS;
418 else
419 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LD;
420 break;
Matt Turnerb8aa9f72013-03-06 14:47:01 -0800421 case SHADER_OPCODE_LOD:
422 msg_type = GEN5_SAMPLER_MESSAGE_LOD;
423 break;
Eric Anholt6034b9a2011-05-03 10:55:50 -0700424 default:
425 assert(!"not reached");
426 break;
Eric Anholt11dd9e92011-05-24 16:34:27 -0700427 }
428 } else {
429 switch (inst->opcode) {
Kenneth Graunkefebad172011-10-26 12:58:37 -0700430 case SHADER_OPCODE_TEX:
Eric Anholt11dd9e92011-05-24 16:34:27 -0700431 /* Note that G45 and older determines shadow compare and dispatch width
432 * from message length for most messages.
433 */
Kenneth Graunkea303df82012-11-20 13:50:52 -0800434 assert(dispatch_width == 8);
Eric Anholt11dd9e92011-05-24 16:34:27 -0700435 msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE;
436 if (inst->shadow_compare) {
437 assert(inst->mlen == 6);
438 } else {
439 assert(inst->mlen <= 4);
440 }
441 break;
442 case FS_OPCODE_TXB:
443 if (inst->shadow_compare) {
444 assert(inst->mlen == 6);
445 msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_BIAS_COMPARE;
446 } else {
447 assert(inst->mlen == 9);
448 msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS;
449 simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16;
450 }
451 break;
Kenneth Graunkefebad172011-10-26 12:58:37 -0700452 case SHADER_OPCODE_TXL:
Eric Anholt11dd9e92011-05-24 16:34:27 -0700453 if (inst->shadow_compare) {
454 assert(inst->mlen == 6);
455 msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_LOD_COMPARE;
456 } else {
457 assert(inst->mlen == 9);
458 msg_type = BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_LOD;
459 simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16;
460 }
461 break;
Kenneth Graunkefebad172011-10-26 12:58:37 -0700462 case SHADER_OPCODE_TXD:
Kenneth Graunke6430df32011-06-10 14:48:46 -0700463 /* There is no sample_d_c message; comparisons are done manually */
Kenneth Graunke6c947cf2011-06-08 16:05:34 -0700464 assert(inst->mlen == 7 || inst->mlen == 10);
465 msg_type = BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE_GRADIENTS;
Eric Anholt11dd9e92011-05-24 16:34:27 -0700466 break;
Kenneth Graunkefebad172011-10-26 12:58:37 -0700467 case SHADER_OPCODE_TXF:
Kenneth Graunke47b556f2011-09-06 16:39:01 -0700468 assert(inst->mlen == 9);
469 msg_type = BRW_SAMPLER_MESSAGE_SIMD16_LD;
470 simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16;
471 break;
Kenneth Graunkefebad172011-10-26 12:58:37 -0700472 case SHADER_OPCODE_TXS:
Kenneth Graunke4eeb4c12011-08-17 10:45:47 -0700473 assert(inst->mlen == 3);
474 msg_type = BRW_SAMPLER_MESSAGE_SIMD16_RESINFO;
475 simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16;
476 break;
Eric Anholt6034b9a2011-05-03 10:55:50 -0700477 default:
478 assert(!"not reached");
479 break;
Eric Anholt11dd9e92011-05-24 16:34:27 -0700480 }
481 }
482 assert(msg_type != -1);
483
484 if (simd_mode == BRW_SAMPLER_SIMD_MODE_SIMD16) {
485 rlen = 8;
486 dst = vec16(dst);
487 }
488
Kenneth Graunke82bfb4b2012-08-04 20:33:13 -0700489 /* Load the message header if present. If there's a texture offset,
490 * we need to set it up explicitly and load the offset bitfield.
491 * Otherwise, we can use an implied move from g0 to the first message reg.
492 */
493 if (inst->texture_offset) {
494 brw_push_insn_state(p);
Eric Anholt86536a32012-08-30 11:07:52 -0700495 brw_set_mask_control(p, BRW_MASK_DISABLE);
Kenneth Graunke82bfb4b2012-08-04 20:33:13 -0700496 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
497 /* Explicitly set up the message header by copying g0 to the MRF. */
498 brw_MOV(p, retype(brw_message_reg(inst->base_mrf), BRW_REGISTER_TYPE_UD),
499 retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UD));
500
501 /* Then set the offset bits in DWord 2. */
502 brw_MOV(p, retype(brw_vec1_reg(BRW_MESSAGE_REGISTER_FILE,
503 inst->base_mrf, 2), BRW_REGISTER_TYPE_UD),
504 brw_imm_ud(inst->texture_offset));
505 brw_pop_insn_state(p);
506 } else if (inst->header_present) {
507 /* Set up an implied move from g0 to the MRF. */
508 src = retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW);
509 }
510
Eric Anholt11dd9e92011-05-24 16:34:27 -0700511 brw_SAMPLE(p,
512 retype(dst, BRW_REGISTER_TYPE_UW),
513 inst->base_mrf,
514 src,
515 SURF_INDEX_TEXTURE(inst->sampler),
516 inst->sampler,
Eric Anholt11dd9e92011-05-24 16:34:27 -0700517 msg_type,
518 rlen,
519 inst->mlen,
Eric Anholt11dd9e92011-05-24 16:34:27 -0700520 inst->header_present,
Eric Anholt7e84a642011-11-09 16:07:57 -0800521 simd_mode,
522 return_format);
Eric Anholt11dd9e92011-05-24 16:34:27 -0700523}
524
525
526/* For OPCODE_DDX and OPCODE_DDY, per channel of output we've got input
527 * looking like:
528 *
529 * arg0: ss0.tl ss0.tr ss0.bl ss0.br ss1.tl ss1.tr ss1.bl ss1.br
530 *
531 * and we're trying to produce:
532 *
533 * DDX DDY
534 * dst: (ss0.tr - ss0.tl) (ss0.tl - ss0.bl)
535 * (ss0.tr - ss0.tl) (ss0.tr - ss0.br)
536 * (ss0.br - ss0.bl) (ss0.tl - ss0.bl)
537 * (ss0.br - ss0.bl) (ss0.tr - ss0.br)
538 * (ss1.tr - ss1.tl) (ss1.tl - ss1.bl)
539 * (ss1.tr - ss1.tl) (ss1.tr - ss1.br)
540 * (ss1.br - ss1.bl) (ss1.tl - ss1.bl)
541 * (ss1.br - ss1.bl) (ss1.tr - ss1.br)
542 *
543 * and add another set of two more subspans if in 16-pixel dispatch mode.
544 *
545 * For DDX, it ends up being easy: width = 2, horiz=0 gets us the same result
546 * for each pair, and vertstride = 2 jumps us 2 elements after processing a
547 * pair. But for DDY, it's harder, as we want to produce the pairs swizzled
548 * between each other. We could probably do it like ddx and swizzle the right
549 * order later, but bail for now and just produce
550 * ((ss0.tl - ss0.bl)x4 (ss1.tl - ss1.bl)x4)
551 */
552void
Kenneth Graunkeea681a02012-11-09 01:05:47 -0800553fs_generator::generate_ddx(fs_inst *inst, struct brw_reg dst, struct brw_reg src)
Eric Anholt11dd9e92011-05-24 16:34:27 -0700554{
555 struct brw_reg src0 = brw_reg(src.file, src.nr, 1,
556 BRW_REGISTER_TYPE_F,
557 BRW_VERTICAL_STRIDE_2,
558 BRW_WIDTH_2,
559 BRW_HORIZONTAL_STRIDE_0,
560 BRW_SWIZZLE_XYZW, WRITEMASK_XYZW);
561 struct brw_reg src1 = brw_reg(src.file, src.nr, 0,
562 BRW_REGISTER_TYPE_F,
563 BRW_VERTICAL_STRIDE_2,
564 BRW_WIDTH_2,
565 BRW_HORIZONTAL_STRIDE_0,
566 BRW_SWIZZLE_XYZW, WRITEMASK_XYZW);
567 brw_ADD(p, dst, src0, negate(src1));
568}
569
Paul Berry82d25962012-06-20 13:40:45 -0700570/* The negate_value boolean is used to negate the derivative computation for
571 * FBOs, since they place the origin at the upper left instead of the lower
572 * left.
573 */
Eric Anholt11dd9e92011-05-24 16:34:27 -0700574void
Kenneth Graunkeea681a02012-11-09 01:05:47 -0800575fs_generator::generate_ddy(fs_inst *inst, struct brw_reg dst, struct brw_reg src,
Paul Berry82d25962012-06-20 13:40:45 -0700576 bool negate_value)
Eric Anholt11dd9e92011-05-24 16:34:27 -0700577{
578 struct brw_reg src0 = brw_reg(src.file, src.nr, 0,
579 BRW_REGISTER_TYPE_F,
580 BRW_VERTICAL_STRIDE_4,
581 BRW_WIDTH_4,
582 BRW_HORIZONTAL_STRIDE_0,
583 BRW_SWIZZLE_XYZW, WRITEMASK_XYZW);
584 struct brw_reg src1 = brw_reg(src.file, src.nr, 2,
585 BRW_REGISTER_TYPE_F,
586 BRW_VERTICAL_STRIDE_4,
587 BRW_WIDTH_4,
588 BRW_HORIZONTAL_STRIDE_0,
589 BRW_SWIZZLE_XYZW, WRITEMASK_XYZW);
Paul Berry82d25962012-06-20 13:40:45 -0700590 if (negate_value)
591 brw_ADD(p, dst, src1, negate(src0));
592 else
593 brw_ADD(p, dst, src0, negate(src1));
Eric Anholt11dd9e92011-05-24 16:34:27 -0700594}
595
596void
Eric Anholtbeafced2012-12-06 10:15:08 -0800597fs_generator::generate_discard_jump(fs_inst *inst)
598{
599 assert(intel->gen >= 6);
600
601 /* This HALT will be patched up at FB write time to point UIP at the end of
602 * the program, and at brw_uip_jip() JIP will be set to the end of the
603 * current block (or the program).
604 */
605 this->discard_halt_patches.push_tail(new(mem_ctx) ip_record(p->nr_insn));
606
607 brw_push_insn_state(p);
608 brw_set_mask_control(p, BRW_MASK_DISABLE);
609 gen6_HALT(p);
610 brw_pop_insn_state(p);
611}
612
613void
Kenneth Graunkeea681a02012-11-09 01:05:47 -0800614fs_generator::generate_spill(fs_inst *inst, struct brw_reg src)
Eric Anholt11dd9e92011-05-24 16:34:27 -0700615{
616 assert(inst->mlen != 0);
617
618 brw_MOV(p,
619 retype(brw_message_reg(inst->base_mrf + 1), BRW_REGISTER_TYPE_UD),
620 retype(src, BRW_REGISTER_TYPE_UD));
621 brw_oword_block_write_scratch(p, brw_message_reg(inst->base_mrf), 1,
622 inst->offset);
623}
624
625void
Kenneth Graunkeea681a02012-11-09 01:05:47 -0800626fs_generator::generate_unspill(fs_inst *inst, struct brw_reg dst)
Eric Anholt11dd9e92011-05-24 16:34:27 -0700627{
628 assert(inst->mlen != 0);
629
Eric Anholt11dd9e92011-05-24 16:34:27 -0700630 brw_oword_block_read_scratch(p, dst, brw_message_reg(inst->base_mrf), 1,
631 inst->offset);
Eric Anholt11dd9e92011-05-24 16:34:27 -0700632}
633
634void
Eric Anholt29340d02012-11-07 10:42:34 -0800635fs_generator::generate_uniform_pull_constant_load(fs_inst *inst,
636 struct brw_reg dst,
637 struct brw_reg index,
638 struct brw_reg offset)
Eric Anholt11dd9e92011-05-24 16:34:27 -0700639{
640 assert(inst->mlen != 0);
641
Eric Anholt454dc832012-06-20 15:41:14 -0700642 assert(index.file == BRW_IMMEDIATE_VALUE &&
643 index.type == BRW_REGISTER_TYPE_UD);
644 uint32_t surf_index = index.dw1.ud;
645
646 assert(offset.file == BRW_IMMEDIATE_VALUE &&
647 offset.type == BRW_REGISTER_TYPE_UD);
648 uint32_t read_offset = offset.dw1.ud;
649
Eric Anholt11dd9e92011-05-24 16:34:27 -0700650 brw_oword_block_read(p, dst, brw_message_reg(inst->base_mrf),
Eric Anholt454dc832012-06-20 15:41:14 -0700651 read_offset, surf_index);
Eric Anholt11dd9e92011-05-24 16:34:27 -0700652}
653
Eric Anholtd8214e42012-11-07 11:18:34 -0800654void
Eric Anholt461a2972012-12-05 00:06:30 -0800655fs_generator::generate_uniform_pull_constant_load_gen7(fs_inst *inst,
656 struct brw_reg dst,
657 struct brw_reg index,
658 struct brw_reg offset)
659{
660 assert(inst->mlen == 0);
661
662 assert(index.file == BRW_IMMEDIATE_VALUE &&
663 index.type == BRW_REGISTER_TYPE_UD);
664 uint32_t surf_index = index.dw1.ud;
665
666 assert(offset.file == BRW_GENERAL_REGISTER_FILE);
Eric Anholt4c1fdae2013-03-06 14:47:22 -0800667 /* Reference just the dword we need, to avoid angering validate_reg(). */
668 offset = brw_vec1_grf(offset.nr, 0);
Eric Anholt461a2972012-12-05 00:06:30 -0800669
670 brw_push_insn_state(p);
671 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
672 brw_set_mask_control(p, BRW_MASK_DISABLE);
673 struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
674 brw_pop_insn_state(p);
675
Eric Anholt4c1fdae2013-03-06 14:47:22 -0800676 /* We use the SIMD4x2 mode because we want to end up with 4 components in
677 * the destination loaded consecutively from the same offset (which appears
678 * in the first component, and the rest are ignored).
679 */
680 dst.width = BRW_WIDTH_4;
Eric Anholt461a2972012-12-05 00:06:30 -0800681 brw_set_dest(p, send, dst);
682 brw_set_src0(p, send, offset);
Eric Anholt4c1fdae2013-03-06 14:47:22 -0800683 brw_set_sampler_message(p, send,
Eric Anholt461a2972012-12-05 00:06:30 -0800684 surf_index,
Eric Anholt4c1fdae2013-03-06 14:47:22 -0800685 0, /* LD message ignores sampler unit */
686 GEN5_SAMPLER_MESSAGE_SAMPLE_LD,
687 1, /* rlen */
688 1, /* mlen */
689 false, /* no header */
690 BRW_SAMPLER_SIMD_MODE_SIMD4X2,
691 0);
Eric Anholt461a2972012-12-05 00:06:30 -0800692}
693
694void
Eric Anholtd8214e42012-11-07 11:18:34 -0800695fs_generator::generate_varying_pull_constant_load(fs_inst *inst,
696 struct brw_reg dst,
Eric Anholt70b27e02013-03-18 10:16:42 -0700697 struct brw_reg index,
698 struct brw_reg offset)
Eric Anholtd8214e42012-11-07 11:18:34 -0800699{
700 assert(intel->gen < 7); /* Should use the gen7 variant. */
701 assert(inst->header_present);
Eric Anholt70b27e02013-03-18 10:16:42 -0700702 assert(inst->mlen);
Eric Anholtd8214e42012-11-07 11:18:34 -0800703
704 assert(index.file == BRW_IMMEDIATE_VALUE &&
705 index.type == BRW_REGISTER_TYPE_UD);
706 uint32_t surf_index = index.dw1.ud;
707
Eric Anholt70b27e02013-03-18 10:16:42 -0700708 uint32_t simd_mode, rlen, msg_type;
Eric Anholtd8214e42012-11-07 11:18:34 -0800709 if (dispatch_width == 16) {
Eric Anholt70b27e02013-03-18 10:16:42 -0700710 simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16;
711 rlen = 8;
Eric Anholtd8214e42012-11-07 11:18:34 -0800712 } else {
Eric Anholt70b27e02013-03-18 10:16:42 -0700713 simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD8;
714 rlen = 4;
Eric Anholtd8214e42012-11-07 11:18:34 -0800715 }
716
Eric Anholt70b27e02013-03-18 10:16:42 -0700717 if (intel->gen >= 5)
718 msg_type = GEN5_SAMPLER_MESSAGE_SAMPLE_LD;
719 else {
720 /* We always use the SIMD16 message so that we only have to load U, and
721 * not V or R.
722 */
723 msg_type = BRW_SAMPLER_MESSAGE_SIMD16_LD;
724 assert(inst->mlen == 3);
725 assert(inst->regs_written == 8);
726 rlen = 8;
727 simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16;
728 }
729
730 struct brw_reg offset_mrf = retype(brw_message_reg(inst->base_mrf + 1),
731 BRW_REGISTER_TYPE_D);
732 brw_MOV(p, offset_mrf, offset);
733
Eric Anholtd8214e42012-11-07 11:18:34 -0800734 struct brw_reg header = brw_vec8_grf(0, 0);
735 gen6_resolve_implied_move(p, &header, inst->base_mrf);
736
737 struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
Eric Anholt70b27e02013-03-18 10:16:42 -0700738 send->header.compression_control = BRW_COMPRESSION_NONE;
Eric Anholtd8214e42012-11-07 11:18:34 -0800739 brw_set_dest(p, send, dst);
740 brw_set_src0(p, send, header);
741 if (intel->gen < 6)
742 send->header.destreg__conditionalmod = inst->base_mrf;
Eric Anholt70b27e02013-03-18 10:16:42 -0700743
744 /* Our surface is set up as floats, regardless of what actual data is
745 * stored in it.
746 */
747 uint32_t return_format = BRW_SAMPLER_RETURN_FORMAT_FLOAT32;
748 brw_set_sampler_message(p, send,
Eric Anholtd8214e42012-11-07 11:18:34 -0800749 surf_index,
Eric Anholt70b27e02013-03-18 10:16:42 -0700750 0, /* sampler (unused) */
Eric Anholtd8214e42012-11-07 11:18:34 -0800751 msg_type,
Eric Anholt70b27e02013-03-18 10:16:42 -0700752 rlen,
Eric Anholtd8214e42012-11-07 11:18:34 -0800753 inst->mlen,
754 inst->header_present,
Eric Anholt70b27e02013-03-18 10:16:42 -0700755 simd_mode,
756 return_format);
Eric Anholtd8214e42012-11-07 11:18:34 -0800757}
758
759void
760fs_generator::generate_varying_pull_constant_load_gen7(fs_inst *inst,
761 struct brw_reg dst,
762 struct brw_reg index,
763 struct brw_reg offset)
764{
765 assert(intel->gen >= 7);
766 /* Varying-offset pull constant loads are treated as a normal expression on
767 * gen7, so the fact that it's a send message is hidden at the IR level.
768 */
769 assert(!inst->header_present);
770 assert(!inst->mlen);
771
772 assert(index.file == BRW_IMMEDIATE_VALUE &&
773 index.type == BRW_REGISTER_TYPE_UD);
774 uint32_t surf_index = index.dw1.ud;
775
Eric Anholtdca5fc12013-03-13 14:48:55 -0700776 uint32_t simd_mode, rlen, mlen;
Eric Anholtd8214e42012-11-07 11:18:34 -0800777 if (dispatch_width == 16) {
Eric Anholtdca5fc12013-03-13 14:48:55 -0700778 mlen = 2;
779 rlen = 8;
780 simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD16;
Eric Anholtd8214e42012-11-07 11:18:34 -0800781 } else {
Eric Anholtdca5fc12013-03-13 14:48:55 -0700782 mlen = 1;
783 rlen = 4;
784 simd_mode = BRW_SAMPLER_SIMD_MODE_SIMD8;
Eric Anholtd8214e42012-11-07 11:18:34 -0800785 }
786
787 struct brw_instruction *send = brw_next_insn(p, BRW_OPCODE_SEND);
788 brw_set_dest(p, send, dst);
789 brw_set_src0(p, send, offset);
Eric Anholtdca5fc12013-03-13 14:48:55 -0700790 brw_set_sampler_message(p, send,
Eric Anholtd8214e42012-11-07 11:18:34 -0800791 surf_index,
Eric Anholtdca5fc12013-03-13 14:48:55 -0700792 0, /* LD message ignores sampler unit */
793 GEN5_SAMPLER_MESSAGE_SAMPLE_LD,
794 rlen,
Eric Anholtd8214e42012-11-07 11:18:34 -0800795 mlen,
Eric Anholtdca5fc12013-03-13 14:48:55 -0700796 false, /* no header */
797 simd_mode,
798 0);
Eric Anholtd8214e42012-11-07 11:18:34 -0800799}
Paul Berry3f929ef2012-06-18 14:50:04 -0700800
801/**
802 * Cause the current pixel/sample mask (from R1.7 bits 15:0) to be transferred
803 * into the flags register (f0.0).
804 *
805 * Used only on Gen6 and above.
806 */
807void
Eric Anholtb278f652012-12-06 10:36:11 -0800808fs_generator::generate_mov_dispatch_to_flags(fs_inst *inst)
Paul Berry3f929ef2012-06-18 14:50:04 -0700809{
Eric Anholtb278f652012-12-06 10:36:11 -0800810 struct brw_reg flags = brw_flag_reg(0, inst->flag_subreg);
Eric Anholtd5016492012-12-06 12:15:13 -0800811 struct brw_reg dispatch_mask;
Paul Berry3f929ef2012-06-18 14:50:04 -0700812
Eric Anholtd5016492012-12-06 12:15:13 -0800813 if (intel->gen >= 6)
814 dispatch_mask = retype(brw_vec1_grf(1, 7), BRW_REGISTER_TYPE_UW);
815 else
816 dispatch_mask = retype(brw_vec1_grf(0, 0), BRW_REGISTER_TYPE_UW);
817
Paul Berry3f929ef2012-06-18 14:50:04 -0700818 brw_push_insn_state(p);
819 brw_set_mask_control(p, BRW_MASK_DISABLE);
Eric Anholtd5016492012-12-06 12:15:13 -0800820 brw_MOV(p, flags, dispatch_mask);
Paul Berry3f929ef2012-06-18 14:50:04 -0700821 brw_pop_insn_state(p);
822}
823
824
Eric Anholta3b8c5e2011-11-23 10:13:39 -0800825static uint32_t brw_file_from_reg(fs_reg *reg)
826{
827 switch (reg->file) {
828 case ARF:
829 return BRW_ARCHITECTURE_REGISTER_FILE;
830 case GRF:
831 return BRW_GENERAL_REGISTER_FILE;
832 case MRF:
833 return BRW_MESSAGE_REGISTER_FILE;
834 case IMM:
835 return BRW_IMMEDIATE_VALUE;
836 default:
837 assert(!"not reached");
838 return BRW_GENERAL_REGISTER_FILE;
839 }
840}
841
Eric Anholt11dd9e92011-05-24 16:34:27 -0700842static struct brw_reg
843brw_reg_from_fs_reg(fs_reg *reg)
844{
845 struct brw_reg brw_reg;
846
847 switch (reg->file) {
848 case GRF:
849 case ARF:
850 case MRF:
851 if (reg->smear == -1) {
Eric Anholta3b8c5e2011-11-23 10:13:39 -0800852 brw_reg = brw_vec8_reg(brw_file_from_reg(reg), reg->reg, 0);
Eric Anholt11dd9e92011-05-24 16:34:27 -0700853 } else {
Eric Anholta3b8c5e2011-11-23 10:13:39 -0800854 brw_reg = brw_vec1_reg(brw_file_from_reg(reg), reg->reg, reg->smear);
Eric Anholt11dd9e92011-05-24 16:34:27 -0700855 }
856 brw_reg = retype(brw_reg, reg->type);
857 if (reg->sechalf)
858 brw_reg = sechalf(brw_reg);
859 break;
860 case IMM:
861 switch (reg->type) {
862 case BRW_REGISTER_TYPE_F:
863 brw_reg = brw_imm_f(reg->imm.f);
864 break;
865 case BRW_REGISTER_TYPE_D:
866 brw_reg = brw_imm_d(reg->imm.i);
867 break;
868 case BRW_REGISTER_TYPE_UD:
869 brw_reg = brw_imm_ud(reg->imm.u);
870 break;
871 default:
872 assert(!"not reached");
873 brw_reg = brw_null_reg();
874 break;
875 }
876 break;
Eric Anholtab04f3b2013-04-29 16:05:05 -0700877 case HW_REG:
Eric Anholt11dd9e92011-05-24 16:34:27 -0700878 brw_reg = reg->fixed_hw_reg;
879 break;
880 case BAD_FILE:
881 /* Probably unused. */
882 brw_reg = brw_null_reg();
883 break;
884 case UNIFORM:
885 assert(!"not reached");
886 brw_reg = brw_null_reg();
887 break;
888 default:
889 assert(!"not reached");
890 brw_reg = brw_null_reg();
891 break;
892 }
893 if (reg->abs)
894 brw_reg = brw_abs(brw_reg);
895 if (reg->negate)
896 brw_reg = negate(brw_reg);
897
898 return brw_reg;
899}
900
Eric Anholt461a2972012-12-05 00:06:30 -0800901/**
Eric Anholt4c1fdae2013-03-06 14:47:22 -0800902 * Sets the first word of a vgrf for gen7+ simd4x2 uniform pull constant
903 * sampler LD messages.
Eric Anholt461a2972012-12-05 00:06:30 -0800904 *
Eric Anholt4c1fdae2013-03-06 14:47:22 -0800905 * We don't want to bake it into the send message's code generation because
906 * that means we don't get a chance to schedule the instructions.
Eric Anholt461a2972012-12-05 00:06:30 -0800907 */
908void
Eric Anholt4c1fdae2013-03-06 14:47:22 -0800909fs_generator::generate_set_simd4x2_offset(fs_inst *inst,
910 struct brw_reg dst,
911 struct brw_reg value)
Eric Anholt461a2972012-12-05 00:06:30 -0800912{
Eric Anholt461a2972012-12-05 00:06:30 -0800913 assert(value.file == BRW_IMMEDIATE_VALUE);
914
915 brw_push_insn_state(p);
916 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
917 brw_set_mask_control(p, BRW_MASK_DISABLE);
Eric Anholt4c1fdae2013-03-06 14:47:22 -0800918 brw_MOV(p, retype(brw_vec1_reg(dst.file, dst.nr, 0), value.type), value);
Eric Anholt461a2972012-12-05 00:06:30 -0800919 brw_pop_insn_state(p);
920}
921
Chad Versace20dfa502013-01-09 11:46:42 -0800922/**
923 * Change the register's data type from UD to W, doubling the strides in order
924 * to compensate for halving the data type width.
925 */
926static struct brw_reg
927ud_reg_to_w(struct brw_reg r)
928{
929 assert(r.type == BRW_REGISTER_TYPE_UD);
930 r.type = BRW_REGISTER_TYPE_W;
931
932 /* The BRW_*_STRIDE enums are defined so that incrementing the field
933 * doubles the real stride.
934 */
935 if (r.hstride != 0)
936 ++r.hstride;
937 if (r.vstride != 0)
938 ++r.vstride;
939
940 return r;
941}
942
943void
944fs_generator::generate_pack_half_2x16_split(fs_inst *inst,
945 struct brw_reg dst,
946 struct brw_reg x,
947 struct brw_reg y)
948{
949 assert(intel->gen >= 7);
950 assert(dst.type == BRW_REGISTER_TYPE_UD);
Vinson Lee15599942013-01-26 08:27:50 +0100951 assert(x.type == BRW_REGISTER_TYPE_F);
952 assert(y.type == BRW_REGISTER_TYPE_F);
Chad Versace20dfa502013-01-09 11:46:42 -0800953
954 /* From the Ivybridge PRM, Vol4, Part3, Section 6.27 f32to16:
955 *
956 * Because this instruction does not have a 16-bit floating-point type,
957 * the destination data type must be Word (W).
958 *
959 * The destination must be DWord-aligned and specify a horizontal stride
960 * (HorzStride) of 2. The 16-bit result is stored in the lower word of
961 * each destination channel and the upper word is not modified.
962 */
963 struct brw_reg dst_w = ud_reg_to_w(dst);
964
965 /* Give each 32-bit channel of dst the form below , where "." means
966 * unchanged.
967 * 0x....hhhh
968 */
969 brw_F32TO16(p, dst_w, y);
970
971 /* Now the form:
972 * 0xhhhh0000
973 */
974 brw_SHL(p, dst, dst, brw_imm_ud(16u));
975
976 /* And, finally the form of packHalf2x16's output:
977 * 0xhhhhllll
978 */
979 brw_F32TO16(p, dst_w, x);
980}
981
982void
983fs_generator::generate_unpack_half_2x16_split(fs_inst *inst,
984 struct brw_reg dst,
985 struct brw_reg src)
986{
987 assert(intel->gen >= 7);
988 assert(dst.type == BRW_REGISTER_TYPE_F);
989 assert(src.type == BRW_REGISTER_TYPE_UD);
990
991 /* From the Ivybridge PRM, Vol4, Part3, Section 6.26 f16to32:
992 *
993 * Because this instruction does not have a 16-bit floating-point type,
994 * the source data type must be Word (W). The destination type must be
995 * F (Float).
996 */
997 struct brw_reg src_w = ud_reg_to_w(src);
998
999 /* Each channel of src has the form of unpackHalf2x16's input: 0xhhhhllll.
1000 * For the Y case, we wish to access only the upper word; therefore
1001 * a 16-bit subregister offset is needed.
1002 */
1003 assert(inst->opcode == FS_OPCODE_UNPACK_HALF_2x16_SPLIT_X ||
1004 inst->opcode == FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y);
1005 if (inst->opcode == FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y)
Chad Versace09740312013-01-24 21:48:40 -08001006 src_w.subnr += 2;
Chad Versace20dfa502013-01-09 11:46:42 -08001007
1008 brw_F16TO32(p, dst, src_w);
1009}
1010
Eric Anholt11dd9e92011-05-24 16:34:27 -07001011void
Eric Anholt5c5218e2013-03-19 15:28:11 -07001012fs_generator::generate_shader_time_add(fs_inst *inst,
1013 struct brw_reg payload,
1014 struct brw_reg offset,
1015 struct brw_reg value)
1016{
1017 assert(intel->gen >= 7);
1018 brw_push_insn_state(p);
1019 brw_set_mask_control(p, true);
1020
1021 assert(payload.file == BRW_GENERAL_REGISTER_FILE);
1022 struct brw_reg payload_offset = retype(brw_vec1_grf(payload.nr, 0),
1023 offset.type);
1024 struct brw_reg payload_value = retype(brw_vec1_grf(payload.nr + 1, 0),
1025 value.type);
1026
1027 assert(offset.file == BRW_IMMEDIATE_VALUE);
1028 if (value.file == BRW_GENERAL_REGISTER_FILE) {
1029 value.width = BRW_WIDTH_1;
1030 value.hstride = BRW_HORIZONTAL_STRIDE_0;
1031 value.vstride = BRW_VERTICAL_STRIDE_0;
1032 } else {
1033 assert(value.file == BRW_IMMEDIATE_VALUE);
1034 }
1035
1036 /* Trying to deal with setup of the params from the IR is crazy in the FS8
1037 * case, and we don't really care about squeezing every bit of performance
1038 * out of this path, so we just emit the MOVs from here.
1039 */
1040 brw_MOV(p, payload_offset, offset);
1041 brw_MOV(p, payload_value, value);
1042 brw_shader_time_add(p, payload, SURF_INDEX_WM_SHADER_TIME);
1043 brw_pop_insn_state(p);
1044}
1045
1046void
Kenneth Graunkeea681a02012-11-09 01:05:47 -08001047fs_generator::generate_code(exec_list *instructions)
Eric Anholt11dd9e92011-05-24 16:34:27 -07001048{
Eric Anholtf2bd3e72012-02-03 11:50:42 +01001049 int last_native_insn_offset = p->next_insn_offset;
Eric Anholt11dd9e92011-05-24 16:34:27 -07001050 const char *last_annotation_string = NULL;
Eric Anholt97615b22012-08-27 14:35:01 -07001051 const void *last_annotation_ir = NULL;
Eric Anholt11dd9e92011-05-24 16:34:27 -07001052
Eric Anholt11dd9e92011-05-24 16:34:27 -07001053 if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
Eric Anholt97615b22012-08-27 14:35:01 -07001054 if (shader) {
1055 printf("Native code for fragment shader %d (%d-wide dispatch):\n",
Kenneth Graunkea303df82012-11-20 13:50:52 -08001056 prog->Name, dispatch_width);
Eric Anholt97615b22012-08-27 14:35:01 -07001057 } else {
1058 printf("Native code for fragment program %d (%d-wide dispatch):\n",
Kenneth Graunke1f740022012-11-20 14:41:21 -08001059 fp->Base.Id, dispatch_width);
Eric Anholt97615b22012-08-27 14:35:01 -07001060 }
Eric Anholt11dd9e92011-05-24 16:34:27 -07001061 }
1062
Eric Anholt7abfb672012-10-03 13:16:09 -07001063 cfg_t *cfg = NULL;
Eric Anholt080b1252012-04-10 12:01:50 -07001064 if (unlikely(INTEL_DEBUG & DEBUG_WM))
Kenneth Graunkeea681a02012-11-09 01:05:47 -08001065 cfg = new(mem_ctx) cfg_t(mem_ctx, instructions);
Eric Anholt080b1252012-04-10 12:01:50 -07001066
Kenneth Graunkeea681a02012-11-09 01:05:47 -08001067 foreach_list(node, instructions) {
Eric Anholt44ffb4a2011-07-29 11:52:39 -07001068 fs_inst *inst = (fs_inst *)node;
Eric Anholt11dd9e92011-05-24 16:34:27 -07001069 struct brw_reg src[3], dst;
1070
1071 if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
Eric Anholt080b1252012-04-10 12:01:50 -07001072 foreach_list(node, &cfg->block_list) {
Eric Anholt7abfb672012-10-03 13:16:09 -07001073 bblock_link *link = (bblock_link *)node;
1074 bblock_t *block = link->block;
Eric Anholt080b1252012-04-10 12:01:50 -07001075
1076 if (block->start == inst) {
1077 printf(" START B%d", block->block_num);
1078 foreach_list(predecessor_node, &block->parents) {
Eric Anholt7abfb672012-10-03 13:16:09 -07001079 bblock_link *predecessor_link =
1080 (bblock_link *)predecessor_node;
1081 bblock_t *predecessor_block = predecessor_link->block;
Eric Anholt080b1252012-04-10 12:01:50 -07001082 printf(" <-B%d", predecessor_block->block_num);
1083 }
1084 printf("\n");
1085 }
1086 }
1087
Eric Anholt11dd9e92011-05-24 16:34:27 -07001088 if (last_annotation_ir != inst->ir) {
1089 last_annotation_ir = inst->ir;
1090 if (last_annotation_ir) {
1091 printf(" ");
Eric Anholt97615b22012-08-27 14:35:01 -07001092 if (shader)
1093 ((ir_instruction *)inst->ir)->print();
1094 else {
1095 const prog_instruction *fpi;
1096 fpi = (const prog_instruction *)inst->ir;
1097 printf("%d: ", (int)(fpi - fp->Base.Instructions));
1098 _mesa_fprint_instruction_opt(stdout,
1099 fpi,
1100 0, PROG_PRINT_DEBUG, NULL);
1101 }
Eric Anholt11dd9e92011-05-24 16:34:27 -07001102 printf("\n");
1103 }
1104 }
1105 if (last_annotation_string != inst->annotation) {
1106 last_annotation_string = inst->annotation;
1107 if (last_annotation_string)
1108 printf(" %s\n", last_annotation_string);
1109 }
1110 }
1111
1112 for (unsigned int i = 0; i < 3; i++) {
1113 src[i] = brw_reg_from_fs_reg(&inst->src[i]);
Eric Anholt73b0a282011-10-03 15:12:10 -07001114
1115 /* The accumulator result appears to get used for the
1116 * conditional modifier generation. When negating a UD
1117 * value, there is a 33rd bit generated for the sign in the
1118 * accumulator value, so now you can't check, for example,
1119 * equality with a 32-bit value. See piglit fs-op-neg-uvec4.
1120 */
1121 assert(!inst->conditional_mod ||
1122 inst->src[i].type != BRW_REGISTER_TYPE_UD ||
1123 !inst->src[i].negate);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001124 }
1125 dst = brw_reg_from_fs_reg(&inst->dst);
1126
1127 brw_set_conditionalmod(p, inst->conditional_mod);
Eric Anholt54679fc2012-10-03 13:23:05 -07001128 brw_set_predicate_control(p, inst->predicate);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001129 brw_set_predicate_inverse(p, inst->predicate_inverse);
Eric Anholtb278f652012-12-06 10:36:11 -08001130 brw_set_flag_reg(p, 0, inst->flag_subreg);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001131 brw_set_saturate(p, inst->saturate);
Eric Anholtef2fbf62012-11-28 14:16:03 -08001132 brw_set_mask_control(p, inst->force_writemask_all);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001133
Kenneth Graunkea303df82012-11-20 13:50:52 -08001134 if (inst->force_uncompressed || dispatch_width == 8) {
Eric Anholt11dd9e92011-05-24 16:34:27 -07001135 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
1136 } else if (inst->force_sechalf) {
1137 brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
1138 } else {
1139 brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
1140 }
1141
1142 switch (inst->opcode) {
1143 case BRW_OPCODE_MOV:
1144 brw_MOV(p, dst, src[0]);
1145 break;
1146 case BRW_OPCODE_ADD:
1147 brw_ADD(p, dst, src[0], src[1]);
1148 break;
1149 case BRW_OPCODE_MUL:
1150 brw_MUL(p, dst, src[0], src[1]);
1151 break;
Eric Anholt3f78f712011-08-15 22:36:18 -07001152 case BRW_OPCODE_MACH:
1153 brw_set_acc_write_control(p, 1);
1154 brw_MACH(p, dst, src[0], src[1]);
1155 brw_set_acc_write_control(p, 0);
1156 break;
Eric Anholt11dd9e92011-05-24 16:34:27 -07001157
Eric Anholt7d55f372012-02-07 00:59:11 +01001158 case BRW_OPCODE_MAD:
1159 brw_set_access_mode(p, BRW_ALIGN_16);
Kenneth Graunkea303df82012-11-20 13:50:52 -08001160 if (dispatch_width == 16) {
Eric Anholt7d55f372012-02-07 00:59:11 +01001161 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
1162 brw_MAD(p, dst, src[0], src[1], src[2]);
1163 brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
1164 brw_MAD(p, sechalf(dst), sechalf(src[0]), sechalf(src[1]), sechalf(src[2]));
1165 brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
1166 } else {
1167 brw_MAD(p, dst, src[0], src[1], src[2]);
1168 }
1169 brw_set_access_mode(p, BRW_ALIGN_1);
1170 break;
1171
Kenneth Graunke0a1d1452012-12-02 00:08:15 -08001172 case BRW_OPCODE_LRP:
1173 brw_set_access_mode(p, BRW_ALIGN_16);
1174 if (dispatch_width == 16) {
1175 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
1176 brw_LRP(p, dst, src[0], src[1], src[2]);
1177 brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
1178 brw_LRP(p, sechalf(dst), sechalf(src[0]), sechalf(src[1]), sechalf(src[2]));
1179 brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
1180 } else {
1181 brw_LRP(p, dst, src[0], src[1], src[2]);
1182 }
1183 brw_set_access_mode(p, BRW_ALIGN_1);
1184 break;
1185
Eric Anholt11dd9e92011-05-24 16:34:27 -07001186 case BRW_OPCODE_FRC:
1187 brw_FRC(p, dst, src[0]);
1188 break;
1189 case BRW_OPCODE_RNDD:
1190 brw_RNDD(p, dst, src[0]);
1191 break;
1192 case BRW_OPCODE_RNDE:
1193 brw_RNDE(p, dst, src[0]);
1194 break;
1195 case BRW_OPCODE_RNDZ:
1196 brw_RNDZ(p, dst, src[0]);
1197 break;
1198
1199 case BRW_OPCODE_AND:
1200 brw_AND(p, dst, src[0], src[1]);
1201 break;
1202 case BRW_OPCODE_OR:
1203 brw_OR(p, dst, src[0], src[1]);
1204 break;
1205 case BRW_OPCODE_XOR:
1206 brw_XOR(p, dst, src[0], src[1]);
1207 break;
1208 case BRW_OPCODE_NOT:
1209 brw_NOT(p, dst, src[0]);
1210 break;
1211 case BRW_OPCODE_ASR:
1212 brw_ASR(p, dst, src[0], src[1]);
1213 break;
1214 case BRW_OPCODE_SHR:
1215 brw_SHR(p, dst, src[0], src[1]);
1216 break;
1217 case BRW_OPCODE_SHL:
1218 brw_SHL(p, dst, src[0], src[1]);
1219 break;
Chad Versace20dfa502013-01-09 11:46:42 -08001220 case BRW_OPCODE_F32TO16:
1221 brw_F32TO16(p, dst, src[0]);
1222 break;
1223 case BRW_OPCODE_F16TO32:
1224 brw_F16TO32(p, dst, src[0]);
1225 break;
Eric Anholt11dd9e92011-05-24 16:34:27 -07001226 case BRW_OPCODE_CMP:
1227 brw_CMP(p, dst, inst->conditional_mod, src[0], src[1]);
1228 break;
1229 case BRW_OPCODE_SEL:
1230 brw_SEL(p, dst, src[0], src[1]);
1231 break;
Matt Turner1f0f26d2013-04-09 19:22:34 -07001232 case BRW_OPCODE_BFREV:
1233 /* BFREV only supports UD type for src and dst. */
1234 brw_BFREV(p, retype(dst, BRW_REGISTER_TYPE_UD),
1235 retype(src[0], BRW_REGISTER_TYPE_UD));
1236 break;
1237 case BRW_OPCODE_FBH:
1238 /* FBH only supports UD type for dst. */
1239 brw_FBH(p, retype(dst, BRW_REGISTER_TYPE_UD), src[0]);
1240 break;
1241 case BRW_OPCODE_FBL:
1242 /* FBL only supports UD type for dst. */
1243 brw_FBL(p, retype(dst, BRW_REGISTER_TYPE_UD), src[0]);
1244 break;
1245 case BRW_OPCODE_CBIT:
1246 /* CBIT only supports UD type for dst. */
1247 brw_CBIT(p, retype(dst, BRW_REGISTER_TYPE_UD), src[0]);
1248 break;
1249
1250 case BRW_OPCODE_BFE:
1251 brw_set_access_mode(p, BRW_ALIGN_16);
1252 if (dispatch_width == 16) {
1253 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
1254 brw_BFE(p, dst, src[0], src[1], src[2]);
1255 brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
1256 brw_BFE(p, sechalf(dst), sechalf(src[0]), sechalf(src[1]), sechalf(src[2]));
1257 brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
1258 } else {
1259 brw_BFE(p, dst, src[0], src[1], src[2]);
1260 }
1261 brw_set_access_mode(p, BRW_ALIGN_1);
1262 break;
1263
1264 case BRW_OPCODE_BFI1:
1265 brw_BFI1(p, dst, src[0], src[1]);
1266 break;
1267 case BRW_OPCODE_BFI2:
1268 brw_set_access_mode(p, BRW_ALIGN_16);
1269 if (dispatch_width == 16) {
1270 brw_set_compression_control(p, BRW_COMPRESSION_NONE);
1271 brw_BFI2(p, dst, src[0], src[1], src[2]);
1272 brw_set_compression_control(p, BRW_COMPRESSION_2NDHALF);
1273 brw_BFI2(p, sechalf(dst), sechalf(src[0]), sechalf(src[1]), sechalf(src[2]));
1274 brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
1275 } else {
1276 brw_BFI2(p, dst, src[0], src[1], src[2]);
1277 }
1278 brw_set_access_mode(p, BRW_ALIGN_1);
1279 break;
Eric Anholt11dd9e92011-05-24 16:34:27 -07001280
1281 case BRW_OPCODE_IF:
1282 if (inst->src[0].file != BAD_FILE) {
1283 /* The instruction has an embedded compare (only allowed on gen6) */
1284 assert(intel->gen == 6);
1285 gen6_IF(p, inst->conditional_mod, src[0], src[1]);
1286 } else {
Kenneth Graunkea303df82012-11-20 13:50:52 -08001287 brw_IF(p, dispatch_width == 16 ? BRW_EXECUTE_16 : BRW_EXECUTE_8);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001288 }
Eric Anholt11dd9e92011-05-24 16:34:27 -07001289 break;
1290
1291 case BRW_OPCODE_ELSE:
1292 brw_ELSE(p);
1293 break;
1294 case BRW_OPCODE_ENDIF:
1295 brw_ENDIF(p);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001296 break;
1297
1298 case BRW_OPCODE_DO:
Eric Anholtce6be332011-12-06 12:30:03 -08001299 brw_DO(p, BRW_EXECUTE_8);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001300 break;
1301
1302 case BRW_OPCODE_BREAK:
Eric Anholtf1d89632011-12-06 12:44:41 -08001303 brw_BREAK(p);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001304 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
1305 break;
1306 case BRW_OPCODE_CONTINUE:
1307 /* FINISHME: We need to write the loop instruction support still. */
1308 if (intel->gen >= 6)
Eric Anholt9f881472011-12-06 12:09:58 -08001309 gen6_CONT(p);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001310 else
Eric Anholtf1d89632011-12-06 12:44:41 -08001311 brw_CONT(p);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001312 brw_set_predicate_control(p, BRW_PREDICATE_NONE);
1313 break;
1314
Eric Anholtce6be332011-12-06 12:30:03 -08001315 case BRW_OPCODE_WHILE:
Eric Anholtce6be332011-12-06 12:30:03 -08001316 brw_WHILE(p);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001317 break;
1318
Eric Anholt65b5cbb2011-08-05 12:38:58 -07001319 case SHADER_OPCODE_RCP:
1320 case SHADER_OPCODE_RSQ:
1321 case SHADER_OPCODE_SQRT:
1322 case SHADER_OPCODE_EXP2:
1323 case SHADER_OPCODE_LOG2:
Eric Anholt65b5cbb2011-08-05 12:38:58 -07001324 case SHADER_OPCODE_SIN:
1325 case SHADER_OPCODE_COS:
Kenneth Graunkea73c65c2011-10-18 12:24:47 -07001326 if (intel->gen >= 7) {
1327 generate_math1_gen7(inst, dst, src[0]);
1328 } else if (intel->gen == 6) {
Kenneth Graunke74e927b2011-08-18 11:55:42 -07001329 generate_math1_gen6(inst, dst, src[0]);
Kenneth Graunke794de2f2013-07-06 00:15:44 -07001330 } else if (intel->gen == 5 || brw->is_g4x) {
Kenneth Graunke1b77d212013-03-30 00:15:54 -07001331 generate_math_g45(inst, dst, src[0]);
Kenneth Graunke74e927b2011-08-18 11:55:42 -07001332 } else {
1333 generate_math_gen4(inst, dst, src[0]);
1334 }
1335 break;
Kenneth Graunkeff8f2722011-09-28 17:37:54 -07001336 case SHADER_OPCODE_INT_QUOTIENT:
1337 case SHADER_OPCODE_INT_REMAINDER:
Kenneth Graunke74e927b2011-08-18 11:55:42 -07001338 case SHADER_OPCODE_POW:
Kenneth Graunkedceb2022011-11-07 12:07:44 -08001339 if (intel->gen >= 7) {
Kenneth Graunkea73c65c2011-10-18 12:24:47 -07001340 generate_math2_gen7(inst, dst, src[0], src[1]);
1341 } else if (intel->gen == 6) {
Kenneth Graunke74e927b2011-08-18 11:55:42 -07001342 generate_math2_gen6(inst, dst, src[0], src[1]);
1343 } else {
1344 generate_math_gen4(inst, dst, src[0]);
1345 }
Eric Anholt11dd9e92011-05-24 16:34:27 -07001346 break;
1347 case FS_OPCODE_PIXEL_X:
1348 generate_pixel_xy(dst, true);
1349 break;
1350 case FS_OPCODE_PIXEL_Y:
1351 generate_pixel_xy(dst, false);
1352 break;
1353 case FS_OPCODE_CINTERP:
1354 brw_MOV(p, dst, src[0]);
1355 break;
1356 case FS_OPCODE_LINTERP:
1357 generate_linterp(inst, dst, src);
1358 break;
Kenneth Graunkefebad172011-10-26 12:58:37 -07001359 case SHADER_OPCODE_TEX:
Eric Anholt11dd9e92011-05-24 16:34:27 -07001360 case FS_OPCODE_TXB:
Kenneth Graunkefebad172011-10-26 12:58:37 -07001361 case SHADER_OPCODE_TXD:
1362 case SHADER_OPCODE_TXF:
Chris Forbesf52ce6a2013-01-24 21:35:15 +13001363 case SHADER_OPCODE_TXF_MS:
Kenneth Graunkefebad172011-10-26 12:58:37 -07001364 case SHADER_OPCODE_TXL:
1365 case SHADER_OPCODE_TXS:
Matt Turnerb8aa9f72013-03-06 14:47:01 -08001366 case SHADER_OPCODE_LOD:
Eric Anholt11dd9e92011-05-24 16:34:27 -07001367 generate_tex(inst, dst, src[0]);
1368 break;
Eric Anholt11dd9e92011-05-24 16:34:27 -07001369 case FS_OPCODE_DDX:
1370 generate_ddx(inst, dst, src[0]);
1371 break;
1372 case FS_OPCODE_DDY:
Paul Berryd08fdac2012-06-20 13:40:45 -07001373 /* Make sure fp->UsesDFdy flag got set (otherwise there's no
1374 * guarantee that c->key.render_to_fbo is set).
1375 */
1376 assert(fp->UsesDFdy);
Paul Berry82d25962012-06-20 13:40:45 -07001377 generate_ddy(inst, dst, src[0], c->key.render_to_fbo);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001378 break;
1379
1380 case FS_OPCODE_SPILL:
1381 generate_spill(inst, src[0]);
1382 break;
1383
1384 case FS_OPCODE_UNSPILL:
1385 generate_unspill(inst, dst);
1386 break;
1387
Eric Anholt29340d02012-11-07 10:42:34 -08001388 case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD:
1389 generate_uniform_pull_constant_load(inst, dst, src[0], src[1]);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001390 break;
1391
Eric Anholt461a2972012-12-05 00:06:30 -08001392 case FS_OPCODE_UNIFORM_PULL_CONSTANT_LOAD_GEN7:
1393 generate_uniform_pull_constant_load_gen7(inst, dst, src[0], src[1]);
1394 break;
1395
Eric Anholtd8214e42012-11-07 11:18:34 -08001396 case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD:
Eric Anholt70b27e02013-03-18 10:16:42 -07001397 generate_varying_pull_constant_load(inst, dst, src[0], src[1]);
Eric Anholtd8214e42012-11-07 11:18:34 -08001398 break;
1399
1400 case FS_OPCODE_VARYING_PULL_CONSTANT_LOAD_GEN7:
1401 generate_varying_pull_constant_load_gen7(inst, dst, src[0], src[1]);
1402 break;
1403
Eric Anholt11dd9e92011-05-24 16:34:27 -07001404 case FS_OPCODE_FB_WRITE:
1405 generate_fb_write(inst);
1406 break;
Paul Berry3f929ef2012-06-18 14:50:04 -07001407
1408 case FS_OPCODE_MOV_DISPATCH_TO_FLAGS:
Eric Anholtb278f652012-12-06 10:36:11 -08001409 generate_mov_dispatch_to_flags(inst);
Paul Berry3f929ef2012-06-18 14:50:04 -07001410 break;
1411
Eric Anholtbeafced2012-12-06 10:15:08 -08001412 case FS_OPCODE_DISCARD_JUMP:
1413 generate_discard_jump(inst);
1414 break;
1415
Eric Anholt71f06342012-11-27 14:10:52 -08001416 case SHADER_OPCODE_SHADER_TIME_ADD:
Eric Anholt5c5218e2013-03-19 15:28:11 -07001417 generate_shader_time_add(inst, src[0], src[1], src[2]);
Eric Anholt71f06342012-11-27 14:10:52 -08001418 break;
1419
Eric Anholt4c1fdae2013-03-06 14:47:22 -08001420 case FS_OPCODE_SET_SIMD4X2_OFFSET:
1421 generate_set_simd4x2_offset(inst, dst, src[0]);
Eric Anholt461a2972012-12-05 00:06:30 -08001422 break;
1423
Chad Versace20dfa502013-01-09 11:46:42 -08001424 case FS_OPCODE_PACK_HALF_2x16_SPLIT:
1425 generate_pack_half_2x16_split(inst, dst, src[0], src[1]);
1426 break;
1427
1428 case FS_OPCODE_UNPACK_HALF_2x16_SPLIT_X:
1429 case FS_OPCODE_UNPACK_HALF_2x16_SPLIT_Y:
1430 generate_unpack_half_2x16_split(inst, dst, src[0]);
1431 break;
1432
Kenneth Graunke57a50252013-03-27 23:19:39 -07001433 case FS_OPCODE_PLACEHOLDER_HALT:
1434 /* This is the place where the final HALT needs to be inserted if
1435 * we've emitted any discards. If not, this will emit no code.
1436 */
1437 patch_discard_jumps_to_fb_writes();
1438 break;
1439
Eric Anholt11dd9e92011-05-24 16:34:27 -07001440 default:
Kenneth Graunkeb02492f2012-11-14 14:24:31 -08001441 if (inst->opcode < (int) ARRAY_SIZE(opcode_descs)) {
Eric Anholt11dd9e92011-05-24 16:34:27 -07001442 _mesa_problem(ctx, "Unsupported opcode `%s' in FS",
Kenneth Graunkeb02492f2012-11-14 14:24:31 -08001443 opcode_descs[inst->opcode].name);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001444 } else {
1445 _mesa_problem(ctx, "Unsupported opcode %d in FS", inst->opcode);
1446 }
Kenneth Graunkedd1fd302012-11-20 17:02:23 -08001447 abort();
Eric Anholt11dd9e92011-05-24 16:34:27 -07001448 }
1449
1450 if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
Eric Anholtf2bd3e72012-02-03 11:50:42 +01001451 brw_dump_compile(p, stdout,
1452 last_native_insn_offset, p->next_insn_offset);
Eric Anholt080b1252012-04-10 12:01:50 -07001453
1454 foreach_list(node, &cfg->block_list) {
Eric Anholt7abfb672012-10-03 13:16:09 -07001455 bblock_link *link = (bblock_link *)node;
1456 bblock_t *block = link->block;
Eric Anholt080b1252012-04-10 12:01:50 -07001457
1458 if (block->end == inst) {
1459 printf(" END B%d", block->block_num);
1460 foreach_list(successor_node, &block->children) {
Eric Anholt7abfb672012-10-03 13:16:09 -07001461 bblock_link *successor_link =
1462 (bblock_link *)successor_node;
1463 bblock_t *successor_block = successor_link->block;
Eric Anholt080b1252012-04-10 12:01:50 -07001464 printf(" ->B%d", successor_block->block_num);
1465 }
1466 printf("\n");
1467 }
1468 }
Eric Anholt11dd9e92011-05-24 16:34:27 -07001469 }
1470
Eric Anholtf2bd3e72012-02-03 11:50:42 +01001471 last_native_insn_offset = p->next_insn_offset;
Eric Anholt11dd9e92011-05-24 16:34:27 -07001472 }
1473
1474 if (unlikely(INTEL_DEBUG & DEBUG_WM)) {
1475 printf("\n");
1476 }
1477
Eric Anholt11dd9e92011-05-24 16:34:27 -07001478 brw_set_uip_jip(p);
1479
1480 /* OK, while the INTEL_DEBUG=wm above is very nice for debugging FS
1481 * emit issues, it doesn't get the jump distances into the output,
1482 * which is often something we want to debug. So this is here in
1483 * case you're doing that.
1484 */
1485 if (0) {
Eric Anholtf2bd3e72012-02-03 11:50:42 +01001486 brw_dump_compile(p, stdout, 0, p->next_insn_offset);
Eric Anholt11dd9e92011-05-24 16:34:27 -07001487 }
1488}
Kenneth Graunkeea681a02012-11-09 01:05:47 -08001489
1490const unsigned *
1491fs_generator::generate_assembly(exec_list *simd8_instructions,
1492 exec_list *simd16_instructions,
1493 unsigned *assembly_size)
1494{
1495 dispatch_width = 8;
1496 generate_code(simd8_instructions);
1497
1498 if (simd16_instructions) {
1499 /* We have to do a compaction pass now, or the one at the end of
1500 * execution will squash down where our prog_offset start needs
1501 * to be.
1502 */
1503 brw_compact_instructions(p);
1504
1505 /* align to 64 byte boundary. */
1506 while ((p->nr_insn * sizeof(struct brw_instruction)) % 64) {
1507 brw_NOP(p);
1508 }
1509
1510 /* Save off the start of this 16-wide program */
1511 c->prog_data.prog_offset_16 = p->nr_insn * sizeof(struct brw_instruction);
1512
1513 brw_set_compression_control(p, BRW_COMPRESSION_COMPRESSED);
1514
1515 dispatch_width = 16;
1516 generate_code(simd16_instructions);
1517 }
1518
1519 return brw_get_program(p, assembly_size);
1520}