Merge branch 'mesa_7_7_branch'
[mesa.git] / src / mesa / drivers / dri / r300 / r300_emit.c
1 /*
2 Copyright (C) The Weather Channel, Inc. 2002. All Rights Reserved.
3
4 The Weather Channel (TM) funded Tungsten Graphics to develop the
5 initial release of the Radeon 8500 driver under the XFree86 license.
6 This notice must be preserved.
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
32 *
33 * \author Keith Whitwell <keith@tungstengraphics.com>
34 * \author Maciej Cencora <m.cencora@gmail.com>
35 */
36
37 #include "main/glheader.h"
38 #include "main/mtypes.h"
39 #include "main/colormac.h"
40 #include "main/imports.h"
41 #include "main/macros.h"
42 #include "main/image.h"
43
44 #include "swrast_setup/swrast_setup.h"
45 #include "math/m_translate.h"
46 #include "tnl/tnl.h"
47 #include "tnl/t_context.h"
48
49 #include "r300_context.h"
50 #include "r300_state.h"
51 #include "r300_emit.h"
52 #include "r300_render.h"
53 #include "r300_swtcl.h"
54
55 GLuint r300VAPInputCntl0(GLcontext * ctx, GLuint InputsRead)
56 {
57 /* No idea what this value means. I have seen other values written to
58 * this register... */
59 return 0x5555;
60 }
61
62 GLuint r300VAPInputCntl1(GLcontext * ctx, GLuint InputsRead)
63 {
64 GLuint i, vic_1 = 0;
65
66 if (InputsRead & (1 << VERT_ATTRIB_POS))
67 vic_1 |= R300_INPUT_CNTL_POS;
68
69 if (InputsRead & (1 << VERT_ATTRIB_NORMAL))
70 vic_1 |= R300_INPUT_CNTL_NORMAL;
71
72 if (InputsRead & (1 << VERT_ATTRIB_COLOR0))
73 vic_1 |= R300_INPUT_CNTL_COLOR;
74
75 for (i = 0; i < ctx->Const.MaxTextureUnits; i++)
76 if (InputsRead & (1 << (VERT_ATTRIB_TEX0 + i))) {
77 vic_1 |= R300_INPUT_CNTL_TC0 << i;
78 }
79
80 return vic_1;
81 }
82
83 GLuint r300VAPOutputCntl0(GLcontext * ctx, GLuint vp_writes)
84 {
85 GLuint ret = 0;
86
87 if (vp_writes & (1 << VERT_RESULT_HPOS))
88 ret |= R300_VAP_OUTPUT_VTX_FMT_0__POS_PRESENT;
89
90 if (vp_writes & (1 << VERT_RESULT_COL0))
91 ret |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT;
92
93 if (vp_writes & (1 << VERT_RESULT_COL1))
94 ret |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_1_PRESENT;
95
96 /* Two sided lighting works only if all 4 colors are written */
97 if (vp_writes & (1 << VERT_RESULT_BFC0) || vp_writes & (1 << VERT_RESULT_BFC1))
98 ret |= R300_VAP_OUTPUT_VTX_FMT_0__COLOR_0_PRESENT | R300_VAP_OUTPUT_VTX_FMT_0__COLOR_1_PRESENT |
99 R300_VAP_OUTPUT_VTX_FMT_0__COLOR_2_PRESENT | R300_VAP_OUTPUT_VTX_FMT_0__COLOR_3_PRESENT;
100
101 if (vp_writes & (1 << VERT_RESULT_PSIZ))
102 ret |= R300_VAP_OUTPUT_VTX_FMT_0__PT_SIZE_PRESENT;
103
104 return ret;
105 }
106
107 GLuint r300VAPOutputCntl1(GLcontext * ctx, GLuint vp_writes)
108 {
109 GLuint i, ret = 0, first_free_texcoord = 0;
110
111 for (i = 0; i < ctx->Const.MaxTextureUnits; i++) {
112 if (vp_writes & (1 << (VERT_RESULT_TEX0 + i))) {
113 ret |= (4 << (3 * first_free_texcoord));
114 ++first_free_texcoord;
115 }
116 }
117
118 if (first_free_texcoord > 8) {
119 fprintf(stderr, "\tout of free texcoords\n");
120 exit(-1);
121 }
122
123 return ret;
124 }
125
126 void r300EmitCacheFlush(r300ContextPtr rmesa)
127 {
128 BATCH_LOCALS(&rmesa->radeon);
129
130 BEGIN_BATCH_NO_AUTOSTATE(4);
131 OUT_BATCH_REGVAL(R300_RB3D_DSTCACHE_CTLSTAT,
132 R300_RB3D_DSTCACHE_CTLSTAT_DC_FREE_FREE_3D_TAGS |
133 R300_RB3D_DSTCACHE_CTLSTAT_DC_FLUSH_FLUSH_DIRTY_3D);
134 OUT_BATCH_REGVAL(R300_ZB_ZCACHE_CTLSTAT,
135 R300_ZB_ZCACHE_CTLSTAT_ZC_FLUSH_FLUSH_AND_FREE |
136 R300_ZB_ZCACHE_CTLSTAT_ZC_FREE_FREE);
137 END_BATCH();
138 COMMIT_BATCH();
139 }