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 **********************************************************/
28 #include "util/u_inlines.h"
29 #include "util/u_prim.h"
30 #include "util/u_time.h"
31 #include "indices/u_indices.h"
33 #include "svga_hw_reg.h"
34 #include "svga_context.h"
35 #include "svga_screen.h"
36 #include "svga_draw.h"
37 #include "svga_state.h"
38 #include "svga_swtnl.h"
39 #include "svga_debug.h"
43 static enum pipe_error
44 retry_draw_range_elements( struct svga_context
*svga
,
45 struct pipe_resource
*index_buffer
,
55 enum pipe_error ret
= 0;
57 svga_hwtnl_set_unfilled( svga
->hwtnl
,
58 svga
->curr
.rast
->hw_unfilled
);
60 svga_hwtnl_set_flatshade( svga
->hwtnl
,
61 svga
->curr
.rast
->templ
.flatshade
,
62 svga
->curr
.rast
->templ
.flatshade_first
);
65 ret
= svga_update_state( svga
, SVGA_STATE_HW_DRAW
);
69 ret
= svga_hwtnl_draw_range_elements( svga
->hwtnl
,
70 index_buffer
, index_size
, index_bias
,
79 svga_context_flush( svga
, NULL
);
83 return retry_draw_range_elements( svga
,
84 index_buffer
, index_size
, index_bias
,
94 static enum pipe_error
95 retry_draw_arrays( struct svga_context
*svga
,
103 svga_hwtnl_set_unfilled( svga
->hwtnl
,
104 svga
->curr
.rast
->hw_unfilled
);
106 svga_hwtnl_set_flatshade( svga
->hwtnl
,
107 svga
->curr
.rast
->templ
.flatshade
,
108 svga
->curr
.rast
->templ
.flatshade_first
);
110 ret
= svga_update_state( svga
, SVGA_STATE_HW_DRAW
);
114 ret
= svga_hwtnl_draw_arrays( svga
->hwtnl
, prim
,
122 if (ret
== PIPE_ERROR_OUT_OF_MEMORY
&& do_retry
)
124 svga_context_flush( svga
, NULL
);
126 return retry_draw_arrays( svga
,
138 svga_draw_vbo(struct pipe_context
*pipe
, const struct pipe_draw_info
*info
)
140 struct svga_context
*svga
= svga_context( pipe
);
141 unsigned reduced_prim
= u_reduced_prim( info
->mode
);
142 unsigned count
= info
->count
;
143 enum pipe_error ret
= 0;
144 boolean needed_swtnl
;
146 if (!u_trim_pipe_prim( info
->mode
, &count
))
150 * Mark currently bound target surfaces as dirty
151 * doesn't really matter if it is done before drawing.
153 * TODO If we ever normaly return something other then
154 * true we should not mark it as dirty then.
156 svga_mark_surfaces_dirty(svga_context(pipe
));
158 if (svga
->curr
.reduced_prim
!= reduced_prim
) {
159 svga
->curr
.reduced_prim
= reduced_prim
;
160 svga
->dirty
|= SVGA_NEW_REDUCED_PRIMITIVE
;
163 needed_swtnl
= svga
->state
.sw
.need_swtnl
;
165 svga_update_state_retry( svga
, SVGA_STATE_NEED_SWTNL
);
168 if (svga
->curr
.vs
->base
.id
== svga
->debug
.disable_shader
||
169 svga
->curr
.fs
->base
.id
== svga
->debug
.disable_shader
)
173 if (svga
->state
.sw
.need_swtnl
) {
176 * We're switching from HW to SW TNL. SW TNL will require mapping all
177 * currently bound vertex buffers, some of which may already be
178 * referenced in the current command buffer as result of previous HW
179 * TNL. So flush now, to prevent the context to flush while a referred
180 * vertex buffer is mapped.
183 svga_context_flush(svga
, NULL
);
186 ret
= svga_swtnl_draw_vbo( svga
, info
);
189 if (info
->indexed
&& svga
->curr
.ib
.buffer
) {
192 assert(svga
->curr
.ib
.offset
% svga
->curr
.ib
.index_size
== 0);
193 offset
= svga
->curr
.ib
.offset
/ svga
->curr
.ib
.index_size
;
195 ret
= retry_draw_range_elements( svga
,
196 svga
->curr
.ib
.buffer
,
197 svga
->curr
.ib
.index_size
,
202 info
->start
+ offset
,
207 ret
= retry_draw_arrays( svga
,
215 if (SVGA_DEBUG
& DEBUG_FLUSH
) {
216 svga_hwtnl_flush_retry( svga
);
217 svga_context_flush(svga
, NULL
);
222 void svga_init_draw_functions( struct svga_context
*svga
)
224 svga
->pipe
.draw_vbo
= svga_draw_vbo
;