static void handle_immediate(struct tgsi_to_rc * ttr, struct tgsi_full_immediate * imm, unsigned index) { struct rc_constant constant; unsigned swizzle = 0; boolean can_swizzle = TRUE; unsigned i; for (i = 0; i < 4; i++) { if (imm->u[i].Float == 0.0f) { swizzle |= RC_SWIZZLE_ZERO << (i * 3); } else if (imm->u[i].Float == 0.5f && ttr->use_half_swizzles) { swizzle |= RC_SWIZZLE_HALF << (i * 3); } else if (imm->u[i].Float == 1.0f) { swizzle |= RC_SWIZZLE_ONE << (i * 3); } else { can_swizzle = FALSE; break; } } if (can_swizzle) { ttr->imms_to_swizzle[ttr->imms_to_swizzle_count].index = index; ttr->imms_to_swizzle[ttr->imms_to_swizzle_count].swizzle = swizzle; ttr->imms_to_swizzle_count++; } else { constant.Type = RC_CONSTANT_IMMEDIATE; constant.Size = 4; for(i = 0; i < 4; ++i) constant.u.Immediate[i] = imm->u[i].Float; rc_constants_add(&ttr->compiler->Program.Constants, &constant); } }
void r300_tgsi_to_rc(struct tgsi_to_rc * ttr, const struct tgsi_token * tokens) { struct tgsi_full_instruction *inst; struct tgsi_parse_context parser; unsigned imm_index = 0; int i; /* Allocate constants placeholders. * * Note: What if declared constants are not contiguous? */ for(i = 0; i <= ttr->info->file_max[TGSI_FILE_CONSTANT]; ++i) { struct rc_constant constant; memset(&constant, 0, sizeof(constant)); constant.Type = RC_CONSTANT_EXTERNAL; constant.Size = 4; constant.u.External = i; rc_constants_add(&ttr->compiler->Program.Constants, &constant); } ttr->immediate_offset = ttr->compiler->Program.Constants.Count; ttr->imms_to_swizzle = malloc(ttr->info->immediate_count * sizeof(struct swizzled_imms)); ttr->imms_to_swizzle_count = 0; tgsi_parse_init(&parser, tokens); while (!tgsi_parse_end_of_tokens(&parser)) { tgsi_parse_token(&parser); switch (parser.FullToken.Token.Type) { case TGSI_TOKEN_TYPE_DECLARATION: break; case TGSI_TOKEN_TYPE_IMMEDIATE: handle_immediate(ttr, &parser.FullToken.FullImmediate, imm_index); imm_index++; break; case TGSI_TOKEN_TYPE_INSTRUCTION: inst = &parser.FullToken.FullInstruction; /* This hack with the RET opcode woudn't work with * conditionals. */ if (inst->Instruction.Opcode == TGSI_OPCODE_END || inst->Instruction.Opcode == TGSI_OPCODE_RET) { break; } transform_instruction(ttr, inst); break; } } tgsi_parse_free(&parser); free(ttr->imms_to_swizzle); rc_calculate_inputs_outputs(ttr->compiler); }
static void handle_immediate(struct tgsi_to_rc * ttr, struct tgsi_full_immediate * imm) { struct rc_constant constant; int i; constant.Type = RC_CONSTANT_IMMEDIATE; constant.Size = 4; for(i = 0; i < 4; ++i) constant.u.Immediate[i] = imm->u[i].Float; rc_constants_add(&ttr->compiler->Program.Constants, &constant); }
/** * Add an immediate vector to the constant list, while trying to avoid * duplicates. */ unsigned rc_constants_add_immediate_vec4(struct rc_constant_list * c, const float * data) { unsigned index; struct rc_constant constant; for(index = 0; index < c->Count; ++index) { if (c->Constants[index].Type == RC_CONSTANT_IMMEDIATE) { if (!memcmp(c->Constants[index].u.Immediate, data, sizeof(float)*4)) return index; } } memset(&constant, 0, sizeof(constant)); constant.Type = RC_CONSTANT_IMMEDIATE; constant.Size = 4; memcpy(constant.u.Immediate, data, sizeof(float) * 4); return rc_constants_add(c, &constant); }
/** * Add a state vector to the constant list, while trying to avoid duplicates. */ unsigned rc_constants_add_state(struct rc_constant_list * c, unsigned state0, unsigned state1) { unsigned index; struct rc_constant constant; for(index = 0; index < c->Count; ++index) { if (c->Constants[index].Type == RC_CONSTANT_STATE) { if (c->Constants[index].u.State[0] == state0 && c->Constants[index].u.State[1] == state1) return index; } } memset(&constant, 0, sizeof(constant)); constant.Type = RC_CONSTANT_STATE; constant.Size = 4; constant.u.State[0] = state0; constant.u.State[1] = state1; return rc_constants_add(c, &constant); }
void r300_tgsi_to_rc(struct tgsi_to_rc * ttr, const struct tgsi_token * tokens) { struct tgsi_parse_context parser; int i; /* Allocate constants placeholders. * * Note: What if declared constants are not contiguous? */ for(i = 0; i <= ttr->info->file_max[TGSI_FILE_CONSTANT]; ++i) { struct rc_constant constant; memset(&constant, 0, sizeof(constant)); constant.Type = RC_CONSTANT_EXTERNAL; constant.Size = 4; constant.u.External = i; rc_constants_add(&ttr->compiler->Program.Constants, &constant); } ttr->immediate_offset = ttr->compiler->Program.Constants.Count; tgsi_parse_init(&parser, tokens); while (!tgsi_parse_end_of_tokens(&parser)) { tgsi_parse_token(&parser); switch (parser.FullToken.Token.Type) { case TGSI_TOKEN_TYPE_DECLARATION: break; case TGSI_TOKEN_TYPE_IMMEDIATE: handle_immediate(ttr, &parser.FullToken.FullImmediate); break; case TGSI_TOKEN_TYPE_INSTRUCTION: transform_instruction(ttr, &parser.FullToken.FullInstruction); break; } } tgsi_parse_free(&parser); rc_calculate_inputs_outputs(ttr->compiler); }
/** * Add an immediate scalar to the constant list, while trying to avoid * duplicates. */ unsigned rc_constants_add_immediate_scalar(struct rc_constant_list * c, float data, unsigned * swizzle) { unsigned index; int free_index = -1; struct rc_constant constant; for(index = 0; index < c->Count; ++index) { if (c->Constants[index].Type == RC_CONSTANT_IMMEDIATE) { unsigned comp; for(comp = 0; comp < c->Constants[index].Size; ++comp) { if (c->Constants[index].u.Immediate[comp] == data) { *swizzle = RC_MAKE_SWIZZLE(comp, comp, comp, comp); return index; } } if (c->Constants[index].Size < 4) free_index = index; } } if (free_index >= 0) { unsigned comp = c->Constants[free_index].Size++; c->Constants[free_index].u.Immediate[comp] = data; *swizzle = RC_MAKE_SWIZZLE(comp, comp, comp, comp); return free_index; } memset(&constant, 0, sizeof(constant)); constant.Type = RC_CONSTANT_IMMEDIATE; constant.Size = 1; constant.u.Immediate[0] = data; *swizzle = RC_SWIZZLE_XXXX; return rc_constants_add(c, &constant); }