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 "util/u_inlines.h"
27 #include "pipe/p_defines.h"
28 #include "util/u_math.h"
29 #include "util/u_upload_mgr.h"
31 #include "svga_context.h"
32 #include "svga_state.h"
33 #include "svga_draw.h"
34 #include "svga_tgsi.h"
35 #include "svga_screen.h"
36 #include "svga_screen_buffer.h"
38 #include "svga_hw_reg.h"
42 upload_user_buffers( struct svga_context
*svga
)
44 enum pipe_error ret
= PIPE_OK
;
49 debug_printf("%s: %d\n", __FUNCTION__
, svga
->curr
.num_vertex_buffers
);
51 nr
= svga
->curr
.num_vertex_buffers
;
53 for (i
= 0; i
< nr
; i
++)
55 if (svga_buffer_is_user_buffer(svga
->curr
.vb
[i
].buffer
))
57 struct svga_buffer
*buffer
= svga_buffer(svga
->curr
.vb
[i
].buffer
);
59 if (!buffer
->uploaded
.buffer
) {
60 ret
= u_upload_buffer( svga
->upload_vb
,
64 &buffer
->uploaded
.offset
,
65 &buffer
->uploaded
.buffer
);
70 debug_printf("%s: %d: orig buf %p upl buf %p ofs %d sz %d\n",
74 buffer
->uploaded
.buffer
,
75 buffer
->uploaded
.offset
,
79 pipe_buffer_reference( &svga
->curr
.vb
[i
].buffer
, buffer
->uploaded
.buffer
);
80 svga
->curr
.vb
[i
].buffer_offset
= buffer
->uploaded
.offset
;
85 debug_printf("%s: DONE\n", __FUNCTION__
);
91 /***********************************************************************
95 static int emit_hw_vs_vdecl( struct svga_context
*svga
,
98 const struct pipe_vertex_element
*ve
= svga
->curr
.velems
->velem
;
99 SVGA3dVertexDecl decl
;
102 assert(svga
->curr
.velems
->count
>=
103 svga
->curr
.vs
->base
.info
.file_count
[TGSI_FILE_INPUT
]);
105 svga_hwtnl_reset_vdecl( svga
->hwtnl
,
106 svga
->curr
.velems
->count
);
108 for (i
= 0; i
< svga
->curr
.velems
->count
; i
++) {
109 const struct pipe_vertex_buffer
*vb
= &svga
->curr
.vb
[ve
[i
].vertex_buffer_index
];
110 unsigned usage
, index
;
113 svga_generate_vdecl_semantics( i
, &usage
, &index
);
117 decl
.identity
.type
= svga
->state
.sw
.ve_format
[i
];
118 decl
.identity
.method
= SVGA3D_DECLMETHOD_DEFAULT
;
119 decl
.identity
.usage
= usage
;
120 decl
.identity
.usageIndex
= index
;
121 decl
.array
.stride
= vb
->stride
;
122 decl
.array
.offset
= (vb
->buffer_offset
+
125 svga_hwtnl_vdecl( svga
->hwtnl
,
135 static int emit_hw_vdecl( struct svga_context
*svga
,
140 /* SVGA_NEW_NEED_SWTNL
142 if (svga
->state
.sw
.need_swtnl
)
143 return 0; /* Do not emit during swtnl */
145 /* If we get to here, we know that we're going to draw. Upload
146 * userbuffers now and try to combine multiple userbuffers from
147 * multiple draw calls into a single host buffer for performance.
149 if (svga
->curr
.any_user_vertex_buffers
&&
150 SVGA_COMBINE_USERBUFFERS
)
152 ret
= upload_user_buffers( svga
);
156 svga
->curr
.any_user_vertex_buffers
= FALSE
;
159 return emit_hw_vs_vdecl( svga
, dirty
);
163 struct svga_tracked_state svga_hw_vdecl
=
165 "hw vertex decl state (hwtnl version)",
166 ( SVGA_NEW_NEED_SWTNL
|