summaryrefslogtreecommitdiff
path: root/src/gallium/auxiliary/gallivm
diff options
context:
space:
mode:
Diffstat (limited to 'src/gallium/auxiliary/gallivm')
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_arit.c41
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_arit.h10
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_depth.c2
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_format_aos.c6
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_format_soa.c4
-rw-r--r--src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c104
6 files changed, 148 insertions, 19 deletions
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.c b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
index 54b31befe6..bbce31f9eb 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_arit.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.c
@@ -614,6 +614,22 @@ lp_build_max(struct lp_build_context *bld,
/**
+ * Generate clamp(a, min, max)
+ * Do checks for special cases.
+ */
+LLVMValueRef
+lp_build_clamp(struct lp_build_context *bld,
+ LLVMValueRef a,
+ LLVMValueRef min,
+ LLVMValueRef max)
+{
+ a = lp_build_min(bld, a, max);
+ a = lp_build_max(bld, a, min);
+ return a;
+}
+
+
+/**
* Generate abs(a)
*/
LLVMValueRef
@@ -693,6 +709,29 @@ lp_build_sgn(struct lp_build_context *bld,
}
+/**
+ * Convert vector of int to vector of float.
+ */
+LLVMValueRef
+lp_build_int_to_float(struct lp_build_context *bld,
+ LLVMValueRef a)
+{
+ const struct lp_type type = bld->type;
+
+ assert(type.floating);
+ /*assert(lp_check_value(type, a));*/
+
+ {
+ LLVMTypeRef vec_type = lp_build_vec_type(type);
+ /*LLVMTypeRef int_vec_type = lp_build_int_vec_type(type);*/
+ LLVMValueRef res;
+ res = LLVMBuildSIToFP(bld->builder, a, vec_type, "");
+ return res;
+ }
+}
+
+
+
enum lp_build_round_sse41_mode
{
LP_BUILD_ROUND_SSE41_NEAREST = 0,
@@ -819,7 +858,7 @@ lp_build_ceil(struct lp_build_context *bld,
/**
* Convert to integer, through whichever rounding method that's fastest,
- * typically truncating to zero.
+ * typically truncating toward zero.
*/
LLVMValueRef
lp_build_itrunc(struct lp_build_context *bld,
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_arit.h b/src/gallium/auxiliary/gallivm/lp_bld_arit.h
index 62be4b9aee..da84b7ca02 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_arit.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_arit.h
@@ -107,6 +107,12 @@ lp_build_max(struct lp_build_context *bld,
LLVMValueRef b);
LLVMValueRef
+lp_build_clamp(struct lp_build_context *bld,
+ LLVMValueRef a,
+ LLVMValueRef min,
+ LLVMValueRef max);
+
+LLVMValueRef
lp_build_abs(struct lp_build_context *bld,
LLVMValueRef a);
@@ -115,6 +121,10 @@ lp_build_sgn(struct lp_build_context *bld,
LLVMValueRef a);
LLVMValueRef
+lp_build_int_to_float(struct lp_build_context *bld,
+ LLVMValueRef a);
+
+LLVMValueRef
lp_build_round(struct lp_build_context *bld,
LLVMValueRef a);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_depth.c b/src/gallium/auxiliary/gallivm/lp_bld_depth.c
index d438c0e63d..f08f8eb6d8 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_depth.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_depth.c
@@ -171,7 +171,7 @@ lp_build_depth_test(LLVMBuilderRef builder,
unsigned padding_right;
unsigned chan;
- assert(format_desc->layout == UTIL_FORMAT_LAYOUT_ARITH);
+ assert(format_desc->layout == UTIL_FORMAT_LAYOUT_PLAIN);
assert(format_desc->channel[z_swizzle].type == UTIL_FORMAT_TYPE_UNSIGNED);
assert(format_desc->channel[z_swizzle].size <= format_desc->block.bits);
assert(format_desc->channel[z_swizzle].normalized);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
index dfa080b853..a07f7418f2 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_format_aos.c
@@ -70,7 +70,7 @@ lp_build_unpack_rgba_aos(LLVMBuilderRef builder,
unsigned i;
/* FIXME: Support more formats */
- assert(desc->layout == UTIL_FORMAT_LAYOUT_ARITH);
+ assert(desc->layout == UTIL_FORMAT_LAYOUT_PLAIN);
assert(desc->block.width == 1);
assert(desc->block.height == 1);
assert(desc->block.bits <= 32);
@@ -189,7 +189,7 @@ lp_build_unpack_rgba8_aos(LLVMBuilderRef builder,
lp_build_context_init(&bld, builder, type);
/* FIXME: Support more formats */
- assert(desc->layout == UTIL_FORMAT_LAYOUT_ARITH);
+ assert(desc->layout == UTIL_FORMAT_LAYOUT_PLAIN);
assert(desc->block.width == 1);
assert(desc->block.height == 1);
assert(desc->block.bits <= 32);
@@ -303,7 +303,7 @@ lp_build_pack_rgba_aos(LLVMBuilderRef builder,
unsigned shift;
unsigned i, j;
- assert(desc->layout == UTIL_FORMAT_LAYOUT_ARITH);
+ assert(desc->layout == UTIL_FORMAT_LAYOUT_PLAIN);
assert(desc->block.width == 1);
assert(desc->block.height == 1);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c
index 64151d169d..abb27e4c32 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_format_soa.c
@@ -92,9 +92,7 @@ lp_build_unpack_rgba_soa(LLVMBuilderRef builder,
unsigned chan;
/* FIXME: Support more formats */
- assert(format_desc->layout == UTIL_FORMAT_LAYOUT_ARITH ||
- (format_desc->layout == UTIL_FORMAT_LAYOUT_ARRAY &&
- format_desc->block.bits == format_desc->channel[0].size));
+ assert(format_desc->layout == UTIL_FORMAT_LAYOUT_PLAIN);
assert(format_desc->block.width == 1);
assert(format_desc->block.height == 1);
assert(format_desc->block.bits <= 32);
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
index 4cf28a9f93..81b0ab760e 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_tgsi_soa.c
@@ -52,6 +52,7 @@
#include "lp_bld_swizzle.h"
#include "lp_bld_flow.h"
#include "lp_bld_tgsi.h"
+#include "lp_bld_debug.h"
#define LP_MAX_TEMPS 256
@@ -81,6 +82,23 @@
#define QUAD_BOTTOM_LEFT 2
#define QUAD_BOTTOM_RIGHT 3
+#define LP_TGSI_MAX_NESTING 16
+
+struct lp_exec_mask {
+ struct lp_build_context *bld;
+
+ boolean has_mask;
+
+ LLVMTypeRef int_vec_type;
+
+ LLVMValueRef cond_stack[LP_TGSI_MAX_NESTING];
+ int cond_stack_size;
+ LLVMValueRef cond_mask;
+
+ LLVMValueRef exec_mask;
+
+ LLVMValueRef inv_mask;
+};
struct lp_build_tgsi_soa_context
{
@@ -97,9 +115,9 @@ struct lp_build_tgsi_soa_context
LLVMValueRef temps[LP_MAX_TEMPS][NUM_CHANNELS];
struct lp_build_mask_context *mask;
+ struct lp_exec_mask exec_mask;
};
-
static const unsigned char
swizzle_left[4] = {
QUAD_TOP_LEFT, QUAD_TOP_LEFT,
@@ -124,6 +142,70 @@ swizzle_bottom[4] = {
QUAD_BOTTOM_LEFT, QUAD_BOTTOM_RIGHT
};
+static void lp_exec_mask_init(struct lp_exec_mask *mask, struct lp_build_context *bld)
+{
+ mask->bld = bld;
+ mask->has_mask = FALSE;
+ mask->cond_stack_size = 0;
+
+ mask->int_vec_type = lp_build_int_vec_type(mask->bld->type);
+ mask->inv_mask =
+ LLVMConstSub(LLVMConstNull(mask->int_vec_type),
+ LLVMConstAllOnes(mask->int_vec_type));
+}
+
+static void lp_exec_mask_update(struct lp_exec_mask *mask)
+{
+ mask->exec_mask = mask->cond_mask;
+ if (mask->cond_stack_size > 0)
+ mask->has_mask = TRUE;
+}
+
+static void lp_exec_mask_cond_push(struct lp_exec_mask *mask,
+ LLVMValueRef val)
+{
+ mask->cond_stack[mask->cond_stack_size++] = mask->cond_mask;
+ mask->cond_mask = LLVMBuildBitCast(mask->bld->builder, val,
+ mask->int_vec_type, "");
+
+ lp_exec_mask_update(mask);
+}
+
+static void lp_exec_mask_cond_invert(struct lp_exec_mask *mask)
+{
+ LLVMValueRef prev_mask = mask->cond_stack[mask->cond_stack_size - 1];
+ LLVMValueRef inv_mask = LLVMBuildXor(mask->bld->builder,
+ mask->cond_mask,
+ mask->inv_mask, "");
+ mask->cond_mask = LLVMBuildAnd(mask->bld->builder,
+ inv_mask,
+ prev_mask, "");
+ lp_exec_mask_update(mask);
+}
+
+static void lp_exec_mask_cond_pop(struct lp_exec_mask *mask)
+{
+ mask->cond_mask = mask->cond_stack[--mask->cond_stack_size];
+ lp_exec_mask_update(mask);
+}
+
+static void lp_exec_mask_store(struct lp_exec_mask *mask,
+ LLVMValueRef val,
+ LLVMValueRef dst)
+{
+ if (mask->has_mask) {
+ LLVMValueRef real_val, dst_val;
+
+ dst_val = LLVMBuildLoad(mask->bld->builder, dst, "");
+ real_val = lp_build_select(mask->bld,
+ mask->exec_mask,
+ val, dst_val);
+
+ LLVMBuildStore(mask->bld->builder, real_val, dst);
+ } else
+ LLVMBuildStore(mask->bld->builder, val, dst);
+}
+
static LLVMValueRef
emit_ddx(struct lp_build_tgsi_soa_context *bld,
@@ -287,13 +369,13 @@ emit_store(
switch( reg->Register.File ) {
case TGSI_FILE_OUTPUT:
- LLVMBuildStore(bld->base.builder, value,
- bld->outputs[reg->Register.Index][chan_index]);
+ lp_exec_mask_store(&bld->exec_mask, value,
+ bld->outputs[reg->Register.Index][chan_index]);
break;
case TGSI_FILE_TEMPORARY:
- LLVMBuildStore(bld->base.builder, value,
- bld->temps[reg->Register.Index][chan_index]);
+ lp_exec_mask_store(&bld->exec_mask, value,
+ bld->temps[reg->Register.Index][chan_index]);
break;
case TGSI_FILE_ADDRESS:
@@ -1272,8 +1354,8 @@ emit_instruction(
break;
case TGSI_OPCODE_IF:
- /* FIXME */
- return 0;
+ tmp0 = emit_fetch(bld, inst, 0, CHAN_X);
+ lp_exec_mask_cond_push(&bld->exec_mask, tmp0);
break;
case TGSI_OPCODE_BGNFOR:
@@ -1289,13 +1371,11 @@ emit_instruction(
break;
case TGSI_OPCODE_ELSE:
- /* FIXME */
- return 0;
+ lp_exec_mask_cond_invert(&bld->exec_mask);
break;
case TGSI_OPCODE_ENDIF:
- /* FIXME */
- return 0;
+ lp_exec_mask_cond_pop(&bld->exec_mask);
break;
case TGSI_OPCODE_ENDFOR:
@@ -1458,6 +1538,8 @@ lp_build_tgsi_soa(LLVMBuilderRef builder,
bld.consts_ptr = consts_ptr;
bld.sampler = sampler;
+ lp_exec_mask_init(&bld.exec_mask, &bld.base);
+
tgsi_parse_init( &parse, tokens );
while( !tgsi_parse_end_of_tokens( &parse ) ) {