gallium: interface changes necessary to implement transform feedback (v5)
[mesa.git] / src / gallium / drivers / softpipe / sp_state_so.c
1 /**************************************************************************
2 *
3 * Copyright 2010 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 #include "sp_context.h"
29 #include "sp_state.h"
30 #include "sp_texture.h"
31
32 #include "util/u_format.h"
33 #include "util/u_memory.h"
34 #include "draw/draw_context.h"
35
36
37 static void *
38 softpipe_create_stream_output_state(struct pipe_context *pipe,
39 const struct pipe_stream_output_info *templ)
40 {
41 struct sp_so_state *so;
42 so = (struct sp_so_state *) CALLOC_STRUCT(sp_so_state);
43
44 if (so) {
45 so->base.num_outputs = templ->num_outputs;
46 so->base.stride = templ->stride;
47 memcpy(so->base.output, templ->output,
48 templ->num_outputs * sizeof(templ->output[0]));
49 }
50 return so;
51 }
52
53
54 static void
55 softpipe_bind_stream_output_state(struct pipe_context *pipe,
56 void *so)
57 {
58 struct softpipe_context *softpipe = softpipe_context(pipe);
59 struct sp_so_state *sp_so = (struct sp_so_state *) so;
60
61 softpipe->so = sp_so;
62
63 softpipe->dirty |= SP_NEW_SO;
64
65 if (sp_so)
66 draw_set_so_state(softpipe->draw, &sp_so->base);
67 }
68
69
70 static void
71 softpipe_delete_stream_output_state(struct pipe_context *pipe, void *so)
72 {
73 FREE( so );
74 }
75
76
77 static void
78 softpipe_set_stream_output_buffers(struct pipe_context *pipe,
79 struct pipe_resource **buffers,
80 int *offsets,
81 int num_buffers)
82 {
83 struct softpipe_context *softpipe = softpipe_context(pipe);
84 int i;
85 void *map_buffers[PIPE_MAX_SO_BUFFERS];
86
87 assert(num_buffers <= PIPE_MAX_SO_BUFFERS);
88 if (num_buffers > PIPE_MAX_SO_BUFFERS)
89 num_buffers = PIPE_MAX_SO_BUFFERS;
90
91 softpipe->dirty |= SP_NEW_SO_BUFFERS;
92
93 for (i = 0; i < num_buffers; ++i) {
94 void *mapped;
95 struct softpipe_resource *res = softpipe_resource(buffers[i]);
96
97 if (!res) {
98 /* the whole call is invalid, bail out */
99 softpipe->so_target.num_buffers = 0;
100 draw_set_mapped_so_buffers(softpipe->draw, 0, 0);
101 return;
102 }
103
104 softpipe->so_target.buffer[i] = res;
105 softpipe->so_target.offset[i] = offsets[i];
106 softpipe->so_target.so_count[i] = 0;
107
108 mapped = res->data;
109 if (offsets[i] >= 0)
110 map_buffers[i] = ((char*)mapped) + offsets[i];
111 else {
112 /* this is a buffer append */
113 assert(!"appending not implemented");
114 map_buffers[i] = mapped;
115 }
116 }
117 softpipe->so_target.num_buffers = num_buffers;
118
119 draw_set_mapped_so_buffers(softpipe->draw, map_buffers, num_buffers);
120 }
121
122
123
124 void
125 softpipe_init_streamout_funcs(struct pipe_context *pipe)
126 {
127 #if 0
128 pipe->create_stream_output_state = softpipe_create_stream_output_state;
129 pipe->bind_stream_output_state = softpipe_bind_stream_output_state;
130 pipe->delete_stream_output_state = softpipe_delete_stream_output_state;
131
132 pipe->set_stream_output_buffers = softpipe_set_stream_output_buffers;
133 #else
134 (void) softpipe_create_stream_output_state;
135 (void) softpipe_bind_stream_output_state;
136 (void) softpipe_delete_stream_output_state;
137 (void) softpipe_set_stream_output_buffers;
138 #endif
139 }
140