[Mesa-dev] [PATCH 09/11] nir: add lowering stage for user-clip-planes / clipdist
Erik Faye-Lund
kusmabite at gmail.com
Mon Sep 14 02:53:59 PDT 2015
On Sun, Sep 13, 2015 at 5:51 PM, Rob Clark <robdclark at gmail.com> wrote:
> From: Rob Clark <robclark at freedesktop.org>
>
> The vertex shader lowering adds calculation for CLIPDIST, if needed
> (ie. user-clip-planes), and the frag shader lowering adds conditional
> kills based on CLIPDIST value (which should be treated as a normal
> interpolated varying by the driver).
<snip>
> +
> +/*
> + * FS lowering
> + */
> +
> +static void
> +lower_clip_fs(nir_function_impl *impl, unsigned ucp_enables,
> + nir_variable **in)
> +{
> + nir_ssa_def *clipdist[MAX_CLIP_PLANES];
> + nir_builder b;
> +
> + nir_builder_init(&b, impl);
> + b.cursor = nir_before_cf_list(&impl->body);
> +
> + if (ucp_enables & 0x0f)
> + load_clipdist_input(&b, in[0], &clipdist[0]);
> + if (ucp_enables & 0xf0)
> + load_clipdist_input(&b, in[1], &clipdist[4]);
> +
> + for (int plane = 0; plane < MAX_CLIP_PLANES; plane++) {
> + if (ucp_enables & (1 << plane)) {
> + nir_intrinsic_instr *discard;
> + nir_ssa_def *cond;
> +
> + cond = nir_flt(&b, clipdist[plane], nir_imm_float(&b, 0.0));
> +
> + discard = nir_intrinsic_instr_create(b.shader,
> + nir_intrinsic_discard_if);
> + discard->src[0] = nir_src_for_ssa(cond);
> + nir_builder_instr_insert(&b, &discard->instr);
I think it's worth noting that this isn't *strictly* correct for
multi-sampling, unless the shader is s run with per-sample shading
(ala GL_ARB_sample_shading). Otherwise, all samples for a pixel will
get the same discard-condition, leading to aliasing along the
resulting edge.
That being said, per-fragment clipping is better than no clipping, so
it's clearly an improvement.
More information about the mesa-dev
mailing list