1 /**********************************************************
2 * Copyright 2008-2009 VMware, Inc. All rights reserved.
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24 **********************************************************/
26 #include "draw/draw_context.h"
27 #include "draw/draw_vbuf.h"
28 #include "util/u_inlines.h"
29 #include "pipe/p_state.h"
31 #include "svga_context.h"
32 #include "svga_swtnl.h"
33 #include "svga_state.h"
34 #include "svga_swtnl_private.h"
39 svga_swtnl_draw_vbo(struct svga_context
*svga
,
40 const struct pipe_draw_info
*info
)
42 struct pipe_transfer
*vb_transfer
[PIPE_MAX_ATTRIBS
];
43 struct pipe_transfer
*ib_transfer
= NULL
;
44 struct pipe_transfer
*cb_transfer
= NULL
;
45 struct draw_context
*draw
= svga
->swtnl
.draw
;
51 assert(svga
->state
.sw
.need_swtnl
);
54 /* Make sure that the need_swtnl flag does not go away */
55 svga
->state
.sw
.in_swtnl_draw
= TRUE
;
57 ret
= svga_update_state(svga
, SVGA_STATE_SWTNL_DRAW
);
59 svga_context_flush(svga
, NULL
);
60 ret
= svga_update_state(svga
, SVGA_STATE_SWTNL_DRAW
);
61 svga
->swtnl
.new_vbuf
= TRUE
;
62 assert(ret
== PIPE_OK
);
68 for (i
= 0; i
< svga
->curr
.num_vertex_buffers
; i
++) {
69 map
= pipe_buffer_map(&svga
->pipe
,
70 svga
->curr
.vb
[i
].buffer
,
74 draw_set_mapped_vertex_buffer(draw
, i
, map
);
77 /* TODO move this to update_swtnl_draw */
78 draw_set_index_buffer(draw
, &svga
->curr
.ib
);
80 /* Map index buffer, if present */
82 if (info
->indexed
&& svga
->curr
.ib
.buffer
) {
83 map
= pipe_buffer_map(&svga
->pipe
, svga
->curr
.ib
.buffer
,
87 draw_set_mapped_index_buffer(draw
, map
);
89 if (svga
->curr
.cb
[PIPE_SHADER_VERTEX
]) {
90 map
= pipe_buffer_map(&svga
->pipe
,
91 svga
->curr
.cb
[PIPE_SHADER_VERTEX
],
95 draw_set_mapped_constant_buffer(
96 draw
, PIPE_SHADER_VERTEX
, 0,
98 svga
->curr
.cb
[PIPE_SHADER_VERTEX
]->width0
);
101 draw_vbo(draw
, info
);
103 draw_flush(svga
->swtnl
.draw
);
105 /* Ensure the draw module didn't touch this */
106 assert(i
== svga
->curr
.num_vertex_buffers
);
109 * unmap vertex/index buffers
111 for (i
= 0; i
< svga
->curr
.num_vertex_buffers
; i
++) {
112 pipe_buffer_unmap(&svga
->pipe
, vb_transfer
[i
]);
113 draw_set_mapped_vertex_buffer(draw
, i
, NULL
);
117 pipe_buffer_unmap(&svga
->pipe
, ib_transfer
);
118 draw_set_mapped_index_buffer(draw
, NULL
);
121 if (svga
->curr
.cb
[PIPE_SHADER_VERTEX
]) {
122 pipe_buffer_unmap(&svga
->pipe
, cb_transfer
);
125 /* Now safe to remove the need_swtnl flag in any update_state call */
126 svga
->state
.sw
.in_swtnl_draw
= FALSE
;
134 boolean
svga_init_swtnl( struct svga_context
*svga
)
136 svga
->swtnl
.backend
= svga_vbuf_render_create(svga
);
137 if(!svga
->swtnl
.backend
)
141 * Create drawing context and plug our rendering stage into it.
143 svga
->swtnl
.draw
= draw_create(&svga
->pipe
);
144 if (svga
->swtnl
.draw
== NULL
)
148 draw_set_rasterize_stage(svga
->swtnl
.draw
,
149 draw_vbuf_stage( svga
->swtnl
.draw
, svga
->swtnl
.backend
));
151 draw_set_render(svga
->swtnl
.draw
, svga
->swtnl
.backend
);
153 draw_install_aaline_stage(svga
->swtnl
.draw
, &svga
->pipe
);
154 draw_install_aapoint_stage(svga
->swtnl
.draw
, &svga
->pipe
);
155 draw_install_pstipple_stage(svga
->swtnl
.draw
, &svga
->pipe
);
157 if (debug_get_bool_option("SVGA_SWTNL_FSE", FALSE
))
158 draw_set_driver_clipping(svga
->swtnl
.draw
, TRUE
, TRUE
);
163 if (svga
->swtnl
.backend
)
164 svga
->swtnl
.backend
->destroy( svga
->swtnl
.backend
);
166 if (svga
->swtnl
.draw
)
167 draw_destroy( svga
->swtnl
.draw
);
173 void svga_destroy_swtnl( struct svga_context
*svga
)
175 draw_destroy( svga
->swtnl
.draw
);