aboutsummaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/softpipe/sp_state_so.c
blob: 31ef38412948f16e16ace1b4821ceca842df361e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**************************************************************************
 *
 * Copyright 2010 VMware, Inc.
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sub license, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice (including the
 * next paragraph) shall be included in all copies or substantial portions
 * of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 *
 **************************************************************************/

#include "sp_context.h"
#include "sp_state.h"
#include "sp_texture.h"

#include "util/u_format.h"
#include "util/u_memory.h"
#include "draw/draw_context.h"


static void *
softpipe_create_stream_output_state(struct pipe_context *pipe,
                                    const struct pipe_stream_output_info *templ)
{
   struct sp_so_state *so;
   so = (struct sp_so_state *) CALLOC_STRUCT(sp_so_state);

   if (so) {
      so->base.num_outputs = templ->num_outputs;
      so->base.stride = templ->stride;
      memcpy(so->base.output, templ->output,
             templ->num_outputs * sizeof(templ->output[0]));
   }
   return so;
}


static void
softpipe_bind_stream_output_state(struct pipe_context *pipe,
                                  void *so)
{
   struct softpipe_context *softpipe = softpipe_context(pipe);
   struct sp_so_state *sp_so = (struct sp_so_state *) so;

   softpipe->so = sp_so;

   softpipe->dirty |= SP_NEW_SO;

   if (sp_so)
      draw_set_so_state(softpipe->draw, &sp_so->base);
}


static void
softpipe_delete_stream_output_state(struct pipe_context *pipe, void *so)
{
   FREE( so );
}


static void
softpipe_set_stream_output_buffers(struct pipe_context *pipe,
                                   struct pipe_resource **buffers,
                                   int *offsets,
                                   int num_buffers)
{
   struct softpipe_context *softpipe = softpipe_context(pipe);
   int i;
   void *map_buffers[PIPE_MAX_SO_BUFFERS];

   assert(num_buffers <= PIPE_MAX_SO_BUFFERS);
   if (num_buffers > PIPE_MAX_SO_BUFFERS)
      num_buffers = PIPE_MAX_SO_BUFFERS;

   softpipe->dirty |= SP_NEW_SO_BUFFERS;

   for (i = 0; i < num_buffers; ++i) {
      void *mapped;
      struct softpipe_resource *res = softpipe_resource(buffers[i]);

      if (!res) {
         /* the whole call is invalid, bail out */
         softpipe->so_target.num_buffers = 0;
         draw_set_mapped_so_buffers(softpipe->draw, 0, 0);
         return;
      }

      softpipe->so_target.buffer[i] = res;
      softpipe->so_target.offset[i] = offsets[i];
      softpipe->so_target.so_count[i] = 0;

      mapped = res->data;
      if (offsets[i] >= 0)
         map_buffers[i] = ((char*)mapped) + offsets[i];
      else {
         /* this is a buffer append */
         assert(!"appending not implemented");
         map_buffers[i] = mapped;
      }
   }
   softpipe->so_target.num_buffers = num_buffers;

   draw_set_mapped_so_buffers(softpipe->draw, map_buffers, num_buffers);
}



void
softpipe_init_streamout_funcs(struct pipe_context *pipe)
{
#if 0
   pipe->create_stream_output_state = softpipe_create_stream_output_state;
   pipe->bind_stream_output_state = softpipe_bind_stream_output_state;
   pipe->delete_stream_output_state = softpipe_delete_stream_output_state;

   pipe->set_stream_output_buffers = softpipe_set_stream_output_buffers;
#else
   (void) softpipe_create_stream_output_state;
   (void) softpipe_bind_stream_output_state;
   (void) softpipe_delete_stream_output_state;
   (void) softpipe_set_stream_output_buffers;
#endif
}