Changeset 41128 in vbox for trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_snapshot.c
- Timestamp:
- May 3, 2012 8:19:54 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/GuestHost/OpenGL/state_tracker/state_snapshot.c
r41057 r41128 62 62 } 63 63 64 #define SHCROGL_GET_STRUCT_PART(_pPtr, _type, _from, _to) do { \ 65 rc = SSMR3GetMem(pSSM, &(_pPtr)->_from, RT_OFFSETOF(_type, _to) - RT_OFFSETOF(_type, _from)); \ 66 AssertRCReturn(rc, rc); \ 67 } while (0) 68 69 #define SHCROGL_GET_STRUCT_TAIL(_pPtr, _type, _from) do { \ 70 rc = SSMR3GetMem(pSSM, &(_pPtr)->_from, sizeof (_type) - RT_OFFSETOF(_type, _from)); \ 71 AssertRCReturn(rc, rc); \ 72 } while (0) 73 74 #define SHCROGL_GET_STRUCT_HEAD(_pPtr, _type, _to) do { \ 75 rc = SSMR3GetMem(pSSM, (_pPtr), RT_OFFSETOF(_type, _to)); \ 76 AssertRCReturn(rc, rc); \ 77 } while (0) 78 79 #define SHCROGL_CUT_FIELD_ALIGNMENT_SIZE(_type, _prevField, _field) (RT_OFFSETOF(_type, _field) - RT_OFFSETOF(_type, _prevField) - RT_SIZEOFMEMB(_type, _prevField)) 80 #define SHCROGL_CUT_FIELD_ALIGNMENT(_type, _prevField, _field) do { \ 81 const int32_t cbAlignment = SHCROGL_CUT_FIELD_ALIGNMENT_SIZE(_type, _prevField, _field) ; \ 82 AssertCompile(SHCROGL_CUT_FIELD_ALIGNMENT_SIZE(_type, _prevField, _field) >= 0 && SHCROGL_CUT_FIELD_ALIGNMENT_SIZE(_type, _prevField, _field) < sizeof (void*)); \ 83 if (cbAlignment) { \ 84 void *Tmp; \ 85 rc = SSMR3GetMem(pSSM, &Tmp, cbAlignment); \ 86 } \ 87 } while (0) 88 89 #define SHCROGL_CUT_TAIL_ALIGNMENT_SIZE(_type, _lastField) (sizeof (_type) - RT_OFFSETOF(_type, _lastField) - RT_SIZEOFMEMB(_type, _lastField)) 90 #define SHCROGL_CUT_TAIL_ALIGNMENT(_type, _lastField) do { \ 91 const int32_t cbAlignment = SHCROGL_CUT_TAIL_ALIGNMENT_SIZE(_type, _lastField); \ 92 AssertCompile(SHCROGL_CUT_TAIL_ALIGNMENT_SIZE(_type, _lastField) >= 0 && SHCROGL_CUT_TAIL_ALIGNMENT_SIZE(_type, _lastField) < sizeof (void*)); \ 93 if (cbAlignment) { \ 94 void *Tmp; \ 95 rc = SSMR3GetMem(pSSM, &Tmp, cbAlignment); \ 96 } \ 97 } while (0) 98 99 static int32_t crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(CRTextureObj *pTexture, PSSMHANDLE pSSM) 100 { 101 int32_t rc; 102 uint32_t cbObj = RT_OFFSETOF(CRTextureObj, ctxUsage); 103 cbObj = ((cbObj + sizeof (void*) - 1) & ~(sizeof (void*) - 1)); 104 rc = SSMR3GetMem(pSSM, pTexture, cbObj); 105 AssertRCReturn(rc, rc); 106 /* just make all bits are used so that we fall back to the pre-ctxUsage behavior, 107 * i.e. all shared resources will be destructed on last shared context termination */ 108 FILLDIRTY(pTexture->ctxUsage); 109 return rc; 110 } 111 112 static int32_t crStateLoadTextureUnit_v_BEFORE_CTXUSAGE_BITS(CRTextureUnit *t, PSSMHANDLE pSSM) 113 { 114 int32_t rc; 115 SHCROGL_GET_STRUCT_HEAD(t, CRTextureUnit, Saved1D); 116 rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->Saved1D, pSSM); 117 AssertRCReturn(rc, rc); 118 SHCROGL_CUT_FIELD_ALIGNMENT(CRTextureUnit, Saved1D, Saved2D); 119 rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->Saved2D, pSSM); 120 AssertRCReturn(rc, rc); 121 SHCROGL_CUT_FIELD_ALIGNMENT(CRTextureUnit, Saved2D, Saved3D); 122 rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->Saved3D, pSSM); 123 AssertRCReturn(rc, rc); 124 #ifdef CR_ARB_texture_cube_map 125 SHCROGL_CUT_FIELD_ALIGNMENT(CRTextureUnit, Saved3D, SavedCubeMap); 126 rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->SavedCubeMap, pSSM); 127 AssertRCReturn(rc, rc); 128 # define SHCROGL_INTERNAL_LAST_FIELD SavedCubeMap 129 #else 130 # define SHCROGL_INTERNAL_LAST_FIELD Saved3D 131 #endif 132 #ifdef CR_NV_texture_rectangle 133 SHCROGL_CUT_FIELD_ALIGNMENT(CRTextureUnit, SHCROGL_INTERNAL_LAST_FIELD, SavedRect); 134 rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->SavedRect, pSSM); 135 AssertRCReturn(rc, rc); 136 # undef SHCROGL_INTERNAL_LAST_FIELD 137 # define SHCROGL_INTERNAL_LAST_FIELD SavedRect 138 #endif 139 SHCROGL_CUT_TAIL_ALIGNMENT(CRTextureUnit, SHCROGL_INTERNAL_LAST_FIELD); 140 #undef SHCROGL_INTERNAL_LAST_FIELD 141 return rc; 142 } 143 144 static int32_t crStateLoadTextureState_v_BEFORE_CTXUSAGE_BITS(CRTextureState *t, PSSMHANDLE pSSM) 145 { 146 GLint i; 147 int32_t rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->base1D, pSSM); 148 AssertRCReturn(rc, rc); 149 SHCROGL_CUT_FIELD_ALIGNMENT(CRTextureState, base1D, base2D); 150 rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->base2D, pSSM); 151 AssertRCReturn(rc, rc); 152 rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->base3D, pSSM); 153 SHCROGL_CUT_FIELD_ALIGNMENT(CRTextureState, base2D, base3D); 154 AssertRCReturn(rc, rc); 155 #ifdef CR_ARB_texture_cube_map 156 SHCROGL_CUT_FIELD_ALIGNMENT(CRTextureState, base3D, baseCubeMap); 157 rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->baseCubeMap, pSSM); 158 AssertRCReturn(rc, rc); 159 # define SHCROGL_INTERNAL_LAST_FIELD baseCubeMap 160 #else 161 # define SHCROGL_INTERNAL_LAST_FIELD base3D 162 #endif 163 #ifdef CR_NV_texture_rectangle 164 SHCROGL_CUT_FIELD_ALIGNMENT(CRTextureState, SHCROGL_INTERNAL_LAST_FIELD, baseRect); 165 rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->baseRect, pSSM); 166 AssertRCReturn(rc, rc); 167 # undef SHCROGL_INTERNAL_LAST_FIELD 168 # define SHCROGL_INTERNAL_LAST_FIELD baseRect 169 #endif 170 SHCROGL_CUT_FIELD_ALIGNMENT(CRTextureState, SHCROGL_INTERNAL_LAST_FIELD, proxy1D); 171 rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->proxy1D, pSSM); 172 AssertRCReturn(rc, rc); 173 #undef SHCROGL_INTERNAL_LAST_FIELD 174 SHCROGL_CUT_FIELD_ALIGNMENT(CRTextureState, proxy1D, proxy2D); 175 rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->proxy2D, pSSM); 176 AssertRCReturn(rc, rc); 177 SHCROGL_CUT_FIELD_ALIGNMENT(CRTextureState, proxy2D, proxy3D); 178 rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->proxy3D, pSSM); 179 AssertRCReturn(rc, rc); 180 #ifdef CR_ARB_texture_cube_map 181 SHCROGL_CUT_FIELD_ALIGNMENT(CRTextureState, proxy3D, proxyCubeMap); 182 rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->proxyCubeMap, pSSM); 183 AssertRCReturn(rc, rc); 184 # define SHCROGL_INTERNAL_LAST_FIELD proxyCubeMap 185 #else 186 # define SHCROGL_INTERNAL_LAST_FIELD proxy3D 187 #endif 188 #ifdef CR_NV_texture_rectangle 189 SHCROGL_CUT_FIELD_ALIGNMENT(CRTextureState, SHCROGL_INTERNAL_LAST_FIELD, proxyRect); 190 rc = crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(&t->proxyRect, pSSM); 191 AssertRCReturn(rc, rc); 192 # undef SHCROGL_INTERNAL_LAST_FIELD 193 # define SHCROGL_INTERNAL_LAST_FIELD proxyRect 194 #endif 195 SHCROGL_CUT_FIELD_ALIGNMENT(CRTextureState, SHCROGL_INTERNAL_LAST_FIELD, curTextureUnit); 196 # undef SHCROGL_INTERNAL_LAST_FIELD 197 SHCROGL_GET_STRUCT_PART(t, CRTextureState, curTextureUnit, unit); 198 199 for (i = 0; i < CR_MAX_TEXTURE_UNITS; ++i) 200 { 201 rc = crStateLoadTextureUnit_v_BEFORE_CTXUSAGE_BITS(&t->unit[i], pSSM); 202 AssertRCReturn(rc, rc); 203 } 204 205 SHCROGL_CUT_TAIL_ALIGNMENT(CRTextureState, unit); 206 207 return rc; 208 } 209 210 static int32_t crStateLoadTextureStack_v_BEFORE_CTXUSAGE_BITS(CRTextureStack *t, PSSMHANDLE pSSM) 211 { 212 int32_t i, rc; 213 SHCROGL_GET_STRUCT_HEAD(t, CRTextureStack, unit); 214 for (i = 0; i < CR_MAX_TEXTURE_UNITS; ++i) 215 { 216 rc = crStateLoadTextureUnit_v_BEFORE_CTXUSAGE_BITS(&t->unit[i], pSSM); 217 AssertRCReturn(rc, rc); 218 } 219 SHCROGL_CUT_TAIL_ALIGNMENT(CRTextureStack, unit); 220 return rc; 221 } 222 223 static int32_t crStateLoadAttribState_v_BEFORE_CTXUSAGE_BITS(CRAttribState *t, PSSMHANDLE pSSM) 224 { 225 int32_t i, rc; 226 SHCROGL_GET_STRUCT_HEAD(t, CRAttribState, textureStack); 227 for (i = 0; i < CR_MAX_ATTRIB_STACK_DEPTH; ++i) 228 { 229 rc = crStateLoadTextureStack_v_BEFORE_CTXUSAGE_BITS(&t->textureStack[i], pSSM); 230 AssertRCReturn(rc, rc); 231 } 232 SHCROGL_GET_STRUCT_TAIL(t, CRAttribState, transformStackDepth); 233 return rc; 234 } 235 236 237 static int32_t crStateLoadTextureObj(CRTextureObj *pTexture, PSSMHANDLE pSSM, uint32_t u32Version) 238 { 239 int32_t rc; 240 if (u32Version == SHCROGL_SSM_VERSION_BEFORE_CTXUSAGE_BITS) 241 return crStateLoadTextureObj_v_BEFORE_CTXUSAGE_BITS(pTexture, pSSM); 242 rc = SSMR3GetMem(pSSM, pTexture, sizeof (*pTexture)); 243 AssertRCReturn(rc, rc); 244 return rc; 245 } 246 247 static int32_t crStateLoadBufferObject(CRBufferObject *pBufferObj, PSSMHANDLE pSSM, uint32_t u32Version) 248 { 249 int32_t rc; 250 if (u32Version == SHCROGL_SSM_VERSION_BEFORE_CTXUSAGE_BITS) 251 { 252 uint32_t cbObj = RT_OFFSETOF(CRBufferObject, ctxUsage); 253 cbObj = ((cbObj + sizeof (void*) - 1) & ~(sizeof (void*) - 1)); 254 rc = SSMR3GetMem(pSSM, pBufferObj, cbObj); 255 AssertRCReturn(rc, rc); 256 /* just make all bits are used so that we fall back to the pre-ctxUsage behavior, 257 * i.e. all shared resources will be destructed on last shared context termination */ 258 FILLDIRTY(pBufferObj->ctxUsage); 259 } 260 else 261 { 262 rc = SSMR3GetMem(pSSM, pBufferObj, sizeof(*pBufferObj)); 263 AssertRCReturn(rc, rc); 264 } 265 return rc; 266 } 267 268 static int32_t crStateLoadFramebufferObject(CRFramebufferObject *pFBO, PSSMHANDLE pSSM, uint32_t u32Version) 269 { 270 int32_t rc; 271 if (u32Version == SHCROGL_SSM_VERSION_BEFORE_CTXUSAGE_BITS) 272 { 273 uint32_t cbObj = RT_OFFSETOF(CRFramebufferObject, ctxUsage); 274 cbObj = ((cbObj + sizeof (void*) - 1) & ~(sizeof (void*) - 1)); 275 rc = SSMR3GetMem(pSSM, pFBO, cbObj); 276 AssertRCReturn(rc, rc); 277 /* just make all bits are used so that we fall back to the pre-ctxUsage behavior, 278 * i.e. all shared resources will be destructed on last shared context termination */ 279 FILLDIRTY(pFBO->ctxUsage); 280 } 281 else 282 { 283 rc = SSMR3GetMem(pSSM, pFBO, sizeof(*pFBO)); 284 AssertRCReturn(rc, rc); 285 } 286 return rc; 287 } 288 289 static int32_t crStateLoadRenderbufferObject(CRRenderbufferObject *pRBO, PSSMHANDLE pSSM, uint32_t u32Version) 290 { 291 int32_t rc; 292 if (u32Version == SHCROGL_SSM_VERSION_BEFORE_CTXUSAGE_BITS) 293 { 294 uint32_t cbObj = RT_OFFSETOF(CRRenderbufferObject, ctxUsage); 295 cbObj = ((cbObj + sizeof (void*) - 1) & ~(sizeof (void*) - 1)); 296 rc = SSMR3GetMem(pSSM, pRBO, cbObj); 297 AssertRCReturn(rc, rc); 298 /* just make all bits are used so that we fall back to the pre-ctxUsage behavior, 299 * i.e. all shared resources will be destructed on last shared context termination */ 300 FILLDIRTY(pRBO->ctxUsage); 301 } 302 else 303 { 304 rc = SSMR3GetMem(pSSM, pRBO, sizeof(*pRBO)); 305 AssertRCReturn(rc, rc); 306 } 307 return rc; 308 } 309 64 310 static int32_t crStateSaveTextureObjData(CRTextureObj *pTexture, PSSMHANDLE pSSM) 65 311 { … … 1404 1650 AssertCompile(RT_OFFSETOF(CRContext, shared) >= VBOXTLSREFDATA_OFFSET(CRContext) + VBOXTLSREFDATA_SIZE() + RT_SIZEOFMEMB(CRContext, bitid) + RT_SIZEOFMEMB(CRContext, neg_bitid)); 1405 1651 1406 int32_t crStateLoadContext(CRContext *pContext, CRHashTable * pCtxTable, PFNCRSTATE_CONTEXT_GET pfnCtxGet, PSSMHANDLE pSSM )1652 int32_t crStateLoadContext(CRContext *pContext, CRHashTable * pCtxTable, PFNCRSTATE_CONTEXT_GET pfnCtxGet, PSSMHANDLE pSSM, uint32_t u32Version) 1407 1653 { 1408 1654 CRContext* pTmpContext; … … 1418 1664 } bitid; 1419 1665 1666 Assert(0); 1667 1420 1668 CRASSERT(pContext && pSSM); 1421 1669 … … 1474 1722 VBOXTLSREFDATA_COPY(pTmpContext, pContext); 1475 1723 1476 rc = SSMR3GetMem(pSSM, &pTmpContext->shared, sizeof (CRContext) - RT_OFFSETOF(CRContext, shared)); 1477 AssertRCReturn(rc, rc); 1724 if (u32Version == SHCROGL_SSM_VERSION_BEFORE_CTXUSAGE_BITS) 1725 { 1726 SHCROGL_GET_STRUCT_PART(pTmpContext, CRContext, shared, attrib); 1727 rc = crStateLoadAttribState_v_BEFORE_CTXUSAGE_BITS(&pTmpContext->attrib, pSSM); 1728 AssertRCReturn(rc, rc); 1729 SHCROGL_CUT_FIELD_ALIGNMENT(CRContext, attrib, buffer); 1730 SHCROGL_GET_STRUCT_PART(pTmpContext, CRContext, buffer, texture); 1731 rc = crStateLoadTextureState_v_BEFORE_CTXUSAGE_BITS(&pTmpContext->texture, pSSM); 1732 AssertRCReturn(rc, rc); 1733 SHCROGL_CUT_FIELD_ALIGNMENT(CRContext, texture, transform); 1734 SHCROGL_GET_STRUCT_TAIL(pTmpContext, CRContext, transform); 1735 } 1736 else 1737 { 1738 SHCROGL_GET_STRUCT_TAIL(pTmpContext, CRContext, shared); 1739 } 1478 1740 1479 1741 /* Deal with shared state */ … … 1720 1982 if (!pTexture) return VERR_NO_MEMORY; 1721 1983 1722 rc = SSMR3GetMem(pSSM, pTexture, sizeof(*pTexture));1984 rc = crStateLoadTextureObj(pTexture, pSSM, u32Version); 1723 1985 AssertRCReturn(rc, rc); 1724 1986 … … 1831 2093 } 1832 2094 1833 rc = SSMR3GetMem(pSSM, pBufferObj, sizeof(*pBufferObj));2095 rc = crStateLoadBufferObject(pBufferObj, pSSM, u32Version); 1834 2096 AssertRCReturn(rc, rc); 1835 2097 … … 1943 2205 AssertRCReturn(rc, rc); 1944 2206 1945 rc = SSMR3GetMem(pSSM, pFBO, sizeof(*pFBO));2207 rc = crStateLoadFramebufferObject(pFBO, pSSM, u32Version); 1946 2208 AssertRCReturn(rc, rc); 1947 2209 … … 1960 2222 AssertRCReturn(rc, rc); 1961 2223 1962 rc = SSMR3GetMem(pSSM, pRBO, sizeof(*pRBO));2224 rc = crStateLoadRenderbufferObject(pRBO, pSSM, u32Version); 1963 2225 AssertRCReturn(rc, rc); 1964 2226
Note:
See TracChangeset
for help on using the changeset viewer.