From 5803417c6775c40bdebc1f8bf41965c6219af123 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Mon, 27 Jun 2022 15:58:27 +1000 Subject: [PATCH] glsl: add implicit half float conversions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Acked-by: Marek Olšák Part-of: --- src/compiler/glsl/ast_to_hir.cpp | 9 +++++++++ src/compiler/glsl/glsl_parser_extras.cpp | 5 +++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/compiler/glsl/ast_to_hir.cpp b/src/compiler/glsl/ast_to_hir.cpp index 0c59c2b6710..9a33a2ccd2d 100644 --- a/src/compiler/glsl/ast_to_hir.cpp +++ b/src/compiler/glsl/ast_to_hir.cpp @@ -243,10 +243,18 @@ get_implicit_conversion_operation(const glsl_type *to, const glsl_type *from, struct _mesa_glsl_parse_state *state) { switch (to->base_type) { + case GLSL_TYPE_FLOAT16: + switch (from->base_type) { + case GLSL_TYPE_INT: return ir_unop_i2f16; + case GLSL_TYPE_UINT: return ir_unop_u2f16; + default: return (ir_expression_operation)0; + } + case GLSL_TYPE_FLOAT: switch (from->base_type) { case GLSL_TYPE_INT: return ir_unop_i2f; case GLSL_TYPE_UINT: return ir_unop_u2f; + case GLSL_TYPE_FLOAT16: return ir_unop_f162f; default: return (ir_expression_operation)0; } @@ -264,6 +272,7 @@ get_implicit_conversion_operation(const glsl_type *to, const glsl_type *from, switch (from->base_type) { case GLSL_TYPE_INT: return ir_unop_i2d; case GLSL_TYPE_UINT: return ir_unop_u2d; + case GLSL_TYPE_FLOAT16: return ir_unop_f162d; case GLSL_TYPE_FLOAT: return ir_unop_f2d; case GLSL_TYPE_INT64: return ir_unop_i642d; case GLSL_TYPE_UINT64: return ir_unop_u642d; diff --git a/src/compiler/glsl/glsl_parser_extras.cpp b/src/compiler/glsl/glsl_parser_extras.cpp index 918286703d0..8c4a08b0bf3 100644 --- a/src/compiler/glsl/glsl_parser_extras.cpp +++ b/src/compiler/glsl/glsl_parser_extras.cpp @@ -980,7 +980,8 @@ _mesa_glsl_can_implicitly_convert(const glsl_type *from, const glsl_type *desire return false; /* int and uint can be converted to float. */ - if (glsl_type_is_float(desired) && glsl_type_is_integer_32(from)) + if (glsl_type_is_float(desired) && (glsl_type_is_integer_32(from) || + glsl_type_is_float_16(from))) return true; /* With GLSL 4.0, ARB_gpu_shader5, or MESA_shader_integer_functions, int @@ -999,7 +1000,7 @@ _mesa_glsl_can_implicitly_convert(const glsl_type *from, const glsl_type *desire /* Conversions from different types to double. */ if ((!state || state->has_double()) && glsl_type_is_double(desired)) { - if (glsl_type_is_float(from)) + if (glsl_type_is_float_16_32(from)) return true; if (glsl_type_is_integer_32(from)) return true;