[Mesa-dev] [PATCH 2/2] draw: simplify prim mask construction

Zack Rusin zackr at vmware.com
Mon Aug 12 12:26:48 PDT 2013


Looks good.

Reviewed-by: Zack Rusin <zackr at vmware.com>

----- Original Message -----
> From: Roland Scheidegger <sroland at vmware.com>
> 
> The code was quite weird, the second comparison was in fact a complete no-op
> and we can also do the comparison with the vector directly instead of scalar,
> which should not also be faster but it is way more obvious how that mask
> is actually going to look like.
> (Not sure how many instructions that saves as it turned out the mask wasn't
> used in the test geometry shader I used at all after all...)
> ---
>  src/gallium/auxiliary/draw/draw_llvm.c |   32
>  ++++++++++----------------------
>  1 file changed, 10 insertions(+), 22 deletions(-)
> 
> diff --git a/src/gallium/auxiliary/draw/draw_llvm.c
> b/src/gallium/auxiliary/draw/draw_llvm.c
> index 68f6369..84e3392 100644
> --- a/src/gallium/auxiliary/draw/draw_llvm.c
> +++ b/src/gallium/auxiliary/draw/draw_llvm.c
> @@ -2040,31 +2040,19 @@ generate_mask_value(struct draw_gs_llvm_variant
> *variant,
>  {
>     struct gallivm_state *gallivm = variant->gallivm;
>     LLVMBuilderRef builder = gallivm->builder;
> -   LLVMValueRef bits[16];
> -   struct lp_type  mask_type = lp_int_type(gs_type);
> -   struct lp_type mask_elem_type = lp_elem_type(mask_type);
> -   LLVMValueRef mask_val = lp_build_const_vec(gallivm,
> -                                              mask_type,
> -                                              0);
> +   struct lp_type mask_type = lp_int_type(gs_type);
> +   LLVMValueRef num_prims;
> +   LLVMValueRef mask_val = lp_build_const_vec(gallivm, mask_type, 0);
>     unsigned i;
>  
> -   assert(gs_type.length <= Elements(bits));
> -
> -   for (i = gs_type.length; i >= 1; --i) {
> -      int idx = i - 1;
> -      LLVMValueRef ind = lp_build_const_int32(gallivm, i);
> -      bits[idx] = lp_build_compare(gallivm,
> -                                   mask_elem_type, PIPE_FUNC_GEQUAL,
> -                                   variant->num_prims, ind);
> -   }
> -   for (i = 0; i < gs_type.length; ++i) {
> -      LLVMValueRef ind = lp_build_const_int32(gallivm, i);
> -      mask_val = LLVMBuildInsertElement(builder, mask_val, bits[i], ind,
> "");
> +   num_prims = lp_build_broadcast(gallivm, lp_build_vec_type(gallivm,
> mask_type),
> +                                  variant->num_prims);
> +   for (i = 0; i <= gs_type.length; i++) {
> +      LLVMValueRef idx = lp_build_const_int32(gallivm, i);
> +      mask_val = LLVMBuildInsertElement(builder, mask_val, idx, idx, "");
>     }
> -   mask_val = lp_build_compare(gallivm,
> -                               mask_type, PIPE_FUNC_NOTEQUAL,
> -                               mask_val,
> -                               lp_build_const_int_vec(gallivm, mask_type,
> 0));
> +   mask_val = lp_build_compare(gallivm, mask_type,
> +                               PIPE_FUNC_GREATER, num_prims, mask_val);
>  
>     return mask_val;
>  }
> --
> 1.7.9.5
> 


More information about the mesa-dev mailing list