Squashed commit of the following:
[profile/ivi/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_varient;
36
37 typedef void (*wrap_nearest_func)(const float s[4],
38                                   unsigned size,
39                                   int icoord[4]);
40
41 typedef void (*wrap_linear_func)(const float s[4], 
42                                  unsigned size,
43                                  int icoord0[4],
44                                  int icoord1[4],
45                                  float w[4]);
46
47 typedef float (*compute_lambda_func)(const struct sp_sampler_varient *sampler,
48                                      const float s[QUAD_SIZE],
49                                      const float t[QUAD_SIZE],
50                                      const float p[QUAD_SIZE]);
51
52 typedef void (*filter_func)(struct tgsi_sampler *tgsi_sampler,
53                             const float s[QUAD_SIZE],
54                             const float t[QUAD_SIZE],
55                             const float p[QUAD_SIZE],
56                             const float c0[QUAD_SIZE],
57                             enum tgsi_sampler_control control,
58                             float rgba[NUM_CHANNELS][QUAD_SIZE]);
59
60
61 union sp_sampler_key {
62    struct {
63       unsigned target:3;
64       unsigned is_pot:1;
65       unsigned processor:2;
66       unsigned unit:4;
67       unsigned pad:22;
68    } bits;
69    unsigned value;
70 };
71
72 /**
73  * Subclass of tgsi_sampler
74  */
75 struct sp_sampler_varient
76 {
77    struct tgsi_sampler base;  /**< base class */
78
79    union sp_sampler_key key;
80
81    /* The owner of this struct:
82     */
83    const struct pipe_sampler_state *sampler;
84
85
86    /* Currently bound texture:
87     */
88    const struct pipe_resource *texture;
89    struct softpipe_tex_tile_cache *cache;
90
91    unsigned processor;
92
93    /* For sp_get_samples_2d_linear_POT:
94     */
95    unsigned xpot;
96    unsigned ypot;
97    unsigned level;
98
99    unsigned faces[4];
100    
101    wrap_nearest_func nearest_texcoord_s;
102    wrap_nearest_func nearest_texcoord_t;
103    wrap_nearest_func nearest_texcoord_p;
104
105    wrap_linear_func linear_texcoord_s;
106    wrap_linear_func linear_texcoord_t;
107    wrap_linear_func linear_texcoord_p;
108
109    filter_func min_img_filter;
110    filter_func mag_img_filter;
111
112    compute_lambda_func compute_lambda;
113
114    filter_func mip_filter;
115    filter_func compare;
116    
117    /* Linked list:
118     */
119    struct sp_sampler_varient *next;
120 };
121
122 struct sp_sampler;
123
124 /* Create a sampler varient for a given set of non-orthogonal state.  Currently the 
125  */
126 struct sp_sampler_varient *
127 sp_create_sampler_varient( const struct pipe_sampler_state *sampler,
128                            const union sp_sampler_key key );
129
130 void sp_sampler_varient_bind_texture( struct sp_sampler_varient *varient,
131                                       struct softpipe_tex_tile_cache *tex_cache,
132                                       const struct pipe_resource *tex );
133
134 void sp_sampler_varient_destroy( struct sp_sampler_varient * );
135
136
137
138 static INLINE struct sp_sampler_varient *
139 sp_sampler_varient(const struct tgsi_sampler *sampler)
140 {
141    return (struct sp_sampler_varient *) sampler;
142 }
143
144 extern void
145 sp_get_samples(struct tgsi_sampler *tgsi_sampler,
146                const float s[QUAD_SIZE],
147                const float t[QUAD_SIZE],
148                const float p[QUAD_SIZE],
149                float lodbias,
150                float rgba[NUM_CHANNELS][QUAD_SIZE]);
151
152
153 #endif /* SP_TEX_SAMPLE_H */