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