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 "pipe/p_inlines.h"
27 #include "util/u_prim.h"
28 #include "util/u_upload_mgr.h"
29 #include "indices/u_indices.h"
32 #include "svga_draw.h"
33 #include "svga_draw_private.h"
34 #include "svga_screen_buffer.h"
35 #include "svga_winsys.h"
36 #include "svga_context.h"
38 #include "svga_hw_reg.h"
41 static enum pipe_error
42 translate_indices( struct svga_hwtnl
*hwtnl
,
43 struct pipe_buffer
*src
,
47 u_translate_func translate
,
48 struct pipe_buffer
**out_buf
)
50 struct pipe_screen
*screen
= hwtnl
->svga
->pipe
.screen
;
51 unsigned size
= index_size
* nr
;
52 const void *src_map
= NULL
;
53 struct pipe_buffer
*dst
= NULL
;
56 dst
= screen
->buffer_create( screen
, 32,
57 PIPE_BUFFER_USAGE_INDEX
|
58 PIPE_BUFFER_USAGE_CPU_WRITE
|
59 PIPE_BUFFER_USAGE_GPU_READ
,
64 src_map
= pipe_buffer_map( screen
, src
, PIPE_BUFFER_USAGE_CPU_READ
);
68 dst_map
= pipe_buffer_map( screen
, dst
, PIPE_BUFFER_USAGE_CPU_WRITE
);
72 translate( (const char *)src_map
+ offset
,
76 pipe_buffer_unmap( screen
, src
);
77 pipe_buffer_unmap( screen
, dst
);
84 screen
->buffer_unmap( screen
, src
);
87 screen
->buffer_unmap( screen
, dst
);
90 screen
->buffer_destroy( dst
);
92 return PIPE_ERROR_OUT_OF_MEMORY
;
100 svga_hwtnl_simple_draw_range_elements( struct svga_hwtnl
*hwtnl
,
101 struct pipe_buffer
*index_buffer
,
110 struct pipe_buffer
*upload_buffer
= NULL
;
111 SVGA3dPrimitiveRange range
;
114 unsigned index_offset
= start
* index_size
;
117 hw_prim
= svga_translate_prim(prim
, count
, &hw_count
);
122 svga_buffer_is_user_buffer(index_buffer
))
124 assert( index_buffer
->size
>= index_offset
+ count
* index_size
);
126 ret
= u_upload_buffer( hwtnl
->upload_ib
,
135 /* Don't need to worry about refcounting index_buffer as this is
136 * just a stack variable without a counted reference of its own.
137 * The caller holds the reference.
139 index_buffer
= upload_buffer
;
142 range
.primType
= hw_prim
;
143 range
.primitiveCount
= hw_count
;
144 range
.indexArray
.offset
= index_offset
;
145 range
.indexArray
.stride
= index_size
;
146 range
.indexWidth
= index_size
;
147 range
.indexBias
= bias
;
149 ret
= svga_hwtnl_prim( hwtnl
, &range
, min_index
, max_index
, index_buffer
);
155 pipe_buffer_reference( &upload_buffer
, NULL
);
164 svga_hwtnl_draw_range_elements( struct svga_hwtnl
*hwtnl
,
165 struct pipe_buffer
*index_buffer
,
169 unsigned prim
, unsigned start
, unsigned count
,
172 unsigned gen_prim
, gen_size
, gen_nr
, gen_type
;
173 u_translate_func gen_func
;
174 enum pipe_error ret
= PIPE_OK
;
176 if (hwtnl
->api_fillmode
!= PIPE_POLYGON_MODE_FILL
&&
177 prim
>= PIPE_PRIM_TRIANGLES
)
179 gen_type
= u_unfilled_translator( prim
,
190 gen_type
= u_index_translator( svga_hw_prims
,
203 if (gen_type
== U_TRANSLATE_MEMCPY
) {
204 /* No need for translation, just pass through to hardware:
206 return svga_hwtnl_simple_draw_range_elements( hwtnl
, index_buffer
,
210 gen_prim
, start
, count
, bias
);
213 struct pipe_buffer
*gen_buf
= NULL
;
215 /* Need to allocate a new index buffer and run the translate
216 * func to populate it. Could potentially cache this translated
217 * index buffer with the original to avoid future
218 * re-translations. Not much point if we're just accelerating
219 * GL though, as index buffers are typically used only once
222 ret
= translate_indices( hwtnl
,
232 ret
= svga_hwtnl_simple_draw_range_elements( hwtnl
,
246 pipe_buffer_reference( &gen_buf
, NULL
);