r600g: upload translated indices via the uploader
[mesa.git] / src / gallium / drivers / llvmpipe / lp_fence.c
1 /**************************************************************************
2 *
3 * Copyright 2009 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28
29 #include "pipe/p_screen.h"
30 #include "util/u_memory.h"
31 #include "lp_debug.h"
32 #include "lp_fence.h"
33
34
35 /**
36 * Create a new fence object.
37 *
38 * The rank will be the number of bins in the scene. Whenever a rendering
39 * thread hits a fence command, it'll increment the fence counter. When
40 * the counter == the rank, the fence is finished.
41 *
42 * \param rank the expected finished value of the fence counter.
43 */
44 struct lp_fence *
45 lp_fence_create(unsigned rank)
46 {
47 static int fence_id;
48 struct lp_fence *fence = CALLOC_STRUCT(lp_fence);
49
50 pipe_reference_init(&fence->reference, 1);
51
52 pipe_mutex_init(fence->mutex);
53 pipe_condvar_init(fence->signalled);
54
55 fence->id = fence_id++;
56 fence->rank = rank;
57
58 if (LP_DEBUG & DEBUG_FENCE)
59 debug_printf("%s %d\n", __FUNCTION__, fence->id);
60
61 return fence;
62 }
63
64
65 /** Destroy a fence. Called when refcount hits zero. */
66 void
67 lp_fence_destroy(struct lp_fence *fence)
68 {
69 if (LP_DEBUG & DEBUG_FENCE)
70 debug_printf("%s %d\n", __FUNCTION__, fence->id);
71
72 pipe_mutex_destroy(fence->mutex);
73 pipe_condvar_destroy(fence->signalled);
74 FREE(fence);
75 }
76
77
78 /**
79 * Called by the rendering threads to increment the fence counter.
80 * When the counter == the rank, the fence is finished.
81 */
82 void
83 lp_fence_signal(struct lp_fence *fence)
84 {
85 if (LP_DEBUG & DEBUG_FENCE)
86 debug_printf("%s %d\n", __FUNCTION__, fence->id);
87
88 pipe_mutex_lock(fence->mutex);
89
90 fence->count++;
91 assert(fence->count <= fence->rank);
92
93 if (LP_DEBUG & DEBUG_FENCE)
94 debug_printf("%s count=%u rank=%u\n", __FUNCTION__,
95 fence->count, fence->rank);
96
97 /* Wakeup all threads waiting on the mutex:
98 */
99 pipe_condvar_broadcast(fence->signalled);
100
101 pipe_mutex_unlock(fence->mutex);
102 }
103
104 boolean
105 lp_fence_signalled(struct lp_fence *f)
106 {
107 return f->count == f->rank;
108 }
109
110 void
111 lp_fence_wait(struct lp_fence *f)
112 {
113 if (LP_DEBUG & DEBUG_FENCE)
114 debug_printf("%s %d\n", __FUNCTION__, f->id);
115
116 pipe_mutex_lock(f->mutex);
117 assert(f->issued);
118 while (f->count < f->rank) {
119 pipe_condvar_wait(f->signalled, f->mutex);
120 }
121 pipe_mutex_unlock(f->mutex);
122 }
123
124