xref: /aosp_15_r20/external/mesa3d/src/gallium/drivers/llvmpipe/lp_bld_interp.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /**************************************************************************
2  *
3  * Copyright 2009 VMware, Inc.
4  * All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the
8  * "Software"), to deal in the Software without restriction, including
9  * without limitation the rights to use, copy, modify, merge, publish,
10  * distribute, sub license, and/or sell copies of the Software, and to
11  * permit persons to whom the Software is furnished to do so, subject to
12  * the following conditions:
13  *
14  * The above copyright notice and this permission notice (including the
15  * next paragraph) shall be included in all copies or substantial portions
16  * of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25  *
26  **************************************************************************/
27 
28 /**
29  * @file
30  * Position and shader input interpolation.
31  *
32  * Special attention is given to the interpolation of side by side quads.
33  * Multiplications are made only for the first quad. Interpolation of
34  * inputs for posterior quads are done exclusively with additions, and
35  * perspective divide if necessary.
36  *
37  * @author Jose Fonseca <[email protected]>
38  */
39 
40 #ifndef LP_BLD_INTERP_H
41 #define LP_BLD_INTERP_H
42 
43 
44 #include "gallivm/lp_bld.h"
45 #include "gallivm/lp_bld_type.h"
46 
47 #include "tgsi/tgsi_exec.h"
48 
49 /**
50  * Describes how to compute the interpolation coefficients (a0, dadx, dady)
51  * from the vertices passed into our triangle/line/point functions by the
52  * draw module.
53  *
54  * Vertices are treated as an array of float[4] values, indexed by
55  * src_index.
56  *
57  * LP_INTERP_COLOR is translated to either LP_INTERP_CONSTANT or
58  * PERSPECTIVE depending on flatshade state.
59  */
60 enum lp_interp {
61    LP_INTERP_CONSTANT,
62    LP_INTERP_COLOR,
63    LP_INTERP_LINEAR,
64    LP_INTERP_PERSPECTIVE,
65    LP_INTERP_POSITION,
66    LP_INTERP_FACING
67 };
68 
69 struct lp_shader_input {
70    uint interp:4;       /* enum lp_interp */
71    uint usage_mask:4;   /* bitmask of TGSI_WRITEMASK_x flags */
72    uint src_index:8;    /* where to find values in incoming vertices */
73    uint location:2;     /* TGSI_INTERPOLATE_LOC_* */
74    uint padding:14;
75 };
76 
77 
78 struct lp_build_interp_soa_context
79 {
80    /* TGSI_QUAD_SIZE x float */
81    struct lp_build_context coeff_bld;
82    struct lp_build_context setup_bld;
83 
84    unsigned num_attribs;
85    unsigned mask[1 + PIPE_MAX_SHADER_INPUTS]; /**< TGSI_WRITE_MASK_x */
86    enum lp_interp interp[1 + PIPE_MAX_SHADER_INPUTS];
87    unsigned interp_loc[1 + PIPE_MAX_SHADER_INPUTS];
88    bool depth_clamp;
89 
90    double pos_offset;
91    unsigned coverage_samples;
92    LLVMValueRef num_loop;
93    LLVMTypeRef sample_pos_array_type;
94    LLVMValueRef sample_pos_array;
95 
96    LLVMValueRef x;
97    LLVMValueRef y;
98 
99    LLVMValueRef a0_ptr;
100    LLVMValueRef dadx_ptr;
101    LLVMValueRef dady_ptr;
102 
103    LLVMValueRef a0aos[1 + PIPE_MAX_SHADER_INPUTS];
104    LLVMValueRef dadxaos[1 + PIPE_MAX_SHADER_INPUTS];
105    LLVMValueRef dadyaos[1 + PIPE_MAX_SHADER_INPUTS];
106 
107    LLVMValueRef attribs[1 + PIPE_MAX_SHADER_INPUTS][TGSI_NUM_CHANNELS];
108 
109    LLVMValueRef xoffset_store;
110    LLVMValueRef yoffset_store;
111    LLVMTypeRef store_elem_type;
112 
113    /*
114     * Convenience pointers. Callers may access this one.
115     */
116    const LLVMValueRef *pos;
117    const LLVMValueRef (*inputs)[TGSI_NUM_CHANNELS];
118 };
119 
120 
121 void
122 lp_build_interp_soa_init(struct lp_build_interp_soa_context *bld,
123                          struct gallivm_state *gallivm,
124                          unsigned num_inputs,
125                          const struct lp_shader_input *inputs,
126                          bool pixel_center_integer,
127                          unsigned coverage_samples,
128                          LLVMTypeRef sample_pos_array_type,
129                          LLVMValueRef sample_pos_array,
130                          LLVMValueRef num_loop,
131                          LLVMBuilderRef builder,
132                          struct lp_type type,
133                          LLVMValueRef a0_ptr,
134                          LLVMValueRef dadx_ptr,
135                          LLVMValueRef dady_ptr,
136                          LLVMValueRef x,
137                          LLVMValueRef y);
138 
139 void
140 lp_build_interp_soa_update_inputs_dyn(struct lp_build_interp_soa_context *bld,
141                                       struct gallivm_state *gallivm,
142                                       LLVMValueRef quad_start_index,
143                                       LLVMTypeRef mask_type,
144                                       LLVMValueRef mask_store,
145                                       LLVMValueRef sample_id);
146 
147 void
148 lp_build_interp_soa_update_pos_dyn(struct lp_build_interp_soa_context *bld,
149                                    struct gallivm_state *gallivm,
150                                    LLVMValueRef quad_start_index,
151                                    LLVMValueRef sample_id);
152 
153 LLVMValueRef
154 lp_build_interp_soa(struct lp_build_interp_soa_context *bld,
155                     struct gallivm_state *gallivm,
156                     LLVMValueRef loop_iter,
157                     LLVMTypeRef mask_type,
158                     LLVMValueRef mask_store,
159                     unsigned attrib, unsigned chan,
160                     enum tgsi_interpolate_loc loc,
161                     LLVMValueRef indir_index,
162                     LLVMValueRef offsets[2]);
163 
164 #endif /* LP_BLD_INTERP_H */
165