From 05921fd4e5305da68bb269748cb0ef059e1db417 Mon Sep 17 00:00:00 2001 From: Keith Whitwell Date: Tue, 19 Oct 2010 22:11:49 -0700 Subject: [PATCH] draw: make sure viewport gets updated in draw llvm shader The viewport state was being baked in at compile time (oops...) --- src/gallium/auxiliary/draw/draw_llvm.c | 66 +++++++++++++--------- src/gallium/auxiliary/draw/draw_llvm.h | 6 +- .../draw/draw_pt_fetch_shade_pipeline_llvm.c | 2 + 3 files changed, 47 insertions(+), 27 deletions(-) diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c index 338127d..beb955f 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.c +++ b/src/gallium/auxiliary/draw/draw_llvm.c @@ -131,13 +131,14 @@ init_globals(struct draw_llvm *llvm) /* struct draw_jit_context */ { - LLVMTypeRef elem_types[4]; + LLVMTypeRef elem_types[5]; LLVMTypeRef context_type; elem_types[0] = LLVMPointerType(LLVMFloatType(), 0); /* vs_constants */ elem_types[1] = LLVMPointerType(LLVMFloatType(), 0); /* gs_constants */ elem_types[2] = LLVMPointerType(LLVMArrayType(LLVMArrayType(LLVMFloatType(), 4), 12), 0); /* planes */ - elem_types[3] = LLVMArrayType(texture_type, + elem_types[3] = LLVMPointerType(LLVMFloatType(), 0); /* viewport */ + elem_types[4] = LLVMArrayType(texture_type, PIPE_MAX_VERTEX_SAMPLERS); /* textures */ context_type = LLVMStructType(elem_types, Elements(elem_types), 0); @@ -784,21 +785,38 @@ store_clip(LLVMBuilderRef builder, } +/* Equivalent of _mm_set1_ps(a) + */ +static LLVMValueRef vec4f_from_scalar(LLVMBuilderRef bld, + LLVMValueRef a, + const char *name) +{ + LLVMValueRef res = LLVMGetUndef(LLVMVectorType(LLVMFloatType(), 4)); + int i; + + for(i = 0; i < 4; ++i) { + LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0); + res = LLVMBuildInsertElement(bld, res, a, index, i == 3 ? name : ""); + } + + return res; +} + /* * Transforms the outputs for viewport mapping */ static void generate_viewport(struct draw_llvm *llvm, LLVMBuilderRef builder, - LLVMValueRef (*outputs)[NUM_CHANNELS]) + LLVMValueRef (*outputs)[NUM_CHANNELS], + LLVMValueRef context_ptr) { int i; - const float *scaleA = llvm->draw->viewport.scale; - const float *transA = llvm->draw->viewport.translate; struct lp_type f32_type = lp_type_float_vec(32); LLVMValueRef out3 = LLVMBuildLoad(builder, outputs[0][3], ""); /*w0 w1 w2 w3*/ LLVMValueRef const1 = lp_build_const_vec(f32_type, 1.0); /*1.0 1.0 1.0 1.0*/ - + LLVMValueRef vp_ptr = draw_jit_context_viewport(builder, context_ptr); + /* for 1/w convention*/ out3 = LLVMBuildFDiv(builder, const1, out3, ""); LLVMBuildStore(builder, out3, outputs[0][3]); @@ -806,9 +824,21 @@ generate_viewport(struct draw_llvm *llvm, /* Viewport Mapping */ for (i=0; i<3; i++){ LLVMValueRef out = LLVMBuildLoad(builder, outputs[0][i], ""); /*x0 x1 x2 x3*/ - LLVMValueRef scale = lp_build_const_vec(f32_type, scaleA[i]); /*sx sx sx sx*/ - LLVMValueRef trans = lp_build_const_vec(f32_type, transA[i]); /*tx tx tx tx*/ + LLVMValueRef scale; + LLVMValueRef trans; + LLVMValueRef scale_i; + LLVMValueRef trans_i; + LLVMValueRef index; + index = LLVMConstInt(LLVMInt32Type(), i, 0); + scale_i = LLVMBuildGEP(builder, vp_ptr, &index, 1, ""); + + index = LLVMConstInt(LLVMInt32Type(), i+4, 0); + trans_i = LLVMBuildGEP(builder, vp_ptr, &index, 1, ""); + + scale = vec4f_from_scalar(builder, LLVMBuildLoad(builder, scale_i, ""), "scale"); + trans = vec4f_from_scalar(builder, LLVMBuildLoad(builder, trans_i, ""), "trans"); + /* divide by w */ out = LLVMBuildMul(builder, out, out3, ""); /* mult by scale */ @@ -822,22 +852,6 @@ generate_viewport(struct draw_llvm *llvm, } -/* Equivalent of _mm_set1_ps(a) - */ -static LLVMValueRef vec4f_from_scalar(LLVMBuilderRef bld, - LLVMValueRef a, - const char *name) -{ - LLVMValueRef res = LLVMGetUndef(LLVMVectorType(LLVMFloatType(), 4)); - int i; - - for(i = 0; i < 4; ++i) { - LLVMValueRef index = LLVMConstInt(LLVMInt32Type(), i, 0); - res = LLVMBuildInsertElement(bld, res, a, index, i == 3 ? name : ""); - } - - return res; -} /* * Returns clipmask as 4xi32 bitmask for the 4 vertices @@ -1143,7 +1157,7 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant) /* do viewport mapping */ if (!bypass_viewport){ - generate_viewport(llvm, builder, outputs); + generate_viewport(llvm, builder, outputs, context_ptr); } /* store clipmask in vertex header and positions in data */ @@ -1354,7 +1368,7 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian /* do viewport mapping */ if (!bypass_viewport){ - generate_viewport(llvm, builder, outputs); + generate_viewport(llvm, builder, outputs, context_ptr); } /* store clipmask in vertex header, diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h index aa984ed..c3c30c0 100644 --- a/src/gallium/auxiliary/draw/draw_llvm.h +++ b/src/gallium/auxiliary/draw/draw_llvm.h @@ -97,6 +97,7 @@ struct draw_jit_context const float *vs_constants; const float *gs_constants; float (*planes) [12][4]; + float *viewport; struct draw_jit_texture textures[PIPE_MAX_VERTEX_SAMPLERS]; }; @@ -111,7 +112,10 @@ struct draw_jit_context #define draw_jit_context_planes(_builder, _ptr) \ lp_build_struct_get(_builder, _ptr, 2, "planes") -#define DRAW_JIT_CTX_TEXTURES 3 +#define draw_jit_context_viewport(_builder, _ptr) \ + lp_build_struct_get(_builder, _ptr, 3, "viewport") + +#define DRAW_JIT_CTX_TEXTURES 4 #define draw_jit_context_textures(_builder, _ptr) \ lp_build_struct_get_ptr(_builder, _ptr, DRAW_JIT_CTX_TEXTURES, "textures") diff --git a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c index e5b2532..a53a768 100644 --- a/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c +++ b/src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c @@ -177,6 +177,8 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle, draw->pt.user.gs_constants[0]; fpme->llvm->jit_context.planes = (float (*) [12][4]) draw->pt.user.planes[0]; + fpme->llvm->jit_context.viewport = + (float *)draw->viewport.scale; } -- 2.7.4