00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #include "pipe/p_debug.h"
00029 #include "pipe/p_shader_tokens.h"
00030 #include "tgsi_build.h"
00031 #include "tgsi_parse.h"
00032
00033
00034
00035
00036
00037 struct tgsi_version
00038 tgsi_build_version( void )
00039 {
00040 struct tgsi_version version;
00041
00042 version.MajorVersion = 1;
00043 version.MinorVersion = 1;
00044 version.Padding = 0;
00045
00046 return version;
00047 }
00048
00049
00050
00051
00052
00053 struct tgsi_header
00054 tgsi_build_header( void )
00055 {
00056 struct tgsi_header header;
00057
00058 header.HeaderSize = 1;
00059 header.BodySize = 0;
00060
00061 return header;
00062 }
00063
00064 static void
00065 header_headersize_grow( struct tgsi_header *header )
00066 {
00067 assert( header->HeaderSize < 0xFF );
00068 assert( header->BodySize == 0 );
00069
00070 header->HeaderSize++;
00071 }
00072
00073 static void
00074 header_bodysize_grow( struct tgsi_header *header )
00075 {
00076 assert( header->BodySize < 0xFFFFFF );
00077
00078 header->BodySize++;
00079 }
00080
00081 struct tgsi_processor
00082 tgsi_default_processor( void )
00083 {
00084 struct tgsi_processor processor;
00085
00086 processor.Processor = TGSI_PROCESSOR_FRAGMENT;
00087 processor.Padding = 0;
00088
00089 return processor;
00090 }
00091
00092 struct tgsi_processor
00093 tgsi_build_processor(
00094 unsigned type,
00095 struct tgsi_header *header )
00096 {
00097 struct tgsi_processor processor;
00098
00099 processor = tgsi_default_processor();
00100 processor.Processor = type;
00101
00102 header_headersize_grow( header );
00103
00104 return processor;
00105 }
00106
00107
00108
00109
00110
00111 struct tgsi_declaration
00112 tgsi_default_declaration( void )
00113 {
00114 struct tgsi_declaration declaration;
00115
00116 declaration.Type = TGSI_TOKEN_TYPE_DECLARATION;
00117 declaration.Size = 1;
00118 declaration.File = TGSI_FILE_NULL;
00119 declaration.UsageMask = TGSI_WRITEMASK_XYZW;
00120 declaration.Interpolate = TGSI_INTERPOLATE_CONSTANT;
00121 declaration.Semantic = 0;
00122 declaration.Centroid = 0;
00123 declaration.Invariant = 0;
00124 declaration.Padding = 0;
00125 declaration.Extended = 0;
00126
00127 return declaration;
00128 }
00129
00130 struct tgsi_declaration
00131 tgsi_build_declaration(
00132 unsigned file,
00133 unsigned usage_mask,
00134 unsigned interpolate,
00135 unsigned semantic,
00136 unsigned centroid,
00137 unsigned invariant,
00138 struct tgsi_header *header )
00139 {
00140 struct tgsi_declaration declaration;
00141
00142 assert(file < TGSI_FILE_COUNT);
00143 assert( interpolate <= TGSI_INTERPOLATE_PERSPECTIVE );
00144
00145 declaration = tgsi_default_declaration();
00146 declaration.File = file;
00147 declaration.UsageMask = usage_mask;
00148 declaration.Interpolate = interpolate;
00149 declaration.Semantic = semantic;
00150 declaration.Centroid = centroid;
00151 declaration.Invariant = invariant;
00152
00153 header_bodysize_grow( header );
00154
00155 return declaration;
00156 }
00157
00158 static void
00159 declaration_grow(
00160 struct tgsi_declaration *declaration,
00161 struct tgsi_header *header )
00162 {
00163 assert( declaration->Size < 0xFF );
00164
00165 declaration->Size++;
00166
00167 header_bodysize_grow( header );
00168 }
00169
00170 struct tgsi_full_declaration
00171 tgsi_default_full_declaration( void )
00172 {
00173 struct tgsi_full_declaration full_declaration;
00174
00175 full_declaration.Declaration = tgsi_default_declaration();
00176 full_declaration.DeclarationRange = tgsi_default_declaration_range();
00177 full_declaration.Semantic = tgsi_default_declaration_semantic();
00178
00179 return full_declaration;
00180 }
00181
00182 unsigned
00183 tgsi_build_full_declaration(
00184 const struct tgsi_full_declaration *full_decl,
00185 struct tgsi_token *tokens,
00186 struct tgsi_header *header,
00187 unsigned maxsize )
00188 {
00189 unsigned size = 0;
00190 struct tgsi_declaration *declaration;
00191 struct tgsi_declaration_range *dr;
00192
00193 if( maxsize <= size )
00194 return 0;
00195 declaration = (struct tgsi_declaration *) &tokens[size];
00196 size++;
00197
00198 *declaration = tgsi_build_declaration(
00199 full_decl->Declaration.File,
00200 full_decl->Declaration.UsageMask,
00201 full_decl->Declaration.Interpolate,
00202 full_decl->Declaration.Semantic,
00203 full_decl->Declaration.Centroid,
00204 full_decl->Declaration.Invariant,
00205 header );
00206
00207 if (maxsize <= size)
00208 return 0;
00209 dr = (struct tgsi_declaration_range *) &tokens[size];
00210 size++;
00211
00212 *dr = tgsi_build_declaration_range(
00213 full_decl->DeclarationRange.First,
00214 full_decl->DeclarationRange.Last,
00215 declaration,
00216 header );
00217
00218 if( full_decl->Declaration.Semantic ) {
00219 struct tgsi_declaration_semantic *ds;
00220
00221 if( maxsize <= size )
00222 return 0;
00223 ds = (struct tgsi_declaration_semantic *) &tokens[size];
00224 size++;
00225
00226 *ds = tgsi_build_declaration_semantic(
00227 full_decl->Semantic.SemanticName,
00228 full_decl->Semantic.SemanticIndex,
00229 declaration,
00230 header );
00231 }
00232
00233 return size;
00234 }
00235
00236 struct tgsi_declaration_range
00237 tgsi_default_declaration_range( void )
00238 {
00239 struct tgsi_declaration_range dr;
00240
00241 dr.First = 0;
00242 dr.Last = 0;
00243
00244 return dr;
00245 }
00246
00247 struct tgsi_declaration_range
00248 tgsi_build_declaration_range(
00249 unsigned first,
00250 unsigned last,
00251 struct tgsi_declaration *declaration,
00252 struct tgsi_header *header )
00253 {
00254 struct tgsi_declaration_range declaration_range;
00255
00256 assert( last >= first );
00257 assert( last <= 0xFFFF );
00258
00259 declaration_range = tgsi_default_declaration_range();
00260 declaration_range.First = first;
00261 declaration_range.Last = last;
00262
00263 declaration_grow( declaration, header );
00264
00265 return declaration_range;
00266 }
00267
00268 struct tgsi_declaration_semantic
00269 tgsi_default_declaration_semantic( void )
00270 {
00271 struct tgsi_declaration_semantic ds;
00272
00273 ds.SemanticName = TGSI_SEMANTIC_POSITION;
00274 ds.SemanticIndex = 0;
00275 ds.Padding = 0;
00276
00277 return ds;
00278 }
00279
00280 struct tgsi_declaration_semantic
00281 tgsi_build_declaration_semantic(
00282 unsigned semantic_name,
00283 unsigned semantic_index,
00284 struct tgsi_declaration *declaration,
00285 struct tgsi_header *header )
00286 {
00287 struct tgsi_declaration_semantic ds;
00288
00289 assert( semantic_name <= TGSI_SEMANTIC_COUNT );
00290 assert( semantic_index <= 0xFFFF );
00291
00292 ds = tgsi_default_declaration_semantic();
00293 ds.SemanticName = semantic_name;
00294 ds.SemanticIndex = semantic_index;
00295
00296 declaration_grow( declaration, header );
00297
00298 return ds;
00299 }
00300
00301
00302
00303
00304
00305 struct tgsi_immediate
00306 tgsi_default_immediate( void )
00307 {
00308 struct tgsi_immediate immediate;
00309
00310 immediate.Type = TGSI_TOKEN_TYPE_IMMEDIATE;
00311 immediate.Size = 1;
00312 immediate.DataType = TGSI_IMM_FLOAT32;
00313 immediate.Padding = 0;
00314 immediate.Extended = 0;
00315
00316 return immediate;
00317 }
00318
00319 struct tgsi_immediate
00320 tgsi_build_immediate(
00321 struct tgsi_header *header )
00322 {
00323 struct tgsi_immediate immediate;
00324
00325 immediate = tgsi_default_immediate();
00326
00327 header_bodysize_grow( header );
00328
00329 return immediate;
00330 }
00331
00332 struct tgsi_full_immediate
00333 tgsi_default_full_immediate( void )
00334 {
00335 struct tgsi_full_immediate fullimm;
00336
00337 fullimm.Immediate = tgsi_default_immediate();
00338 fullimm.u.Pointer = (void *) 0;
00339
00340 return fullimm;
00341 }
00342
00343 static void
00344 immediate_grow(
00345 struct tgsi_immediate *immediate,
00346 struct tgsi_header *header )
00347 {
00348 assert( immediate->Size < 0xFF );
00349
00350 immediate->Size++;
00351
00352 header_bodysize_grow( header );
00353 }
00354
00355 struct tgsi_immediate_float32
00356 tgsi_build_immediate_float32(
00357 float value,
00358 struct tgsi_immediate *immediate,
00359 struct tgsi_header *header )
00360 {
00361 struct tgsi_immediate_float32 immediate_float32;
00362
00363 immediate_float32.Float = value;
00364
00365 immediate_grow( immediate, header );
00366
00367 return immediate_float32;
00368 }
00369
00370 unsigned
00371 tgsi_build_full_immediate(
00372 const struct tgsi_full_immediate *full_imm,
00373 struct tgsi_token *tokens,
00374 struct tgsi_header *header,
00375 unsigned maxsize )
00376 {
00377 unsigned size = 0, i;
00378 struct tgsi_immediate *immediate;
00379
00380 if( maxsize <= size )
00381 return 0;
00382 immediate = (struct tgsi_immediate *) &tokens[size];
00383 size++;
00384
00385 *immediate = tgsi_build_immediate( header );
00386
00387 for( i = 0; i < full_imm->Immediate.Size - 1; i++ ) {
00388 struct tgsi_immediate_float32 *if32;
00389
00390 if( maxsize <= size )
00391 return 0;
00392 if32 = (struct tgsi_immediate_float32 *) &tokens[size];
00393 size++;
00394
00395 *if32 = tgsi_build_immediate_float32(
00396 full_imm->u.ImmediateFloat32[i].Float,
00397 immediate,
00398 header );
00399 }
00400
00401 return size;
00402 }
00403
00404
00405
00406
00407
00408 struct tgsi_instruction
00409 tgsi_default_instruction( void )
00410 {
00411 struct tgsi_instruction instruction;
00412
00413 instruction.Type = TGSI_TOKEN_TYPE_INSTRUCTION;
00414 instruction.Size = 1;
00415 instruction.Opcode = TGSI_OPCODE_MOV;
00416 instruction.Saturate = TGSI_SAT_NONE;
00417 instruction.NumDstRegs = 1;
00418 instruction.NumSrcRegs = 1;
00419 instruction.Padding = 0;
00420 instruction.Extended = 0;
00421
00422 return instruction;
00423 }
00424
00425 struct tgsi_instruction
00426 tgsi_build_instruction(
00427 unsigned opcode,
00428 unsigned saturate,
00429 unsigned num_dst_regs,
00430 unsigned num_src_regs,
00431 struct tgsi_header *header )
00432 {
00433 struct tgsi_instruction instruction;
00434
00435 assert (opcode <= TGSI_OPCODE_LAST);
00436 assert (saturate <= TGSI_SAT_MINUS_PLUS_ONE);
00437 assert (num_dst_regs <= 3);
00438 assert (num_src_regs <= 15);
00439
00440 instruction = tgsi_default_instruction();
00441 instruction.Opcode = opcode;
00442 instruction.Saturate = saturate;
00443 instruction.NumDstRegs = num_dst_regs;
00444 instruction.NumSrcRegs = num_src_regs;
00445
00446 header_bodysize_grow( header );
00447
00448 return instruction;
00449 }
00450
00451 static void
00452 instruction_grow(
00453 struct tgsi_instruction *instruction,
00454 struct tgsi_header *header )
00455 {
00456 assert (instruction->Size < 0xFF);
00457
00458 instruction->Size++;
00459
00460 header_bodysize_grow( header );
00461 }
00462
00463 struct tgsi_full_instruction
00464 tgsi_default_full_instruction( void )
00465 {
00466 struct tgsi_full_instruction full_instruction;
00467 unsigned i;
00468
00469 full_instruction.Instruction = tgsi_default_instruction();
00470 full_instruction.InstructionExtNv = tgsi_default_instruction_ext_nv();
00471 full_instruction.InstructionExtLabel = tgsi_default_instruction_ext_label();
00472 full_instruction.InstructionExtTexture = tgsi_default_instruction_ext_texture();
00473 for( i = 0; i < TGSI_FULL_MAX_DST_REGISTERS; i++ ) {
00474 full_instruction.FullDstRegisters[i] = tgsi_default_full_dst_register();
00475 }
00476 for( i = 0; i < TGSI_FULL_MAX_SRC_REGISTERS; i++ ) {
00477 full_instruction.FullSrcRegisters[i] = tgsi_default_full_src_register();
00478 }
00479
00480 return full_instruction;
00481 }
00482
00483 unsigned
00484 tgsi_build_full_instruction(
00485 const struct tgsi_full_instruction *full_inst,
00486 struct tgsi_token *tokens,
00487 struct tgsi_header *header,
00488 unsigned maxsize )
00489 {
00490 unsigned size = 0;
00491 unsigned i;
00492 struct tgsi_instruction *instruction;
00493 struct tgsi_token *prev_token;
00494
00495 if( maxsize <= size )
00496 return 0;
00497 instruction = (struct tgsi_instruction *) &tokens[size];
00498 size++;
00499
00500 *instruction = tgsi_build_instruction(
00501 full_inst->Instruction.Opcode,
00502 full_inst->Instruction.Saturate,
00503 full_inst->Instruction.NumDstRegs,
00504 full_inst->Instruction.NumSrcRegs,
00505 header );
00506 prev_token = (struct tgsi_token *) instruction;
00507
00508 if( tgsi_compare_instruction_ext_nv(
00509 full_inst->InstructionExtNv,
00510 tgsi_default_instruction_ext_nv() ) ) {
00511 struct tgsi_instruction_ext_nv *instruction_ext_nv;
00512
00513 if( maxsize <= size )
00514 return 0;
00515 instruction_ext_nv =
00516 (struct tgsi_instruction_ext_nv *) &tokens[size];
00517 size++;
00518
00519 *instruction_ext_nv = tgsi_build_instruction_ext_nv(
00520 full_inst->InstructionExtNv.Precision,
00521 full_inst->InstructionExtNv.CondDstIndex,
00522 full_inst->InstructionExtNv.CondFlowIndex,
00523 full_inst->InstructionExtNv.CondMask,
00524 full_inst->InstructionExtNv.CondSwizzleX,
00525 full_inst->InstructionExtNv.CondSwizzleY,
00526 full_inst->InstructionExtNv.CondSwizzleZ,
00527 full_inst->InstructionExtNv.CondSwizzleW,
00528 full_inst->InstructionExtNv.CondDstUpdate,
00529 full_inst->InstructionExtNv.CondFlowEnable,
00530 prev_token,
00531 instruction,
00532 header );
00533 prev_token = (struct tgsi_token *) instruction_ext_nv;
00534 }
00535
00536 if( tgsi_compare_instruction_ext_label(
00537 full_inst->InstructionExtLabel,
00538 tgsi_default_instruction_ext_label() ) ) {
00539 struct tgsi_instruction_ext_label *instruction_ext_label;
00540
00541 if( maxsize <= size )
00542 return 0;
00543 instruction_ext_label =
00544 (struct tgsi_instruction_ext_label *) &tokens[size];
00545 size++;
00546
00547 *instruction_ext_label = tgsi_build_instruction_ext_label(
00548 full_inst->InstructionExtLabel.Label,
00549 prev_token,
00550 instruction,
00551 header );
00552 prev_token = (struct tgsi_token *) instruction_ext_label;
00553 }
00554
00555 if( tgsi_compare_instruction_ext_texture(
00556 full_inst->InstructionExtTexture,
00557 tgsi_default_instruction_ext_texture() ) ) {
00558 struct tgsi_instruction_ext_texture *instruction_ext_texture;
00559
00560 if( maxsize <= size )
00561 return 0;
00562 instruction_ext_texture =
00563 (struct tgsi_instruction_ext_texture *) &tokens[size];
00564 size++;
00565
00566 *instruction_ext_texture = tgsi_build_instruction_ext_texture(
00567 full_inst->InstructionExtTexture.Texture,
00568 prev_token,
00569 instruction,
00570 header );
00571 prev_token = (struct tgsi_token *) instruction_ext_texture;
00572 }
00573
00574 for( i = 0; i < full_inst->Instruction.NumDstRegs; i++ ) {
00575 const struct tgsi_full_dst_register *reg = &full_inst->FullDstRegisters[i];
00576 struct tgsi_dst_register *dst_register;
00577 struct tgsi_token *prev_token;
00578
00579 if( maxsize <= size )
00580 return 0;
00581 dst_register = (struct tgsi_dst_register *) &tokens[size];
00582 size++;
00583
00584 *dst_register = tgsi_build_dst_register(
00585 reg->DstRegister.File,
00586 reg->DstRegister.WriteMask,
00587 reg->DstRegister.Index,
00588 instruction,
00589 header );
00590 prev_token = (struct tgsi_token *) dst_register;
00591
00592 if( tgsi_compare_dst_register_ext_concode(
00593 reg->DstRegisterExtConcode,
00594 tgsi_default_dst_register_ext_concode() ) ) {
00595 struct tgsi_dst_register_ext_concode *dst_register_ext_concode;
00596
00597 if( maxsize <= size )
00598 return 0;
00599 dst_register_ext_concode =
00600 (struct tgsi_dst_register_ext_concode *) &tokens[size];
00601 size++;
00602
00603 *dst_register_ext_concode = tgsi_build_dst_register_ext_concode(
00604 reg->DstRegisterExtConcode.CondMask,
00605 reg->DstRegisterExtConcode.CondSwizzleX,
00606 reg->DstRegisterExtConcode.CondSwizzleY,
00607 reg->DstRegisterExtConcode.CondSwizzleZ,
00608 reg->DstRegisterExtConcode.CondSwizzleW,
00609 reg->DstRegisterExtConcode.CondSrcIndex,
00610 prev_token,
00611 instruction,
00612 header );
00613 prev_token = (struct tgsi_token *) dst_register_ext_concode;
00614 }
00615
00616 if( tgsi_compare_dst_register_ext_modulate(
00617 reg->DstRegisterExtModulate,
00618 tgsi_default_dst_register_ext_modulate() ) ) {
00619 struct tgsi_dst_register_ext_modulate *dst_register_ext_modulate;
00620
00621 if( maxsize <= size )
00622 return 0;
00623 dst_register_ext_modulate =
00624 (struct tgsi_dst_register_ext_modulate *) &tokens[size];
00625 size++;
00626
00627 *dst_register_ext_modulate = tgsi_build_dst_register_ext_modulate(
00628 reg->DstRegisterExtModulate.Modulate,
00629 prev_token,
00630 instruction,
00631 header );
00632 prev_token = (struct tgsi_token *) dst_register_ext_modulate;
00633 }
00634 }
00635
00636 for( i = 0; i < full_inst->Instruction.NumSrcRegs; i++ ) {
00637 const struct tgsi_full_src_register *reg = &full_inst->FullSrcRegisters[i];
00638 struct tgsi_src_register *src_register;
00639 struct tgsi_token *prev_token;
00640
00641 if( maxsize <= size )
00642 return 0;
00643 src_register = (struct tgsi_src_register *) &tokens[size];
00644 size++;
00645
00646 *src_register = tgsi_build_src_register(
00647 reg->SrcRegister.File,
00648 reg->SrcRegister.SwizzleX,
00649 reg->SrcRegister.SwizzleY,
00650 reg->SrcRegister.SwizzleZ,
00651 reg->SrcRegister.SwizzleW,
00652 reg->SrcRegister.Negate,
00653 reg->SrcRegister.Indirect,
00654 reg->SrcRegister.Dimension,
00655 reg->SrcRegister.Index,
00656 instruction,
00657 header );
00658 prev_token = (struct tgsi_token *) src_register;
00659
00660 if( tgsi_compare_src_register_ext_swz(
00661 reg->SrcRegisterExtSwz,
00662 tgsi_default_src_register_ext_swz() ) ) {
00663 struct tgsi_src_register_ext_swz *src_register_ext_swz;
00664
00665
00666
00667 assert( reg->SrcRegister.SwizzleX == TGSI_SWIZZLE_X );
00668 assert( reg->SrcRegister.SwizzleY == TGSI_SWIZZLE_Y );
00669 assert( reg->SrcRegister.SwizzleZ == TGSI_SWIZZLE_Z );
00670 assert( reg->SrcRegister.SwizzleW == TGSI_SWIZZLE_W );
00671 assert( reg->SrcRegister.Negate == FALSE );
00672
00673 if( maxsize <= size )
00674 return 0;
00675 src_register_ext_swz =
00676 (struct tgsi_src_register_ext_swz *) &tokens[size];
00677 size++;
00678
00679 *src_register_ext_swz = tgsi_build_src_register_ext_swz(
00680 reg->SrcRegisterExtSwz.ExtSwizzleX,
00681 reg->SrcRegisterExtSwz.ExtSwizzleY,
00682 reg->SrcRegisterExtSwz.ExtSwizzleZ,
00683 reg->SrcRegisterExtSwz.ExtSwizzleW,
00684 reg->SrcRegisterExtSwz.NegateX,
00685 reg->SrcRegisterExtSwz.NegateY,
00686 reg->SrcRegisterExtSwz.NegateZ,
00687 reg->SrcRegisterExtSwz.NegateW,
00688 prev_token,
00689 instruction,
00690 header );
00691 prev_token = (struct tgsi_token *) src_register_ext_swz;
00692 }
00693
00694 if( tgsi_compare_src_register_ext_mod(
00695 reg->SrcRegisterExtMod,
00696 tgsi_default_src_register_ext_mod() ) ) {
00697 struct tgsi_src_register_ext_mod *src_register_ext_mod;
00698
00699 if( maxsize <= size )
00700 return 0;
00701 src_register_ext_mod =
00702 (struct tgsi_src_register_ext_mod *) &tokens[size];
00703 size++;
00704
00705 *src_register_ext_mod = tgsi_build_src_register_ext_mod(
00706 reg->SrcRegisterExtMod.Complement,
00707 reg->SrcRegisterExtMod.Bias,
00708 reg->SrcRegisterExtMod.Scale2X,
00709 reg->SrcRegisterExtMod.Absolute,
00710 reg->SrcRegisterExtMod.Negate,
00711 prev_token,
00712 instruction,
00713 header );
00714 prev_token = (struct tgsi_token *) src_register_ext_mod;
00715 }
00716
00717 if( reg->SrcRegister.Indirect ) {
00718 struct tgsi_src_register *ind;
00719
00720 if( maxsize <= size )
00721 return 0;
00722 ind = (struct tgsi_src_register *) &tokens[size];
00723 size++;
00724
00725 *ind = tgsi_build_src_register(
00726 reg->SrcRegisterInd.File,
00727 reg->SrcRegisterInd.SwizzleX,
00728 reg->SrcRegisterInd.SwizzleY,
00729 reg->SrcRegisterInd.SwizzleZ,
00730 reg->SrcRegisterInd.SwizzleW,
00731 reg->SrcRegisterInd.Negate,
00732 reg->SrcRegisterInd.Indirect,
00733 reg->SrcRegisterInd.Dimension,
00734 reg->SrcRegisterInd.Index,
00735 instruction,
00736 header );
00737 }
00738
00739 if( reg->SrcRegister.Dimension ) {
00740 struct tgsi_dimension *dim;
00741
00742 assert( !reg->SrcRegisterDim.Dimension );
00743
00744 if( maxsize <= size )
00745 return 0;
00746 dim = (struct tgsi_dimension *) &tokens[size];
00747 size++;
00748
00749 *dim = tgsi_build_dimension(
00750 reg->SrcRegisterDim.Indirect,
00751 reg->SrcRegisterDim.Index,
00752 instruction,
00753 header );
00754
00755 if( reg->SrcRegisterDim.Indirect ) {
00756 struct tgsi_src_register *ind;
00757
00758 if( maxsize <= size )
00759 return 0;
00760 ind = (struct tgsi_src_register *) &tokens[size];
00761 size++;
00762
00763 *ind = tgsi_build_src_register(
00764 reg->SrcRegisterDimInd.File,
00765 reg->SrcRegisterDimInd.SwizzleX,
00766 reg->SrcRegisterDimInd.SwizzleY,
00767 reg->SrcRegisterDimInd.SwizzleZ,
00768 reg->SrcRegisterDimInd.SwizzleW,
00769 reg->SrcRegisterDimInd.Negate,
00770 reg->SrcRegisterDimInd.Indirect,
00771 reg->SrcRegisterDimInd.Dimension,
00772 reg->SrcRegisterDimInd.Index,
00773 instruction,
00774 header );
00775 }
00776 }
00777 }
00778
00779 return size;
00780 }
00781
00782 struct tgsi_instruction_ext_nv
00783 tgsi_default_instruction_ext_nv( void )
00784 {
00785 struct tgsi_instruction_ext_nv instruction_ext_nv;
00786
00787 instruction_ext_nv.Type = TGSI_INSTRUCTION_EXT_TYPE_NV;
00788 instruction_ext_nv.Precision = TGSI_PRECISION_DEFAULT;
00789 instruction_ext_nv.CondDstIndex = 0;
00790 instruction_ext_nv.CondFlowIndex = 0;
00791 instruction_ext_nv.CondMask = TGSI_CC_TR;
00792 instruction_ext_nv.CondSwizzleX = TGSI_SWIZZLE_X;
00793 instruction_ext_nv.CondSwizzleY = TGSI_SWIZZLE_Y;
00794 instruction_ext_nv.CondSwizzleZ = TGSI_SWIZZLE_Z;
00795 instruction_ext_nv.CondSwizzleW = TGSI_SWIZZLE_W;
00796 instruction_ext_nv.CondDstUpdate = 0;
00797 instruction_ext_nv.CondFlowEnable = 0;
00798 instruction_ext_nv.Padding = 0;
00799 instruction_ext_nv.Extended = 0;
00800
00801 return instruction_ext_nv;
00802 }
00803
00804 union token_u32
00805 {
00806 unsigned u32;
00807 };
00808
00809 unsigned
00810 tgsi_compare_instruction_ext_nv(
00811 struct tgsi_instruction_ext_nv a,
00812 struct tgsi_instruction_ext_nv b )
00813 {
00814 a.Padding = b.Padding = 0;
00815 a.Extended = b.Extended = 0;
00816 return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32;
00817 }
00818
00819 struct tgsi_instruction_ext_nv
00820 tgsi_build_instruction_ext_nv(
00821 unsigned precision,
00822 unsigned cond_dst_index,
00823 unsigned cond_flow_index,
00824 unsigned cond_mask,
00825 unsigned cond_swizzle_x,
00826 unsigned cond_swizzle_y,
00827 unsigned cond_swizzle_z,
00828 unsigned cond_swizzle_w,
00829 unsigned cond_dst_update,
00830 unsigned cond_flow_enable,
00831 struct tgsi_token *prev_token,
00832 struct tgsi_instruction *instruction,
00833 struct tgsi_header *header )
00834 {
00835 struct tgsi_instruction_ext_nv instruction_ext_nv;
00836
00837 instruction_ext_nv = tgsi_default_instruction_ext_nv();
00838 instruction_ext_nv.Precision = precision;
00839 instruction_ext_nv.CondDstIndex = cond_dst_index;
00840 instruction_ext_nv.CondFlowIndex = cond_flow_index;
00841 instruction_ext_nv.CondMask = cond_mask;
00842 instruction_ext_nv.CondSwizzleX = cond_swizzle_x;
00843 instruction_ext_nv.CondSwizzleY = cond_swizzle_y;
00844 instruction_ext_nv.CondSwizzleZ = cond_swizzle_z;
00845 instruction_ext_nv.CondSwizzleW = cond_swizzle_w;
00846 instruction_ext_nv.CondDstUpdate = cond_dst_update;
00847 instruction_ext_nv.CondFlowEnable = cond_flow_enable;
00848
00849 prev_token->Extended = 1;
00850 instruction_grow( instruction, header );
00851
00852 return instruction_ext_nv;
00853 }
00854
00855 struct tgsi_instruction_ext_label
00856 tgsi_default_instruction_ext_label( void )
00857 {
00858 struct tgsi_instruction_ext_label instruction_ext_label;
00859
00860 instruction_ext_label.Type = TGSI_INSTRUCTION_EXT_TYPE_LABEL;
00861 instruction_ext_label.Label = 0;
00862 instruction_ext_label.Padding = 0;
00863 instruction_ext_label.Extended = 0;
00864
00865 return instruction_ext_label;
00866 }
00867
00868 unsigned
00869 tgsi_compare_instruction_ext_label(
00870 struct tgsi_instruction_ext_label a,
00871 struct tgsi_instruction_ext_label b )
00872 {
00873 a.Padding = b.Padding = 0;
00874 a.Extended = b.Extended = 0;
00875 return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32;
00876 }
00877
00878 struct tgsi_instruction_ext_label
00879 tgsi_build_instruction_ext_label(
00880 unsigned label,
00881 struct tgsi_token *prev_token,
00882 struct tgsi_instruction *instruction,
00883 struct tgsi_header *header )
00884 {
00885 struct tgsi_instruction_ext_label instruction_ext_label;
00886
00887 instruction_ext_label = tgsi_default_instruction_ext_label();
00888 instruction_ext_label.Label = label;
00889
00890 prev_token->Extended = 1;
00891 instruction_grow( instruction, header );
00892
00893 return instruction_ext_label;
00894 }
00895
00896 struct tgsi_instruction_ext_texture
00897 tgsi_default_instruction_ext_texture( void )
00898 {
00899 struct tgsi_instruction_ext_texture instruction_ext_texture;
00900
00901 instruction_ext_texture.Type = TGSI_INSTRUCTION_EXT_TYPE_TEXTURE;
00902 instruction_ext_texture.Texture = TGSI_TEXTURE_UNKNOWN;
00903 instruction_ext_texture.Padding = 0;
00904 instruction_ext_texture.Extended = 0;
00905
00906 return instruction_ext_texture;
00907 }
00908
00909 unsigned
00910 tgsi_compare_instruction_ext_texture(
00911 struct tgsi_instruction_ext_texture a,
00912 struct tgsi_instruction_ext_texture b )
00913 {
00914 a.Padding = b.Padding = 0;
00915 a.Extended = b.Extended = 0;
00916 return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32;
00917 }
00918
00919 struct tgsi_instruction_ext_texture
00920 tgsi_build_instruction_ext_texture(
00921 unsigned texture,
00922 struct tgsi_token *prev_token,
00923 struct tgsi_instruction *instruction,
00924 struct tgsi_header *header )
00925 {
00926 struct tgsi_instruction_ext_texture instruction_ext_texture;
00927
00928 instruction_ext_texture = tgsi_default_instruction_ext_texture();
00929 instruction_ext_texture.Texture = texture;
00930
00931 prev_token->Extended = 1;
00932 instruction_grow( instruction, header );
00933
00934 return instruction_ext_texture;
00935 }
00936
00937 struct tgsi_src_register
00938 tgsi_default_src_register( void )
00939 {
00940 struct tgsi_src_register src_register;
00941
00942 src_register.File = TGSI_FILE_NULL;
00943 src_register.SwizzleX = TGSI_SWIZZLE_X;
00944 src_register.SwizzleY = TGSI_SWIZZLE_Y;
00945 src_register.SwizzleZ = TGSI_SWIZZLE_Z;
00946 src_register.SwizzleW = TGSI_SWIZZLE_W;
00947 src_register.Negate = 0;
00948 src_register.Indirect = 0;
00949 src_register.Dimension = 0;
00950 src_register.Index = 0;
00951 src_register.Extended = 0;
00952
00953 return src_register;
00954 }
00955
00956 struct tgsi_src_register
00957 tgsi_build_src_register(
00958 unsigned file,
00959 unsigned swizzle_x,
00960 unsigned swizzle_y,
00961 unsigned swizzle_z,
00962 unsigned swizzle_w,
00963 unsigned negate,
00964 unsigned indirect,
00965 unsigned dimension,
00966 int index,
00967 struct tgsi_instruction *instruction,
00968 struct tgsi_header *header )
00969 {
00970 struct tgsi_src_register src_register;
00971
00972 assert(file < TGSI_FILE_COUNT);
00973 assert( swizzle_x <= TGSI_SWIZZLE_W );
00974 assert( swizzle_y <= TGSI_SWIZZLE_W );
00975 assert( swizzle_z <= TGSI_SWIZZLE_W );
00976 assert( swizzle_w <= TGSI_SWIZZLE_W );
00977 assert( negate <= 1 );
00978 assert( index >= -0x8000 && index <= 0x7FFF );
00979
00980 src_register = tgsi_default_src_register();
00981 src_register.File = file;
00982 src_register.SwizzleX = swizzle_x;
00983 src_register.SwizzleY = swizzle_y;
00984 src_register.SwizzleZ = swizzle_z;
00985 src_register.SwizzleW = swizzle_w;
00986 src_register.Negate = negate;
00987 src_register.Indirect = indirect;
00988 src_register.Dimension = dimension;
00989 src_register.Index = index;
00990
00991 instruction_grow( instruction, header );
00992
00993 return src_register;
00994 }
00995
00996 struct tgsi_full_src_register
00997 tgsi_default_full_src_register( void )
00998 {
00999 struct tgsi_full_src_register full_src_register;
01000
01001 full_src_register.SrcRegister = tgsi_default_src_register();
01002 full_src_register.SrcRegisterExtSwz = tgsi_default_src_register_ext_swz();
01003 full_src_register.SrcRegisterExtMod = tgsi_default_src_register_ext_mod();
01004 full_src_register.SrcRegisterInd = tgsi_default_src_register();
01005 full_src_register.SrcRegisterDim = tgsi_default_dimension();
01006 full_src_register.SrcRegisterDimInd = tgsi_default_src_register();
01007
01008 return full_src_register;
01009 }
01010
01011 struct tgsi_src_register_ext_swz
01012 tgsi_default_src_register_ext_swz( void )
01013 {
01014 struct tgsi_src_register_ext_swz src_register_ext_swz;
01015
01016 src_register_ext_swz.Type = TGSI_SRC_REGISTER_EXT_TYPE_SWZ;
01017 src_register_ext_swz.ExtSwizzleX = TGSI_EXTSWIZZLE_X;
01018 src_register_ext_swz.ExtSwizzleY = TGSI_EXTSWIZZLE_Y;
01019 src_register_ext_swz.ExtSwizzleZ = TGSI_EXTSWIZZLE_Z;
01020 src_register_ext_swz.ExtSwizzleW = TGSI_EXTSWIZZLE_W;
01021 src_register_ext_swz.NegateX = 0;
01022 src_register_ext_swz.NegateY = 0;
01023 src_register_ext_swz.NegateZ = 0;
01024 src_register_ext_swz.NegateW = 0;
01025 src_register_ext_swz.Padding = 0;
01026 src_register_ext_swz.Extended = 0;
01027
01028 return src_register_ext_swz;
01029 }
01030
01031 unsigned
01032 tgsi_compare_src_register_ext_swz(
01033 struct tgsi_src_register_ext_swz a,
01034 struct tgsi_src_register_ext_swz b )
01035 {
01036 a.Padding = b.Padding = 0;
01037 a.Extended = b.Extended = 0;
01038 return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32;
01039 }
01040
01041 struct tgsi_src_register_ext_swz
01042 tgsi_build_src_register_ext_swz(
01043 unsigned ext_swizzle_x,
01044 unsigned ext_swizzle_y,
01045 unsigned ext_swizzle_z,
01046 unsigned ext_swizzle_w,
01047 unsigned negate_x,
01048 unsigned negate_y,
01049 unsigned negate_z,
01050 unsigned negate_w,
01051 struct tgsi_token *prev_token,
01052 struct tgsi_instruction *instruction,
01053 struct tgsi_header *header )
01054 {
01055 struct tgsi_src_register_ext_swz src_register_ext_swz;
01056
01057 assert( ext_swizzle_x <= TGSI_EXTSWIZZLE_ONE );
01058 assert( ext_swizzle_y <= TGSI_EXTSWIZZLE_ONE );
01059 assert( ext_swizzle_z <= TGSI_EXTSWIZZLE_ONE );
01060 assert( ext_swizzle_w <= TGSI_EXTSWIZZLE_ONE );
01061 assert( negate_x <= 1 );
01062 assert( negate_y <= 1 );
01063 assert( negate_z <= 1 );
01064 assert( negate_w <= 1 );
01065
01066 src_register_ext_swz = tgsi_default_src_register_ext_swz();
01067 src_register_ext_swz.ExtSwizzleX = ext_swizzle_x;
01068 src_register_ext_swz.ExtSwizzleY = ext_swizzle_y;
01069 src_register_ext_swz.ExtSwizzleZ = ext_swizzle_z;
01070 src_register_ext_swz.ExtSwizzleW = ext_swizzle_w;
01071 src_register_ext_swz.NegateX = negate_x;
01072 src_register_ext_swz.NegateY = negate_y;
01073 src_register_ext_swz.NegateZ = negate_z;
01074 src_register_ext_swz.NegateW = negate_w;
01075
01076 prev_token->Extended = 1;
01077 instruction_grow( instruction, header );
01078
01079 return src_register_ext_swz;
01080 }
01081
01082 struct tgsi_src_register_ext_mod
01083 tgsi_default_src_register_ext_mod( void )
01084 {
01085 struct tgsi_src_register_ext_mod src_register_ext_mod;
01086
01087 src_register_ext_mod.Type = TGSI_SRC_REGISTER_EXT_TYPE_MOD;
01088 src_register_ext_mod.Complement = 0;
01089 src_register_ext_mod.Bias = 0;
01090 src_register_ext_mod.Scale2X = 0;
01091 src_register_ext_mod.Absolute = 0;
01092 src_register_ext_mod.Negate = 0;
01093 src_register_ext_mod.Padding = 0;
01094 src_register_ext_mod.Extended = 0;
01095
01096 return src_register_ext_mod;
01097 }
01098
01099 unsigned
01100 tgsi_compare_src_register_ext_mod(
01101 struct tgsi_src_register_ext_mod a,
01102 struct tgsi_src_register_ext_mod b )
01103 {
01104 a.Padding = b.Padding = 0;
01105 a.Extended = b.Extended = 0;
01106 return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32;
01107 }
01108
01109 struct tgsi_src_register_ext_mod
01110 tgsi_build_src_register_ext_mod(
01111 unsigned complement,
01112 unsigned bias,
01113 unsigned scale_2x,
01114 unsigned absolute,
01115 unsigned negate,
01116 struct tgsi_token *prev_token,
01117 struct tgsi_instruction *instruction,
01118 struct tgsi_header *header )
01119 {
01120 struct tgsi_src_register_ext_mod src_register_ext_mod;
01121
01122 assert( complement <= 1 );
01123 assert( bias <= 1 );
01124 assert( scale_2x <= 1 );
01125 assert( absolute <= 1 );
01126 assert( negate <= 1 );
01127
01128 src_register_ext_mod = tgsi_default_src_register_ext_mod();
01129 src_register_ext_mod.Complement = complement;
01130 src_register_ext_mod.Bias = bias;
01131 src_register_ext_mod.Scale2X = scale_2x;
01132 src_register_ext_mod.Absolute = absolute;
01133 src_register_ext_mod.Negate = negate;
01134
01135 prev_token->Extended = 1;
01136 instruction_grow( instruction, header );
01137
01138 return src_register_ext_mod;
01139 }
01140
01141 struct tgsi_dimension
01142 tgsi_default_dimension( void )
01143 {
01144 struct tgsi_dimension dimension;
01145
01146 dimension.Indirect = 0;
01147 dimension.Dimension = 0;
01148 dimension.Padding = 0;
01149 dimension.Index = 0;
01150 dimension.Extended = 0;
01151
01152 return dimension;
01153 }
01154
01155 struct tgsi_dimension
01156 tgsi_build_dimension(
01157 unsigned indirect,
01158 unsigned index,
01159 struct tgsi_instruction *instruction,
01160 struct tgsi_header *header )
01161 {
01162 struct tgsi_dimension dimension;
01163
01164 dimension = tgsi_default_dimension();
01165 dimension.Indirect = indirect;
01166 dimension.Index = index;
01167
01168 instruction_grow( instruction, header );
01169
01170 return dimension;
01171 }
01172
01173 struct tgsi_dst_register
01174 tgsi_default_dst_register( void )
01175 {
01176 struct tgsi_dst_register dst_register;
01177
01178 dst_register.File = TGSI_FILE_NULL;
01179 dst_register.WriteMask = TGSI_WRITEMASK_XYZW;
01180 dst_register.Indirect = 0;
01181 dst_register.Dimension = 0;
01182 dst_register.Index = 0;
01183 dst_register.Padding = 0;
01184 dst_register.Extended = 0;
01185
01186 return dst_register;
01187 }
01188
01189 struct tgsi_dst_register
01190 tgsi_build_dst_register(
01191 unsigned file,
01192 unsigned mask,
01193 int index,
01194 struct tgsi_instruction *instruction,
01195 struct tgsi_header *header )
01196 {
01197 struct tgsi_dst_register dst_register;
01198
01199 assert(file < TGSI_FILE_COUNT);
01200 assert( mask <= TGSI_WRITEMASK_XYZW );
01201 assert( index >= -32768 && index <= 32767 );
01202
01203 dst_register = tgsi_default_dst_register();
01204 dst_register.File = file;
01205 dst_register.WriteMask = mask;
01206 dst_register.Index = index;
01207
01208 instruction_grow( instruction, header );
01209
01210 return dst_register;
01211 }
01212
01213 struct tgsi_full_dst_register
01214 tgsi_default_full_dst_register( void )
01215 {
01216 struct tgsi_full_dst_register full_dst_register;
01217
01218 full_dst_register.DstRegister = tgsi_default_dst_register();
01219 full_dst_register.DstRegisterExtConcode =
01220 tgsi_default_dst_register_ext_concode();
01221 full_dst_register.DstRegisterExtModulate =
01222 tgsi_default_dst_register_ext_modulate();
01223
01224 return full_dst_register;
01225 }
01226
01227 struct tgsi_dst_register_ext_concode
01228 tgsi_default_dst_register_ext_concode( void )
01229 {
01230 struct tgsi_dst_register_ext_concode dst_register_ext_concode;
01231
01232 dst_register_ext_concode.Type = TGSI_DST_REGISTER_EXT_TYPE_CONDCODE;
01233 dst_register_ext_concode.CondMask = TGSI_CC_TR;
01234 dst_register_ext_concode.CondSwizzleX = TGSI_SWIZZLE_X;
01235 dst_register_ext_concode.CondSwizzleY = TGSI_SWIZZLE_Y;
01236 dst_register_ext_concode.CondSwizzleZ = TGSI_SWIZZLE_Z;
01237 dst_register_ext_concode.CondSwizzleW = TGSI_SWIZZLE_W;
01238 dst_register_ext_concode.CondSrcIndex = 0;
01239 dst_register_ext_concode.Padding = 0;
01240 dst_register_ext_concode.Extended = 0;
01241
01242 return dst_register_ext_concode;
01243 }
01244
01245 unsigned
01246 tgsi_compare_dst_register_ext_concode(
01247 struct tgsi_dst_register_ext_concode a,
01248 struct tgsi_dst_register_ext_concode b )
01249 {
01250 a.Padding = b.Padding = 0;
01251 a.Extended = b.Extended = 0;
01252 return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32;
01253 }
01254
01255 struct tgsi_dst_register_ext_concode
01256 tgsi_build_dst_register_ext_concode(
01257 unsigned cc,
01258 unsigned swizzle_x,
01259 unsigned swizzle_y,
01260 unsigned swizzle_z,
01261 unsigned swizzle_w,
01262 int index,
01263 struct tgsi_token *prev_token,
01264 struct tgsi_instruction *instruction,
01265 struct tgsi_header *header )
01266 {
01267 struct tgsi_dst_register_ext_concode dst_register_ext_concode;
01268
01269 assert( cc <= TGSI_CC_FL );
01270 assert( swizzle_x <= TGSI_SWIZZLE_W );
01271 assert( swizzle_y <= TGSI_SWIZZLE_W );
01272 assert( swizzle_z <= TGSI_SWIZZLE_W );
01273 assert( swizzle_w <= TGSI_SWIZZLE_W );
01274 assert( index >= -32768 && index <= 32767 );
01275
01276 dst_register_ext_concode = tgsi_default_dst_register_ext_concode();
01277 dst_register_ext_concode.CondMask = cc;
01278 dst_register_ext_concode.CondSwizzleX = swizzle_x;
01279 dst_register_ext_concode.CondSwizzleY = swizzle_y;
01280 dst_register_ext_concode.CondSwizzleZ = swizzle_z;
01281 dst_register_ext_concode.CondSwizzleW = swizzle_w;
01282 dst_register_ext_concode.CondSrcIndex = index;
01283
01284 prev_token->Extended = 1;
01285 instruction_grow( instruction, header );
01286
01287 return dst_register_ext_concode;
01288 }
01289
01290 struct tgsi_dst_register_ext_modulate
01291 tgsi_default_dst_register_ext_modulate( void )
01292 {
01293 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate;
01294
01295 dst_register_ext_modulate.Type = TGSI_DST_REGISTER_EXT_TYPE_MODULATE;
01296 dst_register_ext_modulate.Modulate = TGSI_MODULATE_1X;
01297 dst_register_ext_modulate.Padding = 0;
01298 dst_register_ext_modulate.Extended = 0;
01299
01300 return dst_register_ext_modulate;
01301 }
01302
01303 unsigned
01304 tgsi_compare_dst_register_ext_modulate(
01305 struct tgsi_dst_register_ext_modulate a,
01306 struct tgsi_dst_register_ext_modulate b )
01307 {
01308 a.Padding = b.Padding = 0;
01309 a.Extended = b.Extended = 0;
01310 return ((union token_u32 *) &a)->u32 != ((union token_u32 *) &b)->u32;
01311 }
01312
01313 struct tgsi_dst_register_ext_modulate
01314 tgsi_build_dst_register_ext_modulate(
01315 unsigned modulate,
01316 struct tgsi_token *prev_token,
01317 struct tgsi_instruction *instruction,
01318 struct tgsi_header *header )
01319 {
01320 struct tgsi_dst_register_ext_modulate dst_register_ext_modulate;
01321
01322 assert( modulate <= TGSI_MODULATE_EIGHTH );
01323
01324 dst_register_ext_modulate = tgsi_default_dst_register_ext_modulate();
01325 dst_register_ext_modulate.Modulate = modulate;
01326
01327 prev_token->Extended = 1;
01328 instruction_grow( instruction, header );
01329
01330 return dst_register_ext_modulate;
01331 }