VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/include/cr_pack.h@ 78241

Last change on this file since 78241 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: 19.2 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#ifndef CR_PACK_H
8#define CR_PACK_H
9
10#include "cr_compiler.h"
11#include "cr_error.h"
12#include "cr_protocol.h"
13#include "cr_opcodes.h"
14#include "state/cr_statetypes.h"
15#include "state/cr_currentpointers.h"
16#include "state/cr_client.h"
17#ifdef CHROMIUM_THREADSAFE
18#include "cr_threads.h"
19#endif
20
21#include <iprt/types.h>
22
23#ifdef __cplusplus
24extern "C" {
25#endif
26
27typedef struct CRPackContext_t CRPackContext;
28
29/**
30 * Packer buffer
31 */
32typedef struct
33{
34 void *pack; /**< the actual storage space/buffer */
35 unsigned int size; /**< size of pack[] buffer */
36 unsigned int mtu;
37 unsigned char *data_start, *data_current, *data_end;
38 unsigned char *opcode_start, *opcode_current, *opcode_end;
39 GLboolean geometry_only; /**< just used for debugging */
40 GLboolean holds_BeginEnd;
41 GLboolean in_BeginEnd;
42 GLboolean canBarf;
43 GLboolean holds_List;
44 GLboolean in_List;
45 CRPackContext *context;
46} CRPackBuffer;
47
48typedef void (*CRPackFlushFunc)(void *arg);
49typedef void (*CRPackSendHugeFunc)(CROpcode, void *);
50typedef void (*CRPackErrorHandlerFunc)(int line, const char *file, GLenum error, const char *info);
51
52#define CRPACKBLOCKSTATE_OP_BEGIN 0x01
53#define CRPACKBLOCKSTATE_OP_NEWLIST 0x02
54#define CRPACKBLOCKSTATE_OP_BEGINQUERY 0x04
55#define CRPACKBLOCKSTATE_OP_ALL 0x07
56
57#define CRPACKBLOCKSTATE_IS_OP_STARTED(_state, _op) (!!((_state) & (_op)))
58
59#define CRPACKBLOCKSTATE_IS_STARTED(_state) (!!(_state))
60
61#define CRPACKBLOCKSTATE_OP_START(_state, _op) do { \
62 Assert(!CRPACKBLOCKSTATE_IS_OP_STARTED(_state, _op)); \
63 (_state) |= (_op); \
64 } while (0)
65
66#define CRPACKBLOCKSTATE_OP_STOP(_state, _op) do { \
67 Assert(CRPACKBLOCKSTATE_IS_OP_STARTED(_state, _op)); \
68 (_state) &= ~(_op); \
69 } while (0)
70
71/**
72 * Packer context
73 */
74struct CRPackContext_t
75{
76 CRPackBuffer buffer; /**< not a pointer, see comments in pack_buffer.c */
77 CRPackFlushFunc Flush;
78 void *flush_arg;
79 CRPackSendHugeFunc SendHuge;
80 CRPackErrorHandlerFunc Error;
81 CRCurrentStatePointers current;
82 uint32_t u32CmdBlockState;
83 GLvectorf bounds_min, bounds_max;
84 int updateBBOX;
85 CRPackBuffer *currentBuffer;
86#ifdef CHROMIUM_THREADSAFE
87 CRmutex mutex;
88#endif
89 char *file; /**< for debugging only */
90 int line; /**< for debugging only */
91};
92
93#if !defined(IN_RING0)
94# define CR_PACKER_CONTEXT_ARGSINGLEDECL void
95# define CR_PACKER_CONTEXT_ARGDECL
96# define CR_PACKER_CONTEXT_ARG
97# define CR_PACKER_CONTEXT_ARG_NOREF() do {} while (0)
98# define CR_PACKER_CONTEXT_ARGCTX(C)
99# ifdef CHROMIUM_THREADSAFE
100extern CRtsd _PackerTSD;
101# define CR_GET_PACKER_CONTEXT(C) CRPackContext *C = (CRPackContext *) crGetTSD(&_PackerTSD)
102# define CR_LOCK_PACKER_CONTEXT(PC) crLockMutex(&((PC)->mutex))
103# define CR_UNLOCK_PACKER_CONTEXT(PC) crUnlockMutex(&((PC)->mutex))
104# else
105extern DLLDATA(CRPackContext) cr_packer_globals;
106# define CR_GET_PACKER_CONTEXT(C) CRPackContext *C = &cr_packer_globals
107# define CR_LOCK_PACKER_CONTEXT(PC)
108# define CR_UNLOCK_PACKER_CONTEXT(PC)
109# endif
110extern uint32_t cr_packer_cmd_blocks_enabled;
111#else /* if defined IN_RING0 */
112# define CR_PACKER_CONTEXT_ARGSINGLEDECL CRPackContext *_pCtx
113# define CR_PACKER_CONTEXT_ARGDECL CR_PACKER_CONTEXT_ARGSINGLEDECL,
114# define CR_PACKER_CONTEXT_ARG _pCtx,
115# define CR_PACKER_CONTEXT_ARG_NOREF() RT_NOREF_PV(_pCtx)
116# define CR_PACKER_CONTEXT_ARGCTX(C) C,
117# define CR_GET_PACKER_CONTEXT(C) CRPackContext *C = _pCtx
118# define CR_LOCK_PACKER_CONTEXT(PC)
119# define CR_UNLOCK_PACKER_CONTEXT(PC)
120#endif
121
122extern DECLEXPORT(CRPackContext *) crPackNewContext(void);
123extern DECLEXPORT(void) crPackDeleteContext(CRPackContext *pc);
124extern DECLEXPORT(void) crPackSetContext( CRPackContext *pc );
125extern DECLEXPORT(CRPackContext *) crPackGetContext( void );
126
127extern DECLEXPORT(void) crPackSetBuffer( CRPackContext *pc, CRPackBuffer *buffer );
128extern DECLEXPORT(void) crPackSetBufferDEBUG( const char *file, int line, CRPackContext *pc, CRPackBuffer *buffer );
129extern DECLEXPORT(void) crPackReleaseBuffer( CRPackContext *pc );
130extern DECLEXPORT(void) crPackResetPointers( CRPackContext *pc );
131
132extern DECLEXPORT(int) crPackMaxOpcodes( int buffer_size );
133extern DECLEXPORT(int) crPackMaxData( int buffer_size );
134extern DECLEXPORT(void) crPackInitBuffer( CRPackBuffer *buffer, void *buf, int size, int mtu
135#ifdef IN_RING0
136 , unsigned int num_opcodes
137#endif
138 );
139
140extern DECLEXPORT(void) crPackFlushFunc( CRPackContext *pc, CRPackFlushFunc ff );
141extern DECLEXPORT(void) crPackFlushArg( CRPackContext *pc, void *flush_arg );
142extern DECLEXPORT(void) crPackSendHugeFunc( CRPackContext *pc, CRPackSendHugeFunc shf );
143extern DECLEXPORT(void) crPackErrorFunction( CRPackContext *pc, CRPackErrorHandlerFunc errf );
144extern DECLEXPORT(void) crPackOffsetCurrentPointers( int offset );
145extern DECLEXPORT(void) crPackNullCurrentPointers( void );
146
147extern DECLEXPORT(void) crPackResetBoundingBox( CRPackContext *pc );
148extern DECLEXPORT(GLboolean) crPackGetBoundingBox( CRPackContext *pc,
149 GLfloat *xmin, GLfloat *ymin, GLfloat *zmin,
150 GLfloat *xmax, GLfloat *ymax, GLfloat *zmax);
151
152extern DECLEXPORT(void) crPackAppendBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *buffer );
153extern DECLEXPORT(void) crPackAppendBoundedBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *buffer, const CRrecti *bounds );
154extern DECLEXPORT(int) crPackCanHoldBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *buffer );
155extern DECLEXPORT(int) crPackCanHoldBoundedBuffer( CR_PACKER_CONTEXT_ARGDECL const CRPackBuffer *buffer );
156
157#if defined(LINUX) || defined(WINDOWS)
158#define CR_UNALIGNED_ACCESS_OKAY
159#else
160#undef CR_UNALIGNED_ACCESS_OKAY
161#endif
162#ifndef IN_RING0
163extern DECLEXPORT(void) crWriteUnalignedDouble( void *buffer, double d );
164#endif
165
166extern DECLEXPORT(void) *crPackAlloc( CR_PACKER_CONTEXT_ARGDECL unsigned int len );
167extern DECLEXPORT(void) crHugePacket( CR_PACKER_CONTEXT_ARGDECL CROpcode op, void *ptr );
168extern DECLEXPORT(void) crPackFree( CR_PACKER_CONTEXT_ARGDECL void *ptr );
169extern DECLEXPORT(void) crNetworkPointerWrite( CRNetworkPointer *, void * );
170
171extern DECLEXPORT(void) crPackExpandDrawArrays(GLenum mode, GLint first, GLsizei count, CRClientState *c, const GLfloat *pZva);
172extern DECLEXPORT(void) crPackExpandDrawArraysSWAP(GLenum mode, GLint first, GLsizei count, CRClientState *c, const GLfloat *pZva);
173
174extern DECLEXPORT(void) crPackUnrollDrawElements(GLsizei count, GLenum type, const GLvoid *indices);
175extern DECLEXPORT(void) crPackUnrollDrawElementsSWAP(GLsizei count, GLenum type, const GLvoid *indices);
176
177extern DECLEXPORT(void) crPackExpandDrawElements(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c, const GLfloat *pZva);
178extern DECLEXPORT(void) crPackExpandDrawElementsSWAP(GLenum mode, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c, const GLfloat *pZva);
179
180extern DECLEXPORT(void) crPackExpandDrawRangeElements(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c, const GLfloat *pZva);
181extern DECLEXPORT(void) crPackExpandDrawRangeElementsSWAP(GLenum mode, GLuint start, GLuint end, GLsizei count, GLenum type, const GLvoid *indices, CRClientState *c, const GLfloat *pZva);
182
183extern DECLEXPORT(void) crPackExpandArrayElement(GLint index, CRClientState *c, const GLfloat *pZva);
184extern DECLEXPORT(void) crPackExpandArrayElementSWAP(GLint index, CRClientState *c, const GLfloat *pZva);
185
186extern DECLEXPORT(void) crPackExpandMultiDrawArraysEXT( GLenum mode, GLint *first, GLsizei *count, GLsizei primcount, CRClientState *c, const GLfloat *pZva );
187extern DECLEXPORT(void) crPackExpandMultiDrawArraysEXTSWAP( GLenum mode, GLint *first, GLsizei *count, GLsizei primcount, CRClientState *c, const GLfloat *pZva );
188
189extern DECLEXPORT(void) crPackExpandMultiDrawElementsEXT( GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount, CRClientState *c, const GLfloat *pZva );
190extern DECLEXPORT(void) crPackExpandMultiDrawElementsEXTSWAP( GLenum mode, const GLsizei *count, GLenum type, const GLvoid **indices, GLsizei primcount, CRClientState *c, const GLfloat *pZva );
191
192extern DECLEXPORT(void) crPackCapsSet(uint32_t u32Caps);
193
194/**
195 * Return number of opcodes in given buffer.
196 */
197static INLINE int
198crPackNumOpcodes(const CRPackBuffer *buffer)
199{
200 CRASSERT(buffer->opcode_start - buffer->opcode_current >= 0);
201 return buffer->opcode_start - buffer->opcode_current;
202}
203
204DECLINLINE(bool) crPackBufferIsEmpty(CRPackBuffer *buffer)
205{
206 return crPackNumOpcodes(buffer) == 0;
207}
208
209/**
210 * Return amount of data (in bytes) in buffer.
211 */
212static INLINE int
213crPackNumData(const CRPackBuffer *buffer)
214{
215 CRASSERT(buffer->data_current - buffer->data_start >= 0);
216 return buffer->data_current - buffer->data_start; /* in bytes */
217}
218
219
220static INLINE int
221crPackCanHoldOpcode(const CRPackContext *pc, int num_opcode, int num_data)
222{
223 int fitsInMTU, opcodesFit, dataFits;
224
225 CRASSERT(pc->currentBuffer);
226
227 fitsInMTU = (((pc->buffer.data_current - pc->buffer.opcode_current - 1
228 + num_opcode + num_data
229 + 0x3 ) & ~0x3) + sizeof(CRMessageOpcodes)
230 <= pc->buffer.mtu);
231 opcodesFit = (pc->buffer.opcode_current - num_opcode >= pc->buffer.opcode_end);
232 dataFits = (pc->buffer.data_current + num_data <= pc->buffer.data_end);
233
234 return fitsInMTU && opcodesFit && dataFits;
235}
236
237
238#define CR_PACK_SPECIAL_OP( _pc, _op) \
239 do { \
240 data_ptr = pc->buffer.data_current; \
241 (_pc)->buffer.data_current += 4; \
242 WRITE_OPCODE( (_pc), (_op) ); \
243 WRITE_DATA( 0, GLuint, 0xdeadbeef ); \
244 data_ptr = NULL; /* <- sanity*/ \
245 } while (0)
246
247#define CR_CMDBLOCK_OP( _pc, _op) \
248 do { \
249 CR_PACK_SPECIAL_OP( _pc, _op); \
250 } while (0)
251
252#define CR_CMDBLOCK_IS_STARTED( pc, op ) CRPACKBLOCKSTATE_IS_OP_STARTED((pc)->u32CmdBlockState, op)
253
254#define CR_CMDBLOCK_BEGIN( pc, op ) \
255 do { \
256 CR_LOCK_PACKER_CONTEXT(pc); \
257 if (!cr_packer_cmd_blocks_enabled) break; \
258 if (!CRPACKBLOCKSTATE_IS_STARTED((pc)->u32CmdBlockState)) { \
259 THREADASSERT( pc ); \
260 CRASSERT( (pc)->currentBuffer ); \
261 if (!crPackBufferIsEmpty(&(pc)->buffer)) { \
262 if ((*(pc)->buffer.opcode_start) != CR_NOP_OPCODE) { \
263 (pc)->Flush( (pc)->flush_arg ); \
264 Assert(crPackCanHoldOpcode( (pc), 1, 4 ) ); \
265 CR_CMDBLOCK_OP( (pc), CR_CMDBLOCKBEGIN_OPCODE ); \
266 } \
267 else { \
268 (*(pc)->buffer.opcode_start) = CR_CMDBLOCKBEGIN_OPCODE; \
269 } \
270 } \
271 else { \
272 Assert(crPackCanHoldOpcode( (pc), 1, 4 ) ); \
273 CR_CMDBLOCK_OP( (pc), CR_CMDBLOCKBEGIN_OPCODE ); \
274 } \
275 } \
276 Assert(!CRPACKBLOCKSTATE_IS_OP_STARTED((pc)->u32CmdBlockState, op)); \
277 CRPACKBLOCKSTATE_OP_START((pc)->u32CmdBlockState, op); \
278 Assert(CRPACKBLOCKSTATE_IS_OP_STARTED((pc)->u32CmdBlockState, op)); \
279 } while (0)
280
281#define CR_CMDBLOCK_END( pc, op ) \
282 do { \
283 if (!cr_packer_cmd_blocks_enabled) break; \
284 Assert(CRPACKBLOCKSTATE_IS_OP_STARTED((pc)->u32CmdBlockState, op)); \
285 CRPACKBLOCKSTATE_OP_STOP((pc)->u32CmdBlockState, op); \
286 Assert(!CRPACKBLOCKSTATE_IS_OP_STARTED((pc)->u32CmdBlockState, op)); \
287 if (!CRPACKBLOCKSTATE_IS_STARTED((pc)->u32CmdBlockState)) { \
288 THREADASSERT( pc ); \
289 CRASSERT( (pc)->currentBuffer ); \
290 if (!crPackBufferIsEmpty(&(pc)->buffer)) { \
291 if ((*(pc)->buffer.opcode_start) != CR_CMDBLOCKBEGIN_OPCODE) {\
292 if ( !crPackCanHoldOpcode( pc, 1, 4 ) ) { \
293 (pc)->Flush( (pc)->flush_arg ); \
294 Assert(crPackCanHoldOpcode( pc, 1, 4 ) ); \
295 } \
296 CR_CMDBLOCK_OP( pc, CR_CMDBLOCKEND_OPCODE ); \
297 (pc)->Flush( (pc)->flush_arg ); \
298 } \
299 else { \
300 (*(pc)->buffer.opcode_start) = CR_NOP_OPCODE; \
301 } \
302 } \
303 else { \
304 Assert(crPackCanHoldOpcode( pc, 1, 4 ) ); \
305 CR_CMDBLOCK_OP( pc, CR_CMDBLOCKEND_OPCODE ); \
306 (pc)->Flush( pc->flush_arg ); \
307 } \
308 } \
309 } while (0)
310
311#define CR_CMDBLOCK_CHECK_FLUSH( pc ) \
312 do { \
313 if (!(cr_packer_cmd_blocks_enabled & CR_VBOX_CAP_CMDBLOCKS_FLUSH)) break; \
314 if(!CRPACKBLOCKSTATE_IS_OP_STARTED((pc)->u32CmdBlockState, CRPACKBLOCKSTATE_OP_NEWLIST)) break; \
315 THREADASSERT( pc ); \
316 CRASSERT( (pc)->currentBuffer ); \
317 if ( !crPackCanHoldOpcode( pc, 1, 4 ) ) { \
318 (pc)->Flush( (pc)->flush_arg ); \
319 Assert(crPackCanHoldOpcode( pc, 1, 4 ) ); \
320 } \
321 CR_CMDBLOCK_OP( pc, CR_CMDBLOCKFLUSH_OPCODE ); \
322 (pc)->Flush( (pc)->flush_arg ); \
323 } while (0)
324
325/**
326 * Alloc space for a message of 'len' bytes (plus 1 opcode).
327 * Only flush if buffer is full.
328 */
329#define CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH(pc, len, lock) \
330 do { \
331 THREADASSERT( pc ); \
332 if (lock) CR_LOCK_PACKER_CONTEXT(pc); \
333 CRASSERT( pc->currentBuffer ); \
334 if ( !crPackCanHoldOpcode( pc, 1, (len) ) ) { \
335 pc->Flush( pc->flush_arg ); \
336 CRASSERT(crPackCanHoldOpcode( pc, 1, (len) ) ); \
337 } \
338 data_ptr = pc->buffer.data_current; \
339 pc->buffer.data_current += (len); \
340 } while (0)
341
342/**
343 * As above, flush if the buffer contains vertex data and we're
344 * no longer inside glBegin/glEnd.
345 */
346#define CR_GET_BUFFERED_POINTER( pc, len ) \
347 do { \
348 CR_LOCK_PACKER_CONTEXT(pc); \
349 CRASSERT( pc->currentBuffer ); \
350 if ( pc->buffer.holds_BeginEnd && !pc->buffer.in_BeginEnd ) { \
351 CRASSERT( 0 ); /* should never be here currently */ \
352 pc->Flush( pc->flush_arg ); \
353 pc->buffer.holds_BeginEnd = 0; \
354 } \
355 CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, len, GL_FALSE ); \
356 } while (0)
357
358/**
359 * As above, but without lock.
360 */
361#define CR_GET_BUFFERED_POINTER_NOLOCK( pc, len ) \
362 do { \
363 CRASSERT( pc->currentBuffer ); \
364 if ( pc->buffer.holds_BeginEnd && !pc->buffer.in_BeginEnd ) { \
365 CRASSERT( 0 ); /* should never be here currently */ \
366 pc->Flush( pc->flush_arg ); \
367 pc->buffer.holds_BeginEnd = 0; \
368 } \
369 CR_GET_BUFFERED_POINTER_NO_BEGINEND_FLUSH( pc, len, GL_FALSE ); \
370 } while (0)
371
372
373/**
374 * As above, but for vertex data between glBegin/End (counts vertices).
375 */
376#define CR_GET_BUFFERED_COUNT_POINTER( pc, len ) \
377 do { \
378 CR_LOCK_PACKER_CONTEXT(pc); \
379 CRASSERT( pc->currentBuffer ); \
380 if ( !crPackCanHoldOpcode( pc, 1, (len) ) ) { \
381 pc->Flush( pc->flush_arg ); \
382 CRASSERT( crPackCanHoldOpcode( pc, 1, (len) ) ); \
383 } \
384 data_ptr = pc->buffer.data_current; \
385 pc->current.vtx_count++; \
386 pc->buffer.data_current += (len); \
387 } while (0)
388
389
390/**
391 * Allocate space for a msg/command that has no arguments, such
392 * as glFinish().
393 */
394#define CR_GET_BUFFERED_POINTER_NO_ARGS( pc ) \
395 CR_GET_BUFFERED_POINTER( pc, 4 ); \
396 WRITE_DATA( 0, GLuint, 0xdeadbeef )
397
398#define WRITE_DATA( offset, type, data ) \
399 *( (type *) (data_ptr + (offset))) = (data)
400
401/* Write data to current location and auto increment */
402#define WRITE_DATA_AI(type, data) \
403 { \
404 *((type*) (data_ptr)) = (data); \
405 data_ptr += sizeof(type); \
406 }
407
408#ifdef CR_UNALIGNED_ACCESS_OKAY
409#define WRITE_DOUBLE( offset, data ) \
410 WRITE_DATA( offset, GLdouble, data )
411#else
412# ifndef IN_RING0
413# define WRITE_DOUBLE( offset, data ) \
414 crWriteUnalignedDouble( data_ptr + (offset), (data) )
415# else
416# define WRITE_DOUBLE( offset, data ) \
417 AssertReleaseFailed()
418# endif
419#endif
420
421#ifndef IN_RING0
422#define WRITE_SWAPPED_DOUBLE( offset, data ) \
423 crWriteSwappedDouble( data_ptr + (offset), (data) )
424#else
425#define WRITE_SWAPPED_DOUBLE( offset, data ) \
426 AssertReleaseFailed()
427#endif
428
429#define WRITE_OPCODE( pc, opcode ) \
430 *(pc->buffer.opcode_current--) = (unsigned char) opcode
431
432#define WRITE_NETWORK_POINTER( offset, data ) \
433 crNetworkPointerWrite( (CRNetworkPointer *) ( data_ptr + (offset) ), (data) )
434
435#ifdef __cplusplus
436}
437#endif
438
439#endif /* CR_PACK_H */
Note: See TracBrowser for help on using the repository browser.

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