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