2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
6 Permission is hereby granted, free of charge, to any person obtaining
7 a copy of this software and associated documentation files (the
8 "Software"), to deal in the Software without restriction, including
9 without limitation the rights to use, copy, modify, merge, publish,
10 distribute, sublicense, and/or sell copies of the Software, and to
11 permit persons to whom the Software is furnished to do so, subject to
12 the following conditions:
14 The above copyright notice and this permission notice (including the
15 next paragraph) shall be included in all copies or substantial
16 portions of the Software.
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
33 #include "brw_context.h"
35 #include "program_instruction.h"
41 /* Do things as simply as possible. Allocate and populate all regs
44 static void brw_vs_alloc_regs( struct brw_vs_compile
*c
)
46 GLuint i
, reg
= 0, mrf
;
49 /* r0 -- reserved as usual
51 c
->r0
= brw_vec8_grf(reg
, 0); reg
++;
53 /* User clip planes from curbe:
55 if (c
->key
.nr_userclip
) {
56 for (i
= 0; i
< c
->key
.nr_userclip
; i
++) {
57 c
->userplane
[i
] = stride( brw_vec4_grf(reg
+3+i
/2, (i
%2) * 4), 0, 4, 1);
60 /* Deal with curbe alignment:
62 reg
+= ((6+c
->key
.nr_userclip
+3)/4)*2;
65 /* Vertex program parameters from curbe:
67 nr_params
= c
->vp
->program
.Base
.Parameters
->NumParameters
;
68 for (i
= 0; i
< nr_params
; i
++) {
69 c
->regs
[PROGRAM_STATE_VAR
][i
] = stride( brw_vec4_grf(reg
+i
/2, (i
%2) * 4), 0, 4, 1);
71 reg
+= (nr_params
+1)/2;
73 c
->prog_data
.curb_read_length
= reg
- 1;
77 /* Allocate input regs:
80 for (i
= 0; i
< BRW_ATTRIB_MAX
; i
++) {
81 if (c
->prog_data
.inputs_read
& (1<<i
)) {
83 c
->regs
[PROGRAM_INPUT
][i
] = brw_vec8_grf(reg
, 0);
89 /* Allocate outputs: TODO: could organize the non-position outputs
90 * to go straight into message regs.
93 c
->first_output
= reg
;
95 for (i
= 0; i
< VERT_RESULT_MAX
; i
++) {
96 if (c
->prog_data
.outputs_written
& (1<<i
)) {
98 if (i
== VERT_RESULT_HPOS
) {
99 c
->regs
[PROGRAM_OUTPUT
][i
] = brw_vec8_grf(reg
, 0);
102 else if (i
== VERT_RESULT_PSIZ
) {
103 c
->regs
[PROGRAM_OUTPUT
][i
] = brw_vec8_grf(reg
, 0);
105 mrf
++; /* just a placeholder? XXX fix later stages & remove this */
108 c
->regs
[PROGRAM_OUTPUT
][i
] = brw_message_reg(mrf
);
114 /* Allocate program temporaries:
116 for (i
= 0; i
< c
->vp
->program
.Base
.NumTemporaries
; i
++) {
117 c
->regs
[PROGRAM_TEMPORARY
][i
] = brw_vec8_grf(reg
, 0);
121 /* Address reg(s). Don't try to use the internal address reg until
124 for (i
= 0; i
< c
->vp
->program
.Base
.NumAddressRegs
; i
++) {
125 c
->regs
[PROGRAM_ADDRESS
][i
] = brw_reg(BRW_GENERAL_REGISTER_FILE
,
129 BRW_VERTICAL_STRIDE_8
,
131 BRW_HORIZONTAL_STRIDE_1
,
138 /* Some opcodes need an internal temporary:
141 c
->last_tmp
= reg
; /* for allocation purposes */
143 /* Each input reg holds data from two vertices. The
144 * urb_read_length is the number of registers read from *each*
145 * vertex urb, so is half the amount:
147 c
->prog_data
.urb_read_length
= (c
->nr_inputs
+1)/2;
149 c
->prog_data
.urb_entry_size
= (c
->nr_outputs
+2+3)/4;
150 c
->prog_data
.total_grf
= reg
;
154 static struct brw_reg
get_tmp( struct brw_vs_compile
*c
)
156 struct brw_reg tmp
= brw_vec8_grf(c
->last_tmp
, 0);
158 if (++c
->last_tmp
> c
->prog_data
.total_grf
)
159 c
->prog_data
.total_grf
= c
->last_tmp
;
164 static void release_tmp( struct brw_vs_compile
*c
, struct brw_reg tmp
)
166 if (tmp
.nr
== c
->last_tmp
-1)
170 static void release_tmps( struct brw_vs_compile
*c
)
172 c
->last_tmp
= c
->first_tmp
;
176 static void unalias1( struct brw_vs_compile
*c
,
179 void (*func
)( struct brw_vs_compile
*,
183 if (dst
.file
== arg0
.file
&& dst
.nr
== arg0
.nr
) {
184 struct brw_compile
*p
= &c
->func
;
185 struct brw_reg tmp
= brw_writemask(get_tmp(c
), dst
.dw1
.bits
.writemask
);
187 brw_MOV(p
, dst
, tmp
);
194 static void unalias2( struct brw_vs_compile
*c
,
198 void (*func
)( struct brw_vs_compile
*,
203 if ((dst
.file
== arg0
.file
&& dst
.nr
== arg0
.nr
) &&
204 (dst
.file
== arg1
.file
&& dst
.nr
== arg1
.nr
)) {
205 struct brw_compile
*p
= &c
->func
;
206 struct brw_reg tmp
= brw_writemask(get_tmp(c
), dst
.dw1
.bits
.writemask
);
207 func(c
, tmp
, arg0
, arg1
);
208 brw_MOV(p
, dst
, tmp
);
211 func(c
, dst
, arg0
, arg1
);
218 static void emit_slt( struct brw_compile
*p
,
221 struct brw_reg arg1
)
223 /* Could be done with an if/else/endif, but this method uses half
224 * the instructions. Note that we are careful to reference the
225 * arguments before writing the dest. That means we emit the
226 * instructions in an odd order and have to play with the flag
229 brw_push_insn_state(p
);
230 brw_CMP(p
, brw_null_reg(), BRW_CONDITIONAL_GE
, arg0
, arg1
);
232 /* Write all values to 1:
234 brw_set_predicate_control(p
, BRW_PREDICATE_NONE
);
235 brw_MOV(p
, dst
, brw_imm_f(1.0));
237 /* Where the test succeeded, overwite with zero:
239 brw_set_predicate_control(p
, BRW_PREDICATE_NORMAL
);
240 brw_MOV(p
, dst
, brw_imm_f(0.0));
241 brw_pop_insn_state(p
);
245 static void emit_sge( struct brw_compile
*p
,
248 struct brw_reg arg1
)
250 brw_push_insn_state(p
);
251 brw_CMP(p
, brw_null_reg(), BRW_CONDITIONAL_GE
, arg0
, arg1
);
253 /* Write all values to zero:
255 brw_set_predicate_control(p
, BRW_PREDICATE_NONE
);
256 brw_MOV(p
, dst
, brw_imm_f(0));
258 /* Where the test succeeded, overwite with 1:
260 brw_set_predicate_control(p
, BRW_PREDICATE_NORMAL
);
261 brw_MOV(p
, dst
, brw_imm_f(1.0));
262 brw_pop_insn_state(p
);
266 static void emit_max( struct brw_compile
*p
,
269 struct brw_reg arg1
)
271 brw_CMP(p
, brw_null_reg(), BRW_CONDITIONAL_L
, arg0
, arg1
);
272 brw_SEL(p
, dst
, arg1
, arg0
);
273 brw_set_predicate_control(p
, BRW_PREDICATE_NONE
);
276 static void emit_min( struct brw_compile
*p
,
279 struct brw_reg arg1
)
281 brw_CMP(p
, brw_null_reg(), BRW_CONDITIONAL_L
, arg0
, arg1
);
282 brw_SEL(p
, dst
, arg0
, arg1
);
283 brw_set_predicate_control(p
, BRW_PREDICATE_NONE
);
287 static void emit_math1( struct brw_vs_compile
*c
,
293 /* There are various odd behaviours with SEND on the simulator. In
294 * addition there are documented issues with the fact that the GEN4
295 * processor doesn't do dependency control properly on SEND
296 * results. So, on balance, this kludge to get around failures
297 * with writemasked math results looks like it might be necessary
298 * whether that turns out to be a simulator bug or not:
300 struct brw_compile
*p
= &c
->func
;
301 struct brw_reg tmp
= dst
;
302 GLboolean need_tmp
= (dst
.dw1
.bits
.writemask
!= 0xf ||
303 dst
.file
!= BRW_GENERAL_REGISTER_FILE
);
311 BRW_MATH_SATURATE_NONE
,
314 BRW_MATH_DATA_SCALAR
,
318 brw_MOV(p
, dst
, tmp
);
323 static void emit_math2( struct brw_vs_compile
*c
,
330 struct brw_compile
*p
= &c
->func
;
331 struct brw_reg tmp
= dst
;
332 GLboolean need_tmp
= (dst
.dw1
.bits
.writemask
!= 0xf ||
333 dst
.file
!= BRW_GENERAL_REGISTER_FILE
);
338 brw_MOV(p
, brw_message_reg(3), arg1
);
343 BRW_MATH_SATURATE_NONE
,
346 BRW_MATH_DATA_SCALAR
,
350 brw_MOV(p
, dst
, tmp
);
357 static void emit_exp_noalias( struct brw_vs_compile
*c
,
359 struct brw_reg arg0
)
361 struct brw_compile
*p
= &c
->func
;
364 if (dst
.dw1
.bits
.writemask
& WRITEMASK_X
) {
365 struct brw_reg tmp
= get_tmp(c
);
366 struct brw_reg tmp_d
= retype(tmp
, BRW_REGISTER_TYPE_D
);
368 /* tmp_d = floor(arg0.x) */
369 brw_RNDD(p
, tmp_d
, brw_swizzle1(arg0
, 0));
371 /* result[0] = 2.0 ^ tmp */
373 /* Adjust exponent for floating point:
376 brw_ADD(p
, brw_writemask(tmp_d
, WRITEMASK_X
), tmp_d
, brw_imm_d(127));
378 /* Install exponent and sign.
379 * Excess drops off the edge:
381 brw_SHL(p
, brw_writemask(retype(dst
, BRW_REGISTER_TYPE_D
), WRITEMASK_X
),
382 tmp_d
, brw_imm_d(23));
387 if (dst
.dw1
.bits
.writemask
& WRITEMASK_Y
) {
388 /* result[1] = arg0.x - floor(arg0.x) */
389 brw_FRC(p
, brw_writemask(dst
, WRITEMASK_Y
), brw_swizzle1(arg0
, 0));
392 if (dst
.dw1
.bits
.writemask
& WRITEMASK_Z
) {
393 /* As with the LOG instruction, we might be better off just
394 * doing a taylor expansion here, seeing as we have to do all
397 * If mathbox partial precision is too low, consider also:
398 * result[3] = result[0] * EXP(result[1])
401 BRW_MATH_FUNCTION_EXP
,
402 brw_writemask(dst
, WRITEMASK_Z
),
403 brw_swizzle1(arg0
, 0),
404 BRW_MATH_PRECISION_PARTIAL
);
407 if (dst
.dw1
.bits
.writemask
& WRITEMASK_W
) {
408 /* result[3] = 1.0; */
409 brw_MOV(p
, brw_writemask(dst
, WRITEMASK_W
), brw_imm_f(1));
414 static void emit_log_noalias( struct brw_vs_compile
*c
,
416 struct brw_reg arg0
)
418 struct brw_compile
*p
= &c
->func
;
419 struct brw_reg dst_ud
= retype(dst
, BRW_REGISTER_TYPE_UD
);
420 struct brw_reg arg0_ud
= retype(arg0
, BRW_REGISTER_TYPE_UD
);
422 /* Perform mant = frexpf(fabsf(x), &exp), adjust exp and mnt
425 * These almost look likey they could be joined up, but not really
428 * result[0].f = (x.i & ((1<<31)-1) >> 23) - 127
429 * result[1].i = (x.i & ((1<<23)-1) + (127<<23)
431 if (dst
.dw1
.bits
.writemask
& WRITEMASK_XZ
) {
433 brw_writemask(dst_ud
, WRITEMASK_X
),
434 brw_swizzle1(arg0_ud
, 0),
435 brw_imm_ud((1U<<31)-1));
438 brw_writemask(dst_ud
, WRITEMASK_X
),
443 brw_writemask(dst
, WRITEMASK_X
),
444 retype(dst_ud
, BRW_REGISTER_TYPE_D
), /* does it matter? */
448 if (dst
.dw1
.bits
.writemask
& WRITEMASK_YZ
) {
450 brw_writemask(dst_ud
, WRITEMASK_Y
),
451 brw_swizzle1(arg0_ud
, 0),
452 brw_imm_ud((1<<23)-1));
455 brw_writemask(dst_ud
, WRITEMASK_Y
),
457 brw_imm_ud(127<<23));
460 if (dst
.dw1
.bits
.writemask
& WRITEMASK_Z
) {
461 /* result[2] = result[0] + LOG2(result[1]); */
463 /* Why bother? The above is just a hint how to do this with a
464 * taylor series. Maybe we *should* use a taylor series as by
465 * the time all the above has been done it's almost certainly
466 * quicker than calling the mathbox, even with low precision.
469 * - result[0] + mathbox.LOG2(result[1])
470 * - mathbox.LOG2(arg0.x)
471 * - result[0] + inline_taylor_approx(result[1])
474 BRW_MATH_FUNCTION_LOG
,
475 brw_writemask(dst
, WRITEMASK_Z
),
476 brw_swizzle1(dst
, 1),
477 BRW_MATH_PRECISION_FULL
);
480 brw_writemask(dst
, WRITEMASK_Z
),
481 brw_swizzle1(dst
, 2),
482 brw_swizzle1(dst
, 0));
485 if (dst
.dw1
.bits
.writemask
& WRITEMASK_W
) {
486 /* result[3] = 1.0; */
487 brw_MOV(p
, brw_writemask(dst
, WRITEMASK_W
), brw_imm_f(1));
494 /* Need to unalias - consider swizzles: r0 = DST r0.xxxx r1
496 static void emit_dst_noalias( struct brw_vs_compile
*c
,
501 struct brw_compile
*p
= &c
->func
;
503 /* There must be a better way to do this:
505 if (dst
.dw1
.bits
.writemask
& WRITEMASK_X
)
506 brw_MOV(p
, brw_writemask(dst
, WRITEMASK_X
), brw_imm_f(1.0));
507 if (dst
.dw1
.bits
.writemask
& WRITEMASK_Y
)
508 brw_MUL(p
, brw_writemask(dst
, WRITEMASK_Y
), arg0
, arg1
);
509 if (dst
.dw1
.bits
.writemask
& WRITEMASK_Z
)
510 brw_MOV(p
, brw_writemask(dst
, WRITEMASK_Z
), arg0
);
511 if (dst
.dw1
.bits
.writemask
& WRITEMASK_W
)
512 brw_MOV(p
, brw_writemask(dst
, WRITEMASK_W
), arg1
);
515 static void emit_xpd( struct brw_compile
*p
,
520 brw_MUL(p
, brw_null_reg(), brw_swizzle(t
, 1,2,0,3), brw_swizzle(u
,2,0,1,3));
521 brw_MAC(p
, dst
, negate(brw_swizzle(t
, 2,0,1,3)), brw_swizzle(u
,1,2,0,3));
526 static void emit_lit_noalias( struct brw_vs_compile
*c
,
528 struct brw_reg arg0
)
530 struct brw_compile
*p
= &c
->func
;
531 struct brw_instruction
*if_insn
;
532 struct brw_reg tmp
= dst
;
533 GLboolean need_tmp
= (dst
.file
!= BRW_GENERAL_REGISTER_FILE
);
538 brw_MOV(p
, brw_writemask(dst
, WRITEMASK_YZ
), brw_imm_f(0));
539 brw_MOV(p
, brw_writemask(dst
, WRITEMASK_XW
), brw_imm_f(1));
541 /* Need to use BRW_EXECUTE_8 and also do an 8-wide compare in order
542 * to get all channels active inside the IF. In the clipping code
543 * we run with NoMask, so it's not an option and we can use
544 * BRW_EXECUTE_1 for all comparisions.
546 brw_CMP(p
, brw_null_reg(), BRW_CONDITIONAL_G
, brw_swizzle1(arg0
,0), brw_imm_f(0));
547 if_insn
= brw_IF(p
, BRW_EXECUTE_8
);
549 brw_MOV(p
, brw_writemask(dst
, WRITEMASK_Y
), brw_swizzle1(arg0
,0));
551 brw_CMP(p
, brw_null_reg(), BRW_CONDITIONAL_G
, brw_swizzle1(arg0
,1), brw_imm_f(0));
552 brw_MOV(p
, brw_writemask(tmp
, WRITEMASK_Z
), brw_swizzle1(arg0
,1));
553 brw_set_predicate_control(p
, BRW_PREDICATE_NONE
);
556 BRW_MATH_FUNCTION_POW
,
557 brw_writemask(dst
, WRITEMASK_Z
),
558 brw_swizzle1(tmp
, 2),
559 brw_swizzle1(arg0
, 3),
560 BRW_MATH_PRECISION_PARTIAL
);
563 brw_ENDIF(p
, if_insn
);
570 /* TODO: relative addressing!
572 static struct brw_reg
get_reg( struct brw_vs_compile
*c
,
578 case PROGRAM_TEMPORARY
:
581 case PROGRAM_STATE_VAR
:
582 assert(c
->regs
[file
][index
].nr
!= 0);
583 return c
->regs
[file
][index
];
584 case PROGRAM_ADDRESS
:
586 return c
->regs
[file
][index
];
588 case PROGRAM_UNDEFINED
: /* undef values */
589 return brw_null_reg();
591 case PROGRAM_LOCAL_PARAM
:
592 case PROGRAM_ENV_PARAM
:
593 case PROGRAM_WRITE_ONLY
:
596 return brw_null_reg();
602 static struct brw_reg
deref( struct brw_vs_compile
*c
,
606 struct brw_compile
*p
= &c
->func
;
607 struct brw_reg tmp
= vec4(get_tmp(c
));
608 struct brw_reg vp_address
= retype(vec1(get_reg(c
, PROGRAM_ADDRESS
, 0)), BRW_REGISTER_TYPE_UW
);
609 GLuint byte_offset
= arg
.nr
* 32 + arg
.subnr
+ offset
* 16;
610 struct brw_reg indirect
= brw_vec4_indirect(0,0);
613 brw_push_insn_state(p
);
614 brw_set_access_mode(p
, BRW_ALIGN_1
);
616 /* This is pretty clunky - load the address register twice and
617 * fetch each 4-dword value in turn. There must be a way to do
618 * this in a single pass, but I couldn't get it to work.
620 brw_ADD(p
, brw_address_reg(0), vp_address
, brw_imm_d(byte_offset
));
621 brw_MOV(p
, tmp
, indirect
);
623 brw_ADD(p
, brw_address_reg(0), suboffset(vp_address
, 8), brw_imm_d(byte_offset
));
624 brw_MOV(p
, suboffset(tmp
, 4), indirect
);
626 brw_pop_insn_state(p
);
633 static void emit_arl( struct brw_vs_compile
*c
,
635 struct brw_reg arg0
)
637 struct brw_compile
*p
= &c
->func
;
639 brw_RNDD(p
, dst
, arg0
);
641 brw_MUL(p
, dst
, dst
, brw_imm_d(16));
645 /* Will return mangled results for SWZ op. The emit_swz() function
646 * ignores this result and recalculates taking extended swizzles into
649 static struct brw_reg
get_arg( struct brw_vs_compile
*c
,
650 struct prog_src_register src
)
654 if (src
.File
== PROGRAM_UNDEFINED
)
655 return brw_null_reg();
658 reg
= deref(c
, c
->regs
[PROGRAM_STATE_VAR
][0], src
.Index
);
660 reg
= get_reg(c
, src
.File
, src
.Index
);
662 /* Convert 3-bit swizzle to 2-bit.
664 reg
.dw1
.bits
.swizzle
= BRW_SWIZZLE4(GET_SWZ(src
.Swizzle
, 0),
665 GET_SWZ(src
.Swizzle
, 1),
666 GET_SWZ(src
.Swizzle
, 2),
667 GET_SWZ(src
.Swizzle
, 3));
669 /* Note this is ok for non-swizzle instructions:
671 reg
.negate
= src
.NegateBase
? 1 : 0;
677 static struct brw_reg
get_dst( struct brw_vs_compile
*c
,
678 struct prog_dst_register dst
)
680 struct brw_reg reg
= get_reg(c
, dst
.File
, dst
.Index
);
682 reg
.dw1
.bits
.writemask
= dst
.WriteMask
;
690 static void emit_swz( struct brw_vs_compile
*c
,
692 struct prog_src_register src
)
694 struct brw_compile
*p
= &c
->func
;
695 GLuint zeros_mask
= 0;
696 GLuint ones_mask
= 0;
699 GLboolean need_tmp
= (src
.NegateBase
&&
700 dst
.file
!= BRW_GENERAL_REGISTER_FILE
);
701 struct brw_reg tmp
= dst
;
707 for (i
= 0; i
< 4; i
++) {
708 if (dst
.dw1
.bits
.writemask
& (1<<i
)) {
709 GLubyte s
= GET_SWZ(src
.Swizzle
, i
);
728 /* Do src first, in case dst aliases src:
734 arg0
= deref(c
, c
->regs
[PROGRAM_STATE_VAR
][0], src
.Index
);
736 arg0
= get_reg(c
, src
.File
, src
.Index
);
738 arg0
= brw_swizzle(arg0
,
739 src_swz
[0], src_swz
[1],
740 src_swz
[2], src_swz
[3]);
742 brw_MOV(p
, brw_writemask(tmp
, src_mask
), arg0
);
746 brw_MOV(p
, brw_writemask(tmp
, zeros_mask
), brw_imm_f(0));
749 brw_MOV(p
, brw_writemask(tmp
, ones_mask
), brw_imm_f(1));
752 brw_MOV(p
, brw_writemask(tmp
, src
.NegateBase
), negate(tmp
));
755 brw_MOV(p
, dst
, tmp
);
762 /* Post-vertex-program processing. Send the results to the URB.
764 static void emit_vertex_write( struct brw_vs_compile
*c
)
766 struct brw_compile
*p
= &c
->func
;
767 struct brw_reg m0
= brw_message_reg(0);
768 struct brw_reg pos
= c
->regs
[PROGRAM_OUTPUT
][VERT_RESULT_HPOS
];
771 if (c
->key
.copy_edgeflag
) {
773 get_reg(c
, PROGRAM_OUTPUT
, VERT_RESULT_EDGE
),
774 get_reg(c
, PROGRAM_INPUT
, BRW_ATTRIB_EDGEFLAG
));
778 /* Build ndc coords? TODO: Shortcircuit when w is known to be one.
781 emit_math1(c
, BRW_MATH_FUNCTION_INV
, ndc
, brw_swizzle1(pos
, 3), BRW_MATH_PRECISION_FULL
);
782 brw_MUL(p
, brw_writemask(ndc
, WRITEMASK_XYZ
), pos
, ndc
);
784 /* This includes the workaround for -ve rhw, so is no longer an
788 struct brw_reg header1
= retype(get_tmp(c
), BRW_REGISTER_TYPE_UD
);
791 brw_MOV(p
, header1
, brw_imm_ud(0));
793 brw_set_access_mode(p
, BRW_ALIGN_16
);
795 if (c
->prog_data
.outputs_written
& (1<<VERT_RESULT_PSIZ
)) {
796 struct brw_reg psiz
= c
->regs
[PROGRAM_OUTPUT
][VERT_RESULT_PSIZ
];
797 brw_MUL(p
, brw_writemask(header1
, WRITEMASK_W
), brw_swizzle1(psiz
, 0), brw_imm_f(1<<11));
798 brw_AND(p
, brw_writemask(header1
, WRITEMASK_W
), header1
, brw_imm_ud(0x7ff<<8));
802 for (i
= 0; i
< c
->key
.nr_userclip
; i
++) {
803 brw_set_conditionalmod(p
, BRW_CONDITIONAL_L
);
804 brw_DP4(p
, brw_null_reg(), pos
, c
->userplane
[i
]);
805 brw_OR(p
, brw_writemask(header1
, WRITEMASK_W
), header1
, brw_imm_ud(1<<i
));
806 brw_set_predicate_control(p
, BRW_PREDICATE_NONE
);
810 /* i965 clipping workaround:
811 * 1) Test for -ve rhw
813 * set ndc = (0,0,0,0)
816 * Later, clipping will detect ucp[6] and ensure the primitive is
817 * clipped against all fixed planes.
820 vec8(brw_null_reg()),
822 brw_swizzle1(ndc
, 3),
825 brw_OR(p
, brw_writemask(header1
, WRITEMASK_W
), header1
, brw_imm_ud(1<<6));
826 brw_MOV(p
, ndc
, brw_imm_f(0));
827 brw_set_predicate_control(p
, BRW_PREDICATE_NONE
);
834 brw_set_access_mode(p
, BRW_ALIGN_1
); /* why? */
835 brw_MOV(p
, retype(brw_message_reg(1), BRW_REGISTER_TYPE_UD
), header1
);
836 brw_set_access_mode(p
, BRW_ALIGN_16
);
838 release_tmp(c
, header1
);
842 /* Emit the (interleaved) headers for the two vertices - an 8-reg
843 * of zeros followed by two sets of NDC coordinates:
845 brw_set_access_mode(p
, BRW_ALIGN_1
);
846 brw_MOV(p
, offset(m0
, 2), ndc
);
847 brw_MOV(p
, offset(m0
, 3), pos
);
851 brw_null_reg(), /* dest */
852 0, /* starting mrf reg nr */
856 c
->nr_outputs
+ 3, /* msg len */
857 0, /* response len */
859 1, /* writes complete */
860 0, /* urb destination offset */
861 BRW_URB_SWIZZLE_INTERLEAVE
);
868 /* Emit the fragment program instructions here.
870 void brw_vs_emit( struct brw_vs_compile
*c
)
872 struct brw_compile
*p
= &c
->func
;
873 GLuint nr_insns
= c
->vp
->program
.Base
.NumInstructions
;
876 brw_set_compression_control(p
, BRW_COMPRESSION_NONE
);
877 brw_set_access_mode(p
, BRW_ALIGN_16
);
879 /* Static register allocation
881 brw_vs_alloc_regs(c
);
883 for (insn
= 0; insn
< nr_insns
; insn
++) {
885 struct prog_instruction
*inst
= &c
->vp
->program
.Base
.Instructions
[insn
];
886 struct brw_reg args
[3], dst
;
889 /* Get argument regs. SWZ is special and does this itself.
891 if (inst
->Opcode
!= OPCODE_SWZ
)
892 for (i
= 0; i
< 3; i
++)
893 args
[i
] = get_arg(c
, inst
->SrcReg
[i
]);
895 /* Get dest regs. Note that it is possible for a reg to be both
896 * dst and arg, given the static allocation of registers. So
897 * care needs to be taken emitting multi-operation instructions.
899 dst
= get_dst(c
, inst
->DstReg
);
902 switch (inst
->Opcode
) {
904 brw_MOV(p
, dst
, brw_abs(args
[0]));
907 brw_ADD(p
, dst
, args
[0], args
[1]);
910 brw_DP3(p
, dst
, args
[0], args
[1]);
913 brw_DP4(p
, dst
, args
[0], args
[1]);
916 brw_DPH(p
, dst
, args
[0], args
[1]);
919 unalias2(c
, dst
, args
[0], args
[1], emit_dst_noalias
);
922 unalias1(c
, dst
, args
[0], emit_exp_noalias
);
925 emit_math1(c
, BRW_MATH_FUNCTION_EXP
, dst
, args
[0], BRW_MATH_PRECISION_FULL
);
928 emit_arl(c
, dst
, args
[0]);
931 brw_RNDD(p
, dst
, args
[0]);
934 brw_FRC(p
, dst
, args
[0]);
937 unalias1(c
, dst
, args
[0], emit_log_noalias
);
940 emit_math1(c
, BRW_MATH_FUNCTION_LOG
, dst
, args
[0], BRW_MATH_PRECISION_FULL
);
943 unalias1(c
, dst
, args
[0], emit_lit_noalias
);
946 brw_MOV(p
, brw_acc_reg(), args
[2]);
947 brw_MAC(p
, dst
, args
[0], args
[1]);
950 emit_max(p
, dst
, args
[0], args
[1]);
953 emit_min(p
, dst
, args
[0], args
[1]);
956 brw_MOV(p
, dst
, args
[0]);
959 brw_MUL(p
, dst
, args
[0], args
[1]);
962 emit_math2(c
, BRW_MATH_FUNCTION_POW
, dst
, args
[0], args
[1], BRW_MATH_PRECISION_FULL
);
965 emit_math1(c
, BRW_MATH_FUNCTION_INV
, dst
, args
[0], BRW_MATH_PRECISION_FULL
);
968 emit_math1(c
, BRW_MATH_FUNCTION_RSQ
, dst
, args
[0], BRW_MATH_PRECISION_FULL
);
971 emit_sge(p
, dst
, args
[0], args
[1]);
974 emit_slt(p
, dst
, args
[0], args
[1]);
977 brw_ADD(p
, dst
, args
[0], negate(args
[1]));
980 /* The args[0] value can't be used here as it won't have
981 * correctly encoded the full swizzle:
983 emit_swz(c
, dst
, inst
->SrcReg
[0] );
986 emit_xpd(p
, dst
, args
[0], args
[1]);
998 emit_vertex_write(c
);