if (velem->instance_divisor) {
/* Index is equal to the start instance plus the number of current
* instance divided by the divisor. In this case we compute it as:
- * index = start_instance + ((instance_id - start_instance) / divisor)
+ * index = start_instance + (instance_id / divisor)
*/
LLVMValueRef current_instance;
index = lp_build_const_int32(gallivm, draw->start_instance);
- current_instance = LLVMBuildSub(builder, instance_id, index, "");
- current_instance = LLVMBuildUDiv(builder, current_instance,
+ current_instance = LLVMBuildUDiv(builder, instance_id,
lp_build_const_int32(gallivm, velem->instance_divisor),
"instance_divisor");
- index = LLVMBuildAdd(builder, index, current_instance, "instance");
+ index = lp_build_uadd_overflow(gallivm, index, current_instance, &ofbit);
}
stride = lp_build_umul_overflow(gallivm, vb_stride, index, &ofbit);
*/
for (instance = 0; instance < info->instance_count; instance++) {
- draw->instance_id = instance + info->start_instance;
+ unsigned instance_idx = instance + info->start_instance;
draw->start_instance = info->start_instance;
+ draw->instance_id = instance;
/* check for overflow */
- if (draw->instance_id < instance ||
- draw->instance_id < info->start_instance) {
+ if (instance_idx < instance ||
+ instance_idx < draw->start_instance) {
/* if we overflown just set the instance id to the max */
draw->instance_id = 0xffffffff;
}
if (tg->attrib[attr].instance_divisor) {
index = start_instance;
- index += (instance_id - start_instance) /
- tg->attrib[attr].instance_divisor;
+ index += (instance_id / tg->attrib[attr].instance_divisor);
/* XXX we need to clamp the index here too, but to a
* per-array max value, not the draw->pt.max_index value
* that's being given to us via translate->set_buffer().
struct x86_reg tmp_EDX = p->tmp2_EDX;
struct x86_reg tmp_ECX = p->src_ECX;
- /* instance_num = instance_id - start_instance */
- x86_mov(p->func, tmp_EDX, start_instance);
- x86_sub(p->func, tmp_EAX, tmp_EDX);
-
/* TODO: Add x86_shr() to rtasm and use it whenever
* instance divisor is power of two.
*/