* Function body
*/
- block = LLVMAppendBasicBlock(variant->function, "entry");
- builder = LLVMCreateBuilder();
+ block = LLVMAppendBasicBlockInContext(gallivm->context, variant->function, "entry");
+ builder = gallivm->builder;
+ assert(builder);
LLVMPositionBuilderAtEnd(builder, block);
- lp_build_context_init(&bld, builder, lp_type_int(32));
+ lp_build_context_init(&bld, llvm->gallivm, lp_type_int(32));
- system_values_array = lp_build_system_values_array(builder, vs_info,
++ system_values_array = lp_build_system_values_array(gallivm, vs_info,
+ instance_id, NULL);
+
end = lp_build_add(&bld, start, count);
- step = LLVMConstInt(LLVMInt32Type(), max_vertices, 0);
+ step = lp_build_const_int32(gallivm, max_vertices);
/* function will return non-zero i32 value if any clipped vertices */
- ret_ptr = lp_build_alloca(builder, LLVMInt32Type(), "");
- LLVMBuildStore(builder, LLVMConstInt(LLVMInt32Type(), 0, 0), ret_ptr);
+ ret_ptr = lp_build_alloca(gallivm, int32_type, "");
+ LLVMBuildStore(builder, lp_build_const_int32(gallivm, 0), ret_ptr);
/* code generated texture sampling */
sampler = draw_llvm_sampler_soa_create(
}
/* store clipmask in vertex header and positions in data */
- convert_to_aos(builder, io, outputs, clipmask,
+ convert_to_aos(gallivm, io, outputs, clipmask,
- draw->vs.vertex_shader->info.num_outputs,
- max_vertices);
+ vs_info->num_outputs, max_vertices);
}
- lp_build_loop_end_cond(builder, end, step, LLVMIntUGE, &lp_loop);
+ lp_build_loop_end_cond(&lp_loop, end, step, LLVMIntUGE);
sampler->destroy(sampler);
* Function body
*/
- block = LLVMAppendBasicBlock(variant->function_elts, "entry");
- builder = LLVMCreateBuilder();
+ block = LLVMAppendBasicBlockInContext(gallivm->context, variant->function_elts, "entry");
+ builder = gallivm->builder;
LLVMPositionBuilderAtEnd(builder, block);
- lp_build_context_init(&bld, builder, lp_type_int(32));
+ lp_build_context_init(&bld, gallivm, lp_type_int(32));
- system_values_array = lp_build_system_values_array(builder, vs_info,
++ system_values_array = lp_build_system_values_array(gallivm, vs_info,
+ instance_id, NULL);
+
+
- step = LLVMConstInt(LLVMInt32Type(), max_vertices, 0);
+ step = lp_build_const_int32(gallivm, max_vertices);
/* code generated texture sampling */
sampler = draw_llvm_sampler_soa_create(
* original positions in clip
* and transformed positions in data
*/
- convert_to_aos(builder, io, outputs, clipmask,
+ convert_to_aos(gallivm, io, outputs, clipmask,
- draw->vs.vertex_shader->info.num_outputs,
- max_vertices);
+ vs_info->num_outputs, max_vertices);
}
- lp_build_loop_end_cond(builder, fetch_count, step, LLVMIntUGE, &lp_loop);
+ lp_build_loop_end_cond(&lp_loop, fetch_count, step, LLVMIntUGE);
sampler->destroy(sampler);
const struct tgsi_shader_info *info);
-lp_build_system_values_array(LLVMBuilderRef builder,
+ LLVMValueRef
++lp_build_system_values_array(struct gallivm_state *gallivm,
+ const struct tgsi_shader_info *info,
+ LLVMValueRef instance_id,
+ LLVMValueRef facing);
+
+
#endif /* LP_BLD_TGSI_H */
}
break;
- index = lp_build_const_int32(reg->Register.Index * 4 + swizzle);
+ case TGSI_FILE_SYSTEM_VALUE:
+ assert(!reg->Register.Indirect);
+ {
+ LLVMValueRef index; /* index into the system value array */
+ LLVMValueRef scalar, scalar_ptr;
+
- scalar_ptr = LLVMBuildGEP(bld->base.builder, bld->system_values_array,
++ index = lp_build_const_int32(gallivm,
++ reg->Register.Index * 4 + swizzle);
+
- scalar = LLVMBuildLoad(bld->base.builder, scalar_ptr, "");
++ scalar_ptr = LLVMBuildGEP(builder, bld->system_values_array,
+ &index, 1, "");
++ scalar = LLVMBuildLoad(builder, scalar_ptr, "");
+
+ res = lp_build_broadcast_scalar(&bld->base, scalar);
+ }
+ break;
+
default:
assert(0 && "invalid src register in emit_fetch()");
return bld->base.undef;
FREE( bld.instructions );
}
-lp_build_system_values_array(LLVMBuilderRef builder,
+
+ /**
+ * Build up the system values array out of individual values such as
+ * the instance ID, front-face, primitive ID, etc. The shader info is
+ * used to determine which system values are needed and where to put
+ * them in the system values array.
+ *
+ * XXX only instance ID is implemented at this time.
+ *
+ * The system values register file is similar to the constants buffer.
+ * Example declaration:
+ * DCL SV[0], INSTANCEID
+ * Example instruction:
+ * MOVE foo, SV[0].xxxx;
+ *
+ * \return LLVM float array (interpreted as float [][4])
+ */
+ LLVMValueRef
- LLVMValueRef size = lp_build_const_int32(4 * info->num_system_values);
- LLVMValueRef array = lp_build_array_alloca(builder, LLVMFloatType(),
++lp_build_system_values_array(struct gallivm_state *gallivm,
+ const struct tgsi_shader_info *info,
+ LLVMValueRef instance_id,
+ LLVMValueRef facing)
+ {
- LLVMValueRef index = lp_build_const_int32(i * 4);
++ LLVMValueRef size = lp_build_const_int32(gallivm, 4 * info->num_system_values);
++ LLVMTypeRef float_t = LLVMFloatTypeInContext(gallivm->context);
++ LLVMValueRef array = lp_build_array_alloca(gallivm, float_t,
+ size, "sysvals_array");
+ unsigned i;
+
+ for (i = 0; i < info->num_system_values; i++) {
- value = LLVMBuildSIToFP(builder, instance_id, LLVMFloatType(),
++ LLVMValueRef index = lp_build_const_int32(gallivm, i * 4);
+ LLVMValueRef ptr, value;
+
+ switch (info->system_value_semantic_name[i]) {
+ case TGSI_SEMANTIC_INSTANCEID:
+ /* convert instance ID from int to float */
- ptr = LLVMBuildGEP(builder, array, &index, 1, "");
- LLVMBuildStore(builder, value, ptr);
++ value = LLVMBuildSIToFP(gallivm->builder, instance_id, float_t,
+ "sysval_instanceid");
+ break;
+ case TGSI_SEMANTIC_FACE:
+ /* fall-through */
+ default:
+ assert(0 && "unexpected semantic in build_system_values_array()");
+ }
+
++ ptr = LLVMBuildGEP(gallivm->builder, array, &index, 1, "");
++ LLVMBuildStore(gallivm->builder, value, ptr);
+ }
+
+ return array;
+ }
}
}
- lp_build_interp_soa_update_inputs(interp, i);
+ lp_build_interp_soa_update_inputs(interp, gallivm, i);
/* Build the actual shader */
- lp_build_tgsi_soa(builder, tokens, type, &mask,
+ lp_build_tgsi_soa(gallivm, tokens, type, &mask,
- consts_ptr, interp->pos, interp->inputs,
+ consts_ptr, NULL, /* sys values array */
+ interp->pos, interp->inputs,
outputs, sampler, &shader->info.base);
-
/* Alpha test */
if (key->alpha.enabled) {
int color0 = find_output_by_semantic(&shader->info.base,
* something doing a more clever packing would use something other
* than InputsRead/OutputsWritten.
*/
- const glsl_type *element_type;
- int element_size;
-
- if (var->type->is_array())
- element_type = var->type->fields.array;
- else
- element_type = var->type;
-
- if (element_type->is_matrix())
- element_size = element_type->matrix_columns;
- else
- element_size = 1;
-
- index *= element_size;
- for (int i = 0; i < element_size; i++) {
- if (var->mode == ir_var_system_value) {
- prog->SystemValuesRead |= (1 << (var->location + index + i));
- }
- else if (var->mode == ir_var_in)
- prog->InputsRead |= BITFIELD64_BIT(var->location + index + i);
+
+ for (int i = 0; i < len; i++) {
+ if (var->mode == ir_var_in)
+ prog->InputsRead |= BITFIELD64_BIT(var->location + offset + i);
++ else if (var->mode == ir_var_system_value)
++ prog->SystemValuesRead |= (1 << (var->location + offset + i));
else
- prog->OutputsWritten |= BITFIELD64_BIT(var->location + index + i);
+ prog->OutputsWritten |= BITFIELD64_BIT(var->location + offset + i);
}
}
for (i = 0; i < VB->Count; i++) {
GLuint attr;
- init_machine(ctx, machine);
- init_machine(ctx, &machine, tnl->CurInstance);
++ init_machine(ctx, machine, tnl->CurInstance);
#if 0
printf("Input %d: %f, %f, %f, %f\n", i,