VirtualBox

Ignore:
Timestamp:
Jul 15, 2015 4:58:56 PM (10 years ago)
Author:
vboxsync
Message:

Host 3D: Display Lists: new implementation for glCallLists(); take into account list base for both glCallList() and glCallLists().

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostServices/SharedOpenGL/dlm/dlm_lists.c

    r56922 r56942  
    258258            crDLMCompileCallList(list);
    259259
    260         /* Find hwid for list. */
    261         listInfo = (DLMListInfo *)crHashtableSearch(listState->dlm->displayLists, list);
     260        /* Find hwid for list.
     261         * We need to take into account listBase:
     262         * - displayLists hash table contains absolute IDs, so we need to add offset in order to resolve guest ID;
     263         * - we also need to substract from hwid in order to execute correct list. */
     264        listInfo = (DLMListInfo *)crHashtableSearch(listState->dlm->displayLists, list + listState->listBase);
    262265        if (listInfo)
    263             dispatchTable->CallList(listInfo->hwid);
     266            dispatchTable->CallList(listInfo->hwid - listState->listBase);
    264267        else
    265268            crDebug("DLM: CallList(%u) issued for non-existent list.", list);
     
    270273
    271274
    272 /* Helper for crDLMCallLists().
    273  * We need to extract list ID by index from array of given type and cast it to GLuint.
    274  * Please replece it w/ something more elegant if better solution will be found!
    275  */
    276 inline GLuint crDLMGetListByIndex(const GLvoid *aValues, GLsizei index, GLenum type)
    277 {
    278     GLuint element = 0;
     275/* This routine translates guest Display List IDs in given format to host IDs.
     276 * It is based on TranslateListIDs() function from crserverlib/server_lists.c. */
     277static bool
     278crDLMConvertListIDs(CRDLMContextState *pListState, GLsizei n, GLenum type, const GLvoid *aGuest, GLuint *aHost)
     279{
     280#define CRDLM_HANDLE_CONVERSION_CASE(_type, _item) \
     281    { \
     282        const _type *src = (const _type *)aGuest; \
     283        for (i = 0; i < n; i++) \
     284        { \
     285            GLuint idGuest = (GLuint)(_item) + pListState->listBase; \
     286            pListInfo = (DLMListInfo *)crHashtableSearch(pListState->dlm->displayLists, idGuest); \
     287            if (pListInfo) \
     288            { \
     289                aHost[i] = pListInfo->hwid - pListState->listBase; \
     290            } \
     291            else \
     292            { \
     293                crDebug("DLM: CallLists() cannot resolve host list ID for guest ID %u.", idGuest); \
     294                fSuccess = false; \
     295                break; \
     296            } \
     297        } \
     298    }
     299
     300    GLsizei      i;
     301    DLMListInfo *pListInfo;
     302    bool         fSuccess = true;
    279303
    280304    switch (type)
    281305    {
    282 #define CRDLM_LIST_BY_INDEX_HANDLE_TYPE(_type_name, _size_of_type) \
    283         case _type_name: \
    284         { \
    285             crMemcpy((void *)&element, (void *)((void *)(aValues) + (index * (_size_of_type))) \
    286             , (_size_of_type)); \
    287             break; \
    288         }
    289 
    290         CRDLM_LIST_BY_INDEX_HANDLE_TYPE(GL_BYTE,            sizeof(GLbyte));
    291         CRDLM_LIST_BY_INDEX_HANDLE_TYPE(GL_UNSIGNED_BYTE,   sizeof(GLubyte));
    292         CRDLM_LIST_BY_INDEX_HANDLE_TYPE(GL_SHORT,           sizeof(GLshort));
    293         CRDLM_LIST_BY_INDEX_HANDLE_TYPE(GL_UNSIGNED_SHORT,  sizeof(GLushort));
    294         CRDLM_LIST_BY_INDEX_HANDLE_TYPE(GL_INT,             sizeof(GLint));
    295         CRDLM_LIST_BY_INDEX_HANDLE_TYPE(GL_UNSIGNED_INT,    sizeof(GLuint));
    296         CRDLM_LIST_BY_INDEX_HANDLE_TYPE(GL_FLOAT,           sizeof(GLfloat));
    297         CRDLM_LIST_BY_INDEX_HANDLE_TYPE(GL_2_BYTES,         2);
    298         CRDLM_LIST_BY_INDEX_HANDLE_TYPE(GL_3_BYTES,         3);
    299         CRDLM_LIST_BY_INDEX_HANDLE_TYPE(GL_4_BYTES,         4);
     306        case GL_UNSIGNED_BYTE:  CRDLM_HANDLE_CONVERSION_CASE(GLubyte,  src[i]); break;
     307        case GL_BYTE:           CRDLM_HANDLE_CONVERSION_CASE(GLbyte,   src[i]); break;
     308        case GL_UNSIGNED_SHORT: CRDLM_HANDLE_CONVERSION_CASE(GLushort, src[i]); break;
     309        case GL_SHORT:          CRDLM_HANDLE_CONVERSION_CASE(GLshort,  src[i]); break;
     310        case GL_UNSIGNED_INT:   CRDLM_HANDLE_CONVERSION_CASE(GLuint,   src[i]); break;
     311        case GL_INT:            CRDLM_HANDLE_CONVERSION_CASE(GLint,    src[i]); break;
     312        case GL_FLOAT:          CRDLM_HANDLE_CONVERSION_CASE(GLfloat,  src[i]); break;
     313
     314        case GL_2_BYTES:
     315        {
     316            CRDLM_HANDLE_CONVERSION_CASE(GLubyte, src[i * 2 + 0] * 256 +
     317                                                  src[i * 2 + 1]);
     318            break;
     319        }
     320
     321        case GL_3_BYTES:
     322        {
     323            CRDLM_HANDLE_CONVERSION_CASE(GLubyte, src[i * 3 + 0] * 256 * 256 +
     324                                                  src[i * 3 + 1] * 256 +
     325                                                  src[i * 3 + 2]);
     326            break;
     327        }
     328
     329        case GL_4_BYTES:
     330        {
     331            CRDLM_HANDLE_CONVERSION_CASE(GLubyte, src[i * 4 + 0] * 256 * 256 * 256 +
     332                                                  src[i * 4 + 1] * 256 * 256 +
     333                                                  src[i * 4 + 2] * 256 +
     334                                                  src[i * 4 + 3]);
     335            break;
     336        }
    300337
    301338        default:
    302             crError("DLM: attempt to pass to crDLMCallLists() unknown type: %u.", index);
    303 
    304 #undef CRDLM_LIST_BY_INDEX_HANDLE_TYPE
    305     }
    306 
    307     return element;
    308 }
    309 
    310 /**
    311  * Execute lists on hardware and cach ethis call if we currently recording a list.
     339            crWarning("DLM: attempt to pass to crDLMCallLists() an unknown type: 0x%x.", type);
     340    }
     341
     342    return fSuccess;
     343#undef CRDLM_HANDLE_CONVERSION_CASE
     344}
     345
     346
     347/**
     348 * Execute lists on hardware and cache this call if we currently recording a list.
    312349 */
    313350void DLM_APIENTRY crDLMCallLists(GLsizei n, GLenum type, const GLvoid *lists, SPUDispatchTable *dispatchTable)
    314351{
    315     CRDLMContextState *listState = CURRENT_STATE();
     352    CRDLMContextState *pListState = CURRENT_STATE();
    316353
    317354    crDebug("DLM: CallLists(%d, %u, %p).", n, type, lists);
    318355
    319     if (listState)
     356    if (pListState)
    320357    {
    321358        GLsizei i;
     359        GLuint  *aHostIDs;
    322360
    323361        /* Add to calls cache if we recording a list. */
    324         if (listState->currentListInfo)
     362        if (pListState->currentListInfo)
    325363            crDLMCompileCallLists(n, type, lists);
    326364
    327         /* This is sad, but we need to translate guest IDs into host ones.
    328          * Since spec does not promise that @param lists conain contiguous set of IDs,
    329          * the only way to do that is to iterate over each guest ID and perform translation.
    330          * This might have negative performance impact. */
    331         for (i = 0; i < n; i++)
    332         {
    333             DLMListInfo *listInfo;
    334             GLuint guest_id = crDLMGetListByIndex(lists, n, type);
    335 
    336             if (guest_id > 0)
    337             {
    338                 listInfo = (DLMListInfo *)crHashtableSearch(listState->dlm->displayLists, guest_id);
    339                 if (listInfo)
    340                     dispatchTable->CallList(listInfo->hwid);
    341                 else
    342                     crDebug("DLM: CallLists(%d, %u, %p) was unabbe to resolve host ID for guest ID %u.", n, type, lists, guest_id);
    343             }
     365        aHostIDs = (GLuint *)crAlloc(n * sizeof(GLuint));
     366        if (aHostIDs)
     367        {
     368            if (crDLMConvertListIDs(pListState, n, type, lists, aHostIDs))
     369                dispatchTable->CallLists(n, type, aHostIDs);
    344370            else
    345                 crDebug("DLM: CallLists(%d, %u, %p) received bad array of IDs.", n, type, lists);
    346         }
     371                crDebug("DLM: CallLists() failed.");
     372
     373            crFree(aHostIDs);
     374        }
     375        else
     376            crDebug("DLM: no memory on CallLists().");
    347377    }
    348378    else
Note: See TracChangeset for help on using the changeset viewer.

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