revert between 56095 -> 55830 in arch
[AROS.git] / workbench / libs / mesa / src / gallium / drivers / i915 / i915_screen.c
blob8e817d624840c820c7d7bb16dd0e79b916116ab2
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 "draw/draw_context.h"
30 #include "util/u_format.h"
31 #include "util/u_format_s3tc.h"
32 #include "util/u_inlines.h"
33 #include "util/u_memory.h"
34 #include "util/u_string.h"
36 #include "i915_reg.h"
37 #include "i915_debug.h"
38 #include "i915_context.h"
39 #include "i915_screen.h"
40 #include "i915_resource.h"
41 #include "i915_winsys.h"
42 #include "i915_public.h"
46 * Probe functions
50 static const char *
51 i915_get_vendor(struct pipe_screen *screen)
53 return "VMware, Inc.";
56 static const char *
57 i915_get_name(struct pipe_screen *screen)
59 static char buffer[128];
60 const char *chipset;
62 switch (i915_screen(screen)->iws->pci_id) {
63 case PCI_CHIP_I915_G:
64 chipset = "915G";
65 break;
66 case PCI_CHIP_I915_GM:
67 chipset = "915GM";
68 break;
69 case PCI_CHIP_I945_G:
70 chipset = "945G";
71 break;
72 case PCI_CHIP_I945_GM:
73 chipset = "945GM";
74 break;
75 case PCI_CHIP_I945_GME:
76 chipset = "945GME";
77 break;
78 case PCI_CHIP_G33_G:
79 chipset = "G33";
80 break;
81 case PCI_CHIP_Q35_G:
82 chipset = "Q35";
83 break;
84 case PCI_CHIP_Q33_G:
85 chipset = "Q33";
86 break;
87 case PCI_CHIP_PINEVIEW_G:
88 chipset = "Pineview G";
89 break;
90 case PCI_CHIP_PINEVIEW_M:
91 chipset = "Pineview M";
92 break;
93 default:
94 chipset = "unknown";
95 break;
98 util_snprintf(buffer, sizeof(buffer), "i915 (chipset: %s)", chipset);
99 return buffer;
102 static int
103 i915_get_param(struct pipe_screen *screen, enum pipe_cap cap)
105 struct i915_screen *is = i915_screen(screen);
107 switch (cap) {
108 /* Supported features (boolean caps). */
109 case PIPE_CAP_ANISOTROPIC_FILTER:
110 case PIPE_CAP_DEPTHSTENCIL_CLEAR_SEPARATE:
111 case PIPE_CAP_NPOT_TEXTURES:
112 case PIPE_CAP_POINT_SPRITE:
113 case PIPE_CAP_PRIMITIVE_RESTART: /* draw module */
114 case PIPE_CAP_TEXTURE_MIRROR_REPEAT:
115 case PIPE_CAP_TEXTURE_SHADOW_MAP:
116 case PIPE_CAP_TWO_SIDED_STENCIL:
117 return 1;
119 /* Features that should be supported (boolean caps). */
120 /* XXX: Just test the code */
121 case PIPE_CAP_BLEND_EQUATION_SEPARATE:
122 /* Also lie about these when asked to (needed for GLSL / GL 2.0) */
123 return is->debug.lie ? 1 : 0;
125 /* Unsupported features (boolean caps). */
126 case PIPE_CAP_ARRAY_TEXTURES:
127 case PIPE_CAP_DEPTH_CLAMP:
128 case PIPE_CAP_INDEP_BLEND_ENABLE:
129 case PIPE_CAP_INDEP_BLEND_FUNC:
130 case PIPE_CAP_TGSI_INSTANCEID:
131 case PIPE_CAP_VERTEX_ELEMENT_INSTANCE_DIVISOR:
132 case PIPE_CAP_SHADER_STENCIL_EXPORT:
133 case PIPE_CAP_TEXTURE_MIRROR_CLAMP:
134 case PIPE_CAP_TEXTURE_SWIZZLE:
135 case PIPE_CAP_TIMER_QUERY:
136 case PIPE_CAP_SM3:
137 case PIPE_CAP_SEAMLESS_CUBE_MAP:
138 case PIPE_CAP_SEAMLESS_CUBE_MAP_PER_TEXTURE:
139 case PIPE_CAP_FRAGMENT_COLOR_CLAMP_CONTROL:
140 case PIPE_CAP_MIXED_COLORBUFFER_FORMATS:
141 return 0;
143 /* Features we can lie about (boolean caps). */
144 case PIPE_CAP_GLSL:
145 case PIPE_CAP_OCCLUSION_QUERY:
146 return is->debug.lie ? 1 : 0;
148 /* Texturing. */
149 case PIPE_CAP_MAX_TEXTURE_IMAGE_UNITS:
150 case PIPE_CAP_MAX_COMBINED_SAMPLERS:
151 return 8;
152 case PIPE_CAP_MAX_VERTEX_TEXTURE_UNITS:
153 return 0;
154 case PIPE_CAP_MAX_TEXTURE_2D_LEVELS:
155 return I915_MAX_TEXTURE_2D_LEVELS;
156 case PIPE_CAP_MAX_TEXTURE_3D_LEVELS:
157 return I915_MAX_TEXTURE_3D_LEVELS;
158 case PIPE_CAP_MAX_TEXTURE_CUBE_LEVELS:
159 return I915_MAX_TEXTURE_2D_LEVELS;
161 /* Render targets. */
162 case PIPE_CAP_MAX_RENDER_TARGETS:
163 return 1;
165 /* Fragment coordinate conventions. */
166 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_UPPER_LEFT:
167 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_HALF_INTEGER:
168 return 1;
169 case PIPE_CAP_TGSI_FS_COORD_ORIGIN_LOWER_LEFT:
170 case PIPE_CAP_TGSI_FS_COORD_PIXEL_CENTER_INTEGER:
171 return 0;
173 default:
174 debug_printf("%s: Unknown cap %u.\n", __FUNCTION__, cap);
175 return 0;
179 static int
180 i915_get_shader_param(struct pipe_screen *screen, unsigned shader, enum pipe_shader_cap cap)
182 switch(shader) {
183 case PIPE_SHADER_VERTEX:
184 return draw_get_shader_param(shader, cap);
185 case PIPE_SHADER_FRAGMENT:
186 break;
187 default:
188 return 0;
191 /* XXX: these are just shader model 2.0 values, fix this! */
192 switch(cap) {
193 case PIPE_SHADER_CAP_MAX_INSTRUCTIONS:
194 return 96;
195 case PIPE_SHADER_CAP_MAX_ALU_INSTRUCTIONS:
196 return 64;
197 case PIPE_SHADER_CAP_MAX_TEX_INSTRUCTIONS:
198 return 32;
199 case PIPE_SHADER_CAP_MAX_TEX_INDIRECTIONS:
200 return 8;
201 case PIPE_SHADER_CAP_MAX_CONTROL_FLOW_DEPTH:
202 return 0;
203 case PIPE_SHADER_CAP_MAX_INPUTS:
204 return 10;
205 case PIPE_SHADER_CAP_MAX_CONSTS:
206 return 32;
207 case PIPE_SHADER_CAP_MAX_CONST_BUFFERS:
208 return 1;
209 case PIPE_SHADER_CAP_MAX_TEMPS:
210 return 12; /* XXX: 12 -> 32 ? */
211 case PIPE_SHADER_CAP_MAX_ADDRS:
212 return 0;
213 case PIPE_SHADER_CAP_MAX_PREDS:
214 return 0;
215 case PIPE_SHADER_CAP_TGSI_CONT_SUPPORTED:
216 return 0;
217 case PIPE_SHADER_CAP_INDIRECT_INPUT_ADDR:
218 case PIPE_SHADER_CAP_INDIRECT_OUTPUT_ADDR:
219 case PIPE_SHADER_CAP_INDIRECT_TEMP_ADDR:
220 case PIPE_SHADER_CAP_INDIRECT_CONST_ADDR:
221 return 1;
222 case PIPE_SHADER_CAP_SUBROUTINES:
223 return 0;
224 default:
225 debug_printf("%s: Unknown cap %u.\n", __FUNCTION__, cap);
226 return 0;
230 static float
231 i915_get_paramf(struct pipe_screen *screen, enum pipe_cap cap)
233 switch(cap) {
234 case PIPE_CAP_MAX_LINE_WIDTH:
235 /* fall-through */
236 case PIPE_CAP_MAX_LINE_WIDTH_AA:
237 return 7.5;
239 case PIPE_CAP_MAX_POINT_WIDTH:
240 /* fall-through */
241 case PIPE_CAP_MAX_POINT_WIDTH_AA:
242 return 255.0;
244 case PIPE_CAP_MAX_TEXTURE_ANISOTROPY:
245 return 4.0;
247 case PIPE_CAP_MAX_TEXTURE_LOD_BIAS:
248 return 16.0;
250 default:
251 debug_printf("%s: Unknown cap %u.\n", __FUNCTION__, cap);
252 return 0;
256 boolean
257 i915_is_format_supported(struct pipe_screen *screen,
258 enum pipe_format format,
259 enum pipe_texture_target target,
260 unsigned sample_count,
261 unsigned tex_usage)
263 static const enum pipe_format tex_supported[] = {
264 PIPE_FORMAT_B8G8R8A8_UNORM,
265 PIPE_FORMAT_B8G8R8X8_UNORM,
266 PIPE_FORMAT_R8G8B8A8_UNORM,
267 PIPE_FORMAT_R8G8B8X8_UNORM,
268 PIPE_FORMAT_B5G6R5_UNORM,
269 PIPE_FORMAT_L8_UNORM,
270 PIPE_FORMAT_A8_UNORM,
271 PIPE_FORMAT_I8_UNORM,
272 PIPE_FORMAT_L8A8_UNORM,
273 PIPE_FORMAT_UYVY,
274 PIPE_FORMAT_YUYV,
275 /* XXX why not?
276 PIPE_FORMAT_Z16_UNORM, */
278 // AROS Quoke1 fix,seems to work,but probably better to fix SDL so
279 // that some other format is used.
280 // Sami
281 PIPE_FORMAT_Z16_UNORM,
283 PIPE_FORMAT_DXT1_RGB,
284 PIPE_FORMAT_DXT1_RGBA,
285 PIPE_FORMAT_DXT3_RGBA,
286 PIPE_FORMAT_DXT5_RGBA,
287 PIPE_FORMAT_Z24X8_UNORM,
288 PIPE_FORMAT_Z24_UNORM_S8_USCALED,
289 PIPE_FORMAT_NONE /* list terminator */
291 static const enum pipe_format render_supported[] = {
292 PIPE_FORMAT_B8G8R8A8_UNORM,
293 PIPE_FORMAT_R8G8B8A8_UNORM,
294 PIPE_FORMAT_B5G6R5_UNORM,
295 PIPE_FORMAT_L8_UNORM,
296 PIPE_FORMAT_A8_UNORM,
297 PIPE_FORMAT_I8_UNORM,
298 PIPE_FORMAT_NONE /* list terminator */
300 static const enum pipe_format depth_supported[] = {
301 /* XXX why not?
302 PIPE_FORMAT_Z16_UNORM, */
303 PIPE_FORMAT_Z16_UNORM, // AROS quake1 fix
304 PIPE_FORMAT_Z24X8_UNORM,
305 PIPE_FORMAT_Z24_UNORM_S8_USCALED,
306 PIPE_FORMAT_NONE /* list terminator */
308 const enum pipe_format *list;
309 uint i;
311 if (!util_format_is_supported(format, tex_usage))
312 return FALSE;
314 if (sample_count > 1)
315 return FALSE;
317 if(tex_usage & PIPE_BIND_DEPTH_STENCIL)
318 list = depth_supported;
319 else if (tex_usage & PIPE_BIND_RENDER_TARGET)
320 list = render_supported;
321 else
322 list = tex_supported;
324 for (i = 0; list[i] != PIPE_FORMAT_NONE; i++) {
325 if (list[i] == format)
326 return TRUE;
329 return FALSE;
334 * Fence functions
338 static void
339 i915_fence_reference(struct pipe_screen *screen,
340 struct pipe_fence_handle **ptr,
341 struct pipe_fence_handle *fence)
343 struct i915_screen *is = i915_screen(screen);
345 is->iws->fence_reference(is->iws, ptr, fence);
348 static boolean
349 i915_fence_signalled(struct pipe_screen *screen,
350 struct pipe_fence_handle *fence)
352 struct i915_screen *is = i915_screen(screen);
354 return is->iws->fence_signalled(is->iws, fence) == 0;
357 static boolean
358 i915_fence_finish(struct pipe_screen *screen,
359 struct pipe_fence_handle *fence,
360 uint64_t timeout)
362 struct i915_screen *is = i915_screen(screen);
364 return is->iws->fence_finish(is->iws, fence) == 0;
369 * Generic functions
373 static void
374 i915_flush_frontbuffer(struct pipe_screen *screen,
375 struct pipe_resource *resource,
376 unsigned level, unsigned layer,
377 void *winsys_drawable_handle)
379 /* XXX: Dummy right now. */
380 (void)screen;
381 (void)resource;
382 (void)level;
383 (void)layer;
384 (void)winsys_drawable_handle;
387 static void
388 i915_destroy_screen(struct pipe_screen *screen)
390 struct i915_screen *is = i915_screen(screen);
392 if (is->iws)
393 is->iws->destroy(is->iws);
395 FREE(is);
399 * Create a new i915_screen object
401 struct pipe_screen *
402 i915_screen_create(struct i915_winsys *iws)
404 struct i915_screen *is = CALLOC_STRUCT(i915_screen);
406 if (!is)
407 return NULL;
409 switch (iws->pci_id) {
410 case PCI_CHIP_I915_G:
411 case PCI_CHIP_I915_GM:
412 is->is_i945 = FALSE;
413 break;
415 case PCI_CHIP_I945_G:
416 case PCI_CHIP_I945_GM:
417 case PCI_CHIP_I945_GME:
418 case PCI_CHIP_G33_G:
419 case PCI_CHIP_Q33_G:
420 case PCI_CHIP_Q35_G:
421 case PCI_CHIP_PINEVIEW_G:
422 case PCI_CHIP_PINEVIEW_M:
423 is->is_i945 = TRUE;
424 break;
426 default:
427 debug_printf("%s: unknown pci id 0x%x, cannot create screen\n",
428 __FUNCTION__, iws->pci_id);
429 FREE(is);
430 return NULL;
433 is->iws = iws;
435 is->base.winsys = NULL;
437 is->base.destroy = i915_destroy_screen;
438 is->base.flush_frontbuffer = i915_flush_frontbuffer;
440 is->base.get_name = i915_get_name;
441 is->base.get_vendor = i915_get_vendor;
442 is->base.get_param = i915_get_param;
443 is->base.get_shader_param = i915_get_shader_param;
444 is->base.get_paramf = i915_get_paramf;
445 is->base.is_format_supported = i915_is_format_supported;
447 is->base.context_create = i915_create_context;
449 is->base.fence_reference = i915_fence_reference;
450 is->base.fence_signalled = i915_fence_signalled;
451 is->base.fence_finish = i915_fence_finish;
453 i915_init_screen_resource_functions(is);
455 i915_debug_init(is);
457 util_format_s3tc_init();
459 return &is->base;