From 147dc2354c21f098a2a63a085c21ec10252cab24 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 2 Jun 2010 09:56:05 +0100 Subject: llvmpipe: Centralize all position interpolation in lp_bld_interp.c. --- src/gallium/drivers/llvmpipe/lp_bld_interp.c | 42 ++++++++++++++++++++++---- src/gallium/drivers/llvmpipe/lp_bld_interp.h | 7 +++-- src/gallium/drivers/llvmpipe/lp_state_fs.c | 45 +--------------------------- 3 files changed, 43 insertions(+), 51 deletions(-) diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.c b/src/gallium/drivers/llvmpipe/lp_bld_interp.c index d1f0185684d..49af8289954 100644 --- a/src/gallium/drivers/llvmpipe/lp_bld_interp.c +++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.c @@ -75,6 +75,10 @@ */ +static const unsigned char quad_offset_x[4] = {0, 1, 0, 1}; +static const unsigned char quad_offset_y[4] = {0, 0, 1, 1}; + + static void attrib_name(LLVMValueRef val, unsigned attrib, unsigned chan, const char *suffix) { @@ -281,18 +285,46 @@ attribs_update(struct lp_build_interp_soa_context *bld, int quad_index) /** * Generate the position vectors. * - * Parameter x0, y0 are the integer values with the quad upper left coordinates. + * Parameter x0, y0 are the integer values with upper left coordinates. */ static void pos_init(struct lp_build_interp_soa_context *bld, LLVMValueRef x0, LLVMValueRef y0) { - lp_build_name(x0, "pos.x"); - lp_build_name(y0, "pos.y"); + LLVMBuilderRef builder = bld->base.builder; + LLVMTypeRef int_elem_type = LLVMInt32Type(); + LLVMTypeRef int_vec_type = LLVMVectorType(int_elem_type, QUAD_SIZE); + LLVMTypeRef elem_type = LLVMFloatType(); + LLVMTypeRef vec_type = LLVMVectorType(elem_type, QUAD_SIZE); + LLVMValueRef x_offsets[QUAD_SIZE]; + LLVMValueRef y_offsets[QUAD_SIZE]; + unsigned i; + + /* + * Derive from the quad's upper left scalar coordinates the coordinates for + * all other quad pixels + */ + + x0 = lp_build_broadcast(builder, int_vec_type, x0); + y0 = lp_build_broadcast(builder, int_vec_type, y0); + + for(i = 0; i < QUAD_SIZE; ++i) { + x_offsets[i] = LLVMConstInt(int_elem_type, quad_offset_x[i], 0); + y_offsets[i] = LLVMConstInt(int_elem_type, quad_offset_y[i], 0); + } + + x0 = LLVMBuildAdd(builder, x0, LLVMConstVector(x_offsets, QUAD_SIZE), ""); + y0 = LLVMBuildAdd(builder, y0, LLVMConstVector(y_offsets, QUAD_SIZE), ""); + + bld->x0 = LLVMBuildSIToFP(builder, x0, vec_type, ""); + bld->y0 = LLVMBuildSIToFP(builder, y0, vec_type, ""); + + lp_build_name(bld->x0, "pos.x"); + lp_build_name(bld->y0, "pos.y"); - bld->attribs[0][0] = x0; - bld->attribs[0][1] = y0; + bld->attribs[0][0] = bld->x0; + bld->attribs[0][1] = bld->y0; } diff --git a/src/gallium/drivers/llvmpipe/lp_bld_interp.h b/src/gallium/drivers/llvmpipe/lp_bld_interp.h index 79d1e51605a..8ba06916092 100644 --- a/src/gallium/drivers/llvmpipe/lp_bld_interp.h +++ b/src/gallium/drivers/llvmpipe/lp_bld_interp.h @@ -57,6 +57,9 @@ struct lp_build_interp_soa_context unsigned mask[1 + PIPE_MAX_SHADER_INPUTS]; /**< TGSI_WRITE_MASK_x */ enum lp_interp interp[1 + PIPE_MAX_SHADER_INPUTS]; + LLVMValueRef x0; + LLVMValueRef y0; + LLVMValueRef a0 [1 + PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS]; LLVMValueRef dadx[1 + PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS]; LLVMValueRef dady[1 + PIPE_MAX_SHADER_INPUTS][NUM_CHANNELS]; @@ -83,8 +86,8 @@ lp_build_interp_soa_init(struct lp_build_interp_soa_context *bld, LLVMValueRef a0_ptr, LLVMValueRef dadx_ptr, LLVMValueRef dady_ptr, - LLVMValueRef x0, - LLVMValueRef y0); + LLVMValueRef x, + LLVMValueRef y); void lp_build_interp_soa_update(struct lp_build_interp_soa_context *bld, diff --git a/src/gallium/drivers/llvmpipe/lp_state_fs.c b/src/gallium/drivers/llvmpipe/lp_state_fs.c index 835175db138..c8ef1281f4e 100644 --- a/src/gallium/drivers/llvmpipe/lp_state_fs.c +++ b/src/gallium/drivers/llvmpipe/lp_state_fs.c @@ -99,45 +99,6 @@ #include -static const unsigned char quad_offset_x[4] = {0, 1, 0, 1}; -static const unsigned char quad_offset_y[4] = {0, 0, 1, 1}; - - -/* - * Derive from the quad's upper left scalar coordinates the coordinates for - * all other quad pixels - */ -static void -generate_pos0(LLVMBuilderRef builder, - LLVMValueRef x, - LLVMValueRef y, - LLVMValueRef *x0, - LLVMValueRef *y0) -{ - LLVMTypeRef int_elem_type = LLVMInt32Type(); - LLVMTypeRef int_vec_type = LLVMVectorType(int_elem_type, QUAD_SIZE); - LLVMTypeRef elem_type = LLVMFloatType(); - LLVMTypeRef vec_type = LLVMVectorType(elem_type, QUAD_SIZE); - LLVMValueRef x_offsets[QUAD_SIZE]; - LLVMValueRef y_offsets[QUAD_SIZE]; - unsigned i; - - x = lp_build_broadcast(builder, int_vec_type, x); - y = lp_build_broadcast(builder, int_vec_type, y); - - for(i = 0; i < QUAD_SIZE; ++i) { - x_offsets[i] = LLVMConstInt(int_elem_type, quad_offset_x[i], 0); - y_offsets[i] = LLVMConstInt(int_elem_type, quad_offset_y[i], 0); - } - - x = LLVMBuildAdd(builder, x, LLVMConstVector(x_offsets, QUAD_SIZE), ""); - y = LLVMBuildAdd(builder, y, LLVMConstVector(y_offsets, QUAD_SIZE), ""); - - *x0 = LLVMBuildSIToFP(builder, x, vec_type, ""); - *y0 = LLVMBuildSIToFP(builder, y, vec_type, ""); -} - - /** * Generate the depth /stencil test code. */ @@ -635,8 +596,6 @@ generate_fragment(struct llvmpipe_context *lp, LLVMValueRef c0, c1, c2, step0_ptr, step1_ptr, step2_ptr, counter = NULL; LLVMBasicBlockRef block; LLVMBuilderRef builder; - LLVMValueRef x0; - LLVMValueRef y0; struct lp_build_sampler_soa *sampler; struct lp_build_interp_soa_context interp; LLVMValueRef fs_mask[LP_MAX_VECTOR_LENGTH]; @@ -757,8 +716,6 @@ generate_fragment(struct llvmpipe_context *lp, builder = LLVMCreateBuilder(); LLVMPositionBuilderAtEnd(builder, block); - generate_pos0(builder, x, y, &x0, &y0); - /* * The shader input interpolation info is not explicitely baked in the * shader key, but everything it derives from (TGSI, and flatshade) is @@ -769,7 +726,7 @@ generate_fragment(struct llvmpipe_context *lp, lp->inputs, builder, fs_type, a0_ptr, dadx_ptr, dady_ptr, - x0, y0); + x, y); /* code generated texture sampling */ sampler = lp_llvm_sampler_soa_create(key->sampler, context_ptr); -- cgit v1.2.3