Merge remote branch 'origin/mesa_7_6_branch'
[mesa.git] / src / gallium / auxiliary / tgsi / tgsi_build.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 #include "util/u_debug.h"
29 #include "pipe/p_shader_tokens.h"
30 #include "tgsi_build.h"
31 #include "tgsi_parse.h"
32
33 /*
34 * version
35 */
36
37 struct tgsi_version
38 tgsi_build_version( void )
39 {
40 struct tgsi_version version;
41
42 version.MajorVersion = 1;
43 version.MinorVersion = 1;
44 version.Padding = 0;
45
46 return version;
47 }
48
49 /*
50 * header
51 */
52
53 struct tgsi_header
54 tgsi_build_header( void )
55 {
56 struct tgsi_header header;
57
58 header.HeaderSize = 1;
59 header.BodySize = 0;
60
61 return header;
62 }
63
64 static void
65 header_headersize_grow( struct tgsi_header *header )
66 {
67 assert( header->HeaderSize < 0xFF );
68 assert( header->BodySize == 0 );
69
70 header->HeaderSize++;
71 }
72
73 static void
74 header_bodysize_grow( struct tgsi_header *header )
75 {
76 assert( header->BodySize < 0xFFFFFF );
77
78 header->BodySize++;
79 }
80
81 struct tgsi_processor
82 tgsi_default_processor( void )
83 {
84 struct tgsi_processor processor;
85
86 processor.Processor = TGSI_PROCESSOR_FRAGMENT;
87 processor.Padding = 0;
88
89 return processor;
90 }
91
92 struct tgsi_processor
93 tgsi_build_processor(
94 unsigned type,
95 struct tgsi_header *header )
96 {
97 struct tgsi_processor processor;
98
99 processor = tgsi_default_processor();
100 processor.Processor = type;
101
102 header_headersize_grow( header );
103
104 return processor;
105 }
106
107 /*
108 * declaration
109 */
110
111 struct tgsi_declaration
112 tgsi_default_declaration( void )
113 {
114 struct tgsi_declaration declaration;
115
116 declaration.Type = TGSI_TOKEN_TYPE_DECLARATION;
117 declaration.NrTokens = 1;
118 declaration.File = TGSI_FILE_NULL;
119 declaration.UsageMask = TGSI_WRITEMASK_XYZW;
120 declaration.Interpolate = TGSI_INTERPOLATE_CONSTANT;
121 declaration.Semantic = 0;
122 declaration.Centroid = 0;
123 declaration.Invariant = 0;
124 declaration.Padding = 0;
125 declaration.Extended = 0;
126
127 return declaration;
128 }
129
130 struct tgsi_declaration
131 tgsi_build_declaration(
132 unsigned file,
133 unsigned usage_mask,
134 unsigned interpolate,
135 unsigned semantic,
136 unsigned centroid,
137 unsigned invariant,
138 struct tgsi_header *header )
139 {
140 struct tgsi_declaration declaration;
141
142 assert( file < TGSI_FILE_COUNT );
143 assert( interpolate < TGSI_INTERPOLATE_COUNT );
144
145 declaration = tgsi_default_declaration();
146 declaration.File = file;
147 declaration.UsageMask = usage_mask;
148 declaration.Interpolate = interpolate;
149 declaration.Semantic = semantic;
150 declaration.Centroid = centroid;
151 declaration.Invariant = invariant;
152
153 header_bodysize_grow( header );
154
155 return declaration;
156 }
157
158 static void
159 declaration_grow(
160 struct tgsi_declaration *declaration,
161 struct tgsi_header *header )
162 {
163 assert( declaration->NrTokens < 0xFF );
164
165 declaration->NrTokens++;
166
167 header_bodysize_grow( header );
168 }
169
170 struct tgsi_full_declaration
171 tgsi_default_full_declaration( void )
172 {
173 struct tgsi_full_declaration full_declaration;
174
175 full_declaration.Declaration = tgsi_default_declaration();
176 full_declaration.DeclarationRange = tgsi_default_declaration_range();
177 full_declaration.Semantic = tgsi_default_declaration_semantic();
178
179 return full_declaration;
180 }
181
182 unsigned
183 tgsi_build_full_declaration(
184 const struct tgsi_full_declaration *full_decl,
185 struct tgsi_token *tokens,
186 struct tgsi_header *header,
187 unsigned maxsize )
188 {
189 unsigned size = 0;
190 struct tgsi_declaration *declaration;
191 struct tgsi_declaration_range *dr;
192
193 if( maxsize <= size )
194 return 0;
195 declaration = (struct tgsi_declaration *) &tokens[size];
196 size++;
197
198 *declaration = tgsi_build_declaration(
199 full_decl->Declaration.File,
200 full_decl->Declaration.UsageMask,
201 full_decl->Declaration.Interpolate,
202 full_decl->Declaration.Semantic,
203 full_decl->Declaration.Centroid,
204 full_decl->Declaration.Invariant,
205 header );
206
207 if (maxsize <= size)
208 return 0;
209 dr = (struct tgsi_declaration_range *) &tokens[size];
210 size++;
211
212 *dr = tgsi_build_declaration_range(
213 full_decl->DeclarationRange.First,
214 full_decl->DeclarationRange.Last,
215 declaration,
216 header );
217
218 if( full_decl->Declaration.Semantic ) {
219 struct tgsi_declaration_semantic *ds;
220
221 if( maxsize <= size )
222 return 0;
223 ds = (struct tgsi_declaration_semantic *) &tokens[size];
224 size++;
225
226 *ds = tgsi_build_declaration_semantic(
227 full_decl->Semantic.SemanticName,
228 full_decl->Semantic.SemanticIndex,
229 declaration,
230 header );
231 }
232
233 return size;
234 }
235
236 struct tgsi_declaration_range
237 tgsi_default_declaration_range( void )
238 {
239 struct tgsi_declaration_range dr;
240
241 dr.First = 0;
242 dr.Last = 0;
243
244 return dr;
245 }
246
247 struct tgsi_declaration_range
248 tgsi_build_declaration_range(
249 unsigned first,
250 unsigned last,
251 struct tgsi_declaration *declaration,
252 struct tgsi_header *header )
253 {
254 struct tgsi_declaration_range declaration_range;
255
256 assert( last >= first );
257 assert( last <= 0xFFFF );
258
259 declaration_range = tgsi_default_declaration_range();
260 declaration_range.First = first;
261 declaration_range.Last = last;
262
263 declaration_grow( declaration, header );
264
265 return declaration_range;
266 }
267
268 struct tgsi_declaration_semantic
269 tgsi_default_declaration_semantic( void )
270 {
271 struct tgsi_declaration_semantic ds;
272
273 ds.SemanticName = TGSI_SEMANTIC_POSITION;
274 ds.SemanticIndex = 0;
275 ds.Padding = 0;
276
277 return ds;
278 }
279
280 struct tgsi_declaration_semantic
281 tgsi_build_declaration_semantic(
282 unsigned semantic_name,
283 unsigned semantic_index,
284 struct tgsi_declaration *declaration,
285 struct tgsi_header *header )
286 {
287 struct tgsi_declaration_semantic ds;
288
289 assert( semantic_name <= TGSI_SEMANTIC_COUNT );
290 assert( semantic_index <= 0xFFFF );
291
292 ds = tgsi_default_declaration_semantic();
293 ds.SemanticName = semantic_name;
294 ds.SemanticIndex = semantic_index;
295
296 declaration_grow( declaration, header );
297
298 return ds;
299 }
300
301 /*
302 * immediate
303 */
304
305 struct tgsi_immediate
306 tgsi_default_immediate( void )
307 {
308 struct tgsi_immediate immediate;
309
310 immediate.Type = TGSI_TOKEN_TYPE_IMMEDIATE;
311 immediate.NrTokens = 1;
312 immediate.DataType = TGSI_IMM_FLOAT32;
313 immediate.Padding = 0;
314 immediate.Extended = 0;
315
316 return immediate;
317 }
318
319 struct tgsi_immediate
320 tgsi_build_immediate(
321 struct tgsi_header *header )
322 {
323 struct tgsi_immediate immediate;
324
325 immediate = tgsi_default_immediate();
326
327 header_bodysize_grow( header );
328
329 return immediate;
330 }
331
332 struct tgsi_full_immediate
333 tgsi_default_full_immediate( void )
334 {
335 struct tgsi_full_immediate fullimm;
336
337 fullimm.Immediate = tgsi_default_immediate();
338 fullimm.u[0].Float = 0.0f;
339 fullimm.u[1].Float = 0.0f;
340 fullimm.u[2].Float = 0.0f;
341 fullimm.u[3].Float = 0.0f;
342
343 return fullimm;
344 }
345
346 static void
347 immediate_grow(
348 struct tgsi_immediate *immediate,
349 struct tgsi_header *header )
350 {
351 assert( immediate->NrTokens < 0xFF );
352
353 immediate->NrTokens++;
354
355 header_bodysize_grow( header );
356 }
357
358 union tgsi_immediate_data
359 tgsi_build_immediate_float32(
360 float value,
361 struct tgsi_immediate *immediate,
362 struct tgsi_header *header )
363 {
364 union tgsi_immediate_data immediate_data;
365
366 immediate_data.Float = value;
367
368 immediate_grow( immediate, header );
369
370 return immediate_data;
371 }
372
373 unsigned
374 tgsi_build_full_immediate(
375 const struct tgsi_full_immediate *full_imm,
376 struct tgsi_token *tokens,
377 struct tgsi_header *header,
378 unsigned maxsize )
379 {
380 unsigned size = 0, i;
381 struct tgsi_immediate *immediate;
382
383 if( maxsize <= size )
384 return 0;
385 immediate = (struct tgsi_immediate *) &tokens[size];
386 size++;
387
388 *immediate = tgsi_build_immediate( header );
389
390 assert( full_imm->Immediate.NrTokens <= 4 + 1 );
391
392 for( i = 0; i < full_imm->Immediate.NrTokens - 1; i++ ) {
393 union tgsi_immediate_data *data;
394
395 if( maxsize <= size )
396 return 0;
397 data = (union tgsi_immediate_data *) &tokens[size];
398 size++;
399
400 *data = tgsi_build_immediate_float32(
401 full_imm->u[i].Float,
402 immediate,
403 header );
404 }
405
406 return size;
407 }
408
409 /*
410 * instruction
411 */
412
413 struct tgsi_instruction
414 tgsi_default_instruction( void )
415 {
416 struct tgsi_instruction instruction;
417
418 instruction.Type = TGSI_TOKEN_TYPE_INSTRUCTION;
419 instruction.NrTokens = 1;
420 instruction.Opcode = TGSI_OPCODE_MOV;
421 instruction.Saturate = TGSI_SAT_NONE;
422 instruction.NumDstRegs = 1;
423 instruction.NumSrcRegs = 1;
424 instruction.Padding = 0;
425 instruction.Extended = 0;
426
427 return instruction;
428 }
429
430 struct tgsi_instruction
431 tgsi_build_instruction(
432 unsigned opcode,
433 unsigned saturate,
434 unsigned num_dst_regs,
435 unsigned num_src_regs,
436 struct tgsi_header *header )
437 {
438 struct tgsi_instruction instruction;
439
440 assert (opcode <= TGSI_OPCODE_LAST);
441 assert (saturate <= TGSI_SAT_MINUS_PLUS_ONE);
442 assert (num_dst_regs <= 3);
443 assert (num_src_regs <= 15);
444
445 instruction = tgsi_default_instruction();
446 instruction.Opcode = opcode;
447 instruction.Saturate = saturate;
448 instruction.NumDstRegs = num_dst_regs;
449 instruction.NumSrcRegs = num_src_regs;
450
451 header_bodysize_grow( header );
452
453 return instruction;
454 }
455
456 static void
457 instruction_grow(
458 struct tgsi_instruction *instruction,
459 struct tgsi_header *header )
460 {
461 assert (instruction->NrTokens < 0xFF);
462
463 instruction->NrTokens++;
464
465 header_bodysize_grow( header );
466 }
467
468 struct tgsi_full_instruction
469 tgsi_default_full_instruction( void )
470 {
471 struct tgsi_full_instruction full_instruction;
472 unsigned i;
473
474 full_instruction.Instruction = tgsi_default_instruction();
475 full_instruction.InstructionExtLabel = tgsi_default_instruction_ext_label();
476 full_instruction.InstructionExtTexture = tgsi_default_instruction_ext_texture();
477 full_instruction.InstructionExtPredicate = tgsi_default_instruction_ext_predicate();
478 for( i = 0; i < TGSI_FULL_MAX_DST_REGISTERS; i++ ) {
479 full_instruction.FullDstRegisters[i] = tgsi_default_full_dst_register();
480 }
481 for( i = 0; i < TGSI_FULL_MAX_SRC_REGISTERS; i++ ) {
482 full_instruction.FullSrcRegisters[i] = tgsi_default_full_src_register();
483 }
484
485 full_instruction.Flags = 0x0;
486
487 return full_instruction;
488 }
489
490 unsigned
491 tgsi_build_full_instruction(
492 const struct tgsi_full_instruction *full_inst,
493 struct tgsi_token *tokens,
494 struct tgsi_header *header,
495 unsigned maxsize )
496 {
497 unsigned size = 0;
498 unsigned i;
499 struct tgsi_instruction *instruction;
500 struct tgsi_token *prev_token;
501
502 if( maxsize <= size )
503 return 0;
504 instruction = (struct tgsi_instruction *) &tokens[size];
505 size++;
506
507 *instruction = tgsi_build_instruction(
508 full_inst->Instruction.Opcode,
509 full_inst->Instruction.Saturate,
510 full_inst->Instruction.NumDstRegs,
511 full_inst->Instruction.NumSrcRegs,
512 header );
513 prev_token = (struct tgsi_token *) instruction;
514
515 if( tgsi_compare_instruction_ext_label(
516 full_inst->InstructionExtLabel,
517 tgsi_default_instruction_ext_label() ) ) {
518 struct tgsi_instruction_ext_label *instruction_ext_label;
519
520 if( maxsize <= size )
521 return 0;
522 instruction_ext_label =
523 (struct tgsi_instruction_ext_label *) &tokens[size];
524 size++;
525
526 *instruction_ext_label = tgsi_build_instruction_ext_label(
527 full_inst->InstructionExtLabel.Label,
528 prev_token,
529 instruction,
530 header );
531 prev_token = (struct tgsi_token *) instruction_ext_label;
532 }
533
534 if( tgsi_compare_instruction_ext_texture(
535 full_inst->InstructionExtTexture,
536 tgsi_default_instruction_ext_texture() ) ) {
537 struct tgsi_instruction_ext_texture *instruction_ext_texture;
538
539 if( maxsize <= size )
540 return 0;
541 instruction_ext_texture =
542 (struct tgsi_instruction_ext_texture *) &tokens[size];
543 size++;
544
545 *instruction_ext_texture = tgsi_build_instruction_ext_texture(
546 full_inst->InstructionExtTexture.Texture,
547 prev_token,
548 instruction,
549 header );
550 prev_token = (struct tgsi_token *) instruction_ext_texture;
551 }
552
553 if (tgsi_compare_instruction_ext_predicate(full_inst->InstructionExtPredicate,
554 tgsi_default_instruction_ext_predicate())) {
555 struct tgsi_instruction_ext_predicate *instruction_ext_predicate;
556
557 if (maxsize <= size) {
558 return 0;
559 }
560 instruction_ext_predicate = (struct tgsi_instruction_ext_predicate *)&tokens[size];
561 size++;
562
563 *instruction_ext_predicate =
564 tgsi_build_instruction_ext_predicate(full_inst->InstructionExtPredicate.SrcIndex,
565 full_inst->InstructionExtPredicate.Negate,
566 full_inst->InstructionExtPredicate.SwizzleX,
567 full_inst->InstructionExtPredicate.SwizzleY,
568 full_inst->InstructionExtPredicate.SwizzleZ,
569 full_inst->InstructionExtPredicate.SwizzleW,
570 prev_token,
571 instruction,
572 header);
573 prev_token = (struct tgsi_token *)instruction_ext_predicate;
574 }
575
576 for( i = 0; i < full_inst->Instruction.NumDstRegs; i++ ) {
577 const struct tgsi_full_dst_register *reg = &full_inst->FullDstRegisters[i];
578 struct tgsi_dst_register *dst_register;
579 struct tgsi_token *prev_token;
580
581 if( maxsize <= size )
582 return 0;
583 dst_register = (struct tgsi_dst_register *) &tokens[size];
584 size++;
585
586 *dst_register = tgsi_build_dst_register(
587 reg->DstRegister.File,
588 reg->DstRegister.WriteMask,
589 reg->DstRegister.Indirect,
590 reg->DstRegister.Index,
591 instruction,
592 header );
593 prev_token = (struct tgsi_token *) dst_register;
594
595 if( tgsi_compare_dst_register_ext_modulate(
596 reg->DstRegisterExtModulate,
597 tgsi_default_dst_register_ext_modulate() ) ) {
598 struct tgsi_dst_register_ext_modulate *dst_register_ext_modulate;
599
600 if( maxsize <= size )
601 return 0;
602 dst_register_ext_modulate =
603 (struct tgsi_dst_register_ext_modulate *) &tokens[size];
604 size++;
605
606 *dst_register_ext_modulate = tgsi_build_dst_register_ext_modulate(
607 reg->DstRegisterExtModulate.Modulate,
608 prev_token,
609 instruction,
610 header );
611 prev_token = (struct tgsi_token *) dst_register_ext_modulate;
612 }
613
614 if( reg->DstRegister.Indirect ) {
615 struct tgsi_src_register *ind;
616
617 if( maxsize <= size )
618 return 0;
619 ind = (struct tgsi_src_register *) &tokens[size];
620 size++;
621
622 *ind = tgsi_build_src_register(
623 reg->DstRegisterInd.File,
624 reg->DstRegisterInd.SwizzleX,
625 reg->DstRegisterInd.SwizzleY,
626 reg->DstRegisterInd.SwizzleZ,
627 reg->DstRegisterInd.SwizzleW,
628 reg->DstRegisterInd.Negate,
629 reg->DstRegisterInd.Indirect,
630 reg->DstRegisterInd.Dimension,
631 reg->DstRegisterInd.Index,
632 instruction,
633 header );
634 }
635 }
636
637 for( i = 0; i < full_inst->Instruction.NumSrcRegs; i++ ) {
638 const struct tgsi_full_src_register *reg = &full_inst->FullSrcRegisters[i];
639 struct tgsi_src_register *src_register;
640 struct tgsi_token *prev_token;
641
642 if( maxsize <= size )
643 return 0;
644 src_register = (struct tgsi_src_register *) &tokens[size];
645 size++;
646
647 *src_register = tgsi_build_src_register(
648 reg->SrcRegister.File,
649 reg->SrcRegister.SwizzleX,
650 reg->SrcRegister.SwizzleY,
651 reg->SrcRegister.SwizzleZ,
652 reg->SrcRegister.SwizzleW,
653 reg->SrcRegister.Negate,
654 reg->SrcRegister.Indirect,
655 reg->SrcRegister.Dimension,
656 reg->SrcRegister.Index,
657 instruction,
658 header );
659 prev_token = (struct tgsi_token *) src_register;
660
661 if( tgsi_compare_src_register_ext_mod(
662 reg->SrcRegisterExtMod,
663 tgsi_default_src_register_ext_mod() ) ) {
664 struct tgsi_src_register_ext_mod *src_register_ext_mod;
665
666 if( maxsize <= size )
667 return 0;
668 src_register_ext_mod =
669 (struct tgsi_src_register_ext_mod *) &tokens[size];
670 size++;
671
672 *src_register_ext_mod = tgsi_build_src_register_ext_mod(
673 reg->SrcRegisterExtMod.Complement,
674 reg->SrcRegisterExtMod.Bias,
675 reg->SrcRegisterExtMod.Scale2X,
676 reg->SrcRegisterExtMod.Absolute,
677 reg->SrcRegisterExtMod.Negate,
678 prev_token,
679 instruction,
680 header );
681 prev_token = (struct tgsi_token *) src_register_ext_mod;
682 }
683
684 if( reg->SrcRegister.Indirect ) {
685 struct tgsi_src_register *ind;
686
687 if( maxsize <= size )
688 return 0;
689 ind = (struct tgsi_src_register *) &tokens[size];
690 size++;
691
692 *ind = tgsi_build_src_register(
693 reg->SrcRegisterInd.File,
694 reg->SrcRegisterInd.SwizzleX,
695 reg->SrcRegisterInd.SwizzleY,
696 reg->SrcRegisterInd.SwizzleZ,
697 reg->SrcRegisterInd.SwizzleW,
698 reg->SrcRegisterInd.Negate,
699 reg->SrcRegisterInd.Indirect,
700 reg->SrcRegisterInd.Dimension,
701 reg->SrcRegisterInd.Index,
702 instruction,
703 header );
704 }
705
706 if( reg->SrcRegister.Dimension ) {
707 struct tgsi_dimension *dim;
708
709 assert( !reg->SrcRegisterDim.Dimension );
710
711 if( maxsize <= size )
712 return 0;
713 dim = (struct tgsi_dimension *) &tokens[size];
714 size++;
715
716 *dim = tgsi_build_dimension(
717 reg->SrcRegisterDim.Indirect,
718 reg->SrcRegisterDim.Index,
719 instruction,
720 header );
721
722 if( reg->SrcRegisterDim.Indirect ) {
723 struct tgsi_src_register *ind;
724
725 if( maxsize <= size )
726 return 0;
727 ind = (struct tgsi_src_register *) &tokens[size];
728 size++;
729
730 *ind = tgsi_build_src_register(
731 reg->SrcRegisterDimInd.File,
732 reg->SrcRegisterDimInd.SwizzleX,
733 reg->SrcRegisterDimInd.SwizzleY,
734 reg->SrcRegisterDimInd.SwizzleZ,
735 reg->SrcRegisterDimInd.SwizzleW,
736 reg->SrcRegisterDimInd.Negate,
737 reg->SrcRegisterDimInd.Indirect,
738 reg->SrcRegisterDimInd.Dimension,
739 reg->SrcRegisterDimInd.Index,
740 instruction,
741 header );
742 }
743 }
744 }
745
746 return size;
747 }
748
749 /** test for inequality of 32-bit values pointed to by a and b */
750 static INLINE boolean
751 compare32(const void *a, const void *b)
752 {
753 return *((uint32_t *) a) != *((uint32_t *) b);
754 }
755
756 struct tgsi_instruction_ext_label
757 tgsi_default_instruction_ext_label( void )
758 {
759 struct tgsi_instruction_ext_label instruction_ext_label;
760
761 instruction_ext_label.Type = TGSI_INSTRUCTION_EXT_TYPE_LABEL;
762 instruction_ext_label.Label = 0;
763 instruction_ext_label.Padding = 0;
764 instruction_ext_label.Extended = 0;
765
766 return instruction_ext_label;
767 }
768
769 unsigned
770 tgsi_compare_instruction_ext_label(
771 struct tgsi_instruction_ext_label a,
772 struct tgsi_instruction_ext_label b )
773 {
774 a.Padding = b.Padding = 0;
775 a.Extended = b.Extended = 0;
776 return compare32(&a, &b);
777 }
778
779 struct tgsi_instruction_ext_label
780 tgsi_build_instruction_ext_label(
781 unsigned label,
782 struct tgsi_token *prev_token,
783 struct tgsi_instruction *instruction,
784 struct tgsi_header *header )
785 {
786 struct tgsi_instruction_ext_label instruction_ext_label;
787
788 instruction_ext_label = tgsi_default_instruction_ext_label();
789 instruction_ext_label.Label = label;
790
791 prev_token->Extended = 1;
792 instruction_grow( instruction, header );
793
794 return instruction_ext_label;
795 }
796
797 struct tgsi_instruction_ext_texture
798 tgsi_default_instruction_ext_texture( void )
799 {
800 struct tgsi_instruction_ext_texture instruction_ext_texture;
801
802 instruction_ext_texture.Type = TGSI_INSTRUCTION_EXT_TYPE_TEXTURE;
803 instruction_ext_texture.Texture = TGSI_TEXTURE_UNKNOWN;
804 instruction_ext_texture.Padding = 0;
805 instruction_ext_texture.Extended = 0;
806
807 return instruction_ext_texture;
808 }
809
810 unsigned
811 tgsi_compare_instruction_ext_texture(
812 struct tgsi_instruction_ext_texture a,
813 struct tgsi_instruction_ext_texture b )
814 {
815 a.Padding = b.Padding = 0;
816 a.Extended = b.Extended = 0;
817 return compare32(&a, &b);
818 }
819
820 struct tgsi_instruction_ext_texture
821 tgsi_build_instruction_ext_texture(
822 unsigned texture,
823 struct tgsi_token *prev_token,
824 struct tgsi_instruction *instruction,
825 struct tgsi_header *header )
826 {
827 struct tgsi_instruction_ext_texture instruction_ext_texture;
828
829 instruction_ext_texture = tgsi_default_instruction_ext_texture();
830 instruction_ext_texture.Texture = texture;
831
832 prev_token->Extended = 1;
833 instruction_grow( instruction, header );
834
835 return instruction_ext_texture;
836 }
837
838 struct tgsi_instruction_ext_predicate
839 tgsi_default_instruction_ext_predicate(void)
840 {
841 struct tgsi_instruction_ext_predicate instruction_ext_predicate;
842
843 instruction_ext_predicate.Type = TGSI_INSTRUCTION_EXT_TYPE_PREDICATE;
844 instruction_ext_predicate.SwizzleX = TGSI_SWIZZLE_X;
845 instruction_ext_predicate.SwizzleY = TGSI_SWIZZLE_Y;
846 instruction_ext_predicate.SwizzleZ = TGSI_SWIZZLE_Z;
847 instruction_ext_predicate.SwizzleW = TGSI_SWIZZLE_W;
848 instruction_ext_predicate.Negate = 0;
849 instruction_ext_predicate.SrcIndex = 0;
850 instruction_ext_predicate.Padding = 0;
851 instruction_ext_predicate.Extended = 0;
852
853 return instruction_ext_predicate;
854 }
855
856 unsigned
857 tgsi_compare_instruction_ext_predicate(struct tgsi_instruction_ext_predicate a,
858 struct tgsi_instruction_ext_predicate b)
859 {
860 a.Padding = b.Padding = 0;
861 a.Extended = b.Extended = 0;
862 return compare32(&a, &b);
863 }
864
865 struct tgsi_instruction_ext_predicate
866 tgsi_build_instruction_ext_predicate(unsigned index,
867 unsigned negate,
868 unsigned swizzleX,
869 unsigned swizzleY,
870 unsigned swizzleZ,
871 unsigned swizzleW,
872 struct tgsi_token *prev_token,
873 struct tgsi_instruction *instruction,
874 struct tgsi_header *header)
875 {
876 struct tgsi_instruction_ext_predicate instruction_ext_predicate;
877
878 instruction_ext_predicate = tgsi_default_instruction_ext_predicate();
879 instruction_ext_predicate.SwizzleX = swizzleX;
880 instruction_ext_predicate.SwizzleY = swizzleY;
881 instruction_ext_predicate.SwizzleZ = swizzleZ;
882 instruction_ext_predicate.SwizzleW = swizzleW;
883 instruction_ext_predicate.Negate = negate;
884 instruction_ext_predicate.SrcIndex = index;
885
886 prev_token->Extended = 1;
887 instruction_grow(instruction, header);
888
889 return instruction_ext_predicate;
890 }
891
892 struct tgsi_src_register
893 tgsi_default_src_register( void )
894 {
895 struct tgsi_src_register src_register;
896
897 src_register.File = TGSI_FILE_NULL;
898 src_register.SwizzleX = TGSI_SWIZZLE_X;
899 src_register.SwizzleY = TGSI_SWIZZLE_Y;
900 src_register.SwizzleZ = TGSI_SWIZZLE_Z;
901 src_register.SwizzleW = TGSI_SWIZZLE_W;
902 src_register.Negate = 0;
903 src_register.Indirect = 0;
904 src_register.Dimension = 0;
905 src_register.Index = 0;
906 src_register.Extended = 0;
907
908 return src_register;
909 }
910
911 struct tgsi_src_register
912 tgsi_build_src_register(
913 unsigned file,
914 unsigned swizzle_x,
915 unsigned swizzle_y,
916 unsigned swizzle_z,
917 unsigned swizzle_w,
918 unsigned negate,
919 unsigned indirect,
920 unsigned dimension,
921 int index,
922 struct tgsi_instruction *instruction,
923 struct tgsi_header *header )
924 {
925 struct tgsi_src_register src_register;
926
927 assert( file < TGSI_FILE_COUNT );
928 assert( swizzle_x <= TGSI_SWIZZLE_W );
929 assert( swizzle_y <= TGSI_SWIZZLE_W );
930 assert( swizzle_z <= TGSI_SWIZZLE_W );
931 assert( swizzle_w <= TGSI_SWIZZLE_W );
932 assert( negate <= 1 );
933 assert( index >= -0x8000 && index <= 0x7FFF );
934
935 src_register = tgsi_default_src_register();
936 src_register.File = file;
937 src_register.SwizzleX = swizzle_x;
938 src_register.SwizzleY = swizzle_y;
939 src_register.SwizzleZ = swizzle_z;
940 src_register.SwizzleW = swizzle_w;
941 src_register.Negate = negate;
942 src_register.Indirect = indirect;
943 src_register.Dimension = dimension;
944 src_register.Index = index;
945
946 instruction_grow( instruction, header );
947
948 return src_register;
949 }
950
951 struct tgsi_full_src_register
952 tgsi_default_full_src_register( void )
953 {
954 struct tgsi_full_src_register full_src_register;
955
956 full_src_register.SrcRegister = tgsi_default_src_register();
957 full_src_register.SrcRegisterExtMod = tgsi_default_src_register_ext_mod();
958 full_src_register.SrcRegisterInd = tgsi_default_src_register();
959 full_src_register.SrcRegisterDim = tgsi_default_dimension();
960 full_src_register.SrcRegisterDimInd = tgsi_default_src_register();
961
962 return full_src_register;
963 }
964
965
966 struct tgsi_src_register_ext_mod
967 tgsi_default_src_register_ext_mod( void )
968 {
969 struct tgsi_src_register_ext_mod src_register_ext_mod;
970
971 src_register_ext_mod.Type = TGSI_SRC_REGISTER_EXT_TYPE_MOD;
972 src_register_ext_mod.Complement = 0;
973 src_register_ext_mod.Bias = 0;
974 src_register_ext_mod.Scale2X = 0;
975 src_register_ext_mod.Absolute = 0;
976 src_register_ext_mod.Negate = 0;
977 src_register_ext_mod.Padding = 0;
978 src_register_ext_mod.Extended = 0;
979
980 return src_register_ext_mod;
981 }
982
983 unsigned
984 tgsi_compare_src_register_ext_mod(
985 struct tgsi_src_register_ext_mod a,
986 struct tgsi_src_register_ext_mod b )
987 {
988 a.Padding = b.Padding = 0;
989 a.Extended = b.Extended = 0;
990 return compare32(&a, &b);
991 }
992
993 struct tgsi_src_register_ext_mod
994 tgsi_build_src_register_ext_mod(
995 unsigned complement,
996 unsigned bias,
997 unsigned scale_2x,
998 unsigned absolute,
999 unsigned negate,
1000 struct tgsi_token *prev_token,
1001 struct tgsi_instruction *instruction,
1002 struct tgsi_header *header )
1003 {
1004 struct tgsi_src_register_ext_mod src_register_ext_mod;
1005
1006 assert( complement <= 1 );
1007 assert( bias <= 1 );
1008 assert( scale_2x <= 1 );
1009 assert( absolute <= 1 );
1010 assert( negate <= 1 );
1011
1012 src_register_ext_mod = tgsi_default_src_register_ext_mod();
1013 src_register_ext_mod.Complement = complement;
1014 src_register_ext_mod.Bias = bias;
1015 src_register_ext_mod.Scale2X = scale_2x;
1016 src_register_ext_mod.Absolute = absolute;
1017 src_register_ext_mod.Negate = negate;
1018
1019 prev_token->Extended = 1;
1020 instruction_grow( instruction, header );
1021
1022 return src_register_ext_mod;
1023 }
1024
1025 struct tgsi_dimension
1026 tgsi_default_dimension( void )
1027 {
1028 struct tgsi_dimension dimension;
1029
1030 dimension.Indirect = 0;
1031 dimension.Dimension = 0;
1032 dimension.Padding = 0;
1033 dimension.Index = 0;
1034 dimension.Extended = 0;
1035
1036 return dimension;
1037 }
1038
1039 struct tgsi_dimension
1040 tgsi_build_dimension(
1041 unsigned indirect,
1042 unsigned index,
1043 struct tgsi_instruction *instruction,
1044 struct tgsi_header *header )
1045 {
1046 struct tgsi_dimension dimension;
1047
1048 dimension = tgsi_default_dimension();
1049 dimension.Indirect = indirect;
1050 dimension.Index = index;
1051
1052 instruction_grow( instruction, header );
1053
1054 return dimension;
1055 }
1056
1057 struct tgsi_dst_register
1058 tgsi_default_dst_register( void )
1059 {
1060 struct tgsi_dst_register dst_register;
1061
1062 dst_register.File = TGSI_FILE_NULL;
1063 dst_register.WriteMask = TGSI_WRITEMASK_XYZW;
1064 dst_register.Indirect = 0;
1065 dst_register.Dimension = 0;
1066 dst_register.Index = 0;
1067 dst_register.Padding = 0;
1068 dst_register.Extended = 0;
1069
1070 return dst_register;
1071 }
1072
1073 struct tgsi_dst_register
1074 tgsi_build_dst_register(
1075 unsigned file,
1076 unsigned mask,
1077 unsigned indirect,
1078 int index,
1079 struct tgsi_instruction *instruction,
1080 struct tgsi_header *header )
1081 {
1082 struct tgsi_dst_register dst_register;
1083
1084 assert( file < TGSI_FILE_COUNT );
1085 assert( mask <= TGSI_WRITEMASK_XYZW );
1086 assert( index >= -32768 && index <= 32767 );
1087
1088 dst_register = tgsi_default_dst_register();
1089 dst_register.File = file;
1090 dst_register.WriteMask = mask;
1091 dst_register.Index = index;
1092 dst_register.Indirect = indirect;
1093
1094 instruction_grow( instruction, header );
1095
1096 return dst_register;
1097 }
1098
1099 struct tgsi_full_dst_register
1100 tgsi_default_full_dst_register( void )
1101 {
1102 struct tgsi_full_dst_register full_dst_register;
1103
1104 full_dst_register.DstRegister = tgsi_default_dst_register();
1105 full_dst_register.DstRegisterInd = tgsi_default_src_register();
1106 full_dst_register.DstRegisterExtModulate =
1107 tgsi_default_dst_register_ext_modulate();
1108
1109 return full_dst_register;
1110 }
1111
1112 struct tgsi_dst_register_ext_modulate
1113 tgsi_default_dst_register_ext_modulate( void )
1114 {
1115 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate;
1116
1117 dst_register_ext_modulate.Type = TGSI_DST_REGISTER_EXT_TYPE_MODULATE;
1118 dst_register_ext_modulate.Modulate = TGSI_MODULATE_1X;
1119 dst_register_ext_modulate.Padding = 0;
1120 dst_register_ext_modulate.Extended = 0;
1121
1122 return dst_register_ext_modulate;
1123 }
1124
1125 unsigned
1126 tgsi_compare_dst_register_ext_modulate(
1127 struct tgsi_dst_register_ext_modulate a,
1128 struct tgsi_dst_register_ext_modulate b )
1129 {
1130 a.Padding = b.Padding = 0;
1131 a.Extended = b.Extended = 0;
1132 return compare32(&a, &b);
1133 }
1134
1135 struct tgsi_dst_register_ext_modulate
1136 tgsi_build_dst_register_ext_modulate(
1137 unsigned modulate,
1138 struct tgsi_token *prev_token,
1139 struct tgsi_instruction *instruction,
1140 struct tgsi_header *header )
1141 {
1142 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate;
1143
1144 assert( modulate <= TGSI_MODULATE_EIGHTH );
1145
1146 dst_register_ext_modulate = tgsi_default_dst_register_ext_modulate();
1147 dst_register_ext_modulate.Modulate = modulate;
1148
1149 prev_token->Extended = 1;
1150 instruction_grow( instruction, header );
1151
1152 return dst_register_ext_modulate;
1153 }