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