/[packages]/cauldron/mesa/current/SOURCES/0016-nir-builder-Add-a-vector-extract-helper.patch
ViewVC logotype

Annotation of /cauldron/mesa/current/SOURCES/0016-nir-builder-Add-a-vector-extract-helper.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1379265 - (hide annotations) (download)
Wed Mar 20 17:08:42 2019 UTC (3 months ago) by tmb
File size: 2954 byte(s)
more fixes from staging/19.0 branch
1 tmb 1379153 From fa137cd655c901fdcfe3fc2d2dab1dae86e0b3e8 Mon Sep 17 00:00:00 2001
2     From: Jason Ekstrand <jason.ekstrand@intel.com>
3     Date: Mon, 11 Mar 2019 18:58:24 -0500
4 tmb 1379265 Subject: [PATCH 16/24] nir/builder: Add a vector extract helper
5 tmb 1379153
6     This one's a tiny bit better than what we had in spirv_to_nir because it
7     emits a binary tree rather than a linear walk. It also doesn't leave
8     around unneeded bcsel instructions for a constant index and returns an
9     undef for constant OOB access.
10    
11     Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
12     (cherry picked from commit fe9a6c0f14aa3ca6dfb1c7480871c95838b5cf14)
13     ---
14     src/compiler/nir/nir_builder.h | 29 +++++++++++++++++++++++++++++
15     src/compiler/spirv/spirv_to_nir.c | 7 +------
16     2 files changed, 30 insertions(+), 6 deletions(-)
17    
18     diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h
19     index 2a36eb3c91b..101bc7ad637 100644
20     --- a/src/compiler/nir/nir_builder.h
21     +++ b/src/compiler/nir/nir_builder.h
22     @@ -560,6 +560,35 @@ nir_channels(nir_builder *b, nir_ssa_def *def, nir_component_mask_t mask)
23     return nir_swizzle(b, def, swizzle, num_channels, false);
24     }
25    
26     +static inline nir_ssa_def *
27     +_nir_vector_extract_helper(nir_builder *b, nir_ssa_def *vec, nir_ssa_def *c,
28     + unsigned start, unsigned end)
29     +{
30     + if (start == end - 1) {
31     + return nir_channel(b, vec, start);
32     + } else {
33     + unsigned mid = start + (end - start) / 2;
34     + return nir_bcsel(b, nir_ilt(b, c, nir_imm_int(b, mid)),
35     + _nir_vector_extract_helper(b, vec, c, start, mid),
36     + _nir_vector_extract_helper(b, vec, c, mid, end));
37     + }
38     +}
39     +
40     +static inline nir_ssa_def *
41     +nir_vector_extract(nir_builder *b, nir_ssa_def *vec, nir_ssa_def *c)
42     +{
43     + nir_src c_src = nir_src_for_ssa(c);
44     + if (nir_src_is_const(c_src)) {
45     + unsigned c_const = nir_src_as_uint(c_src);
46     + if (c_const < vec->num_components)
47     + return nir_channel(b, vec, c_const);
48     + else
49     + return nir_ssa_undef(b, 1, vec->bit_size);
50     + } else {
51     + return _nir_vector_extract_helper(b, vec, c, 0, vec->num_components);
52     + }
53     +}
54     +
55     static inline nir_ssa_def *
56     nir_i2i(nir_builder *build, nir_ssa_def *x, unsigned dest_bit_size)
57     {
58     diff --git a/src/compiler/spirv/spirv_to_nir.c b/src/compiler/spirv/spirv_to_nir.c
59     index 770460115ca..f91b5e1019c 100644
60     --- a/src/compiler/spirv/spirv_to_nir.c
61     +++ b/src/compiler/spirv/spirv_to_nir.c
62     @@ -3045,12 +3045,7 @@ nir_ssa_def *
63     vtn_vector_extract_dynamic(struct vtn_builder *b, nir_ssa_def *src,
64     nir_ssa_def *index)
65     {
66     - nir_ssa_def *dest = vtn_vector_extract(b, src, 0);
67     - for (unsigned i = 1; i < src->num_components; i++)
68     - dest = nir_bcsel(&b->nb, nir_ieq_imm(&b->nb, index, i),
69     - vtn_vector_extract(b, src, i), dest);
70     -
71     - return dest;
72     + return nir_vector_extract(&b->nb, src, nir_i2i(&b->nb, index, 32));
73     }
74    
75     nir_ssa_def *
76     --
77     2.21.0
78    

  ViewVC Help
Powered by ViewVC 1.1.26