VirtualBox

source: vbox/trunk/src/VBox/HostServices/SharedOpenGL/crserverlib/server_papi.cpp@ 78375

Last change on this file since 78375 was 78190, checked in by vboxsync, 6 years ago

Merge first stage of the Chromium cleanup from the branch:

  • r129818 (Remove VBOX_WITH_CR_DISPLAY_LISTS and accompanying code as it was disabled since r108676 and was never brought back (see ​bugref:3456 and ​bugref:8485))
  • r129819 (HostServices/SharedOpenGL: Remove unused main entry point from upstream server process based implementation)
  • r129820 (HostServices/SharedOpenGL: Started eliminating all backends other than HGCM. They are not used and probably wouldn't work anymore anyway)
  • r129821 (HostServices/SharedOpenGL,GuestHost/OpenGLAdditions/common/crOpenGL: Kill crTimer* API as it is not used anywhere)
  • r129822 (HostServices/SharedOpenGL,GuestHost/OpenGLAdditions/common/crOpenGL: Kill most from cr_process.h apart from two used methods)
  • r129823 (HostServices/SharedOpenGL,GuestHost/OpenGLAdditions/common/crOpenGL: Kill crList* API as it is unused)
  • r129824 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill crHullInteriorBox API as it is unused)
  • r129825 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill crWarpPoint API as it is unused)
  • r129826 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill CrSa* API as it is unused and not even compiled in)
  • r129827 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Kill cr_bbox.h as it is unused)
  • r129828 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove a few crParseUrl() two uses)
  • r129829 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove last crParseURL() use)
  • r129830 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove crParseURL())
  • r129831 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove VBOX_WITH_COCOA_QT and related code when not set as it is the default for years now and we don't support anything else anymore)
  • r129832 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused cr_logo.h)
  • r129833 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused crut_api.h and crut_clientapi.h)
  • r129834 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused cr_dmx.h)
  • r129835 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused cr_perf.h)
  • r129836 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove cr_rand.h and friends as it is not actively used anywhere)
  • r129837 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of all the swapped versions in the packer SPU, we never change endianess from guest to host and don't need it)
  • r129838 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove more swapper versions in the packer related code)
  • r129839 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove more swapper versions in the packer related code)
  • r129840 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused pack_pica.c)
  • r129841 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove more swapper versions in the packer related code)
  • r129842 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of cr_endianess.h and friends)
  • r129843 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused lowercase.py)
  • r129844 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused cr_calllists.h and friends)
  • r129845 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of completely unused idpool.c, not even compiled in)
  • r129846 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused cr_debugopcodes.h and friends)
  • r129847 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Make the cr_mem.h API inline and get rid of the implementation in the util library)
  • r129848 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of SPUOptions and related code as it is of no use for us)
  • r129849 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of cr_environment.h and friends and convert usage to RTEnv* APIs)
  • r129850 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of unused renderspu_agl.c)
  • r129851 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Remove unused code in cr_htable.h)
  • r129853 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Introduce a state paremeter for the unpacker workers instead of reyling on global variables, work in progress)
  • r129854 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Let the caller of crUnpack set up the initial state. This allows to get rid of the global return_ptr and writeback_ptr as they get supplied in the unpacker state by the server)
  • r129855 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of the cr_lastDispatch and cr_unpackDispatch as they are of no use now)
  • r129856 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Get rid of the global cr_unpackData and cr_unpackDataEnd symbols by indtroducing another hack to make it possible for certail server dispatch callbacks to access the data buffer)
  • r129857 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: build fix for release builds)
  • r129858 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Make the pointer to the unpacker state non const (is required for the access verification))
  • r129859 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: First iteration of the buffer size validation to prevent out of bound read access + added todos for places where additional checks are needed)
  • r129860 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129861 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129871 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129872 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Stop as soon as the unpacker encountered an error)
  • r129876 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129880 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Working on remaining verification todos)
  • r129882 (HostServices/SharedOpenGL,GuestHost/OpenGL,Additions/common/crOpenGL: Fixed some offsets in unpack_texture.c, 3DMark03 renders correctly again)
  • r130013 (HostServices/SharedOpenGL: Convert files to C++ so we can use C99 featuers on Windows with cl.exe)
  • r130014 (HostServices/SharedOpenGL,GuestHost/OpenGL: WIndows build fixes)
  • r130015 (HostServices/SharedOpenGL,GuestHost/OpenGL: More Windows build fixes)
  • r130036 (Config.kmk: Fix linker error on Windows by temporarily disabling the use of VBoxGuestR3DllMinW2K)
  • r130094 (src/VBox/GuestHost/OpenGL: Revert inlining the allocation/free functions in R3 completely as it doesn't work on Windows if memory is allocated and freed across different DLLs which don't share a common CRT, causes crashes in RtlValidtaeHeap())
  • r130095 (src/VBox/GuestHost/OpenGL,src/VBox/Additions/common/crOpenGL/pack: Don't use floating point specifiers in packspu_GetString() to avoid R6002 errors (couldn't fully understand why they occur suddenly after the rework but this gets rid of it))
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 7.5 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#include "server_dispatch.h"
8#include "server.h"
9#include "cr_error.h"
10#include "cr_mem.h"
11#include "state/cr_statetypes.h"
12
13#define DEBUG_BARRIERS 1
14#ifdef DEBUG_BARRIERS
15# include <stdio.h>
16#endif
17
18void SERVER_DISPATCH_APIENTRY crServerDispatchBarrierCreateCR( GLuint name, GLuint count )
19{
20 CRServerBarrier *barrier;
21#if DEBUG_BARRIERS
22 char debug_buf[4096];
23#endif
24
25 if (cr_server.ignore_papi)
26 {
27 cr_server.head_spu->dispatch_table.BarrierCreateCR( name, count );
28 return;
29 }
30
31 barrier = (CRServerBarrier *) crHashtableSearch( cr_server.barriers, name );
32
33#if DEBUG_BARRIERS
34 sprintf( debug_buf, "BarrierCreateCR( %d, %d )", name, count );
35 cr_server.head_spu->dispatch_table.ChromiumParametervCR( GL_PRINT_STRING_CR, GL_UNSIGNED_BYTE, sizeof(debug_buf), debug_buf );
36#endif
37
38 if (count > CR_MAX_CLIENTS)
39 count = CR_MAX_CLIENTS;
40
41 if (count == 0)
42 {
43 count = cr_server.numClients;
44#if DEBUG_BARRIERS
45 sprintf( debug_buf, "changing count to %d", count );
46 cr_server.head_spu->dispatch_table.ChromiumParametervCR( GL_PRINT_STRING_CR, GL_UNSIGNED_BYTE, sizeof(debug_buf), debug_buf );
47#endif
48 }
49
50
51 /* we use maxBarrierCount in Clear() and SwapBuffers() and also use it
52 * in __getNextClient() for deadlock detection. The issue is that all
53 * the existing clients may be blocked, but we might soon get another
54 * client connection to break the apparent deadlock.
55 */
56 if (count > cr_server.maxBarrierCount)
57 cr_server.maxBarrierCount = count;
58
59 if ( barrier == NULL )
60 {
61 barrier = (CRServerBarrier *) crAlloc( sizeof(*barrier) );
62 barrier->count = count;
63 barrier->num_waiting = 0;
64 barrier->waiting = (RunQueue **)
65 crAlloc( count * sizeof(*(barrier->waiting)) );
66
67 crHashtableAdd( cr_server.barriers, name, barrier );
68#if DEBUG_BARRIERS
69 sprintf( debug_buf, "This was a new barrier!" );
70 cr_server.head_spu->dispatch_table.ChromiumParametervCR( GL_PRINT_STRING_CR, GL_UNSIGNED_BYTE, sizeof(debug_buf), debug_buf );
71#endif
72 }
73 else
74 {
75 /* HACK -- this allows everybody to create a barrier, and all
76 but the first creation are ignored, assuming the count
77 match. */
78#if DEBUG_BARRIERS
79 sprintf( debug_buf, "I already knew about this barrier." );
80 cr_server.head_spu->dispatch_table.ChromiumParametervCR( GL_PRINT_STRING_CR, GL_UNSIGNED_BYTE, sizeof(debug_buf), debug_buf );
81#endif
82 if ( barrier->count != count )
83 {
84#if DEBUG_BARRIERS
85 sprintf( debug_buf, "And someone messed up the count!." );
86 cr_server.head_spu->dispatch_table.ChromiumParametervCR( GL_PRINT_STRING_CR, GL_UNSIGNED_BYTE, sizeof(debug_buf), debug_buf );
87#endif
88 crError( "Barrier name=%u created with count=%u, but already "
89 "exists with count=%u", name, count, barrier->count );
90 }
91 }
92
93 if (cr_server.debug_barriers)
94 crDebug("crserver: BarrierCreate(id=%d, count=%d)", name, barrier->count);
95}
96
97void SERVER_DISPATCH_APIENTRY crServerDispatchBarrierDestroyCR( GLuint name )
98{
99 if (cr_server.ignore_papi)
100 {
101 cr_server.head_spu->dispatch_table.BarrierDestroyCR( name );
102 return;
103 }
104
105 crError( "NO BARRIER DESTROY FOR YOU! (name=%u)", name );
106}
107
108void SERVER_DISPATCH_APIENTRY crServerDispatchBarrierExecCR( GLuint name )
109{
110 CRServerBarrier *barrier;
111#if DEBUG_BARRIERS
112 char debug_buf[4096];
113#endif
114
115 if (cr_server.ignore_papi)
116 {
117 cr_server.head_spu->dispatch_table.BarrierExecCR( name );
118 return;
119 }
120
121 barrier = (CRServerBarrier *) crHashtableSearch( cr_server.barriers, name );
122 if ( barrier == NULL )
123 {
124 crError( "crServerDispatchBarrierExec: No such barrier: %d", name );
125 }
126
127#if DEBUG_BARRIERS
128 sprintf( debug_buf, "BarrierExec( %d )", name );
129 cr_server.head_spu->dispatch_table.ChromiumParametervCR( GL_PRINT_STRING_CR, GL_UNSIGNED_BYTE, sizeof(debug_buf), debug_buf );
130 sprintf( debug_buf, "num_waiting = %d", barrier->num_waiting );
131 cr_server.head_spu->dispatch_table.ChromiumParametervCR( GL_PRINT_STRING_CR, GL_UNSIGNED_BYTE, sizeof(debug_buf), debug_buf );
132#endif
133
134 barrier->waiting[barrier->num_waiting++] = cr_server.run_queue;
135
136 cr_server.run_queue->blocked = 1;
137
138 if ( barrier->num_waiting == barrier->count )
139 {
140 GLuint i;
141
142 if (cr_server.debug_barriers)
143 crDebug("crserver: BarrierExec(client=%p, id=%d, num_waiting=%d/%d) - release",
144 cr_server.curClient, name, barrier->num_waiting,
145 barrier->count);
146
147 for ( i = 0; i < barrier->count; i++ )
148 {
149 barrier->waiting[i]->blocked = 0;
150 }
151 barrier->num_waiting = 0;
152 }
153 else if (cr_server.debug_barriers)
154 crDebug("crserver: BarrierExec(client=%p, id=%d, num_waiting=%d/%d) - block",
155 cr_server.curClient, name, barrier->num_waiting,
156 barrier->count);
157
158}
159
160void SERVER_DISPATCH_APIENTRY crServerDispatchSemaphoreCreateCR( GLuint name, GLuint count )
161{
162 CRServerSemaphore *sema;
163
164 if (cr_server.ignore_papi)
165 {
166 cr_server.head_spu->dispatch_table.SemaphoreCreateCR( name, count );
167 return;
168 }
169
170 sema = (CRServerSemaphore *)crHashtableSearch(cr_server.semaphores, name);
171 if (sema)
172 return; /* already created */
173
174 sema = (CRServerSemaphore *) crAlloc( sizeof( *sema ) );
175 crHashtableAdd( cr_server.semaphores, name, sema );
176 sema->count = count;
177 sema->waiting = sema->tail = NULL;
178 if (cr_server.debug_barriers)
179 crDebug("crserver: SemaphoreCreate(id=%d, count=%d)", name, count);
180}
181
182void SERVER_DISPATCH_APIENTRY crServerDispatchSemaphoreDestroyCR( GLuint name )
183{
184 if (cr_server.ignore_papi)
185 {
186 cr_server.head_spu->dispatch_table.SemaphoreDestroyCR( name );
187 return;
188 }
189
190 crError( "NO DESTROY FOR YOU! (name=%u)", name );
191}
192
193/* Semaphore wait */
194void SERVER_DISPATCH_APIENTRY crServerDispatchSemaphorePCR( GLuint name )
195{
196 CRServerSemaphore *sema;
197
198 if (cr_server.ignore_papi)
199 {
200 cr_server.head_spu->dispatch_table.SemaphorePCR( name );
201 return;
202 }
203
204 sema = (CRServerSemaphore *) crHashtableSearch( cr_server.semaphores, name );
205 if (!sema)
206 {
207 crError( "No such semaphore: %d", name );
208 }
209 if (sema->count)
210 {
211 /* go */
212 if (cr_server.debug_barriers)
213 crDebug("crserver: SemaphoreP(client=%p, id=%d, count=%d) decrement to %d",
214 cr_server.curClient, name, sema->count, sema->count - 1);
215 sema->count--;
216 }
217 else
218 {
219 /* block */
220 wqnode *node;
221 if (cr_server.debug_barriers)
222 crDebug("crserver: SemaphoreP(client=%p, id=%d, count=%d) - block.",
223 cr_server.curClient, name, sema->count);
224 cr_server.run_queue->blocked = 1;
225 node = (wqnode *) crAlloc( sizeof( *node ) );
226 node->q = cr_server.run_queue;
227 node->next = NULL;
228 if (sema->tail)
229 {
230 sema->tail->next = node;
231 }
232 else
233 {
234 sema->waiting = node;
235 }
236 sema->tail = node;
237 }
238}
239
240/* Semaphore signal */
241void SERVER_DISPATCH_APIENTRY crServerDispatchSemaphoreVCR( GLuint name )
242{
243 CRServerSemaphore *sema;
244
245 if (cr_server.ignore_papi)
246 {
247 cr_server.head_spu->dispatch_table.SemaphoreVCR( name );
248 return;
249 }
250
251 sema = (CRServerSemaphore *) crHashtableSearch( cr_server.semaphores, name );
252 if (!sema)
253 {
254 crError( "No such semaphore: %d", name );
255 }
256 if (sema->waiting)
257 {
258 wqnode *temp = sema->waiting;
259 if (cr_server.debug_barriers)
260 crDebug("crserver: SemaphoreV(client=%p, id=%d, count=%d) - unblock.",
261 cr_server.curClient, name, sema->count);
262 /* unblock one waiter */
263 temp->q->blocked = 0;
264 sema->waiting = temp->next;
265 crFree( temp );
266 if (!sema->waiting)
267 {
268 sema->tail = NULL;
269 }
270 }
271 else
272 {
273 /* nobody's waiting */
274 if (cr_server.debug_barriers)
275 crDebug("crserver: SemaphoreV(client=%p, id=%d, count=%d) - increment to %d",
276 cr_server.curClient, name, sema->count, sema->count + 1);
277 sema->count++;
278 }
279}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette