mesa,glsl: Move round_to_even() from glsl to mesa/main (v2)
Move round_to_even's definition to mesa/main so that _mesa_float_to_half() can use it in order to eliminate rounding bias. In additon to moving the fuction definition, prefix its name with "_mesa", just as all other functions in mesa/main are prefixed. v2: Fix Android build. Reviewed-by: Ian Romanick <ian.d.romanick@intel.com> Signed-off-by: Chad Versace <chad.versace@linux.intel.com>
This commit is contained in:
@@ -52,6 +52,7 @@ check_PROGRAMS = \
|
|||||||
|
|
||||||
tests_uniform_initializer_test_SOURCES = \
|
tests_uniform_initializer_test_SOURCES = \
|
||||||
$(top_srcdir)/src/mesa/main/hash_table.c \
|
$(top_srcdir)/src/mesa/main/hash_table.c \
|
||||||
|
$(top_srcdir)/src/mesa/main/imports.c \
|
||||||
$(top_srcdir)/src/mesa/program/prog_hash_table.c\
|
$(top_srcdir)/src/mesa/program/prog_hash_table.c\
|
||||||
$(top_srcdir)/src/mesa/program/symbol_table.c \
|
$(top_srcdir)/src/mesa/program/symbol_table.c \
|
||||||
tests/copy_constant_to_storage_tests.cpp \
|
tests/copy_constant_to_storage_tests.cpp \
|
||||||
@@ -100,6 +101,7 @@ endif
|
|||||||
|
|
||||||
glsl_test_SOURCES = \
|
glsl_test_SOURCES = \
|
||||||
$(top_srcdir)/src/mesa/main/hash_table.c \
|
$(top_srcdir)/src/mesa/main/hash_table.c \
|
||||||
|
$(top_srcdir)/src/mesa/main/imports.c \
|
||||||
$(top_srcdir)/src/mesa/program/prog_hash_table.c \
|
$(top_srcdir)/src/mesa/program/prog_hash_table.c \
|
||||||
$(top_srcdir)/src/mesa/program/symbol_table.c \
|
$(top_srcdir)/src/mesa/program/symbol_table.c \
|
||||||
$(GLSL_SRCDIR)/standalone_scaffolding.cpp \
|
$(GLSL_SRCDIR)/standalone_scaffolding.cpp \
|
||||||
|
@@ -55,6 +55,7 @@ libglslcore_la_SOURCES = \
|
|||||||
|
|
||||||
builtin_compiler_SOURCES = \
|
builtin_compiler_SOURCES = \
|
||||||
$(top_srcdir)/src/mesa/main/hash_table.c \
|
$(top_srcdir)/src/mesa/main/hash_table.c \
|
||||||
|
$(top_srcdir)/src/mesa/main/imports.c \
|
||||||
$(top_srcdir)/src/mesa/program/prog_hash_table.c\
|
$(top_srcdir)/src/mesa/program/prog_hash_table.c\
|
||||||
$(top_srcdir)/src/mesa/program/symbol_table.c \
|
$(top_srcdir)/src/mesa/program/symbol_table.c \
|
||||||
$(BUILTIN_COMPILER_CXX_FILES) \
|
$(BUILTIN_COMPILER_CXX_FILES) \
|
||||||
|
@@ -40,25 +40,6 @@
|
|||||||
#include "glsl_types.h"
|
#include "glsl_types.h"
|
||||||
#include "program/hash_table.h"
|
#include "program/hash_table.h"
|
||||||
|
|
||||||
/* Using C99 rounding functions for roundToEven() implementation is
|
|
||||||
* difficult, because round(), rint, and nearbyint() are affected by
|
|
||||||
* fesetenv(), which the application may have done for its own
|
|
||||||
* purposes. Mesa's IROUND macro is close to what we want, but it
|
|
||||||
* rounds away from 0 on n + 0.5.
|
|
||||||
*/
|
|
||||||
static int
|
|
||||||
round_to_even(float val)
|
|
||||||
{
|
|
||||||
int rounded = IROUND(val);
|
|
||||||
|
|
||||||
if (val - floor(val) == 0.5) {
|
|
||||||
if (rounded % 2 != 0)
|
|
||||||
rounded += val > 0 ? -1 : 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return rounded;
|
|
||||||
}
|
|
||||||
|
|
||||||
static float
|
static float
|
||||||
dot(ir_constant *op0, ir_constant *op1)
|
dot(ir_constant *op0, ir_constant *op1)
|
||||||
{
|
{
|
||||||
@@ -279,7 +260,7 @@ ir_expression::constant_expression_value(struct hash_table *variable_context)
|
|||||||
case ir_unop_round_even:
|
case ir_unop_round_even:
|
||||||
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
|
assert(op[0]->type->base_type == GLSL_TYPE_FLOAT);
|
||||||
for (unsigned c = 0; c < op[0]->type->components(); c++) {
|
for (unsigned c = 0; c < op[0]->type->components(); c++) {
|
||||||
data.f[c] = round_to_even(op[0]->value.f[c]);
|
data.f[c] = _mesa_round_to_even(op[0]->value.f[c]);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@@ -35,10 +35,13 @@ include $(CLEAR_VARS)
|
|||||||
|
|
||||||
LOCAL_MODULE := libmesa_glsl_utils
|
LOCAL_MODULE := libmesa_glsl_utils
|
||||||
|
|
||||||
LOCAL_C_INCLUDES := $(MESA_TOP)/src/glsl
|
LOCAL_C_INCLUDES := \
|
||||||
|
$(MESA_TOP)/src/glsl \
|
||||||
|
$(MESA_TOP)/src/mapi
|
||||||
|
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
main/hash_table.c \
|
main/hash_table.c \
|
||||||
|
main/imports.c \
|
||||||
program/prog_hash_table.c \
|
program/prog_hash_table.c \
|
||||||
program/symbol_table.c
|
program/symbol_table.c
|
||||||
|
|
||||||
@@ -54,10 +57,13 @@ include $(CLEAR_VARS)
|
|||||||
LOCAL_MODULE := libmesa_glsl_utils
|
LOCAL_MODULE := libmesa_glsl_utils
|
||||||
LOCAL_IS_HOST_MODULE := true
|
LOCAL_IS_HOST_MODULE := true
|
||||||
|
|
||||||
LOCAL_C_INCLUDES := $(MESA_TOP)/src/glsl
|
LOCAL_C_INCLUDES := \
|
||||||
|
$(MESA_TOP)/src/glsl \
|
||||||
|
$(MESA_TOP)/src/mapi
|
||||||
|
|
||||||
LOCAL_SRC_FILES := \
|
LOCAL_SRC_FILES := \
|
||||||
main/hash_table.c \
|
main/hash_table.c \
|
||||||
|
main/imports.c \
|
||||||
program/prog_hash_table.c \
|
program/prog_hash_table.c \
|
||||||
program/symbol_table.c
|
program/symbol_table.c
|
||||||
|
|
||||||
|
@@ -314,6 +314,26 @@ _mesa_bitcount_64(uint64_t n)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/* Using C99 rounding functions for roundToEven() implementation is
|
||||||
|
* difficult, because round(), rint, and nearbyint() are affected by
|
||||||
|
* fesetenv(), which the application may have done for its own
|
||||||
|
* purposes. Mesa's IROUND macro is close to what we want, but it
|
||||||
|
* rounds away from 0 on n + 0.5.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
_mesa_round_to_even(float val)
|
||||||
|
{
|
||||||
|
int rounded = IROUND(val);
|
||||||
|
|
||||||
|
if (val - floor(val) == 0.5) {
|
||||||
|
if (rounded % 2 != 0)
|
||||||
|
rounded += val > 0 ? -1 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return rounded;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a 4-byte float to a 2-byte half float.
|
* Convert a 4-byte float to a 2-byte half float.
|
||||||
* Based on code from:
|
* Based on code from:
|
||||||
|
@@ -548,6 +548,9 @@ _mesa_fls(unsigned int n)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int
|
||||||
|
_mesa_round_to_even(float val);
|
||||||
|
|
||||||
extern GLhalfARB
|
extern GLhalfARB
|
||||||
_mesa_float_to_half(float f);
|
_mesa_float_to_half(float f);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user