1 /**************************************************************************
3 * Copyright 2010 VMware, Inc.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #include "lp_context.h"
30 #include "lp_texture.h"
32 #include "util/u_memory.h"
33 #include "draw/draw_context.h"
35 static struct pipe_stream_output_target
*
36 llvmpipe_create_so_target(struct pipe_context
*pipe
,
37 struct pipe_resource
*buffer
,
38 unsigned buffer_offset
,
41 struct draw_so_target
*t
;
43 t
= CALLOC_STRUCT(draw_so_target
);
47 t
->target
.context
= pipe
;
48 t
->target
.reference
.count
= 1;
49 pipe_resource_reference(&t
->target
.buffer
, buffer
);
50 t
->target
.buffer_offset
= buffer_offset
;
51 t
->target
.buffer_size
= buffer_size
;
56 llvmpipe_so_target_destroy(struct pipe_context
*pipe
,
57 struct pipe_stream_output_target
*target
)
59 pipe_resource_reference(&target
->buffer
, NULL
);
64 llvmpipe_set_so_targets(struct pipe_context
*pipe
,
66 struct pipe_stream_output_target
**targets
,
67 const unsigned *offsets
)
69 struct llvmpipe_context
*llvmpipe
= llvmpipe_context(pipe
);
71 for (i
= 0; i
< num_targets
; i
++) {
72 const boolean append
= (offsets
[i
] == (unsigned)-1);
74 * Warn if the so target was created in another context.
75 * XXX Not entirely sure if mesa/st may rely on this?
76 * Otherwise should just assert.
78 if (targets
[i
] && targets
[i
]->context
!= pipe
) {
79 debug_printf("Illegal setting of so target with target %d created in "
80 "another context\n", i
);
82 pipe_so_target_reference((struct pipe_stream_output_target
**)&llvmpipe
->so_targets
[i
], targets
[i
]);
83 /* If we're not appending then lets set the internal
84 offset to what was requested */
85 if (!append
&& llvmpipe
->so_targets
[i
]) {
86 llvmpipe
->so_targets
[i
]->internal_offset
= offsets
[i
];
90 void *buf
= llvmpipe_resource(targets
[i
]->buffer
)->data
;
91 llvmpipe
->so_targets
[i
]->mapping
= buf
;
95 for (; i
< llvmpipe
->num_so_targets
; i
++) {
96 pipe_so_target_reference((struct pipe_stream_output_target
**)&llvmpipe
->so_targets
[i
], NULL
);
98 llvmpipe
->num_so_targets
= num_targets
;
100 draw_set_mapped_so_targets(llvmpipe
->draw
, llvmpipe
->num_so_targets
,
101 llvmpipe
->so_targets
);
105 llvmpipe_init_so_funcs(struct llvmpipe_context
*pipe
)
107 pipe
->pipe
.create_stream_output_target
= llvmpipe_create_so_target
;
108 pipe
->pipe
.stream_output_target_destroy
= llvmpipe_so_target_destroy
;
109 pipe
->pipe
.set_stream_output_targets
= llvmpipe_set_so_targets
;