1 /*
2 * Copyright 2014, 2015 Red Hat.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #include "util/u_inlines.h"
24 #include "util/u_memory.h"
25 #include "virgl_context.h"
26 #include "virgl_encode.h"
27 #include "virgl_protocol.h"
28 #include "virgl_resource.h"
29
virgl_create_so_target(struct pipe_context * ctx,struct pipe_resource * buffer,unsigned buffer_offset,unsigned buffer_size)30 static struct pipe_stream_output_target *virgl_create_so_target(
31 struct pipe_context *ctx,
32 struct pipe_resource *buffer,
33 unsigned buffer_offset,
34 unsigned buffer_size)
35 {
36 struct virgl_context *vctx = virgl_context(ctx);
37 struct virgl_resource *res = virgl_resource(buffer);
38 struct virgl_so_target *t = CALLOC_STRUCT(virgl_so_target);
39 uint32_t handle;
40
41 if (!t)
42 return NULL;
43 handle = virgl_object_assign_handle();
44
45 t->base.reference.count = 1;
46 t->base.context = ctx;
47 pipe_resource_reference(&t->base.buffer, buffer);
48 t->base.buffer_offset = buffer_offset;
49 t->base.buffer_size = buffer_size;
50 t->handle = handle;
51 res->clean = FALSE;
52 virgl_encoder_create_so_target(vctx, handle, res, buffer_offset, buffer_size);
53 return &t->base;
54 }
55
virgl_destroy_so_target(struct pipe_context * ctx,struct pipe_stream_output_target * target)56 static void virgl_destroy_so_target(struct pipe_context *ctx,
57 struct pipe_stream_output_target *target)
58 {
59 struct virgl_context *vctx = virgl_context(ctx);
60 struct virgl_so_target *t = virgl_so_target(target);
61
62 pipe_resource_reference(&t->base.buffer, NULL);
63 virgl_encode_delete_object(vctx, t->handle, VIRGL_OBJECT_STREAMOUT_TARGET);
64 FREE(t);
65 }
66
virgl_set_so_targets(struct pipe_context * ctx,unsigned num_targets,struct pipe_stream_output_target ** targets,const unsigned * offset)67 static void virgl_set_so_targets(struct pipe_context *ctx,
68 unsigned num_targets,
69 struct pipe_stream_output_target **targets,
70 const unsigned *offset)
71 {
72 struct virgl_context *vctx = virgl_context(ctx);
73 int i;
74 for (i = 0; i < num_targets; i++) {
75 pipe_resource_reference(&vctx->so_targets[i].base.buffer, targets[i]->buffer);
76 }
77 for (i = num_targets; i < vctx->num_so_targets; i++)
78 pipe_resource_reference(&vctx->so_targets[i].base.buffer, NULL);
79 vctx->num_so_targets = num_targets;
80 virgl_encoder_set_so_targets(vctx, num_targets, targets, 0);//append_bitmask);
81 }
82
virgl_init_so_functions(struct virgl_context * vctx)83 void virgl_init_so_functions(struct virgl_context *vctx)
84 {
85 vctx->base.create_stream_output_target = virgl_create_so_target;
86 vctx->base.stream_output_target_destroy = virgl_destroy_so_target;
87 vctx->base.set_stream_output_targets = virgl_set_so_targets;
88 }
89