1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
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 **************************************************************************/
28 #include "sp_context.h"
30 #include "sp_texture.h"
32 #include "util/u_format.h"
33 #include "util/u_memory.h"
34 #include "draw/draw_context.h"
38 softpipe_create_stream_output_state(struct pipe_context
*pipe
,
39 const struct pipe_stream_output_state
*templ
)
41 struct sp_so_state
*so
;
42 so
= (struct sp_so_state
*) CALLOC_STRUCT(sp_so_state
);
45 so
->base
.num_outputs
= templ
->num_outputs
;
46 so
->base
.stride
= templ
->stride
;
47 memcpy(so
->base
.output_buffer
,
49 sizeof(int) * templ
->num_outputs
);
50 memcpy(so
->base
.register_index
,
51 templ
->register_index
,
52 sizeof(int) * templ
->num_outputs
);
53 memcpy(so
->base
.register_mask
,
55 sizeof(ubyte
) * templ
->num_outputs
);
62 softpipe_bind_stream_output_state(struct pipe_context
*pipe
,
65 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
66 struct sp_so_state
*sp_so
= (struct sp_so_state
*) so
;
70 softpipe
->dirty
|= SP_NEW_SO
;
73 draw_set_so_state(softpipe
->draw
, &sp_so
->base
);
78 softpipe_delete_stream_output_state(struct pipe_context
*pipe
, void *so
)
85 softpipe_set_stream_output_buffers(struct pipe_context
*pipe
,
86 struct pipe_resource
**buffers
,
90 struct softpipe_context
*softpipe
= softpipe_context(pipe
);
92 void *map_buffers
[PIPE_MAX_SO_BUFFERS
];
94 assert(num_buffers
<= PIPE_MAX_SO_BUFFERS
);
95 if (num_buffers
> PIPE_MAX_SO_BUFFERS
)
96 num_buffers
= PIPE_MAX_SO_BUFFERS
;
98 softpipe
->dirty
|= SP_NEW_SO_BUFFERS
;
100 for (i
= 0; i
< num_buffers
; ++i
) {
102 struct softpipe_resource
*res
= softpipe_resource(buffers
[i
]);
105 /* the whole call is invalid, bail out */
106 softpipe
->so_target
.num_buffers
= 0;
107 draw_set_mapped_so_buffers(softpipe
->draw
, 0, 0);
111 softpipe
->so_target
.buffer
[i
] = res
;
112 softpipe
->so_target
.offset
[i
] = offsets
[i
];
113 softpipe
->so_target
.so_count
[i
] = 0;
117 map_buffers
[i
] = ((char*)mapped
) + offsets
[i
];
119 /* this is a buffer append */
120 assert(!"appending not implemented");
121 map_buffers
[i
] = mapped
;
124 softpipe
->so_target
.num_buffers
= num_buffers
;
126 draw_set_mapped_so_buffers(softpipe
->draw
, map_buffers
, num_buffers
);
132 softpipe_init_streamout_funcs(struct pipe_context
*pipe
)
134 pipe
->create_stream_output_state
= softpipe_create_stream_output_state
;
135 pipe
->bind_stream_output_state
= softpipe_bind_stream_output_state
;
136 pipe
->delete_stream_output_state
= softpipe_delete_stream_output_state
;
138 pipe
->set_stream_output_buffers
= softpipe_set_stream_output_buffers
;