1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
34 #include "pipe/p_defines.h"
35 #include "pipe/p_context.h"
36 #include "pipe/internal/p_winsys_screen.h"
37 #include "pipe/p_inlines.h"
38 #include "util/u_prim.h"
40 #include "sp_context.h"
44 #include "draw/draw_context.h"
49 softpipe_map_constant_buffers(struct softpipe_context
*sp
)
51 struct pipe_winsys
*ws
= sp
->pipe
.winsys
;
54 for (i
= 0; i
< PIPE_SHADER_TYPES
; i
++) {
57 for (j
= 0; j
< PIPE_MAX_CONSTANT_BUFFERS
; j
++) {
58 if (sp
->constants
[i
][j
] && sp
->constants
[i
][j
]->size
) {
59 sp
->mapped_constants
[i
][j
] = ws
->buffer_map(ws
,
61 PIPE_BUFFER_USAGE_CPU_READ
);
66 for (i
= 0; i
< PIPE_MAX_CONSTANT_BUFFERS
; i
++) {
67 if (sp
->constants
[PIPE_SHADER_VERTEX
][i
]) {
68 draw_set_mapped_constant_buffer(sp
->draw
,
71 sp
->mapped_constants
[PIPE_SHADER_VERTEX
][i
],
72 sp
->constants
[PIPE_SHADER_VERTEX
][i
]->size
);
74 if (sp
->constants
[PIPE_SHADER_GEOMETRY
][i
]) {
75 draw_set_mapped_constant_buffer(sp
->draw
,
78 sp
->mapped_constants
[PIPE_SHADER_GEOMETRY
][i
],
79 sp
->constants
[PIPE_SHADER_GEOMETRY
][i
]->size
);
86 softpipe_unmap_constant_buffers(struct softpipe_context
*sp
)
88 struct pipe_winsys
*ws
= sp
->pipe
.winsys
;
91 /* really need to flush all prims since the vert/frag shaders const buffers
96 for (i
= 0; i
< PIPE_MAX_CONSTANT_BUFFERS
; i
++) {
97 draw_set_mapped_constant_buffer(sp
->draw
,
102 draw_set_mapped_constant_buffer(sp
->draw
,
103 PIPE_SHADER_GEOMETRY
,
109 for (i
= 0; i
< PIPE_SHADER_TYPES
; i
++) {
112 for (j
= 0; j
< PIPE_MAX_CONSTANT_BUFFERS
; j
++) {
113 if (sp
->constants
[i
][j
] && sp
->constants
[i
][j
]->size
) {
114 ws
->buffer_unmap(ws
, sp
->constants
[i
][j
]);
116 sp
->mapped_constants
[i
][j
] = NULL
;
123 * Draw vertex arrays, with optional indexing.
124 * Basically, map the vertex buffers (and drawing surfaces), then hand off
125 * the drawing to the 'draw' module.
128 softpipe_draw_range_elements_instanced(struct pipe_context
*pipe
,
129 struct pipe_buffer
*indexBuffer
,
136 unsigned startInstance
,
137 unsigned instanceCount
);
141 softpipe_draw_arrays(struct pipe_context
*pipe
, unsigned mode
,
142 unsigned start
, unsigned count
)
144 softpipe_draw_range_elements_instanced(pipe
,
158 softpipe_draw_range_elements(struct pipe_context
*pipe
,
159 struct pipe_buffer
*indexBuffer
,
163 unsigned mode
, unsigned start
, unsigned count
)
165 softpipe_draw_range_elements_instanced(pipe
,
179 softpipe_draw_elements(struct pipe_context
*pipe
,
180 struct pipe_buffer
*indexBuffer
,
182 unsigned mode
, unsigned start
, unsigned count
)
184 softpipe_draw_range_elements_instanced(pipe
,
197 softpipe_draw_arrays_instanced(struct pipe_context
*pipe
,
201 unsigned startInstance
,
202 unsigned instanceCount
)
204 softpipe_draw_range_elements_instanced(pipe
,
217 softpipe_draw_elements_instanced(struct pipe_context
*pipe
,
218 struct pipe_buffer
*indexBuffer
,
223 unsigned startInstance
,
224 unsigned instanceCount
)
226 softpipe_draw_range_elements_instanced(pipe
,
239 softpipe_draw_range_elements_instanced(struct pipe_context
*pipe
,
240 struct pipe_buffer
*indexBuffer
,
247 unsigned startInstance
,
248 unsigned instanceCount
)
250 struct softpipe_context
*sp
= softpipe_context(pipe
);
251 struct draw_context
*draw
= sp
->draw
;
254 if (!softpipe_check_render_cond(sp
))
257 sp
->reduced_api_prim
= u_reduced_prim(mode
);
260 softpipe_update_derived(sp
);
263 softpipe_map_transfers(sp
);
264 softpipe_map_constant_buffers(sp
);
266 /* Map vertex buffers */
267 for (i
= 0; i
< sp
->num_vertex_buffers
; i
++) {
270 buf
= pipe_buffer_map(pipe
->screen
,
271 sp
->vertex_buffer
[i
].buffer
,
272 PIPE_BUFFER_USAGE_CPU_READ
);
273 draw_set_mapped_vertex_buffer(draw
, i
, buf
);
276 /* Map index buffer, if present */
278 void *mapped_indexes
;
280 mapped_indexes
= pipe_buffer_map(pipe
->screen
,
282 PIPE_BUFFER_USAGE_CPU_READ
);
283 draw_set_mapped_element_buffer_range(draw
,
289 /* no index/element buffer */
290 draw_set_mapped_element_buffer_range(draw
,
298 draw_arrays_instanced(draw
, mode
, start
, count
, startInstance
, instanceCount
);
300 /* unmap vertex/index buffers - will cause draw module to flush */
301 for (i
= 0; i
< sp
->num_vertex_buffers
; i
++) {
302 draw_set_mapped_vertex_buffer(draw
, i
, NULL
);
303 pipe_buffer_unmap(pipe
->screen
, sp
->vertex_buffer
[i
].buffer
);
306 draw_set_mapped_element_buffer(draw
, 0, NULL
);
307 pipe_buffer_unmap(pipe
->screen
, indexBuffer
);
310 /* Note: leave drawing surfaces mapped */
311 softpipe_unmap_constant_buffers(sp
);
313 sp
->dirty_render_cache
= TRUE
;