• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 VMWARE 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 #include "pipebuffer/pb_buffer.h"
36 
37 static struct pipe_stream_output_target *
softpipe_create_so_target(struct pipe_context * pipe,struct pipe_resource * buffer,unsigned buffer_offset,unsigned buffer_size)38 softpipe_create_so_target(struct pipe_context *pipe,
39                           struct pipe_resource *buffer,
40                           unsigned buffer_offset,
41                           unsigned buffer_size)
42 {
43    struct draw_so_target *t;
44 
45    t = CALLOC_STRUCT(draw_so_target);
46    t->target.context = pipe;
47    t->target.reference.count = 1;
48    pipe_resource_reference(&t->target.buffer, buffer);
49    t->target.buffer_offset = buffer_offset;
50    t->target.buffer_size = buffer_size;
51    return &t->target;
52 }
53 
54 static void
softpipe_so_target_destroy(struct pipe_context * pipe,struct pipe_stream_output_target * target)55 softpipe_so_target_destroy(struct pipe_context *pipe,
56                            struct pipe_stream_output_target *target)
57 {
58    pipe_resource_reference(&target->buffer, NULL);
59    FREE(target);
60 }
61 
62 static void
softpipe_set_so_targets(struct pipe_context * pipe,unsigned num_targets,struct pipe_stream_output_target ** targets,const unsigned * offsets)63 softpipe_set_so_targets(struct pipe_context *pipe,
64                         unsigned num_targets,
65                         struct pipe_stream_output_target **targets,
66                         const unsigned *offsets)
67 {
68    struct softpipe_context *softpipe = softpipe_context(pipe);
69    unsigned i;
70 
71    for (i = 0; i < num_targets; i++) {
72       pipe_so_target_reference((struct pipe_stream_output_target **)&softpipe->so_targets[i], targets[i]);
73    }
74 
75    for (; i < softpipe->num_so_targets; i++) {
76       pipe_so_target_reference((struct pipe_stream_output_target **)&softpipe->so_targets[i], NULL);
77    }
78 
79    softpipe->num_so_targets = num_targets;
80 }
81 
82 void
softpipe_init_streamout_funcs(struct pipe_context * pipe)83 softpipe_init_streamout_funcs(struct pipe_context *pipe)
84 {
85    pipe->create_stream_output_target = softpipe_create_so_target;
86    pipe->stream_output_target_destroy = softpipe_so_target_destroy;
87    pipe->set_stream_output_targets = softpipe_set_so_targets;
88 }
89 
90