r300-gallium: Fix BEGIN_CS and END_CS counting and mismatch.
[mesa.git] / src / gallium / drivers / r300 / r300_swtcl_emit.c
1 /*
2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
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 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE. */
22
23 #include "draw/draw_pipe.h"
24 #include "util/u_memory.h"
25
26 #include "r300_cs.h"
27 #include "r300_context.h"
28 #include "r300_reg.h"
29
30 /* r300_swtcl_emit: Primitive vertex emission using an immediate
31 * vertex buffer and no HW TCL. */
32
33 struct swtcl_stage {
34 /* Parent class */
35 struct draw_stage draw;
36
37 struct r300_context* r300;
38 };
39
40 static INLINE struct swtcl_stage* swtcl_stage(struct draw_stage* draw) {
41 return (struct swtcl_stage*)draw;
42 }
43
44 static INLINE void r300_emit_vertex(struct r300_context* r300,
45 const struct vertex_header* vertex)
46 {
47 struct vertex_info* vinfo = &r300->vertex_info;
48 CS_LOCALS(r300);
49 uint i, j;
50
51 for (i = 0; i < vinfo->num_attribs; i++) {
52 j = vinfo->attrib[i].src_index;
53 switch (vinfo->attrib[i].emit) {
54 case EMIT_1F:
55 OUT_CS_32F(vertex->data[j][0]);
56 break;
57 case EMIT_2F:
58 OUT_CS_32F(vertex->data[j][0]);
59 OUT_CS_32F(vertex->data[j][1]);
60 break;
61 case EMIT_3F:
62 OUT_CS_32F(vertex->data[j][0]);
63 OUT_CS_32F(vertex->data[j][1]);
64 OUT_CS_32F(vertex->data[j][2]);
65 break;
66 case EMIT_4F:
67 OUT_CS_32F(vertex->data[j][0]);
68 OUT_CS_32F(vertex->data[j][1]);
69 OUT_CS_32F(vertex->data[j][2]);
70 OUT_CS_32F(vertex->data[j][3]);
71 break;
72 default:
73 debug_printf("r300: Unknown emit value %d\n",
74 vinfo->attrib[i].emit);
75 break;
76 }
77 }
78 }
79
80 static INLINE void r300_emit_prim(struct draw_stage* draw,
81 struct prim_header* prim,
82 unsigned hwprim,
83 unsigned count)
84 {
85 struct r300_context* r300 = swtcl_stage(draw)->r300;
86 CS_LOCALS(r300);
87 int i;
88
89 r300_emit_dirty_state(r300);
90
91 BEGIN_CS(3);
92 OUT_CS_REG_SEQ(R300_VAP_OUTPUT_VTX_FMT_0, 2);
93 OUT_CS(r300->vertex_info.hwfmt[0]);
94 OUT_CS(r300->vertex_info.hwfmt[1]);
95 END_CS;
96
97 BEGIN_CS(2 + (count * r300->vertex_info.size) + 2);
98 OUT_CS(CP_PACKET3(R200_3D_DRAW_IMMD_2, count));
99 OUT_CS(hwprim | R300_PRIM_WALK_RING |
100 (count << R300_PRIM_NUM_VERTICES_SHIFT));
101
102 for (i = 0; i < count; i++) {
103 r300_emit_vertex(r300, prim->v[i]);
104 }
105
106 END_CS;
107 }
108
109 /* Just as an aside...
110 *
111 * Radeons can do many more primitives:
112 * - Line strip
113 * - Triangle fan
114 * - Triangle strip
115 * - Line loop
116 * - Quads
117 * - Quad strip
118 * - Polygons
119 *
120 * The following were just the only ones in Draw. */
121
122 static void r300_emit_point(struct draw_stage* draw, struct prim_header* prim)
123 {
124 r300_emit_prim(draw, prim, R300_PRIM_TYPE_POINT, 1);
125 }
126
127 static void r300_emit_line(struct draw_stage* draw, struct prim_header* prim)
128 {
129 r300_emit_prim(draw, prim, R300_PRIM_TYPE_LINE, 2);
130 }
131
132 static void r300_emit_tri(struct draw_stage* draw, struct prim_header* prim)
133 {
134 r300_emit_prim(draw, prim, R300_PRIM_TYPE_TRI_LIST, 3);
135 }
136
137 static void r300_swtcl_flush(struct draw_stage* draw, unsigned flags)
138 {
139 }
140
141 static void r300_reset_stipple(struct draw_stage* draw)
142 {
143 /* XXX */
144 }
145
146 static void r300_swtcl_destroy(struct draw_stage* draw)
147 {
148 FREE(draw);
149 }
150
151 struct draw_stage* r300_draw_swtcl_stage(struct r300_context* r300)
152 {
153 struct swtcl_stage* swtcl = CALLOC_STRUCT(swtcl_stage);
154
155 swtcl->r300 = r300;
156 swtcl->draw.point = r300_emit_point;
157 swtcl->draw.line = r300_emit_line;
158 swtcl->draw.tri = r300_emit_tri;
159 swtcl->draw.flush = r300_swtcl_flush;
160 swtcl->draw.reset_stipple_counter = r300_reset_stipple;
161 swtcl->draw.destroy = r300_swtcl_destroy;
162
163 return &swtcl->draw;
164 }