Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / drivers / dri / r600 / r700_clear.c
1 /*
2 * Copyright (C) 2008-2009 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 */
21
22 /*
23 * Authors:
24 * Richard Li <RichardZ.Li@amd.com>, <richardradeon@gmail.com>
25 * CooperYuan <cooper.yuan@amd.com>, <cooperyuan@gmail.com>
26 */
27
28 #include "main/glheader.h"
29 #include "main/context.h"
30 #include "main/macros.h"
31 #include "main/imports.h"
32 #include "main/mtypes.h"
33 #include "main/enums.h"
34 #include "swrast/swrast.h"
35
36 #include "radeon_lock.h"
37 #include "r600_context.h"
38
39 #include "r700_shaderinst.h"
40 #include "r600_emit.h"
41 #include "r700_clear.h"
42
43 static GLboolean r700ClearFast(context_t *context, GLbitfield mask)
44 {
45 /* TODO, fast clear need implementation */
46 return GL_FALSE;
47 }
48
49 void r700Clear(GLcontext * ctx, GLbitfield mask)
50 {
51 context_t *context = R700_CONTEXT(ctx);
52 __DRIdrawable *dPriv = radeon_get_drawable(&context->radeon);
53 const GLuint colorMask = *((GLuint *) & ctx->Color.ColorMask[0]);
54 GLbitfield swrast_mask = 0, tri_mask = 0;
55 int i;
56 struct gl_framebuffer *fb = ctx->DrawBuffer;
57
58 radeon_print(RADEON_RENDER, RADEON_VERBOSE, "%s %x\n", __func__, mask);
59
60 if (mask & (BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_FRONT_RIGHT)) {
61 context->radeon.front_buffer_dirty = GL_TRUE;
62 }
63
64 if( GL_TRUE == r700ClearFast(context, mask) )
65 {
66 return;
67 }
68 if (!context->radeon.radeonScreen->driScreen->dri2.enabled) {
69 LOCK_HARDWARE(&context->radeon);
70 UNLOCK_HARDWARE(&context->radeon);
71 if (dPriv->numClipRects == 0)
72 return;
73 }
74
75 R600_NEWPRIM(context);
76
77 if (colorMask == ~0)
78 tri_mask |= (mask & BUFFER_BITS_COLOR);
79 else
80 tri_mask |= (mask & (BUFFER_BIT_FRONT_LEFT | BUFFER_BIT_BACK_LEFT));
81
82
83 /* HW stencil */
84 if (mask & BUFFER_BIT_STENCIL) {
85 tri_mask |= BUFFER_BIT_STENCIL;
86 }
87
88 /* HW depth */
89 if (mask & BUFFER_BIT_DEPTH) {
90 tri_mask |= BUFFER_BIT_DEPTH;
91 }
92
93 /* If we're doing a tri pass for depth/stencil, include a likely color
94 * buffer with it.
95 */
96
97 for (i = 0; i < BUFFER_COUNT; i++) {
98 GLuint bufBit = 1 << i;
99 if ((tri_mask) & bufBit) {
100 if (!fb->Attachment[i].Renderbuffer->ClassID) {
101 tri_mask &= ~bufBit;
102 swrast_mask |= bufBit;
103 }
104 }
105 }
106
107 /* SW fallback clearing */
108 swrast_mask = mask & ~tri_mask;
109
110 if (tri_mask) {
111 radeonUserClear(ctx, tri_mask);
112 }
113
114 if (swrast_mask) {
115 radeon_print(RADEON_FALLBACKS, RADEON_IMPORTANT, "%s: swrast clear, mask: %x\n",
116 __FUNCTION__, swrast_mask);
117 _swrast_Clear(ctx, swrast_mask);
118 }
119
120 }
121
122