diff options
author | Ian Romanick <ian.d.romanick@intel.com> | 2014-09-03 18:38:08 -0700 |
---|---|---|
committer | Ian Romanick <ian.d.romanick@intel.com> | 2014-09-17 15:17:50 -0400 |
commit | d859c94fd1d0406c3d109ed209897baccf99b57d (patch) | |
tree | cc6dc6e4b955206d8f7595a9cb0cf30851253c74 | |
parent | b2793d0a998a92b48978d2aa31f8715ae1cb77a8 (diff) |
shader_runner: Allow loading hex values for floats
For some cases we want to have shaders where we load an exact bit
pattern into a float (or double) uniform.
NOTE: The double path isn't really tested.
Signed-off-by: Ian Romanick <ian.d.romanick@intel.com>
Reviewed-by: Chris Forbes <chrisf@ijw.co.nz>
-rw-r--r-- | tests/shaders/shader_runner.c | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/tests/shaders/shader_runner.c b/tests/shaders/shader_runner.c index 310b2d46a..1f93216c1 100644 --- a/tests/shaders/shader_runner.c +++ b/tests/shaders/shader_runner.c @@ -1175,8 +1175,21 @@ get_floats(const char *line, float *f, unsigned count) { unsigned i; - for (i = 0; i < count; i++) - f[i] = strtod_inf(line, (char **) &line); + for (i = 0; i < count; i++) { + line = eat_whitespace(line); + + if (strncmp(line, "0x", 2) == 0) { + union { + int32_t i; + float f; + } x; + + x.i = strtol(line, (char **) &line, 16); + f[i] = x.f; + } else { + f[i] = strtod_inf(line, (char **) &line); + } + } } void @@ -1184,8 +1197,21 @@ get_doubles(const char *line, double *d, unsigned count) { unsigned i; - for (i = 0; i < count; i++) - d[i] = strtod_inf(line, (char **) &line); + for (i = 0; i < count; i++) { + line = eat_whitespace(line); + + if (strncmp(line, "0x", 2) == 0) { + union { + int64_t i64; + double d; + } x; + + x.i64 = strtoll(line, (char **) &line, 16); + d[i] = x.d; + } else { + d[i] = strtod_inf(line, (char **) &line); + } + } } |