revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / mesa / src / gallium / drivers / softpipe / sp_screen.c
blob30f53a9e6743c687b705d66aa7346cd8a01568d1
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:
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.
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.
26 **************************************************************************/
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 #include "draw/draw_context.h"
36 #include "state_tracker/sw_winsys.h"
37 #include "tgsi/tgsi_exec.h"
39 #include "sp_texture.h"
40 #include "sp_screen.h"
41 #include "sp_context.h"
42 #include "sp_fence.h"
43 #include "sp_public.h"
46 static const char *
47 softpipe_get_vendor(struct pipe_screen *screen)
49 return "VMware, Inc.";
53 static const char *
54 softpipe_get_name(struct pipe_screen *screen)
56 return "softpipe";
60 static int
61 softpipe_get_param(struct pipe_screen *screen, enum pipe_cap param)
63 switch (param) {
64 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
65 return PIPE_MAX_SAMPLERS;
66 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS:
67 #ifdef HAVE_LLVM
68 /* Softpipe doesn't yet know how to tell draw/llvm about textures */
69 return 0;
70 #else
71 return PIPE_MAX_VERTEX_SAMPLERS;
72 #endif
73 case PIPE_CAP_MAX_COMBINED_SAMPLERS:
74 return PIPE_MAX_SAMPLERS + PIPE_MAX_VERTEX_SAMPLERS;
75 case PIPE_CAP_NPOT_TEXTURES:
76 return 1;
77 case PIPE_CAP_TWO_SIDED_STENCIL:
78 return 1;
79 case PIPE_CAP_GLSL:
80 return 1;
81 case PIPE_CAP_SM3:
82 return 1;
83 case PIPE_CAP_ANISOTROPIC_FILTER:
84 return 1;
85 case PIPE_CAP_POINT_SPRITE:
86 return 1;
87 case PIPE_CAP_MAX_RENDER_TARGETS:
88 return PIPE_MAX_COLOR_BUFS;
89 case PIPE_CAP_OCCLUSION_QUERY:
90 return 1;
91 case PIPE_CAP_TIMER_QUERY:
92 return 1;
93 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
94 return 1;
95 case PIPE_CAP_TEXTURE_MIRROR_REPEAT:
96 return 1;
97 case PIPE_CAP_TEXTURE_SHADOW_MAP:
98 return 1;
99 case PIPE_CAP_TEXTURE_SWIZZLE:
100 return 1;
101 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
102 return SP_MAX_TEXTURE_2D_LEVELS;
103 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
104 return SP_MAX_TEXTURE_3D_LEVELS;
105 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
106 return SP_MAX_TEXTURE_2D_LEVELS;
107 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
108 return 1;
109 case PIPE_CAP_INDEP_BLEND_ENABLE:
110 return 1;
111 case PIPE_CAP_INDEP_BLEND_FUNC:
112 return 1;
113 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
114 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
115 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
116 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
117 return 1;
118 case PIPE_CAP_STREAM_OUTPUT:
119 return 1;
120 case PIPE_CAP_PRIMITIVE_RESTART:
121 return 1;
122 case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE:
123 return 0;
124 case PIPE_CAP_SHADER_STENCIL_EXPORT:
125 return 1;
126 case PIPE_CAP_TGSI_INSTANCEID:
127 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
128 return 1;
129 case PIPE_CAP_ARRAY_TEXTURES:
130 return 1;
131 default:
132 return 0;
136 static int
137 softpipe_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shader_cap param)
139 switch(shader)
141 case PIPE_SHADER_FRAGMENT:
142 return tgsi_exec_get_shader_param(param);
143 case PIPE_SHADER_VERTEX:
144 case PIPE_SHADER_GEOMETRY:
145 return draw_get_shader_param(shader, param);
146 default:
147 return 0;
151 static float
152 softpipe_get_paramf(struct pipe_screen *screen, enum pipe_cap param)
154 switch (param) {
155 case PIPE_CAP_MAX_LINE_WIDTH:
156 /* fall-through */
157 case PIPE_CAP_MAX_LINE_WIDTH_AA:
158 return 255.0; /* arbitrary */
159 case PIPE_CAP_MAX_POINT_WIDTH:
160 /* fall-through */
161 case PIPE_CAP_MAX_POINT_WIDTH_AA:
162 return 255.0; /* arbitrary */
163 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
164 return 16.0;
165 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
166 return 16.0; /* arbitrary */
167 default:
168 return 0;
174 * Query format support for creating a texture, drawing surface, etc.
175 * \param format the format to test
176 * \param type one of PIPE_TEXTURE, PIPE_SURFACE
178 static boolean
179 softpipe_is_format_supported( struct pipe_screen *screen,
180 enum pipe_format format,
181 enum pipe_texture_target target,
182 unsigned sample_count,
183 unsigned bind)
185 struct sw_winsys *winsys = softpipe_screen(screen)->winsys;
186 const struct util_format_description *format_desc;
188 assert(target == PIPE_BUFFER ||
189 target == PIPE_TEXTURE_1D ||
190 target == PIPE_TEXTURE_1D_ARRAY ||
191 target == PIPE_TEXTURE_2D ||
192 target == PIPE_TEXTURE_2D_ARRAY ||
193 target == PIPE_TEXTURE_RECT ||
194 target == PIPE_TEXTURE_3D ||
195 target == PIPE_TEXTURE_CUBE);
197 format_desc = util_format_description(format);
198 if (!format_desc)
199 return FALSE;
201 if (sample_count > 1)
202 return FALSE;
204 if (bind & (PIPE_BIND_DISPLAY_TARGET |
205 PIPE_BIND_SCANOUT |
206 PIPE_BIND_SHARED)) {
207 if(!winsys->is_displaytarget_format_supported(winsys, bind, format))
208 return FALSE;
211 if (bind & PIPE_BIND_RENDER_TARGET) {
212 if (format_desc->colorspace == UTIL_FORMAT_COLORSPACE_ZS)
213 return FALSE;
216 * Although possible, it is unnatural to render into compressed or YUV
217 * surfaces. So disable these here to avoid going into weird paths
218 * inside the state trackers.
220 if (format_desc->block.width != 1 ||
221 format_desc->block.height != 1)
222 return FALSE;
225 if (bind & PIPE_BIND_DEPTH_STENCIL) {
226 if (format_desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
227 return FALSE;
230 * TODO: Unfortunately we cannot render into anything more than 32 bits
231 * because we encode depth and stencil clear values into a 32bit word.
233 if (format_desc->block.bits > 32)
234 return FALSE;
237 * TODO: eliminate this restriction
239 if (format == PIPE_FORMAT_Z32_FLOAT)
240 return FALSE;
244 * All other operations (sampling, transfer, etc).
247 if (format_desc->layout == UTIL_FORMAT_LAYOUT_S3TC) {
248 return util_format_s3tc_enabled;
252 * Everything else should be supported by u_format.
254 return TRUE;
258 static void
259 softpipe_destroy_screen( struct pipe_screen *screen )
261 struct softpipe_screen *sp_screen = softpipe_screen(screen);
262 struct sw_winsys *winsys = sp_screen->winsys;
264 if(winsys->destroy)
265 winsys->destroy(winsys);
267 FREE(screen);
271 /* This is often overriden by the co-state tracker.
273 static void
274 softpipe_flush_frontbuffer(struct pipe_screen *_screen,
275 struct pipe_resource *resource,
276 unsigned level, unsigned layer,
277 void *context_private)
279 struct softpipe_screen *screen = softpipe_screen(_screen);
280 struct sw_winsys *winsys = screen->winsys;
281 struct softpipe_resource *texture = softpipe_resource(resource);
283 assert(texture->dt);
284 if (texture->dt)
285 winsys->displaytarget_display(winsys, texture->dt, context_private);
289 * Create a new pipe_screen object
290 * Note: we're not presently subclassing pipe_screen (no softpipe_screen).
292 struct pipe_screen *
293 softpipe_create_screen(struct sw_winsys *winsys)
295 struct softpipe_screen *screen = CALLOC_STRUCT(softpipe_screen);
297 if (!screen)
298 return NULL;
300 screen->winsys = winsys;
302 screen->base.winsys = NULL;
303 screen->base.destroy = softpipe_destroy_screen;
305 screen->base.get_name = softpipe_get_name;
306 screen->base.get_vendor = softpipe_get_vendor;
307 screen->base.get_param = softpipe_get_param;
308 screen->base.get_shader_param = softpipe_get_shader_param;
309 screen->base.get_paramf = softpipe_get_paramf;
310 screen->base.is_format_supported = softpipe_is_format_supported;
311 screen->base.context_create = softpipe_create_context;
312 screen->base.flush_frontbuffer = softpipe_flush_frontbuffer;
314 util_format_s3tc_init();
316 softpipe_init_screen_texture_funcs(&screen->base);
317 softpipe_init_screen_fence_funcs(&screen->base);
319 return &screen->base;