nir: add support for flushing to zero denorm constants

v2:
- Refactor conditions and shared function (Connor).
- Move code to nir_eval_const_opcode() (Connor).
- Don't flush to zero on fquantize2f16
  From Vulkan spec, VK_KHR_shader_float_controls section:

  "3) Do denorm and rounding mode controls apply to OpSpecConstantOp?

  RESOLVED: Yes, except when the opcode is OpQuantizeToF16."

v3:
- Fix bit size (Connor).
- Fix execution mode on nir_loop_analize (Connor).

v4:
- Adapt after API changes to nir_eval_const_opcode (Andres).

v5:
- Simplify constant_denorm_flush_to_zero (Caio).

v6:
- Adapt after API changes and to use the new constant
  constructors (Andres).
- Replace MAYBE_UNUSED with UNUSED as the first is going
  away (Andres).

v7:
- Adapt to newly added calls (Andres).
- Simplified the auxiliary to flush denorms to zero (Caio).
- Updated to renamed supported capabilities member (Andres).

Signed-off-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
Signed-off-by: Andres Gomez <agomez@igalia.com>
Reviewed-by: Connor Abbott <cwabbott0@gmail.com> [v4]
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
This commit is contained in:
Samuel Iglesias Gonsálvez
2018-06-20 09:11:14 +02:00
committed by Andres Gomez
parent 45668a8be1
commit f7d73db353
5 changed files with 109 additions and 41 deletions

View File

@@ -33,7 +33,7 @@
*/
static bool
constant_fold_alu_instr(nir_alu_instr *instr, void *mem_ctx)
constant_fold_alu_instr(nir_alu_instr *instr, void *mem_ctx, unsigned execution_mode)
{
nir_const_value src[NIR_MAX_VEC_COMPONENTS][NIR_MAX_VEC_COMPONENTS];
@@ -88,7 +88,7 @@ constant_fold_alu_instr(nir_alu_instr *instr, void *mem_ctx)
for (unsigned i = 0; i < nir_op_infos[instr->op].num_inputs; ++i)
srcs[i] = src[i];
nir_eval_const_opcode(instr->op, dest, instr->dest.dest.ssa.num_components,
bit_size, srcs);
bit_size, srcs, execution_mode);
nir_load_const_instr *new_instr =
nir_load_const_instr_create(mem_ctx,
@@ -144,14 +144,14 @@ constant_fold_intrinsic_instr(nir_intrinsic_instr *instr)
}
static bool
constant_fold_block(nir_block *block, void *mem_ctx)
constant_fold_block(nir_block *block, void *mem_ctx, unsigned execution_mode)
{
bool progress = false;
nir_foreach_instr_safe(instr, block) {
switch (instr->type) {
case nir_instr_type_alu:
progress |= constant_fold_alu_instr(nir_instr_as_alu(instr), mem_ctx);
progress |= constant_fold_alu_instr(nir_instr_as_alu(instr), mem_ctx, execution_mode);
break;
case nir_instr_type_intrinsic:
progress |=
@@ -167,13 +167,13 @@ constant_fold_block(nir_block *block, void *mem_ctx)
}
static bool
nir_opt_constant_folding_impl(nir_function_impl *impl)
nir_opt_constant_folding_impl(nir_function_impl *impl, unsigned execution_mode)
{
void *mem_ctx = ralloc_parent(impl);
bool progress = false;
nir_foreach_block(block, impl) {
progress |= constant_fold_block(block, mem_ctx);
progress |= constant_fold_block(block, mem_ctx, execution_mode);
}
if (progress) {
@@ -192,10 +192,11 @@ bool
nir_opt_constant_folding(nir_shader *shader)
{
bool progress = false;
unsigned execution_mode = shader->info.float_controls_execution_mode;
nir_foreach_function(function, shader) {
if (function->impl)
progress |= nir_opt_constant_folding_impl(function->impl);
progress |= nir_opt_constant_folding_impl(function->impl, execution_mode);
}
return progress;