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.

Cleaned up printing/parsing by Ilia Mirkin <imirkin@alum.mit.edu>

Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
Dave Airlie
2014-08-27 09:56:14 +10:00
parent 3cd1338534
commit fa43e0443e
8 changed files with 113 additions and 6 deletions

View File

@@ -83,6 +83,7 @@ dump_enum(
#define INSTID(I) ctx->dump_printf( ctx, "% 3u", I ) #define INSTID(I) ctx->dump_printf( ctx, "% 3u", I )
#define SID(I) ctx->dump_printf( ctx, "%d", I ) #define SID(I) ctx->dump_printf( ctx, "%d", I )
#define FLT(F) ctx->dump_printf( ctx, "%10.4f", F ) #define FLT(F) ctx->dump_printf( ctx, "%10.4f", F )
#define DBL(D) ctx->dump_printf( ctx, "%10.8f", D )
#define ENM(E,ENUMS) dump_enum( ctx, E, ENUMS, sizeof( ENUMS ) / sizeof( *ENUMS ) ) #define ENM(E,ENUMS) dump_enum( ctx, E, ENUMS, sizeof( ENUMS ) / sizeof( *ENUMS ) )
const char * const char *
@@ -238,6 +239,13 @@ dump_imm_data(struct tgsi_iterate_context *iter,
assert( num_tokens <= 4 ); assert( num_tokens <= 4 );
for (i = 0; i < num_tokens; i++) { for (i = 0; i < num_tokens; i++) {
switch (data_type) { switch (data_type) {
case TGSI_IMM_FLOAT64: {
union di d;
d.ui = data[i].Uint | (uint64_t)data[i+1].Uint << 32;
DBL( d.d );
i++;
break;
}
case TGSI_IMM_FLOAT32: case TGSI_IMM_FLOAT32:
FLT( data[i].Float ); FLT( data[i].Float );
break; break;

View File

@@ -148,6 +148,7 @@ tgsi_parse_token(
switch (imm->Immediate.DataType) { switch (imm->Immediate.DataType) {
case TGSI_IMM_FLOAT32: case TGSI_IMM_FLOAT32:
case TGSI_IMM_FLOAT64:
for (i = 0; i < imm_count; i++) { for (i = 0; i < imm_count; i++) {
next_token(ctx, &imm->u[i].Float); next_token(ctx, &imm->u[i].Float);
} }

View File

@@ -181,11 +181,12 @@ const char *tgsi_fs_coord_pixel_center_names[2] =
"INTEGER" "INTEGER"
}; };
const char *tgsi_immediate_type_names[3] = const char *tgsi_immediate_type_names[4] =
{ {
"FLT32", "FLT32",
"UINT32", "UINT32",
"INT32" "INT32",
"FLT64"
}; };

View File

@@ -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_fs_coord_pixel_center_names[2];
extern const char *tgsi_immediate_type_names[3]; extern const char *tgsi_immediate_type_names[4];
const char * const char *

View File

@@ -232,6 +232,24 @@ static boolean parse_float( const char **pcur, float *val )
return TRUE; return TRUE;
} }
static boolean parse_double( const char **pcur, uint32_t *val0, uint32_t *val1)
{
const char *cur = *pcur;
union {
double dval;
uint32_t uval[2];
} v;
v.dval = strtod(cur, pcur);
if (*pcur == cur)
return FALSE;
*val0 = v.uval[0];
*val1 = v.uval[1];
return TRUE;
}
struct translate_ctx struct translate_ctx
{ {
const char *text; const char *text;
@@ -1104,6 +1122,10 @@ static boolean parse_immediate_data(struct translate_ctx *ctx, unsigned type,
} }
switch (type) { switch (type) {
case TGSI_IMM_FLOAT64:
ret = parse_double(&ctx->cur, &values[i].Uint, &values[i+1].Uint);
i++;
break;
case TGSI_IMM_FLOAT32: case TGSI_IMM_FLOAT32:
ret = parse_float(&ctx->cur, &values[i].Float); ret = parse_float(&ctx->cur, &values[i].Float);
break; break;

View File

@@ -622,7 +622,8 @@ ureg_DECL_sampler_view(struct ureg_program *ureg,
} }
static int static int
match_or_expand_immediate( const unsigned *v, match_or_expand_immediate64( const unsigned *v,
int type,
unsigned nr, unsigned nr,
unsigned *v2, unsigned *v2,
unsigned *pnr2, unsigned *pnr2,
@@ -630,6 +631,49 @@ match_or_expand_immediate( const unsigned *v,
{ {
unsigned nr2 = *pnr2; unsigned nr2 = *pnr2;
unsigned i, j; 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,
unsigned *swizzle )
{
unsigned nr2 = *pnr2;
unsigned i, j;
if (type == TGSI_IMM_FLOAT64)
return match_or_expand_immediate64(v, type, nr, v2, pnr2, swizzle);
*swizzle = 0; *swizzle = 0;
@@ -679,6 +723,7 @@ decl_immediate( struct ureg_program *ureg,
continue; continue;
} }
if (match_or_expand_immediate(v, if (match_or_expand_immediate(v,
type,
nr, nr,
ureg->immediate[i].value.u, ureg->immediate[i].value.u,
&ureg->immediate[i].nr, &ureg->immediate[i].nr,
@@ -691,6 +736,7 @@ decl_immediate( struct ureg_program *ureg,
i = ureg->nr_immediates++; i = ureg->nr_immediates++;
ureg->immediate[i].type = type; ureg->immediate[i].type = type;
if (match_or_expand_immediate(v, if (match_or_expand_immediate(v,
type,
nr, nr,
ureg->immediate[i].value.u, ureg->immediate[i].value.u,
&ureg->immediate[i].nr, &ureg->immediate[i].nr,
@@ -705,10 +751,15 @@ out:
/* Make sure that all referenced elements are from this immediate. /* Make sure that all referenced elements are from this immediate.
* Has the effect of making size-one immediates into scalars. * Has the effect of making size-one immediates into scalars.
*/ */
if (type == TGSI_IMM_FLOAT64) {
for (j = nr; j < 4; j+=2) {
swizzle |= (swizzle & 0xf) << (j * 2);
}
} else {
for (j = nr; j < 4; j++) { for (j = nr; j < 4; j++) {
swizzle |= (swizzle & 0x3) << (j * 2); swizzle |= (swizzle & 0x3) << (j * 2);
} }
}
return ureg_swizzle(ureg_src_register(TGSI_FILE_IMMEDIATE, i), return ureg_swizzle(ureg_src_register(TGSI_FILE_IMMEDIATE, i),
(swizzle >> 0) & 0x3, (swizzle >> 0) & 0x3,
(swizzle >> 2) & 0x3, (swizzle >> 2) & 0x3,
@@ -735,6 +786,24 @@ ureg_DECL_immediate( struct ureg_program *ureg,
return decl_immediate(ureg, fu.u, nr, TGSI_IMM_FLOAT32); 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 struct ureg_src
ureg_DECL_immediate_uint( struct ureg_program *ureg, ureg_DECL_immediate_uint( struct ureg_program *ureg,

View File

@@ -228,6 +228,11 @@ ureg_DECL_immediate( struct ureg_program *,
const float *v, const float *v,
unsigned nr ); unsigned nr );
struct ureg_src
ureg_DECL_immediate_f64( struct ureg_program *,
const double *v,
unsigned nr );
struct ureg_src struct ureg_src
ureg_DECL_immediate_uint( struct ureg_program *, ureg_DECL_immediate_uint( struct ureg_program *,
const unsigned *v, const unsigned *v,

View File

@@ -228,6 +228,7 @@ struct tgsi_declaration_array {
#define TGSI_IMM_FLOAT32 0 #define TGSI_IMM_FLOAT32 0
#define TGSI_IMM_UINT32 1 #define TGSI_IMM_UINT32 1
#define TGSI_IMM_INT32 2 #define TGSI_IMM_INT32 2
#define TGSI_IMM_FLOAT64 3
struct tgsi_immediate struct tgsi_immediate
{ {