gallium: switch dedicated centroid field to interpolation location
[mesa.git] / src / gallium / auxiliary / tgsi / tgsi_ureg.h
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * 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, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE, INC AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #ifndef TGSI_UREG_H
29 #define TGSI_UREG_H
30
31 #include "pipe/p_compiler.h"
32 #include "pipe/p_shader_tokens.h"
33 #include "util/u_debug.h"
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39 struct ureg_program;
40 struct pipe_stream_output_info;
41
42 /* Almost a tgsi_src_register, but we need to pull in the Absolute
43 * flag from the _ext token. Indirect flag always implies ADDR[0].
44 */
45 struct ureg_src
46 {
47 unsigned File : 4; /* TGSI_FILE_ */
48 unsigned SwizzleX : 2; /* TGSI_SWIZZLE_ */
49 unsigned SwizzleY : 2; /* TGSI_SWIZZLE_ */
50 unsigned SwizzleZ : 2; /* TGSI_SWIZZLE_ */
51 unsigned SwizzleW : 2; /* TGSI_SWIZZLE_ */
52 unsigned Indirect : 1; /* BOOL */
53 unsigned DimIndirect : 1; /* BOOL */
54 unsigned Dimension : 1; /* BOOL */
55 unsigned Absolute : 1; /* BOOL */
56 unsigned Negate : 1; /* BOOL */
57 unsigned IndirectFile : 4; /* TGSI_FILE_ */
58 unsigned IndirectSwizzle : 2; /* TGSI_SWIZZLE_ */
59 unsigned DimIndFile : 4; /* TGSI_FILE_ */
60 unsigned DimIndSwizzle : 2; /* TGSI_SWIZZLE_ */
61 int Index : 16; /* SINT */
62 int IndirectIndex : 16; /* SINT */
63 int DimensionIndex : 16; /* SINT */
64 int DimIndIndex : 16; /* SINT */
65 unsigned ArrayID : 10; /* UINT */
66 };
67
68 /* Very similar to a tgsi_dst_register, removing unsupported fields
69 * and adding a Saturate flag. It's easier to push saturate into the
70 * destination register than to try and create a _SAT variant of each
71 * instruction function.
72 */
73 struct ureg_dst
74 {
75 unsigned File : 4; /* TGSI_FILE_ */
76 unsigned WriteMask : 4; /* TGSI_WRITEMASK_ */
77 unsigned Indirect : 1; /* BOOL */
78 unsigned Saturate : 1; /* BOOL */
79 unsigned Predicate : 1;
80 unsigned PredNegate : 1; /* BOOL */
81 unsigned PredSwizzleX : 2; /* TGSI_SWIZZLE_ */
82 unsigned PredSwizzleY : 2; /* TGSI_SWIZZLE_ */
83 unsigned PredSwizzleZ : 2; /* TGSI_SWIZZLE_ */
84 unsigned PredSwizzleW : 2; /* TGSI_SWIZZLE_ */
85 int Index : 16; /* SINT */
86 int IndirectIndex : 16; /* SINT */
87 unsigned IndirectFile : 4; /* TGSI_FILE_ */
88 int IndirectSwizzle : 2; /* TGSI_SWIZZLE_ */
89 unsigned ArrayID : 10; /* UINT */
90 };
91
92 struct pipe_context;
93
94 struct ureg_program *
95 ureg_create( unsigned processor );
96
97 const struct tgsi_token *
98 ureg_finalize( struct ureg_program * );
99
100 /* Create and return a shader:
101 */
102 void *
103 ureg_create_shader( struct ureg_program *,
104 struct pipe_context *pipe,
105 const struct pipe_stream_output_info *so );
106
107
108 /* Alternately, return the built token stream and hand ownership of
109 * that memory to the caller:
110 */
111 const struct tgsi_token *
112 ureg_get_tokens( struct ureg_program *ureg,
113 unsigned *nr_tokens );
114
115 /*
116 * Returns the number of currently declared outputs.
117 */
118 const unsigned
119 ureg_get_nr_outputs( const struct ureg_program *ureg );
120
121
122 /* Free the tokens created by ureg_get_tokens() */
123 void ureg_free_tokens( const struct tgsi_token *tokens );
124
125
126 void
127 ureg_destroy( struct ureg_program * );
128
129
130 /***********************************************************************
131 * Convenience routine:
132 */
133 static INLINE void *
134 ureg_create_shader_with_so_and_destroy( struct ureg_program *p,
135 struct pipe_context *pipe,
136 const struct pipe_stream_output_info *so )
137 {
138 void *result = ureg_create_shader( p, pipe, so );
139 ureg_destroy( p );
140 return result;
141 }
142
143 static INLINE void *
144 ureg_create_shader_and_destroy( struct ureg_program *p,
145 struct pipe_context *pipe )
146 {
147 return ureg_create_shader_with_so_and_destroy(p, pipe, NULL);
148 }
149
150
151 /***********************************************************************
152 * Build shader properties:
153 */
154
155 void
156 ureg_property_gs_input_prim(struct ureg_program *ureg,
157 unsigned input_prim);
158
159 void
160 ureg_property_gs_output_prim(struct ureg_program *ureg,
161 unsigned output_prim);
162
163 void
164 ureg_property_gs_max_vertices(struct ureg_program *ureg,
165 unsigned max_vertices);
166
167 void
168 ureg_property_gs_invocations(struct ureg_program *ureg,
169 unsigned invocations);
170
171 void
172 ureg_property_fs_coord_origin(struct ureg_program *ureg,
173 unsigned fs_coord_origin);
174
175 void
176 ureg_property_fs_coord_pixel_center(struct ureg_program *ureg,
177 unsigned fs_coord_pixel_center);
178
179 void
180 ureg_property_fs_color0_writes_all_cbufs(struct ureg_program *ureg,
181 unsigned fs_color0_writes_all_cbufs);
182
183 void
184 ureg_property_fs_depth_layout(struct ureg_program *ureg,
185 unsigned fs_depth_layout);
186
187 void
188 ureg_property_vs_window_space_position(struct ureg_program *ureg,
189 boolean vs_window_space_position);
190
191
192 /***********************************************************************
193 * Build shader declarations:
194 */
195
196 struct ureg_src
197 ureg_DECL_fs_input_cyl_centroid(struct ureg_program *,
198 unsigned semantic_name,
199 unsigned semantic_index,
200 unsigned interp_mode,
201 unsigned cylindrical_wrap,
202 unsigned interp_location);
203
204 static INLINE struct ureg_src
205 ureg_DECL_fs_input_cyl(struct ureg_program *ureg,
206 unsigned semantic_name,
207 unsigned semantic_index,
208 unsigned interp_mode,
209 unsigned cylindrical_wrap)
210 {
211 return ureg_DECL_fs_input_cyl_centroid(ureg,
212 semantic_name,
213 semantic_index,
214 interp_mode,
215 cylindrical_wrap,
216 0);
217 }
218
219 static INLINE struct ureg_src
220 ureg_DECL_fs_input(struct ureg_program *ureg,
221 unsigned semantic_name,
222 unsigned semantic_index,
223 unsigned interp_mode)
224 {
225 return ureg_DECL_fs_input_cyl_centroid(ureg,
226 semantic_name,
227 semantic_index,
228 interp_mode,
229 0, 0);
230 }
231
232 struct ureg_src
233 ureg_DECL_vs_input( struct ureg_program *,
234 unsigned index );
235
236 struct ureg_src
237 ureg_DECL_gs_input(struct ureg_program *,
238 unsigned index,
239 unsigned semantic_name,
240 unsigned semantic_index);
241
242 struct ureg_src
243 ureg_DECL_system_value(struct ureg_program *,
244 unsigned index,
245 unsigned semantic_name,
246 unsigned semantic_index);
247
248 struct ureg_dst
249 ureg_DECL_output_masked( struct ureg_program *,
250 unsigned semantic_name,
251 unsigned semantic_index,
252 unsigned usage_mask );
253
254 struct ureg_dst
255 ureg_DECL_output( struct ureg_program *,
256 unsigned semantic_name,
257 unsigned semantic_index );
258
259 struct ureg_src
260 ureg_DECL_immediate( struct ureg_program *,
261 const float *v,
262 unsigned nr );
263
264 struct ureg_src
265 ureg_DECL_immediate_uint( struct ureg_program *,
266 const unsigned *v,
267 unsigned nr );
268
269 struct ureg_src
270 ureg_DECL_immediate_block_uint( struct ureg_program *,
271 const unsigned *v,
272 unsigned nr );
273
274 struct ureg_src
275 ureg_DECL_immediate_int( struct ureg_program *,
276 const int *v,
277 unsigned nr );
278
279 void
280 ureg_DECL_constant2D(struct ureg_program *ureg,
281 unsigned first,
282 unsigned last,
283 unsigned index2D);
284
285 struct ureg_src
286 ureg_DECL_constant( struct ureg_program *,
287 unsigned index );
288
289 struct ureg_dst
290 ureg_DECL_temporary( struct ureg_program * );
291
292 /**
293 * Emit a temporary with the LOCAL declaration flag set. For use when
294 * the register value is not required to be preserved across
295 * subroutine boundaries.
296 */
297 struct ureg_dst
298 ureg_DECL_local_temporary( struct ureg_program * );
299
300 /**
301 * Declare "size" continuous temporary registers.
302 */
303 struct ureg_dst
304 ureg_DECL_array_temporary( struct ureg_program *,
305 unsigned size,
306 boolean local );
307
308 void
309 ureg_release_temporary( struct ureg_program *ureg,
310 struct ureg_dst tmp );
311
312 struct ureg_dst
313 ureg_DECL_address( struct ureg_program * );
314
315 struct ureg_dst
316 ureg_DECL_predicate(struct ureg_program *);
317
318 /* Supply an index to the sampler declaration as this is the hook to
319 * the external pipe_sampler state. Users of this function probably
320 * don't want just any sampler, but a specific one which they've set
321 * up state for in the context.
322 */
323 struct ureg_src
324 ureg_DECL_sampler( struct ureg_program *,
325 unsigned index );
326
327 struct ureg_src
328 ureg_DECL_sampler_view(struct ureg_program *,
329 unsigned index,
330 unsigned target,
331 unsigned return_type_x,
332 unsigned return_type_y,
333 unsigned return_type_z,
334 unsigned return_type_w );
335
336
337 static INLINE struct ureg_src
338 ureg_imm4f( struct ureg_program *ureg,
339 float a, float b,
340 float c, float d)
341 {
342 float v[4];
343 v[0] = a;
344 v[1] = b;
345 v[2] = c;
346 v[3] = d;
347 return ureg_DECL_immediate( ureg, v, 4 );
348 }
349
350 static INLINE struct ureg_src
351 ureg_imm3f( struct ureg_program *ureg,
352 float a, float b,
353 float c)
354 {
355 float v[3];
356 v[0] = a;
357 v[1] = b;
358 v[2] = c;
359 return ureg_DECL_immediate( ureg, v, 3 );
360 }
361
362 static INLINE struct ureg_src
363 ureg_imm2f( struct ureg_program *ureg,
364 float a, float b)
365 {
366 float v[2];
367 v[0] = a;
368 v[1] = b;
369 return ureg_DECL_immediate( ureg, v, 2 );
370 }
371
372 static INLINE struct ureg_src
373 ureg_imm1f( struct ureg_program *ureg,
374 float a)
375 {
376 float v[1];
377 v[0] = a;
378 return ureg_DECL_immediate( ureg, v, 1 );
379 }
380
381 static INLINE struct ureg_src
382 ureg_imm4u( struct ureg_program *ureg,
383 unsigned a, unsigned b,
384 unsigned c, unsigned d)
385 {
386 unsigned v[4];
387 v[0] = a;
388 v[1] = b;
389 v[2] = c;
390 v[3] = d;
391 return ureg_DECL_immediate_uint( ureg, v, 4 );
392 }
393
394 static INLINE struct ureg_src
395 ureg_imm3u( struct ureg_program *ureg,
396 unsigned a, unsigned b,
397 unsigned c)
398 {
399 unsigned v[3];
400 v[0] = a;
401 v[1] = b;
402 v[2] = c;
403 return ureg_DECL_immediate_uint( ureg, v, 3 );
404 }
405
406 static INLINE struct ureg_src
407 ureg_imm2u( struct ureg_program *ureg,
408 unsigned a, unsigned b)
409 {
410 unsigned v[2];
411 v[0] = a;
412 v[1] = b;
413 return ureg_DECL_immediate_uint( ureg, v, 2 );
414 }
415
416 static INLINE struct ureg_src
417 ureg_imm1u( struct ureg_program *ureg,
418 unsigned a)
419 {
420 return ureg_DECL_immediate_uint( ureg, &a, 1 );
421 }
422
423 static INLINE struct ureg_src
424 ureg_imm4i( struct ureg_program *ureg,
425 int a, int b,
426 int c, int d)
427 {
428 int v[4];
429 v[0] = a;
430 v[1] = b;
431 v[2] = c;
432 v[3] = d;
433 return ureg_DECL_immediate_int( ureg, v, 4 );
434 }
435
436 static INLINE struct ureg_src
437 ureg_imm3i( struct ureg_program *ureg,
438 int a, int b,
439 int c)
440 {
441 int v[3];
442 v[0] = a;
443 v[1] = b;
444 v[2] = c;
445 return ureg_DECL_immediate_int( ureg, v, 3 );
446 }
447
448 static INLINE struct ureg_src
449 ureg_imm2i( struct ureg_program *ureg,
450 int a, int b)
451 {
452 int v[2];
453 v[0] = a;
454 v[1] = b;
455 return ureg_DECL_immediate_int( ureg, v, 2 );
456 }
457
458 static INLINE struct ureg_src
459 ureg_imm1i( struct ureg_program *ureg,
460 int a)
461 {
462 return ureg_DECL_immediate_int( ureg, &a, 1 );
463 }
464
465 /* Where the destination register has a valid file, but an empty
466 * writemask.
467 */
468 static INLINE boolean
469 ureg_dst_is_empty( struct ureg_dst dst )
470 {
471 return dst.File != TGSI_FILE_NULL &&
472 dst.WriteMask == 0;
473 }
474
475 /***********************************************************************
476 * Functions for patching up labels
477 */
478
479
480 /* Will return a number which can be used in a label to point to the
481 * next instruction to be emitted.
482 */
483 unsigned
484 ureg_get_instruction_number( struct ureg_program *ureg );
485
486
487 /* Patch a given label (expressed as a token number) to point to a
488 * given instruction (expressed as an instruction number).
489 *
490 * Labels are obtained from instruction emitters, eg ureg_CAL().
491 * Instruction numbers are obtained from ureg_get_instruction_number(),
492 * above.
493 */
494 void
495 ureg_fixup_label(struct ureg_program *ureg,
496 unsigned label_token,
497 unsigned instruction_number );
498
499
500 /* Generic instruction emitter. Use if you need to pass the opcode as
501 * a parameter, rather than using the emit_OP() variants below.
502 */
503 void
504 ureg_insn(struct ureg_program *ureg,
505 unsigned opcode,
506 const struct ureg_dst *dst,
507 unsigned nr_dst,
508 const struct ureg_src *src,
509 unsigned nr_src );
510
511
512 void
513 ureg_tex_insn(struct ureg_program *ureg,
514 unsigned opcode,
515 const struct ureg_dst *dst,
516 unsigned nr_dst,
517 unsigned target,
518 const struct tgsi_texture_offset *texoffsets,
519 unsigned nr_offset,
520 const struct ureg_src *src,
521 unsigned nr_src );
522
523
524 void
525 ureg_label_insn(struct ureg_program *ureg,
526 unsigned opcode,
527 const struct ureg_src *src,
528 unsigned nr_src,
529 unsigned *label);
530
531
532 /***********************************************************************
533 * Internal instruction helpers, don't call these directly:
534 */
535
536 struct ureg_emit_insn_result {
537 unsigned insn_token; /*< Used to fixup insn size. */
538 unsigned extended_token; /*< Used to set the Extended bit, usually the same as insn_token. */
539 };
540
541 struct ureg_emit_insn_result
542 ureg_emit_insn(struct ureg_program *ureg,
543 unsigned opcode,
544 boolean saturate,
545 boolean predicate,
546 boolean pred_negate,
547 unsigned pred_swizzle_x,
548 unsigned pred_swizzle_y,
549 unsigned pred_swizzle_z,
550 unsigned pred_swizzle_w,
551 unsigned num_dst,
552 unsigned num_src );
553
554 void
555 ureg_emit_label(struct ureg_program *ureg,
556 unsigned insn_token,
557 unsigned *label_token );
558
559 void
560 ureg_emit_texture(struct ureg_program *ureg,
561 unsigned insn_token,
562 unsigned target, unsigned num_offsets);
563
564 void
565 ureg_emit_texture_offset(struct ureg_program *ureg,
566 const struct tgsi_texture_offset *offset);
567
568 void
569 ureg_emit_dst( struct ureg_program *ureg,
570 struct ureg_dst dst );
571
572 void
573 ureg_emit_src( struct ureg_program *ureg,
574 struct ureg_src src );
575
576 void
577 ureg_fixup_insn_size(struct ureg_program *ureg,
578 unsigned insn );
579
580
581 #define OP00( op ) \
582 static INLINE void ureg_##op( struct ureg_program *ureg ) \
583 { \
584 unsigned opcode = TGSI_OPCODE_##op; \
585 struct ureg_emit_insn_result insn; \
586 insn = ureg_emit_insn(ureg, \
587 opcode, \
588 FALSE, \
589 FALSE, \
590 FALSE, \
591 TGSI_SWIZZLE_X, \
592 TGSI_SWIZZLE_Y, \
593 TGSI_SWIZZLE_Z, \
594 TGSI_SWIZZLE_W, \
595 0, \
596 0); \
597 ureg_fixup_insn_size( ureg, insn.insn_token ); \
598 }
599
600 #define OP01( op ) \
601 static INLINE void ureg_##op( struct ureg_program *ureg, \
602 struct ureg_src src ) \
603 { \
604 unsigned opcode = TGSI_OPCODE_##op; \
605 struct ureg_emit_insn_result insn; \
606 insn = ureg_emit_insn(ureg, \
607 opcode, \
608 FALSE, \
609 FALSE, \
610 FALSE, \
611 TGSI_SWIZZLE_X, \
612 TGSI_SWIZZLE_Y, \
613 TGSI_SWIZZLE_Z, \
614 TGSI_SWIZZLE_W, \
615 0, \
616 1); \
617 ureg_emit_src( ureg, src ); \
618 ureg_fixup_insn_size( ureg, insn.insn_token ); \
619 }
620
621 #define OP00_LBL( op ) \
622 static INLINE void ureg_##op( struct ureg_program *ureg, \
623 unsigned *label_token ) \
624 { \
625 unsigned opcode = TGSI_OPCODE_##op; \
626 struct ureg_emit_insn_result insn; \
627 insn = ureg_emit_insn(ureg, \
628 opcode, \
629 FALSE, \
630 FALSE, \
631 FALSE, \
632 TGSI_SWIZZLE_X, \
633 TGSI_SWIZZLE_Y, \
634 TGSI_SWIZZLE_Z, \
635 TGSI_SWIZZLE_W, \
636 0, \
637 0); \
638 ureg_emit_label( ureg, insn.extended_token, label_token ); \
639 ureg_fixup_insn_size( ureg, insn.insn_token ); \
640 }
641
642 #define OP01_LBL( op ) \
643 static INLINE void ureg_##op( struct ureg_program *ureg, \
644 struct ureg_src src, \
645 unsigned *label_token ) \
646 { \
647 unsigned opcode = TGSI_OPCODE_##op; \
648 struct ureg_emit_insn_result insn; \
649 insn = ureg_emit_insn(ureg, \
650 opcode, \
651 FALSE, \
652 FALSE, \
653 FALSE, \
654 TGSI_SWIZZLE_X, \
655 TGSI_SWIZZLE_Y, \
656 TGSI_SWIZZLE_Z, \
657 TGSI_SWIZZLE_W, \
658 0, \
659 1); \
660 ureg_emit_label( ureg, insn.extended_token, label_token ); \
661 ureg_emit_src( ureg, src ); \
662 ureg_fixup_insn_size( ureg, insn.insn_token ); \
663 }
664
665 #define OP10( op ) \
666 static INLINE void ureg_##op( struct ureg_program *ureg, \
667 struct ureg_dst dst ) \
668 { \
669 unsigned opcode = TGSI_OPCODE_##op; \
670 struct ureg_emit_insn_result insn; \
671 if (ureg_dst_is_empty(dst)) \
672 return; \
673 insn = ureg_emit_insn(ureg, \
674 opcode, \
675 dst.Saturate, \
676 dst.Predicate, \
677 dst.PredNegate, \
678 dst.PredSwizzleX, \
679 dst.PredSwizzleY, \
680 dst.PredSwizzleZ, \
681 dst.PredSwizzleW, \
682 1, \
683 0); \
684 ureg_emit_dst( ureg, dst ); \
685 ureg_fixup_insn_size( ureg, insn.insn_token ); \
686 }
687
688
689 #define OP11( op ) \
690 static INLINE void ureg_##op( struct ureg_program *ureg, \
691 struct ureg_dst dst, \
692 struct ureg_src src ) \
693 { \
694 unsigned opcode = TGSI_OPCODE_##op; \
695 struct ureg_emit_insn_result insn; \
696 if (ureg_dst_is_empty(dst)) \
697 return; \
698 insn = ureg_emit_insn(ureg, \
699 opcode, \
700 dst.Saturate, \
701 dst.Predicate, \
702 dst.PredNegate, \
703 dst.PredSwizzleX, \
704 dst.PredSwizzleY, \
705 dst.PredSwizzleZ, \
706 dst.PredSwizzleW, \
707 1, \
708 1); \
709 ureg_emit_dst( ureg, dst ); \
710 ureg_emit_src( ureg, src ); \
711 ureg_fixup_insn_size( ureg, insn.insn_token ); \
712 }
713
714 #define OP12( op ) \
715 static INLINE void ureg_##op( struct ureg_program *ureg, \
716 struct ureg_dst dst, \
717 struct ureg_src src0, \
718 struct ureg_src src1 ) \
719 { \
720 unsigned opcode = TGSI_OPCODE_##op; \
721 struct ureg_emit_insn_result insn; \
722 if (ureg_dst_is_empty(dst)) \
723 return; \
724 insn = ureg_emit_insn(ureg, \
725 opcode, \
726 dst.Saturate, \
727 dst.Predicate, \
728 dst.PredNegate, \
729 dst.PredSwizzleX, \
730 dst.PredSwizzleY, \
731 dst.PredSwizzleZ, \
732 dst.PredSwizzleW, \
733 1, \
734 2); \
735 ureg_emit_dst( ureg, dst ); \
736 ureg_emit_src( ureg, src0 ); \
737 ureg_emit_src( ureg, src1 ); \
738 ureg_fixup_insn_size( ureg, insn.insn_token ); \
739 }
740
741 #define OP12_TEX( op ) \
742 static INLINE void ureg_##op( struct ureg_program *ureg, \
743 struct ureg_dst dst, \
744 unsigned target, \
745 struct ureg_src src0, \
746 struct ureg_src src1 ) \
747 { \
748 unsigned opcode = TGSI_OPCODE_##op; \
749 struct ureg_emit_insn_result insn; \
750 if (ureg_dst_is_empty(dst)) \
751 return; \
752 insn = ureg_emit_insn(ureg, \
753 opcode, \
754 dst.Saturate, \
755 dst.Predicate, \
756 dst.PredNegate, \
757 dst.PredSwizzleX, \
758 dst.PredSwizzleY, \
759 dst.PredSwizzleZ, \
760 dst.PredSwizzleW, \
761 1, \
762 2); \
763 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
764 ureg_emit_dst( ureg, dst ); \
765 ureg_emit_src( ureg, src0 ); \
766 ureg_emit_src( ureg, src1 ); \
767 ureg_fixup_insn_size( ureg, insn.insn_token ); \
768 }
769
770 #define OP12_SAMPLE( op ) \
771 static INLINE void ureg_##op( struct ureg_program *ureg, \
772 struct ureg_dst dst, \
773 struct ureg_src src0, \
774 struct ureg_src src1 ) \
775 { \
776 unsigned opcode = TGSI_OPCODE_##op; \
777 unsigned target = TGSI_TEXTURE_UNKNOWN; \
778 struct ureg_emit_insn_result insn; \
779 if (ureg_dst_is_empty(dst)) \
780 return; \
781 insn = ureg_emit_insn(ureg, \
782 opcode, \
783 dst.Saturate, \
784 dst.Predicate, \
785 dst.PredNegate, \
786 dst.PredSwizzleX, \
787 dst.PredSwizzleY, \
788 dst.PredSwizzleZ, \
789 dst.PredSwizzleW, \
790 1, \
791 2); \
792 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
793 ureg_emit_dst( ureg, dst ); \
794 ureg_emit_src( ureg, src0 ); \
795 ureg_emit_src( ureg, src1 ); \
796 ureg_fixup_insn_size( ureg, insn.insn_token ); \
797 }
798
799 #define OP13( op ) \
800 static INLINE void ureg_##op( struct ureg_program *ureg, \
801 struct ureg_dst dst, \
802 struct ureg_src src0, \
803 struct ureg_src src1, \
804 struct ureg_src src2 ) \
805 { \
806 unsigned opcode = TGSI_OPCODE_##op; \
807 struct ureg_emit_insn_result insn; \
808 if (ureg_dst_is_empty(dst)) \
809 return; \
810 insn = ureg_emit_insn(ureg, \
811 opcode, \
812 dst.Saturate, \
813 dst.Predicate, \
814 dst.PredNegate, \
815 dst.PredSwizzleX, \
816 dst.PredSwizzleY, \
817 dst.PredSwizzleZ, \
818 dst.PredSwizzleW, \
819 1, \
820 3); \
821 ureg_emit_dst( ureg, dst ); \
822 ureg_emit_src( ureg, src0 ); \
823 ureg_emit_src( ureg, src1 ); \
824 ureg_emit_src( ureg, src2 ); \
825 ureg_fixup_insn_size( ureg, insn.insn_token ); \
826 }
827
828 #define OP13_SAMPLE( op ) \
829 static INLINE void ureg_##op( struct ureg_program *ureg, \
830 struct ureg_dst dst, \
831 struct ureg_src src0, \
832 struct ureg_src src1, \
833 struct ureg_src src2 ) \
834 { \
835 unsigned opcode = TGSI_OPCODE_##op; \
836 unsigned target = TGSI_TEXTURE_UNKNOWN; \
837 struct ureg_emit_insn_result insn; \
838 if (ureg_dst_is_empty(dst)) \
839 return; \
840 insn = ureg_emit_insn(ureg, \
841 opcode, \
842 dst.Saturate, \
843 dst.Predicate, \
844 dst.PredNegate, \
845 dst.PredSwizzleX, \
846 dst.PredSwizzleY, \
847 dst.PredSwizzleZ, \
848 dst.PredSwizzleW, \
849 1, \
850 3); \
851 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
852 ureg_emit_dst( ureg, dst ); \
853 ureg_emit_src( ureg, src0 ); \
854 ureg_emit_src( ureg, src1 ); \
855 ureg_emit_src( ureg, src2 ); \
856 ureg_fixup_insn_size( ureg, insn.insn_token ); \
857 }
858
859 #define OP14_TEX( op ) \
860 static INLINE void ureg_##op( struct ureg_program *ureg, \
861 struct ureg_dst dst, \
862 unsigned target, \
863 struct ureg_src src0, \
864 struct ureg_src src1, \
865 struct ureg_src src2, \
866 struct ureg_src src3 ) \
867 { \
868 unsigned opcode = TGSI_OPCODE_##op; \
869 struct ureg_emit_insn_result insn; \
870 if (ureg_dst_is_empty(dst)) \
871 return; \
872 insn = ureg_emit_insn(ureg, \
873 opcode, \
874 dst.Saturate, \
875 dst.Predicate, \
876 dst.PredNegate, \
877 dst.PredSwizzleX, \
878 dst.PredSwizzleY, \
879 dst.PredSwizzleZ, \
880 dst.PredSwizzleW, \
881 1, \
882 4); \
883 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
884 ureg_emit_dst( ureg, dst ); \
885 ureg_emit_src( ureg, src0 ); \
886 ureg_emit_src( ureg, src1 ); \
887 ureg_emit_src( ureg, src2 ); \
888 ureg_emit_src( ureg, src3 ); \
889 ureg_fixup_insn_size( ureg, insn.insn_token ); \
890 }
891
892 #define OP14_SAMPLE( op ) \
893 static INLINE void ureg_##op( struct ureg_program *ureg, \
894 struct ureg_dst dst, \
895 struct ureg_src src0, \
896 struct ureg_src src1, \
897 struct ureg_src src2, \
898 struct ureg_src src3 ) \
899 { \
900 unsigned opcode = TGSI_OPCODE_##op; \
901 unsigned target = TGSI_TEXTURE_UNKNOWN; \
902 struct ureg_emit_insn_result insn; \
903 if (ureg_dst_is_empty(dst)) \
904 return; \
905 insn = ureg_emit_insn(ureg, \
906 opcode, \
907 dst.Saturate, \
908 dst.Predicate, \
909 dst.PredNegate, \
910 dst.PredSwizzleX, \
911 dst.PredSwizzleY, \
912 dst.PredSwizzleZ, \
913 dst.PredSwizzleW, \
914 1, \
915 4); \
916 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
917 ureg_emit_dst( ureg, dst ); \
918 ureg_emit_src( ureg, src0 ); \
919 ureg_emit_src( ureg, src1 ); \
920 ureg_emit_src( ureg, src2 ); \
921 ureg_emit_src( ureg, src3 ); \
922 ureg_fixup_insn_size( ureg, insn.insn_token ); \
923 }
924
925
926 #define OP14( op ) \
927 static INLINE void ureg_##op( struct ureg_program *ureg, \
928 struct ureg_dst dst, \
929 struct ureg_src src0, \
930 struct ureg_src src1, \
931 struct ureg_src src2, \
932 struct ureg_src src3 ) \
933 { \
934 unsigned opcode = TGSI_OPCODE_##op; \
935 struct ureg_emit_insn_result insn; \
936 if (ureg_dst_is_empty(dst)) \
937 return; \
938 insn = ureg_emit_insn(ureg, \
939 opcode, \
940 dst.Saturate, \
941 dst.Predicate, \
942 dst.PredNegate, \
943 dst.PredSwizzleX, \
944 dst.PredSwizzleY, \
945 dst.PredSwizzleZ, \
946 dst.PredSwizzleW, \
947 1, \
948 4); \
949 ureg_emit_dst( ureg, dst ); \
950 ureg_emit_src( ureg, src0 ); \
951 ureg_emit_src( ureg, src1 ); \
952 ureg_emit_src( ureg, src2 ); \
953 ureg_emit_src( ureg, src3 ); \
954 ureg_fixup_insn_size( ureg, insn.insn_token ); \
955 }
956
957
958 #define OP15( op ) \
959 static INLINE void ureg_##op( struct ureg_program *ureg, \
960 struct ureg_dst dst, \
961 struct ureg_src src0, \
962 struct ureg_src src1, \
963 struct ureg_src src2, \
964 struct ureg_src src3, \
965 struct ureg_src src4 ) \
966 { \
967 unsigned opcode = TGSI_OPCODE_##op; \
968 struct ureg_emit_insn_result insn; \
969 if (ureg_dst_is_empty(dst)) \
970 return; \
971 insn = ureg_emit_insn(ureg, \
972 opcode, \
973 dst.Saturate, \
974 dst.Predicate, \
975 dst.PredNegate, \
976 dst.PredSwizzleX, \
977 dst.PredSwizzleY, \
978 dst.PredSwizzleZ, \
979 dst.PredSwizzleW, \
980 1, \
981 5); \
982 ureg_emit_dst( ureg, dst ); \
983 ureg_emit_src( ureg, src0 ); \
984 ureg_emit_src( ureg, src1 ); \
985 ureg_emit_src( ureg, src2 ); \
986 ureg_emit_src( ureg, src3 ); \
987 ureg_emit_src( ureg, src4 ); \
988 ureg_fixup_insn_size( ureg, insn.insn_token ); \
989 }
990
991 #define OP15_SAMPLE( op ) \
992 static INLINE void ureg_##op( struct ureg_program *ureg, \
993 struct ureg_dst dst, \
994 struct ureg_src src0, \
995 struct ureg_src src1, \
996 struct ureg_src src2, \
997 struct ureg_src src3, \
998 struct ureg_src src4 ) \
999 { \
1000 unsigned opcode = TGSI_OPCODE_##op; \
1001 unsigned target = TGSI_TEXTURE_UNKNOWN; \
1002 struct ureg_emit_insn_result insn; \
1003 if (ureg_dst_is_empty(dst)) \
1004 return; \
1005 insn = ureg_emit_insn(ureg, \
1006 opcode, \
1007 dst.Saturate, \
1008 dst.Predicate, \
1009 dst.PredNegate, \
1010 dst.PredSwizzleX, \
1011 dst.PredSwizzleY, \
1012 dst.PredSwizzleZ, \
1013 dst.PredSwizzleW, \
1014 1, \
1015 5); \
1016 ureg_emit_texture( ureg, insn.extended_token, target, 0 ); \
1017 ureg_emit_dst( ureg, dst ); \
1018 ureg_emit_src( ureg, src0 ); \
1019 ureg_emit_src( ureg, src1 ); \
1020 ureg_emit_src( ureg, src2 ); \
1021 ureg_emit_src( ureg, src3 ); \
1022 ureg_emit_src( ureg, src4 ); \
1023 ureg_fixup_insn_size( ureg, insn.insn_token ); \
1024 }
1025
1026 /* Use a template include to generate a correctly-typed ureg_OP()
1027 * function for each TGSI opcode:
1028 */
1029 #include "tgsi_opcode_tmp.h"
1030
1031
1032 /***********************************************************************
1033 * Inline helpers for manipulating register structs:
1034 */
1035 static INLINE struct ureg_src
1036 ureg_negate( struct ureg_src reg )
1037 {
1038 assert(reg.File != TGSI_FILE_NULL);
1039 reg.Negate ^= 1;
1040 return reg;
1041 }
1042
1043 static INLINE struct ureg_src
1044 ureg_abs( struct ureg_src reg )
1045 {
1046 assert(reg.File != TGSI_FILE_NULL);
1047 reg.Absolute = 1;
1048 reg.Negate = 0;
1049 return reg;
1050 }
1051
1052 static INLINE struct ureg_src
1053 ureg_swizzle( struct ureg_src reg,
1054 int x, int y, int z, int w )
1055 {
1056 unsigned swz = ( (reg.SwizzleX << 0) |
1057 (reg.SwizzleY << 2) |
1058 (reg.SwizzleZ << 4) |
1059 (reg.SwizzleW << 6));
1060
1061 assert(reg.File != TGSI_FILE_NULL);
1062 assert(x < 4);
1063 assert(y < 4);
1064 assert(z < 4);
1065 assert(w < 4);
1066
1067 reg.SwizzleX = (swz >> (x*2)) & 0x3;
1068 reg.SwizzleY = (swz >> (y*2)) & 0x3;
1069 reg.SwizzleZ = (swz >> (z*2)) & 0x3;
1070 reg.SwizzleW = (swz >> (w*2)) & 0x3;
1071 return reg;
1072 }
1073
1074 static INLINE struct ureg_src
1075 ureg_scalar( struct ureg_src reg, int x )
1076 {
1077 return ureg_swizzle(reg, x, x, x, x);
1078 }
1079
1080 static INLINE struct ureg_dst
1081 ureg_writemask( struct ureg_dst reg,
1082 unsigned writemask )
1083 {
1084 assert(reg.File != TGSI_FILE_NULL);
1085 reg.WriteMask &= writemask;
1086 return reg;
1087 }
1088
1089 static INLINE struct ureg_dst
1090 ureg_saturate( struct ureg_dst reg )
1091 {
1092 assert(reg.File != TGSI_FILE_NULL);
1093 reg.Saturate = 1;
1094 return reg;
1095 }
1096
1097 static INLINE struct ureg_dst
1098 ureg_predicate(struct ureg_dst reg,
1099 boolean negate,
1100 unsigned swizzle_x,
1101 unsigned swizzle_y,
1102 unsigned swizzle_z,
1103 unsigned swizzle_w)
1104 {
1105 assert(reg.File != TGSI_FILE_NULL);
1106 reg.Predicate = 1;
1107 reg.PredNegate = negate;
1108 reg.PredSwizzleX = swizzle_x;
1109 reg.PredSwizzleY = swizzle_y;
1110 reg.PredSwizzleZ = swizzle_z;
1111 reg.PredSwizzleW = swizzle_w;
1112 return reg;
1113 }
1114
1115 static INLINE struct ureg_dst
1116 ureg_dst_indirect( struct ureg_dst reg, struct ureg_src addr )
1117 {
1118 assert(reg.File != TGSI_FILE_NULL);
1119 assert(addr.File == TGSI_FILE_ADDRESS || addr.File == TGSI_FILE_TEMPORARY);
1120 reg.Indirect = 1;
1121 reg.IndirectFile = addr.File;
1122 reg.IndirectIndex = addr.Index;
1123 reg.IndirectSwizzle = addr.SwizzleX;
1124 return reg;
1125 }
1126
1127 static INLINE struct ureg_src
1128 ureg_src_indirect( struct ureg_src reg, struct ureg_src addr )
1129 {
1130 assert(reg.File != TGSI_FILE_NULL);
1131 assert(addr.File == TGSI_FILE_ADDRESS || addr.File == TGSI_FILE_TEMPORARY);
1132 reg.Indirect = 1;
1133 reg.IndirectFile = addr.File;
1134 reg.IndirectIndex = addr.Index;
1135 reg.IndirectSwizzle = addr.SwizzleX;
1136 return reg;
1137 }
1138
1139 static INLINE struct ureg_src
1140 ureg_src_dimension( struct ureg_src reg, int index )
1141 {
1142 assert(reg.File != TGSI_FILE_NULL);
1143 reg.Dimension = 1;
1144 reg.DimIndirect = 0;
1145 reg.DimensionIndex = index;
1146 return reg;
1147 }
1148
1149
1150 static INLINE struct ureg_src
1151 ureg_src_dimension_indirect( struct ureg_src reg, struct ureg_src addr,
1152 int index )
1153 {
1154 assert(reg.File != TGSI_FILE_NULL);
1155 reg.Dimension = 1;
1156 reg.DimIndirect = 1;
1157 reg.DimensionIndex = index;
1158 reg.DimIndFile = addr.File;
1159 reg.DimIndIndex = addr.Index;
1160 reg.DimIndSwizzle = addr.SwizzleX;
1161 return reg;
1162 }
1163
1164 static INLINE struct ureg_dst
1165 ureg_dst_array_offset( struct ureg_dst reg, int offset )
1166 {
1167 assert(reg.File == TGSI_FILE_TEMPORARY);
1168 reg.Index += offset;
1169 return reg;
1170 }
1171
1172 static INLINE struct ureg_dst
1173 ureg_dst( struct ureg_src src )
1174 {
1175 struct ureg_dst dst;
1176
1177 assert(!src.Indirect ||
1178 (src.IndirectFile == TGSI_FILE_ADDRESS ||
1179 src.IndirectFile == TGSI_FILE_TEMPORARY));
1180
1181 dst.File = src.File;
1182 dst.WriteMask = TGSI_WRITEMASK_XYZW;
1183 dst.IndirectFile = src.IndirectFile;
1184 dst.Indirect = src.Indirect;
1185 dst.IndirectIndex = src.IndirectIndex;
1186 dst.IndirectSwizzle = src.IndirectSwizzle;
1187 dst.Saturate = 0;
1188 dst.Predicate = 0;
1189 dst.PredNegate = 0;
1190 dst.PredSwizzleX = TGSI_SWIZZLE_X;
1191 dst.PredSwizzleY = TGSI_SWIZZLE_Y;
1192 dst.PredSwizzleZ = TGSI_SWIZZLE_Z;
1193 dst.PredSwizzleW = TGSI_SWIZZLE_W;
1194 dst.Index = src.Index;
1195 dst.ArrayID = src.ArrayID;
1196
1197 return dst;
1198 }
1199
1200 static INLINE struct ureg_src
1201 ureg_src_register(unsigned file,
1202 unsigned index)
1203 {
1204 struct ureg_src src;
1205
1206 src.File = file;
1207 src.SwizzleX = TGSI_SWIZZLE_X;
1208 src.SwizzleY = TGSI_SWIZZLE_Y;
1209 src.SwizzleZ = TGSI_SWIZZLE_Z;
1210 src.SwizzleW = TGSI_SWIZZLE_W;
1211 src.Indirect = 0;
1212 src.IndirectFile = TGSI_FILE_NULL;
1213 src.IndirectIndex = 0;
1214 src.IndirectSwizzle = 0;
1215 src.Absolute = 0;
1216 src.Index = index;
1217 src.Negate = 0;
1218 src.Dimension = 0;
1219 src.DimensionIndex = 0;
1220 src.DimIndirect = 0;
1221 src.DimIndFile = TGSI_FILE_NULL;
1222 src.DimIndIndex = 0;
1223 src.DimIndSwizzle = 0;
1224 src.ArrayID = 0;
1225
1226 return src;
1227 }
1228
1229 static INLINE struct ureg_src
1230 ureg_src( struct ureg_dst dst )
1231 {
1232 struct ureg_src src;
1233
1234 src.File = dst.File;
1235 src.SwizzleX = TGSI_SWIZZLE_X;
1236 src.SwizzleY = TGSI_SWIZZLE_Y;
1237 src.SwizzleZ = TGSI_SWIZZLE_Z;
1238 src.SwizzleW = TGSI_SWIZZLE_W;
1239 src.Indirect = dst.Indirect;
1240 src.IndirectFile = dst.IndirectFile;
1241 src.IndirectIndex = dst.IndirectIndex;
1242 src.IndirectSwizzle = dst.IndirectSwizzle;
1243 src.Absolute = 0;
1244 src.Index = dst.Index;
1245 src.Negate = 0;
1246 src.Dimension = 0;
1247 src.DimensionIndex = 0;
1248 src.DimIndirect = 0;
1249 src.DimIndFile = TGSI_FILE_NULL;
1250 src.DimIndIndex = 0;
1251 src.DimIndSwizzle = 0;
1252 src.ArrayID = dst.ArrayID;
1253
1254 return src;
1255 }
1256
1257
1258
1259 static INLINE struct ureg_dst
1260 ureg_dst_undef( void )
1261 {
1262 struct ureg_dst dst;
1263
1264 dst.File = TGSI_FILE_NULL;
1265 dst.WriteMask = 0;
1266 dst.Indirect = 0;
1267 dst.IndirectFile = TGSI_FILE_NULL;
1268 dst.IndirectIndex = 0;
1269 dst.IndirectSwizzle = 0;
1270 dst.Saturate = 0;
1271 dst.Predicate = 0;
1272 dst.PredNegate = 0;
1273 dst.PredSwizzleX = TGSI_SWIZZLE_X;
1274 dst.PredSwizzleY = TGSI_SWIZZLE_Y;
1275 dst.PredSwizzleZ = TGSI_SWIZZLE_Z;
1276 dst.PredSwizzleW = TGSI_SWIZZLE_W;
1277 dst.Index = 0;
1278 dst.ArrayID = 0;
1279
1280 return dst;
1281 }
1282
1283 static INLINE struct ureg_src
1284 ureg_src_undef( void )
1285 {
1286 struct ureg_src src;
1287
1288 src.File = TGSI_FILE_NULL;
1289 src.SwizzleX = 0;
1290 src.SwizzleY = 0;
1291 src.SwizzleZ = 0;
1292 src.SwizzleW = 0;
1293 src.Indirect = 0;
1294 src.IndirectFile = TGSI_FILE_NULL;
1295 src.IndirectIndex = 0;
1296 src.IndirectSwizzle = 0;
1297 src.Absolute = 0;
1298 src.Index = 0;
1299 src.Negate = 0;
1300 src.Dimension = 0;
1301 src.DimensionIndex = 0;
1302 src.DimIndirect = 0;
1303 src.DimIndFile = TGSI_FILE_NULL;
1304 src.DimIndIndex = 0;
1305 src.DimIndSwizzle = 0;
1306 src.ArrayID = 0;
1307
1308 return src;
1309 }
1310
1311 static INLINE boolean
1312 ureg_src_is_undef( struct ureg_src src )
1313 {
1314 return src.File == TGSI_FILE_NULL;
1315 }
1316
1317 static INLINE boolean
1318 ureg_dst_is_undef( struct ureg_dst dst )
1319 {
1320 return dst.File == TGSI_FILE_NULL;
1321 }
1322
1323
1324 #ifdef __cplusplus
1325 }
1326 #endif
1327
1328 #endif