llvmpipe: First minify the texture size, then broadcast.

This commit is contained in:
José Fonseca 2010-10-08 19:11:32 +01:00
parent f5b5fb32d3
commit 438390418d
3 changed files with 42 additions and 32 deletions

View File

@ -235,7 +235,7 @@ lp_build_rho(struct lp_build_sample_context *bld,
rho_vec = lp_build_max(float_size_bld, rho_x, rho_y); rho_vec = lp_build_max(float_size_bld, rho_x, rho_y);
float_size = lp_build_int_to_float(float_size_bld, bld->uint_size); float_size = lp_build_int_to_float(float_size_bld, bld->int_size);
rho_vec = lp_build_mul(float_size_bld, rho_vec, float_size); rho_vec = lp_build_mul(float_size_bld, rho_vec, float_size);
@ -583,18 +583,22 @@ lp_build_get_const_mipmap_level(struct lp_build_sample_context *bld,
* Return max(1, base_size >> level); * Return max(1, base_size >> level);
*/ */
static LLVMValueRef static LLVMValueRef
lp_build_minify(struct lp_build_sample_context *bld, lp_build_minify(struct lp_build_context *bld,
LLVMValueRef base_size, LLVMValueRef base_size,
LLVMValueRef level) LLVMValueRef level)
{ {
if (level == bld->int_coord_bld.zero) { assert(lp_check_value(bld->type, base_size));
assert(lp_check_value(bld->type, level));
if (level == bld->zero) {
/* if we're using mipmap level zero, no minification is needed */ /* if we're using mipmap level zero, no minification is needed */
return base_size; return base_size;
} }
else { else {
LLVMValueRef size = LLVMValueRef size =
LLVMBuildLShr(bld->builder, base_size, level, "minify"); LLVMBuildLShr(bld->builder, base_size, level, "minify");
size = lp_build_max(&bld->int_coord_bld, size, bld->int_coord_bld.one); assert(bld->type.sign);
size = lp_build_max(bld, size, bld->one);
return size; return size;
} }
} }
@ -634,15 +638,29 @@ lp_build_mipmap_level_sizes(struct lp_build_sample_context *bld,
{ {
const unsigned dims = bld->dims; const unsigned dims = bld->dims;
LLVMValueRef ilevel_vec; LLVMValueRef ilevel_vec;
LLVMValueRef size_vec;
LLVMValueRef width, height, depth;
LLVMTypeRef i32t = LLVMInt32Type();
ilevel_vec = lp_build_broadcast_scalar(&bld->int_coord_bld, ilevel); ilevel_vec = lp_build_broadcast_scalar(&bld->int_size_bld, ilevel);
/* /*
* Compute width, height, depth at mipmap level 'ilevel' * Compute width, height, depth at mipmap level 'ilevel'
*/ */
*out_width_vec = lp_build_minify(bld, bld->width_vec, ilevel_vec); size_vec = lp_build_minify(&bld->int_size_bld, bld->int_size, ilevel_vec);
if (dims <= 1) {
width = size_vec;
}
else {
width = LLVMBuildExtractElement(bld->builder, size_vec,
LLVMConstInt(i32t, 0, 0), "");
}
*out_width_vec = lp_build_broadcast_scalar(&bld->int_coord_bld, width);
if (dims >= 2) { if (dims >= 2) {
*out_height_vec = lp_build_minify(bld, bld->height_vec, ilevel_vec); height = LLVMBuildExtractElement(bld->builder, size_vec,
LLVMConstInt(i32t, 1, 0), "");
*out_height_vec = lp_build_broadcast_scalar(&bld->int_coord_bld, height);
*row_stride_vec = lp_build_get_level_stride_vec(bld, *row_stride_vec = lp_build_get_level_stride_vec(bld,
bld->row_stride_array, bld->row_stride_array,
ilevel); ilevel);
@ -651,7 +669,9 @@ lp_build_mipmap_level_sizes(struct lp_build_sample_context *bld,
bld->img_stride_array, bld->img_stride_array,
ilevel); ilevel);
if (dims == 3) { if (dims == 3) {
*out_depth_vec = lp_build_minify(bld, bld->depth_vec, ilevel_vec); depth = LLVMBuildExtractElement(bld->builder, size_vec,
LLVMConstInt(i32t, 2, 0), "");
*out_depth_vec = lp_build_broadcast_scalar(&bld->int_coord_bld, depth);
} }
} }
} }

View File

@ -206,8 +206,8 @@ struct lp_build_sample_context
struct lp_build_context int_coord_bld; struct lp_build_context int_coord_bld;
/** Unsigned integer texture size */ /** Unsigned integer texture size */
struct lp_type uint_size_type; struct lp_type int_size_type;
struct lp_build_context uint_size_bld; struct lp_build_context int_size_bld;
/** Unsigned integer texture size */ /** Unsigned integer texture size */
struct lp_type float_size_type; struct lp_type float_size_type;
@ -225,13 +225,8 @@ struct lp_build_sample_context
LLVMValueRef img_stride_array; LLVMValueRef img_stride_array;
LLVMValueRef data_array; LLVMValueRef data_array;
/** Unsigned vector with texture width, height, depth */ /** Integer vector with texture width, height, depth */
LLVMValueRef uint_size; LLVMValueRef int_size;
/* width, height, depth as uint vectors */
LLVMValueRef width_vec;
LLVMValueRef height_vec;
LLVMValueRef depth_vec;
}; };

View File

@ -1170,7 +1170,7 @@ lp_build_sample_soa(LLVMBuilderRef builder,
bld.int_coord_type = lp_int_type(type); bld.int_coord_type = lp_int_type(type);
bld.float_size_type = lp_type_float(32); bld.float_size_type = lp_type_float(32);
bld.float_size_type.length = dims > 1 ? 4 : 1; bld.float_size_type.length = dims > 1 ? 4 : 1;
bld.uint_size_type = lp_uint_type(bld.float_size_type); bld.int_size_type = lp_int_type(bld.float_size_type);
bld.texel_type = type; bld.texel_type = type;
float_vec_type = lp_type_float_vec(32); float_vec_type = lp_type_float_vec(32);
@ -1181,7 +1181,7 @@ lp_build_sample_soa(LLVMBuilderRef builder,
lp_build_context_init(&bld.coord_bld, builder, bld.coord_type); lp_build_context_init(&bld.coord_bld, builder, bld.coord_type);
lp_build_context_init(&bld.uint_coord_bld, builder, bld.uint_coord_type); lp_build_context_init(&bld.uint_coord_bld, builder, bld.uint_coord_type);
lp_build_context_init(&bld.int_coord_bld, builder, bld.int_coord_type); lp_build_context_init(&bld.int_coord_bld, builder, bld.int_coord_type);
lp_build_context_init(&bld.uint_size_bld, builder, bld.uint_size_type); lp_build_context_init(&bld.int_size_bld, builder, bld.int_size_type);
lp_build_context_init(&bld.float_size_bld, builder, bld.float_size_type); lp_build_context_init(&bld.float_size_bld, builder, bld.float_size_type);
lp_build_context_init(&bld.texel_bld, builder, bld.texel_type); lp_build_context_init(&bld.texel_bld, builder, bld.texel_type);
@ -1198,28 +1198,23 @@ lp_build_sample_soa(LLVMBuilderRef builder,
t = coords[1]; t = coords[1];
r = coords[2]; r = coords[2];
/* width, height, depth as single uint vector */ /* width, height, depth as single int vector */
if (dims <= 1) { if (dims <= 1) {
bld.uint_size = bld.width; bld.int_size = bld.width;
} }
else { else {
bld.uint_size = LLVMBuildInsertElement(builder, bld.uint_size_bld.undef, bld.int_size = LLVMBuildInsertElement(builder, bld.int_size_bld.undef,
bld.width, LLVMConstInt(i32t, 0, 0), ""); bld.width, LLVMConstInt(i32t, 0, 0), "");
if (dims >= 2) { if (dims >= 2) {
bld.uint_size = LLVMBuildInsertElement(builder, bld.uint_size, bld.int_size = LLVMBuildInsertElement(builder, bld.int_size,
bld.height, LLVMConstInt(i32t, 1, 0), ""); bld.height, LLVMConstInt(i32t, 1, 0), "");
if (dims >= 3) { if (dims >= 3) {
bld.uint_size = LLVMBuildInsertElement(builder, bld.uint_size, bld.int_size = LLVMBuildInsertElement(builder, bld.int_size,
bld.depth, LLVMConstInt(i32t, 2, 0), ""); bld.depth, LLVMConstInt(i32t, 2, 0), "");
} }
} }
} }
/* width, height, depth as uint vectors */
bld.width_vec = lp_build_broadcast_scalar(&bld.uint_coord_bld, bld.width);
bld.height_vec = lp_build_broadcast_scalar(&bld.uint_coord_bld, bld.height);
bld.depth_vec = lp_build_broadcast_scalar(&bld.uint_coord_bld, bld.depth);
if (0) { if (0) {
/* For debug: no-op texture sampling */ /* For debug: no-op texture sampling */
lp_build_sample_nop(bld.texel_type, texel_out); lp_build_sample_nop(bld.texel_type, texel_out);