1 /**************************************************************************
3 Copyright 2000, 2001 ATI Technologies Inc., Ontario, Canada, and
4 VA Linux Systems Inc., Fremont, California.
5 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
7 The Weather Channel (TM) funded Tungsten Graphics to develop the
8 initial release of the Radeon 8500 driver under the XFree86 license.
9 This notice must be preserved.
13 Permission is hereby granted, free of charge, to any person obtaining
14 a copy of this software and associated documentation files (the
15 "Software"), to deal in the Software without restriction, including
16 without limitation the rights to use, copy, modify, merge, publish,
17 distribute, sublicense, and/or sell copies of the Software, and to
18 permit persons to whom the Software is furnished to do so, subject to
19 the following conditions:
21 The above copyright notice and this permission notice (including the
22 next paragraph) shall be included in all copies or substantial
23 portions of the Software.
25 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
29 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 **************************************************************************/
35 #include "radeon_common.h"
36 #include "xmlpool.h" /* for symbolic values of enum-type options */
39 #include "drirenderbuffer.h"
40 #include "main/context.h"
41 #include "main/framebuffer.h"
42 #include "main/renderbuffer.h"
43 #include "main/state.h"
44 #include "main/simple_list.h"
45 #include "swrast/swrast.h"
46 #include "swrast_setup/swrast_setup.h"
49 #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R600) /* +r6/r7 */
50 #include "r600_context.h"
53 #define DRIVER_DATE "20090101"
56 int RADEON_DEBUG
= (0);
60 static const char* get_chip_family_name(int chip_family
)
63 case CHIP_FAMILY_R100
: return "R100";
64 case CHIP_FAMILY_RV100
: return "RV100";
65 case CHIP_FAMILY_RS100
: return "RS100";
66 case CHIP_FAMILY_RV200
: return "RV200";
67 case CHIP_FAMILY_RS200
: return "RS200";
68 case CHIP_FAMILY_R200
: return "R200";
69 case CHIP_FAMILY_RV250
: return "RV250";
70 case CHIP_FAMILY_RS300
: return "RS300";
71 case CHIP_FAMILY_RV280
: return "RV280";
72 case CHIP_FAMILY_R300
: return "R300";
73 case CHIP_FAMILY_R350
: return "R350";
74 case CHIP_FAMILY_RV350
: return "RV350";
75 case CHIP_FAMILY_RV380
: return "RV380";
76 case CHIP_FAMILY_R420
: return "R420";
77 case CHIP_FAMILY_RV410
: return "RV410";
78 case CHIP_FAMILY_RS400
: return "RS400";
79 case CHIP_FAMILY_RS600
: return "RS600";
80 case CHIP_FAMILY_RS690
: return "RS690";
81 case CHIP_FAMILY_RS740
: return "RS740";
82 case CHIP_FAMILY_RV515
: return "RV515";
83 case CHIP_FAMILY_R520
: return "R520";
84 case CHIP_FAMILY_RV530
: return "RV530";
85 case CHIP_FAMILY_R580
: return "R580";
86 case CHIP_FAMILY_RV560
: return "RV560";
87 case CHIP_FAMILY_RV570
: return "RV570";
88 case CHIP_FAMILY_R600
: return "R600";
89 case CHIP_FAMILY_RV610
: return "RV610";
90 case CHIP_FAMILY_RV630
: return "RV630";
91 case CHIP_FAMILY_RV670
: return "RV670";
92 case CHIP_FAMILY_RV620
: return "RV620";
93 case CHIP_FAMILY_RV635
: return "RV635";
94 case CHIP_FAMILY_RS780
: return "RS780";
95 case CHIP_FAMILY_RV770
: return "RV770";
96 case CHIP_FAMILY_RV730
: return "RV730";
97 case CHIP_FAMILY_RV710
: return "RV710";
98 case CHIP_FAMILY_RV740
: return "RV740";
99 default: return "unknown";
104 /* Return various strings for glGetString().
106 static const GLubyte
*radeonGetString(GLcontext
* ctx
, GLenum name
)
108 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
109 static char buffer
[128];
113 if (IS_R600_CLASS(radeon
->radeonScreen
))
114 return (GLubyte
*) "Advanced Micro Devices, Inc.";
115 else if (IS_R300_CLASS(radeon
->radeonScreen
))
116 return (GLubyte
*) "DRI R300 Project";
118 return (GLubyte
*) "Tungsten Graphics, Inc.";
123 GLuint agp_mode
= (radeon
->radeonScreen
->card_type
==RADEON_CARD_PCI
) ? 0 :
124 radeon
->radeonScreen
->AGPMode
;
125 const char* chipclass
;
126 char hardwarename
[32];
128 if (IS_R600_CLASS(radeon
->radeonScreen
))
130 else if (IS_R300_CLASS(radeon
->radeonScreen
))
132 else if (IS_R200_CLASS(radeon
->radeonScreen
))
137 sprintf(hardwarename
, "%s (%s %04X)",
139 get_chip_family_name(radeon
->radeonScreen
->chip_family
),
140 radeon
->radeonScreen
->device_id
);
142 offset
= driGetRendererString(buffer
, hardwarename
, DRIVER_DATE
,
145 if (IS_R600_CLASS(radeon
->radeonScreen
)) {
146 sprintf(&buffer
[offset
], " TCL");
147 } else if (IS_R300_CLASS(radeon
->radeonScreen
)) {
148 sprintf(&buffer
[offset
], " %sTCL",
149 (radeon
->radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
)
152 sprintf(&buffer
[offset
], " %sTCL",
153 !(radeon
->TclFallback
& RADEON_TCL_FALLBACK_TCL_DISABLE
)
157 if (radeon
->radeonScreen
->driScreen
->dri2
.enabled
)
158 strcat(buffer
, " DRI2");
160 return (GLubyte
*) buffer
;
168 /* Initialize the driver's misc functions.
170 static void radeonInitDriverFuncs(struct dd_function_table
*functions
)
172 functions
->GetString
= radeonGetString
;
176 * Create and initialize all common fields of the context,
177 * including the Mesa context itself.
179 GLboolean
radeonInitContext(radeonContextPtr radeon
,
180 struct dd_function_table
* functions
,
181 const __GLcontextModes
* glVisual
,
182 __DRIcontextPrivate
* driContextPriv
,
183 void *sharedContextPrivate
)
185 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
186 radeonScreenPtr screen
= (radeonScreenPtr
) (sPriv
->private);
191 /* Fill in additional standard functions. */
192 radeonInitDriverFuncs(functions
);
194 radeon
->radeonScreen
= screen
;
195 /* Allocate and initialize the Mesa context */
196 if (sharedContextPrivate
)
197 shareCtx
= ((radeonContextPtr
)sharedContextPrivate
)->glCtx
;
200 radeon
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
201 functions
, (void *)radeon
);
206 driContextPriv
->driverPrivate
= radeon
;
208 meta_init_metaops(ctx
, &radeon
->meta
);
210 radeon
->dri
.context
= driContextPriv
;
211 radeon
->dri
.screen
= sPriv
;
212 radeon
->dri
.hwContext
= driContextPriv
->hHWContext
;
213 radeon
->dri
.hwLock
= &sPriv
->pSAREA
->lock
;
214 radeon
->dri
.hwLockCount
= 0;
215 radeon
->dri
.fd
= sPriv
->fd
;
216 radeon
->dri
.drmMinor
= sPriv
->drm_version
.minor
;
218 radeon
->sarea
= (drm_radeon_sarea_t
*) ((GLubyte
*) sPriv
->pSAREA
+
219 screen
->sarea_priv_offset
);
222 fthrottle_mode
= driQueryOptioni(&radeon
->optionCache
, "fthrottle_mode");
223 radeon
->iw
.irq_seq
= -1;
224 radeon
->irqsEmitted
= 0;
225 if (IS_R600_CLASS(radeon
->radeonScreen
))
228 radeon
->do_irqs
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
&&
229 radeon
->radeonScreen
->irq
);
231 radeon
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
233 if (!radeon
->do_irqs
)
235 "IRQ's not enabled, falling back to %s: %d %d\n",
236 radeon
->do_usleeps
? "usleeps" : "busy waits",
237 fthrottle_mode
, radeon
->radeonScreen
->irq
);
239 radeon
->texture_depth
= driQueryOptioni (&radeon
->optionCache
,
241 if (radeon
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
242 radeon
->texture_depth
= ( glVisual
->rgbBits
> 16 ) ?
243 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
245 if (IS_R600_CLASS(radeon
->radeonScreen
)) {
246 radeon
->texture_row_align
= 256;
247 radeon
->texture_rect_row_align
= 256;
248 radeon
->texture_compressed_row_align
= 256;
249 } else if (IS_R200_CLASS(radeon
->radeonScreen
) ||
250 IS_R100_CLASS(radeon
->radeonScreen
)) {
251 radeon
->texture_row_align
= 32;
252 radeon
->texture_rect_row_align
= 64;
253 radeon
->texture_compressed_row_align
= 32;
254 } else { /* R300 - not sure this is all correct */
255 int chip_family
= radeon
->radeonScreen
->chip_family
;
256 if (chip_family
== CHIP_FAMILY_RS600
||
257 chip_family
== CHIP_FAMILY_RS690
||
258 chip_family
== CHIP_FAMILY_RS740
)
259 radeon
->texture_row_align
= 64;
261 radeon
->texture_row_align
= 32;
262 radeon
->texture_rect_row_align
= 64;
263 radeon
->texture_compressed_row_align
= 64;
272 * Destroy the command buffer and state atoms.
274 static void radeon_destroy_atom_list(radeonContextPtr radeon
)
276 struct radeon_state_atom
*atom
;
278 foreach(atom
, &radeon
->hw
.atomlist
) {
287 * Cleanup common context fields.
288 * Called by r200DestroyContext/r300DestroyContext
290 void radeonDestroyContext(__DRIcontextPrivate
*driContextPriv
)
292 #ifdef RADEON_BO_TRACK
295 GET_CURRENT_CONTEXT(ctx
);
296 radeonContextPtr radeon
= (radeonContextPtr
) driContextPriv
->driverPrivate
;
297 radeonContextPtr current
= ctx
? RADEON_CONTEXT(ctx
) : NULL
;
298 #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R600) /* +r6/r7 */
299 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
300 radeonScreenPtr screen
= (radeonScreenPtr
) (sPriv
->private);
303 if (radeon
== current
) {
304 radeon_firevertices(radeon
);
305 _mesa_make_current(NULL
, NULL
, NULL
);
310 if (radeon
->dma
.current
) {
311 rcommonFlushCmdBuf( radeon
, __FUNCTION__
);
314 radeonReleaseArrays(radeon
->glCtx
, ~0);
315 meta_destroy_metaops(&radeon
->meta
);
316 if (radeon
->vtbl
.free_context
)
317 radeon
->vtbl
.free_context(radeon
->glCtx
);
318 _swsetup_DestroyContext( radeon
->glCtx
);
319 _tnl_DestroyContext( radeon
->glCtx
);
320 _vbo_DestroyContext( radeon
->glCtx
);
321 _swrast_DestroyContext( radeon
->glCtx
);
324 /* free the Mesa context */
325 _mesa_destroy_context(radeon
->glCtx
);
327 /* _mesa_destroy_context() might result in calls to functions that
328 * depend on the DriverCtx, so don't set it to NULL before.
330 * radeon->glCtx->DriverCtx = NULL;
332 /* free the option cache */
333 driDestroyOptionCache(&radeon
->optionCache
);
335 rcommonDestroyCmdBuf(radeon
);
337 #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R600) /* +r6/r7 */
338 if (!IS_R600_CLASS(screen
))
340 radeon_destroy_atom_list(radeon
);
342 if (radeon
->state
.scissor
.pClipRects
) {
343 FREE(radeon
->state
.scissor
.pClipRects
);
344 radeon
->state
.scissor
.pClipRects
= 0;
347 #ifdef RADEON_BO_TRACK
348 track
= fopen("/tmp/tracklog", "w");
350 radeon_tracker_print(&radeon
->radeonScreen
->bom
->tracker
, track
);
357 /* Force the context `c' to be unbound from its buffer.
359 GLboolean
radeonUnbindContext(__DRIcontextPrivate
* driContextPriv
)
361 radeonContextPtr radeon
= (radeonContextPtr
) driContextPriv
->driverPrivate
;
363 if (RADEON_DEBUG
& DEBUG_DRI
)
364 fprintf(stderr
, "%s ctx %p\n", __FUNCTION__
,
372 radeon_make_kernel_renderbuffer_current(radeonContextPtr radeon
,
373 struct radeon_framebuffer
*draw
)
375 /* if radeon->fake */
376 struct radeon_renderbuffer
*rb
;
378 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
)) {
380 #ifdef RADEON_DEBUG_BO
381 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
382 radeon
->radeonScreen
->frontOffset
,
385 RADEON_GEM_DOMAIN_VRAM
,
389 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
390 radeon
->radeonScreen
->frontOffset
,
393 RADEON_GEM_DOMAIN_VRAM
,
395 #endif /* RADEON_DEBUG_BO */
397 rb
->cpp
= radeon
->radeonScreen
->cpp
;
398 rb
->pitch
= radeon
->radeonScreen
->frontPitch
* rb
->cpp
;
400 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
)) {
402 #ifdef RADEON_DEBUG_BO
403 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
404 radeon
->radeonScreen
->backOffset
,
407 RADEON_GEM_DOMAIN_VRAM
,
411 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
412 radeon
->radeonScreen
->backOffset
,
415 RADEON_GEM_DOMAIN_VRAM
,
417 #endif /* RADEON_DEBUG_BO */
419 rb
->cpp
= radeon
->radeonScreen
->cpp
;
420 rb
->pitch
= radeon
->radeonScreen
->backPitch
* rb
->cpp
;
422 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_DEPTH
].Renderbuffer
)) {
424 #ifdef RADEON_DEBUG_BO
425 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
426 radeon
->radeonScreen
->depthOffset
,
429 RADEON_GEM_DOMAIN_VRAM
,
433 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
434 radeon
->radeonScreen
->depthOffset
,
437 RADEON_GEM_DOMAIN_VRAM
,
439 #endif /* RADEON_DEBUG_BO */
441 rb
->cpp
= radeon
->radeonScreen
->cpp
;
442 rb
->pitch
= radeon
->radeonScreen
->depthPitch
* rb
->cpp
;
444 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_STENCIL
].Renderbuffer
)) {
446 #ifdef RADEON_DEBUG_BO
447 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
448 radeon
->radeonScreen
->depthOffset
,
451 RADEON_GEM_DOMAIN_VRAM
,
455 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
456 radeon
->radeonScreen
->depthOffset
,
459 RADEON_GEM_DOMAIN_VRAM
,
461 #endif /* RADEON_DEBUG_BO */
463 rb
->cpp
= radeon
->radeonScreen
->cpp
;
464 rb
->pitch
= radeon
->radeonScreen
->depthPitch
* rb
->cpp
;
469 radeon_make_renderbuffer_current(radeonContextPtr radeon
,
470 struct radeon_framebuffer
*draw
)
472 int size
= 4096*4096*4;
473 /* if radeon->fake */
474 struct radeon_renderbuffer
*rb
;
476 if (radeon
->radeonScreen
->kernel_mm
) {
477 radeon_make_kernel_renderbuffer_current(radeon
, draw
);
482 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
)) {
484 #ifdef RADEON_DEBUG_BO
485 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
486 radeon
->radeonScreen
->frontOffset
+
487 radeon
->radeonScreen
->fbLocation
,
490 RADEON_GEM_DOMAIN_VRAM
,
494 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
495 radeon
->radeonScreen
->frontOffset
+
496 radeon
->radeonScreen
->fbLocation
,
499 RADEON_GEM_DOMAIN_VRAM
,
501 #endif /* RADEON_DEBUG_BO */
503 rb
->cpp
= radeon
->radeonScreen
->cpp
;
504 rb
->pitch
= radeon
->radeonScreen
->frontPitch
* rb
->cpp
;
506 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
)) {
508 #ifdef RADEON_DEBUG_BO
509 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
510 radeon
->radeonScreen
->backOffset
+
511 radeon
->radeonScreen
->fbLocation
,
514 RADEON_GEM_DOMAIN_VRAM
,
518 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
519 radeon
->radeonScreen
->backOffset
+
520 radeon
->radeonScreen
->fbLocation
,
523 RADEON_GEM_DOMAIN_VRAM
,
525 #endif /* RADEON_DEBUG_BO */
527 rb
->cpp
= radeon
->radeonScreen
->cpp
;
528 rb
->pitch
= radeon
->radeonScreen
->backPitch
* rb
->cpp
;
530 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_DEPTH
].Renderbuffer
)) {
532 #ifdef RADEON_DEBUG_BO
533 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
534 radeon
->radeonScreen
->depthOffset
+
535 radeon
->radeonScreen
->fbLocation
,
538 RADEON_GEM_DOMAIN_VRAM
,
542 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
543 radeon
->radeonScreen
->depthOffset
+
544 radeon
->radeonScreen
->fbLocation
,
547 RADEON_GEM_DOMAIN_VRAM
,
549 #endif /* RADEON_DEBUG_BO */
551 rb
->cpp
= radeon
->radeonScreen
->cpp
;
552 rb
->pitch
= radeon
->radeonScreen
->depthPitch
* rb
->cpp
;
554 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_STENCIL
].Renderbuffer
)) {
556 #ifdef RADEON_DEBUG_BO
557 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
558 radeon
->radeonScreen
->depthOffset
+
559 radeon
->radeonScreen
->fbLocation
,
562 RADEON_GEM_DOMAIN_VRAM
,
566 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
567 radeon
->radeonScreen
->depthOffset
+
568 radeon
->radeonScreen
->fbLocation
,
571 RADEON_GEM_DOMAIN_VRAM
,
573 #endif /* RADEON_DEBUG_BO */
575 rb
->cpp
= radeon
->radeonScreen
->cpp
;
576 rb
->pitch
= radeon
->radeonScreen
->depthPitch
* rb
->cpp
;
581 radeon_bits_per_pixel(const struct radeon_renderbuffer
*rb
)
583 switch (rb
->base
._ActualFormat
) {
585 case GL_DEPTH_COMPONENT16
:
589 case GL_DEPTH_COMPONENT24
:
590 case GL_DEPTH24_STENCIL8_EXT
:
591 case GL_STENCIL_INDEX8_EXT
:
599 radeon_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
601 unsigned int attachments
[10];
602 __DRIbuffer
*buffers
= NULL
;
604 struct radeon_renderbuffer
*rb
;
606 struct radeon_framebuffer
*draw
;
607 radeonContextPtr radeon
;
609 struct radeon_bo
*depth_bo
= NULL
, *bo
;
611 if (RADEON_DEBUG
& DEBUG_DRI
)
612 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
614 draw
= drawable
->driverPrivate
;
615 screen
= context
->driScreenPriv
;
616 radeon
= (radeonContextPtr
) context
->driverPrivate
;
618 if (screen
->dri2
.loader
619 && (screen
->dri2
.loader
->base
.version
> 2)
620 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
621 struct radeon_renderbuffer
*depth_rb
;
622 struct radeon_renderbuffer
*stencil_rb
;
625 if ((radeon
->is_front_buffer_rendering
||
626 radeon
->is_front_buffer_reading
||
628 && draw
->color_rb
[0]) {
629 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
630 attachments
[i
++] = radeon_bits_per_pixel(draw
->color_rb
[0]);
633 if (draw
->color_rb
[1]) {
634 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
635 attachments
[i
++] = radeon_bits_per_pixel(draw
->color_rb
[1]);
638 depth_rb
= radeon_get_renderbuffer(&draw
->base
, BUFFER_DEPTH
);
639 stencil_rb
= radeon_get_renderbuffer(&draw
->base
, BUFFER_STENCIL
);
641 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
642 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
643 attachments
[i
++] = radeon_bits_per_pixel(depth_rb
);
644 } else if (depth_rb
!= NULL
) {
645 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
646 attachments
[i
++] = radeon_bits_per_pixel(depth_rb
);
647 } else if (stencil_rb
!= NULL
) {
648 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
649 attachments
[i
++] = radeon_bits_per_pixel(stencil_rb
);
652 buffers
= (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
657 drawable
->loaderPrivate
);
658 } else if (screen
->dri2
.loader
) {
660 if (draw
->color_rb
[0])
661 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
662 if (draw
->color_rb
[1])
663 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
664 if (radeon_get_renderbuffer(&draw
->base
, BUFFER_DEPTH
))
665 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
666 if (radeon_get_renderbuffer(&draw
->base
, BUFFER_STENCIL
))
667 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
669 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
674 drawable
->loaderPrivate
);
680 /* set one cliprect to cover the whole drawable */
685 drawable
->numClipRects
= 1;
686 drawable
->pClipRects
[0].x1
= 0;
687 drawable
->pClipRects
[0].y1
= 0;
688 drawable
->pClipRects
[0].x2
= drawable
->w
;
689 drawable
->pClipRects
[0].y2
= drawable
->h
;
690 drawable
->numBackClipRects
= 1;
691 drawable
->pBackClipRects
[0].x1
= 0;
692 drawable
->pBackClipRects
[0].y1
= 0;
693 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
694 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
695 for (i
= 0; i
< count
; i
++) {
696 switch (buffers
[i
].attachment
) {
697 case __DRI_BUFFER_FRONT_LEFT
:
698 rb
= draw
->color_rb
[0];
699 regname
= "dri2 front buffer";
701 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
702 rb
= draw
->color_rb
[0];
703 regname
= "dri2 fake front buffer";
705 case __DRI_BUFFER_BACK_LEFT
:
706 rb
= draw
->color_rb
[1];
707 regname
= "dri2 back buffer";
709 case __DRI_BUFFER_DEPTH
:
710 rb
= radeon_get_renderbuffer(&draw
->base
, BUFFER_DEPTH
);
711 regname
= "dri2 depth buffer";
713 case __DRI_BUFFER_DEPTH_STENCIL
:
714 rb
= radeon_get_renderbuffer(&draw
->base
, BUFFER_DEPTH
);
715 regname
= "dri2 depth / stencil buffer";
717 case __DRI_BUFFER_STENCIL
:
718 rb
= radeon_get_renderbuffer(&draw
->base
, BUFFER_STENCIL
);
719 regname
= "dri2 stencil buffer";
721 case __DRI_BUFFER_ACCUM
:
724 "unhandled buffer attach event, attacment type %d\n",
725 buffers
[i
].attachment
);
733 uint32_t name
= radeon_gem_name_bo(rb
->bo
);
734 if (name
== buffers
[i
].name
)
738 if (RADEON_DEBUG
& DEBUG_DRI
)
740 "attaching buffer %s, %d, at %d, cpp %d, pitch %d\n",
741 regname
, buffers
[i
].name
, buffers
[i
].attachment
,
742 buffers
[i
].cpp
, buffers
[i
].pitch
);
744 rb
->cpp
= buffers
[i
].cpp
;
745 rb
->pitch
= buffers
[i
].pitch
;
746 rb
->base
.Width
= drawable
->w
;
747 rb
->base
.Height
= drawable
->h
;
750 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_bo
) {
751 if (RADEON_DEBUG
& DEBUG_DRI
)
752 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
756 uint32_t tiling_flags
= 0, pitch
= 0;
758 #ifdef RADEON_DEBUG_BO
759 bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
763 RADEON_GEM_DOMAIN_VRAM
,
767 bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
771 RADEON_GEM_DOMAIN_VRAM
,
773 #endif /* RADEON_DEBUG_BO */
776 fprintf(stderr
, "failed to attach %s %d\n",
777 regname
, buffers
[i
].name
);
781 ret
= radeon_bo_get_tiling(bo
, &tiling_flags
, &pitch
);
782 if (tiling_flags
& RADEON_TILING_MACRO
)
783 bo
->flags
|= RADEON_BO_FLAGS_MACRO_TILE
;
784 if (tiling_flags
& RADEON_TILING_MICRO
)
785 bo
->flags
|= RADEON_BO_FLAGS_MICRO_TILE
;
789 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
) {
790 if (draw
->base
.Visual
.depthBits
== 16)
795 radeon_renderbuffer_set_bo(rb
, bo
);
798 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
799 rb
= radeon_get_renderbuffer(&draw
->base
, BUFFER_STENCIL
);
801 struct radeon_bo
*stencil_bo
= NULL
;
804 uint32_t name
= radeon_gem_name_bo(rb
->bo
);
805 if (name
== buffers
[i
].name
)
810 radeon_bo_ref(stencil_bo
);
811 radeon_renderbuffer_set_bo(rb
, stencil_bo
);
812 radeon_bo_unref(stencil_bo
);
817 driUpdateFramebufferSize(radeon
->glCtx
, drawable
);
820 /* Force the context `c' to be the current context and associate with it
823 GLboolean
radeonMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
824 __DRIdrawablePrivate
* driDrawPriv
,
825 __DRIdrawablePrivate
* driReadPriv
)
827 radeonContextPtr radeon
;
828 struct radeon_framebuffer
*drfb
;
829 struct gl_framebuffer
*readfb
;
831 if (!driContextPriv
) {
832 if (RADEON_DEBUG
& DEBUG_DRI
)
833 fprintf(stderr
, "%s ctx is null\n", __FUNCTION__
);
834 _mesa_make_current(NULL
, NULL
, NULL
);
838 radeon
= (radeonContextPtr
) driContextPriv
->driverPrivate
;
839 drfb
= driDrawPriv
->driverPrivate
;
840 readfb
= driReadPriv
->driverPrivate
;
842 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
843 radeon_update_renderbuffers(driContextPriv
, driDrawPriv
);
844 if (driDrawPriv
!= driReadPriv
)
845 radeon_update_renderbuffers(driContextPriv
, driReadPriv
);
846 _mesa_reference_renderbuffer(&radeon
->state
.color
.rb
,
847 &(radeon_get_renderbuffer(&drfb
->base
, BUFFER_BACK_LEFT
)->base
));
848 _mesa_reference_renderbuffer(&radeon
->state
.depth
.rb
,
849 &(radeon_get_renderbuffer(&drfb
->base
, BUFFER_DEPTH
)->base
));
851 radeon_make_renderbuffer_current(radeon
, drfb
);
854 if (RADEON_DEBUG
& DEBUG_DRI
)
855 fprintf(stderr
, "%s ctx %p dfb %p rfb %p\n", __FUNCTION__
, radeon
->glCtx
, drfb
, readfb
);
857 driUpdateFramebufferSize(radeon
->glCtx
, driDrawPriv
);
858 if (driReadPriv
!= driDrawPriv
)
859 driUpdateFramebufferSize(radeon
->glCtx
, driReadPriv
);
861 _mesa_make_current(radeon
->glCtx
, &drfb
->base
, readfb
);
863 _mesa_update_state(radeon
->glCtx
);
865 if (radeon
->glCtx
->DrawBuffer
== &drfb
->base
) {
866 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
868 driDrawPriv
->vblFlags
=
869 (radeon
->radeonScreen
->irq
!= 0)
870 ? driGetDefaultVBlankFlags(&radeon
->
872 : VBLANK_FLAG_NO_IRQ
;
874 driDrawableInitVBlank(driDrawPriv
);
875 drfb
->vbl_waited
= driDrawPriv
->vblSeq
;
877 for (i
= 0; i
< 2; i
++) {
878 if (drfb
->color_rb
[i
])
879 drfb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
884 radeon_window_moved(radeon
);
885 radeon_draw_buffer(radeon
->glCtx
, &drfb
->base
);
889 if (RADEON_DEBUG
& DEBUG_DRI
)
890 fprintf(stderr
, "End %s\n", __FUNCTION__
);