1 /****************************************************************************
2 * Copyright (C) 2016 Intel Corporation. All Rights Reserved.
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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
22 ***************************************************************************/
24 #include "swr_context.h"
25 #include "swr_fence.h"
27 #include "util/u_inlines.h"
28 #include "util/u_memory.h"
31 * Called by swr_fence_cb to complete the work queue
34 swr_fence_do_work(struct swr_fence
*fence
)
36 struct swr_fence_work
*work
, *tmp
;
38 if (fence
->work
.head
.next
) {
39 work
= fence
->work
.head
.next
;
40 /* Immediately clear the head so any new work gets added to a new work
42 p_atomic_set(&fence
->work
.head
.next
, 0);
43 p_atomic_set(&fence
->work
.tail
, &fence
->work
.head
);
44 p_atomic_set(&fence
->work
.count
, 0);
57 * Called by one of the specialized work routines below
60 swr_add_fence_work(struct pipe_fence_handle
*fh
,
61 struct swr_fence_work
*work
)
63 /* If no fence, just do the work now */
70 struct swr_fence
*fence
= swr_fence(fh
);
71 p_atomic_set(&fence
->work
.tail
->next
, work
);
72 p_atomic_set(&fence
->work
.tail
, work
);
73 p_atomic_inc(&fence
->work
.count
);
78 * Generic free/free_aligned, and delete vs/fs
80 template<bool aligned_free
>
82 swr_free_cb(struct swr_fence_work
*work
)
85 AlignedFree(work
->free
.data
);
87 FREE(work
->free
.data
);
91 swr_delete_vs_cb(struct swr_fence_work
*work
)
93 delete work
->free
.swr_vs
;
97 swr_delete_fs_cb(struct swr_fence_work
*work
)
99 delete work
->free
.swr_fs
;
103 swr_delete_gs_cb(struct swr_fence_work
*work
)
105 delete work
->free
.swr_gs
;
109 swr_fence_work_free(struct pipe_fence_handle
*fence
, void *data
,
112 struct swr_fence_work
*work
= CALLOC_STRUCT(swr_fence_work
);
116 work
->callback
= swr_free_cb
<true>;
118 work
->callback
= swr_free_cb
<false>;
119 work
->free
.data
= data
;
121 swr_add_fence_work(fence
, work
);
127 swr_fence_work_delete_vs(struct pipe_fence_handle
*fence
,
128 struct swr_vertex_shader
*swr_vs
)
130 struct swr_fence_work
*work
= CALLOC_STRUCT(swr_fence_work
);
133 work
->callback
= swr_delete_vs_cb
;
134 work
->free
.swr_vs
= swr_vs
;
136 swr_add_fence_work(fence
, work
);
142 swr_fence_work_delete_fs(struct pipe_fence_handle
*fence
,
143 struct swr_fragment_shader
*swr_fs
)
145 struct swr_fence_work
*work
= CALLOC_STRUCT(swr_fence_work
);
148 work
->callback
= swr_delete_fs_cb
;
149 work
->free
.swr_fs
= swr_fs
;
151 swr_add_fence_work(fence
, work
);
157 swr_fence_work_delete_gs(struct pipe_fence_handle
*fence
,
158 struct swr_geometry_shader
*swr_gs
)
160 struct swr_fence_work
*work
= CALLOC_STRUCT(swr_fence_work
);
163 work
->callback
= swr_delete_gs_cb
;
164 work
->free
.swr_gs
= swr_gs
;
166 swr_add_fence_work(fence
, work
);