• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**************************************************************************
2  *
3  * Copyright 2007 VMware, Inc.
4  * All Rights Reserved.
5  * Copyright 2010 VMware, Inc.  All rights reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the
9  * "Software"), to deal in the Software without restriction, including
10  * without limitation the rights to use, copy, modify, merge, publish,
11  * distribute, sub license, and/or sell copies of the Software, and to
12  * permit persons to whom the Software is furnished to do so, subject to
13  * the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the
16  * next paragraph) shall be included in all copies or substantial portions
17  * of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
23  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  *
27  **************************************************************************/
28 
29 #ifndef SP_TEX_SAMPLE_H
30 #define SP_TEX_SAMPLE_H
31 
32 
33 #include "tgsi/tgsi_exec.h"
34 
35 
36 struct sp_sampler_view;
37 struct sp_sampler;
38 
39 typedef void (*wrap_nearest_func)(float s,
40                                   unsigned size,
41                                   int offset,
42                                   int *icoord);
43 
44 typedef void (*wrap_linear_func)(float s,
45                                  unsigned size,
46                                  int offset,
47                                  int *icoord0,
48                                  int *icoord1,
49                                  float *w);
50 
51 typedef float (*compute_lambda_func)(const struct sp_sampler_view *sp_sview,
52                                      const float s[TGSI_QUAD_SIZE],
53                                      const float t[TGSI_QUAD_SIZE],
54                                      const float p[TGSI_QUAD_SIZE]);
55 
56 struct img_filter_args {
57    float s;
58    float t;
59    float p;
60    unsigned level;
61    unsigned face_id;
62    const int8_t *offset;
63    bool gather_only;
64    int gather_comp;
65 };
66 
67 typedef void (*img_filter_func)(const struct sp_sampler_view *sp_sview,
68                                 const struct sp_sampler *sp_samp,
69                                 const struct img_filter_args *args,
70                                 float *rgba);
71 
72 struct filter_args {
73    enum tgsi_sampler_control control;
74    const int8_t *offset;
75    const uint *faces;
76 };
77 
78 typedef void (*mip_filter_func)(const struct sp_sampler_view *sp_sview,
79                                 const struct sp_sampler *sp_samp,
80                                 img_filter_func min_filter,
81                                 img_filter_func mag_filter,
82                                 const float s[TGSI_QUAD_SIZE],
83                                 const float t[TGSI_QUAD_SIZE],
84                                 const float p[TGSI_QUAD_SIZE],
85                                 const float c0[TGSI_QUAD_SIZE],
86                                 const float lod[TGSI_QUAD_SIZE],
87                                 const struct filter_args *args,
88                                 float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]);
89 
90 
91 typedef void (*mip_level_func)(const struct sp_sampler_view *sp_sview,
92                                const struct sp_sampler *sp_samp,
93                                const float lod[TGSI_QUAD_SIZE],
94                                float level[TGSI_QUAD_SIZE]);
95 
96 typedef void (*fetch_func)(struct sp_sampler_view *sp_sview,
97                            const int i[TGSI_QUAD_SIZE],
98                            const int j[TGSI_QUAD_SIZE], const int k[TGSI_QUAD_SIZE],
99                            const int lod[TGSI_QUAD_SIZE], const int8_t offset[3],
100                            float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]);
101 
102 
103 struct sp_sampler_view
104 {
105    struct pipe_sampler_view base;
106 
107    /* For sp_get_samples_2d_linear_POT:
108     */
109    unsigned xpot;
110    unsigned ypot;
111 
112    boolean need_swizzle;
113    boolean pot2d;
114    boolean need_cube_convert;
115 
116    /* these are different per shader type */
117    struct softpipe_tex_tile_cache *cache;
118    compute_lambda_func compute_lambda;
119 
120 };
121 
122 struct sp_filter_funcs {
123    mip_level_func relative_level;
124    mip_filter_func filter;
125 };
126 
127 struct sp_sampler {
128    struct pipe_sampler_state base;
129 
130    boolean min_mag_equal_repeat_linear;
131    boolean min_mag_equal;
132    unsigned min_img_filter;
133 
134    wrap_nearest_func nearest_texcoord_s;
135    wrap_nearest_func nearest_texcoord_t;
136    wrap_nearest_func nearest_texcoord_p;
137 
138    wrap_linear_func linear_texcoord_s;
139    wrap_linear_func linear_texcoord_t;
140    wrap_linear_func linear_texcoord_p;
141 
142    const struct sp_filter_funcs *filter_funcs;
143 };
144 
145 
146 /**
147  * Subclass of tgsi_sampler
148  */
149 struct sp_tgsi_sampler
150 {
151    struct tgsi_sampler base;  /**< base class */
152    struct sp_sampler *sp_sampler[PIPE_MAX_SAMPLERS];
153    struct sp_sampler_view sp_sview[PIPE_MAX_SHADER_SAMPLER_VIEWS];
154 
155 };
156 
157 compute_lambda_func
158 softpipe_get_lambda_func(const struct pipe_sampler_view *view,
159                          enum pipe_shader_type shader);
160 
161 
162 void *
163 softpipe_create_sampler_state(struct pipe_context *pipe,
164                               const struct pipe_sampler_state *sampler);
165 
166 
167 struct pipe_sampler_view *
168 softpipe_create_sampler_view(struct pipe_context *pipe,
169                              struct pipe_resource *resource,
170                              const struct pipe_sampler_view *templ);
171 
172 
173 struct sp_tgsi_sampler *
174 sp_create_tgsi_sampler(void);
175 
176 
177 #endif /* SP_TEX_SAMPLE_H */
178