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