Merge branch '7.8'
[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 "pipe/p_defines.h"
31 #include "pipe/p_screen.h"
32
33 #include "state_tracker/sw_winsys.h"
34
35 #include "sp_texture.h"
36 #include "sp_screen.h"
37 #include "sp_context.h"
38 #include "sp_buffer.h"
39 #include "sp_fence.h"
40 #include "sp_public.h"
41
42
43 static const char *
44 softpipe_get_vendor(struct pipe_screen *screen)
45 {
46 return "VMware, Inc.";
47 }
48
49
50 static const char *
51 softpipe_get_name(struct pipe_screen *screen)
52 {
53 return "softpipe";
54 }
55
56
57 static int
58 softpipe_get_param(struct pipe_screen *screen, int param)
59 {
60 switch (param) {
61 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
62 return PIPE_MAX_SAMPLERS;
63 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS:
64 return PIPE_MAX_VERTEX_SAMPLERS;
65 case PIPE_CAP_MAX_COMBINED_SAMPLERS:
66 return PIPE_MAX_SAMPLERS + PIPE_MAX_VERTEX_SAMPLERS;
67 case PIPE_CAP_NPOT_TEXTURES:
68 return 1;
69 case PIPE_CAP_TWO_SIDED_STENCIL:
70 return 1;
71 case PIPE_CAP_GLSL:
72 return 1;
73 case PIPE_CAP_ANISOTROPIC_FILTER:
74 return 0;
75 case PIPE_CAP_POINT_SPRITE:
76 return 1;
77 case PIPE_CAP_MAX_RENDER_TARGETS:
78 return PIPE_MAX_COLOR_BUFS;
79 case PIPE_CAP_OCCLUSION_QUERY:
80 return 1;
81 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
82 return 1;
83 case PIPE_CAP_TEXTURE_MIRROR_REPEAT:
84 return 1;
85 case PIPE_CAP_TEXTURE_SHADOW_MAP:
86 return 1;
87 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
88 return SP_MAX_TEXTURE_2D_LEVELS;
89 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
90 return SP_MAX_TEXTURE_3D_LEVELS;
91 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
92 return SP_MAX_TEXTURE_2D_LEVELS;
93 case PIPE_CAP_TGSI_CONT_SUPPORTED:
94 return 1;
95 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
96 return 1;
97 case PIPE_CAP_MAX_CONST_BUFFERS:
98 return PIPE_MAX_CONSTANT_BUFFERS;
99 case PIPE_CAP_MAX_CONST_BUFFER_SIZE:
100 return 4096 * 4 * sizeof(float);
101 case PIPE_CAP_INDEP_BLEND_ENABLE:
102 return 1;
103 case PIPE_CAP_INDEP_BLEND_FUNC:
104 return 1;
105 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
106 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
107 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
108 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
109 return 1;
110 default:
111 return 0;
112 }
113 }
114
115
116 static float
117 softpipe_get_paramf(struct pipe_screen *screen, int param)
118 {
119 switch (param) {
120 case PIPE_CAP_MAX_LINE_WIDTH:
121 /* fall-through */
122 case PIPE_CAP_MAX_LINE_WIDTH_AA:
123 return 255.0; /* arbitrary */
124 case PIPE_CAP_MAX_POINT_WIDTH:
125 /* fall-through */
126 case PIPE_CAP_MAX_POINT_WIDTH_AA:
127 return 255.0; /* arbitrary */
128 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
129 return 16.0; /* not actually signficant at this time */
130 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
131 return 16.0; /* arbitrary */
132 default:
133 return 0;
134 }
135 }
136
137
138 /**
139 * Query format support for creating a texture, drawing surface, etc.
140 * \param format the format to test
141 * \param type one of PIPE_TEXTURE, PIPE_SURFACE
142 */
143 static boolean
144 softpipe_is_format_supported( struct pipe_screen *screen,
145 enum pipe_format format,
146 enum pipe_texture_target target,
147 unsigned tex_usage,
148 unsigned geom_flags )
149 {
150 struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
151
152 assert(target == PIPE_TEXTURE_1D ||
153 target == PIPE_TEXTURE_2D ||
154 target == PIPE_TEXTURE_3D ||
155 target == PIPE_TEXTURE_CUBE);
156
157 switch(format) {
158 case PIPE_FORMAT_L16_UNORM:
159 case PIPE_FORMAT_YUYV:
160 case PIPE_FORMAT_UYVY:
161 case PIPE_FORMAT_DXT1_RGB:
162 case PIPE_FORMAT_DXT1_RGBA:
163 case PIPE_FORMAT_DXT3_RGBA:
164 case PIPE_FORMAT_DXT5_RGBA:
165 case PIPE_FORMAT_Z32_FLOAT:
166 case PIPE_FORMAT_R8G8_SNORM:
167 case PIPE_FORMAT_R5SG5SB6U_NORM:
168 case PIPE_FORMAT_R8SG8SB8UX8U_NORM:
169 case PIPE_FORMAT_R8G8B8A8_SNORM:
170 case PIPE_FORMAT_NONE:
171 return FALSE;
172 default:
173 break;
174 }
175
176 if(tex_usage & (PIPE_TEXTURE_USAGE_DISPLAY_TARGET |
177 PIPE_TEXTURE_USAGE_SCANOUT |
178 PIPE_TEXTURE_USAGE_SHARED)) {
179 if(!winsys->is_displaytarget_format_supported(winsys, tex_usage, format))
180 return FALSE;
181 }
182
183 /* XXX: this is often a lie. Pull in logic from llvmpipe to fix.
184 */
185 return TRUE;
186 }
187
188
189 static void
190 softpipe_destroy_screen( struct pipe_screen *screen )
191 {
192 struct softpipe_screen *sp_screen = softpipe_screen(screen);
193 struct sw_winsys *winsys = sp_screen->winsys;
194
195 if(winsys->destroy)
196 winsys->destroy(winsys);
197
198 FREE(screen);
199 }
200
201
202 /* This is often overriden by the co-state tracker.
203 */
204 static void
205 softpipe_flush_frontbuffer(struct pipe_screen *_screen,
206 struct pipe_surface *surface,
207 void *context_private)
208 {
209 struct softpipe_screen *screen = softpipe_screen(_screen);
210 struct sw_winsys *winsys = screen->winsys;
211 struct softpipe_texture *texture = softpipe_texture(surface->texture);
212
213 assert(texture->dt);
214 if (texture->dt)
215 winsys->displaytarget_display(winsys, texture->dt, context_private);
216 }
217
218 /**
219 * Create a new pipe_screen object
220 * Note: we're not presently subclassing pipe_screen (no softpipe_screen).
221 */
222 struct pipe_screen *
223 softpipe_create_screen(struct sw_winsys *winsys)
224 {
225 struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen);
226
227 if (!screen)
228 return NULL;
229
230 screen->winsys = winsys;
231
232 screen->base.winsys = NULL;
233 screen->base.destroy = softpipe_destroy_screen;
234
235 screen->base.get_name = softpipe_get_name;
236 screen->base.get_vendor = softpipe_get_vendor;
237 screen->base.get_param = softpipe_get_param;
238 screen->base.get_paramf = softpipe_get_paramf;
239 screen->base.is_format_supported = softpipe_is_format_supported;
240 screen->base.context_create = softpipe_create_context;
241 screen->base.flush_frontbuffer = softpipe_flush_frontbuffer;
242
243 softpipe_init_screen_texture_funcs(&screen->base);
244 softpipe_init_screen_buffer_funcs(&screen->base);
245 softpipe_init_screen_fence_funcs(&screen->base);
246
247 return &screen->base;
248 }