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_memory.h"
24 #include "util/u_inlines.h"
25 #include "virgl_context.h"
26 #include "virgl_encode.h"
27 #include "virgl_resource.h"
29 static struct pipe_stream_output_target
*virgl_create_so_target(
30 struct pipe_context
*ctx
,
31 struct pipe_resource
*buffer
,
32 unsigned buffer_offset
,
35 struct virgl_context
*vctx
= (struct virgl_context
*)ctx
;
36 struct virgl_resource
*res
= (struct virgl_resource
*)buffer
;
37 struct virgl_so_target
*t
= CALLOC_STRUCT(virgl_so_target
);
42 handle
= virgl_object_assign_handle();
44 t
->base
.reference
.count
= 1;
45 t
->base
.context
= ctx
;
46 pipe_resource_reference(&t
->base
.buffer
, buffer
);
47 t
->base
.buffer_offset
= buffer_offset
;
48 t
->base
.buffer_size
= buffer_size
;
51 virgl_encoder_create_so_target(vctx
, handle
, res
, buffer_offset
, buffer_size
);
55 static void virgl_destroy_so_target(struct pipe_context
*ctx
,
56 struct pipe_stream_output_target
*target
)
58 struct virgl_context
*vctx
= (struct virgl_context
*)ctx
;
59 struct virgl_so_target
*t
= (struct virgl_so_target
*)target
;
61 pipe_resource_reference(&t
->base
.buffer
, NULL
);
62 virgl_encode_delete_object(vctx
, t
->handle
, VIRGL_OBJECT_STREAMOUT_TARGET
);
66 static void virgl_set_so_targets(struct pipe_context
*ctx
,
68 struct pipe_stream_output_target
**targets
,
69 const unsigned *offset
)
71 struct virgl_context
*vctx
= (struct virgl_context
*)ctx
;
73 for (i
= 0; i
< num_targets
; i
++) {
74 pipe_resource_reference(&vctx
->so_targets
[i
].base
.buffer
, targets
[i
]->buffer
);
76 for (i
= num_targets
; i
< vctx
->num_so_targets
; i
++)
77 pipe_resource_reference(&vctx
->so_targets
[i
].base
.buffer
, NULL
);
78 vctx
->num_so_targets
= num_targets
;
79 virgl_encoder_set_so_targets(vctx
, num_targets
, targets
, 0);//append_bitmask);
82 void virgl_init_so_functions(struct virgl_context
*vctx
)
84 vctx
->base
.create_stream_output_target
= virgl_create_so_target
;
85 vctx
->base
.stream_output_target_destroy
= virgl_destroy_so_target
;
86 vctx
->base
.set_stream_output_targets
= virgl_set_so_targets
;