2 * Copyright 2014, 2015 Red Hat.
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:
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
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.
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"
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
,
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
);
43 handle
= virgl_object_assign_handle();
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
;
52 virgl_encoder_create_so_target(vctx
, handle
, res
, buffer_offset
, buffer_size
);
56 static void virgl_destroy_so_target(struct pipe_context
*ctx
,
57 struct pipe_stream_output_target
*target
)
59 struct virgl_context
*vctx
= virgl_context(ctx
);
60 struct virgl_so_target
*t
= virgl_so_target(target
);
62 pipe_resource_reference(&t
->base
.buffer
, NULL
);
63 virgl_encode_delete_object(vctx
, t
->handle
, VIRGL_OBJECT_STREAMOUT_TARGET
);
67 static void virgl_set_so_targets(struct pipe_context
*ctx
,
69 struct pipe_stream_output_target
**targets
,
70 const unsigned *offset
)
72 struct virgl_context
*vctx
= virgl_context(ctx
);
74 for (i
= 0; i
< num_targets
; i
++) {
75 pipe_resource_reference(&vctx
->so_targets
[i
].base
.buffer
, targets
[i
]->buffer
);
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);
83 void virgl_init_so_functions(struct virgl_context
*vctx
)
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
;