Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / drivers / llvmpipe / lp_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 "pipe/p_defines.h"
32 #include "pipe/p_screen.h"
33
34 #include "lp_texture.h"
35 #include "lp_buffer.h"
36 #include "lp_winsys.h"
37 #include "lp_jit.h"
38 #include "lp_screen.h"
39 #include "lp_debug.h"
40
41 #ifdef DEBUG
42 int LP_DEBUG = 0;
43
44 static const struct debug_named_value lp_debug_flags[] = {
45 { "pipe", DEBUG_PIPE },
46 { "tgsi", DEBUG_TGSI },
47 { "tex", DEBUG_TEX },
48 { "asm", DEBUG_ASM },
49 { "setup", DEBUG_SETUP },
50 { "rast", DEBUG_RAST },
51 { "query", DEBUG_QUERY },
52 { "screen", DEBUG_SCREEN },
53 { "jit", DEBUG_JIT },
54 {NULL, 0}
55 };
56 #endif
57
58
59 static const char *
60 llvmpipe_get_vendor(struct pipe_screen *screen)
61 {
62 return "VMware, Inc.";
63 }
64
65
66 static const char *
67 llvmpipe_get_name(struct pipe_screen *screen)
68 {
69 return "llvmpipe";
70 }
71
72
73 static int
74 llvmpipe_get_param(struct pipe_screen *screen, int param)
75 {
76 switch (param) {
77 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
78 return PIPE_MAX_SAMPLERS;
79 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS:
80 return PIPE_MAX_VERTEX_SAMPLERS;
81 case PIPE_CAP_MAX_COMBINED_SAMPLERS:
82 return PIPE_MAX_SAMPLERS + PIPE_MAX_VERTEX_SAMPLERS;
83 case PIPE_CAP_NPOT_TEXTURES:
84 return 1;
85 case PIPE_CAP_TWO_SIDED_STENCIL:
86 return 1;
87 case PIPE_CAP_GLSL:
88 return 1;
89 case PIPE_CAP_ANISOTROPIC_FILTER:
90 return 0;
91 case PIPE_CAP_POINT_SPRITE:
92 return 1;
93 case PIPE_CAP_MAX_RENDER_TARGETS:
94 return PIPE_MAX_COLOR_BUFS;
95 case PIPE_CAP_OCCLUSION_QUERY:
96 return 1;
97 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
98 return 1;
99 case PIPE_CAP_TEXTURE_MIRROR_REPEAT:
100 return 1;
101 case PIPE_CAP_TEXTURE_SHADOW_MAP:
102 return 1;
103 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
104 return 13; /* max 4Kx4K */
105 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
106 return 9; /* max 256x256x256 */
107 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
108 return 13; /* max 4Kx4K */
109 case PIPE_CAP_TGSI_CONT_SUPPORTED:
110 return 1;
111 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
112 return 1;
113 default:
114 return 0;
115 }
116 }
117
118
119 static float
120 llvmpipe_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 llvmpipe_is_format_supported( struct pipe_screen *_screen,
148 enum pipe_format format,
149 enum pipe_texture_target target,
150 unsigned tex_usage,
151 unsigned geom_flags )
152 {
153 struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
154 struct llvmpipe_winsys *winsys = screen->winsys;
155 const struct util_format_description *format_desc;
156
157 format_desc = util_format_description(format);
158 if(!format_desc)
159 return FALSE;
160
161 assert(target == PIPE_TEXTURE_1D ||
162 target == PIPE_TEXTURE_2D ||
163 target == PIPE_TEXTURE_3D ||
164 target == PIPE_TEXTURE_CUBE);
165
166 switch(format) {
167 case PIPE_FORMAT_DXT1_RGB:
168 case PIPE_FORMAT_DXT1_RGBA:
169 case PIPE_FORMAT_DXT3_RGBA:
170 case PIPE_FORMAT_DXT5_RGBA:
171 return FALSE;
172 default:
173 break;
174 }
175
176 if(tex_usage & PIPE_TEXTURE_USAGE_RENDER_TARGET) {
177 if(format_desc->block.width != 1 ||
178 format_desc->block.height != 1)
179 return FALSE;
180
181 if(format_desc->layout != UTIL_FORMAT_LAYOUT_SCALAR &&
182 format_desc->layout != UTIL_FORMAT_LAYOUT_ARITH &&
183 format_desc->layout != UTIL_FORMAT_LAYOUT_ARRAY)
184 return FALSE;
185
186 if(format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB &&
187 format_desc->colorspace != UTIL_FORMAT_COLORSPACE_SRGB)
188 return FALSE;
189 }
190
191 if(tex_usage & PIPE_TEXTURE_USAGE_DISPLAY_TARGET) {
192 if(!winsys->is_displaytarget_format_supported(winsys, format))
193 return FALSE;
194 }
195
196 if(tex_usage & PIPE_TEXTURE_USAGE_DEPTH_STENCIL) {
197 if(format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
198 return FALSE;
199
200 /* FIXME: Temporary restriction. See lp_state_fs.c. */
201 if(format_desc->block.bits != 32)
202 return FALSE;
203 }
204
205 /* FIXME: Temporary restrictions. See lp_bld_sample_soa.c */
206 if(tex_usage & PIPE_TEXTURE_USAGE_SAMPLER) {
207 if(format_desc->block.width != 1 ||
208 format_desc->block.height != 1)
209 return FALSE;
210
211 if(format_desc->layout != UTIL_FORMAT_LAYOUT_SCALAR &&
212 format_desc->layout != UTIL_FORMAT_LAYOUT_ARITH &&
213 format_desc->layout != UTIL_FORMAT_LAYOUT_ARRAY)
214 return FALSE;
215
216 if(format_desc->colorspace != UTIL_FORMAT_COLORSPACE_RGB &&
217 format_desc->colorspace != UTIL_FORMAT_COLORSPACE_SRGB &&
218 format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
219 return FALSE;
220 }
221
222 return TRUE;
223 }
224
225
226 static struct pipe_buffer *
227 llvmpipe_surface_buffer_create(struct pipe_screen *screen,
228 unsigned width, unsigned height,
229 enum pipe_format format,
230 unsigned tex_usage,
231 unsigned usage,
232 unsigned *stride)
233 {
234 /* This function should never be used */
235 assert(0);
236 return NULL;
237 }
238
239
240 static void
241 llvmpipe_flush_frontbuffer(struct pipe_screen *_screen,
242 struct pipe_surface *surface,
243 void *context_private)
244 {
245 struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
246 struct llvmpipe_winsys *winsys = screen->winsys;
247 struct llvmpipe_texture *texture = llvmpipe_texture(surface->texture);
248
249 assert(texture->dt);
250 if (texture->dt)
251 winsys->displaytarget_display(winsys, texture->dt, context_private);
252 }
253
254
255 static void
256 llvmpipe_destroy_screen( struct pipe_screen *_screen )
257 {
258 struct llvmpipe_screen *screen = llvmpipe_screen(_screen);
259 struct llvmpipe_winsys *winsys = screen->winsys;
260
261 lp_jit_screen_cleanup(screen);
262
263 if(winsys->destroy)
264 winsys->destroy(winsys);
265
266 FREE(screen);
267 }
268
269
270
271 /**
272 * Create a new pipe_screen object
273 * Note: we're not presently subclassing pipe_screen (no llvmpipe_screen).
274 */
275 struct pipe_screen *
276 llvmpipe_create_screen(struct llvmpipe_winsys *winsys)
277 {
278 struct llvmpipe_screen *screen = CALLOC_STRUCT(llvmpipe_screen);
279
280 #ifdef DEBUG
281 LP_DEBUG = debug_get_flags_option("LP_DEBUG", lp_debug_flags, 0 );
282 #endif
283
284 if (!screen)
285 return NULL;
286
287 screen->winsys = winsys;
288
289 screen->base.destroy = llvmpipe_destroy_screen;
290
291 screen->base.get_name = llvmpipe_get_name;
292 screen->base.get_vendor = llvmpipe_get_vendor;
293 screen->base.get_param = llvmpipe_get_param;
294 screen->base.get_paramf = llvmpipe_get_paramf;
295 screen->base.is_format_supported = llvmpipe_is_format_supported;
296
297 screen->base.surface_buffer_create = llvmpipe_surface_buffer_create;
298 screen->base.flush_frontbuffer = llvmpipe_flush_frontbuffer;
299
300 llvmpipe_init_screen_texture_funcs(&screen->base);
301 llvmpipe_init_screen_buffer_funcs(&screen->base);
302
303 lp_jit_screen_init(screen);
304
305 return &screen->base;
306 }