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