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_delete_tcs_cb(struct swr_fence_work
*work
)
111 delete work
->free
.swr_tcs
;
115 swr_delete_tes_cb(struct swr_fence_work
*work
)
117 delete work
->free
.swr_tes
;
122 swr_fence_work_free(struct pipe_fence_handle
*fence
, void *data
,
125 struct swr_fence_work
*work
= CALLOC_STRUCT(swr_fence_work
);
129 work
->callback
= swr_free_cb
<true>;
131 work
->callback
= swr_free_cb
<false>;
132 work
->free
.data
= data
;
134 swr_add_fence_work(fence
, work
);
140 swr_fence_work_delete_vs(struct pipe_fence_handle
*fence
,
141 struct swr_vertex_shader
*swr_vs
)
143 struct swr_fence_work
*work
= CALLOC_STRUCT(swr_fence_work
);
146 work
->callback
= swr_delete_vs_cb
;
147 work
->free
.swr_vs
= swr_vs
;
149 swr_add_fence_work(fence
, work
);
155 swr_fence_work_delete_fs(struct pipe_fence_handle
*fence
,
156 struct swr_fragment_shader
*swr_fs
)
158 struct swr_fence_work
*work
= CALLOC_STRUCT(swr_fence_work
);
161 work
->callback
= swr_delete_fs_cb
;
162 work
->free
.swr_fs
= swr_fs
;
164 swr_add_fence_work(fence
, work
);
170 swr_fence_work_delete_gs(struct pipe_fence_handle
*fence
,
171 struct swr_geometry_shader
*swr_gs
)
173 struct swr_fence_work
*work
= CALLOC_STRUCT(swr_fence_work
);
176 work
->callback
= swr_delete_gs_cb
;
177 work
->free
.swr_gs
= swr_gs
;
179 swr_add_fence_work(fence
, work
);
185 swr_fence_work_delete_tcs(struct pipe_fence_handle
*fence
,
186 struct swr_tess_control_shader
*swr_tcs
)
188 struct swr_fence_work
*work
= CALLOC_STRUCT(swr_fence_work
);
191 work
->callback
= swr_delete_tcs_cb
;
192 work
->free
.swr_tcs
= swr_tcs
;
194 swr_add_fence_work(fence
, work
);
201 swr_fence_work_delete_tes(struct pipe_fence_handle
*fence
,
202 struct swr_tess_evaluation_shader
*swr_tes
)
204 struct swr_fence_work
*work
= CALLOC_STRUCT(swr_fence_work
);
207 work
->callback
= swr_delete_tes_cb
;
208 work
->free
.swr_tes
= swr_tes
;
210 swr_add_fence_work(fence
, work
);