dri: Allow selective generation of accum. buffer configs
[mesa.git] / src / mesa / drivers / dri / radeon / radeon_screen.c
1 /**************************************************************************
2
3 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
4 VA Linux Systems Inc., Fremont, California.
5
6 All Rights Reserved.
7
8 Permission is hereby granted, free of charge, to any person obtaining
9 a copy of this software and associated documentation files (the
10 "Software"), to deal in the Software without restriction, including
11 without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense, and/or sell copies of the Software, and to
13 permit persons to whom the Software is furnished to do so, subject to
14 the following conditions:
15
16 The above copyright notice and this permission notice (including the
17 next paragraph) shall be included in all copies or substantial
18 portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
24 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
28 **************************************************************************/
29
30 /**
31 * \file radeon_screen.c
32 * Screen initialization functions for the Radeon driver.
33 *
34 * \author Kevin E. Martin <martin@valinux.com>
35 * \author Gareth Hughes <gareth@valinux.com>
36 */
37
38 #include <errno.h>
39 #include "main/glheader.h"
40 #include "main/imports.h"
41 #include "main/mtypes.h"
42 #include "main/framebuffer.h"
43 #include "main/renderbuffer.h"
44
45 #define STANDALONE_MMIO
46 #include "radeon_chipset.h"
47 #include "radeon_macros.h"
48 #include "radeon_screen.h"
49 #include "radeon_common.h"
50 #if defined(RADEON_R100)
51 #include "radeon_context.h"
52 #include "radeon_tex.h"
53 #elif defined(RADEON_R200)
54 #include "r200_context.h"
55 #include "r200_ioctl.h"
56 #include "r200_tex.h"
57 #elif defined(RADEON_R300)
58 #include "r300_context.h"
59 #include "r300_tex.h"
60 #elif defined(RADEON_R600)
61 #include "r600_context.h"
62 #include "r700_driconf.h" /* +r6/r7 */
63 #include "r600_tex.h" /* +r6/r7 */
64 #endif
65
66 #include "utils.h"
67 #include "vblank.h"
68
69 #include "radeon_bocs_wrapper.h"
70
71 #include "GL/internal/dri_interface.h"
72
73 /* Radeon configuration
74 */
75 #include "xmlpool.h"
76
77 #define DRI_CONF_COMMAND_BUFFER_SIZE(def,min,max) \
78 DRI_CONF_OPT_BEGIN_V(command_buffer_size,int,def, # min ":" # max ) \
79 DRI_CONF_DESC(en,"Size of command buffer (in KB)") \
80 DRI_CONF_DESC(de,"Grösse des Befehlspuffers (in KB)") \
81 DRI_CONF_OPT_END
82
83 #if defined(RADEON_R100) /* R100 */
84 PUBLIC const char __driConfigOptions[] =
85 DRI_CONF_BEGIN
86 DRI_CONF_SECTION_PERFORMANCE
87 DRI_CONF_TCL_MODE(DRI_CONF_TCL_CODEGEN)
88 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
89 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
90 DRI_CONF_MAX_TEXTURE_UNITS(3,2,3)
91 DRI_CONF_HYPERZ(false)
92 DRI_CONF_COMMAND_BUFFER_SIZE(8, 8, 32)
93 DRI_CONF_SECTION_END
94 DRI_CONF_SECTION_QUALITY
95 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB)
96 DRI_CONF_DEF_MAX_ANISOTROPY(1.0,"1.0,2.0,4.0,8.0,16.0")
97 DRI_CONF_NO_NEG_LOD_BIAS(false)
98 DRI_CONF_FORCE_S3TC_ENABLE(false)
99 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER)
100 DRI_CONF_ROUND_MODE(DRI_CONF_ROUND_TRUNC)
101 DRI_CONF_DITHER_MODE(DRI_CONF_DITHER_XERRORDIFF)
102 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
103 DRI_CONF_SECTION_END
104 DRI_CONF_SECTION_DEBUG
105 DRI_CONF_NO_RAST(false)
106 DRI_CONF_SECTION_END
107 DRI_CONF_END;
108 static const GLuint __driNConfigOptions = 15;
109
110 #elif defined(RADEON_R200)
111
112 PUBLIC const char __driConfigOptions[] =
113 DRI_CONF_BEGIN
114 DRI_CONF_SECTION_PERFORMANCE
115 DRI_CONF_TCL_MODE(DRI_CONF_TCL_CODEGEN)
116 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
117 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
118 DRI_CONF_MAX_TEXTURE_UNITS(6,2,6)
119 DRI_CONF_HYPERZ(false)
120 DRI_CONF_COMMAND_BUFFER_SIZE(8, 8, 32)
121 DRI_CONF_SECTION_END
122 DRI_CONF_SECTION_QUALITY
123 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB)
124 DRI_CONF_DEF_MAX_ANISOTROPY(1.0,"1.0,2.0,4.0,8.0,16.0")
125 DRI_CONF_NO_NEG_LOD_BIAS(false)
126 DRI_CONF_FORCE_S3TC_ENABLE(false)
127 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER)
128 DRI_CONF_ROUND_MODE(DRI_CONF_ROUND_TRUNC)
129 DRI_CONF_DITHER_MODE(DRI_CONF_DITHER_XERRORDIFF)
130 DRI_CONF_ALLOW_LARGE_TEXTURES(2)
131 DRI_CONF_TEXTURE_BLEND_QUALITY(1.0,"0.0:1.0")
132 DRI_CONF_SECTION_END
133 DRI_CONF_SECTION_DEBUG
134 DRI_CONF_NO_RAST(false)
135 DRI_CONF_SECTION_END
136 DRI_CONF_SECTION_SOFTWARE
137 DRI_CONF_NV_VERTEX_PROGRAM(false)
138 DRI_CONF_SECTION_END
139 DRI_CONF_END;
140 static const GLuint __driNConfigOptions = 17;
141
142 #elif defined(RADEON_R300) || defined(RADEON_R600)
143
144 #define DRI_CONF_FP_OPTIMIZATION_SPEED 0
145 #define DRI_CONF_FP_OPTIMIZATION_QUALITY 1
146
147 /* TODO: integrate these into xmlpool.h! */
148 #define DRI_CONF_MAX_TEXTURE_IMAGE_UNITS(def,min,max) \
149 DRI_CONF_OPT_BEGIN_V(texture_image_units,int,def, # min ":" # max ) \
150 DRI_CONF_DESC(en,"Number of texture image units") \
151 DRI_CONF_DESC(de,"Anzahl der Textureinheiten") \
152 DRI_CONF_OPT_END
153
154 #define DRI_CONF_MAX_TEXTURE_COORD_UNITS(def,min,max) \
155 DRI_CONF_OPT_BEGIN_V(texture_coord_units,int,def, # min ":" # max ) \
156 DRI_CONF_DESC(en,"Number of texture coordinate units") \
157 DRI_CONF_DESC(de,"Anzahl der Texturkoordinateneinheiten") \
158 DRI_CONF_OPT_END
159
160
161
162 #define DRI_CONF_DISABLE_S3TC(def) \
163 DRI_CONF_OPT_BEGIN(disable_s3tc,bool,def) \
164 DRI_CONF_DESC(en,"Disable S3TC compression") \
165 DRI_CONF_OPT_END
166
167 #define DRI_CONF_DISABLE_FALLBACK(def) \
168 DRI_CONF_OPT_BEGIN(disable_lowimpact_fallback,bool,def) \
169 DRI_CONF_DESC(en,"Disable Low-impact fallback") \
170 DRI_CONF_OPT_END
171
172 #define DRI_CONF_DISABLE_DOUBLE_SIDE_STENCIL(def) \
173 DRI_CONF_OPT_BEGIN(disable_stencil_two_side,bool,def) \
174 DRI_CONF_DESC(en,"Disable GL_EXT_stencil_two_side") \
175 DRI_CONF_OPT_END
176
177 #define DRI_CONF_FP_OPTIMIZATION(def) \
178 DRI_CONF_OPT_BEGIN_V(fp_optimization,enum,def,"0:1") \
179 DRI_CONF_DESC_BEGIN(en,"Fragment Program optimization") \
180 DRI_CONF_ENUM(0,"Optimize for Speed") \
181 DRI_CONF_ENUM(1,"Optimize for Quality") \
182 DRI_CONF_DESC_END \
183 DRI_CONF_OPT_END
184
185 PUBLIC const char __driConfigOptions[] =
186 DRI_CONF_BEGIN
187 DRI_CONF_SECTION_PERFORMANCE
188 DRI_CONF_TCL_MODE(DRI_CONF_TCL_CODEGEN)
189 DRI_CONF_FTHROTTLE_MODE(DRI_CONF_FTHROTTLE_IRQS)
190 DRI_CONF_VBLANK_MODE(DRI_CONF_VBLANK_DEF_INTERVAL_0)
191 DRI_CONF_MAX_TEXTURE_IMAGE_UNITS(8, 2, 8)
192 DRI_CONF_MAX_TEXTURE_COORD_UNITS(8, 2, 8)
193 DRI_CONF_COMMAND_BUFFER_SIZE(8, 8, 32)
194 DRI_CONF_DISABLE_FALLBACK(true)
195 DRI_CONF_DISABLE_DOUBLE_SIDE_STENCIL(false)
196 DRI_CONF_SECTION_END
197 DRI_CONF_SECTION_QUALITY
198 DRI_CONF_TEXTURE_DEPTH(DRI_CONF_TEXTURE_DEPTH_FB)
199 DRI_CONF_DEF_MAX_ANISOTROPY(1.0, "1.0,2.0,4.0,8.0,16.0")
200 DRI_CONF_FORCE_S3TC_ENABLE(false)
201 DRI_CONF_DISABLE_S3TC(false)
202 DRI_CONF_COLOR_REDUCTION(DRI_CONF_COLOR_REDUCTION_DITHER)
203 DRI_CONF_ROUND_MODE(DRI_CONF_ROUND_TRUNC)
204 DRI_CONF_DITHER_MODE(DRI_CONF_DITHER_XERRORDIFF)
205 DRI_CONF_FP_OPTIMIZATION(DRI_CONF_FP_OPTIMIZATION_SPEED)
206 DRI_CONF_SECTION_END
207 DRI_CONF_SECTION_DEBUG
208 DRI_CONF_NO_RAST(false)
209 DRI_CONF_SECTION_END
210 DRI_CONF_END;
211 static const GLuint __driNConfigOptions = 17;
212
213 #endif
214
215 static int getSwapInfo( __DRIdrawable *dPriv, __DRIswapInfo * sInfo );
216
217 static int
218 radeonGetParam(__DRIscreen *sPriv, int param, void *value)
219 {
220 int ret;
221 drm_radeon_getparam_t gp = { 0 };
222 struct drm_radeon_info info = { 0 };
223
224 if (sPriv->drm_version.major >= 2) {
225 info.value = (uint64_t)(uintptr_t)value;
226 switch (param) {
227 case RADEON_PARAM_DEVICE_ID:
228 info.request = RADEON_INFO_DEVICE_ID;
229 break;
230 case RADEON_PARAM_NUM_GB_PIPES:
231 info.request = RADEON_INFO_NUM_GB_PIPES;
232 break;
233 case RADEON_PARAM_NUM_Z_PIPES:
234 info.request = RADEON_INFO_NUM_Z_PIPES;
235 break;
236 default:
237 return -EINVAL;
238 }
239 ret = drmCommandWriteRead(sPriv->fd, DRM_RADEON_INFO, &info, sizeof(info));
240 } else {
241 gp.param = param;
242 gp.value = value;
243
244 ret = drmCommandWriteRead(sPriv->fd, DRM_RADEON_GETPARAM, &gp, sizeof(gp));
245 }
246 return ret;
247 }
248
249 static const __DRIconfig **
250 radeonFillInModes( __DRIscreen *psp,
251 unsigned pixel_bits, unsigned depth_bits,
252 unsigned stencil_bits, GLboolean have_back_buffer )
253 {
254 __DRIconfig **configs;
255 __GLcontextModes *m;
256 unsigned depth_buffer_factor;
257 unsigned back_buffer_factor;
258 int i;
259
260 /* Right now GLX_SWAP_COPY_OML isn't supported, but it would be easy
261 * enough to add support. Basically, if a context is created with an
262 * fbconfig where the swap method is GLX_SWAP_COPY_OML, pageflipping
263 * will never be used.
264 */
265 static const GLenum back_buffer_modes[] = {
266 GLX_NONE, GLX_SWAP_UNDEFINED_OML /*, GLX_SWAP_COPY_OML */
267 };
268
269 uint8_t depth_bits_array[2];
270 uint8_t stencil_bits_array[2];
271 uint8_t msaa_samples_array[1];
272
273 depth_bits_array[0] = depth_bits;
274 depth_bits_array[1] = depth_bits;
275
276 /* Just like with the accumulation buffer, always provide some modes
277 * with a stencil buffer. It will be a sw fallback, but some apps won't
278 * care about that.
279 */
280 stencil_bits_array[0] = stencil_bits;
281 stencil_bits_array[1] = (stencil_bits == 0) ? 8 : stencil_bits;
282
283 msaa_samples_array[0] = 0;
284
285 depth_buffer_factor = (stencil_bits == 0) ? 2 : 1;
286 back_buffer_factor = (have_back_buffer) ? 2 : 1;
287
288 if (pixel_bits == 16) {
289 __DRIconfig **configs_a8r8g8b8;
290 __DRIconfig **configs_r5g6b5;
291
292 configs_r5g6b5 = driCreateConfigs(GL_RGB, GL_UNSIGNED_SHORT_5_6_5,
293 depth_bits_array, stencil_bits_array,
294 depth_buffer_factor, back_buffer_modes,
295 back_buffer_factor, msaa_samples_array,
296 1, TRUE);
297 configs_a8r8g8b8 = driCreateConfigs(GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
298 depth_bits_array, stencil_bits_array,
299 1, back_buffer_modes, 1,
300 msaa_samples_array, 1, TRUE);
301 configs = driConcatConfigs(configs_r5g6b5, configs_a8r8g8b8);
302 } else
303 configs = driCreateConfigs(GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV,
304 depth_bits_array, stencil_bits_array,
305 depth_buffer_factor,
306 back_buffer_modes, back_buffer_factor,
307 msaa_samples_array, 1, TRUE);
308
309 if (configs == NULL) {
310 fprintf( stderr, "[%s:%u] Error creating FBConfig!\n",
311 __func__, __LINE__ );
312 return NULL;
313 }
314
315 /* Mark the visual as slow if there are "fake" stencil bits.
316 */
317 for (i = 0; configs[i]; i++) {
318 m = &configs[i]->modes;
319 if ((m->stencilBits != 0) && (m->stencilBits != stencil_bits)) {
320 m->visualRating = GLX_SLOW_CONFIG;
321 }
322 }
323
324 return (const __DRIconfig **) configs;
325 }
326
327 #if defined(RADEON_R100)
328 static const __DRItexOffsetExtension radeonTexOffsetExtension = {
329 { __DRI_TEX_OFFSET, __DRI_TEX_OFFSET_VERSION },
330 radeonSetTexOffset,
331 };
332
333 static const __DRItexBufferExtension radeonTexBufferExtension = {
334 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
335 radeonSetTexBuffer,
336 radeonSetTexBuffer2,
337 };
338 #endif
339
340 #if defined(RADEON_R200)
341 static const __DRIallocateExtension r200AllocateExtension = {
342 { __DRI_ALLOCATE, __DRI_ALLOCATE_VERSION },
343 r200AllocateMemoryMESA,
344 r200FreeMemoryMESA,
345 r200GetMemoryOffsetMESA
346 };
347
348 static const __DRItexOffsetExtension r200texOffsetExtension = {
349 { __DRI_TEX_OFFSET, __DRI_TEX_OFFSET_VERSION },
350 r200SetTexOffset,
351 };
352
353 static const __DRItexBufferExtension r200TexBufferExtension = {
354 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
355 r200SetTexBuffer,
356 r200SetTexBuffer2,
357 };
358 #endif
359
360 #if defined(RADEON_R300)
361 static const __DRItexOffsetExtension r300texOffsetExtension = {
362 { __DRI_TEX_OFFSET, __DRI_TEX_OFFSET_VERSION },
363 r300SetTexOffset,
364 };
365
366 static const __DRItexBufferExtension r300TexBufferExtension = {
367 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
368 r300SetTexBuffer,
369 r300SetTexBuffer2,
370 };
371 #endif
372
373 #if defined(RADEON_R600)
374 static const __DRItexOffsetExtension r600texOffsetExtension = {
375 { __DRI_TEX_OFFSET, __DRI_TEX_OFFSET_VERSION },
376 r600SetTexOffset, /* +r6/r7 */
377 };
378
379 static const __DRItexBufferExtension r600TexBufferExtension = {
380 { __DRI_TEX_BUFFER, __DRI_TEX_BUFFER_VERSION },
381 r600SetTexBuffer, /* +r6/r7 */
382 r600SetTexBuffer2, /* +r6/r7 */
383 };
384 #endif
385
386 static int radeon_set_screen_flags(radeonScreenPtr screen, int device_id)
387 {
388 screen->device_id = device_id;
389 screen->chip_flags = 0;
390 switch ( device_id ) {
391 case PCI_CHIP_RN50_515E:
392 case PCI_CHIP_RN50_5969:
393 return -1;
394
395 case PCI_CHIP_RADEON_LY:
396 case PCI_CHIP_RADEON_LZ:
397 case PCI_CHIP_RADEON_QY:
398 case PCI_CHIP_RADEON_QZ:
399 screen->chip_family = CHIP_FAMILY_RV100;
400 break;
401
402 case PCI_CHIP_RS100_4136:
403 case PCI_CHIP_RS100_4336:
404 screen->chip_family = CHIP_FAMILY_RS100;
405 break;
406
407 case PCI_CHIP_RS200_4137:
408 case PCI_CHIP_RS200_4337:
409 case PCI_CHIP_RS250_4237:
410 case PCI_CHIP_RS250_4437:
411 screen->chip_family = CHIP_FAMILY_RS200;
412 break;
413
414 case PCI_CHIP_RADEON_QD:
415 case PCI_CHIP_RADEON_QE:
416 case PCI_CHIP_RADEON_QF:
417 case PCI_CHIP_RADEON_QG:
418 /* all original radeons (7200) presumably have a stencil op bug */
419 screen->chip_family = CHIP_FAMILY_R100;
420 screen->chip_flags = RADEON_CHIPSET_TCL | RADEON_CHIPSET_BROKEN_STENCIL;
421 break;
422
423 case PCI_CHIP_RV200_QW:
424 case PCI_CHIP_RV200_QX:
425 case PCI_CHIP_RADEON_LW:
426 case PCI_CHIP_RADEON_LX:
427 screen->chip_family = CHIP_FAMILY_RV200;
428 screen->chip_flags = RADEON_CHIPSET_TCL;
429 break;
430
431 case PCI_CHIP_R200_BB:
432 case PCI_CHIP_R200_BC:
433 case PCI_CHIP_R200_QH:
434 case PCI_CHIP_R200_QL:
435 case PCI_CHIP_R200_QM:
436 screen->chip_family = CHIP_FAMILY_R200;
437 screen->chip_flags = RADEON_CHIPSET_TCL;
438 break;
439
440 case PCI_CHIP_RV250_If:
441 case PCI_CHIP_RV250_Ig:
442 case PCI_CHIP_RV250_Ld:
443 case PCI_CHIP_RV250_Lf:
444 case PCI_CHIP_RV250_Lg:
445 screen->chip_family = CHIP_FAMILY_RV250;
446 screen->chip_flags = R200_CHIPSET_YCBCR_BROKEN | RADEON_CHIPSET_TCL;
447 break;
448
449 case PCI_CHIP_RV280_5960:
450 case PCI_CHIP_RV280_5961:
451 case PCI_CHIP_RV280_5962:
452 case PCI_CHIP_RV280_5964:
453 case PCI_CHIP_RV280_5965:
454 case PCI_CHIP_RV280_5C61:
455 case PCI_CHIP_RV280_5C63:
456 screen->chip_family = CHIP_FAMILY_RV280;
457 screen->chip_flags = RADEON_CHIPSET_TCL;
458 break;
459
460 case PCI_CHIP_RS300_5834:
461 case PCI_CHIP_RS300_5835:
462 case PCI_CHIP_RS350_7834:
463 case PCI_CHIP_RS350_7835:
464 screen->chip_family = CHIP_FAMILY_RS300;
465 break;
466
467 case PCI_CHIP_R300_AD:
468 case PCI_CHIP_R300_AE:
469 case PCI_CHIP_R300_AF:
470 case PCI_CHIP_R300_AG:
471 case PCI_CHIP_R300_ND:
472 case PCI_CHIP_R300_NE:
473 case PCI_CHIP_R300_NF:
474 case PCI_CHIP_R300_NG:
475 screen->chip_family = CHIP_FAMILY_R300;
476 screen->chip_flags = RADEON_CHIPSET_TCL;
477 break;
478
479 case PCI_CHIP_RV350_AP:
480 case PCI_CHIP_RV350_AQ:
481 case PCI_CHIP_RV350_AR:
482 case PCI_CHIP_RV350_AS:
483 case PCI_CHIP_RV350_AT:
484 case PCI_CHIP_RV350_AV:
485 case PCI_CHIP_RV350_AU:
486 case PCI_CHIP_RV350_NP:
487 case PCI_CHIP_RV350_NQ:
488 case PCI_CHIP_RV350_NR:
489 case PCI_CHIP_RV350_NS:
490 case PCI_CHIP_RV350_NT:
491 case PCI_CHIP_RV350_NV:
492 screen->chip_family = CHIP_FAMILY_RV350;
493 screen->chip_flags = RADEON_CHIPSET_TCL;
494 break;
495
496 case PCI_CHIP_R350_AH:
497 case PCI_CHIP_R350_AI:
498 case PCI_CHIP_R350_AJ:
499 case PCI_CHIP_R350_AK:
500 case PCI_CHIP_R350_NH:
501 case PCI_CHIP_R350_NI:
502 case PCI_CHIP_R360_NJ:
503 case PCI_CHIP_R350_NK:
504 screen->chip_family = CHIP_FAMILY_R350;
505 screen->chip_flags = RADEON_CHIPSET_TCL;
506 break;
507
508 case PCI_CHIP_RV370_5460:
509 case PCI_CHIP_RV370_5462:
510 case PCI_CHIP_RV370_5464:
511 case PCI_CHIP_RV370_5B60:
512 case PCI_CHIP_RV370_5B62:
513 case PCI_CHIP_RV370_5B63:
514 case PCI_CHIP_RV370_5B64:
515 case PCI_CHIP_RV370_5B65:
516 case PCI_CHIP_RV380_3150:
517 case PCI_CHIP_RV380_3152:
518 case PCI_CHIP_RV380_3154:
519 case PCI_CHIP_RV380_3E50:
520 case PCI_CHIP_RV380_3E54:
521 screen->chip_family = CHIP_FAMILY_RV380;
522 screen->chip_flags = RADEON_CHIPSET_TCL;
523 break;
524
525 case PCI_CHIP_R420_JN:
526 case PCI_CHIP_R420_JH:
527 case PCI_CHIP_R420_JI:
528 case PCI_CHIP_R420_JJ:
529 case PCI_CHIP_R420_JK:
530 case PCI_CHIP_R420_JL:
531 case PCI_CHIP_R420_JM:
532 case PCI_CHIP_R420_JO:
533 case PCI_CHIP_R420_JP:
534 case PCI_CHIP_R420_JT:
535 case PCI_CHIP_R481_4B49:
536 case PCI_CHIP_R481_4B4A:
537 case PCI_CHIP_R481_4B4B:
538 case PCI_CHIP_R481_4B4C:
539 case PCI_CHIP_R423_UH:
540 case PCI_CHIP_R423_UI:
541 case PCI_CHIP_R423_UJ:
542 case PCI_CHIP_R423_UK:
543 case PCI_CHIP_R430_554C:
544 case PCI_CHIP_R430_554D:
545 case PCI_CHIP_R430_554E:
546 case PCI_CHIP_R430_554F:
547 case PCI_CHIP_R423_5550:
548 case PCI_CHIP_R423_UQ:
549 case PCI_CHIP_R423_UR:
550 case PCI_CHIP_R423_UT:
551 case PCI_CHIP_R430_5D48:
552 case PCI_CHIP_R430_5D49:
553 case PCI_CHIP_R430_5D4A:
554 case PCI_CHIP_R480_5D4C:
555 case PCI_CHIP_R480_5D4D:
556 case PCI_CHIP_R480_5D4E:
557 case PCI_CHIP_R480_5D4F:
558 case PCI_CHIP_R480_5D50:
559 case PCI_CHIP_R480_5D52:
560 case PCI_CHIP_R423_5D57:
561 screen->chip_family = CHIP_FAMILY_R420;
562 screen->chip_flags = RADEON_CHIPSET_TCL;
563 break;
564
565 case PCI_CHIP_RV410_5E4C:
566 case PCI_CHIP_RV410_5E4F:
567 case PCI_CHIP_RV410_564A:
568 case PCI_CHIP_RV410_564B:
569 case PCI_CHIP_RV410_564F:
570 case PCI_CHIP_RV410_5652:
571 case PCI_CHIP_RV410_5653:
572 case PCI_CHIP_RV410_5657:
573 case PCI_CHIP_RV410_5E48:
574 case PCI_CHIP_RV410_5E4A:
575 case PCI_CHIP_RV410_5E4B:
576 case PCI_CHIP_RV410_5E4D:
577 screen->chip_family = CHIP_FAMILY_RV410;
578 screen->chip_flags = RADEON_CHIPSET_TCL;
579 break;
580
581 case PCI_CHIP_RS480_5954:
582 case PCI_CHIP_RS480_5955:
583 case PCI_CHIP_RS482_5974:
584 case PCI_CHIP_RS482_5975:
585 case PCI_CHIP_RS400_5A41:
586 case PCI_CHIP_RS400_5A42:
587 case PCI_CHIP_RC410_5A61:
588 case PCI_CHIP_RC410_5A62:
589 screen->chip_family = CHIP_FAMILY_RS400;
590 break;
591
592 case PCI_CHIP_RS600_793F:
593 case PCI_CHIP_RS600_7941:
594 case PCI_CHIP_RS600_7942:
595 screen->chip_family = CHIP_FAMILY_RS600;
596 break;
597
598 case PCI_CHIP_RS690_791E:
599 case PCI_CHIP_RS690_791F:
600 screen->chip_family = CHIP_FAMILY_RS690;
601 break;
602 case PCI_CHIP_RS740_796C:
603 case PCI_CHIP_RS740_796D:
604 case PCI_CHIP_RS740_796E:
605 case PCI_CHIP_RS740_796F:
606 screen->chip_family = CHIP_FAMILY_RS740;
607 break;
608
609 case PCI_CHIP_R520_7100:
610 case PCI_CHIP_R520_7101:
611 case PCI_CHIP_R520_7102:
612 case PCI_CHIP_R520_7103:
613 case PCI_CHIP_R520_7104:
614 case PCI_CHIP_R520_7105:
615 case PCI_CHIP_R520_7106:
616 case PCI_CHIP_R520_7108:
617 case PCI_CHIP_R520_7109:
618 case PCI_CHIP_R520_710A:
619 case PCI_CHIP_R520_710B:
620 case PCI_CHIP_R520_710C:
621 case PCI_CHIP_R520_710E:
622 case PCI_CHIP_R520_710F:
623 screen->chip_family = CHIP_FAMILY_R520;
624 screen->chip_flags = RADEON_CHIPSET_TCL;
625 break;
626
627 case PCI_CHIP_RV515_7140:
628 case PCI_CHIP_RV515_7141:
629 case PCI_CHIP_RV515_7142:
630 case PCI_CHIP_RV515_7143:
631 case PCI_CHIP_RV515_7144:
632 case PCI_CHIP_RV515_7145:
633 case PCI_CHIP_RV515_7146:
634 case PCI_CHIP_RV515_7147:
635 case PCI_CHIP_RV515_7149:
636 case PCI_CHIP_RV515_714A:
637 case PCI_CHIP_RV515_714B:
638 case PCI_CHIP_RV515_714C:
639 case PCI_CHIP_RV515_714D:
640 case PCI_CHIP_RV515_714E:
641 case PCI_CHIP_RV515_714F:
642 case PCI_CHIP_RV515_7151:
643 case PCI_CHIP_RV515_7152:
644 case PCI_CHIP_RV515_7153:
645 case PCI_CHIP_RV515_715E:
646 case PCI_CHIP_RV515_715F:
647 case PCI_CHIP_RV515_7180:
648 case PCI_CHIP_RV515_7181:
649 case PCI_CHIP_RV515_7183:
650 case PCI_CHIP_RV515_7186:
651 case PCI_CHIP_RV515_7187:
652 case PCI_CHIP_RV515_7188:
653 case PCI_CHIP_RV515_718A:
654 case PCI_CHIP_RV515_718B:
655 case PCI_CHIP_RV515_718C:
656 case PCI_CHIP_RV515_718D:
657 case PCI_CHIP_RV515_718F:
658 case PCI_CHIP_RV515_7193:
659 case PCI_CHIP_RV515_7196:
660 case PCI_CHIP_RV515_719B:
661 case PCI_CHIP_RV515_719F:
662 case PCI_CHIP_RV515_7200:
663 case PCI_CHIP_RV515_7210:
664 case PCI_CHIP_RV515_7211:
665 screen->chip_family = CHIP_FAMILY_RV515;
666 screen->chip_flags = RADEON_CHIPSET_TCL;
667 break;
668
669 case PCI_CHIP_RV530_71C0:
670 case PCI_CHIP_RV530_71C1:
671 case PCI_CHIP_RV530_71C2:
672 case PCI_CHIP_RV530_71C3:
673 case PCI_CHIP_RV530_71C4:
674 case PCI_CHIP_RV530_71C5:
675 case PCI_CHIP_RV530_71C6:
676 case PCI_CHIP_RV530_71C7:
677 case PCI_CHIP_RV530_71CD:
678 case PCI_CHIP_RV530_71CE:
679 case PCI_CHIP_RV530_71D2:
680 case PCI_CHIP_RV530_71D4:
681 case PCI_CHIP_RV530_71D5:
682 case PCI_CHIP_RV530_71D6:
683 case PCI_CHIP_RV530_71DA:
684 case PCI_CHIP_RV530_71DE:
685 screen->chip_family = CHIP_FAMILY_RV530;
686 screen->chip_flags = RADEON_CHIPSET_TCL;
687 break;
688
689 case PCI_CHIP_R580_7240:
690 case PCI_CHIP_R580_7243:
691 case PCI_CHIP_R580_7244:
692 case PCI_CHIP_R580_7245:
693 case PCI_CHIP_R580_7246:
694 case PCI_CHIP_R580_7247:
695 case PCI_CHIP_R580_7248:
696 case PCI_CHIP_R580_7249:
697 case PCI_CHIP_R580_724A:
698 case PCI_CHIP_R580_724B:
699 case PCI_CHIP_R580_724C:
700 case PCI_CHIP_R580_724D:
701 case PCI_CHIP_R580_724E:
702 case PCI_CHIP_R580_724F:
703 case PCI_CHIP_R580_7284:
704 screen->chip_family = CHIP_FAMILY_R580;
705 screen->chip_flags = RADEON_CHIPSET_TCL;
706 break;
707
708 case PCI_CHIP_RV570_7280:
709 case PCI_CHIP_RV560_7281:
710 case PCI_CHIP_RV560_7283:
711 case PCI_CHIP_RV560_7287:
712 case PCI_CHIP_RV570_7288:
713 case PCI_CHIP_RV570_7289:
714 case PCI_CHIP_RV570_728B:
715 case PCI_CHIP_RV570_728C:
716 case PCI_CHIP_RV560_7290:
717 case PCI_CHIP_RV560_7291:
718 case PCI_CHIP_RV560_7293:
719 case PCI_CHIP_RV560_7297:
720 screen->chip_family = CHIP_FAMILY_RV560;
721 screen->chip_flags = RADEON_CHIPSET_TCL;
722 break;
723
724 case PCI_CHIP_R600_9400:
725 case PCI_CHIP_R600_9401:
726 case PCI_CHIP_R600_9402:
727 case PCI_CHIP_R600_9403:
728 case PCI_CHIP_R600_9405:
729 case PCI_CHIP_R600_940A:
730 case PCI_CHIP_R600_940B:
731 case PCI_CHIP_R600_940F:
732 screen->chip_family = CHIP_FAMILY_R600;
733 screen->chip_flags = RADEON_CHIPSET_TCL;
734 break;
735
736 case PCI_CHIP_RV610_94C0:
737 case PCI_CHIP_RV610_94C1:
738 case PCI_CHIP_RV610_94C3:
739 case PCI_CHIP_RV610_94C4:
740 case PCI_CHIP_RV610_94C5:
741 case PCI_CHIP_RV610_94C6:
742 case PCI_CHIP_RV610_94C7:
743 case PCI_CHIP_RV610_94C8:
744 case PCI_CHIP_RV610_94C9:
745 case PCI_CHIP_RV610_94CB:
746 case PCI_CHIP_RV610_94CC:
747 case PCI_CHIP_RV610_94CD:
748 screen->chip_family = CHIP_FAMILY_RV610;
749 screen->chip_flags = RADEON_CHIPSET_TCL;
750 break;
751
752 case PCI_CHIP_RV630_9580:
753 case PCI_CHIP_RV630_9581:
754 case PCI_CHIP_RV630_9583:
755 case PCI_CHIP_RV630_9586:
756 case PCI_CHIP_RV630_9587:
757 case PCI_CHIP_RV630_9588:
758 case PCI_CHIP_RV630_9589:
759 case PCI_CHIP_RV630_958A:
760 case PCI_CHIP_RV630_958B:
761 case PCI_CHIP_RV630_958C:
762 case PCI_CHIP_RV630_958D:
763 case PCI_CHIP_RV630_958E:
764 case PCI_CHIP_RV630_958F:
765 screen->chip_family = CHIP_FAMILY_RV630;
766 screen->chip_flags = RADEON_CHIPSET_TCL;
767 break;
768
769 case PCI_CHIP_RV670_9500:
770 case PCI_CHIP_RV670_9501:
771 case PCI_CHIP_RV670_9504:
772 case PCI_CHIP_RV670_9505:
773 case PCI_CHIP_RV670_9506:
774 case PCI_CHIP_RV670_9507:
775 case PCI_CHIP_RV670_9508:
776 case PCI_CHIP_RV670_9509:
777 case PCI_CHIP_RV670_950F:
778 case PCI_CHIP_RV670_9511:
779 case PCI_CHIP_RV670_9515:
780 case PCI_CHIP_RV670_9517:
781 case PCI_CHIP_RV670_9519:
782 screen->chip_family = CHIP_FAMILY_RV670;
783 screen->chip_flags = RADEON_CHIPSET_TCL;
784 break;
785
786 case PCI_CHIP_RV620_95C0:
787 case PCI_CHIP_RV620_95C2:
788 case PCI_CHIP_RV620_95C4:
789 case PCI_CHIP_RV620_95C5:
790 case PCI_CHIP_RV620_95C6:
791 case PCI_CHIP_RV620_95C7:
792 case PCI_CHIP_RV620_95C9:
793 case PCI_CHIP_RV620_95CC:
794 case PCI_CHIP_RV620_95CD:
795 case PCI_CHIP_RV620_95CE:
796 case PCI_CHIP_RV620_95CF:
797 screen->chip_family = CHIP_FAMILY_RV620;
798 screen->chip_flags = RADEON_CHIPSET_TCL;
799 break;
800
801 case PCI_CHIP_RV635_9590:
802 case PCI_CHIP_RV635_9591:
803 case PCI_CHIP_RV635_9593:
804 case PCI_CHIP_RV635_9595:
805 case PCI_CHIP_RV635_9596:
806 case PCI_CHIP_RV635_9597:
807 case PCI_CHIP_RV635_9598:
808 case PCI_CHIP_RV635_9599:
809 case PCI_CHIP_RV635_959B:
810 screen->chip_family = CHIP_FAMILY_RV635;
811 screen->chip_flags = RADEON_CHIPSET_TCL;
812 break;
813
814 case PCI_CHIP_RS780_9610:
815 case PCI_CHIP_RS780_9611:
816 case PCI_CHIP_RS780_9612:
817 case PCI_CHIP_RS780_9613:
818 case PCI_CHIP_RS780_9614:
819 case PCI_CHIP_RS780_9615:
820 case PCI_CHIP_RS780_9616:
821 screen->chip_family = CHIP_FAMILY_RS780;
822 screen->chip_flags = RADEON_CHIPSET_TCL;
823 break;
824 case PCI_CHIP_RS880_9710:
825 case PCI_CHIP_RS880_9711:
826 case PCI_CHIP_RS880_9712:
827 case PCI_CHIP_RS880_9713:
828 case PCI_CHIP_RS880_9714:
829 screen->chip_family = CHIP_FAMILY_RS880;
830 screen->chip_flags = RADEON_CHIPSET_TCL;
831 break;
832
833 case PCI_CHIP_RV770_9440:
834 case PCI_CHIP_RV770_9441:
835 case PCI_CHIP_RV770_9442:
836 case PCI_CHIP_RV770_9443:
837 case PCI_CHIP_RV770_9444:
838 case PCI_CHIP_RV770_9446:
839 case PCI_CHIP_RV770_944A:
840 case PCI_CHIP_RV770_944B:
841 case PCI_CHIP_RV770_944C:
842 case PCI_CHIP_RV770_944E:
843 case PCI_CHIP_RV770_9450:
844 case PCI_CHIP_RV770_9452:
845 case PCI_CHIP_RV770_9456:
846 case PCI_CHIP_RV770_945A:
847 case PCI_CHIP_RV770_945B:
848 case PCI_CHIP_RV790_9460:
849 case PCI_CHIP_RV790_9462:
850 case PCI_CHIP_RV770_946A:
851 case PCI_CHIP_RV770_946B:
852 case PCI_CHIP_RV770_947A:
853 case PCI_CHIP_RV770_947B:
854 screen->chip_family = CHIP_FAMILY_RV770;
855 screen->chip_flags = RADEON_CHIPSET_TCL;
856 break;
857
858 case PCI_CHIP_RV730_9480:
859 case PCI_CHIP_RV730_9487:
860 case PCI_CHIP_RV730_9488:
861 case PCI_CHIP_RV730_9489:
862 case PCI_CHIP_RV730_948F:
863 case PCI_CHIP_RV730_9490:
864 case PCI_CHIP_RV730_9491:
865 case PCI_CHIP_RV730_9495:
866 case PCI_CHIP_RV730_9498:
867 case PCI_CHIP_RV730_949C:
868 case PCI_CHIP_RV730_949E:
869 case PCI_CHIP_RV730_949F:
870 screen->chip_family = CHIP_FAMILY_RV730;
871 screen->chip_flags = RADEON_CHIPSET_TCL;
872 break;
873
874 case PCI_CHIP_RV710_9540:
875 case PCI_CHIP_RV710_9541:
876 case PCI_CHIP_RV710_9542:
877 case PCI_CHIP_RV710_954E:
878 case PCI_CHIP_RV710_954F:
879 case PCI_CHIP_RV710_9552:
880 case PCI_CHIP_RV710_9553:
881 case PCI_CHIP_RV710_9555:
882 case PCI_CHIP_RV710_9557:
883 screen->chip_family = CHIP_FAMILY_RV710;
884 screen->chip_flags = RADEON_CHIPSET_TCL;
885 break;
886
887 case PCI_CHIP_RV740_94A0:
888 case PCI_CHIP_RV740_94A1:
889 case PCI_CHIP_RV740_94A3:
890 case PCI_CHIP_RV740_94B1:
891 case PCI_CHIP_RV740_94B3:
892 case PCI_CHIP_RV740_94B4:
893 case PCI_CHIP_RV740_94B5:
894 case PCI_CHIP_RV740_94B9:
895 screen->chip_family = CHIP_FAMILY_RV740;
896 screen->chip_flags = RADEON_CHIPSET_TCL;
897 break;
898
899 default:
900 fprintf(stderr, "unknown chip id 0x%x, can't guess.\n",
901 device_id);
902 return -1;
903 }
904
905 return 0;
906 }
907
908
909 /* Create the device specific screen private data struct.
910 */
911 static radeonScreenPtr
912 radeonCreateScreen( __DRIscreen *sPriv )
913 {
914 radeonScreenPtr screen;
915 RADEONDRIPtr dri_priv = (RADEONDRIPtr)sPriv->pDevPriv;
916 unsigned char *RADEONMMIO = NULL;
917 int i;
918 int ret;
919 uint32_t temp = 0;
920
921 if (sPriv->devPrivSize != sizeof(RADEONDRIRec)) {
922 fprintf(stderr,"\nERROR! sizeof(RADEONDRIRec) does not match passed size from device driver\n");
923 return GL_FALSE;
924 }
925
926 /* Allocate the private area */
927 screen = (radeonScreenPtr) CALLOC( sizeof(*screen) );
928 if ( !screen ) {
929 __driUtilMessage("%s: Could not allocate memory for screen structure",
930 __FUNCTION__);
931 return NULL;
932 }
933
934 radeon_init_debug();
935
936 /* parse information in __driConfigOptions */
937 driParseOptionInfo (&screen->optionCache,
938 __driConfigOptions, __driNConfigOptions);
939
940 /* This is first since which regions we map depends on whether or
941 * not we are using a PCI card.
942 */
943 screen->card_type = (dri_priv->IsPCI ? RADEON_CARD_PCI : RADEON_CARD_AGP);
944 {
945 int ret;
946
947 ret = radeonGetParam(sPriv, RADEON_PARAM_GART_BUFFER_OFFSET,
948 &screen->gart_buffer_offset);
949
950 if (ret) {
951 FREE( screen );
952 fprintf(stderr, "drm_radeon_getparam_t (RADEON_PARAM_GART_BUFFER_OFFSET): %d\n", ret);
953 return NULL;
954 }
955
956 ret = radeonGetParam(sPriv, RADEON_PARAM_GART_BASE,
957 &screen->gart_base);
958 if (ret) {
959 FREE( screen );
960 fprintf(stderr, "drm_radeon_getparam_t (RADEON_PARAM_GART_BASE): %d\n", ret);
961 return NULL;
962 }
963
964 ret = radeonGetParam(sPriv, RADEON_PARAM_IRQ_NR,
965 &screen->irq);
966 if (ret) {
967 FREE( screen );
968 fprintf(stderr, "drm_radeon_getparam_t (RADEON_PARAM_IRQ_NR): %d\n", ret);
969 return NULL;
970 }
971 screen->drmSupportsCubeMapsR200 = (sPriv->drm_version.minor >= 7);
972 screen->drmSupportsBlendColor = (sPriv->drm_version.minor >= 11);
973 screen->drmSupportsTriPerf = (sPriv->drm_version.minor >= 16);
974 screen->drmSupportsFragShader = (sPriv->drm_version.minor >= 18);
975 screen->drmSupportsPointSprites = (sPriv->drm_version.minor >= 13);
976 screen->drmSupportsCubeMapsR100 = (sPriv->drm_version.minor >= 15);
977 screen->drmSupportsVertexProgram = (sPriv->drm_version.minor >= 25);
978 screen->drmSupportsOcclusionQueries = (sPriv->drm_version.minor >= 30);
979 }
980
981 ret = radeon_set_screen_flags(screen, dri_priv->deviceID);
982 if (ret == -1)
983 return NULL;
984
985 screen->mmio.handle = dri_priv->registerHandle;
986 screen->mmio.size = dri_priv->registerSize;
987 if ( drmMap( sPriv->fd,
988 screen->mmio.handle,
989 screen->mmio.size,
990 &screen->mmio.map ) ) {
991 FREE( screen );
992 __driUtilMessage("%s: drmMap failed\n", __FUNCTION__ );
993 return NULL;
994 }
995
996 RADEONMMIO = screen->mmio.map;
997
998 screen->status.handle = dri_priv->statusHandle;
999 screen->status.size = dri_priv->statusSize;
1000 if ( drmMap( sPriv->fd,
1001 screen->status.handle,
1002 screen->status.size,
1003 &screen->status.map ) ) {
1004 drmUnmap( screen->mmio.map, screen->mmio.size );
1005 FREE( screen );
1006 __driUtilMessage("%s: drmMap (2) failed\n", __FUNCTION__ );
1007 return NULL;
1008 }
1009 if (screen->chip_family < CHIP_FAMILY_R600)
1010 screen->scratch = (__volatile__ uint32_t *)
1011 ((GLubyte *)screen->status.map + RADEON_SCRATCH_REG_OFFSET);
1012 else
1013 screen->scratch = (__volatile__ uint32_t *)
1014 ((GLubyte *)screen->status.map + R600_SCRATCH_REG_OFFSET);
1015
1016 screen->buffers = drmMapBufs( sPriv->fd );
1017 if ( !screen->buffers ) {
1018 drmUnmap( screen->status.map, screen->status.size );
1019 drmUnmap( screen->mmio.map, screen->mmio.size );
1020 FREE( screen );
1021 __driUtilMessage("%s: drmMapBufs failed\n", __FUNCTION__ );
1022 return NULL;
1023 }
1024
1025 if ( dri_priv->gartTexHandle && dri_priv->gartTexMapSize ) {
1026 screen->gartTextures.handle = dri_priv->gartTexHandle;
1027 screen->gartTextures.size = dri_priv->gartTexMapSize;
1028 if ( drmMap( sPriv->fd,
1029 screen->gartTextures.handle,
1030 screen->gartTextures.size,
1031 (drmAddressPtr)&screen->gartTextures.map ) ) {
1032 drmUnmapBufs( screen->buffers );
1033 drmUnmap( screen->status.map, screen->status.size );
1034 drmUnmap( screen->mmio.map, screen->mmio.size );
1035 FREE( screen );
1036 __driUtilMessage("%s: drmMap failed for GART texture area\n", __FUNCTION__);
1037 return NULL;
1038 }
1039
1040 screen->gart_texture_offset = dri_priv->gartTexOffset + screen->gart_base;
1041 }
1042
1043 if ((screen->chip_family == CHIP_FAMILY_R350 || screen->chip_family == CHIP_FAMILY_R300) &&
1044 sPriv->ddx_version.minor < 2) {
1045 fprintf(stderr, "xf86-video-ati-6.6.2 or newer needed for Radeon 9500/9700/9800 cards.\n");
1046 return NULL;
1047 }
1048
1049 if ((sPriv->drm_version.minor < 29) && (screen->chip_family >= CHIP_FAMILY_RV515)) {
1050 fprintf(stderr, "R500 support requires a newer drm.\n");
1051 return NULL;
1052 }
1053
1054 if (getenv("R300_NO_TCL"))
1055 screen->chip_flags &= ~RADEON_CHIPSET_TCL;
1056
1057 if (screen->chip_family <= CHIP_FAMILY_RS200)
1058 screen->chip_flags |= RADEON_CLASS_R100;
1059 else if (screen->chip_family <= CHIP_FAMILY_RV280)
1060 screen->chip_flags |= RADEON_CLASS_R200;
1061 else if (screen->chip_family <= CHIP_FAMILY_RV570)
1062 screen->chip_flags |= RADEON_CLASS_R300;
1063 else
1064 screen->chip_flags |= RADEON_CLASS_R600;
1065
1066 screen->cpp = dri_priv->bpp / 8;
1067 screen->AGPMode = dri_priv->AGPMode;
1068
1069 ret = radeonGetParam(sPriv, RADEON_PARAM_FB_LOCATION, &temp);
1070
1071 /* +r6/r7 */
1072 if(screen->chip_family >= CHIP_FAMILY_R600)
1073 {
1074 if (ret)
1075 {
1076 FREE( screen );
1077 fprintf(stderr, "Unable to get fb location need newer drm\n");
1078 return NULL;
1079 }
1080 else
1081 {
1082 screen->fbLocation = (temp & 0xffff) << 24;
1083 }
1084 }
1085 else
1086 {
1087 if (ret)
1088 {
1089 if (screen->chip_family < CHIP_FAMILY_RS600 && !screen->kernel_mm)
1090 screen->fbLocation = ( INREG( RADEON_MC_FB_LOCATION ) & 0xffff) << 16;
1091 else
1092 {
1093 FREE( screen );
1094 fprintf(stderr, "Unable to get fb location need newer drm\n");
1095 return NULL;
1096 }
1097 }
1098 else
1099 {
1100 screen->fbLocation = (temp & 0xffff) << 16;
1101 }
1102 }
1103
1104 if (IS_R300_CLASS(screen)) {
1105 ret = radeonGetParam(sPriv, RADEON_PARAM_NUM_GB_PIPES, &temp);
1106 if (ret) {
1107 fprintf(stderr, "Unable to get num_pipes, need newer drm\n");
1108 switch (screen->chip_family) {
1109 case CHIP_FAMILY_R300:
1110 case CHIP_FAMILY_R350:
1111 screen->num_gb_pipes = 2;
1112 break;
1113 case CHIP_FAMILY_R420:
1114 case CHIP_FAMILY_R520:
1115 case CHIP_FAMILY_R580:
1116 case CHIP_FAMILY_RV560:
1117 case CHIP_FAMILY_RV570:
1118 screen->num_gb_pipes = 4;
1119 break;
1120 case CHIP_FAMILY_RV350:
1121 case CHIP_FAMILY_RV515:
1122 case CHIP_FAMILY_RV530:
1123 case CHIP_FAMILY_RV410:
1124 default:
1125 screen->num_gb_pipes = 1;
1126 break;
1127 }
1128 } else {
1129 screen->num_gb_pipes = temp;
1130 }
1131
1132 /* pipe overrides */
1133 switch (dri_priv->deviceID) {
1134 case PCI_CHIP_R300_AD: /* 9500 with 1 quadpipe verified by: Reid Linnemann <lreid@cs.okstate.edu> */
1135 case PCI_CHIP_RV410_5E4C: /* RV410 SE only have 1 quadpipe */
1136 case PCI_CHIP_RV410_5E4F: /* RV410 SE only have 1 quadpipe */
1137 screen->num_gb_pipes = 1;
1138 break;
1139 default:
1140 break;
1141 }
1142
1143 if ( sPriv->drm_version.minor >= 31 ) {
1144 ret = radeonGetParam(sPriv, RADEON_PARAM_NUM_Z_PIPES, &temp);
1145 if (ret)
1146 screen->num_z_pipes = 2;
1147 else
1148 screen->num_z_pipes = temp;
1149 } else
1150 screen->num_z_pipes = 2;
1151 }
1152
1153 if ( sPriv->drm_version.minor >= 10 ) {
1154 drm_radeon_setparam_t sp;
1155
1156 sp.param = RADEON_SETPARAM_FB_LOCATION;
1157 sp.value = screen->fbLocation;
1158
1159 drmCommandWrite( sPriv->fd, DRM_RADEON_SETPARAM,
1160 &sp, sizeof( sp ) );
1161 }
1162
1163 screen->frontOffset = dri_priv->frontOffset;
1164 screen->frontPitch = dri_priv->frontPitch;
1165 screen->backOffset = dri_priv->backOffset;
1166 screen->backPitch = dri_priv->backPitch;
1167 screen->depthOffset = dri_priv->depthOffset;
1168 screen->depthPitch = dri_priv->depthPitch;
1169
1170 /* Check if ddx has set up a surface reg to cover depth buffer */
1171 screen->depthHasSurface = (sPriv->ddx_version.major > 4) ||
1172 /* these chips don't use tiled z without hyperz. So always pretend
1173 we have set up a surface which will cause linear reads/writes */
1174 (IS_R100_CLASS(screen) &&
1175 !(screen->chip_flags & RADEON_CHIPSET_TCL));
1176
1177 if ( dri_priv->textureSize == 0 ) {
1178 screen->texOffset[RADEON_LOCAL_TEX_HEAP] = screen->gart_texture_offset;
1179 screen->texSize[RADEON_LOCAL_TEX_HEAP] = dri_priv->gartTexMapSize;
1180 screen->logTexGranularity[RADEON_LOCAL_TEX_HEAP] =
1181 dri_priv->log2GARTTexGran;
1182 } else {
1183 screen->texOffset[RADEON_LOCAL_TEX_HEAP] = dri_priv->textureOffset
1184 + screen->fbLocation;
1185 screen->texSize[RADEON_LOCAL_TEX_HEAP] = dri_priv->textureSize;
1186 screen->logTexGranularity[RADEON_LOCAL_TEX_HEAP] =
1187 dri_priv->log2TexGran;
1188 }
1189
1190 if ( !screen->gartTextures.map || dri_priv->textureSize == 0
1191 || getenv( "RADEON_GARTTEXTURING_FORCE_DISABLE" ) ) {
1192 screen->numTexHeaps = RADEON_NR_TEX_HEAPS - 1;
1193 screen->texOffset[RADEON_GART_TEX_HEAP] = 0;
1194 screen->texSize[RADEON_GART_TEX_HEAP] = 0;
1195 screen->logTexGranularity[RADEON_GART_TEX_HEAP] = 0;
1196 } else {
1197 screen->numTexHeaps = RADEON_NR_TEX_HEAPS;
1198 screen->texOffset[RADEON_GART_TEX_HEAP] = screen->gart_texture_offset;
1199 screen->texSize[RADEON_GART_TEX_HEAP] = dri_priv->gartTexMapSize;
1200 screen->logTexGranularity[RADEON_GART_TEX_HEAP] =
1201 dri_priv->log2GARTTexGran;
1202 }
1203
1204 i = 0;
1205 screen->extensions[i++] = &driCopySubBufferExtension.base;
1206 screen->extensions[i++] = &driFrameTrackingExtension.base;
1207 screen->extensions[i++] = &driReadDrawableExtension;
1208
1209 if ( screen->irq != 0 ) {
1210 screen->extensions[i++] = &driSwapControlExtension.base;
1211 screen->extensions[i++] = &driMediaStreamCounterExtension.base;
1212 }
1213
1214 #if defined(RADEON_R100)
1215 screen->extensions[i++] = &radeonTexOffsetExtension.base;
1216 #endif
1217
1218 #if defined(RADEON_R200)
1219 if (IS_R200_CLASS(screen))
1220 screen->extensions[i++] = &r200AllocateExtension.base;
1221
1222 screen->extensions[i++] = &r200texOffsetExtension.base;
1223 #endif
1224
1225 #if defined(RADEON_R300)
1226 screen->extensions[i++] = &r300texOffsetExtension.base;
1227 #endif
1228
1229 #if defined(RADEON_R600)
1230 screen->extensions[i++] = &r600texOffsetExtension.base;
1231 #endif
1232
1233 screen->extensions[i++] = NULL;
1234 sPriv->extensions = screen->extensions;
1235
1236 screen->driScreen = sPriv;
1237 screen->sarea_priv_offset = dri_priv->sarea_priv_offset;
1238 screen->sarea = (drm_radeon_sarea_t *) ((GLubyte *) sPriv->pSAREA +
1239 screen->sarea_priv_offset);
1240
1241 screen->bom = radeon_bo_manager_legacy_ctor(screen);
1242 if (screen->bom == NULL) {
1243 free(screen);
1244 return NULL;
1245 }
1246
1247 return screen;
1248 }
1249
1250 static radeonScreenPtr
1251 radeonCreateScreen2(__DRIscreen *sPriv)
1252 {
1253 radeonScreenPtr screen;
1254 int i;
1255 int ret;
1256 uint32_t device_id = 0;
1257 uint32_t temp = 0;
1258
1259 /* Allocate the private area */
1260 screen = (radeonScreenPtr) CALLOC( sizeof(*screen) );
1261 if ( !screen ) {
1262 __driUtilMessage("%s: Could not allocate memory for screen structure",
1263 __FUNCTION__);
1264 fprintf(stderr, "leaving here\n");
1265 return NULL;
1266 }
1267
1268 radeon_init_debug();
1269
1270 /* parse information in __driConfigOptions */
1271 driParseOptionInfo (&screen->optionCache,
1272 __driConfigOptions, __driNConfigOptions);
1273
1274 screen->kernel_mm = 1;
1275 screen->chip_flags = 0;
1276
1277 /* if we have kms we can support all of these */
1278 screen->drmSupportsCubeMapsR200 = 1;
1279 screen->drmSupportsBlendColor = 1;
1280 screen->drmSupportsTriPerf = 1;
1281 screen->drmSupportsFragShader = 1;
1282 screen->drmSupportsPointSprites = 1;
1283 screen->drmSupportsCubeMapsR100 = 1;
1284 screen->drmSupportsVertexProgram = 1;
1285 screen->drmSupportsOcclusionQueries = 1;
1286 screen->irq = 1;
1287
1288 ret = radeonGetParam(sPriv, RADEON_PARAM_DEVICE_ID, &device_id);
1289 if (ret) {
1290 FREE( screen );
1291 fprintf(stderr, "drm_radeon_getparam_t (RADEON_PARAM_DEVICE_ID): %d\n", ret);
1292 return NULL;
1293 }
1294
1295 ret = radeon_set_screen_flags(screen, device_id);
1296 if (ret == -1)
1297 return NULL;
1298
1299 if (getenv("R300_NO_TCL"))
1300 screen->chip_flags &= ~RADEON_CHIPSET_TCL;
1301
1302 if (screen->chip_family <= CHIP_FAMILY_RS200)
1303 screen->chip_flags |= RADEON_CLASS_R100;
1304 else if (screen->chip_family <= CHIP_FAMILY_RV280)
1305 screen->chip_flags |= RADEON_CLASS_R200;
1306 else if (screen->chip_family <= CHIP_FAMILY_RV570)
1307 screen->chip_flags |= RADEON_CLASS_R300;
1308 else
1309 screen->chip_flags |= RADEON_CLASS_R600;
1310
1311 if (IS_R300_CLASS(screen)) {
1312 ret = radeonGetParam(sPriv, RADEON_PARAM_NUM_GB_PIPES, &temp);
1313 if (ret) {
1314 fprintf(stderr, "Unable to get num_pipes, need newer drm\n");
1315 switch (screen->chip_family) {
1316 case CHIP_FAMILY_R300:
1317 case CHIP_FAMILY_R350:
1318 screen->num_gb_pipes = 2;
1319 break;
1320 case CHIP_FAMILY_R420:
1321 case CHIP_FAMILY_R520:
1322 case CHIP_FAMILY_R580:
1323 case CHIP_FAMILY_RV560:
1324 case CHIP_FAMILY_RV570:
1325 screen->num_gb_pipes = 4;
1326 break;
1327 case CHIP_FAMILY_RV350:
1328 case CHIP_FAMILY_RV515:
1329 case CHIP_FAMILY_RV530:
1330 case CHIP_FAMILY_RV410:
1331 default:
1332 screen->num_gb_pipes = 1;
1333 break;
1334 }
1335 } else {
1336 screen->num_gb_pipes = temp;
1337 }
1338
1339 /* pipe overrides */
1340 switch (device_id) {
1341 case PCI_CHIP_R300_AD: /* 9500 with 1 quadpipe verified by: Reid Linnemann <lreid@cs.okstate.edu> */
1342 case PCI_CHIP_RV410_5E4C: /* RV410 SE only have 1 quadpipe */
1343 case PCI_CHIP_RV410_5E4F: /* RV410 SE only have 1 quadpipe */
1344 screen->num_gb_pipes = 1;
1345 break;
1346 default:
1347 break;
1348 }
1349
1350 ret = radeonGetParam(sPriv, RADEON_PARAM_NUM_Z_PIPES, &temp);
1351 if (ret)
1352 screen->num_z_pipes = 2;
1353 else
1354 screen->num_z_pipes = temp;
1355
1356 }
1357
1358 i = 0;
1359 screen->extensions[i++] = &driCopySubBufferExtension.base;
1360 screen->extensions[i++] = &driFrameTrackingExtension.base;
1361 screen->extensions[i++] = &driReadDrawableExtension;
1362
1363 if ( screen->irq != 0 ) {
1364 screen->extensions[i++] = &driSwapControlExtension.base;
1365 screen->extensions[i++] = &driMediaStreamCounterExtension.base;
1366 }
1367
1368 #if defined(RADEON_R100)
1369 screen->extensions[i++] = &radeonTexBufferExtension.base;
1370 #endif
1371
1372 #if defined(RADEON_R200)
1373 if (IS_R200_CLASS(screen))
1374 screen->extensions[i++] = &r200AllocateExtension.base;
1375
1376 screen->extensions[i++] = &r200TexBufferExtension.base;
1377 #endif
1378
1379 #if defined(RADEON_R300)
1380 screen->extensions[i++] = &r300TexBufferExtension.base;
1381 #endif
1382
1383 #if defined(RADEON_R600)
1384 screen->extensions[i++] = &r600TexBufferExtension.base;
1385 #endif
1386
1387 screen->extensions[i++] = NULL;
1388 sPriv->extensions = screen->extensions;
1389
1390 screen->driScreen = sPriv;
1391 screen->bom = radeon_bo_manager_gem_ctor(sPriv->fd);
1392 if (screen->bom == NULL) {
1393 free(screen);
1394 return NULL;
1395 }
1396 return screen;
1397 }
1398
1399 /* Destroy the device specific screen private data struct.
1400 */
1401 static void
1402 radeonDestroyScreen( __DRIscreen *sPriv )
1403 {
1404 radeonScreenPtr screen = (radeonScreenPtr)sPriv->private;
1405
1406 if (!screen)
1407 return;
1408
1409 if (screen->kernel_mm) {
1410 #ifdef RADEON_BO_TRACK
1411 radeon_tracker_print(&screen->bom->tracker, stderr);
1412 #endif
1413 radeon_bo_manager_gem_dtor(screen->bom);
1414 } else {
1415 radeon_bo_manager_legacy_dtor(screen->bom);
1416
1417 if ( screen->gartTextures.map ) {
1418 drmUnmap( screen->gartTextures.map, screen->gartTextures.size );
1419 }
1420 drmUnmapBufs( screen->buffers );
1421 drmUnmap( screen->status.map, screen->status.size );
1422 drmUnmap( screen->mmio.map, screen->mmio.size );
1423 }
1424
1425 /* free all option information */
1426 driDestroyOptionInfo (&screen->optionCache);
1427
1428 FREE( screen );
1429 sPriv->private = NULL;
1430 }
1431
1432
1433 /* Initialize the driver specific screen private data.
1434 */
1435 static GLboolean
1436 radeonInitDriver( __DRIscreen *sPriv )
1437 {
1438 if (sPriv->dri2.enabled) {
1439 sPriv->private = (void *) radeonCreateScreen2( sPriv );
1440 } else {
1441 sPriv->private = (void *) radeonCreateScreen( sPriv );
1442 }
1443 if ( !sPriv->private ) {
1444 radeonDestroyScreen( sPriv );
1445 return GL_FALSE;
1446 }
1447
1448 return GL_TRUE;
1449 }
1450
1451
1452
1453 /**
1454 * Create the Mesa framebuffer and renderbuffers for a given window/drawable.
1455 *
1456 * \todo This function (and its interface) will need to be updated to support
1457 * pbuffers.
1458 */
1459 static GLboolean
1460 radeonCreateBuffer( __DRIscreen *driScrnPriv,
1461 __DRIdrawable *driDrawPriv,
1462 const __GLcontextModes *mesaVis,
1463 GLboolean isPixmap )
1464 {
1465 radeonScreenPtr screen = (radeonScreenPtr) driScrnPriv->private;
1466
1467 const GLboolean swDepth = GL_FALSE;
1468 const GLboolean swAlpha = GL_FALSE;
1469 const GLboolean swAccum = mesaVis->accumRedBits > 0;
1470 const GLboolean swStencil = mesaVis->stencilBits > 0 &&
1471 mesaVis->depthBits != 24;
1472 gl_format rgbFormat;
1473 struct radeon_framebuffer *rfb;
1474
1475 if (isPixmap)
1476 return GL_FALSE; /* not implemented */
1477
1478 rfb = CALLOC_STRUCT(radeon_framebuffer);
1479 if (!rfb)
1480 return GL_FALSE;
1481
1482 _mesa_initialize_window_framebuffer(&rfb->base, mesaVis);
1483
1484 if (mesaVis->redBits == 5)
1485 rgbFormat = _mesa_little_endian() ? MESA_FORMAT_RGB565 : MESA_FORMAT_RGB565_REV;
1486 else if (mesaVis->alphaBits == 0)
1487 rgbFormat = _mesa_little_endian() ? MESA_FORMAT_XRGB8888 : MESA_FORMAT_XRGB8888_REV;
1488 else
1489 rgbFormat = _mesa_little_endian() ? MESA_FORMAT_ARGB8888 : MESA_FORMAT_ARGB8888_REV;
1490
1491 /* front color renderbuffer */
1492 rfb->color_rb[0] = radeon_create_renderbuffer(rgbFormat, driDrawPriv);
1493 _mesa_add_renderbuffer(&rfb->base, BUFFER_FRONT_LEFT, &rfb->color_rb[0]->base);
1494 rfb->color_rb[0]->has_surface = 1;
1495
1496 /* back color renderbuffer */
1497 if (mesaVis->doubleBufferMode) {
1498 rfb->color_rb[1] = radeon_create_renderbuffer(rgbFormat, driDrawPriv);
1499 _mesa_add_renderbuffer(&rfb->base, BUFFER_BACK_LEFT, &rfb->color_rb[1]->base);
1500 rfb->color_rb[1]->has_surface = 1;
1501 }
1502
1503 if (mesaVis->depthBits == 24) {
1504 if (mesaVis->stencilBits == 8) {
1505 struct radeon_renderbuffer *depthStencilRb =
1506 radeon_create_renderbuffer(MESA_FORMAT_S8_Z24, driDrawPriv);
1507 _mesa_add_renderbuffer(&rfb->base, BUFFER_DEPTH, &depthStencilRb->base);
1508 _mesa_add_renderbuffer(&rfb->base, BUFFER_STENCIL, &depthStencilRb->base);
1509 depthStencilRb->has_surface = screen->depthHasSurface;
1510 } else {
1511 /* depth renderbuffer */
1512 struct radeon_renderbuffer *depth =
1513 radeon_create_renderbuffer(MESA_FORMAT_X8_Z24, driDrawPriv);
1514 _mesa_add_renderbuffer(&rfb->base, BUFFER_DEPTH, &depth->base);
1515 depth->has_surface = screen->depthHasSurface;
1516 }
1517 } else if (mesaVis->depthBits == 16) {
1518 /* just 16-bit depth buffer, no hw stencil */
1519 struct radeon_renderbuffer *depth =
1520 radeon_create_renderbuffer(MESA_FORMAT_Z16, driDrawPriv);
1521 _mesa_add_renderbuffer(&rfb->base, BUFFER_DEPTH, &depth->base);
1522 depth->has_surface = screen->depthHasSurface;
1523 }
1524
1525 _mesa_add_soft_renderbuffers(&rfb->base,
1526 GL_FALSE, /* color */
1527 swDepth,
1528 swStencil,
1529 swAccum,
1530 swAlpha,
1531 GL_FALSE /* aux */);
1532 driDrawPriv->driverPrivate = (void *) rfb;
1533
1534 return (driDrawPriv->driverPrivate != NULL);
1535 }
1536
1537
1538 static void radeon_cleanup_renderbuffers(struct radeon_framebuffer *rfb)
1539 {
1540 struct radeon_renderbuffer *rb;
1541
1542 rb = rfb->color_rb[0];
1543 if (rb && rb->bo) {
1544 radeon_bo_unref(rb->bo);
1545 rb->bo = NULL;
1546 }
1547 rb = rfb->color_rb[1];
1548 if (rb && rb->bo) {
1549 radeon_bo_unref(rb->bo);
1550 rb->bo = NULL;
1551 }
1552 rb = radeon_get_renderbuffer(&rfb->base, BUFFER_DEPTH);
1553 if (rb && rb->bo) {
1554 radeon_bo_unref(rb->bo);
1555 rb->bo = NULL;
1556 }
1557 }
1558
1559 void
1560 radeonDestroyBuffer(__DRIdrawable *driDrawPriv)
1561 {
1562 struct radeon_framebuffer *rfb;
1563 if (!driDrawPriv)
1564 return;
1565
1566 rfb = (void*)driDrawPriv->driverPrivate;
1567 if (!rfb)
1568 return;
1569 radeon_cleanup_renderbuffers(rfb);
1570 _mesa_reference_framebuffer((GLframebuffer **)(&(driDrawPriv->driverPrivate)), NULL);
1571 }
1572
1573
1574 /**
1575 * This is the driver specific part of the createNewScreen entry point.
1576 *
1577 * \todo maybe fold this into intelInitDriver
1578 *
1579 * \return the __GLcontextModes supported by this driver
1580 */
1581 static const __DRIconfig **
1582 radeonInitScreen(__DRIscreen *psp)
1583 {
1584 #if defined(RADEON_R100)
1585 static const char *driver_name = "Radeon";
1586 static const __DRIutilversion2 ddx_expected = { 4, 5, 0, 0 };
1587 static const __DRIversion dri_expected = { 4, 0, 0 };
1588 static const __DRIversion drm_expected = { 1, 6, 0 };
1589 #elif defined(RADEON_R200)
1590 static const char *driver_name = "R200";
1591 static const __DRIutilversion2 ddx_expected = { 4, 5, 0, 0 };
1592 static const __DRIversion dri_expected = { 4, 0, 0 };
1593 static const __DRIversion drm_expected = { 1, 6, 0 };
1594 #elif defined(RADEON_R300)
1595 static const char *driver_name = "R300";
1596 static const __DRIutilversion2 ddx_expected = { 4, 5, 0, 0 };
1597 static const __DRIversion dri_expected = { 4, 0, 0 };
1598 static const __DRIversion drm_expected = { 1, 24, 0 };
1599 #elif defined(RADEON_R600)
1600 static const char *driver_name = "R600";
1601 static const __DRIutilversion2 ddx_expected = { 4, 5, 0, 0 };
1602 static const __DRIversion dri_expected = { 4, 0, 0 };
1603 static const __DRIversion drm_expected = { 1, 24, 0 };
1604 #endif
1605 RADEONDRIPtr dri_priv = (RADEONDRIPtr) psp->pDevPriv;
1606
1607 if ( ! driCheckDriDdxDrmVersions3( driver_name,
1608 &psp->dri_version, & dri_expected,
1609 &psp->ddx_version, & ddx_expected,
1610 &psp->drm_version, & drm_expected ) ) {
1611 return NULL;
1612 }
1613
1614 if (!radeonInitDriver(psp))
1615 return NULL;
1616
1617 /* for now fill in all modes */
1618 return radeonFillInModes( psp,
1619 dri_priv->bpp,
1620 (dri_priv->bpp == 16) ? 16 : 24,
1621 (dri_priv->bpp == 16) ? 0 : 8, 1);
1622 }
1623 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
1624
1625 /**
1626 * This is the driver specific part of the createNewScreen entry point.
1627 * Called when using DRI2.
1628 *
1629 * \return the __GLcontextModes supported by this driver
1630 */
1631 static const
1632 __DRIconfig **radeonInitScreen2(__DRIscreen *psp)
1633 {
1634 GLenum fb_format[3];
1635 GLenum fb_type[3];
1636 /* GLX_SWAP_COPY_OML is only supported because the Intel driver doesn't
1637 * support pageflipping at all.
1638 */
1639 static const GLenum back_buffer_modes[] = {
1640 GLX_NONE, GLX_SWAP_UNDEFINED_OML, /*, GLX_SWAP_COPY_OML*/
1641 };
1642 uint8_t depth_bits[4], stencil_bits[4], msaa_samples_array[1];
1643 int color;
1644 __DRIconfig **configs = NULL;
1645
1646 if (!radeonInitDriver(psp)) {
1647 return NULL;
1648 }
1649 depth_bits[0] = 0;
1650 stencil_bits[0] = 0;
1651 depth_bits[1] = 16;
1652 stencil_bits[1] = 0;
1653 depth_bits[2] = 24;
1654 stencil_bits[2] = 0;
1655 depth_bits[3] = 24;
1656 stencil_bits[3] = 8;
1657
1658 msaa_samples_array[0] = 0;
1659
1660 fb_format[0] = GL_RGB;
1661 fb_type[0] = GL_UNSIGNED_SHORT_5_6_5;
1662
1663 fb_format[1] = GL_BGR;
1664 fb_type[1] = GL_UNSIGNED_INT_8_8_8_8_REV;
1665
1666 fb_format[2] = GL_BGRA;
1667 fb_type[2] = GL_UNSIGNED_INT_8_8_8_8_REV;
1668
1669 for (color = 0; color < ARRAY_SIZE(fb_format); color++) {
1670 __DRIconfig **new_configs;
1671
1672 new_configs = driCreateConfigs(fb_format[color], fb_type[color],
1673 depth_bits,
1674 stencil_bits,
1675 ARRAY_SIZE(depth_bits),
1676 back_buffer_modes,
1677 ARRAY_SIZE(back_buffer_modes),
1678 msaa_samples_array,
1679 ARRAY_SIZE(msaa_samples_array),
1680 GL_TRUE);
1681 if (configs == NULL)
1682 configs = new_configs;
1683 else
1684 configs = driConcatConfigs(configs, new_configs);
1685 }
1686
1687 if (configs == NULL) {
1688 fprintf(stderr, "[%s:%u] Error creating FBConfig!\n", __func__,
1689 __LINE__);
1690 return NULL;
1691 }
1692
1693 return (const __DRIconfig **)configs;
1694 }
1695
1696 /**
1697 * Get information about previous buffer swaps.
1698 */
1699 static int
1700 getSwapInfo( __DRIdrawable *dPriv, __DRIswapInfo * sInfo )
1701 {
1702 struct radeon_framebuffer *rfb;
1703
1704 if ( (dPriv == NULL) || (dPriv->driContextPriv == NULL)
1705 || (dPriv->driContextPriv->driverPrivate == NULL)
1706 || (sInfo == NULL) ) {
1707 return -1;
1708 }
1709
1710 rfb = dPriv->driverPrivate;
1711 sInfo->swap_count = rfb->swap_count;
1712 sInfo->swap_ust = rfb->swap_ust;
1713 sInfo->swap_missed_count = rfb->swap_missed_count;
1714
1715 sInfo->swap_missed_usage = (sInfo->swap_missed_count != 0)
1716 ? driCalculateSwapUsage( dPriv, 0, rfb->swap_missed_ust )
1717 : 0.0;
1718
1719 return 0;
1720 }
1721
1722 const struct __DriverAPIRec driDriverAPI = {
1723 .InitScreen = radeonInitScreen,
1724 .DestroyScreen = radeonDestroyScreen,
1725 #if defined(RADEON_R200)
1726 .CreateContext = r200CreateContext,
1727 .DestroyContext = r200DestroyContext,
1728 #elif defined(RADEON_R600)
1729 .CreateContext = r600CreateContext,
1730 .DestroyContext = radeonDestroyContext,
1731 #elif defined(RADEON_R300)
1732 .CreateContext = r300CreateContext,
1733 .DestroyContext = radeonDestroyContext,
1734 #else
1735 .CreateContext = r100CreateContext,
1736 .DestroyContext = radeonDestroyContext,
1737 #endif
1738 .CreateBuffer = radeonCreateBuffer,
1739 .DestroyBuffer = radeonDestroyBuffer,
1740 .SwapBuffers = radeonSwapBuffers,
1741 .MakeCurrent = radeonMakeCurrent,
1742 .UnbindContext = radeonUnbindContext,
1743 .GetSwapInfo = getSwapInfo,
1744 .GetDrawableMSC = driDrawableGetMSC32,
1745 .WaitForMSC = driWaitForMSC32,
1746 .WaitForSBC = NULL,
1747 .SwapBuffersMSC = NULL,
1748 .CopySubBuffer = radeonCopySubBuffer,
1749 /* DRI2 */
1750 .InitScreen2 = radeonInitScreen2,
1751 };
1752
1753 /* This is the table of extensions that the loader will dlsym() for. */
1754 PUBLIC const __DRIextension *__driDriverExtensions[] = {
1755 &driCoreExtension.base,
1756 &driLegacyExtension.base,
1757 &driDRI2Extension.base,
1758 NULL
1759 };