Merge branch 'master' of ssh://git.freedesktop.org/git/mesa/mesa into pipe-video
[mesa.git] / src / gallium / drivers / softpipe / sp_screen.c
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28
29 #include "util/u_memory.h"
30 #include "util/u_format.h"
31 #include "util/u_format_s3tc.h"
32 #include "pipe/p_defines.h"
33 #include "pipe/p_screen.h"
34
35 #include "state_tracker/sw_winsys.h"
36
37 #include "sp_texture.h"
38 #include "sp_screen.h"
39 #include "sp_context.h"
40 #include "sp_fence.h"
41 #include "sp_public.h"
42
43
44 static const char *
45 softpipe_get_vendor(struct pipe_screen *screen)
46 {
47 return "VMware, Inc.";
48 }
49
50
51 static const char *
52 softpipe_get_name(struct pipe_screen *screen)
53 {
54 return "softpipe";
55 }
56
57
58 static int
59 softpipe_get_param(struct pipe_screen *screen, int param)
60 {
61 switch (param) {
62 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
63 return PIPE_MAX_SAMPLERS;
64 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS:
65 return PIPE_MAX_VERTEX_SAMPLERS;
66 case PIPE_CAP_MAX_COMBINED_SAMPLERS:
67 return PIPE_MAX_SAMPLERS + PIPE_MAX_VERTEX_SAMPLERS;
68 case PIPE_CAP_NPOT_TEXTURES:
69 return 1;
70 case PIPE_CAP_TWO_SIDED_STENCIL:
71 return 1;
72 case PIPE_CAP_GLSL:
73 return 1;
74 case PIPE_CAP_ANISOTROPIC_FILTER:
75 return 0;
76 case PIPE_CAP_POINT_SPRITE:
77 return 1;
78 case PIPE_CAP_MAX_RENDER_TARGETS:
79 return PIPE_MAX_COLOR_BUFS;
80 case PIPE_CAP_OCCLUSION_QUERY:
81 return 1;
82 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
83 return 1;
84 case PIPE_CAP_TEXTURE_MIRROR_REPEAT:
85 return 1;
86 case PIPE_CAP_TEXTURE_SHADOW_MAP:
87 return 1;
88 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
89 return SP_MAX_TEXTURE_2D_LEVELS;
90 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
91 return SP_MAX_TEXTURE_3D_LEVELS;
92 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
93 return SP_MAX_TEXTURE_2D_LEVELS;
94 case PIPE_CAP_TGSI_CONT_SUPPORTED:
95 return 1;
96 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
97 return 1;
98 case PIPE_CAP_MAX_CONST_BUFFERS:
99 return PIPE_MAX_CONSTANT_BUFFERS;
100 case PIPE_CAP_MAX_CONST_BUFFER_SIZE:
101 return 4096 * 4 * sizeof(float);
102 case PIPE_CAP_INDEP_BLEND_ENABLE:
103 return 1;
104 case PIPE_CAP_INDEP_BLEND_FUNC:
105 return 1;
106 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
107 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
108 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
109 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
110 return 1;
111 default:
112 return 0;
113 }
114 }
115
116
117 static float
118 softpipe_get_paramf(struct pipe_screen *screen, int param)
119 {
120 switch (param) {
121 case PIPE_CAP_MAX_LINE_WIDTH:
122 /* fall-through */
123 case PIPE_CAP_MAX_LINE_WIDTH_AA:
124 return 255.0; /* arbitrary */
125 case PIPE_CAP_MAX_POINT_WIDTH:
126 /* fall-through */
127 case PIPE_CAP_MAX_POINT_WIDTH_AA:
128 return 255.0; /* arbitrary */
129 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
130 return 16.0; /* not actually signficant at this time */
131 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
132 return 16.0; /* arbitrary */
133 default:
134 return 0;
135 }
136 }
137
138
139 /**
140 * Query format support for creating a texture, drawing surface, etc.
141 * \param format the format to test
142 * \param type one of PIPE_TEXTURE, PIPE_SURFACE
143 */
144 static boolean
145 softpipe_is_format_supported( struct pipe_screen *screen,
146 enum pipe_format format,
147 enum pipe_texture_target target,
148 unsigned bind,
149 unsigned geom_flags )
150 {
151 struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
152 const struct util_format_description *format_desc;
153
154 assert(target == PIPE_TEXTURE_1D ||
155 target == PIPE_TEXTURE_2D ||
156 target == PIPE_TEXTURE_3D ||
157 target == PIPE_TEXTURE_CUBE);
158
159 format_desc = util_format_description(format);
160 if (!format_desc)
161 return FALSE;
162
163 if (bind & (PIPE_BIND_DISPLAY_TARGET |
164 PIPE_BIND_SCANOUT |
165 PIPE_BIND_SHARED)) {
166 if(!winsys->is_displaytarget_format_supported(winsys, bind, format))
167 return FALSE;
168 }
169
170 if (bind & PIPE_BIND_RENDER_TARGET) {
171 if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS)
172 return FALSE;
173
174 /*
175 * Although possible, it is unnatural to render into compressed or YUV
176 * surfaces. So disable these here to avoid going into weird paths
177 * inside the state trackers.
178 */
179 if (format_desc->block.width != 1 ||
180 format_desc->block.height != 1)
181 return FALSE;
182
183 /*
184 * TODO: Unfortunately we cannot render into anything more than 32 bits
185 * because we encode color clear values into a 32bit word.
186 */
187 if (format_desc->block.bits > 32)
188 return FALSE;
189 }
190
191 if (bind & PIPE_BIND_DEPTH_STENCIL) {
192 if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
193 return FALSE;
194
195 /*
196 * TODO: Unfortunately we cannot render into anything more than 32 bits
197 * because we encode depth and stencil clear values into a 32bit word.
198 */
199 if (format_desc->block.bits > 32)
200 return FALSE;
201
202 /*
203 * TODO: eliminate this restriction
204 */
205 if (format == PIPE_FORMAT_Z32_FLOAT)
206 return FALSE;
207 }
208
209 /*
210 * All other operations (sampling, transfer, etc).
211 */
212
213 if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
214 return util_format_s3tc_enabled;
215 }
216
217 /*
218 * Everything else should be supported by u_format.
219 */
220 return TRUE;
221 }
222
223
224 static void
225 softpipe_destroy_screen( struct pipe_screen *screen )
226 {
227 struct softpipe_screen *sp_screen = softpipe_screen(screen);
228 struct sw_winsys *winsys = sp_screen->winsys;
229
230 if(winsys->destroy)
231 winsys->destroy(winsys);
232
233 FREE(screen);
234 }
235
236
237 /* This is often overriden by the co-state tracker.
238 */
239 static void
240 softpipe_flush_frontbuffer(struct pipe_screen *_screen,
241 struct pipe_surface *surface,
242 void *context_private)
243 {
244 struct softpipe_screen *screen = softpipe_screen(_screen);
245 struct sw_winsys *winsys = screen->winsys;
246 struct softpipe_resource *texture = softpipe_resource(surface->texture);
247
248 assert(texture->dt);
249 if (texture->dt)
250 winsys->displaytarget_display(winsys, texture->dt, context_private);
251 }
252
253 /**
254 * Create a new pipe_screen object
255 * Note: we're not presently subclassing pipe_screen (no softpipe_screen).
256 */
257 struct pipe_screen *
258 softpipe_create_screen(struct sw_winsys *winsys)
259 {
260 struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen);
261
262 if (!screen)
263 return NULL;
264
265 screen->winsys = winsys;
266
267 screen->base.winsys = NULL;
268 screen->base.destroy = softpipe_destroy_screen;
269
270 screen->base.get_name = softpipe_get_name;
271 screen->base.get_vendor = softpipe_get_vendor;
272 screen->base.get_param = softpipe_get_param;
273 screen->base.get_paramf = softpipe_get_paramf;
274 screen->base.is_format_supported = softpipe_is_format_supported;
275 screen->base.context_create = softpipe_create_context;
276 screen->base.flush_frontbuffer = softpipe_flush_frontbuffer;
277
278 util_format_s3tc_init();
279
280 softpipe_init_screen_texture_funcs(&screen->base);
281 softpipe_init_screen_fence_funcs(&screen->base);
282
283 return &screen->base;
284 }