Merge commit 'origin/gallium-master-merge'
[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 void r300_emit_vertex(struct r300_context* r300,
45 const struct vertex_header* vertex)
46 {
47 /* XXX */
48 }
49
50 static INLINE void r300_emit_prim(struct draw_stage* draw,
51 struct prim_header* prim,
52 unsigned hwprim,
53 unsigned count)
54 {
55 struct r300_context* r300 = swtcl_stage(draw)->r300;
56 CS_LOCALS(r300);
57 int i;
58
59 r300_emit_dirty_state(r300);
60
61 /* XXX should be count * vtx size */
62 BEGIN_CS(2 + count + 6);
63 OUT_CS(CP_PACKET3(R200_3D_DRAW_IMMD_2, count));
64 OUT_CS(hwprim | R300_PRIM_WALK_RING |
65 (count << R300_PRIM_NUM_VERTICES_SHIFT));
66
67 for (i = 0; i < count; i++) {
68 r300_emit_vertex(r300, prim->v[i]);
69 }
70 R300_PACIFY;
71 END_CS;
72 }
73
74 /* Just as an aside...
75 *
76 * Radeons can do many more primitives:
77 * - Line strip
78 * - Triangle fan
79 * - Triangle strip
80 * - Line loop
81 * - Quads
82 * - Quad strip
83 * - Polygons
84 *
85 * The following were just the only ones in Draw. */
86
87 static void r300_emit_point(struct draw_stage* draw, struct prim_header* prim)
88 {
89 r300_emit_prim(draw, prim, R300_PRIM_TYPE_POINT, 1);
90 }
91
92 static void r300_emit_line(struct draw_stage* draw, struct prim_header* prim)
93 {
94 r300_emit_prim(draw, prim, R300_PRIM_TYPE_LINE, 2);
95 }
96
97 static void r300_emit_tri(struct draw_stage* draw, struct prim_header* prim)
98 {
99 r300_emit_prim(draw, prim, R300_PRIM_TYPE_TRI_LIST, 3);
100 }
101
102 static void r300_swtcl_flush(struct draw_stage* draw, unsigned flags)
103 {
104 }
105
106 static void r300_reset_stipple(struct draw_stage* draw)
107 {
108 /* XXX */
109 }
110
111 static void r300_swtcl_destroy(struct draw_stage* draw)
112 {
113 FREE(draw);
114 }
115
116 struct draw_stage* r300_draw_swtcl_stage(struct r300_context* r300)
117 {
118 struct swtcl_stage* swtcl = CALLOC_STRUCT(swtcl_stage);
119
120 swtcl->r300 = r300;
121 swtcl->draw.point = r300_emit_point;
122 swtcl->draw.line = r300_emit_line;
123 swtcl->draw.tri = r300_emit_tri;
124 swtcl->draw.flush = r300_swtcl_flush;
125 swtcl->draw.reset_stipple_counter = r300_reset_stipple;
126 swtcl->draw.destroy = r300_swtcl_destroy;
127
128 return &swtcl->draw;
129 }