summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/draw
diff options
context:
space:
mode:
authorKeith Whitwell <keithw@vmware.com>2010-10-19 22:11:49 -0700
committerKeith Whitwell <keithw@vmware.com>2010-10-19 22:11:49 -0700
commit05921fd4e5305da68bb269748cb0ef059e1db417 (patch)
treebc570793e11e0fff245a15d834dfd892a1588a0d /src/gallium/auxiliary/draw
parentcd6a31cd4a9ea6deef4778c2eaef2d47240c3a6e (diff)
draw: make sure viewport gets updated in draw llvm shader
The viewport state was being baked in at compile time (oops...)
Diffstat (limited to 'src/gallium/auxiliary/draw')
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.c66
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.h6
-rw-r--r--src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c2
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 338127dafe..beb955fbf4 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 aa984ed3a2..c3c30c07c6 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 e5b2532b50..a53a768d02 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;
}