LLVMBuilderRef builder,
LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS],
const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS],
- LLVMValueRef system_values_array,
+ LLVMValueRef instance_id,
LLVMValueRef context_ptr,
struct lp_build_sampler_soa *draw_sampler,
boolean clamp_vertex_color)
vs_type,
NULL /*struct lp_build_mask_context *mask*/,
consts_ptr,
- system_values_array,
+ instance_id,
NULL /*pos*/,
inputs,
outputs,
LLVMValueRef stride, step, io_itr;
LLVMValueRef io_ptr, vbuffers_ptr, vb_ptr;
LLVMValueRef instance_id;
- LLVMValueRef system_values_array;
LLVMValueRef zero = lp_build_const_int32(gallivm, 0);
LLVMValueRef one = lp_build_const_int32(gallivm, 1);
struct draw_context *draw = llvm->draw;
lp_build_context_init(&bld, gallivm, lp_type_int(32));
- system_values_array = lp_build_system_values_array(gallivm, vs_info,
- instance_id, NULL);
-
/* function will return non-zero i32 value if any clipped vertices */
ret_ptr = lp_build_alloca(gallivm, int32_type, "");
LLVMBuildStore(builder, zero, ret_ptr);
builder,
outputs,
ptr_aos,
- system_values_array,
+ instance_id,
context_ptr,
sampler,
variant->key.clamp_vertex_color);
struct lp_type type,
struct lp_build_mask_context *mask,
LLVMValueRef consts_ptr,
- LLVMValueRef system_values_array,
+ LLVMValueRef instance_id,
const LLVMValueRef *pos,
const LLVMValueRef (*inputs)[4],
LLVMValueRef (*outputs)[4],
const struct tgsi_shader_info *info);
-LLVMValueRef
-lp_build_system_values_array(struct gallivm_state *gallivm,
- const struct tgsi_shader_info *info,
- LLVMValueRef instance_id,
- LLVMValueRef facing);
-
-
struct lp_exec_mask {
struct lp_build_context *bld;
*/
LLVMValueRef inputs_array;
- LLVMValueRef system_values_array;
+ LLVMValueRef instance_id;
/** bitmask indicating which register files are accessed indirectly */
unsigned indirect_files;
{
struct lp_build_tgsi_soa_context * bld = lp_soa_context(bld_base);
struct gallivm_state *gallivm = bld->bld_base.base.gallivm;
+ const struct tgsi_shader_info *info = bld->bld_base.info;
LLVMBuilderRef builder = gallivm->builder;
- LLVMValueRef index; /* index into the system value array */
- LLVMValueRef scalar, scalar_ptr;
+ LLVMValueRef res;
+ enum tgsi_opcode_type atype; // Actual type of the value
assert(!reg->Register.Indirect);
- index = lp_build_const_int32(gallivm, reg->Register.Index * 4 + swizzle);
+ switch (info->system_value_semantic_name[reg->Register.Index]) {
+ case TGSI_SEMANTIC_INSTANCEID:
+ res = lp_build_broadcast_scalar(&bld_base->uint_bld, bld->instance_id);
+ atype = TGSI_TYPE_UNSIGNED;
+ break;
- scalar_ptr = LLVMBuildGEP(builder, bld->system_values_array, &index, 1, "");
- scalar = LLVMBuildLoad(builder, scalar_ptr, "");
+ default:
+ assert(!"unexpected semantic in emit_fetch_system_value");
+ res = bld_base->base.zero;
+ atype = TGSI_TYPE_FLOAT;
+ break;
+ }
+
+ if (atype != stype) {
+ if (stype == TGSI_TYPE_FLOAT) {
+ res = LLVMBuildBitCast(builder, res, bld_base->base.vec_type, "");
+ } else if (stype == TGSI_TYPE_UNSIGNED) {
+ res = LLVMBuildBitCast(builder, res, bld_base->uint_bld.vec_type, "");
+ } else if (stype == TGSI_TYPE_SIGNED) {
+ res = LLVMBuildBitCast(builder, res, bld_base->int_bld.vec_type, "");
+ }
+ }
- return lp_build_broadcast_scalar(&bld->bld_base.base, scalar);
+ return res;
}
/**
struct lp_type type,
struct lp_build_mask_context *mask,
LLVMValueRef consts_ptr,
- LLVMValueRef system_values_array,
+ LLVMValueRef instance_id,
const LLVMValueRef *pos,
const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS],
LLVMValueRef (*outputs)[TGSI_NUM_CHANNELS],
lp_exec_mask_init(&bld.exec_mask, &bld.bld_base.base);
-
- bld.system_values_array = system_values_array;
+ bld.instance_id = instance_id;
lp_build_tgsi_llvm(&bld.bld_base, tokens);
}
}
-
-
-/**
- * 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
-lp_build_system_values_array(struct gallivm_state *gallivm,
- const struct tgsi_shader_info *info,
- LLVMValueRef instance_id,
- LLVMValueRef facing)
-{
- 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++) {
- LLVMValueRef index = lp_build_const_int32(gallivm, i * 4);
- LLVMValueRef ptr, value = 0;
-
- switch (info->system_value_semantic_name[i]) {
- case TGSI_SEMANTIC_INSTANCEID:
- /* convert instance ID from int to float */
- 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;
-}