1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**************************************************************************
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2010 VMware, Inc.
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * All Rights Reserved.
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * "Software"), to deal in the Software without restriction, including
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * without limitation the rights to use, copy, modify, merge, publish,
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * distribute, sub license, and/or sell copies of the Software, and to
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * permit persons to whom the Software is furnished to do so, subject to
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the following conditions:
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * next paragraph) shall be included in all copies or substantial portions
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of the Software.
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org **************************************************************************/
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "sp_context.h"
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "sp_state.h"
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "sp_texture.h"
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_format.h"
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "util/u_memory.h"
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "draw/draw_context.h"
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "pipebuffer/pb_buffer.h"
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic struct pipe_stream_output_target *
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgsoftpipe_create_so_target(struct pipe_context *pipe,
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                          struct pipe_resource *buffer,
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                          unsigned buffer_offset,
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                          unsigned buffer_size)
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct draw_so_target *t;
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   t = CALLOC_STRUCT(draw_so_target);
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   t->target.context = pipe;
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   t->target.reference.count = 1;
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   pipe_resource_reference(&t->target.buffer, buffer);
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   t->target.buffer_offset = buffer_offset;
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   t->target.buffer_size = buffer_size;
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   return &t->target;
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgsoftpipe_so_target_destroy(struct pipe_context *pipe,
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                           struct pipe_stream_output_target *target)
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   pipe_resource_reference(&target->buffer, NULL);
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   FREE(target);
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgstatic void
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgsoftpipe_set_so_targets(struct pipe_context *pipe,
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                        unsigned num_targets,
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                        struct pipe_stream_output_target **targets,
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org                        unsigned append_bitmask)
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   struct softpipe_context *softpipe = softpipe_context(pipe);
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   int i;
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   for (i = 0; i < num_targets; i++) {
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      pipe_so_target_reference((struct pipe_stream_output_target **)&softpipe->so_targets[i], targets[i]);
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   for (; i < softpipe->num_so_targets; i++) {
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org      pipe_so_target_reference((struct pipe_stream_output_target **)&softpipe->so_targets[i], NULL);
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   }
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   softpipe->num_so_targets = num_targets;
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgvoid
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgsoftpipe_init_streamout_funcs(struct pipe_context *pipe)
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   pipe->create_stream_output_target = softpipe_create_so_target;
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   pipe->stream_output_target_destroy = softpipe_so_target_destroy;
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org   pipe->set_stream_output_targets = softpipe_set_so_targets;
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
90