summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordelphi <[email protected]>2010-10-10 00:31:16 +0100
committerKeith Whitwell <[email protected]>2010-10-10 08:40:11 +0100
commit08f890d4c3b8376d1840f90474f7c56329432d95 (patch)
tree135d9b47adc27a0fcca7feb997258762aa8f1560
parent25bb05fef075a87ec6e5f2a989049faff2afedd2 (diff)
draw: some changes to allow for runtime changes to userclip planes
-rw-r--r--src/gallium/auxiliary/draw/draw_context.c1
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.c70
-rw-r--r--src/gallium/auxiliary/draw/draw_llvm.h10
-rw-r--r--src/gallium/auxiliary/draw/draw_private.h3
-rw-r--r--src/gallium/auxiliary/draw/draw_pt_fetch_shade_pipeline_llvm.c3
5 files changed, 67 insertions, 20 deletions
diff --git a/src/gallium/auxiliary/draw/draw_context.c b/src/gallium/auxiliary/draw/draw_context.c
index b07de76a498..c52234d8e31 100644
--- a/src/gallium/auxiliary/draw/draw_context.c
+++ b/src/gallium/auxiliary/draw/draw_context.c
@@ -335,6 +335,7 @@ draw_set_mapped_constant_buffer(struct draw_context *draw,
case PIPE_SHADER_VERTEX:
draw->pt.user.vs_constants[slot] = buffer;
draw->pt.user.vs_constants_size[slot] = size;
+ draw->pt.user.planes = (float (*) [12][4]) &(draw->plane[0]);
draw_vs_set_constants(draw, slot, buffer, size);
break;
case PIPE_SHADER_GEOMETRY:
diff --git a/src/gallium/auxiliary/draw/draw_llvm.c b/src/gallium/auxiliary/draw/draw_llvm.c
index 9c17e7763ae..5f11b82bb99 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.c
+++ b/src/gallium/auxiliary/draw/draw_llvm.c
@@ -130,12 +130,13 @@ init_globals(struct draw_llvm *llvm)
/* struct draw_jit_context */
{
- LLVMTypeRef elem_types[3];
+ LLVMTypeRef elem_types[4];
LLVMTypeRef context_type;
elem_types[0] = LLVMPointerType(LLVMFloatType(), 0); /* vs_constants */
- elem_types[1] = LLVMPointerType(LLVMFloatType(), 0); /* vs_constants */
- elem_types[2] = LLVMArrayType(texture_type,
+ 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,
PIPE_MAX_VERTEX_SAMPLERS); /* textures */
context_type = LLVMStructType(elem_types, Elements(elem_types), 0);
@@ -144,6 +145,8 @@ init_globals(struct draw_llvm *llvm)
llvm->target, context_type, 0);
LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, gs_constants,
llvm->target, context_type, 1);
+ LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, planes,
+ llvm->target, context_type, 2);
LP_CHECK_MEMBER_OFFSET(struct draw_jit_context, textures,
llvm->target, context_type,
DRAW_JIT_CTX_TEXTURES);
@@ -817,6 +820,23 @@ 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
*/
@@ -827,17 +847,16 @@ generate_clipmask(LLVMBuilderRef builder,
boolean clip_z,
boolean clip_user,
boolean enable_d3dclipping,
- struct draw_llvm *llvm)
+ unsigned nr,
+ LLVMValueRef context_ptr)
{
LLVMValueRef mask; /* stores the <4xi32> clipmasks */
LLVMValueRef test, temp;
LLVMValueRef zero, shift;
LLVMValueRef pos_x, pos_y, pos_z, pos_w;
- LLVMValueRef planes, sum;
+ LLVMValueRef plane1, planes, plane_ptr, sum;
- unsigned nr;
unsigned i;
- float (*plane)[4];
struct lp_type f32_type = lp_type_float_vec(32);
@@ -903,22 +922,38 @@ generate_clipmask(LLVMBuilderRef builder,
}
if (clip_user){
+ LLVMValueRef planes_ptr = draw_jit_context_planes(builder, context_ptr);
+ LLVMValueRef indices[3];
+
/* userclip planes */
- nr = llvm->draw->nr_planes;
- plane = llvm->draw->plane;
for (i = 6; i < nr; i++) {
- planes = lp_build_const_vec(f32_type, plane[i][0]);
+ indices[0] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ indices[1] = LLVMConstInt(LLVMInt32Type(), i, 0);
+
+ indices[2] = LLVMConstInt(LLVMInt32Type(), 0, 0);
+ plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, "");
+ plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_x");
+ planes = vec4f_from_scalar(builder, plane1, "plane4_x");
sum = LLVMBuildMul(builder, planes, pos_x, "");
- planes = lp_build_const_vec(f32_type, plane[i][1]);
+ indices[2] = LLVMConstInt(LLVMInt32Type(), 1, 0);
+ plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, "");
+ plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_y");
+ planes = vec4f_from_scalar(builder, plane1, "plane4_y");
test = LLVMBuildMul(builder, planes, pos_y, "");
sum = LLVMBuildFAdd(builder, sum, test, "");
-
- planes = lp_build_const_vec(f32_type, plane[i][2]);
+
+ indices[2] = LLVMConstInt(LLVMInt32Type(), 2, 0);
+ plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, "");
+ plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_z");
+ planes = vec4f_from_scalar(builder, plane1, "plane4_z");
test = LLVMBuildMul(builder, planes, pos_z, "");
sum = LLVMBuildFAdd(builder, sum, test, "");
- planes = lp_build_const_vec(f32_type, plane[i][3]);
+ indices[2] = LLVMConstInt(LLVMInt32Type(), 3, 0);
+ plane_ptr = LLVMBuildGEP(builder, planes_ptr, indices, 3, "");
+ plane1 = LLVMBuildLoad(builder, plane_ptr, "plane_w");
+ planes = vec4f_from_scalar(builder, plane1, "plane4_w");
test = LLVMBuildMul(builder, planes, pos_w, "");
sum = LLVMBuildFAdd(builder, sum, test, "");
@@ -1098,7 +1133,8 @@ draw_llvm_generate(struct draw_llvm *llvm, struct draw_llvm_variant *variant)
variant->key.clip_z,
variant->key.clip_user,
variant->key.enable_d3dclipping,
- llvm);
+ variant->key.nr_planes,
+ context_ptr);
/* return clipping boolean value for function */
clipmask_bool(builder, clipmask, ret_ptr);
}
@@ -1308,7 +1344,8 @@ draw_llvm_generate_elts(struct draw_llvm *llvm, struct draw_llvm_variant *varian
variant->key.clip_z,
variant->key.clip_user,
variant->key.enable_d3dclipping,
- llvm);
+ variant->key.nr_planes,
+ context_ptr);
/* return clipping boolean value for function */
clipmask_bool(builder, clipmask, ret_ptr);
}
@@ -1392,6 +1429,7 @@ draw_llvm_make_variant_key(struct draw_llvm *llvm, char *store)
key->bypass_viewport = llvm->draw->identity_viewport;
key->enable_d3dclipping = (boolean)!llvm->draw->rasterizer->gl_rasterization_rules;
key->need_edgeflags = (llvm->draw->vs.edgeflag_output ? TRUE : FALSE);
+ key->nr_planes = llvm->draw->nr_planes;
/* All variants of this shader will have the same value for
* nr_samplers. Not yet trying to compact away holes in the
diff --git a/src/gallium/auxiliary/draw/draw_llvm.h b/src/gallium/auxiliary/draw/draw_llvm.h
index 4a4d93f33a8..fc7885499ef 100644
--- a/src/gallium/auxiliary/draw/draw_llvm.h
+++ b/src/gallium/auxiliary/draw/draw_llvm.h
@@ -97,7 +97,7 @@ struct draw_jit_context
{
const float *vs_constants;
const float *gs_constants;
-
+ float (*planes) [12][4];
struct draw_jit_texture textures[PIPE_MAX_VERTEX_SAMPLERS];
};
@@ -109,13 +109,14 @@ struct draw_jit_context
#define draw_jit_context_gs_constants(_builder, _ptr) \
lp_build_struct_get(_builder, _ptr, 1, "gs_constants")
-#define DRAW_JIT_CTX_TEXTURES 2
+#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_textures(_builder, _ptr) \
lp_build_struct_get_ptr(_builder, _ptr, DRAW_JIT_CTX_TEXTURES, "textures")
-
-
#define draw_jit_header_id(_builder, _ptr) \
lp_build_struct_get_ptr(_builder, _ptr, 0, "id")
@@ -167,6 +168,7 @@ struct draw_llvm_variant_key
unsigned bypass_viewport:1;
unsigned enable_d3dclipping:1;
unsigned need_edgeflags:1;
+ unsigned nr_planes;
/* Variable number of vertex elements:
*/
diff --git a/src/gallium/auxiliary/draw/draw_private.h b/src/gallium/auxiliary/draw/draw_private.h
index d417f825a0f..54163d7f9eb 100644
--- a/src/gallium/auxiliary/draw/draw_private.h
+++ b/src/gallium/auxiliary/draw/draw_private.h
@@ -169,6 +169,9 @@ struct draw_context
unsigned vs_constants_size[PIPE_MAX_CONSTANT_BUFFERS];
const void *gs_constants[PIPE_MAX_CONSTANT_BUFFERS];
unsigned gs_constants_size[PIPE_MAX_CONSTANT_BUFFERS];
+
+ /* pointer to planes */
+ float (*planes)[12][4];
} user;
boolean test_fse; /* enable FSE even though its not correct (eg for softpipe) */
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 dc138b980da..e5b2532b50a 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
@@ -175,6 +175,9 @@ llvm_middle_end_prepare( struct draw_pt_middle_end *middle,
draw->pt.user.vs_constants[0];
fpme->llvm->jit_context.gs_constants =
draw->pt.user.gs_constants[0];
+ fpme->llvm->jit_context.planes =
+ (float (*) [12][4]) draw->pt.user.planes[0];
+
}