1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**************************************************************************
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * All Rights Reserved.
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2010 VMware, Inc.  All rights reserved.
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * "Software"), to deal in the Software without restriction, including
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * without limitation the rights to use, copy, modify, merge, publish,
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * distribute, sub license, and/or sell copies of the Software, and to
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * permit persons to whom the Software is furnished to do so, subject to
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the following conditions:
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * next paragraph) shall be included in all copies or substantial portions
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of the Software.
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org **************************************************************************/
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#ifndef SP_TEX_SAMPLE_H
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#define SP_TEX_SAMPLE_H
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "tgsi/tgsi_exec.h"
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct sp_sampler_variant;
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef void (*wrap_nearest_func)(float s,
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                  unsigned size,
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                  int *icoord);
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef void (*wrap_linear_func)(float s,
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                 unsigned size,
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                 int *icoord0,
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                 int *icoord1,
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                 float *w);
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef float (*compute_lambda_func)(const struct sp_sampler_variant *sampler,
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                     const float s[TGSI_QUAD_SIZE],
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                     const float t[TGSI_QUAD_SIZE],
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                     const float p[TGSI_QUAD_SIZE]);
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef void (*img_filter_func)(struct tgsi_sampler *tgsi_sampler,
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                float s,
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                float t,
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                float p,
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                unsigned level,
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                unsigned face_id,
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                enum tgsi_sampler_control control,
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                float *rgba);
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgtypedef void (*filter_func)(struct tgsi_sampler *tgsi_sampler,
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                            const float s[TGSI_QUAD_SIZE],
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                            const float t[TGSI_QUAD_SIZE],
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                            const float p[TGSI_QUAD_SIZE],
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                            const float c0[TGSI_QUAD_SIZE],
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                            enum tgsi_sampler_control control,
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                            float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]);
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgunion sp_sampler_key {
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct {
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      unsigned target:3;
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      unsigned is_pot:1;
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      unsigned processor:2;
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      unsigned unit:4;
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      unsigned swizzle_r:3;
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      unsigned swizzle_g:3;
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      unsigned swizzle_b:3;
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      unsigned swizzle_a:3;
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      unsigned pad:10;
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   } bits;
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   unsigned value;
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Subclass of tgsi_sampler
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct sp_sampler_variant
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct tgsi_sampler base;  /**< base class */
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   union sp_sampler_key key;
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* The owner of this struct:
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    */
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   const struct pipe_sampler_state *sampler;
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* Currently bound texture:
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    */
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   const struct pipe_sampler_view *view;
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct softpipe_tex_tile_cache *cache;
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   unsigned processor;
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* For sp_get_samples_2d_linear_POT:
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    */
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   unsigned xpot;
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   unsigned ypot;
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   unsigned faces[TGSI_QUAD_SIZE];
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   wrap_nearest_func nearest_texcoord_s;
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   wrap_nearest_func nearest_texcoord_t;
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   wrap_nearest_func nearest_texcoord_p;
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   wrap_linear_func linear_texcoord_s;
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   wrap_linear_func linear_texcoord_t;
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   wrap_linear_func linear_texcoord_p;
120f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
121f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   img_filter_func min_img_filter;
122f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   img_filter_func mag_img_filter;
123f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
124f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   compute_lambda_func compute_lambda;
125f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
126f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   filter_func mip_filter;
127f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   filter_func compare;
128f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   filter_func sample_target;
129f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
130f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   /* Linked list:
131f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org    */
132f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct sp_sampler_variant *next;
133f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org};
134f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
135f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct sp_sampler;
136f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
137f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/* Create a sampler variant for a given set of non-orthogonal state.  Currently the
138f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org */
139f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstruct sp_sampler_variant *
140f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgsp_create_sampler_variant( const struct pipe_sampler_state *sampler,
141f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                           const union sp_sampler_key key );
142f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
143f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid sp_sampler_variant_bind_view( struct sp_sampler_variant *variant,
144f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                   struct softpipe_tex_tile_cache *tex_cache,
145f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                                   const struct pipe_sampler_view *view );
146f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
147f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid sp_sampler_variant_destroy( struct sp_sampler_variant * );
148f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
149f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
150f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
151f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic INLINE struct sp_sampler_variant *
152f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgsp_sampler_variant(const struct tgsi_sampler *sampler)
153f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
154f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return (struct sp_sampler_variant *) sampler;
155f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
156f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
157f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgextern void
158f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgsp_get_samples(struct tgsi_sampler *tgsi_sampler,
159f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               const float s[TGSI_QUAD_SIZE],
160f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               const float t[TGSI_QUAD_SIZE],
161f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               const float p[TGSI_QUAD_SIZE],
162f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               float lodbias,
163f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org               float rgba[TGSI_NUM_CHANNELS][TGSI_QUAD_SIZE]);
164f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
165f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
166f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#endif /* SP_TEX_SAMPLE_H */
167