svga: better method for generating white fs color outputs
[mesa.git] / src / gallium / drivers / svga / svga_screen_texture.h
1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 *
24 **********************************************************/
25
26 #ifndef SVGA_TEXTURE_H
27 #define SVGA_TEXTURE_H
28
29
30 #include "pipe/p_compiler.h"
31 #include "pipe/p_state.h"
32 #include "svga_screen_cache.h"
33
34 struct pipe_context;
35 struct pipe_screen;
36 struct svga_context;
37 struct svga_winsys_surface;
38 enum SVGA3dSurfaceFormat;
39
40
41 #define SVGA_MAX_TEXTURE_LEVELS 12 /* 2048x2048 */
42
43
44 /**
45 * A sampler's view into a texture
46 *
47 * We currently cache one sampler view on
48 * the texture and in there by holding a reference
49 * from the texture to the sampler view.
50 *
51 * Because of this we can not hold a refernce to the
52 * texture from the sampler view. So the user
53 * of the sampler views must make sure that the
54 * texture has a reference take for as long as
55 * the sampler view is refrenced.
56 *
57 * Just unreferencing the sampler_view before the
58 * texture is enough.
59 */
60 struct svga_sampler_view
61 {
62 struct pipe_reference reference;
63
64 struct pipe_texture *texture;
65
66 int min_lod;
67 int max_lod;
68
69 unsigned age;
70
71 struct svga_host_surface_cache_key key;
72 struct svga_winsys_surface *handle;
73 };
74
75
76 struct svga_texture
77 {
78 struct pipe_texture base;
79
80 boolean defined[6][PIPE_MAX_TEXTURE_LEVELS];
81
82 struct svga_sampler_view *cached_view;
83
84 unsigned view_age[SVGA_MAX_TEXTURE_LEVELS];
85 unsigned age;
86
87 boolean views_modified;
88
89 /**
90 * Creation key for the host surface handle.
91 *
92 * This structure describes all the host surface characteristics so that it
93 * can be looked up in cache, since creating a host surface is often a slow
94 * operation.
95 */
96 struct svga_host_surface_cache_key key;
97
98 /**
99 * Handle for the host side surface.
100 *
101 * This handle is owned by this texture. Views should hold on to a reference
102 * to this texture and never destroy this handle directly.
103 */
104 struct svga_winsys_surface *handle;
105 };
106
107
108 struct svga_surface
109 {
110 struct pipe_surface base;
111
112 struct svga_host_surface_cache_key key;
113 struct svga_winsys_surface *handle;
114
115 unsigned real_face;
116 unsigned real_level;
117 unsigned real_zslice;
118
119 boolean dirty;
120 };
121
122
123 struct svga_transfer
124 {
125 struct pipe_transfer base;
126
127 struct svga_winsys_buffer *hwbuf;
128
129 /* Height of the hardware buffer in pixel blocks */
130 unsigned hw_nblocksy;
131
132 /* Temporary malloc buffer when we can't allocate a hardware buffer
133 * big enough */
134 void *swbuf;
135 };
136
137
138 static INLINE struct svga_texture *
139 svga_texture(struct pipe_texture *texture)
140 {
141 return (struct svga_texture *)texture;
142 }
143
144 static INLINE struct svga_surface *
145 svga_surface(struct pipe_surface *surface)
146 {
147 assert(surface);
148 return (struct svga_surface *)surface;
149 }
150
151 static INLINE struct svga_transfer *
152 svga_transfer(struct pipe_transfer *transfer)
153 {
154 assert(transfer);
155 return (struct svga_transfer *)transfer;
156 }
157
158 extern struct svga_sampler_view *
159 svga_get_tex_sampler_view(struct pipe_context *pipe,
160 struct pipe_texture *pt,
161 unsigned min_lod, unsigned max_lod);
162
163 void
164 svga_validate_sampler_view(struct svga_context *svga, struct svga_sampler_view *v);
165
166 void
167 svga_destroy_sampler_view_priv(struct svga_sampler_view *v);
168
169 static INLINE void
170 svga_sampler_view_reference(struct svga_sampler_view **ptr, struct svga_sampler_view *v)
171 {
172 struct svga_sampler_view *old = *ptr;
173
174 if (pipe_reference(&(*ptr)->reference, &v->reference))
175 svga_destroy_sampler_view_priv(old);
176 *ptr = v;
177 }
178
179 extern void
180 svga_propagate_surface(struct pipe_context *pipe, struct pipe_surface *surf);
181
182 extern boolean
183 svga_surface_needs_propagation(struct pipe_surface *surf);
184
185 extern void
186 svga_screen_init_texture_functions(struct pipe_screen *screen);
187
188 enum SVGA3dSurfaceFormat
189 svga_translate_format(enum pipe_format format);
190
191 enum SVGA3dSurfaceFormat
192 svga_translate_format_render(enum pipe_format format);
193
194
195 #endif /* SVGA_TEXTURE_H */