summaryrefslogtreecommitdiffstats
path: root/src/gallium/auxiliary
diff options
context:
space:
mode:
authorDave Airlie <airlied@gmail.com>2013-09-16 10:13:55 +1000
committerDave Airlie <airlied@redhat.com>2015-10-23 11:55:02 +1000
commit041081dc219dcf7f61748284033c6fd7627acc69 (patch)
treed27eb91d8b2c0d77f633dc4408cb1a2864f5b259 /src/gallium/auxiliary
parent231d53923918f4a885e74da0a063dcbf1a4353e3 (diff)
downloadexternal_mesa3d-041081dc219dcf7f61748284033c6fd7627acc69.zip
external_mesa3d-041081dc219dcf7f61748284033c6fd7627acc69.tar.gz
external_mesa3d-041081dc219dcf7f61748284033c6fd7627acc69.tar.bz2
tgsi: add option to dump floats as hex values
This adds support to the parser to accept hex values as floats, and then adds support to the dumper to allow the user to select to dump float as 32-bit hex numbers. This is required to get accurate values for virgl use of TGSI. Reviewed-by: Marek Olšák <marek.olsak@amd.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'src/gallium/auxiliary')
-rw-r--r--src/gallium/auxiliary/tgsi/tgsi_dump.c19
-rw-r--r--src/gallium/auxiliary/tgsi/tgsi_dump.h2
-rw-r--r--src/gallium/auxiliary/tgsi/tgsi_text.c11
3 files changed, 30 insertions, 2 deletions
diff --git a/src/gallium/auxiliary/tgsi/tgsi_dump.c b/src/gallium/auxiliary/tgsi/tgsi_dump.c
index 5d80cca..3470739 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_dump.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_dump.c
@@ -29,6 +29,7 @@
#include "util/u_string.h"
#include "util/u_math.h"
#include "util/u_memory.h"
+#include "util/u_math.h"
#include "tgsi_dump.h"
#include "tgsi_info.h"
#include "tgsi_iterate.h"
@@ -43,6 +44,8 @@ struct dump_ctx
{
struct tgsi_iterate_context iter;
+ boolean dump_float_as_hex;
+
uint instno;
uint immno;
int indent;
@@ -88,6 +91,7 @@ dump_enum(
#define SID(I) ctx->dump_printf( ctx, "%d", I )
#define FLT(F) ctx->dump_printf( ctx, "%10.4f", F )
#define DBL(D) ctx->dump_printf( ctx, "%10.8f", D )
+#define HFLT(F) ctx->dump_printf( ctx, "0x%08x", fui((F)) )
#define ENM(E,ENUMS) dump_enum( ctx, E, ENUMS, sizeof( ENUMS ) / sizeof( *ENUMS ) )
const char *
@@ -251,7 +255,10 @@ dump_imm_data(struct tgsi_iterate_context *iter,
break;
}
case TGSI_IMM_FLOAT32:
- FLT( data[i].Float );
+ if (ctx->dump_float_as_hex)
+ HFLT( data[i].Float );
+ else
+ FLT( data[i].Float );
break;
case TGSI_IMM_UINT32:
UID(data[i].Uint);
@@ -682,6 +689,11 @@ tgsi_dump_to_file(const struct tgsi_token *tokens, uint flags, FILE *file)
ctx.indentation = 0;
ctx.file = file;
+ if (flags & TGSI_DUMP_FLOAT_AS_HEX)
+ ctx.dump_float_as_hex = TRUE;
+ else
+ ctx.dump_float_as_hex = FALSE;
+
tgsi_iterate_shader( tokens, &ctx.iter );
}
@@ -750,6 +762,11 @@ tgsi_dump_str(
ctx.ptr = str;
ctx.left = (int)size;
+ if (flags & TGSI_DUMP_FLOAT_AS_HEX)
+ ctx.base.dump_float_as_hex = TRUE;
+ else
+ ctx.base.dump_float_as_hex = FALSE;
+
tgsi_iterate_shader( tokens, &ctx.base.iter );
}
diff --git a/src/gallium/auxiliary/tgsi/tgsi_dump.h b/src/gallium/auxiliary/tgsi/tgsi_dump.h
index 7c8f92e..6666b98 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_dump.h
+++ b/src/gallium/auxiliary/tgsi/tgsi_dump.h
@@ -38,6 +38,8 @@
extern "C" {
#endif
+#define TGSI_DUMP_FLOAT_AS_HEX (1 << 0)
+
void
tgsi_dump_str(
const struct tgsi_token *tokens,
diff --git a/src/gallium/auxiliary/tgsi/tgsi_text.c b/src/gallium/auxiliary/tgsi/tgsi_text.c
index 3e3ed5b..4a82c9b 100644
--- a/src/gallium/auxiliary/tgsi/tgsi_text.c
+++ b/src/gallium/auxiliary/tgsi/tgsi_text.c
@@ -195,8 +195,15 @@ static boolean parse_float( const char **pcur, float *val )
boolean integral_part = FALSE;
boolean fractional_part = FALSE;
- *val = (float) atof( cur );
+ if (*cur == '0' && *(cur + 1) == 'x') {
+ union fi fi;
+ fi.ui = strtoul(cur, NULL, 16);
+ *val = fi.f;
+ cur += 10;
+ goto out;
+ }
+ *val = (float) atof( cur );
if (*cur == '-' || *cur == '+')
cur++;
if (is_digit( cur )) {
@@ -228,6 +235,8 @@ static boolean parse_float( const char **pcur, float *val )
else
return FALSE;
}
+
+out:
*pcur = cur;
return TRUE;
}