diff options
author | Neil Roberts <[email protected]> | 2019-05-26 15:32:49 +0200 |
---|---|---|
committer | Marge Bot <[email protected]> | 2020-03-09 16:31:08 +0000 |
commit | 6c1c2b779abfda8c7271240f24e92cb6970106a3 (patch) | |
tree | 219d37aff2a60f736bb528ea5f66331c31be7c92 /src | |
parent | 2b39bb4fc05638c6c250e9b79c5c8dcf7361229c (diff) |
glsl/lower_instructions: Use float16 constants when appropriate
When lowering instructions that involve floating-point constants, pick
the appropriate type for the constant so that it will also work with
float16 parameters.
v2: Use float16_t constructor instead of helper function.
Reviewed-by: Marek Olšák <[email protected]>
Reviewed-by: Alyssa Rosenzweig <[email protected]>
Reviewed-by: Ian Romanick <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3929>
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/glsl/lower_instructions.cpp | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/src/compiler/glsl/lower_instructions.cpp b/src/compiler/glsl/lower_instructions.cpp index f5cf24b86e2..4343159b18f 100644 --- a/src/compiler/glsl/lower_instructions.cpp +++ b/src/compiler/glsl/lower_instructions.cpp @@ -123,6 +123,7 @@ #include "ir.h" #include "ir_builder.h" #include "ir_optimization.h" +#include "util/half_float.h" using namespace ir_builder; @@ -172,6 +173,11 @@ private: void mul64_to_mul_and_mul_high(ir_expression *ir); ir_expression *_carry(operand a, operand b); + + static ir_constant *_imm_fp(void *mem_ctx, + const glsl_type *type, + double f, + unsigned vector_elements=1); }; } /* anonymous namespace */ @@ -273,7 +279,7 @@ lower_instructions_visitor::int_div_to_mul_rcp(ir_expression *ir) void lower_instructions_visitor::exp_to_exp2(ir_expression *ir) { - ir_constant *log2_e = new(ir) ir_constant(float(M_LOG2E)); + ir_constant *log2_e = _imm_fp(ir, ir->type, M_LOG2E); ir->operation = ir_unop_exp2; ir->init_num_operands(); @@ -304,7 +310,7 @@ lower_instructions_visitor::log_to_log2(ir_expression *ir) ir->init_num_operands(); ir->operands[0] = new(ir) ir_expression(ir_unop_log2, ir->operands[0]->type, ir->operands[0], NULL); - ir->operands[1] = new(ir) ir_constant(float(1.0 / M_LOG2E)); + ir->operands[1] = _imm_fp(ir, ir->operands[0]->type, 1.0 / M_LOG2E); this->progress = true; } @@ -837,10 +843,11 @@ lower_instructions_visitor::sat_to_clamp(ir_expression *ir) ir->operation = ir_binop_min; ir->init_num_operands(); + + ir_constant *zero = _imm_fp(ir, ir->operands[0]->type, 0.0); ir->operands[0] = new(ir) ir_expression(ir_binop_max, ir->operands[0]->type, - ir->operands[0], - new(ir) ir_constant(0.0f)); - ir->operands[1] = new(ir) ir_constant(1.0f); + ir->operands[0], zero); + ir->operands[1] = _imm_fp(ir, ir->operands[0]->type, 1.0); this->progress = true; } @@ -1515,6 +1522,25 @@ lower_instructions_visitor::_carry(operand a, operand b) return carry(a, b); } +ir_constant * +lower_instructions_visitor::_imm_fp(void *mem_ctx, + const glsl_type *type, + double f, + unsigned vector_elements) +{ + switch (type->base_type) { + case GLSL_TYPE_FLOAT: + return new(mem_ctx) ir_constant((float) f, vector_elements); + case GLSL_TYPE_DOUBLE: + return new(mem_ctx) ir_constant((double) f, vector_elements); + case GLSL_TYPE_FLOAT16: + return new(mem_ctx) ir_constant(float16_t(f), vector_elements); + default: + assert(!"unknown float type for immediate"); + return NULL; + } +} + void lower_instructions_visitor::imul_high_to_mul(ir_expression *ir) { |