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 "drivers/common/meta.h"
41 #include "main/context.h"
42 #include "main/framebuffer.h"
43 #include "main/renderbuffer.h"
44 #include "main/state.h"
45 #include "main/simple_list.h"
46 #include "swrast/swrast.h"
47 #include "swrast_setup/swrast_setup.h"
50 #if RADEON_COMMON && defined(RADEON_COMMON_FOR_R600) /* +r6/r7 */
51 #include "r600_context.h"
54 #define DRIVER_DATE "20090101"
57 int RADEON_DEBUG
= (0);
61 static const char* get_chip_family_name(int chip_family
)
64 case CHIP_FAMILY_R100
: return "R100";
65 case CHIP_FAMILY_RV100
: return "RV100";
66 case CHIP_FAMILY_RS100
: return "RS100";
67 case CHIP_FAMILY_RV200
: return "RV200";
68 case CHIP_FAMILY_RS200
: return "RS200";
69 case CHIP_FAMILY_R200
: return "R200";
70 case CHIP_FAMILY_RV250
: return "RV250";
71 case CHIP_FAMILY_RS300
: return "RS300";
72 case CHIP_FAMILY_RV280
: return "RV280";
73 case CHIP_FAMILY_R300
: return "R300";
74 case CHIP_FAMILY_R350
: return "R350";
75 case CHIP_FAMILY_RV350
: return "RV350";
76 case CHIP_FAMILY_RV380
: return "RV380";
77 case CHIP_FAMILY_R420
: return "R420";
78 case CHIP_FAMILY_RV410
: return "RV410";
79 case CHIP_FAMILY_RS400
: return "RS400";
80 case CHIP_FAMILY_RS600
: return "RS600";
81 case CHIP_FAMILY_RS690
: return "RS690";
82 case CHIP_FAMILY_RS740
: return "RS740";
83 case CHIP_FAMILY_RV515
: return "RV515";
84 case CHIP_FAMILY_R520
: return "R520";
85 case CHIP_FAMILY_RV530
: return "RV530";
86 case CHIP_FAMILY_R580
: return "R580";
87 case CHIP_FAMILY_RV560
: return "RV560";
88 case CHIP_FAMILY_RV570
: return "RV570";
89 case CHIP_FAMILY_R600
: return "R600";
90 case CHIP_FAMILY_RV610
: return "RV610";
91 case CHIP_FAMILY_RV630
: return "RV630";
92 case CHIP_FAMILY_RV670
: return "RV670";
93 case CHIP_FAMILY_RV620
: return "RV620";
94 case CHIP_FAMILY_RV635
: return "RV635";
95 case CHIP_FAMILY_RS780
: return "RS780";
96 case CHIP_FAMILY_RS880
: return "RS880";
97 case CHIP_FAMILY_RV770
: return "RV770";
98 case CHIP_FAMILY_RV730
: return "RV730";
99 case CHIP_FAMILY_RV710
: return "RV710";
100 case CHIP_FAMILY_RV740
: return "RV740";
101 default: return "unknown";
106 /* Return various strings for glGetString().
108 static const GLubyte
*radeonGetString(GLcontext
* ctx
, GLenum name
)
110 radeonContextPtr radeon
= RADEON_CONTEXT(ctx
);
111 static char buffer
[128];
115 if (IS_R600_CLASS(radeon
->radeonScreen
))
116 return (GLubyte
*) "Advanced Micro Devices, Inc.";
117 else if (IS_R300_CLASS(radeon
->radeonScreen
))
118 return (GLubyte
*) "DRI R300 Project";
120 return (GLubyte
*) "Tungsten Graphics, Inc.";
125 GLuint agp_mode
= (radeon
->radeonScreen
->card_type
==RADEON_CARD_PCI
) ? 0 :
126 radeon
->radeonScreen
->AGPMode
;
127 const char* chipclass
;
128 char hardwarename
[32];
130 if (IS_R600_CLASS(radeon
->radeonScreen
))
132 else if (IS_R300_CLASS(radeon
->radeonScreen
))
134 else if (IS_R200_CLASS(radeon
->radeonScreen
))
139 sprintf(hardwarename
, "%s (%s %04X)",
141 get_chip_family_name(radeon
->radeonScreen
->chip_family
),
142 radeon
->radeonScreen
->device_id
);
144 offset
= driGetRendererString(buffer
, hardwarename
, DRIVER_DATE
,
147 if (IS_R600_CLASS(radeon
->radeonScreen
)) {
148 sprintf(&buffer
[offset
], " TCL");
149 } else if (IS_R300_CLASS(radeon
->radeonScreen
)) {
150 sprintf(&buffer
[offset
], " %sTCL",
151 (radeon
->radeonScreen
->chip_flags
& RADEON_CHIPSET_TCL
)
154 sprintf(&buffer
[offset
], " %sTCL",
155 !(radeon
->TclFallback
& RADEON_TCL_FALLBACK_TCL_DISABLE
)
159 if (radeon
->radeonScreen
->driScreen
->dri2
.enabled
)
160 strcat(buffer
, " DRI2");
162 return (GLubyte
*) buffer
;
170 /* Initialize the driver's misc functions.
172 static void radeonInitDriverFuncs(struct dd_function_table
*functions
)
174 functions
->GetString
= radeonGetString
;
178 * Create and initialize all common fields of the context,
179 * including the Mesa context itself.
181 GLboolean
radeonInitContext(radeonContextPtr radeon
,
182 struct dd_function_table
* functions
,
183 const __GLcontextModes
* glVisual
,
184 __DRIcontextPrivate
* driContextPriv
,
185 void *sharedContextPrivate
)
187 __DRIscreenPrivate
*sPriv
= driContextPriv
->driScreenPriv
;
188 radeonScreenPtr screen
= (radeonScreenPtr
) (sPriv
->private);
193 /* Fill in additional standard functions. */
194 radeonInitDriverFuncs(functions
);
196 radeon
->radeonScreen
= screen
;
197 /* Allocate and initialize the Mesa context */
198 if (sharedContextPrivate
)
199 shareCtx
= ((radeonContextPtr
)sharedContextPrivate
)->glCtx
;
202 radeon
->glCtx
= _mesa_create_context(glVisual
, shareCtx
,
203 functions
, (void *)radeon
);
208 driContextPriv
->driverPrivate
= radeon
;
210 meta_init_metaops(ctx
, &radeon
->meta
);
212 _mesa_meta_init(ctx
);
215 radeon
->dri
.context
= driContextPriv
;
216 radeon
->dri
.screen
= sPriv
;
217 radeon
->dri
.hwContext
= driContextPriv
->hHWContext
;
218 radeon
->dri
.hwLock
= &sPriv
->pSAREA
->lock
;
219 radeon
->dri
.hwLockCount
= 0;
220 radeon
->dri
.fd
= sPriv
->fd
;
221 radeon
->dri
.drmMinor
= sPriv
->drm_version
.minor
;
223 radeon
->sarea
= (drm_radeon_sarea_t
*) ((GLubyte
*) sPriv
->pSAREA
+
224 screen
->sarea_priv_offset
);
227 fthrottle_mode
= driQueryOptioni(&radeon
->optionCache
, "fthrottle_mode");
228 radeon
->iw
.irq_seq
= -1;
229 radeon
->irqsEmitted
= 0;
230 if (IS_R600_CLASS(radeon
->radeonScreen
))
233 radeon
->do_irqs
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_IRQS
&&
234 radeon
->radeonScreen
->irq
);
236 radeon
->do_usleeps
= (fthrottle_mode
== DRI_CONF_FTHROTTLE_USLEEPS
);
238 if (!radeon
->do_irqs
)
240 "IRQ's not enabled, falling back to %s: %d %d\n",
241 radeon
->do_usleeps
? "usleeps" : "busy waits",
242 fthrottle_mode
, radeon
->radeonScreen
->irq
);
244 radeon
->texture_depth
= driQueryOptioni (&radeon
->optionCache
,
246 if (radeon
->texture_depth
== DRI_CONF_TEXTURE_DEPTH_FB
)
247 radeon
->texture_depth
= ( glVisual
->rgbBits
> 16 ) ?
248 DRI_CONF_TEXTURE_DEPTH_32
: DRI_CONF_TEXTURE_DEPTH_16
;
250 if (IS_R600_CLASS(radeon
->radeonScreen
)) {
251 radeon
->texture_row_align
= 256;
252 radeon
->texture_rect_row_align
= 256;
253 radeon
->texture_compressed_row_align
= 256;
254 } else if (IS_R200_CLASS(radeon
->radeonScreen
) ||
255 IS_R100_CLASS(radeon
->radeonScreen
)) {
256 radeon
->texture_row_align
= 32;
257 radeon
->texture_rect_row_align
= 64;
258 radeon
->texture_compressed_row_align
= 32;
259 } else { /* R300 - not sure this is all correct */
260 int chip_family
= radeon
->radeonScreen
->chip_family
;
261 if (chip_family
== CHIP_FAMILY_RS600
||
262 chip_family
== CHIP_FAMILY_RS690
||
263 chip_family
== CHIP_FAMILY_RS740
)
264 radeon
->texture_row_align
= 64;
266 radeon
->texture_row_align
= 32;
267 radeon
->texture_rect_row_align
= 64;
268 radeon
->texture_compressed_row_align
= 64;
271 make_empty_list(&radeon
->query
.not_flushed_head
);
272 radeon_init_dma(radeon
);
280 * Destroy the command buffer and state atoms.
282 static void radeon_destroy_atom_list(radeonContextPtr radeon
)
284 struct radeon_state_atom
*atom
;
286 foreach(atom
, &radeon
->hw
.atomlist
) {
295 * Cleanup common context fields.
296 * Called by r200DestroyContext/r300DestroyContext
298 void radeonDestroyContext(__DRIcontextPrivate
*driContextPriv
)
300 #ifdef RADEON_BO_TRACK
303 GET_CURRENT_CONTEXT(ctx
);
304 radeonContextPtr radeon
= (radeonContextPtr
) driContextPriv
->driverPrivate
;
305 radeonContextPtr current
= ctx
? RADEON_CONTEXT(ctx
) : NULL
;
309 _mesa_meta_free(radeon
->glCtx
);
311 if (radeon
== current
) {
312 radeon_firevertices(radeon
);
313 _mesa_make_current(NULL
, NULL
, NULL
);
316 if (!is_empty_list(&radeon
->dma
.reserved
)) {
317 rcommonFlushCmdBuf( radeon
, __FUNCTION__
);
320 radeonFreeDmaRegions(radeon
);
321 radeonReleaseArrays(radeon
->glCtx
, ~0);
322 meta_destroy_metaops(&radeon
->meta
);
323 if (radeon
->vtbl
.free_context
)
324 radeon
->vtbl
.free_context(radeon
->glCtx
);
325 _swsetup_DestroyContext( radeon
->glCtx
);
326 _tnl_DestroyContext( radeon
->glCtx
);
327 _vbo_DestroyContext( radeon
->glCtx
);
328 _swrast_DestroyContext( radeon
->glCtx
);
331 /* free the Mesa context */
332 _mesa_destroy_context(radeon
->glCtx
);
334 /* _mesa_destroy_context() might result in calls to functions that
335 * depend on the DriverCtx, so don't set it to NULL before.
337 * radeon->glCtx->DriverCtx = NULL;
339 /* free the option cache */
340 driDestroyOptionCache(&radeon
->optionCache
);
342 rcommonDestroyCmdBuf(radeon
);
344 radeon_destroy_atom_list(radeon
);
346 if (radeon
->state
.scissor
.pClipRects
) {
347 FREE(radeon
->state
.scissor
.pClipRects
);
348 radeon
->state
.scissor
.pClipRects
= 0;
350 #ifdef RADEON_BO_TRACK
351 track
= fopen("/tmp/tracklog", "w");
353 radeon_tracker_print(&radeon
->radeonScreen
->bom
->tracker
, track
);
360 /* Force the context `c' to be unbound from its buffer.
362 GLboolean
radeonUnbindContext(__DRIcontextPrivate
* driContextPriv
)
364 radeonContextPtr radeon
= (radeonContextPtr
) driContextPriv
->driverPrivate
;
366 if (RADEON_DEBUG
& RADEON_DRI
)
367 fprintf(stderr
, "%s ctx %p\n", __FUNCTION__
,
375 radeon_make_kernel_renderbuffer_current(radeonContextPtr radeon
,
376 struct radeon_framebuffer
*draw
)
378 /* if radeon->fake */
379 struct radeon_renderbuffer
*rb
;
381 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
)) {
383 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
384 radeon
->radeonScreen
->frontOffset
,
387 RADEON_GEM_DOMAIN_VRAM
,
390 rb
->cpp
= radeon
->radeonScreen
->cpp
;
391 rb
->pitch
= radeon
->radeonScreen
->frontPitch
* rb
->cpp
;
393 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
)) {
395 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
396 radeon
->radeonScreen
->backOffset
,
399 RADEON_GEM_DOMAIN_VRAM
,
402 rb
->cpp
= radeon
->radeonScreen
->cpp
;
403 rb
->pitch
= radeon
->radeonScreen
->backPitch
* rb
->cpp
;
405 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_DEPTH
].Renderbuffer
)) {
407 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
408 radeon
->radeonScreen
->depthOffset
,
411 RADEON_GEM_DOMAIN_VRAM
,
414 rb
->cpp
= radeon
->radeonScreen
->cpp
;
415 rb
->pitch
= radeon
->radeonScreen
->depthPitch
* rb
->cpp
;
417 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_STENCIL
].Renderbuffer
)) {
419 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
420 radeon
->radeonScreen
->depthOffset
,
423 RADEON_GEM_DOMAIN_VRAM
,
426 rb
->cpp
= radeon
->radeonScreen
->cpp
;
427 rb
->pitch
= radeon
->radeonScreen
->depthPitch
* rb
->cpp
;
432 radeon_make_renderbuffer_current(radeonContextPtr radeon
,
433 struct radeon_framebuffer
*draw
)
435 int size
= 4096*4096*4;
436 /* if radeon->fake */
437 struct radeon_renderbuffer
*rb
;
439 if (radeon
->radeonScreen
->kernel_mm
) {
440 radeon_make_kernel_renderbuffer_current(radeon
, draw
);
445 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_FRONT_LEFT
].Renderbuffer
)) {
447 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
448 radeon
->radeonScreen
->frontOffset
+
449 radeon
->radeonScreen
->fbLocation
,
452 RADEON_GEM_DOMAIN_VRAM
,
455 rb
->cpp
= radeon
->radeonScreen
->cpp
;
456 rb
->pitch
= radeon
->radeonScreen
->frontPitch
* rb
->cpp
;
458 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_BACK_LEFT
].Renderbuffer
)) {
460 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
461 radeon
->radeonScreen
->backOffset
+
462 radeon
->radeonScreen
->fbLocation
,
465 RADEON_GEM_DOMAIN_VRAM
,
468 rb
->cpp
= radeon
->radeonScreen
->cpp
;
469 rb
->pitch
= radeon
->radeonScreen
->backPitch
* rb
->cpp
;
471 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_DEPTH
].Renderbuffer
)) {
473 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
474 radeon
->radeonScreen
->depthOffset
+
475 radeon
->radeonScreen
->fbLocation
,
478 RADEON_GEM_DOMAIN_VRAM
,
481 rb
->cpp
= radeon
->radeonScreen
->cpp
;
482 rb
->pitch
= radeon
->radeonScreen
->depthPitch
* rb
->cpp
;
484 if ((rb
= (void *)draw
->base
.Attachment
[BUFFER_STENCIL
].Renderbuffer
)) {
486 rb
->bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
487 radeon
->radeonScreen
->depthOffset
+
488 radeon
->radeonScreen
->fbLocation
,
491 RADEON_GEM_DOMAIN_VRAM
,
494 rb
->cpp
= radeon
->radeonScreen
->cpp
;
495 rb
->pitch
= radeon
->radeonScreen
->depthPitch
* rb
->cpp
;
500 radeon_bits_per_pixel(const struct radeon_renderbuffer
*rb
)
502 switch (rb
->base
._ActualFormat
) {
504 case GL_DEPTH_COMPONENT16
:
508 case GL_DEPTH_COMPONENT24
:
509 case GL_DEPTH24_STENCIL8_EXT
:
510 case GL_STENCIL_INDEX8_EXT
:
518 radeon_update_renderbuffers(__DRIcontext
*context
, __DRIdrawable
*drawable
)
520 unsigned int attachments
[10];
521 __DRIbuffer
*buffers
= NULL
;
523 struct radeon_renderbuffer
*rb
;
525 struct radeon_framebuffer
*draw
;
526 radeonContextPtr radeon
;
528 struct radeon_bo
*depth_bo
= NULL
, *bo
;
530 if (RADEON_DEBUG
& RADEON_DRI
)
531 fprintf(stderr
, "enter %s, drawable %p\n", __func__
, drawable
);
533 draw
= drawable
->driverPrivate
;
534 screen
= context
->driScreenPriv
;
535 radeon
= (radeonContextPtr
) context
->driverPrivate
;
537 if (screen
->dri2
.loader
538 && (screen
->dri2
.loader
->base
.version
> 2)
539 && (screen
->dri2
.loader
->getBuffersWithFormat
!= NULL
)) {
540 struct radeon_renderbuffer
*depth_rb
;
541 struct radeon_renderbuffer
*stencil_rb
;
544 if ((radeon
->is_front_buffer_rendering
||
545 radeon
->is_front_buffer_reading
||
547 && draw
->color_rb
[0]) {
548 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
549 attachments
[i
++] = radeon_bits_per_pixel(draw
->color_rb
[0]);
552 if (draw
->color_rb
[1]) {
553 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
554 attachments
[i
++] = radeon_bits_per_pixel(draw
->color_rb
[1]);
557 depth_rb
= radeon_get_renderbuffer(&draw
->base
, BUFFER_DEPTH
);
558 stencil_rb
= radeon_get_renderbuffer(&draw
->base
, BUFFER_STENCIL
);
560 if ((depth_rb
!= NULL
) && (stencil_rb
!= NULL
)) {
561 attachments
[i
++] = __DRI_BUFFER_DEPTH_STENCIL
;
562 attachments
[i
++] = radeon_bits_per_pixel(depth_rb
);
563 } else if (depth_rb
!= NULL
) {
564 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
565 attachments
[i
++] = radeon_bits_per_pixel(depth_rb
);
566 } else if (stencil_rb
!= NULL
) {
567 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
568 attachments
[i
++] = radeon_bits_per_pixel(stencil_rb
);
571 buffers
= (*screen
->dri2
.loader
->getBuffersWithFormat
)(drawable
,
576 drawable
->loaderPrivate
);
577 } else if (screen
->dri2
.loader
) {
579 if (draw
->color_rb
[0])
580 attachments
[i
++] = __DRI_BUFFER_FRONT_LEFT
;
581 if (draw
->color_rb
[1])
582 attachments
[i
++] = __DRI_BUFFER_BACK_LEFT
;
583 if (radeon_get_renderbuffer(&draw
->base
, BUFFER_DEPTH
))
584 attachments
[i
++] = __DRI_BUFFER_DEPTH
;
585 if (radeon_get_renderbuffer(&draw
->base
, BUFFER_STENCIL
))
586 attachments
[i
++] = __DRI_BUFFER_STENCIL
;
588 buffers
= (*screen
->dri2
.loader
->getBuffers
)(drawable
,
593 drawable
->loaderPrivate
);
599 /* set one cliprect to cover the whole drawable */
604 drawable
->numClipRects
= 1;
605 drawable
->pClipRects
[0].x1
= 0;
606 drawable
->pClipRects
[0].y1
= 0;
607 drawable
->pClipRects
[0].x2
= drawable
->w
;
608 drawable
->pClipRects
[0].y2
= drawable
->h
;
609 drawable
->numBackClipRects
= 1;
610 drawable
->pBackClipRects
[0].x1
= 0;
611 drawable
->pBackClipRects
[0].y1
= 0;
612 drawable
->pBackClipRects
[0].x2
= drawable
->w
;
613 drawable
->pBackClipRects
[0].y2
= drawable
->h
;
614 for (i
= 0; i
< count
; i
++) {
615 switch (buffers
[i
].attachment
) {
616 case __DRI_BUFFER_FRONT_LEFT
:
617 rb
= draw
->color_rb
[0];
618 regname
= "dri2 front buffer";
620 case __DRI_BUFFER_FAKE_FRONT_LEFT
:
621 rb
= draw
->color_rb
[0];
622 regname
= "dri2 fake front buffer";
624 case __DRI_BUFFER_BACK_LEFT
:
625 rb
= draw
->color_rb
[1];
626 regname
= "dri2 back buffer";
628 case __DRI_BUFFER_DEPTH
:
629 rb
= radeon_get_renderbuffer(&draw
->base
, BUFFER_DEPTH
);
630 regname
= "dri2 depth buffer";
632 case __DRI_BUFFER_DEPTH_STENCIL
:
633 rb
= radeon_get_renderbuffer(&draw
->base
, BUFFER_DEPTH
);
634 regname
= "dri2 depth / stencil buffer";
636 case __DRI_BUFFER_STENCIL
:
637 rb
= radeon_get_renderbuffer(&draw
->base
, BUFFER_STENCIL
);
638 regname
= "dri2 stencil buffer";
640 case __DRI_BUFFER_ACCUM
:
643 "unhandled buffer attach event, attacment type %d\n",
644 buffers
[i
].attachment
);
652 uint32_t name
= radeon_gem_name_bo(rb
->bo
);
653 if (name
== buffers
[i
].name
)
657 if (RADEON_DEBUG
& RADEON_DRI
)
659 "attaching buffer %s, %d, at %d, cpp %d, pitch %d\n",
660 regname
, buffers
[i
].name
, buffers
[i
].attachment
,
661 buffers
[i
].cpp
, buffers
[i
].pitch
);
663 rb
->cpp
= buffers
[i
].cpp
;
664 rb
->pitch
= buffers
[i
].pitch
;
665 rb
->base
.Width
= drawable
->w
;
666 rb
->base
.Height
= drawable
->h
;
669 if (buffers
[i
].attachment
== __DRI_BUFFER_STENCIL
&& depth_bo
) {
670 if (RADEON_DEBUG
& RADEON_DRI
)
671 fprintf(stderr
, "(reusing depth buffer as stencil)\n");
675 uint32_t tiling_flags
= 0, pitch
= 0;
678 bo
= radeon_bo_open(radeon
->radeonScreen
->bom
,
682 RADEON_GEM_DOMAIN_VRAM
,
687 fprintf(stderr
, "failed to attach %s %d\n",
688 regname
, buffers
[i
].name
);
692 ret
= radeon_bo_get_tiling(bo
, &tiling_flags
, &pitch
);
693 if (tiling_flags
& RADEON_TILING_MACRO
)
694 bo
->flags
|= RADEON_BO_FLAGS_MACRO_TILE
;
695 if (tiling_flags
& RADEON_TILING_MICRO
)
696 bo
->flags
|= RADEON_BO_FLAGS_MICRO_TILE
;
700 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH
) {
701 if (draw
->base
.Visual
.depthBits
== 16)
706 radeon_renderbuffer_set_bo(rb
, bo
);
709 if (buffers
[i
].attachment
== __DRI_BUFFER_DEPTH_STENCIL
) {
710 rb
= radeon_get_renderbuffer(&draw
->base
, BUFFER_STENCIL
);
712 struct radeon_bo
*stencil_bo
= NULL
;
715 uint32_t name
= radeon_gem_name_bo(rb
->bo
);
716 if (name
== buffers
[i
].name
)
721 radeon_bo_ref(stencil_bo
);
722 radeon_renderbuffer_set_bo(rb
, stencil_bo
);
723 radeon_bo_unref(stencil_bo
);
728 driUpdateFramebufferSize(radeon
->glCtx
, drawable
);
731 /* Force the context `c' to be the current context and associate with it
734 GLboolean
radeonMakeCurrent(__DRIcontextPrivate
* driContextPriv
,
735 __DRIdrawablePrivate
* driDrawPriv
,
736 __DRIdrawablePrivate
* driReadPriv
)
738 radeonContextPtr radeon
;
739 struct radeon_framebuffer
*drfb
;
740 struct gl_framebuffer
*readfb
;
742 if (!driContextPriv
) {
743 if (RADEON_DEBUG
& RADEON_DRI
)
744 fprintf(stderr
, "%s ctx is null\n", __FUNCTION__
);
745 _mesa_make_current(NULL
, NULL
, NULL
);
749 radeon
= (radeonContextPtr
) driContextPriv
->driverPrivate
;
750 drfb
= driDrawPriv
->driverPrivate
;
751 readfb
= driReadPriv
->driverPrivate
;
753 if (driContextPriv
->driScreenPriv
->dri2
.enabled
) {
754 radeon_update_renderbuffers(driContextPriv
, driDrawPriv
);
755 if (driDrawPriv
!= driReadPriv
)
756 radeon_update_renderbuffers(driContextPriv
, driReadPriv
);
757 _mesa_reference_renderbuffer(&radeon
->state
.color
.rb
,
758 &(radeon_get_renderbuffer(&drfb
->base
, BUFFER_BACK_LEFT
)->base
));
759 _mesa_reference_renderbuffer(&radeon
->state
.depth
.rb
,
760 &(radeon_get_renderbuffer(&drfb
->base
, BUFFER_DEPTH
)->base
));
762 radeon_make_renderbuffer_current(radeon
, drfb
);
765 if (RADEON_DEBUG
& RADEON_DRI
)
766 fprintf(stderr
, "%s ctx %p dfb %p rfb %p\n", __FUNCTION__
, radeon
->glCtx
, drfb
, readfb
);
768 driUpdateFramebufferSize(radeon
->glCtx
, driDrawPriv
);
769 if (driReadPriv
!= driDrawPriv
)
770 driUpdateFramebufferSize(radeon
->glCtx
, driReadPriv
);
772 _mesa_make_current(radeon
->glCtx
, &drfb
->base
, readfb
);
774 _mesa_update_state(radeon
->glCtx
);
776 if (radeon
->glCtx
->DrawBuffer
== &drfb
->base
) {
777 if (driDrawPriv
->swap_interval
== (unsigned)-1) {
779 driDrawPriv
->vblFlags
=
780 (radeon
->radeonScreen
->irq
!= 0)
781 ? driGetDefaultVBlankFlags(&radeon
->
783 : VBLANK_FLAG_NO_IRQ
;
785 driDrawableInitVBlank(driDrawPriv
);
786 drfb
->vbl_waited
= driDrawPriv
->vblSeq
;
788 for (i
= 0; i
< 2; i
++) {
789 if (drfb
->color_rb
[i
])
790 drfb
->color_rb
[i
]->vbl_pending
= driDrawPriv
->vblSeq
;
795 radeon_window_moved(radeon
);
796 radeon_draw_buffer(radeon
->glCtx
, &drfb
->base
);
800 if (RADEON_DEBUG
& RADEON_DRI
)
801 fprintf(stderr
, "End %s\n", __FUNCTION__
);