Go to the source code of this file.
Functions | |
boolean | cell_gen_fragment_program (struct cell_context *cell, const struct tgsi_token *tokens, struct spe_function *f) |
Translate TGSI shader code to SPE instructions. |
boolean cell_gen_fragment_program | ( | struct cell_context * | cell, | |
const struct tgsi_token * | tokens, | |||
struct spe_function * | f | |||
) |
Translate TGSI shader code to SPE instructions.
This is done when the state tracker gives us a new shader (via pipe->create_fs_state()).
cell | the rendering context (in) | |
tokens | the TGSI shader (in) | |
f | the generated function (out) |
Definition at line 455 of file cell_gen_fp.c.
References assert, codegen::constants_reg, emit_declaration(), emit_END(), emit_instruction(), codegen::error, codegen::f, tgsi_full_token::FullDeclaration, tgsi_full_token::FullImmediate, tgsi_full_token::FullInstruction, tgsi_parse_context::FullToken, codegen::inputs_reg, spe_function::num_inst, codegen::outputs_reg, spe_allocate_register(), spe_init_func(), SPE_INST_SIZE, SPU_MAX_FRAGMENT_PROGRAM_INSTS, tgsi_dump(), tgsi_parse_end_of_tokens(), tgsi_parse_free(), tgsi_parse_init(), tgsi_parse_token(), TGSI_TOKEN_TYPE_DECLARATION, TGSI_TOKEN_TYPE_IMMEDIATE, TGSI_TOKEN_TYPE_INSTRUCTION, tgsi_full_token::Token, and tgsi_token::Type.
00458 { 00459 struct tgsi_parse_context parse; 00460 struct codegen gen; 00461 00462 memset(&gen, 0, sizeof(gen)); 00463 gen.f = f; 00464 00465 /* For SPE function calls: reg $3 = first param, $4 = second param, etc. */ 00466 gen.inputs_reg = 3; /* pointer to inputs array */ 00467 gen.outputs_reg = 4; /* pointer to outputs array */ 00468 gen.constants_reg = 5; /* pointer to constants array */ 00469 00470 spe_init_func(f, SPU_MAX_FRAGMENT_PROGRAM_INSTS * SPE_INST_SIZE); 00471 spe_allocate_register(f, gen.inputs_reg); 00472 spe_allocate_register(f, gen.outputs_reg); 00473 spe_allocate_register(f, gen.constants_reg); 00474 00475 #if DISASSEM 00476 printf("Begin %s\n", __FUNCTION__); 00477 tgsi_dump(tokens, 0); 00478 #endif 00479 00480 tgsi_parse_init(&parse, tokens); 00481 00482 while (!tgsi_parse_end_of_tokens(&parse) && !gen.error) { 00483 tgsi_parse_token(&parse); 00484 00485 switch (parse.FullToken.Token.Type) { 00486 case TGSI_TOKEN_TYPE_IMMEDIATE: 00487 #if 0 00488 if (!note_immediate(&gen, &parse.FullToken.FullImmediate )) 00489 goto fail; 00490 #endif 00491 break; 00492 00493 case TGSI_TOKEN_TYPE_DECLARATION: 00494 emit_declaration(&gen, &parse.FullToken.FullDeclaration); 00495 break; 00496 00497 case TGSI_TOKEN_TYPE_INSTRUCTION: 00498 if (!emit_instruction(&gen, &parse.FullToken.FullInstruction )) { 00499 gen.error = true; 00500 } 00501 break; 00502 00503 default: 00504 assert(0); 00505 00506 } 00507 } 00508 00509 00510 if (gen.error) { 00511 /* terminate the SPE code */ 00512 return emit_END(&gen); 00513 } 00514 00515 #if DISASSEM 00516 printf("cell_gen_fragment_program nr instructions: %d\n", f->num_inst); 00517 printf("End %s\n", __FUNCTION__); 00518 #endif 00519 00520 tgsi_parse_free( &parse ); 00521 00522 return !gen.error; 00523 }