tgsi: ureg_DECL_gs_input() accepts shader semantics.
[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
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 struct ureg_program;
39
40 /* Almost a tgsi_src_register, but we need to pull in the Absolute
41 * flag from the _ext token. Indirect flag always implies ADDR[0].
42 */
43 struct ureg_src
44 {
45 unsigned File : 4; /* TGSI_FILE_ */
46 unsigned SwizzleX : 2; /* TGSI_SWIZZLE_ */
47 unsigned SwizzleY : 2; /* TGSI_SWIZZLE_ */
48 unsigned SwizzleZ : 2; /* TGSI_SWIZZLE_ */
49 unsigned SwizzleW : 2; /* TGSI_SWIZZLE_ */
50 unsigned Indirect : 1; /* BOOL */
51 unsigned Dimension : 1; /* BOOL */
52 unsigned Absolute : 1; /* BOOL */
53 unsigned Negate : 1; /* BOOL */
54 int Index : 16; /* SINT */
55 unsigned IndirectFile : 4; /* TGSI_FILE_ */
56 int IndirectIndex : 16; /* SINT */
57 unsigned IndirectSwizzle : 2; /* TGSI_SWIZZLE_ */
58 int DimensionIndex : 16; /* SINT */
59 };
60
61 /* Very similar to a tgsi_dst_register, removing unsupported fields
62 * and adding a Saturate flag. It's easier to push saturate into the
63 * destination register than to try and create a _SAT varient of each
64 * instruction function.
65 */
66 struct ureg_dst
67 {
68 unsigned File : 4; /* TGSI_FILE_ */
69 unsigned WriteMask : 4; /* TGSI_WRITEMASK_ */
70 unsigned Indirect : 1; /* BOOL */
71 unsigned Saturate : 1; /* BOOL */
72 unsigned Predicate : 1;
73 unsigned PredNegate : 1; /* BOOL */
74 unsigned PredSwizzleX: 2; /* TGSI_SWIZZLE_ */
75 unsigned PredSwizzleY: 2; /* TGSI_SWIZZLE_ */
76 unsigned PredSwizzleZ: 2; /* TGSI_SWIZZLE_ */
77 unsigned PredSwizzleW: 2; /* TGSI_SWIZZLE_ */
78 int Index : 16; /* SINT */
79 int IndirectIndex : 16; /* SINT */
80 int IndirectSwizzle : 2; /* TGSI_SWIZZLE_ */
81 };
82
83 struct pipe_context;
84
85 struct ureg_program *
86 ureg_create( unsigned processor );
87
88 const struct tgsi_token *
89 ureg_finalize( struct ureg_program * );
90
91 /* Create and return a shader:
92 */
93 void *
94 ureg_create_shader( struct ureg_program *,
95 struct pipe_context *pipe );
96
97
98 /* Alternately, return the built token stream and hand ownership of
99 * that memory to the caller:
100 */
101 const struct tgsi_token *
102 ureg_get_tokens( struct ureg_program *ureg,
103 unsigned *nr_tokens );
104
105
106 void
107 ureg_destroy( struct ureg_program * );
108
109
110 /***********************************************************************
111 * Convenience routine:
112 */
113 static INLINE void *
114 ureg_create_shader_and_destroy( struct ureg_program *p,
115 struct pipe_context *pipe )
116 {
117 void *result = ureg_create_shader( p, pipe );
118 ureg_destroy( p );
119 return result;
120 }
121
122
123 /***********************************************************************
124 * Build shader properties:
125 */
126
127 void
128 ureg_property_gs_input_prim(struct ureg_program *ureg,
129 unsigned input_prim);
130
131 void
132 ureg_property_gs_output_prim(struct ureg_program *ureg,
133 unsigned output_prim);
134
135 void
136 ureg_property_gs_max_vertices(struct ureg_program *ureg,
137 unsigned max_vertices);
138
139 void
140 ureg_property_fs_coord_origin(struct ureg_program *ureg,
141 unsigned fs_coord_origin);
142
143 void
144 ureg_property_fs_coord_pixel_center(struct ureg_program *ureg,
145 unsigned fs_coord_pixel_center);
146
147 /***********************************************************************
148 * Build shader declarations:
149 */
150
151 struct ureg_src
152 ureg_DECL_fs_input( struct ureg_program *,
153 unsigned semantic_name,
154 unsigned semantic_index,
155 unsigned interp_mode );
156
157 struct ureg_src
158 ureg_DECL_vs_input( struct ureg_program *,
159 unsigned index );
160
161 struct ureg_src
162 ureg_DECL_gs_input(struct ureg_program *,
163 unsigned index,
164 unsigned semantic_name,
165 unsigned semantic_index);
166
167 struct ureg_src
168 ureg_DECL_system_value(struct ureg_program *,
169 unsigned index,
170 unsigned semantic_name,
171 unsigned semantic_index);
172
173 struct ureg_dst
174 ureg_DECL_output( struct ureg_program *,
175 unsigned semantic_name,
176 unsigned semantic_index );
177
178 struct ureg_src
179 ureg_DECL_immediate( struct ureg_program *,
180 const float *v,
181 unsigned nr );
182
183 struct ureg_src
184 ureg_DECL_immediate_uint( struct ureg_program *,
185 const unsigned *v,
186 unsigned nr );
187
188 struct ureg_src
189 ureg_DECL_immediate_block_uint( struct ureg_program *,
190 const unsigned *v,
191 unsigned nr );
192
193 struct ureg_src
194 ureg_DECL_immediate_int( struct ureg_program *,
195 const int *v,
196 unsigned nr );
197
198 void
199 ureg_DECL_constant2D(struct ureg_program *ureg,
200 unsigned first,
201 unsigned last,
202 unsigned index2D);
203
204 struct ureg_src
205 ureg_DECL_constant( struct ureg_program *,
206 unsigned index );
207
208 struct ureg_dst
209 ureg_DECL_temporary( struct ureg_program * );
210
211 void
212 ureg_release_temporary( struct ureg_program *ureg,
213 struct ureg_dst tmp );
214
215 struct ureg_dst
216 ureg_DECL_address( struct ureg_program * );
217
218 struct ureg_dst
219 ureg_DECL_loop( struct ureg_program * );
220
221 struct ureg_dst
222 ureg_DECL_predicate(struct ureg_program *);
223
224 /* Supply an index to the sampler declaration as this is the hook to
225 * the external pipe_sampler state. Users of this function probably
226 * don't want just any sampler, but a specific one which they've set
227 * up state for in the context.
228 */
229 struct ureg_src
230 ureg_DECL_sampler( struct ureg_program *,
231 unsigned index );
232
233
234 static INLINE struct ureg_src
235 ureg_imm4f( struct ureg_program *ureg,
236 float a, float b,
237 float c, float d)
238 {
239 float v[4];
240 v[0] = a;
241 v[1] = b;
242 v[2] = c;
243 v[3] = d;
244 return ureg_DECL_immediate( ureg, v, 4 );
245 }
246
247 static INLINE struct ureg_src
248 ureg_imm3f( struct ureg_program *ureg,
249 float a, float b,
250 float c)
251 {
252 float v[3];
253 v[0] = a;
254 v[1] = b;
255 v[2] = c;
256 return ureg_DECL_immediate( ureg, v, 3 );
257 }
258
259 static INLINE struct ureg_src
260 ureg_imm2f( struct ureg_program *ureg,
261 float a, float b)
262 {
263 float v[2];
264 v[0] = a;
265 v[1] = b;
266 return ureg_DECL_immediate( ureg, v, 2 );
267 }
268
269 static INLINE struct ureg_src
270 ureg_imm1f( struct ureg_program *ureg,
271 float a)
272 {
273 float v[1];
274 v[0] = a;
275 return ureg_DECL_immediate( ureg, v, 1 );
276 }
277
278 static INLINE struct ureg_src
279 ureg_imm4u( struct ureg_program *ureg,
280 unsigned a, unsigned b,
281 unsigned c, unsigned d)
282 {
283 unsigned v[4];
284 v[0] = a;
285 v[1] = b;
286 v[2] = c;
287 v[3] = d;
288 return ureg_DECL_immediate_uint( ureg, v, 4 );
289 }
290
291 static INLINE struct ureg_src
292 ureg_imm3u( struct ureg_program *ureg,
293 unsigned a, unsigned b,
294 unsigned c)
295 {
296 unsigned v[3];
297 v[0] = a;
298 v[1] = b;
299 v[2] = c;
300 return ureg_DECL_immediate_uint( ureg, v, 3 );
301 }
302
303 static INLINE struct ureg_src
304 ureg_imm2u( struct ureg_program *ureg,
305 unsigned a, unsigned b)
306 {
307 unsigned v[2];
308 v[0] = a;
309 v[1] = b;
310 return ureg_DECL_immediate_uint( ureg, v, 2 );
311 }
312
313 static INLINE struct ureg_src
314 ureg_imm1u( struct ureg_program *ureg,
315 unsigned a)
316 {
317 return ureg_DECL_immediate_uint( ureg, &a, 1 );
318 }
319
320 static INLINE struct ureg_src
321 ureg_imm4i( struct ureg_program *ureg,
322 int a, int b,
323 int c, int d)
324 {
325 int v[4];
326 v[0] = a;
327 v[1] = b;
328 v[2] = c;
329 v[3] = d;
330 return ureg_DECL_immediate_int( ureg, v, 4 );
331 }
332
333 static INLINE struct ureg_src
334 ureg_imm3i( struct ureg_program *ureg,
335 int a, int b,
336 int c)
337 {
338 int v[3];
339 v[0] = a;
340 v[1] = b;
341 v[2] = c;
342 return ureg_DECL_immediate_int( ureg, v, 3 );
343 }
344
345 static INLINE struct ureg_src
346 ureg_imm2i( struct ureg_program *ureg,
347 int a, int b)
348 {
349 int v[2];
350 v[0] = a;
351 v[1] = b;
352 return ureg_DECL_immediate_int( ureg, v, 2 );
353 }
354
355 static INLINE struct ureg_src
356 ureg_imm1i( struct ureg_program *ureg,
357 int a)
358 {
359 return ureg_DECL_immediate_int( ureg, &a, 1 );
360 }
361
362 /***********************************************************************
363 * Functions for patching up labels
364 */
365
366
367 /* Will return a number which can be used in a label to point to the
368 * next instruction to be emitted.
369 */
370 unsigned
371 ureg_get_instruction_number( struct ureg_program *ureg );
372
373
374 /* Patch a given label (expressed as a token number) to point to a
375 * given instruction (expressed as an instruction number).
376 *
377 * Labels are obtained from instruction emitters, eg ureg_CAL().
378 * Instruction numbers are obtained from ureg_get_instruction_number(),
379 * above.
380 */
381 void
382 ureg_fixup_label(struct ureg_program *ureg,
383 unsigned label_token,
384 unsigned instruction_number );
385
386
387 /* Generic instruction emitter. Use if you need to pass the opcode as
388 * a parameter, rather than using the emit_OP() varients below.
389 */
390 void
391 ureg_insn(struct ureg_program *ureg,
392 unsigned opcode,
393 const struct ureg_dst *dst,
394 unsigned nr_dst,
395 const struct ureg_src *src,
396 unsigned nr_src );
397
398
399 void
400 ureg_tex_insn(struct ureg_program *ureg,
401 unsigned opcode,
402 const struct ureg_dst *dst,
403 unsigned nr_dst,
404 unsigned target,
405 const struct ureg_src *src,
406 unsigned nr_src );
407
408
409 void
410 ureg_label_insn(struct ureg_program *ureg,
411 unsigned opcode,
412 const struct ureg_src *src,
413 unsigned nr_src,
414 unsigned *label);
415
416
417 /***********************************************************************
418 * Internal instruction helpers, don't call these directly:
419 */
420
421 struct ureg_emit_insn_result {
422 unsigned insn_token; /*< Used to fixup insn size. */
423 unsigned extended_token; /*< Used to set the Extended bit, usually the same as insn_token. */
424 };
425
426 struct ureg_emit_insn_result
427 ureg_emit_insn(struct ureg_program *ureg,
428 unsigned opcode,
429 boolean saturate,
430 boolean predicate,
431 boolean pred_negate,
432 unsigned pred_swizzle_x,
433 unsigned pred_swizzle_y,
434 unsigned pred_swizzle_z,
435 unsigned pred_swizzle_w,
436 unsigned num_dst,
437 unsigned num_src );
438
439 void
440 ureg_emit_label(struct ureg_program *ureg,
441 unsigned insn_token,
442 unsigned *label_token );
443
444 void
445 ureg_emit_texture(struct ureg_program *ureg,
446 unsigned insn_token,
447 unsigned target );
448
449 void
450 ureg_emit_dst( struct ureg_program *ureg,
451 struct ureg_dst dst );
452
453 void
454 ureg_emit_src( struct ureg_program *ureg,
455 struct ureg_src src );
456
457 void
458 ureg_fixup_insn_size(struct ureg_program *ureg,
459 unsigned insn );
460
461
462 #define OP00( op ) \
463 static INLINE void ureg_##op( struct ureg_program *ureg ) \
464 { \
465 unsigned opcode = TGSI_OPCODE_##op; \
466 unsigned insn = ureg_emit_insn(ureg, \
467 opcode, \
468 FALSE, \
469 FALSE, \
470 FALSE, \
471 TGSI_SWIZZLE_X, \
472 TGSI_SWIZZLE_Y, \
473 TGSI_SWIZZLE_Z, \
474 TGSI_SWIZZLE_W, \
475 0, \
476 0).insn_token; \
477 ureg_fixup_insn_size( ureg, insn ); \
478 }
479
480 #define OP01( op ) \
481 static INLINE void ureg_##op( struct ureg_program *ureg, \
482 struct ureg_src src ) \
483 { \
484 unsigned opcode = TGSI_OPCODE_##op; \
485 unsigned insn = ureg_emit_insn(ureg, \
486 opcode, \
487 FALSE, \
488 FALSE, \
489 FALSE, \
490 TGSI_SWIZZLE_X, \
491 TGSI_SWIZZLE_Y, \
492 TGSI_SWIZZLE_Z, \
493 TGSI_SWIZZLE_W, \
494 0, \
495 1).insn_token; \
496 ureg_emit_src( ureg, src ); \
497 ureg_fixup_insn_size( ureg, insn ); \
498 }
499
500 #define OP00_LBL( op ) \
501 static INLINE void ureg_##op( struct ureg_program *ureg, \
502 unsigned *label_token ) \
503 { \
504 unsigned opcode = TGSI_OPCODE_##op; \
505 struct ureg_emit_insn_result insn; \
506 insn = ureg_emit_insn(ureg, \
507 opcode, \
508 FALSE, \
509 FALSE, \
510 FALSE, \
511 TGSI_SWIZZLE_X, \
512 TGSI_SWIZZLE_Y, \
513 TGSI_SWIZZLE_Z, \
514 TGSI_SWIZZLE_W, \
515 0, \
516 0); \
517 ureg_emit_label( ureg, insn.extended_token, label_token ); \
518 ureg_fixup_insn_size( ureg, insn.insn_token ); \
519 }
520
521 #define OP01_LBL( op ) \
522 static INLINE void ureg_##op( struct ureg_program *ureg, \
523 struct ureg_src src, \
524 unsigned *label_token ) \
525 { \
526 unsigned opcode = TGSI_OPCODE_##op; \
527 struct ureg_emit_insn_result insn; \
528 insn = ureg_emit_insn(ureg, \
529 opcode, \
530 FALSE, \
531 FALSE, \
532 FALSE, \
533 TGSI_SWIZZLE_X, \
534 TGSI_SWIZZLE_Y, \
535 TGSI_SWIZZLE_Z, \
536 TGSI_SWIZZLE_W, \
537 0, \
538 1); \
539 ureg_emit_label( ureg, insn.extended_token, label_token ); \
540 ureg_emit_src( ureg, src ); \
541 ureg_fixup_insn_size( ureg, insn.insn_token ); \
542 }
543
544 #define OP10( op ) \
545 static INLINE void ureg_##op( struct ureg_program *ureg, \
546 struct ureg_dst dst ) \
547 { \
548 unsigned opcode = TGSI_OPCODE_##op; \
549 unsigned insn = ureg_emit_insn(ureg, \
550 opcode, \
551 dst.Saturate, \
552 dst.Predicate, \
553 dst.PredNegate, \
554 dst.PredSwizzleX, \
555 dst.PredSwizzleY, \
556 dst.PredSwizzleZ, \
557 dst.PredSwizzleW, \
558 1, \
559 0).insn_token; \
560 ureg_emit_dst( ureg, dst ); \
561 ureg_fixup_insn_size( ureg, insn ); \
562 }
563
564
565 #define OP11( op ) \
566 static INLINE void ureg_##op( struct ureg_program *ureg, \
567 struct ureg_dst dst, \
568 struct ureg_src src ) \
569 { \
570 unsigned opcode = TGSI_OPCODE_##op; \
571 unsigned insn = ureg_emit_insn(ureg, \
572 opcode, \
573 dst.Saturate, \
574 dst.Predicate, \
575 dst.PredNegate, \
576 dst.PredSwizzleX, \
577 dst.PredSwizzleY, \
578 dst.PredSwizzleZ, \
579 dst.PredSwizzleW, \
580 1, \
581 1).insn_token; \
582 ureg_emit_dst( ureg, dst ); \
583 ureg_emit_src( ureg, src ); \
584 ureg_fixup_insn_size( ureg, insn ); \
585 }
586
587 #define OP12( op ) \
588 static INLINE void ureg_##op( struct ureg_program *ureg, \
589 struct ureg_dst dst, \
590 struct ureg_src src0, \
591 struct ureg_src src1 ) \
592 { \
593 unsigned opcode = TGSI_OPCODE_##op; \
594 unsigned insn = ureg_emit_insn(ureg, \
595 opcode, \
596 dst.Saturate, \
597 dst.Predicate, \
598 dst.PredNegate, \
599 dst.PredSwizzleX, \
600 dst.PredSwizzleY, \
601 dst.PredSwizzleZ, \
602 dst.PredSwizzleW, \
603 1, \
604 2).insn_token; \
605 ureg_emit_dst( ureg, dst ); \
606 ureg_emit_src( ureg, src0 ); \
607 ureg_emit_src( ureg, src1 ); \
608 ureg_fixup_insn_size( ureg, insn ); \
609 }
610
611 #define OP12_TEX( op ) \
612 static INLINE void ureg_##op( struct ureg_program *ureg, \
613 struct ureg_dst dst, \
614 unsigned target, \
615 struct ureg_src src0, \
616 struct ureg_src src1 ) \
617 { \
618 unsigned opcode = TGSI_OPCODE_##op; \
619 struct ureg_emit_insn_result insn; \
620 insn = ureg_emit_insn(ureg, \
621 opcode, \
622 dst.Saturate, \
623 dst.Predicate, \
624 dst.PredNegate, \
625 dst.PredSwizzleX, \
626 dst.PredSwizzleY, \
627 dst.PredSwizzleZ, \
628 dst.PredSwizzleW, \
629 1, \
630 2); \
631 ureg_emit_texture( ureg, insn.extended_token, target ); \
632 ureg_emit_dst( ureg, dst ); \
633 ureg_emit_src( ureg, src0 ); \
634 ureg_emit_src( ureg, src1 ); \
635 ureg_fixup_insn_size( ureg, insn.insn_token ); \
636 }
637
638 #define OP13( op ) \
639 static INLINE void ureg_##op( struct ureg_program *ureg, \
640 struct ureg_dst dst, \
641 struct ureg_src src0, \
642 struct ureg_src src1, \
643 struct ureg_src src2 ) \
644 { \
645 unsigned opcode = TGSI_OPCODE_##op; \
646 unsigned insn = ureg_emit_insn(ureg, \
647 opcode, \
648 dst.Saturate, \
649 dst.Predicate, \
650 dst.PredNegate, \
651 dst.PredSwizzleX, \
652 dst.PredSwizzleY, \
653 dst.PredSwizzleZ, \
654 dst.PredSwizzleW, \
655 1, \
656 3).insn_token; \
657 ureg_emit_dst( ureg, dst ); \
658 ureg_emit_src( ureg, src0 ); \
659 ureg_emit_src( ureg, src1 ); \
660 ureg_emit_src( ureg, src2 ); \
661 ureg_fixup_insn_size( ureg, insn ); \
662 }
663
664 #define OP14_TEX( op ) \
665 static INLINE void ureg_##op( struct ureg_program *ureg, \
666 struct ureg_dst dst, \
667 unsigned target, \
668 struct ureg_src src0, \
669 struct ureg_src src1, \
670 struct ureg_src src2, \
671 struct ureg_src src3 ) \
672 { \
673 unsigned opcode = TGSI_OPCODE_##op; \
674 struct ureg_emit_insn_result insn; \
675 insn = ureg_emit_insn(ureg, \
676 opcode, \
677 dst.Saturate, \
678 dst.Predicate, \
679 dst.PredNegate, \
680 dst.PredSwizzleX, \
681 dst.PredSwizzleY, \
682 dst.PredSwizzleZ, \
683 dst.PredSwizzleW, \
684 1, \
685 4); \
686 ureg_emit_texture( ureg, insn.extended_token, target ); \
687 ureg_emit_dst( ureg, dst ); \
688 ureg_emit_src( ureg, src0 ); \
689 ureg_emit_src( ureg, src1 ); \
690 ureg_emit_src( ureg, src2 ); \
691 ureg_emit_src( ureg, src3 ); \
692 ureg_fixup_insn_size( ureg, insn.insn_token ); \
693 }
694
695
696 /* Use a template include to generate a correctly-typed ureg_OP()
697 * function for each TGSI opcode:
698 */
699 #include "tgsi_opcode_tmp.h"
700
701
702 /***********************************************************************
703 * Inline helpers for manipulating register structs:
704 */
705 static INLINE struct ureg_src
706 ureg_negate( struct ureg_src reg )
707 {
708 assert(reg.File != TGSI_FILE_NULL);
709 reg.Negate ^= 1;
710 return reg;
711 }
712
713 static INLINE struct ureg_src
714 ureg_abs( struct ureg_src reg )
715 {
716 assert(reg.File != TGSI_FILE_NULL);
717 reg.Absolute = 1;
718 reg.Negate = 0;
719 return reg;
720 }
721
722 static INLINE struct ureg_src
723 ureg_swizzle( struct ureg_src reg,
724 int x, int y, int z, int w )
725 {
726 unsigned swz = ( (reg.SwizzleX << 0) |
727 (reg.SwizzleY << 2) |
728 (reg.SwizzleZ << 4) |
729 (reg.SwizzleW << 6));
730
731 assert(reg.File != TGSI_FILE_NULL);
732 assert(x < 4);
733 assert(y < 4);
734 assert(z < 4);
735 assert(w < 4);
736
737 reg.SwizzleX = (swz >> (x*2)) & 0x3;
738 reg.SwizzleY = (swz >> (y*2)) & 0x3;
739 reg.SwizzleZ = (swz >> (z*2)) & 0x3;
740 reg.SwizzleW = (swz >> (w*2)) & 0x3;
741 return reg;
742 }
743
744 static INLINE struct ureg_src
745 ureg_scalar( struct ureg_src reg, int x )
746 {
747 return ureg_swizzle(reg, x, x, x, x);
748 }
749
750 static INLINE struct ureg_dst
751 ureg_writemask( struct ureg_dst reg,
752 unsigned writemask )
753 {
754 assert(reg.File != TGSI_FILE_NULL);
755 reg.WriteMask &= writemask;
756 return reg;
757 }
758
759 static INLINE struct ureg_dst
760 ureg_saturate( struct ureg_dst reg )
761 {
762 assert(reg.File != TGSI_FILE_NULL);
763 reg.Saturate = 1;
764 return reg;
765 }
766
767 static INLINE struct ureg_dst
768 ureg_predicate(struct ureg_dst reg,
769 boolean negate,
770 unsigned swizzle_x,
771 unsigned swizzle_y,
772 unsigned swizzle_z,
773 unsigned swizzle_w)
774 {
775 assert(reg.File != TGSI_FILE_NULL);
776 reg.Predicate = 1;
777 reg.PredNegate = negate;
778 reg.PredSwizzleX = swizzle_x;
779 reg.PredSwizzleY = swizzle_y;
780 reg.PredSwizzleZ = swizzle_z;
781 reg.PredSwizzleW = swizzle_w;
782 return reg;
783 }
784
785 static INLINE struct ureg_dst
786 ureg_dst_indirect( struct ureg_dst reg, struct ureg_src addr )
787 {
788 assert(reg.File != TGSI_FILE_NULL);
789 assert(addr.File == TGSI_FILE_ADDRESS);
790 reg.Indirect = 1;
791 reg.IndirectIndex = addr.Index;
792 reg.IndirectSwizzle = addr.SwizzleX;
793 return reg;
794 }
795
796 static INLINE struct ureg_src
797 ureg_src_indirect( struct ureg_src reg, struct ureg_src addr )
798 {
799 assert(reg.File != TGSI_FILE_NULL);
800 assert(addr.File == TGSI_FILE_ADDRESS || addr.File == TGSI_FILE_TEMPORARY);
801 reg.Indirect = 1;
802 reg.IndirectFile = addr.File;
803 reg.IndirectIndex = addr.Index;
804 reg.IndirectSwizzle = addr.SwizzleX;
805 return reg;
806 }
807
808 static INLINE struct ureg_src
809 ureg_src_dimension( struct ureg_src reg, int index )
810 {
811 assert(reg.File != TGSI_FILE_NULL);
812 reg.Dimension = 1;
813 reg.DimensionIndex = index;
814 return reg;
815 }
816
817 static INLINE struct ureg_dst
818 ureg_dst( struct ureg_src src )
819 {
820 struct ureg_dst dst;
821
822 assert(!src.Indirect || src.IndirectFile == TGSI_FILE_ADDRESS);
823
824 dst.File = src.File;
825 dst.WriteMask = TGSI_WRITEMASK_XYZW;
826 dst.Indirect = src.Indirect;
827 dst.IndirectIndex = src.IndirectIndex;
828 dst.IndirectSwizzle = src.IndirectSwizzle;
829 dst.Saturate = 0;
830 dst.Predicate = 0;
831 dst.PredNegate = 0;
832 dst.PredSwizzleX = TGSI_SWIZZLE_X;
833 dst.PredSwizzleY = TGSI_SWIZZLE_Y;
834 dst.PredSwizzleZ = TGSI_SWIZZLE_Z;
835 dst.PredSwizzleW = TGSI_SWIZZLE_W;
836 dst.Index = src.Index;
837
838 return dst;
839 }
840
841 static INLINE struct ureg_src
842 ureg_src_register(unsigned file,
843 unsigned index)
844 {
845 struct ureg_src src;
846
847 src.File = file;
848 src.SwizzleX = TGSI_SWIZZLE_X;
849 src.SwizzleY = TGSI_SWIZZLE_Y;
850 src.SwizzleZ = TGSI_SWIZZLE_Z;
851 src.SwizzleW = TGSI_SWIZZLE_W;
852 src.Indirect = 0;
853 src.IndirectFile = TGSI_FILE_NULL;
854 src.IndirectIndex = 0;
855 src.IndirectSwizzle = 0;
856 src.Absolute = 0;
857 src.Index = index;
858 src.Negate = 0;
859 src.Dimension = 0;
860 src.DimensionIndex = 0;
861
862 return src;
863 }
864
865 static INLINE struct ureg_src
866 ureg_src( struct ureg_dst dst )
867 {
868 struct ureg_src src;
869
870 src.File = dst.File;
871 src.SwizzleX = TGSI_SWIZZLE_X;
872 src.SwizzleY = TGSI_SWIZZLE_Y;
873 src.SwizzleZ = TGSI_SWIZZLE_Z;
874 src.SwizzleW = TGSI_SWIZZLE_W;
875 src.Indirect = dst.Indirect;
876 src.IndirectFile = TGSI_FILE_ADDRESS;
877 src.IndirectIndex = dst.IndirectIndex;
878 src.IndirectSwizzle = dst.IndirectSwizzle;
879 src.Absolute = 0;
880 src.Index = dst.Index;
881 src.Negate = 0;
882 src.Dimension = 0;
883 src.DimensionIndex = 0;
884
885 return src;
886 }
887
888
889
890 static INLINE struct ureg_dst
891 ureg_dst_undef( void )
892 {
893 struct ureg_dst dst;
894
895 dst.File = TGSI_FILE_NULL;
896 dst.WriteMask = 0;
897 dst.Indirect = 0;
898 dst.IndirectIndex = 0;
899 dst.IndirectSwizzle = 0;
900 dst.Saturate = 0;
901 dst.Predicate = 0;
902 dst.PredNegate = 0;
903 dst.PredSwizzleX = TGSI_SWIZZLE_X;
904 dst.PredSwizzleY = TGSI_SWIZZLE_Y;
905 dst.PredSwizzleZ = TGSI_SWIZZLE_Z;
906 dst.PredSwizzleW = TGSI_SWIZZLE_W;
907 dst.Index = 0;
908
909 return dst;
910 }
911
912 static INLINE struct ureg_src
913 ureg_src_undef( void )
914 {
915 struct ureg_src src;
916
917 src.File = TGSI_FILE_NULL;
918 src.SwizzleX = 0;
919 src.SwizzleY = 0;
920 src.SwizzleZ = 0;
921 src.SwizzleW = 0;
922 src.Indirect = 0;
923 src.IndirectFile = TGSI_FILE_NULL;
924 src.IndirectIndex = 0;
925 src.IndirectSwizzle = 0;
926 src.Absolute = 0;
927 src.Index = 0;
928 src.Negate = 0;
929 src.Dimension = 0;
930 src.DimensionIndex = 0;
931
932 return src;
933 }
934
935 static INLINE boolean
936 ureg_src_is_undef( struct ureg_src src )
937 {
938 return src.File == TGSI_FILE_NULL;
939 }
940
941 static INLINE boolean
942 ureg_dst_is_undef( struct ureg_dst dst )
943 {
944 return dst.File == TGSI_FILE_NULL;
945 }
946
947
948 #ifdef __cplusplus
949 }
950 #endif
951
952 #endif