2 * Copyright 2008 Corbin Simpson <MostAwesomeDude@gmail.com>
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:
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
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. */
23 #include "draw/draw_pipe.h"
24 #include "util/u_memory.h"
27 #include "r300_context.h"
30 /* r300_swtcl_emit: Primitive vertex emission using an immediate
31 * vertex buffer and no HW TCL. */
35 struct draw_stage draw
;
37 struct r300_context
* r300
;
40 static INLINE
struct swtcl_stage
* swtcl_stage(struct draw_stage
* draw
) {
41 return (struct swtcl_stage
*)draw
;
44 static INLINE
void r300_emit_vertex(struct r300_context
* r300
,
45 const struct vertex_header
* vertex
)
47 struct vertex_info
* vinfo
= &r300
->vertex_info
;
51 for (i
= 0; i
< vinfo
->num_attribs
; i
++) {
52 j
= vinfo
->attrib
[i
].src_index
;
53 switch (vinfo
->attrib
[i
].emit
) {
55 OUT_CS_32F(vertex
->data
[j
][0]);
58 OUT_CS_32F(vertex
->data
[j
][0]);
59 OUT_CS_32F(vertex
->data
[j
][1]);
62 OUT_CS_32F(vertex
->data
[j
][0]);
63 OUT_CS_32F(vertex
->data
[j
][1]);
64 OUT_CS_32F(vertex
->data
[j
][2]);
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]);
73 debug_printf("r300: Unknown emit value %d\n",
74 vinfo
->attrib
[i
].emit
);
80 static INLINE
void r300_emit_prim(struct draw_stage
* draw
,
81 struct prim_header
* prim
,
85 struct r300_context
* r300
= swtcl_stage(draw
)->r300
;
89 r300_emit_dirty_state(r300
);
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]);
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
));
102 for (i
= 0; i
< count
; i
++) {
103 r300_emit_vertex(r300
, prim
->v
[i
]);
109 /* Just as an aside...
111 * Radeons can do many more primitives:
120 * The following were just the only ones in Draw. */
122 static void r300_emit_point(struct draw_stage
* draw
, struct prim_header
* prim
)
124 r300_emit_prim(draw
, prim
, R300_PRIM_TYPE_POINT
, 1);
127 static void r300_emit_line(struct draw_stage
* draw
, struct prim_header
* prim
)
129 r300_emit_prim(draw
, prim
, R300_PRIM_TYPE_LINE
, 2);
132 static void r300_emit_tri(struct draw_stage
* draw
, struct prim_header
* prim
)
134 r300_emit_prim(draw
, prim
, R300_PRIM_TYPE_TRI_LIST
, 3);
137 static void r300_swtcl_flush(struct draw_stage
* draw
, unsigned flags
)
141 static void r300_reset_stipple(struct draw_stage
* draw
)
146 static void r300_swtcl_destroy(struct draw_stage
* draw
)
151 struct draw_stage
* r300_draw_swtcl_stage(struct r300_context
* r300
)
153 struct swtcl_stage
* swtcl
= CALLOC_STRUCT(swtcl_stage
);
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
;