softpipe/draw/tgsi: simplify driver/tgsi sampler interface
[mesa.git] / src / gallium / drivers / softpipe / sp_tex_sample.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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 struct sp_sampler_variant;
36
37 typedef void (*wrap_nearest_func)(float s,
38 unsigned size,
39 int *icoord);
40
41 typedef void (*wrap_linear_func)(float s,
42 unsigned size,
43 int *icoord0,
44 int *icoord1,
45 float *w);
46
47 typedef float (*compute_lambda_func)(const struct sp_sampler_variant *samp,
48 const float s[TGSI_QUAD_SIZE],
49 const float t[TGSI_QUAD_SIZE],
50 const float p[TGSI_QUAD_SIZE]);
51
52 typedef void (*img_filter_func)(struct sp_sampler_variant *samp,
53 float s,
54 float t,
55 float p,
56 unsigned level,
57 unsigned face_id,
58 float *rgba);
59
60 typedef void (*filter_func)(struct sp_sampler_variant *sp_samp,
61 const float s[TGSI_QUAD_SIZE],
62 const float t[TGSI_QUAD_SIZE],
63 const float p[TGSI_QUAD_SIZE],
64 const float c0[TGSI_QUAD_SIZE],
65 const float lod[TGSI_QUAD_SIZE],
66 enum tgsi_sampler_control control,
67 float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]);
68
69
70 typedef void (*get_dim_func)(struct sp_sampler_variant *sp_samp,
71 int level, int dims[4]);
72
73 typedef void (*fetch_func)(struct sp_sampler_variant *sp_samp,
74 const int i[TGSI_QUAD_SIZE],
75 const int j[TGSI_QUAD_SIZE], const int k[TGSI_QUAD_SIZE],
76 const int lod[TGSI_QUAD_SIZE], const int8_t offset[3],
77 float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]);
78
79
80 union sp_sampler_key {
81 struct {
82 unsigned target:5;
83 unsigned is_pot:1;
84 unsigned processor:2;
85 unsigned unit:4;
86 unsigned swizzle_r:3;
87 unsigned swizzle_g:3;
88 unsigned swizzle_b:3;
89 unsigned swizzle_a:3;
90 unsigned pad:8;
91 } bits;
92 unsigned value;
93 };
94
95
96 struct sp_sampler_variant
97 {
98 union sp_sampler_key key;
99
100 /* The owner of this struct:
101 */
102 const struct pipe_sampler_state *sampler;
103
104
105 /* Currently bound texture:
106 */
107 const struct pipe_sampler_view *view;
108 struct softpipe_tex_tile_cache *cache;
109
110 /* For sp_get_samples_2d_linear_POT:
111 */
112 unsigned xpot;
113 unsigned ypot;
114
115 unsigned faces[TGSI_QUAD_SIZE];
116
117 wrap_nearest_func nearest_texcoord_s;
118 wrap_nearest_func nearest_texcoord_t;
119 wrap_nearest_func nearest_texcoord_p;
120
121 wrap_linear_func linear_texcoord_s;
122 wrap_linear_func linear_texcoord_t;
123 wrap_linear_func linear_texcoord_p;
124
125 img_filter_func min_img_filter;
126 img_filter_func mag_img_filter;
127
128 compute_lambda_func compute_lambda;
129
130 filter_func mip_filter;
131 filter_func compare;
132 filter_func sample_target;
133
134 filter_func get_samples;
135 fetch_func get_texel;
136 get_dim_func get_dims;
137
138
139 /* Linked list:
140 */
141 struct sp_sampler_variant *next;
142 };
143
144
145 /**
146 * Subclass of tgsi_sampler
147 */
148 struct sp_tgsi_sampler
149 {
150 struct tgsi_sampler base; /**< base class */
151 struct sp_sampler_variant *sp_sampler[PIPE_MAX_SAMPLERS];
152
153 };
154
155
156 struct sp_sampler;
157
158 /* Create a sampler variant for a given set of non-orthogonal state. Currently the
159 */
160 struct sp_sampler_variant *
161 sp_create_sampler_variant( const struct pipe_sampler_state *sampler,
162 const union sp_sampler_key key );
163
164 void sp_sampler_variant_bind_view( struct sp_sampler_variant *variant,
165 struct softpipe_tex_tile_cache *tex_cache,
166 const struct pipe_sampler_view *view );
167
168 void sp_sampler_variant_destroy( struct sp_sampler_variant * );
169
170
171
172 static INLINE struct sp_sampler_variant *
173 sp_sampler_variant(const struct tgsi_sampler *sampler)
174 {
175 return (struct sp_sampler_variant *) sampler;
176 }
177
178 extern void
179 sp_get_samples(struct tgsi_sampler *tgsi_sampler,
180 const float s[TGSI_QUAD_SIZE],
181 const float t[TGSI_QUAD_SIZE],
182 const float p[TGSI_QUAD_SIZE],
183 float lodbias,
184 float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]);
185
186
187 struct sp_tgsi_sampler *
188 sp_create_tgsi_sampler(void);
189
190
191 #endif /* SP_TEX_SAMPLE_H */