diff options
author | Dave Airlie <airlied@redhat.com> | 2014-08-27 09:56:14 +1000 |
---|---|---|
committer | Topi Pohjolainen <topi.pohjolainen@intel.com> | 2014-11-11 11:15:01 +0200 |
commit | d8e9edf4b86c2162ccc70c2c5dbb4f88943e6b0a (patch) | |
tree | e44638e68910e679080f3e187aa987d887bf3227 | |
parent | 304a4bfbdd8636299cd9e53943b5bebf5f3abf82 (diff) |
tgsi: add support for flt64 constants
These act like flt32 except they take up two slots, and you
can only add 2 x flt64 constants in one slot.
The main reason they are different is we don't want to match half a flt64
constants against a flt32 constant in the matching code, we need to make
sure we treat both parts of the flt64 as an single structure.
Signed-off-by: Dave Airlie <airlied@redhat.com>
-rw-r--r-- | src/gallium/auxiliary/tgsi/tgsi_dump.c | 1 | ||||
-rw-r--r-- | src/gallium/auxiliary/tgsi/tgsi_parse.c | 1 | ||||
-rw-r--r-- | src/gallium/auxiliary/tgsi/tgsi_strings.c | 5 | ||||
-rw-r--r-- | src/gallium/auxiliary/tgsi/tgsi_strings.h | 2 | ||||
-rw-r--r-- | src/gallium/auxiliary/tgsi/tgsi_text.c | 1 | ||||
-rw-r--r-- | src/gallium/auxiliary/tgsi/tgsi_ureg.c | 75 | ||||
-rw-r--r-- | src/gallium/auxiliary/tgsi/tgsi_ureg.h | 5 | ||||
-rw-r--r-- | src/gallium/include/pipe/p_shader_tokens.h | 1 |
8 files changed, 85 insertions, 6 deletions
diff --git a/src/gallium/auxiliary/tgsi/tgsi_dump.c b/src/gallium/auxiliary/tgsi/tgsi_dump.c index 972a37e83e1..eebb590240c 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_dump.c +++ b/src/gallium/auxiliary/tgsi/tgsi_dump.c @@ -239,6 +239,7 @@ dump_imm_data(struct tgsi_iterate_context *iter, for (i = 0; i < num_tokens; i++) { switch (data_type) { case TGSI_IMM_FLOAT32: + case TGSI_IMM_FLOAT64: FLT( data[i].Float ); break; case TGSI_IMM_UINT32: diff --git a/src/gallium/auxiliary/tgsi/tgsi_parse.c b/src/gallium/auxiliary/tgsi/tgsi_parse.c index 5bf8f483970..296d1084d75 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_parse.c +++ b/src/gallium/auxiliary/tgsi/tgsi_parse.c @@ -148,6 +148,7 @@ tgsi_parse_token( switch (imm->Immediate.DataType) { case TGSI_IMM_FLOAT32: + case TGSI_IMM_FLOAT64: for (i = 0; i < imm_count; i++) { next_token(ctx, &imm->u[i].Float); } diff --git a/src/gallium/auxiliary/tgsi/tgsi_strings.c b/src/gallium/auxiliary/tgsi/tgsi_strings.c index f84cd79b8e4..b6e05ebf794 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_strings.c +++ b/src/gallium/auxiliary/tgsi/tgsi_strings.c @@ -179,11 +179,12 @@ const char *tgsi_fs_coord_pixel_center_names[2] = "INTEGER" }; -const char *tgsi_immediate_type_names[3] = +const char *tgsi_immediate_type_names[4] = { "FLT32", "UINT32", - "INT32" + "INT32", + "FLT64" }; diff --git a/src/gallium/auxiliary/tgsi/tgsi_strings.h b/src/gallium/auxiliary/tgsi/tgsi_strings.h index c8427467793..90014a225b0 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_strings.h +++ b/src/gallium/auxiliary/tgsi/tgsi_strings.h @@ -58,7 +58,7 @@ extern const char *tgsi_fs_coord_origin_names[2]; extern const char *tgsi_fs_coord_pixel_center_names[2]; -extern const char *tgsi_immediate_type_names[3]; +extern const char *tgsi_immediate_type_names[4]; const char * diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c index f965b0130e0..0ae755a99e5 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_text.c +++ b/src/gallium/auxiliary/tgsi/tgsi_text.c @@ -1105,6 +1105,7 @@ static boolean parse_immediate_data(struct translate_ctx *ctx, unsigned type, switch (type) { case TGSI_IMM_FLOAT32: + case TGSI_IMM_FLOAT64: ret = parse_float(&ctx->cur, &values[i].Float); break; case TGSI_IMM_UINT32: diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.c b/src/gallium/auxiliary/tgsi/tgsi_ureg.c index 6d3ac918a59..40df962a018 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_ureg.c +++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.c @@ -713,7 +713,48 @@ ureg_DECL_sampler_view(struct ureg_program *ureg, } static int +match_or_expand_immediate64( const unsigned *v, + int type, + unsigned nr, + unsigned *v2, + unsigned *pnr2, + unsigned *swizzle ) +{ + unsigned nr2 = *pnr2; + unsigned i, j; + *swizzle = 0; + + for (i = 0; i < nr; i += 2) { + boolean found = FALSE; + + for (j = 0; j < nr2 && !found; j += 2) { + if (v[i] == v2[j] && v[i + 1] == v2[j + 1]) { + *swizzle |= (j << (i * 2)) | ((j + 1) << ((i + 1) * 2)); + found = TRUE; + } + } + if (!found) { + if ((nr2) >= 4) { + return FALSE; + } + + v2[nr2] = v[i]; + v2[nr2 + 1] = v[i + 1]; + + *swizzle |= (nr2 << (i * 2)) | ((nr2 + 1) << ((i + 1) * 2)); + nr2 += 2; + } + } + + /* Actually expand immediate only when fully succeeded. + */ + *pnr2 = nr2; + return TRUE; +} + +static int match_or_expand_immediate( const unsigned *v, + int type, unsigned nr, unsigned *v2, unsigned *pnr2, @@ -722,6 +763,9 @@ match_or_expand_immediate( const unsigned *v, unsigned nr2 = *pnr2; unsigned i, j; + if (type == TGSI_IMM_FLOAT64) + return match_or_expand_immediate64(v, type, nr, v2, pnr2, swizzle); + *swizzle = 0; for (i = 0; i < nr; i++) { @@ -770,6 +814,7 @@ decl_immediate( struct ureg_program *ureg, continue; } if (match_or_expand_immediate(v, + type, nr, ureg->immediate[i].value.u, &ureg->immediate[i].nr, @@ -782,6 +827,7 @@ decl_immediate( struct ureg_program *ureg, i = ureg->nr_immediates++; ureg->immediate[i].type = type; if (match_or_expand_immediate(v, + type, nr, ureg->immediate[i].value.u, &ureg->immediate[i].nr, @@ -796,10 +842,15 @@ out: /* Make sure that all referenced elements are from this immediate. * Has the effect of making size-one immediates into scalars. */ - for (j = nr; j < 4; j++) { - swizzle |= (swizzle & 0x3) << (j * 2); + if (type == TGSI_IMM_FLOAT64) { + for (j = nr; j < 4; j+=2) { + swizzle |= (swizzle & 0xf) << (j * 2); + } + } else { + for (j = nr; j < 4; j++) { + swizzle |= (swizzle & 0x3) << (j * 2); + } } - return ureg_swizzle(ureg_src_register(TGSI_FILE_IMMEDIATE, i), (swizzle >> 0) & 0x3, (swizzle >> 2) & 0x3, @@ -826,6 +877,24 @@ ureg_DECL_immediate( struct ureg_program *ureg, return decl_immediate(ureg, fu.u, nr, TGSI_IMM_FLOAT32); } +struct ureg_src +ureg_DECL_immediate_f64( struct ureg_program *ureg, + const double *v, + unsigned nr ) +{ + union { + unsigned u[4]; + double d[2]; + } fu; + unsigned int i; + + assert((nr / 2) < 3); + for (i = 0; i < nr / 2; i++) { + fu.d[i] = v[i]; + } + + return decl_immediate(ureg, fu.u, nr, TGSI_IMM_FLOAT64); +} struct ureg_src ureg_DECL_immediate_uint( struct ureg_program *ureg, diff --git a/src/gallium/auxiliary/tgsi/tgsi_ureg.h b/src/gallium/auxiliary/tgsi/tgsi_ureg.h index f014b5304a5..8fac8babc7c 100644 --- a/src/gallium/auxiliary/tgsi/tgsi_ureg.h +++ b/src/gallium/auxiliary/tgsi/tgsi_ureg.h @@ -262,6 +262,11 @@ ureg_DECL_immediate( struct ureg_program *, unsigned nr ); struct ureg_src +ureg_DECL_immediate_f64( struct ureg_program *, + const double *v, + unsigned nr ); + +struct ureg_src ureg_DECL_immediate_uint( struct ureg_program *, const unsigned *v, unsigned nr ); diff --git a/src/gallium/include/pipe/p_shader_tokens.h b/src/gallium/include/pipe/p_shader_tokens.h index 787d7afe993..42306f7361d 100644 --- a/src/gallium/include/pipe/p_shader_tokens.h +++ b/src/gallium/include/pipe/p_shader_tokens.h @@ -226,6 +226,7 @@ struct tgsi_declaration_array { #define TGSI_IMM_FLOAT32 0 #define TGSI_IMM_UINT32 1 #define TGSI_IMM_INT32 2 +#define TGSI_IMM_FLOAT64 3 struct tgsi_immediate { |