softpipe: adapt to interface changes
[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_SM3:
75 return 1;
76 case PIPE_CAP_ANISOTROPIC_FILTER:
77 return 0;
78 case PIPE_CAP_POINT_SPRITE:
79 return 1;
80 case PIPE_CAP_MAX_RENDER_TARGETS:
81 return PIPE_MAX_COLOR_BUFS;
82 case PIPE_CAP_OCCLUSION_QUERY:
83 return 1;
84 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
85 return 1;
86 case PIPE_CAP_TEXTURE_MIRROR_REPEAT:
87 return 1;
88 case PIPE_CAP_TEXTURE_SHADOW_MAP:
89 return 1;
90 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
91 return SP_MAX_TEXTURE_2D_LEVELS;
92 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
93 return SP_MAX_TEXTURE_3D_LEVELS;
94 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
95 return SP_MAX_TEXTURE_2D_LEVELS;
96 case PIPE_CAP_TGSI_CONT_SUPPORTED:
97 return 1;
98 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
99 return 1;
100 case PIPE_CAP_MAX_CONST_BUFFERS:
101 return PIPE_MAX_CONSTANT_BUFFERS;
102 case PIPE_CAP_MAX_CONST_BUFFER_SIZE:
103 return 4096 * 4 * sizeof(float);
104 case PIPE_CAP_INDEP_BLEND_ENABLE:
105 return 1;
106 case PIPE_CAP_INDEP_BLEND_FUNC:
107 return 1;
108 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
109 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
110 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
111 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
112 return 1;
113 default:
114 return 0;
115 }
116 }
117
118
119 static float
120 softpipe_get_paramf(struct pipe_screen *screen, int param)
121 {
122 switch (param) {
123 case PIPE_CAP_MAX_LINE_WIDTH:
124 /* fall-through */
125 case PIPE_CAP_MAX_LINE_WIDTH_AA:
126 return 255.0; /* arbitrary */
127 case PIPE_CAP_MAX_POINT_WIDTH:
128 /* fall-through */
129 case PIPE_CAP_MAX_POINT_WIDTH_AA:
130 return 255.0; /* arbitrary */
131 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
132 return 16.0; /* not actually signficant at this time */
133 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
134 return 16.0; /* arbitrary */
135 default:
136 return 0;
137 }
138 }
139
140
141 /**
142 * Query format support for creating a texture, drawing surface, etc.
143 * \param format the format to test
144 * \param type one of PIPE_TEXTURE, PIPE_SURFACE
145 */
146 static boolean
147 softpipe_is_format_supported( struct pipe_screen *screen,
148 enum pipe_format format,
149 enum pipe_texture_target target,
150 unsigned sample_count,
151 unsigned bind,
152 unsigned geom_flags )
153 {
154 struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
155 const struct util_format_description *format_desc;
156
157 assert(target == PIPE_TEXTURE_1D ||
158 target == PIPE_TEXTURE_2D ||
159 target == PIPE_TEXTURE_3D ||
160 target == PIPE_TEXTURE_CUBE);
161
162 format_desc = util_format_description(format);
163 if (!format_desc)
164 return FALSE;
165
166 if (sample_count > 1)
167 return FALSE;
168
169 if (bind & (PIPE_BIND_DISPLAY_TARGET |
170 PIPE_BIND_SCANOUT |
171 PIPE_BIND_SHARED)) {
172 if(!winsys->is_displaytarget_format_supported(winsys, bind, format))
173 return FALSE;
174 }
175
176 if (bind & PIPE_BIND_RENDER_TARGET) {
177 if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS)
178 return FALSE;
179
180 /*
181 * Although possible, it is unnatural to render into compressed or YUV
182 * surfaces. So disable these here to avoid going into weird paths
183 * inside the state trackers.
184 */
185 if (format_desc->block.width != 1 ||
186 format_desc->block.height != 1)
187 return FALSE;
188
189 /*
190 * TODO: Unfortunately we cannot render into anything more than 32 bits
191 * because we encode color clear values into a 32bit word.
192 */
193 if (format_desc->block.bits > 32)
194 return FALSE;
195 }
196
197 if (bind & PIPE_BIND_DEPTH_STENCIL) {
198 if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
199 return FALSE;
200
201 /*
202 * TODO: Unfortunately we cannot render into anything more than 32 bits
203 * because we encode depth and stencil clear values into a 32bit word.
204 */
205 if (format_desc->block.bits > 32)
206 return FALSE;
207
208 /*
209 * TODO: eliminate this restriction
210 */
211 if (format == PIPE_FORMAT_Z32_FLOAT)
212 return FALSE;
213 }
214
215 /*
216 * All other operations (sampling, transfer, etc).
217 */
218
219 if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
220 return util_format_s3tc_enabled;
221 }
222
223 /*
224 * Everything else should be supported by u_format.
225 */
226 return TRUE;
227 }
228
229
230 static void
231 softpipe_destroy_screen( struct pipe_screen *screen )
232 {
233 struct softpipe_screen *sp_screen = softpipe_screen(screen);
234 struct sw_winsys *winsys = sp_screen->winsys;
235
236 if(winsys->destroy)
237 winsys->destroy(winsys);
238
239 FREE(screen);
240 }
241
242
243 /* This is often overriden by the co-state tracker.
244 */
245 static void
246 softpipe_flush_frontbuffer(struct pipe_screen *_screen,
247 struct pipe_surface *surface,
248 void *context_private)
249 {
250 struct softpipe_screen *screen = softpipe_screen(_screen);
251 struct sw_winsys *winsys = screen->winsys;
252 struct softpipe_resource *texture = softpipe_resource(surface->texture);
253
254 assert(texture->dt);
255 if (texture->dt)
256 winsys->displaytarget_display(winsys, texture->dt, context_private);
257 }
258
259 /**
260 * Create a new pipe_screen object
261 * Note: we're not presently subclassing pipe_screen (no softpipe_screen).
262 */
263 struct pipe_screen *
264 softpipe_create_screen(struct sw_winsys *winsys)
265 {
266 struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen);
267
268 if (!screen)
269 return NULL;
270
271 screen->winsys = winsys;
272
273 screen->base.winsys = NULL;
274 screen->base.destroy = softpipe_destroy_screen;
275
276 screen->base.get_name = softpipe_get_name;
277 screen->base.get_vendor = softpipe_get_vendor;
278 screen->base.get_param = softpipe_get_param;
279 screen->base.get_paramf = softpipe_get_paramf;
280 screen->base.is_format_supported = softpipe_is_format_supported;
281 screen->base.context_create = softpipe_create_context;
282 screen->base.flush_frontbuffer = softpipe_flush_frontbuffer;
283
284 util_format_s3tc_init();
285
286 softpipe_init_screen_texture_funcs(&screen->base);
287 softpipe_init_screen_fence_funcs(&screen->base);
288
289 return &screen->base;
290 }