From: Caio Marcelo de Oliveira Filho Date: Wed, 27 Mar 2019 22:07:20 +0000 (-0700) Subject: nir/algebraic: Lower CS derivatives to zero when no group defined X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d08a74d2bf12721f450098cfac300b4f5bcc5dfc;p=mesa.git nir/algebraic: Lower CS derivatives to zero when no group defined In compute shaders if no derivative group is defined, the derivatives will always be zero. Specified in NV_compute_shader_derivatives. To make the check more convenient, add a "info" local variable to the generated code so we can refer to it in the Python rules. (Jason) Reviewed-by: Ian Romanick Reviewed-by: Jason Ekstrand --- diff --git a/src/compiler/nir/nir_algebraic.py b/src/compiler/nir/nir_algebraic.py index d4b3bb5957f..4772d4d123d 100644 --- a/src/compiler/nir/nir_algebraic.py +++ b/src/compiler/nir/nir_algebraic.py @@ -770,7 +770,9 @@ ${pass_name}(nir_shader *shader) bool progress = false; bool condition_flags[${len(condition_list)}]; const nir_shader_compiler_options *options = shader->options; + const shader_info *info = &shader->info; (void) options; + (void) info; % for index, condition in enumerate(condition_list): condition_flags[${index}] = ${condition}; diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py index d6737995844..b8d418c2e49 100644 --- a/src/compiler/nir/nir_opt_algebraic.py +++ b/src/compiler/nir/nir_opt_algebraic.py @@ -972,6 +972,18 @@ for op in ['fadd', 'fmul', 'iadd', 'imul']: ((op, ('bcsel(is_used_once)', a, '#b', c), '#d'), ('bcsel', a, (op, b, d), (op, c, d))) ] +# For derivatives in compute shaders, GLSL_NV_compute_shader_derivatives +# states: +# +# If neither layout qualifier is specified, derivatives in compute shaders +# return zero, which is consistent with the handling of built-in texture +# functions like texture() in GLSL 4.50 compute shaders. +for op in ['fddx', 'fddx_fine', 'fddx_coarse', + 'fddy', 'fddy_fine', 'fddy_coarse']: + optimizations += [ + ((op, 'a'), 0.0, 'info->stage == MESA_SHADER_COMPUTE && info->cs.derivative_group == DERIVATIVE_GROUP_NONE') +] + # This section contains "late" optimizations that should be run before # creating ffmas and calling regular optimizations for the final time. # Optimizations should go here if they help code generation and conflict