[Mesa-stable] [PATCH] nir: Flip gl_SamplePosition in nir_lower_wpos_ytransform().

Anuj Phogat anuj.phogat at gmail.com
Wed Nov 2 21:58:15 UTC 2016


On Tue, Nov 1, 2016 at 2:25 PM, Francisco Jerez <currojerez at riseup.net> wrote:
> Assuming the hardware is set-up to use a screen coordinate system
> flipped vertically with respect to the GL's window coordinate system,
> the SYSTEM_VALUE_SAMPLE_POS vector will also be flipped vertically
> with respect to the value expected by the GL, so we need to give it
> the same treatment as gl_FragCoord.  Fixes the following CTS tests on
> i965:
Makes sense.
Reviewed-by: Anuj Phogat <anuj.phogat at gmail.com>

>
>  ES31-CTS.functional.shaders.multisample_interpolation.interpolate_at_offset.at_sample_position.default_framebuffer
>  ES31-CTS.functional.shaders.sample_variables.sample_pos.correctness.default_framebuffer
>
> when run with any multisample configuration, e.g. rgba8888d24s8ms4.
>
> Cc: <mesa-stable at lists.freedesktop.org>
> ---
>  src/compiler/nir/nir_lower_wpos_ytransform.c | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
>
> diff --git a/src/compiler/nir/nir_lower_wpos_ytransform.c b/src/compiler/nir/nir_lower_wpos_ytransform.c
> index 173f058..f211c73 100644
> --- a/src/compiler/nir/nir_lower_wpos_ytransform.c
> +++ b/src/compiler/nir/nir_lower_wpos_ytransform.c
> @@ -273,6 +273,26 @@ lower_interp_var_at_offset(lower_wpos_ytransform_state *state,
>  }
>
>  static void
> +lower_load_sample_pos(lower_wpos_ytransform_state *state,
> +                      nir_intrinsic_instr *intr)
> +{
> +   nir_builder *b = &state->b;
> +   b->cursor = nir_after_instr(&intr->instr);
> +
> +   nir_ssa_def *pos = &intr->dest.ssa;
> +   nir_ssa_def *scale = nir_channel(b, get_transform(state), 0);
> +   nir_ssa_def *neg_scale = nir_channel(b, get_transform(state), 2);
> +   /* Either y or 1-y for scale equal to 1 or -1 respectively. */
> +   nir_ssa_def *flipped_y =
> +               nir_fadd(b, nir_fmax(b, neg_scale, nir_imm_float(b, 0.0)),
> +                        nir_fmul(b, nir_channel(b, pos, 1), scale));
> +   nir_ssa_def *flipped_pos = nir_vec2(b, nir_channel(b, pos, 0), flipped_y);
> +
> +   nir_ssa_def_rewrite_uses_after(&intr->dest.ssa, nir_src_for_ssa(flipped_pos),
> +                                  flipped_pos->parent_instr);
> +}
> +
> +static void
>  lower_wpos_ytransform_block(lower_wpos_ytransform_state *state, nir_block *block)
>  {
>     nir_foreach_instr_safe(instr, block) {
> @@ -287,6 +307,10 @@ lower_wpos_ytransform_block(lower_wpos_ytransform_state *state, nir_block *block
>                 /* gl_FragCoord should not have array/struct deref's: */
>                 assert(dvar->deref.child == NULL);
>                 lower_fragcoord(state, intr);
> +            } else if (var->data.mode == nir_var_system_value &&
> +                       var->data.location == SYSTEM_VALUE_SAMPLE_POS) {
> +               assert(dvar->deref.child == NULL);
> +               lower_load_sample_pos(state, intr);
>              }
>           } else if (intr->intrinsic == nir_intrinsic_interp_var_at_offset) {
>              lower_interp_var_at_offset(state, intr);
> --
> 2.10.1
>
> _______________________________________________
> mesa-stable mailing list
> mesa-stable at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-stable


More information about the mesa-stable mailing list